I am experiencing a problem when using externalize and the align environment. In some weird cases the pdf of tikz figures are not generated properly and they have to be re-generated every time that the tex file is compiled.
Here is a MWE:
The main file, called test.tex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize % activate with the default mode
\usepackage[cmex10]{amsmath}
\begin{document}
\tikzsetexternalprefix{figs/tikz2pdf/}
\begin{figure}
\tikzpicturedependsonfile{figs/fig.tikz}
\tikzsetnextfilename{fig}
\input{figs/fig.tikz}
\end{figure}
\begin{align}
A &= 1 \label{A} \nonumber \\
B &= 2 \label{B}
\end{align}
\end{document}
The content of figs/fig.tikz is:
\begin{tikzpicture}
\draw (0,0) --(1,2);
\end{tikzpicture}
The directory figs/tikz2pdf exists prior to the compilation. I compile the code using "pdflatex -interaction=nonstopmode -shell-escape test.tex". To my understanding this should create figs/tikz2pdf/fig.pdf, but it does not. It successfuly creates test.pdf, but reports the following two errors:
! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e rror -interaction=batchmode -jobname "figs/tikz2pdf/fig" "\def\tikzexternalreal job{test}\input{test}"' did NOT result in a usable output file 'figs/tikz2pdf/f ig' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enable d system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'write 18' or something like that. Or maybe the command simply fail ed? Error messages can be found in 'figs/tikz2pdf/fig.log'. If you continue now , I'll try to typeset the picture.
! Package amsmath Error: Multiple \label's: label 'A' will be lost.
Interestingly:
if I remove either the "\nonumber" or "\label{A}" from the align environment, figs/tikz2pdf/fig.pdf is created.
Once that figs/tikz2pdf/fig.pdf is created once, it is used in following compilations of test.tex, not needing to re-compile figs/fig.tikz
I know that labelling a line in align and then using \nonumber is somehow incongruent. What puzzles me is that the error in the align environment prevents externalize to work properly. And despite all, a proper test.pdf is produced. The overall visible effect is a large compilation time in documents containing many tikz figures.
A final note: I came up with the provided MWE stripping down a long complex document. After that I removed all (accidental) occurrences of simultaneous labelling and usage of \nonumber, after which externalize still does not produce the pdf from tikz figures. I therefore suspect that the previous MWE could be one way to reproduce a more intricate issue.
Any light on this is appreciated. Am I doing something wrong? Am I missing something?
EDIT: It seems that I forgot an occurrence of simultaneous labelling and usage of \nonumber. After its removal externalize does produce the pdf from tikz figures, so this seems to be the key issue.
cmex10
option toamsmath
, which is provided for compatibility with very old TeX systems.\label{A}\nonumber
doesn't make much sense.