我正在尝试编写一些代码来让我在单个方程式中多次使用 stackrel 内的脚注到目前为止,这就是我想到的
\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}
这样所有数字都正确,但是公式内的两个脚注链接指向的内容为空。日志向我发出以下警告:
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
这可能意味着相对脚注锚点未命名为Hfootnote.3
和Hfootnote.2
。我该如何更改这些锚点以获得正确的链接?
答案1
您不能使用 \footnotetext 的可选参数,hyperref 不支持它。因此,您不应使用计算值,而应重置脚注计数器。此外,当使用多个 \footnotetext 时,hyperref 没有代码来重置锚点名称,这必须手动完成:
\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}