# Unknown TikZ/pgfplots error with external [closed]

I am trying to compile a large document (PhD thesis) and I have no problems compiling without using external, but as soon as I enable that feature, it has problems. So far I haven't found the answer in the various other similar topics. I have attempted to compile using both lualatex and pdflatex, both with -shell-escape enabled. The document itself compiles fine but I get errors when it gets to the TikZ images. This error is reproducible on my Windows machine using MikTeX as well as TeX Live on Ubuntu and running directly from a terminal as well as in TeXmaker.

Oddly enough, using an identical package list and syntax but only including the call to the TikZ file in the MWE produces a document that works successfully, so there is clearly something in my document or file system itself that prevents this from working properly when I am doing the actual thesis document.

Anyway, checking the .log file from my actual document reveals the following:

! Package tikz Error: Sorry, the system call 'pdflatex -halt-on-error -interact
ion=batchmode -jobname "img/cache/sac-thesis-figure0" "\def\tikzexternalrealjob
{sac-thesis}\input{sac-thesis}"' did NOT result in a usable output file 'img/ca
che/sac-thesis-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify
that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-esca
pe'. Sometimes it is also named 'write 18' or something like that. Or maybe the
command simply failed? Error messages can be found in 'img/cache/sac-thesis-fi
gure0.log'. If you continue now, I'll try to typeset the picture.
See the tikz package documentation for explanation.


When checking the .log file for the figure itself, it ends on the following error:

\@writefile{toc}{}
! Undefined control sequence.
\pgfmathsetlength ...\pgfmath@onquick #2\pgfmath@
{\begingroup \pgfmath@sele...
l.34 \end{tikzpicture}


For reference, here is my .tikz file that I am trying to compile. The .pdf referenced is a figure I built just using MATLAB and I am mostly placing annoatations on the figure in this instance (though I do have much more data-heavy TikZ pictures in there as well). You could honestly place any .pdf picture there to try it out and it wouldn't change the spirit of the problem here.

\begin{tikzpicture}
% Styles
[pointer/.style={thick}]

\node[anchor=south west] (diagram) at (0,0)
{\includegraphics[width=4.5in]{img/ch1/2mode/5DC-2mode.pdf}};
\begin{scope}[x={(diagram.south east)},y={(diagram.north west)}]

% Temporary gridlines
%\draw[step=0.1,gray,ultra thin] (0,0) grid (1,1);

% Wall label
\draw {(0.5,0.08)} node[anchor=center,color=white] {Wall};

% Trapped acoustic wave
\draw {(0.66,0.2)} node[anchor=west,color=red] {Trapped acoustic wave};

% Sonic line
\draw {(0.55,0.29)} node[anchor=west] {Sonic line: $\overbar{M}^2 = 1$, $y = y_a$};

% Inner layer
\draw {(0.05,0.2)} node[anchor=west] {$\overbar{M} > 1$};

% Outer layer
\draw {(0.05,0.4)} node[anchor=west] {$\overbar{M} < 1$};

% U(y)
\draw {(0.45,0.66)} node[anchor=center,color=blue] {$U(y)$};

% y-axis
\draw {(0.24,0.94)} node[anchor=east] {$y$};

\end{scope}
\end{tikzpicture}


I am honestly out of ideas here at the moment and would really like to externalize since I am going to have a LOT of figures in the document and compile times would get unruly.

## closed as unclear what you're asking by Paul Gessler, user13907, Jesse, Masroor, GuidoJan 21 '15 at 3:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• have you tried to use --shell-escape instead of -shell-escape? – Guido Oct 6 '14 at 1:05
• @Guido -shell-escape is correct on my system (TeX Live). – cfr Oct 6 '14 at 1:08
• @Guido I tried that and it did not work. Same result. – Alex Oct 6 '14 at 1:17
• Why is it concerned with writing to the toc file in what seems to be the middle of a TikZ picture? I find that the best way to use TikZ externalise is as follows: turn it off by default in the preamble and then selectively reenable it for just those figures which work. I also find it is best not to spend time trying to figure out why it doesn't work in particular cases. It is better to think of it as a matter of fate. That way, you don't waste time the feature is meant to save. At least for me, the feature is both fragile and fickle. – cfr Oct 7 '14 at 2:19
• There are other possible approaches. standalone offers some support for externalisation. Or you can, of course, just compile to PDF and include the figures that way. Mostly, though, don't keep compiling your entire thesis. Split it up into chapters or whatever so you can work on one at a time. Then \include or \input. You should not need to compile the master document often at all - at least, not until right at the end when you are preparing to submit or finalising the formatting. – cfr Oct 7 '14 at 2:24