![当前版本的 hyperref 出现“\pdfendlink 最终与 \pdfstartlink 处于不同的嵌套级别”错误](https://linux22.com/image/313049/%E5%BD%93%E5%89%8D%E7%89%88%E6%9C%AC%E7%9A%84%20hyperref%20%E5%87%BA%E7%8E%B0%E2%80%9C%5Cpdfendlink%20%E6%9C%80%E7%BB%88%E4%B8%8E%20%5Cpdfstartlink%20%E5%A4%84%E4%BA%8E%E4%B8%8D%E5%90%8C%E7%9A%84%E5%B5%8C%E5%A5%97%E7%BA%A7%E5%88%AB%E2%80%9D%E9%94%99%E8%AF%AF.png)
我正在经历超链接链接分裂问题描述以前的 问题。我尝试更新超链接包装推荐以及奥伯迪克包中似乎也有一些超链接-相关文件。
我的hyperref.sty
现在版本是 v6.83m,hobsub-hyperref.sty
版本是 v1.13。@Michael 的问题中的 MWE编译没有问题,但我的文档仍然产生相同的错误。我的 documentclass 是elsarticle
(版本 1.2.0)。
以下内容足以产生该问题:
\documentclass[5p]{elsarticle}
\usepackage{kantlipsum}
\usepackage{hyperref}
\begin{document}
\begin{frontmatter}
\end{frontmatter}
\kant*[1-4]
\kant[5]
\href{http://tex.stackexchange.com}{This is a very very
very very very very very very very very very very very very very
very very very very very very very very long link.}
\end{document}
选项5p
和frontmatter
似乎都是必需的,尽管后者可能是空的。
答案1
MWE 是一个很好的起点。从那里我可以进一步简化它。frontmatter
在 的可选参数中设置标题\twocolumn
。这样\twocolumn[]
就足够了。文本可以用垂直空格替换。类可以用标准article
类替换。
梅威瑟:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\twocolumn[]
\null\vfill\newpage
\null\kern.95\textheight
\href{http://tex.stackexchange.com}{This is a very very
very very very very very very very very very very very very very
very very very very very very very very long link.}
\end{document}
如果\twocolumn
使用可选参数调用,则\@topnewpage
调用宏,将可选参数的内容放入页面顶部的双列浮点对象中。因此,以下操作也会触发问题,而不是\twocolumn[]
:
\twocolumn
\begin{figure*}\end{figure*}
在输出例程的稍后时间,宏\@combinedblfloats
将顶部双浮点对象与正常页面内容结合起来:
\setbox\@outputbox \vbox to\textheight{%
\unvbox\@tempboxa
\vskip-\dblfloatsep
\ifnum \@dbltopnum>\m@ne
\dblfigrule
\fi
\vskip \dbltextfloatsep
\box\@outputbox
}%
可以看出,\@outputbox
又被一个附加的 框住了\vbox
。因此,与没有双浮点对象的第二页相比,链接第一部分的框层高了一个。
下列解决方法增加除第一页之外的装箱等级:
\documentclass{article}
\usepackage{hyperref}
\AtBeginShipout{%
\ifnum\value{page}>1 %
\typeout{* Additional boxing of page `\thepage'}%
\setbox\AtBeginShipoutBox=\hbox{\copy\AtBeginShipoutBox}%
\fi
}
\begin{document}
\twocolumn[]
\null\vfill\newpage
\null\kern.95\textheight
\href{http://tex.stackexchange.com}{This is a very very
very very very very very very very very very very very very very
very very very very very very very very long link.}
\end{document}
该解决方法也适用于问题的原始 MWE。在实际文档中,要知道哪些页面需要多少个额外的框级别并不是一件容易的事。
一种手动方式是使用下面的代码片段,前两行相当早,甚至在之前\documentclass
,其余部分应该稍后执行,这里通过\AtBeginDocument
。
\RequirePackage{atbegshi}
\AtBeginShipoutInit
\AtBeginDocument{%
\AtBeginShipout{%
\begingroup
\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen
\tracingonline=1 %
\edef\restoreinteractionmode{\interactionmode=\the\interactionmode}%
\nonstopmode
\showbox\AtBeginShipoutBox
\restoreinteractionmode
\endgroup
}%
}
然后可以分析输出页面的框列表,以识别链接的开始部分和下一页的结束部分。然后需要比较行开头的点数。
下一个示例尝试一种更自动化的解决方案:
\documentclass[5p]{elsarticle}
\usepackage{kantlipsum}
\usepackage{hyperref}
\usepackage{etoolbox}
\makeatletter
\newcount\c@additionalboxlevel
\setcounter{additionalboxlevel}{0}
\newcount\c@maxboxlevel
\setcounter{maxboxlevel}{1}
\patchcmd\@combinedblfloats{\box\@outputbox}{%
\stepcounter{additionalboxlevel}%
\box\@outputbox
}{}{\errmessage{\noexpand\@combinedblfloats could not be patched}}
\AtBeginShipout{%
\ifnum\value{additionalboxlevel}>\value{maxboxlevel}%
\typeout{Warning: maxboxlevel might be too small, increase to %
\the\value{additionalboxlevel}%
}%
\fi
\@whilenum\value{additionalboxlevel}<\value{maxboxlevel}\do{%
\typeout{* Additional boxing of page `\thepage'}%
\setbox\AtBeginShipoutBox=\hbox{\copy\AtBeginShipoutBox}%
\stepcounter{additionalboxlevel}%
}%
\setcounter{additionalboxlevel}{0}%
}
\makeatother
\begin{document}
\begin{frontmatter}
\end{frontmatter}
\kant*[1-4]
\kant[5]
\href{http://tex.stackexchange.com}{This is a very very
very very very very very very very very very very very very very
very very very very very very very very long link.}
\end{document}
\box\@outputbox
也许这个问题也可以通过\unvbox\@outputbox
在宏中替换来解决\@combinedblfloats
(也许垂直粘合分配可能会改变):
\usepackage{etoolbox}
\makeatletter
\patchcmd\@combinedblfloats{\box\@outputbox}{\unvbox\@outputbox}{}{%
\errmessage{\noexpand\@combinedblfloats could not be patched}%
}%
\makeatother
答案2
这实际上更像是对@HeikoOberdiek 知识性回答的回应,但不适合评论。
首先,我尝试了您建议的两种解决方法,“更自动化的解决方案”和重新定义\@combinedblfloats
。前者对我来说不起作用(我收到了几条* Additional boxing
消息,但错误仍然发生),但后者起作用了。所以再次感谢您!
其次,与此同时,我在文档中做了一些更改,使错误消失。我有一些浮动元素,它们以前有一个[!hbt]
位置修饰符,我删除了它。现在它们被放置在浮动页面上,而且这些页面之后的链接似乎不受影响。以下是 MWE:
\documentclass[5p]{elsarticle}
\usepackage{hyperref}
\begin{document}
\begin{frontmatter}
\end{frontmatter}
\null\vfill\newpage
\null\kern.95\textheight
\begin{figure*}[p]
\rule{1pt}{.9\textheight}
\caption{A figure.}
\end{figure*}
\null\vfill\newpage
\null\kern.95\textheight
\href{http://tex.stackexchange.com}{This is a very very
very very very very very very very very very very very very very
very very very very very very very very long link.}
\end{document}
答案3
正如所指出的这篇旧帖子,你必须指出hyperref
它可以断开链接:
\usepackage[breaklinks=true]{hyperref}
这在最新版本的 6.83m 中有效,并且还修复了每秒运行 时hyperref
不包含或给出错误的问题\refs
pdflatex