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?

4
  • Just try \leavevmode\label{bigthm}, without \phantomsection
    – user31729
    Jun 2, 2017 at 15:39
  • @ChristianHupfer But that changes the formatting. I don’t want to start a new line. Jun 2, 2017 at 15:57
  • Without \leavevmode the first item starts on the line of header line of the environment, which looks very ugly
    – user31729
    Jun 2, 2017 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. Jun 2, 2017 at 16:10

2 Answers 2

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

2
  • This is great. Thank you so much, Christian! And thanks also for answering my other parenthetical question. Jun 2, 2017 at 17:13
  • @MarcoVarisco: You're welcome. Happy TeXing!
    – user31729
    Jun 3, 2017 at 19:50
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}%
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .