3

I use the algpseudocode package to write algorithms, and the hyperref package to add hyperlinks to footnotes. I want to be be able to add footnotes with hyperlinks within my algorithms.

Something like this would be nice:

\documentclass[12pt]{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{hyperref}

\begin{document}

\begin{algorithm}[H]\caption{Do something}
    \label{alg: CR}
    On input, do:
    \begin{enumerate}
        \item Do something. \footnote{Footnote one}
        \item Do a second thing.
        \item Aha! The final thing. \footnote{Footnote two}
        \item Oops, do one more. \footnote{Footnote three}
    \end{enumerate}
\end{algorithm}


Text\footnote{Footnote four}

\end{document}

Unfortunately, this doesn't work; only footnote four is displayed: enter image description here

I believe this has something to do with the algorithm environment being a float, similar to figures or tables. As such, I hoped that solutions to "Footnote in table" type questions would help, but I haven't had much luck. Wrapping the algorithm environment in a savenotes environment worked insofar as all of the footnotes get displayed, but only the hyperlinks for footnote three and footnote four work (the other two just take you to the start of the document). Similar results can be achieved using tablefootnotes and manually adding footnotetext.

Any suggestions would be gratefully received!

1
  • I think I must've been using savenotes incorrectly. I managed the resolve the issue; solution documented below. Commented May 2, 2024 at 12:42

1 Answer 1

1

Using savenotes from the footnotehyper package is the correct way to go, and whilst it is possible to achieve the desired results using \savenotes and \spewnotes, the easier way is to use \makesavenoteenv.

From the the footnotehpyer package documentation:

Finally there is a \makesavenoteenv macro which takes as argument an environment name and patches it to do the \savenotes/\spewnotes automatically.

The syntax is either \makesavenoteenv{foo} which patches environment foo [...] to do automatically \savenotes/\spewnotes, or \makesavenoteenv[bar]{foo} which defines environment bar as foo inside a savenotes environment.

Provided that it is okay to overwrite the algorithm environment, adding \makesavenoteenv{algorithm} after \usepackage{footnotehyper} and \usepackage{algorithm} should work.

In the context of the question:

\documentclass[12pt]{article}
\usepackage{hyperref, footnotehyper}
\usepackage{algorithm}
\makesavenoteenv{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}[H]\caption{Do something}
    \label{alg: CR}
    On input:
    \begin{enumerate}
        \item Do something. \footnote{Footnote one}
        \item Do a second thing.
        \item Aha! Do the final thing. \footnote{Footnote two}
        \item Oops, do one more. \footnote{Footnote three}
    \end{enumerate}
\end{algorithm}

Text\footnote{Footnote four}

\end{document}

tex output showing an algorithm with four footnotes, and the footnote text being correctly displayed at the bottom of the page

Note that the hyperlinks also work, but that's quite difficult to show in this answer!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.