Menu

#372 [external] external library doesn't write pages of labels correctly to the aux-file

v1.0 (example)
open
nobody
external (8)
5
2017-10-23
2015-11-10
U_Fischer
No

This example document:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{external}
\tikzexternalize%
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(1,1);
\label{leg:test}
\end{tikzpicture}
\end{document}

write (in a current texlive 2015) this line to the aux-file:

\def \dpthimport {\newlabel {leg:test}{{}{\thepage }}}\dpthimport

As one can see \thepage is not expanded and so the label is useless.

Discussion

  • U_Fischer

    U_Fischer - 2015-11-10

    After some thinking I realized that it is probably not a bug but a (difficult to implement) feature to get the pageref in this way. But I wonder why the external library goes to such length to move this useless commands to the main aux-file.

     
  • Christian Feuersänger

    Thanks for the report.

    You are right... and I have forgotten the issue. I remember that I was happy to report the references as such and accepted that page numbers failed to work.

    In order to see that labels make sense even without page numbers, you should consider labels which have some value in themselfes like equation numbers or referenceable graphical material (pgfplots legends, colorbars, or plots).

    A somewhat more sophisticated example would be

    \documentclass{article}
    \usepackage{tikz}
    \usepackage{amsmath}
    
    \usetikzlibrary{external}
    \tikzexternalize%
    \begin{document}
    
    \section{Section 1}
    \begin{equation}
        1+1=2 
    \end{equation}
    \section{Section 2}
    \begin{tikzpicture}
    \draw (0,0)--(1,1);
    \node[text width=5cm] at (2,2) {
    \begin{equation}
        1+1
    \label{leg:test}
    \end{equation}
    };
    \end{tikzpicture}
    
    \clearpage
    
    \section{Section 3}
    Next page
    
    Equation~\eqref{leg:test} on page~\pageref{leg:test}
    \end{document}
    

    In this context, \eqref makes sense (and is correct) whereas \pageref is broken.

     

    Last edit: Stefan Pinnow 2018-12-23
  • Christian Feuersänger

    I believe that there are two choices to proceed:

    1) ensure that no-one relies on the wrong page numbers (i.e. generate some error) or
    2) fix it.

    I believe that I could fix it if inject the page number into the read aux data at usage time, i.e. as soon as the graphics is reinserted into the main document. An early experiment resulted in correct page numbers.

    Do you know if \thepage is the only macro related to page references? If so, I might be able to expand just this very macro and keep all other macros intact.

     

    Last edit: Stefan Pinnow 2018-12-23
  • Christian Feuersänger

    The following snipped is just for me since I do not know if I can make this production ready.

    My "early experiment" is to use

    Index: generic/pgf/basiclayer/pgfcoreexternal.code.tex
    ===================================================================
    RCS file: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoreexternal.code.tex,v
    retrieving revision 1.22
    diff -r1.22 pgfcoreexternal.code.tex
    339a340,345
    >                     \edef\content{\the\toks0}%
    >                     \pgfplots@command@to@string\content\content
    >                     \def\XX{\thepage}%
    >                     \pgfplots@command@to@string\XX\XX
    >                     \edef\X{\noexpand\pgfplotsutilstrreplace{\XX}{\thepage}{\content}}%
    >                     \X
    344c350
    <                         \noexpand\def\noexpand\dpthimport{\the\toks0}\noexpand\dpthimport}%
    ---
    >                         \noexpand\def\noexpand\dpthimport{\pgfplotsretval}\noexpand\dpthimport}%
    >                         
    
     

    Last edit: Christian Feuersänger 2018-12-28