Tuesday, February 23, 2010

LaTeX: Speed up Latex compilation by precompiling the preamble part

Compiling a preamble, i.e. the part before \begin{document} takes up to a few seconds each time you recompile your document. If you don't change that part very often, you can precompile it to a separate file and save you these seconds.

  1. Open your .tex document and copy all text that appears before the \begin{document} line to a new file (call it preamble.tex).
  2. In the same direcory create a batch file precompile.bat (or shell script if your are on Linux/Mac) and paste the following line there
    pdflatex -ini "&pdflatex preamble.tex\dump"
    Save and run this file. It creates the format file preamble.fmt
  3. Go back to your .tex document, delete all lines you've copied on step 1 (all the lines before \begin{document}) and insert the following line instead (at the very beginning of you file):
    %&preamble
    (preamble here comes from the name of your preamble.fmt)
Next time you need to change your preamble, change preamble.tex and recompile it with precompile.bat

No comments: