2

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. – NickD May 5 at 13:29
0

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"))
(add-hook 'org-export-before-processing-hook #'seed-random-generator)

(To be honest, I don't really understand why you'd want to diff the generated LaTeX files instead of diffing the original org files. At least you're not diffing PDFs. :P)

| improve this answer | |
  • latexdiff generates documents where additions are marked in blue and deletions in red. That document is helpful to distribute to people that are, eh...diff- and org-ed challenged. – Niclas Börlin May 20 at 20:08
  • @NiclasBörlin Oh, yes, latexdiff on the generated files is a great idea! – Omar May 20 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.