[Tex/LaTex] Beamer: multiple references to the same footnote

beamerfootnotes

In the LaTeX wikibook I found a workaround for having multiple references to the same footnote:

First reference.\footnote{This is the footnote}\addtocounter{footnote}{-1}\addtocounter{Hfootnote}{-1}
Second reference.\footnotemark

However, when using the beamer package and placing a footnote in the following context

\usetheme{CambridgeUS}
% ...

\begin{block}{testblock}
    one program\footnote{open-source software}\addtocounter{footnote}{-1},
    other program\footnotemark
\end{block}

this trick doesn't work (as the second reference is '0' instead of 'a'). What's the best way to achieve this with beamer (it seems that the problem is that beamer uses another counter for the 'footnotes' inside the block environment and \footnotemark returns the regular counter)?

Best Answer

The Hfootnote counter is needed for articles because hyperref plays fast and loose with the internals and has its own counters for many things, including footnotes. So when changing a counter in a non-normal fashion, you also have to change the hyperref version, which is usually H<original counter name>.

However, this is only needed when hyperref is making links between things in the document. In this case, it isn't. Beamer turns off much of hyperref's stuff as it loads the package with implicit=false. If you look carefully at the resulting PDF of a beamer presentation with footnotes, you'll see that there are no hyperlinks on footnotes.

So the internal footnote stuff isn't installed, and this is why Marco gets the error that he does: Hfootnote isn't defined.

Thus, in fact, the original solution from the LaTeX WikiBook works absolutely fine in this context:

\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{block}{testblock}
    one program\footnote{open-source software},
    other program\footnotemark[\value{footnote}],
    third program\footnote{proprietry}
\end{block}
\end{frame}
\end{document}

Indeed, this is a far more robust version since if you want more references to the same footnote, you can easily just copy that line:

\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{block}{testblock}
    one program\footnote{open-source software},
    other program\footnotemark[\value{footnote}],
    other program\footnotemark[\value{footnote}],
    third program\footnote{proprietry}
\end{block}
\end{frame}
\end{document}

This would not work with the \addtocounter hack, you'd need to \addtocounter{footnote}{-1} after each use of the footnotemark. However, this still doesn't work with out-of-order footnotes, to do that you'd need to save the footnote marker. Here's a simple hack for that, though I wouldn't be surprised to learn that there's a package to do it more cleanly (and that can cope with saving more than one footnote at a time).

\documentclass{beamer}
\renewcommand{\thefootnote}{\alph{footnote}}
\newcommand{\savefootnote}{\edef\tmpfn{\the\value{footnote}}}
\newcommand{\savedfootnote}{\footnotemark[\tmpfn]}
\begin{document}

\begin{frame}
\begin{block}{testblock}
    one program\footnote{open-source software}\savefootnote,
    other program\savedfootnote,
    fourth program\savedfootnote,
    third program\footnote{proprietry}
    other program\savedfootnote
\end{block}
\end{frame}
\end{document}

(Note: As this answer has been accepted, and as nothing in the above is actually wrong, I'm adding this rather than deleting the above and replacing it. However, the below is a more accurate analysis and more suitable fix. I still don't claim any elegance, though.)

After a bit of digging, I've discovered that this is nothing to do with beamer whatsoever and everything to do with minipages. The reason that you are seeing this is because when beamer does fancy boxes then the contents get put inside a minipage. Minipages have their own setup for footnotes and so within a minipage we have to hook in to the minipage system instead of the usual one. In particular, minipage footnotes have their own counter, mpfootnote, and this is the one that should be saved. At the start of the minipage environment, the old footnote stuff is replaced by the minipage-specific stuff. This should mean that everything just works. Except that it doesn't, because whoever designed the minipage environment didn't think that someone would want to use the \footnotemark command with an optional argument so the particular bit that that calls isn't swapped.

Fortunately, it's not hard to swap that bit if we need it. Unfortunately, I can't see a way to test if we're in a minipage so we need to define a different command to save the footnote inside a minipage (or a block) to outside. Maybe some passerby will be able to correct this.

Here's a sample code:

\documentclass{article}

\makeatletter
\newcommand{\savefootnote}{%
\edef\tmpfn{\the\value{footnote}}}
\newcommand{\savempfootnote}{%
    \let\@xfootnotemark=\@mpxfootnotemark
\edef\tmpfn{\the\value{footnote}}}
\newcommand{\savedfootnote}{\footnotemark[\tmpfn]}
\def\@mpxfootnotemark[#1]{%
  \begingroup
  \c@footnote #1\relax
  \unrestored@protected@xdef\@thefnmark{\thempfootnote}%
  \endgroup
  \@footnotemark}
\makeatother
\begin{document}

    one program\footnote{open-source software}\savefootnote,
    one program\savedfootnote,
    one program\savedfootnote,
    other program\footnote{proprietry},
    one program\savedfootnote,
\begin{minipage}{\textwidth}
    one program\footnote{open-source software}\savempfootnote,
    one program\savedfootnote,
    one program\savedfootnote,
    other program\footnote{proprietry},
    one program\savedfootnote,
\end{minipage}
\end{document}