2

I am using the externalize feature of tikz/pgf to save space for my thesis. I am using TeXShop on a Mac. I am running into trouble referencing something in the main document from the externalized tikzpicture. A MWE for the main file:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{tikz}
\usepgfplotslibrary{external}
\tikzexternalize[prefix=pdfimages/]

\newcommand{\includetikz}[1]{%
    \tikzsetnextfilename{#1}%
    \input{#1.tex}%
}

\begin{document}

\begin{equation} \label{eq:equation}
y = x + x^2
\end{equation}

\includetikz{image}

\end{document}

A MWE for"image.tex":

\begin{tikzpicture}
    \begin{axis}
        \addplot [color=black,solid,line width=1.0pt,domain=0:1,samples=11]{x+x^2};
        \addlegendentry{Eq. \ref{eq:equation}};
    \end{axis}
\end{tikzpicture}

Produces: Can't reference!

The pgfplots manual (Operations Mode in sec 7.1) suggests using mode=list and make to solve this issue, but I am having trouble understanding how to run the makefile that is generated. What would be a robust way of implementing this with TeXShop? Thanks for your help.

EDIT: Using make from the command line is the only way of doing this so far that has worked for me. I added mode=list and make to \tikzexternalize and then compiled it from TeXShop. Prompted by the compiler, running make -f main.makefile (main is the filename) generated the images. Compiled the document a few more times and the reference from within the graphic worked as promised. This works but wasn't what I originally intended. If someone knows a way to this without the command line from within TeXShop, I would be much obliged.

2

As of pgfplots 1.13, this works without any modifications, i.e. simply running pdflatex -shell-escape file.tex twice results in the desired output.

Here is a reduced minimal without the extra image.tex (but otherwise identical), compiled with pgfplots 1.13 and pgf 3.0.1:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{tikz}
\usepgfplotslibrary{external}
\tikzexternalize

\begin{document}

\begin{equation} \label{eq:equation}
y = x + x^2
\end{equation}

\begin{tikzpicture}
    \begin{axis}
        \addplot [color=black,solid,line width=1.0pt,domain=0:1,samples=11]{x+x^2};
        \addlegendentry{Eq. \ref{eq:equation}};
    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

A solution for you might be to update your TeX distribution.

1
  • I tried to, but my package manager only updated it to 1.12. I fully trust you however. Thanks for writing such a great package! Jun 4 '16 at 23:10
1

Did you try to rerun Latex? For the first run I get the warnings LaTeX Warning: External picture 'pdfimages/Latex1' contains undefined references on input line 6. and LaTeX Warning: There were undefined references. After a second Latex run the warnings clear and I get:

enter image description here

14
  • Unfortunately that did not work. Would have been a nice fix. Apr 24 '16 at 19:20
  • This is strange. Please try to run the MWE without the externalisation, i.e. just using \input{image.tex} and removing \tikzexternalize[prefix=pdfimages/] and your declaration of \includetikz. Probably this is an issue with the set-up of your Latex compiler.
    – JMP
    Apr 24 '16 at 19:24
  • I checked just make sure, and it did work without the externalization. I'm surprised yours worked without doing anything extra as the manual does mention this problem for external graphics. Apr 24 '16 at 19:30
  • Then I think the problem is the Latex compiler. The externalization just works, if there are some additional commands passed to the compiler. Does the externalization work in general for you? What compiler do you use?
    – JMP
    Apr 24 '16 at 19:36
  • 1
    Replace -shell-escape by --shell-escape
    – JMP
    Apr 24 '16 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.