Creating TeX Format Files


BlogPublisher can run in two modes

  1. tex_engine='pdflatex' using pdflatex and a pre-compiled format. which is super-fast but uses default fonts, or
  2. tex_engine='lualatex' using lualatex and no format, which is slower but allows custom fonts.

Using the pdflatex engine

To create a template called tikz.fmt (about 14MB) run

pdflatex -ini -jobname=tikz "&pdflatex" mylatexformat.ltx dm.tex


  1. The options can be specified as -ini or --ini. Both seem to work.
  2. Do not use \ in the filename, use /.
  3. If the file name includes - enclose it in quotes. (Powershell, at least.)
  4. The argument &pdflatex loads the base format for pdflatex.
  5. mylatexformat.ltx (located C:/Users/steve/AppData/Local/Programs/MiKTeX/tex/latex/mylatexformat) is from the mylatexformat package file.
  6. dm.tex should include all the packages you want to load in the format, between \documentclass and \begin{document}.

Here is an example dm.tex for tikz diagrams. Note the font items are commented out—they only work with extended TeX varieties. The actual document is irrelevant but the libraries and other definitions are important. In particular the format must be rebuilt if other packages are added to the preamble.

% build format: pdflatex -ini -jobname=tikz "&pdflatex" mylatexformat.ltx "tikz-stand-alone.tex"

% needs lualatex - uncomment for Wiley fonts
%\setmainfont{Stix Two Text}
%\setmathfont{Stix Two Math}

% add packages you want included in the format here
\usetikzlibrary{mindmap, shadows}

% really common macros





The same command runs with lualatex in place of pdflatex but the format doesn’t work to create pdf files.

Having built the format, use it to build a TeX file by running

pdflatex --fmt=tikz dm.tex

which is super-fast. It does not handle fonts. dm.tex does not need any of the header information.

Notes. 1. Anything between documentclass and \begin{document} is ignored. 2. New macros can be defined after \begin{document}.

For example, the following suffices.




\path[draw, latex-latex] (0.01, 0.25) -- (1.99, 0.25)  node[fill=white, text=black, pos=0.5, align=center] {Jan 1};
\path[draw, latex-latex] (2.01, 0.25) -- (3.99, 0.25) node[fill=white, text=black, pos=0.5, align=center] {Jan 2};

\path[draw, very thin] (0, 0.3) -- (0, -0.1);
\path[draw, very thin] (2, 0.3) -- (2, -0.1);
\path[draw, very thin] (4, 0.3) -- (4, -0.1);

\path[draw, very thin] (1, 0.0) -- (1, -0.1)
    node[scale=0.5, below, align=center] {$t=0.5$\\ Noon};

\path[draw] (-1,0)
-- (0, 0) node[circle, fill=blue, scale=0.35] {} node[below, align=center] {$t=0$}
-- (2, 0) node[circle, fill=blue, scale=0.35] {} node[below, align=center, pos=1] {$t=1$}
-- (4, 0) node[circle, fill=blue, scale=0.35] {} node[below, align=center, pos=1] {$t=2$}
-- (5, 0);

\node at (4,4) {HELLO};



Wiley Book Examples

In the folder /S/TELOS/PIR_Proofs/src

  • pbit_template.tex used to create the template with pmaketemplate.bat
pdflatex --ini --aux-directory=temp --output-directory=temp --jobname=wiley "&pdflatex" mylatexformat.ltx pbit_template.tex
  • pbit.tex a runner, insert your new code in the document
  • pmakebit.bat quick-makes pbit.tex using
pdflatex --fmt=temp/wiley.fmt --aux-directory=temp --output-directory=latest pbit.tex
  • To slow make with xelatex you need to include all the header info; you can do this by pasting into pbit_template.tex, for example.


Based on an old Reddit post I gave up trying to get lualatex to make a format file.

If anyone stumbles into this one day in search of help, I concluded that it is either impossible, or very difficult to get mylatexformat to work nicely with lualatex (or maybe just my vast collection of packages). I did see success by commenting out the lualatex specific packages (fonts etc.), moving some packages like tikz and tikz externalization to the dynamic preamble section and running mylatexformat with pdflatex. This decreased the compile times DRAMATICALY for my use case anyway.

posted 2022-02-04 | tags: blog, TeX, workflow

Share on