When has a LaTeX document compiled enough times for cross-references to be final?
0 reputation · 21 Jan 2020, 15:57 UTC
0 reputation · 21 Jan 2020, 15:57 UTC
I am building a small automated pipeline that compiles LaTeX documents and I need to decide when compilation is actually done. From what I understand, LaTeX writes \label data to the .aux file during a run, and \ref commands read the previous run's data, which is why a first pass prints ?? and logs an undefined-reference warning.
What I cannot pin down is the stopping condition. LaTeX appears to emit a rerun warning when labels changed, but it only reports one pending pass at a time rather than stating how many runs remain. I have also read that elements like table-of-contents page numbers, longtable column widths, and hyperref bookmarks can shift across several runs, so two passes are not always sufficient. Tools like latexmk seem to rerun until generated files stop changing, which suggests the convergence decision is delegated outside the engine itself.
Assume a current pdfLaTeX-based setup with a standard document class.
Is comparing the .aux file between runs a reliable convergence test, or can references still be wrong when it stops changing? Does the log's rerun warning guarantee that one more pass is enough? And when a bibliography via BibTeX or Biber is involved, how should the extra engine runs be sequenced into that decision?
In a standard pdfLaTeX run the first pass writes label data to the .aux file. Subsequent reads of that file by ref commands produce the familiar ?? and undefined-reference warnings until the label data from a prior run is available. This is why a single initial pass is never sufficient for final references.
LaTeX’s built-in rerun warning indicates that labels changed between the current and previous run but it reports only one pending pass. If those labels continue shifting in later runs additional passes follow. Elements such as table-of-contents page numbers longtable column widths and hyperref bookmarks have independent stabilization behavior and often require three to four runs before their values stop changing.
If your pipeline currently assumes only basic cross-references and no bibliography the two-run test after the initial compile is sufficient. Do you include a bibliography or page-layout elements such as longtable extensive toc or hyperref bookmarks? This determines whether the simpler test applies or the full convergence cycle is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.