[Tex/LaTex] hyperref bad references

babelcross-referencinghyperrefxetex

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)

Best Answer

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

\usepackage[hungarian]{babel}

is broken with respect to the interaction with hyperref.

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

/usr/local/texlive/2012/texmf-dist/doc/latex/magyar/magyar.ldf

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

~/texmf/tex/latex/magyar

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

Then call babel as

\def\magyarOptions{suggestions=no}
\usepackage[magyar]{babel}

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

\usepackage{polyglossia}
\setmainlanguage{magyar}
Related Question