In answering this question I came across an unusual feature of hyperref.
The issue is that sometimes the hyperlinks generated by hyperref and \pageref point back to the first page of the document rather than to the page that they are supposed to go to. Here is a MWE:
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\begin{document}
Page 1\newpage
Page 2\label{page2}\newpage
Page 3: Here is a link to \pageref{page2}
\end{document}
Clicking on the link on page 3 takes you back to page 1 rather than to page 2, even though the pdf file says that the link is on page 2. For the record, I note that the page numbers are in arabic (roman is known to cause problems) and I am using TeXLive 2014 and pdflatex.
Now this particular issue is known and is apparently NOT a bug because
label does not create an anchor so there is nothing to link to. Indeed, if I change my minimal working example to:
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\begin{document}
Page 1\newpage
\newcounter{acounter}\refstepcounter{acounter}
Page 2\label{page2}\newpage
Page 3: Here is a link to \pageref{page2}
\end{document}
The link on page 3 now correctly sends me back to page 2.
Interestingly, if instead I write
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\begin{document}
\newcounter{acounter}\refstepcounter{acounter}
Page 1\newpage
Page 2\label{page2}\newpage
Page 3: Here is a link to \pageref{page2}
\end{document}
then my hyperlink is again wrong as it sends me back to page 1. Arguably, as there is no anchor on the current page hyperref is justified in being confused. On the other hand, since latex does correctly produce the correct page number I think that hpyerref should produce correct hyperlinks in all of these cases.
So my question: what should hyperref do in these cases?
Judging from the link above, these are probably not bugs...personally, I wonder why \label doesn't create a hyperlink anchor.
\labelis not just after a stepped counter, no anchor is set;\phantomsection\label{...}in these cases should do. – egreg Jul 26 '14 at 15:41hyperrefanchor via\phantomsection. – Werner Jul 26 '14 at 15:42\refstepcounter? Wouldn't it make more sense for\labelto create it? If\refstepcountercreates the anchor but there is no subsequent\labelthen the anchor isn't needed...I'm just like to understand the logic here. – Jul 26 '14 at 15:47\labelmust go after a number is stepped, in order to know what number it should refer to. One might think to a\pagelabelcommand for this case; when LaTeX was released, hyperlinks did not exist. – egreg Jul 26 '14 at 15:55hyperrefif\labelwas used to place the anchor, since then you would typically find yourself jumping to the line below a section title rather than the title itself. This is the case with\captions (where the\refstepcounteroccurs), but luckily the structure of a float containing a\captionis somewhat predictable... andhypcapwas born). – Werner Jul 26 '14 at 16:04