It is an unfortunate reality that one must compile a LaTeX file several times in order to get all labels and citations correct. As far as I know, one should go on compiling as long as TeX warns that that "labels may have changed", and two or three passes may not be enough.

Is it possible to write a LaTeX document that never stabilizes, i.e., no matter how many times I compile it, it will go on complaining that labels have changed?

I am thinking about something like a \pageref{something} written in a large font that moves from page 9 to page 10, which requires longer to typeset and thus makes the corresponding label change page and so on ad infinitum.

  • 3
    We will need a minimal example. – Joseph Wright Oct 6 '11 at 11:37
  • 11
    @JosephWright That's the question! :) – egreg Oct 6 '11 at 11:50
  • 1
    Due to the halting problem, it isn't even possible to find out, if the document will eventually compile without label-changes. – FUZxxl Oct 6 '11 at 12:01
  • it's possible that with some add-on packages, this warning becomes "pathological". we know it's true with the package amsbooktoc (which is sent out to ams authors only on request, so it's not in general distribution), but haven't had time to track down the source of the problem yet. however, after the number of runs normally required to get a good table of contents, the document is stable, so we just warn our authors about what they should check for. but i believe this is a different situation than you are describing. – barbara beeton Oct 6 '11 at 12:17
  • 4
    @FUZxxl That isn't true: That just states that there exists a class of problems exists for which you cannot prove if they will halt or not. Not all problems belong to that class. For example, you can mathematically prove that while(n>0){n++;} will go forever, and that n=10;while(n<10){n--}; will halt. – Canageek Jan 22 '12 at 20:47

Having an explicit \ifthenelse test makes the document look like the looping is intentional. It is possible for the cross referencing not to converge even if there is no explicit conditional switching within the file. This document for example.



a\clearpage b\clearpage c\clearpage

\caption{a figure to take up space}

Some interesting text about  something in Section \ref{x},
which starts on page \pageref{x}.

The text of an interesting section.
| improve this answer | |
  • 2
    Cool, that's exactly what I was looking for. I hope @RoelofSpijker won't mind if I accept this answer instead. – Federico Poloni Oct 30 '12 at 14:01
  • 10
    For those who wonder and are too lazy to compile: this crucially relies on the fact that in roman numerals, the page number IV takes more space than the page number V. This wouldn't work with Arabic page numbers, since increasing page numbers take increasing space. – Bruno Le Floch Aug 7 '14 at 22:48
  • 1
    @yo' are you sure? that seems unlikely, unless you have a funky font where 9 is wider than 10. – David Carlisle Sep 17 '19 at 9:21
  • 1
    @DavidCarlisle Ouch. Right, sorry that's my bad. – yo' Sep 17 '19 at 9:32
  • 1
    @yo' but now I have to find a font with 9 wider than 10, there must be one somewhere.... – David Carlisle Sep 17 '19 at 9:51

Quickly testing something, this seems to give the warning each time it is compiled.

\newcommand{\tes}[1]{\ifthenelse{\equal{#1}{1}}{\Huge A}{\small A}}

So it seems that it is possible. Basically, \tes puts a huge A in front of the label if the label is on page 1, moving its location to page 2. If it's on page 2, \tes puts a small A in front of it instead, moving it back to page 1. Changed the code a little bit, no longer needs lipsum, just uses a vspace now. If you just run latex file.tex you will see the output switches between a 1 page dvi and a 2 page dvi after each run.

| improve this answer | |
  • 1
    The output is different each time, the A might have the same size, but it is not on the same page. The output switches between having 0 and 1 blank pages prior to the Huge A. I would not call that stable at all. – Roelof Spijker Oct 6 '11 at 11:56
  • 1
    As a matter of fact, thats incorrect. The A also switches between Huge and small size. Change the capital A to a lowercase a in the else branch to see this a little more clearly. – Roelof Spijker Oct 6 '11 at 11:59
  • 6
    Now someone should put this into latexmk and watch it run forever. – Canageek Jan 22 '12 at 21:23
  • 3
    @Canageek: I got 'pdflatex' needed too many passes after latexmk compiled it five times. – Martin Scharrer May 1 '12 at 18:48
  • 1
    @MartinScharrer Good to know that there is a built in safety for that. – Canageek May 2 '12 at 5:33

I accidentally created such a document for real. I used biblatex-icomp. Two consecutive citations of the same source happened to be in the vicinity of a page break. Then apparently the following happened (citing Paul Stanley's accurate description):

  1. On the first run the citation seems to fit on the first page, so the aux file records "this citation was on page 1".

  2. Next time round, biblatex looks at this, and says "OK, that fit on page 1, so I'll use ibid". Unfortunately, doing that forces the citation onto the next page, so this time the aux file records: "citation was on page 2". And biblatex (which is using "old information" about where the citation appears) wrongly prints the citation as an "ibid".

  3. All would be well if the citation stayed on page 2, because biblatex would put things right next time it ran and it would get back in sync. But in fact next time, because a full citation is used, it moves back to page 1! So this time you end up with a full citation on page 1.

  4. And next time ... you get the picture.

A working example and Paul Stanley's explanation can be found at the question Avoid infinite compiler passes with biblatex ibid citation styles?

| improve this answer | |

For the fun of it. See also The LaTeX runs (with varioref) never settle down to a stable final state.





xxxx xxxx 
xxxx xxxx 
xxxx xxxx 
xxxx xxxx 
xxxx xxxx 
xxxx xxxx xxxx xx
See section on page~\pageref{bar}



Where am I ?

| improve this answer | |
  • ah sorry, I had not seen that Roman numerals were also in use in @DavidCarlisle answer from 2012. Here VIII has two more characters than IX. With monotype font, would be easier yet. – user4686 Jan 22 '16 at 16:57

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.