# tikz externalization: list and make forces make to recompile the tikz images every time

I'm trying to speed up my latex development by parallelising as much tasks as possible and by redoing as little work as possible on every run.

Amongst other things, I want to externalise my tikz images with the list and make option set. This allows me to recompile all the tikz images at once using make -j -f main.makefile.

To automate this I use following makefile (simplified for purpose of this question):

main.pdf: main.tex
pdflatex -shell-escape -interaction=batchmode -draftmode -fmt=preamble main.tex
make -j -s -f main.makefile
pdflatex -shell-escape -interaction=batchmode main.tex


One problem I have using this approach is that make -j -s -f main.makefile always recompiles all images, even when it is not necessary (when only some ir even none of the tikz images have been changed in main.tex).

It being so that the tikz images usually are taking the lions share of my compilation time, this seems incredibly wasteful.

Is there a way to get around this? I would think it is trivial for tikz only to write the images that need to be rebuilt to the makefile.

## important update:

It appears as though list and make does work as it should except when the -fmt=preamble flag is set (as I did in my makefile). However, to create more speedup I would like to keep using my precompiled preamble. Any way to get around this?

My preamble contains all my package inclusions and command definitions. The \tikzexternalize and \tikzset commands are place inside my dynamic preamble.

# MWE

Consider the following directory structure:

.
|- main.tex      # this is the main document
|- preamble.tex  # this is the preamble document

• preamble.tex contains all static stuff:

\documentclass[a4paper, titlepage]{article}

\usepackage[dutch]{babel}
\usepackage[babel]{microtype}
\usepackage{hyperref}
% ...
\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{external}

% package settings
\hypersetup {
% ...
}


• main.tex contains the dynamic preamble and the document:

% load preamble if it wasn't precompiled
\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax}

\typeout{!! PRECOMILED PREAMBLE NOT LOADED --}\input{preamble.tex}
\else
\fi

% tikz external settings
\tikzexternalize[
optimize=true,
% system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -file-line-error -interaction=batchmode -jobname "\image" "\texsource"},
% also works and is faster:
system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -file-line-error -interaction=batchmode -fmt=preamble -jobname "\image" "\texsource"},
mode=list and make
]

\begin{document}
some text...
% ...
\end{document}


Note the system call setting for tikz externalisation.

To precompile the preamble, the following command is used:

pdflatex -ini -shell-escape -interaction=batchmode -file-line-error -jobname="preamble" "&latex preamble.tex\dump" preamble.tex


To compile the document using the precompiled fmt file I use:

pdflatex      -shell-escape -interaction=batchmode -file-line-error -output-format=pdf -fmt=preamble main.tex


• I would not be surprised if the precompiled preamble simply does not fit in externalization mode: the externalization sets up (and requires) a different preamble. And I am unsure if this is still possible together with your fmt file – Christian Feuersänger Apr 28 '14 at 20:19