I've been reading and gathering material from multiple sources online about what steps are required to externalize a document that contains TikZ pictures which store a reference to their legends using legend to name=<name> and use \ref{<name>} to include the legends at the bottom of, for example, groupplots.
Options include using list and make instead of convert with system call, or using a trick/hack which does not externalize the reference by using the following in the preamble:
\pgfplotsset{
invoke before crossref tikzpicture={\tikzexternaldisable},
invoke after crossref tikzpicture={\tikzexternalenable},
}
Since my document includes 30+ figures and I have not found a way to make list and make not re-produce the figures every time (two passes are needed as well!), my only option is to try the "hacky" way. Below is a MWE of what I have.
MWE:
\documentclass{article}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{external}
\pgfplotsset{
compat=newest,
invoke before crossref tikzpicture={\tikzexternaldisable},
invoke after crossref tikzpicture={\tikzexternalenable},
}
% \tikzexternalize
\begin{document}
\begin{figure}[]
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=2 by 1,},]
\nextgroupplot[scale only axis,width=0.35\textwidth,height=0.35\textwidth,legend to name=grouplegend,]
\addplot
coordinates {(1,1) (2,2) (3,3)};
\addlegendentry{Legend 1}
\addplot
coordinates {(1,3) (2,2) (3,1)};
\addlegendentry{Legend 2}
\nextgroupplot[scale only axis,width=0.35\textwidth,height=0.35\textwidth]
\addplot
coordinates {(1,1) (2,2) (3,3)};
\addplot
coordinates {(1,3) (2,2) (3,1)};
\end{groupplot}
\node (legend) at ($(group c1r1.south)!0.5!(group c2r1.south)$)
[below, yshift=-3\pgfkeysvalueof{/pgfplots/every axis title shift}]
{\ref{grouplegend}};
\end{tikzpicture}%
\caption{The caption.}
\end{figure}
\end{document}
If I compile this with two passes of pdflatex -shell-escape <file>, the reference is resolved and the legend shows up correctly at the bottom of my two figures. Similarly, when list and make is used, running pdflatex -shell-escape <file> and make -B -f <makefile> twice also resolves the reference. When \tikzexternalize is used however, I can't find the right sequence of commands which resolves the reference. No matter how many times I run pdflatex -shell-escape <file>, the reference remains unresolved and the legend shows "??".
Does anyone know why the trick in the preamble has no effect? Am I doing something wrong?
list and makeoption as a not so nice workaround. – Alexander Jul 26 '13 at 16:39list and makeis that the-Bflag is needed for two passes to take place, and this causes all 30+ figures to be re-produced. If you know an easy way to fix this, I'll gladly use it. – sudosensei Jul 26 '13 at 16:55-Bflag, runmake -f <makefile>once, delete the externalized pdf of the figure that includes a reference and runmake -f <makefile>again, or would that break something? – sudosensei Jul 26 '13 at 17:13