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.texcontains all static stuff:\documentclass[a4paper, titlepage]{article} \usepackage[dutch]{babel} \usepackage[babel]{microtype} \usepackage{hyperref} % ... \usepackage{tikz} \usepackage{pgfplots} % tikz and pgf library loading and settings \usetikzlibrary{external} \pgfplotsset{compat = newest } % package settings \hypersetup { % ... }% ... \def\preambleloaded{-- PRECOMILED PREAMBLE LOADED --}
main.texcontains the dynamic preamble and the document:% load preamble if it wasn't precompiled \def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax} \ifundefined{preambleloaded} \typeout{!! PRECOMILED PREAMBLE NOT LOADED --}\input{preamble.tex} \else \typeout{\preambleloaded} \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
The mwe is also downloadable from dropbox.
fmtfile – Christian Feuersänger Apr 28 '14 at 20:19tikzuses it's own format file for the external compilations, mypreamble.fmtdoes not get used and thus must me included for everytikzrun (because thepreambleloadedis not set -- seemain.tex). This is again slower. So merging the format files would give three speedups: one for the first run, one for each tikz picture that is built (in parallel usingmake -j) and one for the second run. – romeovs May 02 '14 at 07:10fmt=preamblein theexternal/system calldoes seem to work as expected and speeds up the image compilation considerably. – romeovs May 02 '14 at 08:01