尾声中的章节和定理的超链接指向正文中的相应章节

尾声中的章节和定理的超链接指向正文中的相应章节

一位同事刚刚向我指出,我在本书尾声中给出的所有定理和章节的超链接都是:

www.math.jhu.edu/~eriehl/context.pdf

指向倒数第二章第 6 章中的相应部分,尽管内部标签是明确的。问题可能出在我重置结语计数器的方式上。这是一个最小的工作示例:

\documentclass[pdflatex]{amsbook}

\usepackage[pdfborder=0, hidelinks]{hyperref}

\theoremstyle{theorem}

%theorems & stuff
\newtheorem{thm}{Theorem}[section]

\begin{document}

\setcounter{tocdepth}{1}
\tableofcontents

\chapter{Chapter 1}\label{ch:one}

\section{Chapter section}\label{sec:in-chapter}

\begin{thm}\label{thm:in-chapter} Chapter theorem.
\end{thm}

Compare Theorem \ref{thm:in-chapter} found in \S\ref{sec:in-chapter} in Chapter \ref{ch:one} with Theorem \ref{thm:in-epilogue} found in \S\ref{sec:in-epilogue} in Chapter \ref{ch:epilogue}.

\chapter*{Epilogue}\label{ch:epilogue}
\setcounter{thm}{0}
\setcounter{section}{0}
\renewcommand{\thesection}{E.\arabic{section}} 

\section{Epilogue section}\label{sec:in-epilogue}

\begin{thm}\label{thm:in-epilogue} Epilogue theorem.
\end{thm}

Compare Theorem \ref{thm:in-chapter} found in \S\ref{sec:in-chapter} in Chapter \ref{ch:one} with Theorem \ref{thm:in-epilogue} found in \S\ref{sec:in-epilogue} in Chapter \ref{ch:epilogue}.

\end{document}

当您编译为 PDF 时,对章节和结语章节的引用是正确的,但对定理和章节的引用都指向第 1 章。

有什么想法可以修复此问题吗?由于 PDF 对应于已出版的书籍,因此我更愿意修复超链接,而不更改印刷版中标签的外观。

更新:正如 Teepeemm 在下面指出的那样,我当前的代码生成一个如下所示的 aux 文件(摘录):

    \newlabel{sec:in-chapter}{{1}{3}{Chapter section}{section.1.1}{}} 
    \newlabel{thm:in-chapter}{{1.1}{3}{}{thm.1.1.1}{}} 
    \newlabel{sec:in-epilogue}{{E.1}{5}{Epilogue section}{section.1.1}{}}
 \newlabel{thm:in-epilogue}{{E.1.1}{5}{}{thm.1.1.1}{}}

根据 Teepeemm 的建议添加“\let\theHsection=\thesection”,aux 文件的最后两行更新为:

\newlabel{sec:in-epilogue}{{E.1}{5}{Epilogue section}{section.1}{}}
\newlabel{thm:in-epilogue}{{E.1.1}{5}{}{thm.1.1}{}}

这修复了最小工作示例中的链接,但并没有修复实际书中的超链接。

它为指向尾声章节的超链接提供了唯一的标识符,但尾声部分和定理仍然分配了第 6 章的重复编号:

