# Background

Looking to generate a PDF using latexmk. The LaTeX document, which is automatically generated from a web-based application, will include many large images, Tikz graphics, table of contents, multiple indices, etc.

The default call to latexmk will include the images in each run of pdflatex. To increase performance, it was advised to use -draftmode.

# Problem

The latexmk program cannot determine whether the next run of pdflatex will be the last run required to produce a finished document.

The difference, with a simple test, was 10 seconds without -draftmode and 0.9 seconds with using -draftmode: an order of magnitude, which is quite significant.

# Question

How can you determine the exact number of pdflatex runs that are required to produce a PDF document so that calls to pdflatex, except the final call, can use -draftmode?

Thank you!

# Ideas

• It might be possible to pass in a number that equals the number of runs required. I'd rather not use this approach as dynamic determination is ideal.
• Perform an extra run of pdflatex at the end, which is not in -draftmode.
-

## closed as too localized by Dave Jarvis, David Carlisle, Thorsten, Kurt, lockstepMar 27 '13 at 21:36

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

It is not possible to determine the number of required runs. You can always construct an example which requires one more run, and one more, and one more, … – Marco Mar 27 '13 at 19:01
@Marco: In this case, the LaTeX file is computer-generated, with a database-backed preamble. We should be able to determine the number of runs required because users cannot add "more" to the document. They can add more content, and mix & match different items from predefined preamble snippets, but they cannot, for example, add a table of figures nor change the class/style. – Dave Jarvis Mar 27 '13 at 19:18
How the TeX file is generated doesn't matter. It depends on you data and on the macros (read: packages) you use. Some kinds of macros, e.g. variable references or randomly generated data, are known to be unpredictable and might never converge. For simple documents it is possible to prove an upper limit of runs if you know the macros. – Marco Mar 27 '13 at 19:30
Recall that TeX is a Turing-complete programming language and it's up to the macro writer to decide when the TeX run will end. Furthermore, TeX itself does not think in terms of multiple runs. Each run is an independent typesetting task. The fact that the data (e.g. TOC) is gathered in a former TeX run does not matter at all from TeX point of view. – Marco Mar 27 '13 at 19:35
The preamble is, quite literally, combined from a set of distinct snippets within a database table. It would be trivial to associate a count of the number of additional runs that each snippet requires. We control the packages. There is no randomly generated data; the LaTeX files are quite simple: images and text. – Dave Jarvis Mar 27 '13 at 19:39

If there are any \pageref cross references then it is best to typeset until LaTeX determines that the refs are stable as there are cyclic dependencies between the typeset page numbers and the pagination of the document that in pathological cases might not resolve at all.
If there are no page references then one run of latex will get all the reference numbers into the aux file and so all \ref should be correct on the second run.
There are two indices with page references. I can associate each "preamble snippet" (e.g., font definitions) with an additional latex runs tally. Unfortunately, latexmk doesn't provide an option (yet) to use draftmode until the final run, which is the crux of the problem. – Dave Jarvis Mar 27 '13 at 20:34