1

A colleague has just pointed out to me that all of my hyperlinks to theorems and sections within the epilogue of this book:

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

point to the corresponding sections in the penultimate Chapter 6, despite the fact that the internal labels are unambiguous. Presumably the issue is in the way I reset the counter for the Epilogue. Here is a minimal working example:

\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}

When you compile as a PDF, the references to the Chapter and the Epilogue Chapter are correct, but the references to the theorems and sections all point within Chapter 1.

Any idea how I might fix this? Since the PDF corresponds to a published book, I'd prefer to fix the hyperlinks without changing the appearance of the labels in a printed copy.

UPDATE: As Teepeemm points out below, my current code produces an aux file that looks like this (excerpted):

    \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}{}}

With Teepeemm's suggestion to add "\let\theHsection=\thesection" the last two lines of the aux file update to:

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

This fixes the links in the minimum working example but doesn't fix the hyperlinks in the actual book.

It gives a unique identifier to the hyperlink to the epilogue chapter but the epilogue sections and theorems are still assigned duplicates of numbers from chapter 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}{}}

Could you suggest the more complicated solution you were alluding to? It seems I might need it here.

  • 1
    My guess is that the extra sections in your epilog are causing the problem, but I'm having trouble creating an example where my \let fails. Does changing the \let to \renewcommand{\theHsection}{epilog.\thesection} fix things? – Teepeemm Oct 26 '18 at 21:53
  • It turns out the \let is fine. I just needed to add "\let\theHsection=\thesection" right after redefining \thesection as opposed to right before, which is what I tried initially. Thanks! I'd be happy to credit you by name in the online version of the book, if you'd like? Just let me know (here or via email: eriehl@math.jhu.edu) how you'd like to be identified. – Emily Riehl Oct 31 '18 at 13:05
  • I appreciate the sentiment, but since my attempt didn't actually solve your problem correctly, I'll pass on the acknowledgement. – Teepeemm Nov 02 '18 at 02:48

1 Answers1

2

When compiling your MWE without modifications, the labels in the .aux-files will be:

\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}{}}

You can see that the second entry and the last but one entry both make use of the same anchor-name for hyperlinking which is: section.1.1.

You can see that the third entry and the last entry both make use of the same anchor-name for hyperlinking which is: thm.1.1.1.

When compiling your MWE without modifications, the . log-file contains the following warnings:

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

Be aware that applying sectioning-commands like \chapter or \section or \begin{theorem} causes the hyperref-package to automatically place anchors/targets for hyperlinking to the corresponding sectioning-headings. Automatically placing an anchor includes automatically creating a name for that anchor.
Whenever the hyperref-package creates a new anchor automatically, it will save the name of that anchor in the macro \@currentHref. When placing a \label, the \label-macro in turn will rely on the expansion of \@currentHref for obtaining the name of the anchor created as the last one and writing that anchor-name into the aux-file's \newlabel-entry.

For unambiguously denoting anchors when creating hyperlinks, each anchor needs an unique name which identifies only that anchor.

The reason for the .log-file-warnings is that setting values of count-registers for sectioning-commands to former values does lead to names of automatically created anchors for hyperlinks not being unique any more.

Names of automatically created anchors come from these \theH...-macros.

Therefore when setting sectioning-counters to former values you need to make sure that the corresponding \theH...-macros get redefined in a way where uniqueness of anchor-names remains ensured.

I suggest doing something like:

\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 

The MWE will become something like:

\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}

The labels in the .aux-files will now be:

\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}{}}

You can see that the anchor-name for hyperlinking within the last but one entry will change from section.1.1 to section.E.1.

You can see that the anchor-name for hyperlinking within the last but one entry will change from thm.1.1.1 to thm.E.1.1.

Ulrich Diez
  • 28,770
  • Thanks this worked perfectly. I'd be happy to credit you by name in the online version of the book, if you wouldn't mind? – Emily Riehl Oct 31 '18 at 13:06
  • @EmilyRiehl Thank you very much for your kind words and for accepting my answer. Being credited for this would be somewhat similar to someone being credited by a marathon-running champion for chattering about one aspect of one way of tying shoes. :-) I did not implement any of the means and things used by you for creating your book. I just tried to give some info about how to use one them (i.e., the hyperref-package). Every experienced user of the hyperref-package could have done that. Therefore I don't see a need for being credited. I do explicitly wish to be not credited for this. :-) – Ulrich Diez Oct 31 '18 at 20:14
  • Understood. I'll honor your request. But as a totally-naive user of the hyperref package I'm extremely grateful that you took the time to share your expertise (and explain in a way that I could understand). So thanks again. – Emily Riehl Oct 31 '18 at 22:33
  • @EmilyRiehl In case you foresee being faced with struggling with LaTeX 2e's cross-referencing-mechanism ore often: In July 2016 a discussion "How to prevent reference to enumeration inside new environment?" took place where I tried to elaborate in more detail on how cross-referencing works in LaTeX2e. By the way: I like the book you linked in your question. ;-) – Ulrich Diez Nov 01 '18 at 17:05