As countless questions/answers have noted in the past, LaTeX requires you to compile at least twice when there are references, TOC/LOF, etc. Many of these situations have been documented in the answer to What are the situations where you have to compile a document more than once?

Efforts at avoiding this extra step have been successful in select, very specific cases, such as How can I avoid compiling twice? Yet, it is a practice that we take as a given today, simply developing scripts and macros to automate this process enough to ease the pain.

The answer to [this question about moving to the previous page] alludes to memory constraints of early computers being central to the reasons why TeX was originally built the way it was. Information that might be needed later is simply stowed away in any number of auxiliary files, and referred to as the next pass was made. Once a page is "complete", it is forgotten by the compiler.

I have often thought: Given the advancements in computer processing and memory capabilities, is it possible/realistic/planned for LaTeX to maintain more of the document in memory to avoid having to compile multiple times?

Keeping the entire document in memory would take a lot of memory, and perhaps some very large documents could not go this route (maybe it would have to be an optional behavior). But it seems that many aspects of typesetting would benefit from this sort of enhanced compilation.

I realize this gets to the heart of what (La)TeX is and how it was built. It is not a simple patch; it likely requires a rewrite of the whole core (or does it?). There are certainly other issues that surround this as well (Would this actually reduce compilation time?); I'd be delighted for a reference to another place that discusses this or related issues. (Has this been thought about for LaTeX3?)

  • 7
    Note: unless you use a fundamentally different underlying technology, LateX3 can't do this as it still uses TeX. I also note that ConTeXt MkIV still uses multiple passes (all rolled up into context).
    – Joseph Wright
    Mar 19, 2014 at 15:08
  • 1
    You might find this question interesting: tex.stackexchange.com/questions/114292/…
    – alexwlchan
    Mar 19, 2014 at 15:13
  • What do you mean by "many aspects of typesetting would benefit from this sort of enhanced compilation"? I'm no power-user of any kind but for most of my work, texify.exe does the job of streamlining it all into one, seamless process.
    – Doggie52
    Mar 19, 2014 at 16:17
  • @Doggie52, Perhaps "many aspects" was overstating the problem. Most "ordinary" documents won't benefit greatly; but anything that wants to optimize page breaks or float text itself could use the feature (perhaps this question, for instance).
    – cslstr
    Mar 19, 2014 at 20:28
  • I recognize that the feature is not "easy" in any sense. And that TeX doesn't inherently support the feature. Nevertheless, I wonder if there isn't some sort of overlay that could augment TeX in a way that would make it more intelligent in the vertical-mode sense. @alexwlchan The TuG Q&A was pretty insightful and helps me accept the way things are a bit easier.
    – cslstr
    Mar 19, 2014 at 20:31

1 Answer 1


As Joseph said this isn't a feature of latex it's a feature of tex (shared with xetex and luatex) so there is no feasible way to do that in anything called latex. Also I don't think it is true that in general the memory constraints are that different: people's expectations increase even faster than hardware capacity. See the need for tikz externalize as a document with a few tikz pictures can soon eat serious amounts of memory, even on modern hardware.

But it's all really in a name any system allowing forward and backward references is storing the information somewhere. You may think of latex as storing it in the .aux file on disk as being very 1970's but the .aux file may be on an SSD or on a virtual filesystem in main memory and accessing it needn't be any practical hindrance, and as you commented you can replace "latex" by make or latexmk or arara or context or a batch file that just runs latex 4 times, so the end effect to the user can be of compiling in a single pass if that is what is wanted.

Of course doing it in one pass is only really of benefit if you can write your complete document with no errors and never need to process it more than once. If you are using an edit/compile/preview cycle it is only an annoyance in that it slows the cycle down.

  • 3
    Perhaps note that the usual argument for having the entire doc in memory is for global optimisation of page breaks, and that soon starts to look very complex even on a modern system (if you allow re-breaking of paragraphs as part of the process).
    – Joseph Wright
    Mar 19, 2014 at 15:22
  • 1
    Yes I thought afterwards that maybe I was a bit hard on the idea, but anyway it's basically same thing. All you need to do is parametrise the document so you can vary the page breaking, then typeset 72,192 versions at the same time on a suitable machine and pick the one you like best Mar 19, 2014 at 15:27
  • 1
    One optimization that could be obtained by keeping the whole document in memory would be to first number all sections and equations etc, then resolve references done through \ref, then typeset. In the absence of \pageref, all of the typeset content would be known on a first pass, which reduces the total compilation time. Aug 7, 2014 at 22:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .