33

I ran into the "mysterious"

\pdfendlink ended up in different nesting level than \pdfstartlink

error. According to http://www.tug.org/errors, "this happens when hyperref is used under pdftex and a citation splits across a page boundary". The given solution is to manual fix the citation to not split across the page boundary.

However, this workaround isn't feasible for me, as the documents are automatically generated on a server with no user interaction.

Is there any solution to the problem known, perhaps an experimental hyperref action or a patch to pdftex? (Probably, one could use luatex to solve the problem, but for other reasons, luatex is not an option in this project.)

MWE:

\documentclass[%draft
              ]{article}
\usepackage{hyperref}
\setlength{\textwidth}{3cm}
\setlength{\textheight}{3cm}

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna
\href{http://www.tug.org/errors}{aliquyam erat, sed diam voluptua.}
\end{document}
10
  • Your example works ok for me. Maybe you just need to update your TeX distribution. Jul 18, 2012 at 21:58
  • @Ian Thompson: I use latest TeXLive 2011 with pdfTeX 3.1415926-2.3-1.40.12 (TeX Live 2011), hyperref 2012/02/28 v6.82p Hypertext links for LaTeX, hobsub-hyperref 2012/04/25 v1.12 Bundle oberdiek. Which versions do you have?
    – Michael
    Jul 18, 2012 at 22:07
  • My pdfTeX version is the same, but it turns out that my packages are older (hyperref 2011/04/17 v6.82g, hobsub-hyperref 2011/04/23 v1.4). Jul 18, 2012 at 22:37
  • Interesting. So this might be a bug in hyperref? I made a test with TL 2012 (pdfTeX 3.1415926-2.4-1.40.13, hyperref 2012/05/13 v6.82q, hobsub-hyperref 2012/05/28 v1.13), but I continue to get the error.
    – Michael
    Jul 18, 2012 at 23:32
  • 1
    With hyperref v6.82v the bug is fixed.
    – Michael
    Jul 30, 2012 at 11:43

3 Answers 3

7

According to Heiko Oberdiek, the bug was introduced with a change to atbegshi. With hyperref v6.82r, it should be fixed. I tested with v6.82v (which hit texlive 2012 today) and the MWE runs properly without error.

5
  • 7
    I have the latest version of hyperref from TeX Live (6.83m) and stil encounter this error. Feb 15, 2013 at 12:39
  • Do you a reference for this? I have hyperref v6.82q. Jan 4, 2014 at 18:51
  • 1
    Upgrading to the current v6.83m fixes the problem for me. Thanks very much. Jan 4, 2014 at 19:03
  • @Michael Don't forget to accept your own answer if it is the one that worked for you. Also, would you mind expanding the steps you followed to upgrade hyperref?
    – Gabriel
    Aug 6, 2014 at 14:36
  • 10
    BTW I can confirm this is still present in version 6.83m of hyperref .
    – Gabriel
    Sep 1, 2014 at 19:00
5

The following splits the argument on spaces and then on explicit hyphens and makes each word an unbreakable link, but allowing breaks between links.

 \documentclass[%draft
              ]{article}
\usepackage{hyperref}
\setlength{\textwidth}{3cm}
\setlength{\textheight}{3cm}

\def\linkspace#1#2{\leavevmode
\def\tmp##1{\nolinebreak[2]\href{#1}{\hbox{##1}}}%
\xlinkspace#2 \relax}

\def\xlinkspace#1 #2{%
 \ifx\relax#2%
 \xlinkdash#1-\relax
 \else
 \xlinkdash#1 -\relax
 \expandafter\xlinkspace\expandafter#2%
 \fi}

\def\xlinkdash#1-#2{%
 \ifx\relax#2%
 \tmp{#1}%
 \else
 \tmp{#1-}%
 \expandafter\xlinkdash\expandafter#2%
 \fi}

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna
\linkspace{http://www.tug.org/errors}{aliquyam erat, sed diam vol-uptua.  Cons-etetur sadi-pscing elitr,}%

\end{document}
3
  • Thank, you @david-carlisle. However, your example doesn't work as it is. Apparently, line 9 must read \xlinkspace#2 \relax}, and line 11 \def\xlinkspace#1 #2{% (the space is important, to break the linktext into words). Do you have any idea how to break not only at spaces, but at hyphens, too (so "that very-long-compound-word" would be breaken)?
    – Michael
    Jul 18, 2012 at 23:19
  • Sorry about the last minute edit messing up the space delimiter. I added a second pass that splits on - Jul 19, 2012 at 8:31
  • Thank you for the code. I don't mark my question as answered yet, as I think the error was introduced with a recent version of hobsub. I wrote a mail to Heiko Oberdiek.
    – Michael
    Jul 19, 2012 at 15:23
1

You can try putting the link in an \mbox, (edit: was originally \hbox) and generate overfull hbox warnings instead. The following compiles for me (and I do get the error on your minimal example). Depending on the circumstances this could look fairly ugly.

\documentclass[%draft
              ]{article}
\usepackage{hyperref}
\setlength{\textwidth}{3cm}
\setlength{\textheight}{3cm}

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna
\mbox{\href{http://www.tug.org/errors}{aliquyam erat, sed diam voluptua.}}
\end{document}

Edit (following comment about multicolumn): given that this is automatically generated, a very hacky workaround might be to do something like the following:

\mbox{\href{http://www.tug.org/errors}{aliquyam}} 
\mbox{\href{http://www.tug.org/errors}{erat,}}
\mbox{\href{http://www.tug.org/errors}{sed}} 
\mbox{\href{http://www.tug.org/errors}{diam}}
\mbox{\href{http://www.tug.org/errors}{voluptua.}}

Then hopefully the overfull boxes wouldn't be so prevalent / ugly. It doesn't look terrible in your test case, at least. Also, the links in this hack look much better with the colorlinks option to hyperref.

4
  • The text is typeset in multicolumns, so this would make nearly every document quite ugly (even the vast majority, which compile fine). So this is not an option to me. :(
    – Michael
    Jul 18, 2012 at 22:23
  • edited with a sort of solution...hopefully something more elegant will come along from someone else.
    – kgr
    Jul 18, 2012 at 22:37
  • The \hbox/\mbox solution might be a workaround. Unfortunately, the texts are in german, which has a lot of very long words. But maybe I can check if the compilation process fails, and only then break up the \href.
    – Michael
    Jul 18, 2012 at 22:47
  • 1
    \mbox (or at least \leavevmode) would be required rather than \hbox if there is any possibility of the link being the first thing in the paragraph, as a sequence of hboxes would be stacked vertically not horizontally in vmode. Jul 18, 2012 at 22:58

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