1

I'm trying to write some code that lets me use footnotes inside stackrel multiple times in a single equation, and so far this is what I've come up with

\documentclass{article}
\usepackage{hyperref}
\usepackage{xparse}
% --------------------------
\newcounter{stckrelfnotes}
\setcounter{stckrelfnotes}{-1}
%
\newcommand{\tofootnote}[1]{%
\mathrel{\vbox{\offinterlineskip\ialign{\hfil##\hfil\cr$\scriptscriptstyle\footnotemark$\cr\noalign{\kern.05ex}$#1$\cr}}}%
\addtocounter{stckrelfnotes}{1}}
%
\let\oldfootnotetext\footnotetext
\renewcommand{\footnotetext}[1]{%
\oldfootnotetext[\crrctnmbr]{#1}%
\addtocounter{stckrelfnotes}{-1}}
%
\ExplSyntaxOn
\NewExpandableDocumentCommand{\crrctnmbr}{}{
  \int_eval:n { \value{footnote} - \value{stckrelfnotes} }
}
\ExplSyntaxOff
% --------------------------
\begin{document}
\footnote{a}
%
\begin{equation}
a \tofootnote{=} b \tofootnote{=} c
\end{equation}
\footnotetext{b}
\footnotetext{c}
%
\footnote{d}
\end{document}

this gets all the numbers right, however the two footnote links inside the equation link to nothing. The log gives me the following warnings:

pdfTeX warning (dest): name{Hfootnote.3} has been referenced but does not exist, replaced by a fixed one

pdfTeX warning (dest): name{Hfootnote.2} has been referenced but does not exist, replaced by a fixed one

which probably means that the relative footnote anchors are not named Hfootnote.3 and Hfootnote.2. How can I change those anchors so that I get the right links?

1

You can't use the optional argument of \footnotetext, hyperref has not support for it. So you shouldn't use a calculated value but should reset the footnote counter. Also hyperref doesn't have code to reset the anchor names when more than one \footnotetext is used, this has to be done manually:

\documentclass{article}
\usepackage{hyperref}
\usepackage{xparse}
% --------------------------
\newcounter{stckrelfnotes}
\setcounter{stckrelfnotes}{-1}
%
\newcommand{\tofootnote}[1]{%
\mathrel{\vbox{\offinterlineskip\ialign{\hfil##\hfil\cr$\scriptscriptstyle\footnotemark$\cr\noalign{\kern.05ex}$#1$\cr}}}%
\addtocounter{stckrelfnotes}{1}}
%
\makeatletter
\let\oldfootnotetext\footnotetext
\renewcommand{\footnotetext}[1]{%
 \ifnum\c@stckrelfnotes >-1
 \addtocounter{footnote}{\numexpr-\value{stckrelfnotes}-1}
 \addtocounter{Hfootnote}{\numexpr-\value{stckrelfnotes}-1}
 \fi
 \stepcounter{footnote}%
 \stepcounter{Hfootnote}%
 \hyper@makecurrent{Hfootnote}%
 \global\let\Hy@footnote@currentHref\@currentHref
 \oldfootnotetext{#1}%
 \setcounter{stckrelfnotes}{-1}}
\makeatother
% --------------------------
\begin{document}
\footnote{a}
%
\begin{equation}
a \tofootnote{=} b \tofootnote{=} c
\end{equation}

\footnotetext{b}
\footnotetext{c}
%
\footnote{d}
\end{document}
  • Thanks a lot, I'd been trying to solve this problem for the last two days ;) – noibe May 2 at 14:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.