1

I am using the following TeX code (minimal example), which compiles fine, when running pdflatex then run make -f filename.makefile and repeat the procedure a second time to also include the referenced legend:

\documentclass{article}

\usepackage{pgfplots}
\usepgfplotslibrary{external}
\usepackage{tikz}

\pgfplotsset{
    /tikz/external/mode=list and make
}

\tikzexternalize

\begin{document}

\begin{figure}
    \ref{leg}
    \begin{tikzpicture}
        \begin{axis}[legend to name=leg]
            \addplot {x};
            \addlegendentry{$x=0,1$};
        \end{axis}
    \end{tikzpicture}%
\end{figure}

\end{document}

As I need to submit the files to a journal I can not use the pgfplots package and would like to use the tikzexternal.sty package instead. In order to do so I tried to replace lines 3-9 with \usepackage{tikzexternal} and put the tikzexternal.sty file into the directory. However, this does not seem to be compatible with the legend to name feature.

Werner
  • 603,163
Mamo
  • 13
  • Welcome! I'm afraid I'm not sure I've understood. If you cannot use pgfplots then you can't create that figure with that code whether it is externalised or not. Have I missed something? – cfr Nov 20 '15 at 14:27
  • @cfr , the external library creates the corresponding figures and saves them as pdf files. Once all figures are created one can use the tikzexternal package instead of pgfplots and tikz. This package then recognizes the pgfplot environments and simply inserts the corresponding pdf files. I have used this before for a journal submission, however, I could not figure out, how to do it with the legend to name feature. – Mamo Nov 20 '15 at 15:16
  • 1
    I figured out a manual workaround, which would be okay for me as I only have three figures with legends. After creating all figures one can replace the \ref{leg} command by an includegraphics command using the correct pdf file and then remove the legend to name keyword and remove all \addlegendentry commands. This works but it would be nicer to have a solution that does not require so much manual editing. – Mamo Nov 20 '15 at 15:20
  • externalization and legend referencing seems to be problematic, see http://tex.stackexchange.com/questions/37471/pgfplots-externalization-and-legend-referencing and http://tex.stackexchange.com/questions/85985/tikz-externalize-referenced-legends-from-pgfplots-are-not-included. None of these seem to help in your case, though. – jarauh Nov 20 '15 at 16:44
  • Oh, OK. They don't object to the output from pgfplots which was what I thought you mean (i.e. they don't want it to look like this). Just the use of the package. Then I understand. – cfr Nov 20 '15 at 17:38

1 Answers1

2

My attempt to substitute the compiled result by tikzexternal.sty worked as soon as I defined \ifpgfpicture. The legend to name feature uses this switch which belongs to PGF. However, it should be save to define it and keep it at value 'false'.

The following example worked for me:

\documentclass{article}

%\usepackage{pgfplots}
%\usepgfplotslibrary{external}
%\usepackage{tikz}

\usepackage{tikzexternal}
\newif\ifpgfpicture

\tikzset{
    /tikz/external/mode=list and make
}

\tikzexternalize

\begin{document}

\begin{figure}
    \ref{leg}
    \begin{tikzpicture}
        \begin{axis}[legend to name=leg]
            \addplot {x};
            \addlegendentry{$x=0,1$};
        \end{axis}
    \end{tikzpicture}%
\end{figure}

\end{document}

I seems that this definition needs to become part of tikzexternal.sty. Note that I also replaced \pgfplotsset by \tikzset since tikzexternal.sty does not know that control sequence.

For a complex document, you could define

\def\pgfplotsset#1{}

in order to substitute it as well.