我想在我的健壮的外部化库。我想解析aux
文件,提取与标签相关的行,例如:
\newlabel{sec:dependencies}{{3.4}{7}{Dependencies}{subsection.3.4}{}}
\newlabel{sec:dependencies@cref}{{[subsection][4][3]3.4}{[1][7][]7}}
并将其输入到我的文档的序言中。作为概念证明,我写道:
\begin{CacheMe}{latex, add to preamble={\usepackage{hyperref}\newlabel{sec:dependencies}{{3.4}{7}{Dependencies}{subsection.3.4}{}}}}
Hello \ref{sec:dependencies}.
\end{CacheMe}
而且它确实有效!
但有一个恼人的问题:我无法点击链接转到相应的部分(而\ref{sec:dependencies}
在文档的任何地方都可以书写)。你知道有没有办法让\includegraphics
链接也能正常工作吗?
梅威瑟:
\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}
编辑
我尝试使用 newpax,但它不起作用,链接指向包含的图像本身。我认为问题在于当我使用编译子文件时pdflatex robExt-471D7E5B93E3AC81760E014C437DDD7B.tex
,它实际上包含:
\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}
我收到一个警告:
pdfTeX warning (dest): name{section.2} has been referenced but does not exist,
replaced by a fixed one
因此,我猜想问题可以改写为“如何让 Latex 保留链接,即使该链接不存在于当前文档中”。
这也是 paxfile:
\[{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}{
}\\
以下是完整的流程,仅供参考。无需逃逸外壳:
- 创造
\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}
- 编译:
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 ..
- 复制到
robExt-471D7E5B93E3AC81760E014C437DDD7B.pdf file
主文件夹中(不知道如何使其在子文件夹中工作):
cp robustExternalize/robExt-471D7E5B93E3AC81760E014C437DDD7B.pdf .
- 创建文件
testnewpax.tex
:
\documentclass{article}
% load the lua code
\directlua{require("newpax")}
% write .newpax files for newpax.sty
\directlua
{
newpax.writenewpax("robExt-471D7E5B93E3AC81760E014C437DDD7B")
}
\begin{document}
\end{document}
使用 lualatex 编译该文件:
lualatex testnewpax.tex
Uncomment later
取消注释上述文档中的后一行,然后重新编译两次:
pdflatex debug-crossref.tex
pdflatex debug-crossref.tex
发现创建的链接没有指向正确的部分。