Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I process the file below either with pdflatex, or with latex and then dvipdf, the link on page 1 of the resulting PDF file does not take me to Lemma 1 as expected.

\documentclass{amsart}

\usepackage{hyperref}
\newtheorem{lem}{Lemma}

\begin{document}

See Lemma~\ref{testlemma} below.
\pagebreak

\begin{lem}\label{testlemma}
  \begin{enumerate}
  \item Testing!
  \end{enumerate}
\end{lem}

\end{document}

When I use pdflatex then I get a warning:

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

If I replace \documentclass{amsart} with \documentclass{article} then the link works as expected.

How can I fix this test file to get working hyperref links in PDF files with amsart?

I am using pdfTeX 3.1415926-1.40.10-2.2 (TeX Live 2009/Debian).

share|improve this question
    
Welcome to TeX.SX! –  Heiko Oberdiek Mar 21 at 18:52
    
The same happens if the class is article and amsthm is loaded before hyperref. –  egreg Mar 21 at 18:55

2 Answers 2

up vote 5 down vote accepted

for the reference counter of a theorem-class environment to be properly accessed by a \label, something has to follow the \begin{<environment>} in horizontal mode. since the next thing in this example is \begin{enumerate}, horizontal mode is never entered, and the label is lost. (i'm not sure exactly how it gets lost, but that's the net effect.)

there are various approaches to handling this situation. all involve inserting something in horizontal mode before starting the list. the suggestions most often made (other than adding actual text) are \leavevmode or $ $; even a single "slash-space" will work. however, all of these will result in the list being started on the next line rather than being run-in.

here are two other questions that address related situations, although not the interaction with \label:

here's a somewhat different approach that involves entering the number of the first item manually, and starting the "real" enumeration with the second item; it's applied to a proof in this answer, but works as well with any theorem-class object. advantage -- this allows a label intended to point to the theorem to have the correct value; disadvantage -- it may not be possible to have a cross-reference to the first item.

share|improve this answer
    
Following this, I tried putting the \label command after the first \item. The link works, but the item number (not the lemma number) becomes the link. –  Dan Mar 21 at 19:58
    
@Dan - Which object do you wish to cross-reference: The entire lemma, or a specific enumerated item within the lemma? You can assign a \label to both the lemma and to individual enumerated items. –  Mico Mar 21 at 23:15

Adding \leavevmode before the enumerate environment fixes the issue.

\documentclass{amsart}
\newtheorem{lem}{Lemma}

\usepackage{hyperref}

\begin{document}

\section{test}\label{sec:1}

See Lemma~\ref{testlemma} or rather Lemma~\ref{testlemma2} below.

\begin{lem}
\label{testlemma}
  \begin{enumerate}
  \item Testing!
  \end{enumerate}
\end{lem}

\begin{lem}
\label{testlemma2}
\leavevmode
  \begin{enumerate}
  \item Testing!
  \end{enumerate}
\end{lem}

\begin{lem}
\label{testlemma3}
\leavevmode  
  \begin{enumerate}
  \item Testing!
  \end{enumerate}
\end{lem}

lemma \ref{testlemma2}

section \ref{sec:1}

lemma \ref{testlemma3}

reference to lemma \ref{testlemma} does not work.
\end{document}
share|improve this answer
    
or any text which will start paragraph mode. –  jfbu Mar 21 at 19:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.