# What are the situations where you have to compile a document more than once?

You have to compile a file twice to get the desired output in the accepted answer to Lineno for 2 column. The accepted answer to How can I avoid compiling twice? provides a way to avoid compiling multiple times.

My question is, what are those situations where you have to compile a file more than once?
(We know of at least two such situations with reference to the linked questions.)

-
Is there a reason why you're talking about typesetting and not about compiling? I suppose the latter would be a narrower term, more closely related to the reason of the multiple runs needed. –  doncherry Nov 23 '11 at 11:00
I use TeXShop. There is a "Typeset" pulldown menu option but no "Compile" option in TeXShop. Therefore, I use the word "Typeset" rather than the word "compile" to be consistent. –  Sony Nov 23 '11 at 11:49
My answer here: tex.stackexchange.com/q/30677/8344 shows that it is even possible to never get stable output. –  Roelof Spijker Nov 23 '11 at 13:43

Any document that requires information to be written to and read from an ancillary file will need compiling more than once. These include documents that contain

• references using \ref, or vref from varioref, or cref from cleveref
• \tableofcontents, \listoffigures, \listoftables
• \thumbsoverview (thumbs package)
• bibliographies
• indexes

In particular, one would need to compile more than once if any of the above has cause to change- for example, you add a new section to your document, which would necessarily change the \tableofcontents.

Of course, in the case of bibliographies and indexes one would need to run biblatex (or biber) or makeidx between multiple compilations to ensure that these are kept up to date.

Following Gonzalo's comment, there are also cases in which no ancillary files are involved as is the case with some table-building packages which require several passes to calculate the proper elements of the table (longtable, for example); or code using PGF/TikZ specially when using the remember picture/overlay options.

-
You could also mention cases in which no ancillary files are involved as is the case with some table-building packages which require several passes to calculate the proper elements of the table (longtable, for example); or code using PGF/TikZ specially when using the remember picture/overlay options. –  Gonzalo Medina Nov 23 '11 at 0:19
...or some zref-related references. I know this to be the case with the savepos module. –  Werner Nov 23 '11 at 0:48
@Werner I've made it community wiki- feel free to make the edit –  cmhughes Nov 23 '11 at 0:51
PGF/TikZ writes stuff to the .aux file when using the remember picture/overlay options. –  Loop Space Mar 13 '12 at 12:43

To correctly line up the various parts of a longtable, "[i]n the typical case the algorithm will converge after three or four passes" (manual, section 4).

-

Often not only two but three or more runs are necessary. Imagine a document with lots of figures and a list of figures somewhere at the first pages of the document. All pages are numbered using ascending Arabic numbers. First compilation run will typeset the document without any entry at the list of figures but collects the information at the .lof file (via .aux file). Second compilation rund will typeset the list of figures with several pages and as a consequence of this the page numbers of all figures will change. So you need a third run to get the correct numbers at the list of figures.

-