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}
Werner
  • 603,163
Michael
  • 1,294
  • Your example works ok for me. Maybe you just need to update your TeX distribution. – Ian Thompson Jul 18 '12 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 '12 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). – Ian Thompson Jul 18 '12 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 '12 at 23:32
  • I've temporarily made the versions of hyperref and hobsub-hyperref from my machine available for download. – Ian Thompson Jul 18 '12 at 23:45
  • Thank you, Ian, but I run into a version mismatch. I need at least your version of hpdftex.def. Probably I should checkout the old version at the svn site of hyperref (https://puszcza.gnu.org.ua/svn/?group=hyperref) – Michael Jul 19 '12 at 00:02
  • I tested with old hyperref, but ran into the same error. But with your version of hobsub-hyperref, the example works. I think I contact Heiko Oberdiek. – Michael Jul 19 '12 at 15:11
  • 1
    With hyperref v6.82v the bug is fixed. – Michael Jul 30 '12 at 11:43
  • I can reproduce this problem with Tex Live 2012 on Debian wheezy. This is using 2012/05/13 v6.82q. – Faheem Mitha Jan 04 '14 at 18:57
  • I can reproduce this using 2017/03/14 v6.85a :( – Paul Crowley Jul 31 '18 at 18:26

3 Answers3

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.

Michael
  • 1,294
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}
David Carlisle
  • 757,742
  • 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 '12 at 23:19
  • Sorry about the last minute edit messing up the space delimiter. I added a second pass that splits on - – David Carlisle Jul 19 '12 at 08: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 '12 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.

kgr
  • 2,251
  • 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 '12 at 22:23
  • edited with a sort of solution...hopefully something more elegant will come along from someone else. – kgr Jul 18 '12 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 '12 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. – David Carlisle Jul 18 '12 at 22:58