In his answer Werner mentions that just loading beamer
takes a lot of time. The problem is that all the definitions have to be processed anew on each TeX run. Because this problem is common and especially significant for large macro collections like LaTeX itself, TeX has a mechanism to deal with it.
TeX defines a notion of a format or a format file, which is a compact dump of TeX's internal state at some point of processing TeX's input. A format can be input by TeX significantly faster than the macro collection it was generated from, because TeX does not have to process the input again. This is somewhat analogous to interpreted and compiled programs: interpreted programs' source has to be parsed each time the program is run, while compiled programs can be loaded and executed directly.
Formats are denoted using the &fmtname
syntax. For example, the LaTeX format is named &latex
. When you compile a LaTeX document, the first thing that actually gets loaded is the format itself. You can load it explicitly by specifying it on TeX's command line:
tex "&latex" latex-test.tex
Formats differ per engine, so there are actually also &pdflatex
, &xelatex
, &lualatex
etc. formats.
Now let's get back to beamer
. It is possible to create a format that contains both the LaTeX's definitions and beamer
's definitions on top of them. We will use the mylatexformat
package for that (be sure to read its documentation for more info!).
Create a file mybeamer.tex
with the following contents:
\documentclass{beamer}
\begin{document}
\end{document}
You can also extend the preamble with packages and/or code you frequently use.
Then execute this command (change the names if using XeTeX or LuaTeX):
pdftex -ini -jobname="mybeamer" "&pdflatex" mylatexformat.ltx mybeamer.tex
A file mybeamer.fmt
is created, which is our new format. To load the format, either use the command line syntax mentioned above or specify it in the source file:
%&mybeamer
\begin{document}
Your presentation here…
\end{document}
Tests on my computer show that mybeamer.tex
takes about 340 ms to process with pdfTeX, while the document using the new format takes only 109 ms. That's roughly three times faster!