# URL over two pages causes nested errors

I tried to generate a MWE where I can reproduce my main problem. The major error says

error:  (pdf backend): 'endlink' ended up in different nesting level than 'startlink'
!  ==> Fatal error occurred, no output PDF file produced!


Searching for solution and hints for this problem I figured out that it is related to URLs which are too long and are finally span two sides. Although the solution found works it has some other problems in the ongoing documents. The packages I've included are the ones I need for processing. We have long tables included - which not necessarily are required for a MWE. The MWE looks like:

\documentclass[a4paper,11pt]{book}
\usepackage[a4paper,includeheadfoot,margin=2.5cm,showframe]{geometry} % for margins on a A4paper
\usepackage{lipsum}
\usepackage{hyperref}
\def\UrlBreaks{\do\/\do-\do\_}
\usepackage{ltablex} % for tables with long lines & long tables (over >1 page)
\usepackage{tabularx}
\begin{document}
\section{Introduction}
\lipsum[1-5]
\begin{itemize}
%\interlinepenalty10000  % workaround ???
\item   Die Zeit (22.9.2016): Kabul schließt Friedensabkommen mit berüchtigtem
Milizenführer Hekmatjar,
\sloppy
\url{http://www.zeit.de/news/2016-09/22/afghanistan-kabul-schliesst-friedensabkommen-mit-beruechtigtem-milizenfuehrer-hekmatjar-22113008}
, Zugriff 5.10.2016
\item   Die Zeit (22.9.2016): Kabul schließt Friedensabkommen mit berüchtigtem
Milizenführer Hekmatjar,
\sloppy
\url{http://www.zeit.de/news/2016-09/22/afghanistan-kabul-schliesst-friedensabkommen-mit-beruechtigtem-milizenfuehrer-hekmatjar-22113008}
, Zugriff 5.10.2016
\end{itemize}

\section{New page}
\lipsum[7-8]
%   \newpage  % workaround ???
\begin{tabularx}{8cm}{|X|X|X|X|}
\hline
In dieser Tabelle & hat jede Zelle genau die & gleich Breite & nämlich gerade
2cm \\
\hline
Und wie man & dabei leicht erkennen kann & reicht diese Breite nicht bei allen
& Spalten aus um den gesamten Text darzustellen. \\
\hline
\end{tabularx}
\end{document}


I see as the root cause of the problem that the URL spans two pages. If I either take care that the item is one page or if I make a new page than the problem vanishes (marked with %workaround ???).

So my main question: How to solve the URL breaking in a better way? (To avoid nested problems).

## 1 Answer

The problem is not really the url over two pages. Normally this works quite fine. The problem is the longtable (hidden in the tabularx, ltablex redefines tabularx to use it). longtable redefines the output routine and adds a box, and this means that the first page has a smaller box level than the second. If one adds an additional box on the first page too the error goes away:

\documentclass[a4paper,11pt]{book}
\usepackage[a4paper,includeheadfoot,margin=2.5cm,showframe]{geometry} % for margins on a A4paper
\usepackage{lipsum}
\usepackage{hyperref}
\def\UrlBreaks{\do\/\do-\do\_}
\usepackage{ltablex} % for tables with long lines & long tables (over >1 page)
\usepackage{tabularx}

\AtBeginShipout{%
\ifnum\value{page}=1 % use e.g. zlabel/zref to get the relevant page number
\typeout{* Additional boxing of page \thepage'}%
\setbox\AtBeginShipoutBox=\hbox{\copy\AtBeginShipoutBox}%
\fi
}
\begin{document}
\section{Introduction}
\lipsum[1-5]
\begin{itemize}
%\interlinepenalty10000  % workaround ???
\item   Die Zeit (22.9.2016): Kabul schließt Friedensabkommen mit berüchtigtem
Milizenführer Hekmatjar,
\sloppy
\url{http://www.zeit.de/news/2016-09/22/afghanistan-kabul-schliesst-friedensabkommen-mit-beruechtigtem-milizenfuehrer-hekmatjar-22113008}
, Zugriff 5.10.2016
\item   Die Zeit (22.9.2016): Kabul schließt Friedensabkommen mit berüchtigtem
Milizenführer Hekmatjar,
\sloppy
\url{http://www.zeit.de/news/2016-09/22/afghanistan-kabul-schliesst-friedensabkommen-mit-beruechtigtem-milizenfuehrer-hekmatjar-22113008}
, Zugriff 5.10.2016
\end{itemize}

\section{New page}
\lipsum[7-8]
%   \newpage  % workaround ???
\begin{tabularx}{8cm}{|X|X|X|X|}
\hline
In dieser Tabelle & hat jede Zelle genau die & gleich Breite & nämlich gerade
2cm \\
\hline
Und wie man & dabei leicht erkennen kann & reicht diese Breite nicht bei allen
& Spalten aus um den gesamten Text darzustellen. \\
\hline
\end{tabularx}
\end{document}

• Yeah, I see that your solution fixes this issue. Since the output is somehow automatically generated I don't understand how to use your sample. To my understanding I should somehow set a \zref{MyLink1} in the table and than add them in the \AtBeginShipout. Or should I do this on every page? And how to handle multiple tables across different pages? – LeO Apr 16 at 9:00
• You need to add the additional box on the page before the longtable. I don't know if an automatic solution is possible, but you could check Heiko's answer here: tex.stackexchange.com/a/249743/2388. (The problem in this question is gone as latex changed the code, but yours if similar). You could also add an issue to the github of longtable, perhaps it can avoid the additional boxing. – Ulrike Fischer Apr 16 at 9:49
• Somehow I don't understand the solution. I understand could add a box and this might be related with longtable - but could be as well related with \url cause if you skip the table and you have only an url spanning two sides you see the showframe` highlights the whole frame of the second page differently. Anyway - filling a bug - I don't know where to start. Is it latex-project.org/bugs? – LeO Apr 17 at 6:13
• I will add a bug report. – Ulrike Fischer Apr 17 at 7:47