2

How to mute the pgfplotslink.0.0-warning for named plots when hyperref and externalization is used?

A Known Story?

Section 7.1 p. 512 of the PGFPLOTs manual (Version 1.13 2016/01/06) is clear: A

\label in the externalized graphics which is referenced in the main document

requires\tikzset{external/mode=list and make}so i use the make from cygwin. On linux, make was already there.

Section 4.9.6 p. 246 of the manual states:

\ref{<label name>}

Can be used to reference a labeled, single plot. See the example above.

This will also work together with hyperref links and \pageref

The quotes suggest that the following example is supported:

\documentclass{article}
% Referring to a named plot via~\ref{namedplot} triggers a warning when
% combied with hyperref and externalization.

\usepackage{pgfplots}
\pgfplotsset{compat=1.13} % mute the backwards compatibility warning
\usepgfplotslibrary{external}
\tikzset{external/mode=list and make}
% The warning goes away aswell when externalization is disabled by
% commenting the next line.
\tikzexternalize

% hyperref is needed to trigger the warning
\usepackage{hyperref}

% wrapper of ref{} to avoid externalizing the small ref
\newcommand*{\refne}[1]{\tikzexternaldisable\ref{#1}\tikzexternalenable}

\begin{document}
\begin{figure}
\tikzsetnextfilename{picture_1}%
\begin{tikzpicture}
\begin{axis}[domain=0:10]
\addplot {sin(x^2)};
\label{namedplot}
\end{axis}
\end{tikzpicture}
\caption[alternative caption to keep the ref-stuff away from the lof]
{Referring to the named plot via~\refne{namedplot} triggers the warning.}
\end{figure}
\end{document}

However a warning appears no matter how many compilations:

name{pgfplotslink.0.0} has been referenced but does not exist, replaced by a fixed one

My Research

The known problem Legend referencing in caption *and* externalization is actually related to the legend to name and the solution involed a wrapper to disable the externalization of the ref, which i use anyway (see code).

Similar suggestions in pgfplots, custom legend and tikz library external where \pgfplotslegendfromname{named} was suggested. However, this is only avaiable for legends.

Loading hyperref before pgfplots as suggested in Hyperref does not work for legend labels inside \subbottom didnt solve it.

The request Can we get references into externalized pgfplots images to work? does not seem to invole hyperref. It deals with submitting code to publishers or archives.

The warning suggest that the link will point to the wrong target, i.e. the top of the page that contains the picture. In this particular case, a reader will not notice this, because one rarely clicks on the link from inside the caption.

The Question

How to mute the pgfplotslink.0.0-warning in the example? I dont need the hyperref feature for the named plots, but i would like to keep it for the other references in the document. Abandoning externalization is not an option.

Version infomation:

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9 64-bit) (preloaded format=pdflatex 2016.5.3) 27 JUL 2017 16:15

Package: pgfplots 2016/01/06 v1.13 Data Visualization (1.13)

Package: pgf 2015/08/07 v3.0.1a (rcs-revision 1.15)

1 Answer 1

1

In pgfplots.code.tex i found the definition of \pgfplotsplotfromname which solves the problem like this: Use \pgfplotsplotfromname instead of \ref to refer to a named plot. The warning vanishes because \hyperref is disabled.

Caveat: \pgfplotsplotfromname is undocumented and may change in the future.

For the example, the following code avoids the warning:

\newcommand*{\refne}[1]{\tikzexternaldisable\pgfplotsplotfromname{#1}\tikzexternalenable}

Complete example is:

\documentclass{article}
% Referring to a named plot via~\ref{namedplot} triggers a warning when
% combied with hyperref and externalization.
% Workaround: \pgfplotsplotfromname instead of \ref

\usepackage{pgfplots}
\pgfplotsset{compat=1.13} % mute the backwards compatibility warning
\usepgfplotslibrary{external}
\tikzset{external/mode=list and make}
\tikzexternalize

\usepackage{hyperref}

% \pgfplotsplotfromname instead of \ref fixes the warning
% use of \tikzexternaldisable\tikzexternalenable is optional
\newcommand*{\refne}[1]{\tikzexternaldisable\pgfplotsplotfromname{#1}\tikzexternalenable}

\begin{document}
\begin{figure}
\tikzsetnextfilename{picture_1}%
\begin{tikzpicture}
\begin{axis}[domain=0:10]
\addplot {sin(x^2)};
\label{namedplot}
\end{axis}
\end{tikzpicture}
\caption[alternative caption to keep the ref-stuff away from the lof]
{Referring to the named plot via~\refne{namedplot} will not trigger the warning, because hyperref is not involed.}
\end{figure}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .