How to speed up pdflatex for a very large document on MacOS X?
Take a look this description. It's a description of how to format the preamble yourself. Assuming your source file is main.tex
, it all comes down to these steps (which were copied from the link and modified by mefor my own use):
- Rearrange your preamble so that its static part precedes any dynamic part. What in the preamble can be “dynamic”? For example, if you use
\includeonly
, you probably want to change its argument rather frequently and so it is not static. Finally, some packages read and write auxiliary files when you issue a command that you should put in the preamble (eg,nomencl
uses `\makenomenclature). Clearly, you have to run these commands in every run. - Extract the static part of the preamble into, say,
preamble.tex
. At this point,main.tex
no longer contains the static part. It should start with the dynamic part, or simply `\begin{document} if you have nothing dynamic. Execute:
pdflatex -ini -jobname="preamble" "&pdflatex preamble.tex\dump"
in the command line. You will notice that a new file `preamble.fmt has been generated in the same directory, along with other auxiliary files.
Edit the first line of main.tex so that it starts with
%&preamble
.Execute latex
main.tex
as usual:pdflatex -shell-escape main.tex
You may get an error about the class file immediately, or you may notice that latex finishes as usual. But if you have paid attention to the output, or if you inspect the the log file, then you will see that the preamble gets processed in “no time” at all. At this point, cheers!
To make things slightly fancier, here is an modification. First, add this to the end of preamble.tex
:
\def\preambleloaded{Precompiled preamble loaded.}
Then, before the dynamic preamble (or \begin{document}
if there is none) of
`main.tex, add:
\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax} \ifundefined{preambleloaded}
\typeout{PRECOMILED PREAMBLE NOT LOADED}\input{preamble} \else
\typeout{\preambleloaded}
\fi
The idea is to define a macro in the precompiled preamble and use it to detect if the precompiled preamble has been loaded or not. If not, \input{preamble} will be used to pull the static preamble back in and you will not see any error at all.
Also, if you are using tikz
to make figures, have a look at the external
library. Check the Tikz and Pgf manual, section 32 describes how to use it.
Setting in the preamble
\pdfcompresslevel=0
\pdfobjcompresslevel=0
reduced the compile time for my (current version of my) thesis from 2:05 to 1:01 (Minutes:Seconds), but also increased the size of the pdf from about 65 MB to 718 MB (seven hundred eighteen Megabyte). Therefore for the final pdflatex run probably
\pdfminorversion=4% or 5 or 6...
\pdfcompresslevel=9% which is really slooow
\pdfobjcompresslevel=3% maybe reduce to 2; 3 might not be supported by all readers
should be used. If you use a version control system making (uncompressed) backups also of the pdf, you should think about what to do with the 718 MB files...
for all except the last pdflatex
run use -draftmode
pdflatex -draftmode file
taken from the documentation:
-draftmode Sets \pdfdraftmode so pdfTeX doesn't write a PDF and doesn't read any included images, thus speeding up execution.