I use pgfplots to produce a vast amount of images in my document. Due to limited LaTeX memory, I am forced to use \tikzexternalize. Moreover, I also use the subfig package to group several pictures into a single float and the cleveref package. So far, everything works perfect. However, when I add references to my externalized images, strange bugs occur.
In short, some plots which are based on data from files do not produce correct references. The exact same plots with fixed data do produce correct references. Apart from that, both methods results in correct images. My only problem are the missing references.
Due to the complexity of the project, it is hard to deliver a complete working sample code which produces such a bug. I hope the following explanations are enough to give you a rough idea of what might go wrong.
For all images, I use a shortcut command. Let us assume we have
\newcommand{\myfigureA}[1]{\tikzsetnextfilename{#1}\begin{tikzpicture}
\begin{axis}[width=4cm,height=4cm]
\addplot3[surf] file{#1.data};
\end{axis}\end{tikzpicture}\label{fig:#1}}
and
\newcommand{\myfigureB}[1]{\tikzsetnextfilename{#1}\begin{tikzpicture}
\begin{axis}[width=4cm,height=4cm]
\addplot3[surf] coordinates {
(0,0,0) (1,0,0) (2,0,0) (3,0,0)
(0,1,0) (1,1,0.6) (2,1,0.7) (3,1,0.5)
(0,2,0) (1,2,0.7) (2,2,0.8) (3,2,0.5)};
\end{axis}\end{tikzpicture}\label{fig:#1}}
When I use \myfigureB{name} to produce a certain image, all references \cref{fig:name} are working. On the other hand, when I use \myfigureA{name}, all references \cref{fig:name} are broken and I get "??" signs instead. However, both \myfigureA{name} and \myfigureB{name} result in the exact same image in the final PDF document (assuming the coordinates in the file correspond to the coordinates given here). Strangely enough, references to some images (always the same images) do in fact work. I have no idea what makes these images different from the others.
A usage of these commands to produce a series of four images might look like this:
\begin{figure}[h]
\centering
\subfloat[][]{\myfigureA{name1}}
\subfloat[][]{\myfigureA{name2}} \\
\subfloat[][]{\myfigureA{name3}}
\subfloat[][]{\myfigureA{name4}}
\caption{caption text}
\end{figure}
I use the latest versions of all mentioned packages. Compilation is performed by the usual four commands, namely pdflatex -interaction=nonstopmode -shell-escape mylatexfile, bibtex mybibliography, pdflatex -interaction=nonstopmode -shell-escape mylatexfile and pdflatex -interaction=nonstopmode -shell-escape mylatexfile.
In the .log file of the main document I only get the "Labels may have changed..." message for both \myfigureA{name} and \myfigureB{name}, but even compiling a few dozen times does not change this. I think this might be a result of the externalization process. The individual log files of the externalized images show a lot of missing references for both \myfigureA{name} and \myfigureB{name}, although in the former case they do work in the final PDF document. In the latter case, they do not, as already mentioned. The cleveref package does not seem to have anything to do with this bug.
Unfortunately, I have no more ideas where else to look for my bug.
mode=list and makeis used: pgfplots writes the input file name into the makefile dependencies. I am currently unaware of other differences. Did you try other image conversion modes (likemode=convert with system call)? You could also try to insert\relaxbefore your\labelcommands to exclude string gobbling bugs in the external lib (although not very likely) – Christian Feuersänger Dec 30 '11 at 15:58/pgf/images/aux in dpth=falsewhich will deactivate references/labels inside of externalized images - this will free a further write register. – Christian Feuersänger Dec 30 '11 at 16:05.auxfiles (and perhaps the.dpthfiles as well). They should contain the definitions of the\labelcommands in question. – Christian Feuersänger Dec 30 '11 at 16:38.dpthfiles are empty! There also seem to exist no.auxfiles for my individual externalized pictures. Do I have to enable these somewhere? – Werner Eims Dec 30 '11 at 17:17.dpthfiles can be empty - they contain everything that is usually written to.auxfiles + information for thebaselinefeature. They have to be non-empty in case you have labels inside of the external pictures. In all other cases, the remaining.auxfiles should contain your references in some form. – Christian Feuersänger Dec 30 '11 at 18:08.dpthfiles! Is there any specific place to search for the reason of this behavior? Besides, only my.texdocuments have associated.auxfiles, not the externalized images. – Werner Eims Dec 30 '11 at 18:20