I am currently researching how to generate a recompilation warning from Latex if somthing in the auxfile changes and found this solution.

However I find it rather confusing, it uses:


Which looks to me as if it simply redefines the macro \newreference#1#2 (where #1 and #2 expand to the arguments given to the surrounding macro). However I do not know from where \newreference#1#2 is "called" (expanded? used?) to actually do the check.

I tried taking a look at clsguide and at the points when the auxfile is read. But neither was helpful (apparently the auxfile is only read at \begin{document} so this does not explain it).


This is what \enddocument looks like in latex.ltx:

       \makeatletter \@@input\jobname.aux
     \ifdim \font@submax >\fontsubfuzz\relax
       \@font@warning{Size substitutions with differences\MessageBreak
                  up to \font@submax\space have occurred.\@gobbletwo}%
       \ifx \@multiplelabels \relax
           \@latex@warning@no@line{Label(s) may have changed.
               Rerun to get cross-references right}%
\def\@testdef #1#2#3{%
  \def\reserved@a{#3}\expandafter \ifx \csname #1@#2\endcsname
 \reserved@a  \else \@tempswatrue \fi}

If @filesw is true (you didn't make a call to \nofiles), then LaTeX closes the main .aux file (\immediate\closeout\@mainaux), but after some redefinitions, reads the main .aux again: \makeatletter \@@input\jobname.aux.

The redefinitions above is important in that it checks whether \labels match their definitions. Boris' code attempts to do the same by redefining \newreference in a similar way to how LaTeX redefines \@newl@bel (via \let\@newl@bel\@testdef).

  • While my latex knowledge is not sufficient enough to fully understand the details, your excellent awnser stating that the redefinitions are applied before the output file is read again clarified it a lot. – ted Nov 24 '14 at 21:31
  • @ted: Yes. You can also look at the .log output, where you'll see references to the .aux being printed multiple times. – Werner Nov 24 '14 at 21:40

Package rerunfilecheck calculates MD5 hashes (pdfTeX/LuaTeX in DVI or PDF mode) of the auxiliary files and compares them at the very end of the document, later than \AtEndDocument, where the .aux file is still open. See package atveryend for later hooks.




First run:

Package rerunfilecheck Warning: File `test.aux' has changed. Rerun.
Package rerunfilecheck Warning: File `test.toc' has changed. Rerun.
  • I am sorry that my question is a bit unclear if you omit the title but I was rather interested in the mechanics of the commands quoted than an allternative. I think this answer would have fitted better to my original question that led me here (tex.stackexchange.com/q/213683/19326). I referenced your awnser in a comment there – ted Nov 24 '14 at 21:34

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.