2

Is there a standard solution to log broken hyperlinks over 2 pages? I do not want/prefer them in my document, and it would be nice if I get them outputted to the log, so I can grep on it, instead of visual inspecting complete documents.

For normal Latex bibliography, I created a hyperlink-broken-over-different-pages detector (see first MWE) based on this post.

However the biblatex variant (see second MWE) is not working. Why not?

@Heiko: Can we get this functionality default in hyperref? So in case you run verbose/debug you get for page breaking links a comment like "[broken over 2 pages]"??

Working MWE:

This gives expected output:

HYPERLINK BREAK PAGES

cite

cite.reference LongSurnameOfTheFirstAuthor and LongSurnameOfTheSecondAuthor, 2004

HYPERLINK BREAK PAGES

Package hyperref Info: Reference (cite) `cite.reference' on input line 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 NOT Working based on Biblatex:

When I switch to Biblatex, this solution is not working anymore. I expect now "HYPERLINK NOT BREAKING PAGES", because only the year is hyperlinked which does not break over pages. However I get nothing:

Package hyperref Info: Anchor 'page.2' on input line 83. [2

Package hyperref Info: End of reference (cite) `cite.0@reference', line 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}
  • 2
    biblatex uses \hyper@natlinkend .... \hyper@natlinkend for the link, so you would have to hack these (or \blx@bibhyperref). – Ulrike Fischer Oct 16 '16 at 20:54
  • How do I do this? – robert Oct 17 '16 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.