This is a very special case, I guess, but it's what I need:
%&Testing
\documentclass{article}
\endofdump
\usepackage{pgfplots}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=x axis label,ylabel=y axis label]
\addplot {x};
\end{axis}
\end{tikzpicture}
\end{document}
I want to be able to switch tikz on or off without having to recompile the preamble, hence the \endofdump. I created the header using MiKTeX and
etex -job-name=Testing -initialize "&pdflatex" mylatexformat.ltx Testing.tex
When I then compile Testing.tex, I get this error message:
! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "Testing-figure0" "\def\tikzexternalrealjo
b{Testing}\input{Testing}"' did NOT result in a usable output file 'Testing-fig
ure0' (expected one of .pdf:.jpg:.jpeg:.png:).
Checking the respective log file (Testing-figure0.log), I find this:
! Undefined control sequence.
<recently read> \endofdump
l.3 \endofdump
I was wondering how I could fix this. It seems that the externalized tikz job inputs the preamble, but does not use the custom format. Hence, it can't understand \endofdump.
I found that this works (this may already be the answer).
%&Testing
\documentclass{article}
\ifcsname tikzexternalrealjob\endcsname\else\endofdump\fi
\usepackage{pgfplots}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=x axis label,ylabel=y axis label]
\addplot {x};
\end{axis}
\end{tikzpicture}
\end{document}
Is there a better way to do this?