是否有一个标准解决方案来记录超过 2 页的损坏超链接?我不希望/不喜欢它们出现在我的文档中,如果我将它们输出到日志中就好了,这样我就可以对其进行 grep,而不是目视检查完整的文档。
对于普通的 Latex 书目,我创建了一个不同页面上的超链接断开检测器(参见第一个 MWE)基于这个帖子。
但是,那比布拉特克斯变体(参见第二个 MWE)不起作用。为什么不?
@Heiko:我们可以在 hyperref 中默认使用此功能吗?那么,如果您运行 verbose/debug,您会得到类似“分页链接超过 2 页”这样的注释吗??
工作MWE:
这给出了预期的输出:
超链接中断页
引用
cite.reference LongSurnameOfTheFirstAuthor 和 LongSurnameOfTheSecondAuthor,2004 年
超链接中断页
软件包 hyperref 信息:参考(cite)‘cite.reference’ 在输入行 64。
\documentclass[12pt]{article}
\usepackage[a5paper,hmargin=10mm,vmargin=20mm]{geometry}
\usepackage{cite} % numeric citations
\usepackage[debug]{hyperref} % links in PDF
\usepackage{fancyhdr} % fancy headers and footers
\usepackage{lipsum} % just for the sake of this example
\fancyhead{}
\fancyhead[LO]{\nouppercase{\textsc{\leftmark}}}
\fancyhead[RO]{\nouppercase{\textsc{\thepage}}}
\fancyfoot{}
\setlength{\headheight}{15pt}
\usepackage{zref-abspage}
\makeatletter
\newcounter{lnkpg}
\renewcommand*{\thelnkpg}{lnkpg\the\value{lnkpg}}
\newcommand*{\org@hyper@link@}{}
\let\org@hyper@link@\hyper@link@
\protected\def\hyper@link@[#1]#2#3#4{%
\def\lnkpg@callorg{%
\org@hyper@link@[{#1}]{#2}{#3}{#4}%
}%
\stepcounter{lnkpg}%
\zref@labelbyprops{\thelnkpg a}{abspage}%
\zref@refused{\thelnkpg a}%
\zref@ifrefundefined{\thelnkpg a}{%
\lnkpg@callorg
\zref@labelbyprops{\thelnkpg b}{abspage}%
}{%
\zref@ifrefundefined{\thelnkpg b}{%
\mbox{\lnkpg@callorg}%
}{%
\edef\lnkpg@a{\zref@extractdefault{\thelnkpg a}{abspage}{0}}%
\edef\lnkpg@b{\zref@extractdefault{\thelnkpg b}{abspage}{0}}%
\ifx\lnkpg@a\lnkpg@b
\wlog{>> HYPERLINK NOT BREAKING PAGES}
\wlog{#1}
\wlog{#2}
\wlog{#3}
\wlog{#4}
\wlog{<< HYPERLINK NOT BREAKING PAGES}
\lnkpg@callorg
\zref@labelbyprops{\thelnkpg b}{abspage}%
\else
\wlog{>> HYPERLINK BREAKING PAGES}
\wlog{#1}
\wlog{#2}
\wlog{#3}
\wlog{#4}
\wlog{<< HYPERLINK BREAKING PAGES}
\lnkpg@callorg
\zref@labelbyprops{\thelnkpg b}{abspage}%
\fi
}%
}%
}
\makeatother
\begin{document}
\pagestyle{fancy}
\lipsum[2]\lipsum[2]\lipsum[2]\lipsum[4]
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff
\cite{reference}
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff
\begin{thebibliography}{}
\bibitem[LongSurnameOfTheFirstAuthor and LongSurnameOfTheSecondAuthor,
2004]{reference}
LongSurnameOfTheFirstAuthor, D. and LongSurnameOfTheSecondAuthor, R. (2004).
\newblock Example text.
\newblock {\em Journal of example articles}, 21(12):2326--2339.
\newblock [DOI:\href{http://www.example.com}{example}].
\end{thebibliography}
\end{document}
MWE 不基于 Biblatex 工作:
当我切换到 Biblatex 时,此解决方案不再起作用。我现在期望“超链接不跨页”,因为只有年份是超链接,不会跨页。但是我什么也没得到:
软件包 hyperref 信息:将“page.2”锚定在输入行 83 上。[2
软件包 hyperref 信息:引用结束 (cite) `cite.0@reference',第 78 行。
]
\begin{filecontents}{\jobname.bib}
@article{reference,
author={LongSurnameOfTheFirstAuthor and LongSurnameOfTheSecondAuthor},
title = {Journal of example articles},
year = {2004}
}
\end{filecontents}
\documentclass[12pt]{article}
\usepackage[a5paper,hmargin=10mm,vmargin=20mm]{geometry}
\usepackage[citestyle=authoryear,hyperref=true,backend=bibtex]{biblatex}
\usepackage[debug]{hyperref}
\addbibresource{\jobname.bib}
\usepackage{fancyhdr} % fancy headers and footers
\usepackage{lipsum} % just for the sake of this example
\fancyhead{}
\fancyhead[LO]{\nouppercase{\textsc{\leftmark}}}
\fancyhead[RO]{\nouppercase{\textsc{\thepage}}}
\fancyfoot{}
\setlength{\headheight}{15pt}
\usepackage{zref-abspage}
\makeatletter
\newcounter{lnkpg}
\renewcommand*{\thelnkpg}{lnkpg\the\value{lnkpg}}
\newcommand*{\org@hyper@link@}{}
\let\org@hyper@link@\hyper@link@
\protected\def\hyper@link@[#1]#2#3#4{%
\def\lnkpg@callorg{%
\org@hyper@link@[{#1}]{#2}{#3}{#4}%
}%
\stepcounter{lnkpg}%
\zref@labelbyprops{\thelnkpg a}{abspage}%
\zref@refused{\thelnkpg a}%
\zref@ifrefundefined{\thelnkpg a}{%
\lnkpg@callorg
\zref@labelbyprops{\thelnkpg b}{abspage}%
}{%
\zref@ifrefundefined{\thelnkpg b}{%
\mbox{\lnkpg@callorg}%
}{%
\edef\lnkpg@a{\zref@extractdefault{\thelnkpg a}{abspage}{0}}%
\edef\lnkpg@b{\zref@extractdefault{\thelnkpg b}{abspage}{0}}%
\ifx\lnkpg@a\lnkpg@b
\wlog{>> HYPERLINK NOT BREAKINNG PAGES}
\wlog{#1}
\wlog{#2}
\wlog{#3}
\wlog{#4}
\wlog{<< HYPERLINK NOT BREAKING PAGES}
\lnkpg@callorg
\zref@labelbyprops{\thelnkpg b}{abspage}%
\else
\wlog{>> HYPERLINK BREAKING PAGES}
\wlog{#1}
\wlog{#2}
\wlog{#3}
\wlog{#4}
\wlog{<< HYPERLINK BREAKING PAGES}
\lnkpg@callorg
\zref@labelbyprops{\thelnkpg b}{abspage}%
\fi
}%
}%
}
\makeatother
\begin{document}
\pagestyle{fancy}
\lipsum[2]\lipsum[2]\lipsum[2]\lipsum[4]
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff
\textcite{reference}
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff stuff stuff stuff
Stuff stuff stuff
\printbibliography
\end{document}