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?
hyperrefderives internal link identifiers based on chapter numbers. However, when using different sections, there are two chapters with number 1. So by makinghyperrefdumber, we force it to adopt internal consecutive identifiers, rather than identifiers that map to actual chapter numbering. – Konrad Rudolph Nov 01 '15 at 16:49