One of my biggest problems with LaTeX is the speed that it takes to process large documents. (I typeset books with LaTeX.) I have approaches, such as breaking the book into chapters and running them independently. But the results are not satisfactory.
For example, the book I'm currently working on reports this after I run LaTeX:
Latexmk: All targets () are up-to-date
no errors
make 74.57s user 1.92s system 99% cpu 1:17.05 total
My computer has six cores! LaTeX uses one.
EDIT
Details of my system:
- MacMini (2018) 3 Ghz 6-Core Intel Core i5 Processor, 32 GB 2667 MHz DDR4 RAM
- 41
.tex
input files, total of 11,000 lines of LaTeX source, over 100,000 words of text. - Moved to xelatex due to Unicode issues, but
pdflatex
took roughly the same period of time. - 69 included packages
- Book typesets to 326 pages currently, will typeset to 500 at completion of project.
- 72 images, most in the neighborhood of 20-50k.
- Output logfile is 5611 lines long (!)
- Still using
BiBTeX
becausebiber
breaks, and I can't debug it. But usingbiblatex
, at least. - Compiling with
latexmk
- Multiple targets in
Makefile
, including targets to just typeset each chapter. Typesetting a single chapter can be done in 15.97 seconds
LaTeX experts will say that every page depends on everything that comes before it because LaTeX is Turing Complete. And, of course, every page also depends on every page that comes after it, because of tempfiles. Frankly, it's amazing that LaTeX converges when typesetting!
However, there are well-known tricks that could be used to solve this problem. For example, pages could checkpoint relevant state, and then a new compile could use a multi-threaded implementation and run each page using the previous run's checkpoint, and re-run the pages if the checkpoint changes. Something similar could be used to speed even single-threaded runs: if we're compiling page 265, and the state at the beginning of page 265 is the same this run as the previous run, and no text in the document has changed between the start of page 265 and the start of page 266, then nothing on page 266 probably changed.
It seems that optimizations like these could make LaTeX dramatically faster. So why don't we see them in LaTeX2e, and will they be in LaTeX3?
pdflatex
on Linux instead. – Alan Xiang Oct 10 '20 at 3:07latexmk
with the-time
option (and optionally-silent
) to see output at the end about what took how long. In this case, it seems that the bulk of the 70-odd seconds is taken by four calls toxelatex
each taking about 17 seconds. (Interspersed with calls tomakeindex
andbibtex
.) So if you don't need the index and all references each time, you can just runxelatex
and save about three-fourths of the time. (The “full” version can still be run in the background while you're reading the document I guess.) – ShreevatsaR Oct 19 '20 at 4:48