2

I'm attempting to dynamically reference an Equation number in tikzpicture (via \eqref or \ref) using the following:

% Filename:  Test.tex (say)
\documentclass{article}
\usepackage{latexsym,amsfonts,amsthm,amssymb,amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

% Due to a large number of Tikz plots
\usepgfplotslibrary{external}
\tikzexternalize

\begin{document}
Here is an equation:
\begin{equation}
    \label{eqOne}
    y = x^2
\end{equation}
that I'd like to appear in TikZ.

\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\begin{axis}[%
xmajorgrids,
ymajorgrids
]

\addplot[const plot,color=red,solid,line width=0.5pt] plot table[row sep=crcr] {%
0  0\\
1  1\\
2  4\\
3  9\\
};
]
\node[right, align=left, inner sep=0mm] at (axis cs:2,4) {Equation \eqref{eqOne}};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

but this won't work via pdflatex -shell-escape Test.tex. The output generated shows 'Equation (??)'

By trial and error, dynamic referencing seems to only work without \usepgfplotslibrary{external} and \tikzexternalize, but I need these two lines due to the number of TikZ plots that I have.

Is there a way around this dynamic referencing problem; perhaps I'm going about this the wrong way?

Many thanks!

Peter Grill
  • 223,288
Michael
  • 43

1 Answers1

0

Peter's link to references in externalized pgfplots solved my problem!

Just to be explicit for others: for this example (using file Test.tex), the figure # in question (starting from 0) is 0 (here, there's only one figure); so:

pdflatex -shell-escape -interaction=batchmode -jobname "Test-figure0" "\def\tikzexternalrealjob{Test}\input{Test}"

followed by

pdflatex -shell-escape Test.tex

worked!

My sincere thanks to Peter and this forum/group!!

Michael
  • 43