3

Hyperlinks to theorem-like environments that begin with a nested itemize or enumerate are often broken (see for example http://tex.stackexchange.com/a/187647). Here is a MWE:

\documentclass{amsart}

\usepackage{hyperref}

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
\label{bigthm}
\begin{itemize}
\item A claim.
\item Another claim.
\end{itemize}
\end{theorem}

Let's prove Theorem~\ref{bigthm}.

\end{document}

This produces a warning:

pdfTeX warning (dest): name{theorem.1} has been
referenced but does not exist, replaced by a fixed one

and the hyperlink doesn’t work.

(By the way, if we use article instead of amsart, then everything works as expected. What makes the AMS document class behave differently?)

One solution is to add \leavevmode right after \label{bigthm}:

\begin{theorem}
\label{bigthm}\leavevmode
\begin{itemize}[...]

This fixes the hyperlink, but of course it also changes the formatting, which I don’t want.

A better solution (thanks, Simon!), which does not change the formatting, is to add \phantomsection right before \label{bigthm}:

\begin{theorem}
\phantomsection\label{bigthm}
\begin{itemize}[...]

Now everything works. Great!

However, this better solution does not work with \autoref, alas:

Let's prove~\autoref{bigthm}.

now produces Let’s prove section 1. (albeit with a working hyperlink).

So my question is this: Is there a way to fix the hyperlink that works with \autoref without changing the formatting?

  • Just try \leavevmode\label{bigthm}, without \phantomsection –  Jun 02 '17 at 15:39
  • @ChristianHupfer But that changes the formatting. I don’t want to start a new line. – Marco Varisco Jun 02 '17 at 15:57
  • Without \leavevmode the first item starts on the line of header line of the environment, which looks very ugly –  Jun 02 '17 at 16:06
  • I know, but that’s exactly where I need the first item to start. I don’t particularly like it either, but the house styles of some publishers don’t allow line breaks right after theorem headers. – Marco Varisco Jun 02 '17 at 16:10

2 Answers2

2

A version with a \fakephantomsection, that uses \@currenvir, i.e. the current environment name in order to get the correct autoref name.

This is basically the same what \phantomsection does, but using the correct environment name.

The problem is known and mentioned in the documentation of amsart:

• Other problems inherent in amsthm.

◦ Hyperlinking the first item when a theorem begins with a list

\documentclass{amsart}



\usepackage{hyperref}
\newtheorem{theorem}{Theorem}

\makeatletter
\newcommand{\fakephantomsection}{%
  \Hy@MakeCurrentHref{\@currenvir.\the\Hy@linkcounter}
  \Hy@raisedlink{\hyper@anchorstart{\@currentHref}\hyper@anchorend}%
}
\makeatother



\begin{document}

\tableofcontents

\clearpage
\section{Foo}
\begin{theorem}
\fakephantomsection\label{bigthm}
\begin{itemize}
\item A claim.
\item Another claim.
\end{itemize}
\end{theorem}

Let's prove Theorem~\ref{bigthm} \autoref{bigthm}.

\end{document}

enter image description here

1

I am using this modification of the command proposed in the other answer:

\newcommand*{\fakephantomsection}{%
  \Hy@GlobalStepCount\Hy@linkcounter%
  \Hy@MakeCurrentHref{\@currenvir.\the\Hy@linkcounter}%
  \Hy@raisedlink{\hyper@anchorstart{\@currentHref}\hyper@anchorend}%
}