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.

The following MWE produces a PDF whose TOC has two entries: “Foo” and “Bar” with correct page numbers. So far, so good. However, upon clicking on the link to “Bar”, I am taken to the page for “Foo” instead.

\documentclass{report}
\usepackage{hyperref}
\newcommand*\backmatter{\setcounter{chapter}{0}}

\begin{document}
\tableofcontents
\chapter{Foo}
\backmatter
\chapter{Bar}
\end{document}

(Produced with pdflatex, run twice.)

This MWE is whittled down from a (much!) more complex document but the above does seem to reproduce the error reliably.

Re-setting the chapter count seems to confuse hyperref, even though the page references are still accurate. Notice that in my real document, \backmatter does other things, including setting the numbering style to alphabetical so there’s no chance of confusion even though both chapters are ostensibly labelled as “Chapter 1”.

How do I fix this? Is this a bug? Are there workarounds?

share|improve this question
add comment

2 Answers

up vote 22 down vote accepted

Hyperref is just too clever sometimes. Make it dumber, and hence more robust:

\usepackage[hypertexnames=false]{hyperref}
share|improve this answer
3  
Wow, this actually works, and makes sense. But it’s not guessable from the documentation’s description of the option. Documentation fail. :-( –  Konrad Rudolph Nov 28 '10 at 18:01
    
This helped me with hyperref getting its PDF bookmarks all tangled up because I was resetting chapter numbering in my book parts. +1! –  DevSolar Sep 21 '11 at 15:46
    
+1 well deserved! Got my problem in scientific workplace fixed where my hiërarchy got totally messed up. –  Nick Nov 8 '13 at 15:48
add comment

You have two chapter 1. Naturally this confuse hyperref. You must give the internal counter a unique "look". E.g.:

\documentclass{report}
\usepackage{hyperref}
\newcommand*\backmatter{%
 \setcounter{chapter}{0}%
 \renewcommand\theHchapter{back.\arabic{chapter}}}

\begin{document}
\tableofcontents
\chapter{Foo}
\backmatter
\chapter{Bar}
\end{document}
share|improve this answer
    
Naturally. ;-) But I did originally set \thechapter without effect. And \theHchapter doesn’t even appear in the documentation (nor does any other occurrence of ‘theH’, according to grep). –  Konrad Rudolph Nov 28 '10 at 17:54
add comment

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.