Tell me more ×
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

2 Answers

up vote 16 down vote accepted

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

\usepackage[hypertexnames=false]{hyperref}
share|improve this answer
2  
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

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

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.
http://tex.stackexchange.com/questions/6098/wrong-hyper-references-after-resetting-chapter-counter
tex.stackexchange.com
crawl=CC-MAIN-2013-20
46779
application/http; msgtype=response
sha1:YSKRPAKVWBFFESMYNKMJPTYA46UPALUN
<urn:uuid:caf3c587-fb91-4695-adb9-baf7bb990f1c>
2013-05-24T09:05:20Z
198.252.206.16
sha1:2WFJKWG6PFAUEUGHZUZBGK6UQQ75DTET
<urn:uuid:b684d471-588b-4055-a24b-162fe5b811bd>
http://tex.stackexchange.com/questions/6098/wrong-hyper-references-after-resetting-chapter-counter
response
<urn:uuid:2ee47d9a-a9cf-4b92-8398-874709d91d4a>
robots: classic
hostname: ip-10-60-113-184.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2013-20
operator: CommonCrawl Admin
description: Wide crawl of the web with URLs provided by Blekko for Spring 2013
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf