4

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}
    
    % tikz and pgf library loading and settings
    \usetikzlibrary{external}
    \pgfplotsset{compat = newest }
    
    % package settings
    \hypersetup { 
       % ...
    }
    

    % ... \def\preambleloaded{-- PRECOMILED PREAMBLE LOADED --}

  • 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}             
    
    \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.

  • Related: tex.stackexchange.com/q/70994/31416 – giordano Apr 28 '14 at 19:44
  • 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
  • so nothing can be done? – romeovs Apr 29 '14 at 16:34
  • 1
    Hard to say; I have never tried it. But it sounds a lot as if you would need to use a different precompiled preamble for the externalization - hopefully one which fits all. Perhaps you can create a minimal working example include the commands which generate the fmt files and we can experiment? – Christian Feuersänger May 1 '14 at 9:39
  • The MWE is up and I put it on dropbox too for anyone to download. – romeovs May 1 '14 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.