TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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.


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.


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!


  • 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.
share|improve this question

closed as too localized by Dave Jarvis, David Carlisle, Thorsten, Kurt, lockstep Mar 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
up vote 2 down vote accepted

In comments you indicated that the document is generated and constrained in structure so it might be possible to predetermine the number of runs without typesetting.

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.

A table of contents at the start is effectively a collection of page references so if you have a table of contents and want to limit the number of runs required, place the toc in a frontmatter section with (say) roman page numbering followed by a forced page break so that the pagination and numbering of the main document matter is not affected by the length of the table of contents.

share|improve this answer
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
If the document is generated and not being edited between runs you don't really need latexmk, the index won't affect pagination so you can run latex then makeindex then latex and the numbers will be right so you can just fix that sequence in a simple script. – David Carlisle Mar 27 '13 at 20:39
@DaveJarvis OK I give up then (I've never used latexmk, so can't suggest how to tune its behaviour:-) – David Carlisle Mar 27 '13 at 20:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.