Footnote in align environment
amstext.sty
defines a \iffirstchoice@
test just for this: it is true in the first branch of the inner \mathchoice
called by \text
and false in the remaining three.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\AlignFootnote}[1]{%
\ifmeasuring@
\else
\iffirstchoice@
\footnote{#1}%
\fi
\fi}
\makeatother
\begin{document}
\begin{minipage}{0.5\linewidth}
\begin{align*}
E &= mc^3 &&\text{Einstein}\AlignFootnote{Better check this.} \\
F &= mb &&\text{Newton\AlignFootnote{This also seems wrong for some reason.}}
\end{align*}
\end{minipage}
\end{document}
Actually the size of the footnote mark is not taken into consideration for the size of the equation, so a more correct answer would be
\makeatletter
\newcommand{\AlignFootnote}[1]{%
\ifmeasuring@
\chardef\@tempfn=\value{footnote}%
\footnotemark
\setcounter{footnote}{\@tempfn}%
\else
\iffirstchoice@
\footnote{#1}%
\fi
\fi}
\makeatother
that prints only the footnotemark and restores the counter at its previous value.
Limitation If you say \dfrac{\text{Newton\AlignFootnote{X}}}{2}
you won't get the footnote. But this shouldn't be a big deal.
If you want to use the \footnote
command, this works
\documentclass{article}
\usepackage{amsmath,etoolbox}
\makeatletter
\let\original@footnote\footnote
\newcommand{\align@footnote}[1]{%
\ifmeasuring@
\chardef\@tempfn=\value{footnote}%
\footnotemark
\setcounter{footnote}{\@tempfn}%
\else
\iffirstchoice@
\original@footnote{#1}%
\fi
\fi}
\pretocmd{\start@align}{\let\footnote\align@footnote}{}{}
\makeatother
\begin{document}
\begin{minipage}{0.5\linewidth}
\begin{align*}
E &= mc^3 &&\text{Einstein\footnote{Better check this.}} \\
F &= mb &&\text{Newton\footnote{This also seems wrong for some reason.}}
\end{align*}
\end{minipage}
\end{document}
Note. The above codes only work for when we're inside minipage
. For outer footnotes the only way is to use \footnotemark
and \footnotetext
, with some adjustments not to make the counter advance too many times.
\documentclass{article}
\usepackage{amsmath,etoolbox}
\makeatletter
\let\original@footnotemark\footnotemark
\newcommand{\align@footnotemark}{%
\ifmeasuring@
\chardef\@tempfn=\value{footnote}%
\original@footnotemark
\setcounter{footnote}{\@tempfn}%
\else
\iffirstchoice@
\original@footnotemark
\fi
\fi}
\pretocmd{\start@align}{\let\footnotemark\align@footnotemark}{}{}
\makeatother
\textheight=4cm % just to produce a smaller picture
\begin{document}
\begin{align*}
E &= mc^3 &&\text{Einstein\footnotemark} \\
F &= mb &&\text{Newton\footnotemark}
\end{align*}
\addtocounter{footnote}{-1}
\footnotetext{Better check this.}
\addtocounter{footnote}{1}
\footnotetext{This also seems wrong for some reason.}
\end{document}
Code
\documentclass{article}
\usepackage{amsmath}
\usepackage{letltxmacro}
\makeatletter
\newcommand*{\fakeFN}[1]{\@makefnmark}
\newcommand{\AlignFootnote}[1]{%
\ifmeasuring@% I want to use \@makefnmark here, too,
% but \@thefnmark is undefined.
% The substitute "kerning" (see \else branch) is a work-around, but
% messes with align's spacing.
\else%
\footnote{#1}\sbox0{\@makefnmark}\kern-\wd0%
\fi
}
\makeatother
\newdimen\myparboxwidth
\newcommand{\textfn}[1]{% I need to increment the fnmark counter here …
{\LetLtxMacro\footnote\fakeFN\sbox0{#1}\global\myparboxwidth=\wd0}
\parbox{\myparboxwidth}{#1}%
}
%\usepackage{lua-visual-debug} % for the second output
\begin{document}
\noindent\begin{minipage}{\linewidth}
\begin{align*}
E &= mc^3 &&\text{Einstein}\AlignFootnote{Better check this.} \\
F &= mb &&\textfn{Newton\AlignFootnote{This also seems wrong for some reason.}}
\end{align*}
\end{minipage}
\begin{align*}
E &= mc^2 &&\text{Einstein is happy now.} \\
F &= ma &&\text{Newton, too.}
\end{align*}
\end{document}