# orgmode latex export: How to create repeatable labels?

Every time I export org-mode document to LaTeX, most sections get new and unique labels, e.g.,

\section{Introduction}
\label{sec:orge0665da}


The next time I export the document, the label will change, e.g.,

 \section{Introduction}
\label{sec:orgcd0c5bf}


If I want to do a diff of the LaTeX documents to a previous version, I get a ton of changed labels that hide the changes I have made to the text. Sometimes this confuses latexdiff as well.

Is there a way to ensure that the exported labels are the same between exports? At least for as long as the number of (sub)sections does not change? Set a seed to a random number generator? Write a hook function that returns a label given a section?

I am aware of Is there a way to suggest label names in org-mode latex export?, that solves the problem for a specific label, but not the (in org-mode) un-labelled sections.

• I don't know of any "official" mechanism to accomplish this and a cursory look through the sources did not produce an "aha" moment on a possible implementation. The only thing I can suggest ATM is sed: delete the labels before diffing. May 5, 2020 at 13:29

I think you hit on the solution yourself:

Set a seed to a random number generator?

That seems to work just fine in my limited testing. The function org-export-new-reference in ox.el does indeed call random to generate the reference label.

To seed the random number generator, call random with some string (it seeds the generator with some value computed from the string). If you want the generator seeded before every single export use the org-export-before-processing-hook:

(defun seed-random-generator (_) (random "a fixed and unchanging string"))

• @NiclasBörlin Oh, yes, latexdiff on the generated files is a great idea!
• I can understand. In some cases, you want to commit the .tex files in order they are used by colleagues that don't use Org Mode. Another point for repeatable labels is when you build the PDF files thanks to latexmk which will rerun the compilation (even) if (only) the labels have changed. Mar 18 at 18:08