1

I'm writing a book which contains long footnotes and many links, all created with \hyperlink. If a linked text in a footnote wraps to the following page, then the following happens: The color of the linked text in the footnote disappears on the second page, and the whole main text of the second page is now linked to the target. This happens in the book- and the article-class, but not in amdbook- and amsart-class. Is there a possibility to avoid this?

Here is a minimal code:

\documentclass[11pt]{book}
\usepackage{lipsum}
\usepackage[colorlinks]{hyperref}
%
\begin{document}
\lipsum[2-5]\footnote{\hyperlink{target}{\lipsum[2-3]}}
\lipsum[2-3]
\newpage
\hypertarget{target}{THIS IS THE TARGET!}
%
\end{document}

1 Answer 1

1

To improve the color you can load the pdfcolfoot package.

But for the link there is currently no good solution. You are paying the price for the ability of pdftex to break links over lines and pages: To be able to do this it adds everything between start and end point to the link area, and this encompasses the text body.

A current texlive offers commands to interrupt a link, and for the header and footer there is code in the new PDF management which make use of them: https://tex.stackexchange.com/a/578405/2388.

But this can't be used easily for footnotes. In your example one can for example correct the link with

\documentclass[11pt]{book}
\usepackage{lipsum}
\usepackage[colorlinks]{hyperref}
\usepackage{pdfcolfoot}
\usepackage{etoolbox}
\makeatletter
\patchcmd\@makecol
  {\pdfcolfoot@current\unvbox\footins}
  {\pdfcolfoot@current\pdfrunninglinkon \unvbox \footins \pdfrunninglinkoff}
  {}{\fail}
\makeatletter

\begin{document}
\lipsum[2-5]\footnote{\hyperlink{target}{\lipsum[2-3]}}
\lipsum[2-3]
\newpage
\hypertarget{target}{THIS IS THE TARGET!}
%
\end{document}

But if the main text body contains also a link with a page break the link targets gets confused and the second part of the footnote links to the url:

\documentclass[11pt]{book}
\usepackage{lipsum}
\usepackage[colorlinks]{hyperref}
\usepackage{pdfcolfoot}
%
\usepackage{etoolbox}
\makeatletter
\patchcmd\@makecol
  {\pdfcolfoot@current\unvbox\footins}
  {\pdfcolfoot@current\pdfrunninglinkon \unvbox \footins \pdfrunninglinkoff}
  {}{\fail}
\makeatletter
\begin{document}

\lipsum[2-3]
\footnote{\hyperlink{target}{\lipsum[1-4]}}%
\href{https://www.latex-project.org}{\lipsum[3-5]}%
\lipsum[2]
\newpage
\hypertarget{target}{THIS IS THE TARGET!}
%
\end{document}

enter image description here

So this is not a stable solution. I doubt that one can repair this in pdftex. In my opinion one will need luatex and new link code based on attributes.

Side remark: I quite loath documents with lots of large link areas. I'm often reading on a touch screen and it is a nuisance if one triggers a link when one only wants to scroll or to zoom.

3
  • Thanks a lot, Ulrike. Unfortunately, I need the package fontspec and I'm using LuLaTeX. Then I get an error: Undefined control sequence \pdfrunninglinkoff Jan 16 at 20:54
  • with luatex the command is \pdfextension linkstate 0 \unvbox \footins \pdfextension linkstate 1 . With luatex you could also try github.com/zauguin/lua-links Jan 16 at 21:05
  • If I add this command just after the package hyperref, then the footnote is colored, but only the first line of the footnote is linked. \documentclass[11pt]{book} \usepackage{lipsum} \usepackage{fontspec} \usepackage[breaklinks,colorlinks]{hyperref} \usepackage{pdfcolfoot} \usepackage{etoolbox} \pdfextension linkstate 0 \unvbox \footins \pdfextension linkstate 1 \begin{document} \lipsum[2-5]\footnote{\hyperlink{target}{\lipsum[2-3]}} \lipsum[2-3] \newpage \hypertarget{target}{THIS IS THE TARGET!} \end{document} Jan 18 at 16:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .