# How to change footnote anchors

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}}}%
%
\let\oldfootnotetext\footnotetext
\renewcommand{\footnotetext}[1]{%
\oldfootnotetext[\crrctnmbr]{#1}%
%
\ExplSyntaxOn
\NewExpandableDocumentCommand{\crrctnmbr}{}{
\int_eval:n { \value{footnote} - \value{stckrelfnotes} }
}
\ExplSyntaxOff
% --------------------------
\begin{document}
\footnote{a}
%
$$a \tofootnote{=} b \tofootnote{=} c$$
\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?

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}}}%
%
\makeatletter
\let\oldfootnotetext\footnotetext
\renewcommand{\footnotetext}[1]{%
\ifnum\c@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}
%
$$a \tofootnote{=} b \tofootnote{=} c$$

\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