Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
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 '12 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 '12 at 14:03
1  
What are the "wrong references" you mention? To what do they refer? –  egreg Oct 5 '12 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 '12 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 '12 at 14:32
add comment

3 Answers

up vote 4 down vote accepted

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}
share|improve this answer
    
On windows: texlive\2012\texmf-dist\doc\latex\magyar\magyar.ldf –  nagylzs Oct 8 '12 at 16:44
add comment

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
\printindex

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

Adopting to the table of contents:

\cleardoublepage
\phantomsection
\addcontentsline{toc}{section}{\contentsname}%
\tableofcontents

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

\cleardoublepage
\pdfbookmark[1]{\contentsname}{toc}% for section level
% \pdfbookmark[0]{\contentsname}{toc}% for chapter level
\tableofcontents
share|improve this answer
    
I'm not using any of these. In fact I dont know what they mean. Where should I put them? –  nagylzs Oct 5 '12 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, ... –  Heiko Oberdiek Oct 5 '12 at 15:01
    
Reading your comment about the table of contents, it looks that I am correct. –  Heiko Oberdiek Oct 5 '12 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 '12 at 15:05
    
After \begin{docment}. –  Heiko Oberdiek Oct 5 '12 at 15:06
show 1 more comment

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.

\makeatletter
\let\Hy@magyar@saved@refstepcounter\refstepcounter
\addto\extrasmagyar{%
  \let\H@refstepcounter\refstepcounter
  \let\refstepcounter\Hy@magyar@saved@refstepcounter
  \expandafter\renewcommand\expandafter*\expandafter\@ssect
      \expandafter[\expandafter 5\expandafter]\expandafter{%
    \expandafter\def\expandafter\@currentlabelname\expandafter{%
      \expandafter #\expandafter 5\expandafter
    }%
    \@ssect{#1}{#2}{#3}{#4}{#5}%
    \phantomsection
  }%
  \expandafter\Hy@magyar@patch@sect\expandafter{%
    \@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{#8}%
  }{#1#2#3#4#5#6[#7]#8}{#2}{#7}%
}
\def\Hy@magyar@patch@sect#1#2#3#4{%
  \def\@sect#2{%
    \setcounter{section@level}{#3}%
    \def\@currentlabelname{#4}%
    \ifnum #3>\c@secnumdepth
      \Hy@GlobalStepCount\Hy@linkcounter
      \xdef\@currentHref{section*.\the\Hy@linkcounter}%
    \fi
    #1%
    \ifnum #3>\c@secnumdepth
      \Hy@raisedlink{\hyper@anchorstart{\@currentHref}\hyper@anchorend}%
    \fi
  }%
}
\makeatother

Source: Bug#306586: hyperref: nests bookmarks incorrectly

share|improve this answer
    
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.) –  wasteofspace Oct 26 '12 at 9:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.