Generalhyperref internal link to wrong page

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
JeffR
Posts: 9
Joined: Thu Aug 29, 2013 6:39 pm

hyperref internal link to wrong page

Post by JeffR »

Hello. I am writing long lecture notes in LaTeX, and sometimes modifying the subsection and equation counters myself. It works great, except that occasionally the resulting pdf file's hyperref internal links mysteriously go to the wrong page. I have managed to untangle the problem into a minimal example, which follows. In this case, after compiling the code with pdflatex, the link to 1.1.1 on the page 1 should jump to page 3, but instead it jumps to page 2. Why?? I'm hoping there is a simple fix for this. Thank you!

Code: Select all

\documentclass[12pt]{article}
\usepackage{hyperref}
\renewcommand{\theequation}{\thesubsection.\arabic{equation}}
\begin{document}

Start Section~1, Subsection~1:
\stepcounter{section}

To square $x$, see: \ref{xsquared}.

\vfil\eject

Another equation is:
\begin{equation}
1+1=2
\end{equation}

Start Subsection~2, with reset equation numbers:
\stepcounter{subsection}
\setcounter{equation}{0}

(Some text.)

\vfil\eject

The square of $x$ is:
\begin{equation}\label{xsquared}
x^2
\end{equation}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

hyperref internal link to wrong page

Post by Stefan Kottwitz »

Hi Jeff!

By default, hyperref creates internal links based on the counters. When counters are changed, the names may not be properly distinguishable internally.

Disabling that by setting the hypertexnames option to false can fix it - it works with the example:

\usepackage[hypertexnames=false]{hyperref}

Stefan
LaTeX.org admin
JeffR
Posts: 9
Joined: Thu Aug 29, 2013 6:39 pm

hyperref internal link to wrong page

Post by JeffR »

Yes, that seems to fix it -- in my long notes file too. Woo hoo! Thank you so much!
Stefan Kottwitz wrote:Hi Jeff!

By default, hyperref creates internal links based on the counters. When counters are changed, the names may not be properly distinguishable internally.

Disabling that by setting the hypertexnames option to false can fix it - it works with the example:

\usepackage[hypertexnames=false]{hyperref}

Stefan
JeffR
Posts: 9
Joined: Thu Aug 29, 2013 6:39 pm

hyperref internal link to wrong page

Post by JeffR »

Hi again Stefan. Your solution is working great to fix up the equation hyperlinks -- thanks again! But I just discovered that it created a new problem, with the *index* hyperlinks. Specifically, my document has 11 pages of preamble (Preface etc) numbered with roman numerals, before beginning the main text on a fresh page 1 (arabic). With the hypertexnames=false option, the Index still lists the pages correctly, but the hyperlinks from the Index now take me to 11 pages earlier (e.g. a page 57 link in the index takes me to page 46). Everything else seems correct, aside from the Index hyperlinks. I see that this problem was already discussed somewhat at https://tex.stackexchange.com/questions ... rrect-page and https://stackoverflow.com/questions/145 ... f-the-page but none of their proposed hyperref options (plainpages=false,pdfpagelabels,pagebackref) seems to help. I haven't yet tried to make a minimal example, but I was wondering if you happen to know some other option to hyperref that would make this problem go away (while still allowing me to keep hypertexnames=false to fix that other problem). Thanks a lot!
uudruid74
Posts: 6
Joined: Fri Jun 20, 2014 3:54 am

hyperref internal link to wrong page

Post by uudruid74 »

Stefan Kottwitz wrote:Hi Jeff!

By default, hyperref creates internal links based on the counters. When counters are changed, the names may not be properly distinguishable internally.

Disabling that by setting the hypertexnames option to false can fix it - it works with the example:

\usepackage[hypertexnames=false]{hyperref}

Stefan
OMG. I had been trying to solve this forever. I'm using LyX so all the appendix stuff and PDF support is all in the GUI, the TOC is fine, but the PDF has page numbers for the first chapters where the appendicies should be! No idea how the TOC numbers and PDF numbers are different no searches anywhere told me what was going on. Turning off the built-in hyperref support fixes it, but puts huge red boxes all over my TOC. I ended putting hyperref on with the options I wanted, cut the section out of the TEX file it generated and then pasting that into the LyX preamble adding hypertexnames=false to the list of options and it works perfectly!! Thank you so much!!!
Post Reply