I’d like to make references work in my robust-externalize library. I wanted to parse the aux file, extract the lines related to a label like:
\newlabel{sec:dependencies}{{3.4}{7}{Dependencies}{subsection.3.4}{}}
\newlabel{sec:dependencies@cref}{{[subsection][4][3]3.4}{[1][7][]7}}
and input this in the preamble of my document. As a proof of concept, I wrote:
\begin{CacheMe}{latex, add to preamble={\usepackage{hyperref}\newlabel{sec:dependencies}{{3.4}{7}{Dependencies}{subsection.3.4}{}}}}
Hello \ref{sec:dependencies}.
\end{CacheMe}
and it kind of work!
But there is an annoying issue: I cannot click the link to go to the appropriate section (while writing \ref{sec:dependencies} anywhere in the document would work). Do you know if there is a way to make \includegraphics work for links as well?
MWE:
\documentclass{article}
\usepackage{robust-externalize} % You certainly need to download the .sty in github.com/leo-colisson/robust-externalize, and compile with -shell-escape, or manually (see doc)
\usepackage{hyperref}
\begin{document}
\section{Dependencies}\label{sec:dependencies}
\begin{CacheMe}{latex, add to preamble={\usepackage{hyperref}\newlabel{sec:dependencies}{{1}{1}{Dependencies}{section.1}{}}}}
Hello, go to section \ref{sec:dependencies}.
\end{CacheMe}
\end{document}
EDIT
I tried with newpax but it is not working, the link points to the included image itself. I think that the problem is that when I compile the subfile with pdflatex robExt-471D7E5B93E3AC81760E014C437DDD7B.tex, that actually contains:
\documentclass[,margin=0cm]{standalone}
\usepackage {hyperref}\newlabel {sec:dependencies}{{2}{2}{Dependencies}{section.2}{}}
\begin{document}%
%% We save the height/depth of the content by using a savebox:
\newwrite\writeRobExt%
\immediate\openout\writeRobExt=\jobname-out.tex%
%
\newsavebox\boxRobExt%
\savebox{\boxRobExt}{%
Hello, go to section \ref {sec:dependencies}.%
}%
\usebox{\boxRobExt}%
\immediate\write\writeRobExt{%
\string\def\string\robExtWidth{\the\wd\boxRobExt}%
\string\def\string\robExtHeight{\the\ht\boxRobExt}%
\string\def\string\robExtDepth{\the\dp\boxRobExt}%
}%
%
\end{document}
I get a warning:
pdfTeX warning (dest): name{section.2} has been referenced but does not exist,
replaced by a fixed one
So I guess that the question can be reformulated as "how to make latex keep the link even if it is not present in the current document".
Here is the paxfile as well:
\[{pax}{0.1l}\\
\[{file}{(./robExt-471D7E5B93E3AC81760E014C437DDD7B.pdf)}{
Size={13783},
Date={D:20230906164541+02'00'},
}\\
\[{pagenum}{1}\\
\[{page}{1}{0.0 0.0 94.977 8.856}{}\\
\[{annot}{1}{Link}{86.232 -0.996 93.206 9.852}{GoTo}{
C={[1 0 0 ]},
H={/I},
Border={[0 0 1 ]},
DestLabel={1},
}\\
\[{dest}{1}{1}{Fit}{
}\\
But for reference, here is the full procedure, without shell escape:
- create
\DocumentMetadata{uncompress}
\documentclass{article}
\usepackage{pdfpages,xcolor}
\usepackage{robust-externalize} % You certainly need to download the .sty in github.com/leo-colisson/robust-externalize, and compile with `-shell-escape`, or manually (see doc)
\usepackage{hyperref}
\usepackage{newpax}
\newpaxsetup{usefileattributes=true}
\begin{document}
\section{Test}
\newpage
\robExtConfigure{latex/.append style={do not add margins}, enable manual mode}
\section{Dependencies}\label{sec:dependencies}
\newpage
\section{Test}
\robExtConfigure{latex/.append style={do not add margins}}
\begin{CacheMe}{latex, name output=mycompiledfile, add to preamble={\usepackage{hyperref}\newlabel{sec:dependencies}{{3}{3}{Test}{section.3}{}}}}
Hello, go to section \ref{sec:dependencies}.
\end{CacheMe}
\mycompiledfile
%%% Uncomment later:
%\includegraphics{\mycompiledfile.pdf}
\ref{sec:dependencies}
\end{document}
- compile with:
mkdir robustExternalize
pdflatex debug-crossref.tex
# look in debug-crossref-robExt-compile-missing-figures.sh, but it should be:
cd robustExternalize/ && pdflatex -halt-on-error "robExt-471D7E5B93E3AC81760E014C437DDD7B.tex" && cd ..
- copy the
robExt-471D7E5B93E3AC81760E014C437DDD7B.pdf filein the main folder (don't know how to make it work in subfolder):
cp robustExternalize/robExt-471D7E5B93E3AC81760E014C437DDD7B.pdf .
- Create a file
testnewpax.texwith:
\documentclass{article}
% load the lua code
\directlua{require("newpax")}
% write .newpax files for newpax.sty
\directlua
{
newpax.writenewpax("robExt-471D7E5B93E3AC81760E014C437DDD7B")
}
\begin{document}
\end{document}
compile that file with lualatex:
lualatex testnewpax.tex
Uncomment the line after Uncomment later in the above document, and recompile it twice:
pdflatex debug-crossref.tex
pdflatex debug-crossref.tex
See that the created link does not point to the right section.

--shell-escapewhich contains lots of python code including some which removes all sort of files on my computer. Beside this: if you include a pdf with \includegraphics all annotations it contains are stripped. It is possible to reinclude them with the newpax package. – Ulrike Fischer Sep 06 '23 at 08:40\robExtConfigure{enable manual mode}after loading the file, and it will write all commands (basically onepdflatex, I added a-shell-escapealso here, but it is not needed) in a file\jobname-robExt-compile-missing- figures.sh. (And actually, the python is never run by the program, it just creates the file in case the user wants to clean the cache without removing the picture in use) Actually maybe I should default to that mode if shell escape is not enabled instead of giving an error… – tobiasBora Sep 06 '23 at 13:52newpax, I’ll give it a try! – tobiasBora Sep 06 '23 at 13:53newpaxlibrary, but it is not working: the problem seems to be that warningpdfTeX warning (dest): name{section.2} has been referenced but does not exist, replaced by a fixed onewhen I compile the picture from the first place (see my edit for the precise MWE). Do you know how to force latex not to replace the link with a dummy one? Also, a question regarding your library: is it possible to make it work when the pax file is located in a subfolder, next to the pdf folder to include? In my library I make my best to put all files in a subfolder to limit pollution – tobiasBora Sep 06 '23 at 14:54