Monthly Archives: November 2008

A utility for precompiling LaTeX headers

I recently came across a neat trick which allows precompiling of latex headers (where all the packages are loaded). For a small headers, the loading of style files takes a trivial amount of time. But, for a large documents with alot of \usepackage{} statements, this can take up to 10 seconds (which adds up if you compile frequently). Especially if you use something like tikz which itself loads tons of auxiliary files.

Detailed instructions on how this is done can be found here and some other discussion on this can be found here and here. Please refer there for the full details.

First let me set the stage. Say you have:

  • Set up a main tex file “main.tex” and a header file “preamble.tex”.
  • And you also have the line %&main at the very top of your document.
  • And you are using pdfLaTeX (this is just for the sake of example, regular LaTeX is fine)
  • Also you are on a *nix system (see this link if this is not the case) using a version of texlive.

After you have gotten the hang of doing this yourself you will realize that typing

$ pdflatex -ini -jobname="main" &pdflatex\ preamble.tex\dump

is really annoying and hard to remember.

That is where pretex comes in! This bash shell script is just a wrapper for the command above but it is WAY easier to remember. It also has a few options. Using pretex the command above would be:

$ pretex -o main preamble.tex

(that is assuming you put the script in a place that is in your PATH environment variable). Now isn’t that easier? You can download pretex here. It is published under the GPL v3. For the full options type:

$ pretex -h