\@writefile{toc}{\contentsline {chapter}{\tocchapter {Chapter}{}{Epilogue: Theorems in Category Theory}}{217}{chapter*.43}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\@writefile{toc}{\contentsline {section}{\tocsection {}{E.1}{Theorems in basic category theory}}{217}{section.6.1}}
\newlabel{sec:basic-theorems}{{E.1}{217}{Theorems in basic category theory}{section.6.1}{}}
\citation{maclane-natural-associativity}
\citation{maclane-natural-associativity}
\@writefile{toc}{\contentsline {section}{\tocsection {}{E.2}{Coherence for symmetric monoidal categories}}{219}{section.6.2}}
\newlabel{sec:monoidal}{{E.2}{219}{Coherence for symmetric monoidal categories}{section.6.2}{}}
\newlabel{eq:symmonisos}{{E.2.1}{219}{Coherence for symmetric monoidal categories}{equation.6.2.1}{}}

您能建议一下您提到的更复杂的解决方案吗?看来我可能需要它。

答案1

在不进行修改的情况下编译 MWE 时,.aux 文件中的标签将是:

\newlabel{ch:one}{{1}{3}{Chapter 1}{chapter.1}{}}
\newlabel{sec:in-chapter}{{1}{3}{Chapter section}{section.1.1}{}}
\newlabel{thm:in-chapter}{{1.1}{3}{}{thm.1.1.1}{}}
\newlabel{ch:epilogue}{{1}{5}{Epilogue}{chapter*.1}{}}
\newlabel{sec:in-epilogue}{{E.1}{5}{Epilogue section}{section.1.1}{}}
\newlabel{thm:in-epilogue}{{E.1.1}{5}{}{thm.1.1.1}{}}

您可以看到第二条条目和倒数第二条条目都使用相同的锚点名称进行超链接,即:section.1.1

您可以看到,第三条条目和最后一条条目都使用相同的锚点名称进行超链接,即:thm.1.1.1

在未进行修改的情况下编译 MWE 时,.log 文件包含以下警告:

pdfTeX warning (ext4): destination with the same identifier (name{section.1.1})
has been already used, duplicate ignored

pdfTeX warning (ext4): destination with the same identifier (name{thm.1.1.1})
has been already used, duplicate ignored

\chapter请注意,应用诸如或\section之类的节命令\begin{theorem}会导致 hyperref 包自动放置锚点/目标,以便超链接到相应的节标题。自动放置锚点包括自动为该锚点创建名称。
每当 hyperref 包自动创建新锚点时,它都会将该锚点的名称保存在宏 中\@currentHref。放置 时\label\label宏反过来会依赖 的扩展来\@currentHref获取作为最后一个创建的锚点的名称,并将该锚点名称写入辅助文件的\newlabel条目中。

为了在创建超链接时明确地表示锚点,每个锚点都需要一个唯一的名称来仅标识该锚点。

.log-file-warnings 的原因是,将 sectioning-commands 的计数寄存器的值设置为以前的值会导致自动创建的超链接锚点的名称不再唯一。

自动创建的锚点的名称来自于这些\theH...宏。

因此,当将分段计数器设置为以前的值时,您需要确保以能够\theH...确保锚点名称唯一性的方式重新定义相应的宏。

我建议做类似的事情:

\chapter*{Epilogue}\label{ch:epilogue}
\setcounter{section}{0}
\setcounter{thm}{0}
\renewcommand{\thesection}{E.\arabic{section}} 
\let\theHsection=\thesection % add this line **right after** redefining \thesection 

MWE 将会变成这样:

\documentclass[pdflatex]{amsbook}

\usepackage[pdfborder=0, hidelinks]{hyperref}

\theoremstyle{theorem}

%theorems & stuff
\newtheorem{thm}{Theorem}[section]

\begin{document}

\setcounter{tocdepth}{1}
\tableofcontents

\chapter{Chapter 1}\label{ch:one}

\section{Chapter section}\label{sec:in-chapter}

\begin{thm}\label{thm:in-chapter} Chapter theorem.
\end{thm}

Compare Theorem \ref{thm:in-chapter} found in section \ref{sec:in-chapter} of Chapter \ref{ch:one} with Theorem \ref{thm:in-epilogue} found in section \ref{sec:in-epilogue} of the \nameref{ch:epilogue}.

\chapter*{Epilogue}\label{ch:epilogue}
\setcounter{thm}{0}
\setcounter{section}{0}
\renewcommand{\thesection}{E.\arabic{section}} 
\let\theHsection=\thesection


\section{Epilogue section}\label{sec:in-epilogue}

\begin{thm}\label{thm:in-epilogue} Epilogue theorem.
\end{thm}

Compare Theorem \ref{thm:in-chapter} found in section \ref{sec:in-chapter} of Chapter \ref{ch:one} with Theorem \ref{thm:in-epilogue} found in section \ref{sec:in-epilogue} of the \nameref{ch:epilogue}.

\end{document}

.aux 文件中的标签现在是:

\newlabel{ch:one}{{1}{3}{Chapter 1}{chapter.1}{}}
\newlabel{sec:in-chapter}{{1}{3}{Chapter section}{section.1.1}{}}
\newlabel{thm:in-chapter}{{1.1}{3}{}{thm.1.1.1}{}}
\newlabel{ch:epilogue}{{1}{5}{Epilogue}{chapter*.1}{}}
\newlabel{sec:in-epilogue}{{E.1}{5}{Epilogue section}{section.E.1}{}}
\newlabel{thm:in-epilogue}{{E.1.1}{5}{}{thm.E.1.1}{}}

您可以看到倒数第二个条目中的超链接锚点名称将从 更改section.1.1section.E.1

您可以看到倒数第二个条目中的超链接锚点名称将从 更改thm.1.1.1thm.E.1.1

相关内容