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.

I'm using the hyperref package in LaTeX. In the compiled PDF, in the table of contents (TOC), I correctly get all the links to the corresponding chapters and sections.

There is only one chapter which I typed as

\chapter{Proof of Theorem \ref{thm:myTHM}}

that does not produce a working link. The problem is that also the reference to the Theorem (thm:myTHM) produces a link. In the TOC only the link to the theorem is working when I click on the number produce by \ref{thm:myTHM}.

Is there a way to produce a working link to the chapter even if I have a \ref{} in the chapter title? It would be nice to have both links working, i.e. If I click e.g. on "Proof of Theorem " I should jump to the chapter and if I click on the number produced by \ref{thm:myTHM} I should jump to the theorem from the TOC.

share|improve this question
2  
usually, \ref in a chapter or other title needs to be preceded by \protect for other reasons (e.g. correct running heads), because those headings are moving arguments. perhaps adding \protect would solve this problem as well. –  barbara beeton Nov 27 '12 at 14:35

2 Answers 2

up vote 4 down vote accepted

One possibility is to make use of the optional argument for \chapter and of the starred form of \ref already explained by Heiko:

\chapter[Proof of Theorem \ref*{thm:myTHM}]{Proof of Theorem \ref{thm:myTHM}}

In this way in TOC the chapter link will function then, and in TOC and page headings there is no link to your theorem, but still in the chapter title.

Therefore I would suggest to only use the starred form in \chapter exactly as Heiko showed you. Once again:

\chapter{Proof of Theorem \ref*{thm:myTHM}}

And then you add as first sentence some words like Here I will show the proof of theorem \ref{thm:myTHM}.


To treat this more general:

All sectioning commands have this structure \sectioning[optional argument]{mandatory argument}. As Barbara wrote in her comment, fragile commands like \ref in running heads (shown in TOC and page headers) need to be protected with – you name it – \protect or replaced by a robust variant like \ref*. If only the mandatory argument is given, this one is used for running heads, otherwise the optional argument. In the latter case the mandatory argument is only used for title setting in text.

And just for information: The advanced classes from KOMA-Script bundle and memoir provide more opportunities for setting of headers in TOC and pages.

share|improve this answer
    
\chapter[Proof of Theorem \ref*{thm:myTHM}]{Proof of Theorem \ref{thm:myTHM}}. Thanks, for me it is okay to only have a working link to the theorem in the chapter title as long as the TOC links me too the proof. –  Thomas Nov 28 '12 at 11:28

hyperref also defines a star form for \ref that does not add a link:

\chapter{Proof of Theorem \ref*{thm:myTHM}}

The opposite case with nested links depends on the driver:

  • pdfTeX (hpdftex.def): works.
  • dvips (pdfmark.def): wrong link areas.
  • XeTeX (hxetex.def): Nested links are not supported by XeTeX/(x)dvipdfm(x).
share|improve this answer
1  
I think it's the opposite of what the OP is trying to achieve. –  T. Verron Nov 27 '12 at 13:37

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.