After cleaning up my project and compiling a tex file 10 times in a row:

rm temp.toc temp.pdf temp.out temp.html temp.aux
xelatex temp.tex # executed 10 times!

I still get bad references with hyperref. In the table of contents, I see the hyperlinks. The page number in the TOC is good. But the reference points to a different page.

I cannot provide a minimal working example, because the problem only occurs with long documents. (There is no point in making a table of contents for a two page article at all.) Upon request, I can upload the whole document, but that might not be necessary.

UPDATE: The problem is still there. I have uploaded the complete example here: https://rapidshare.com/files/1197222879/output.zip - contains all tex files, aux files and the generated final pdf file. Engine is xelatex. I have executed the compilation 10 times but the hyperrefs are still wrong. In the table of contents, when you click on a link that says "page 25" then you are directed to page 23. In other words, the page numbers in the TOC are correct, but the hyperref references are incorrect.

UPDATE: This is a bug. If I use \usepackage[hungarian]{babel} and \usepackage{hyperref} together, them the references are wrong. If I remove hungarian babel, then references become good (but then hypenation is wrong, and paragraphs look awful)

  • 1
    How are you setting the bookmark to the references? Please, add only that small part, mentioning the class you're using.
    – egreg
    Oct 5, 2012 at 12:38
  • I do not explicitly add any references. I'm just creating some tables, adding some footnotes and using sections and subsections. E.g. there are no named anchors at all. The document is the basic "article" class: \documentclass[a4paper,11pt]{article} and I have \usepackage{hyperref} just right before \begin{document}.
    – nagylzs
    Oct 5, 2012 at 14:03
  • 1
    What are the "wrong references" you mention? To what do they refer?
    – egreg
    Oct 5, 2012 at 14:23
  • For example, the "table of contents" has a link to a page. It says that it is on page 8. But the link brings me to page 6. Page 8 is correct.
    – nagylzs
    Oct 5, 2012 at 14:29
  • I'm on a Linux box now. I'm going to try this with the windows version too. Within 2 hours.
    – nagylzs
    Oct 5, 2012 at 14:32

3 Answers 3


The main problem in your case is that the current version of magyar.ldf which is loaded with


is broken with respect to the interaction with hyperref.

There is a different version available on TeX Live systems, located in


You can copy it in the working directory or in a folder


(~/Library/texmf/tex/latex/magyar/ with MacTeX on Mac OS X) that you need to create.

Then call babel as


The first line is just to avoid spurious and almost meaningless messages.

It's not the official version of magyar.ldf, but it seems to work.

On the other hand, the Polyglossia module for Hungarian seems to work, so you can consider, when using XeLaTeX, to call

  • On windows: texlive\2012\texmf-dist\doc\latex\magyar\magyar.ldf
    – nagylzs
    Oct 8, 2012 at 16:44

Ninety percent (more ore less) are covered by this kind of example (that is already the cure):

\cleardoublepage % new page to move the anchor to the right page
\phantomsection % anchor setting
\addcontensline{toc}{section}{\indexname}% bookmark with latest anchor

Of course, you have adopt it to your needs, chapter instead of section, bibliography instead of index, …

Adopting to the table of contents:


Or without adding the table of contents to the table of contents, but to the bookmarks only:

\pdfbookmark[1]{\contentsname}{toc}% for section level
% \pdfbookmark[0]{\contentsname}{toc}% for chapter level
  • I'm not using any of these. In fact I dont know what they mean. Where should I put them?
    – nagylzs
    Oct 5, 2012 at 14:05
  • 2
    At least I have tried an answer without knowing what you are doing, which class you are using, which bookmarks have wrong links, which versions you are using, ... Oct 5, 2012 at 15:01
  • Reading your comment about the table of contents, it looks that I am correct. Oct 5, 2012 at 15:03
  • Okay, then where should I put these lines? Is it before \begin{document} or after? ` ! Undefined control sequence. l.21 \addcontensline {toc}{section}{\indexname}% bookmark with latest anchor `
    – nagylzs
    Oct 5, 2012 at 15:05
  • After \begin{docment}. Oct 5, 2012 at 15:06

There is a workaround using the official magyar.ldf, just include the following macro (which I got from an old Debian teTex mailing list) in your preamble.

      \expandafter[\expandafter 5\expandafter]\expandafter{%
      \expandafter #\expandafter 5\expandafter
    \ifnum #3>\c@secnumdepth
    \ifnum #3>\c@secnumdepth

Source: Bug#306586: hyperref: nests bookmarks incorrectly

  • if magyar is redefining large chunks of latex, its size (246164 byte) isn't quite so surprising. fwiw, the previous maintainer of babel refused to work with it -- almost no useful comments. (the new maintainer has more than enough bug reports without even touching magyar ... unless someone else takes it in hand, i suspect it will stay in this broken state for ever.) Oct 26, 2012 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .