Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

It appears that one is not supposed to use \footnote in math mode as per this appropriately named question: Footnote in math mode. However, it appears that I can get it to work without having to resort to \footnotemark and \footnotetext, as long as I use a minipage:

\begin{minipage}{0.5\linewidth}
\begin{align*}
    E &= mc^3 &&\text{Einstein}\footnote{Better check this.}
\end{align*}
\end{minipage}

which yields:

enter image description here

Ok, so that seems to be working.

But wait.. The text of the \footnote duplicated!!! Hmmm, must be the measuring stage that align goes thru. Ok, then that should be easy to fix: all we need to do is to check \ifmeasuring@:

\makeatletter
\newcommand{\AlignFootnote}[1]{%
    \ifmeasuring@
    \else
        \footnote{#1}%
    \fi
}
\makeatother

Now using \AlignFootnote{} instead of \footnote{} we get the desired results:

enter image description here

Ok, but in this first use case (Einstein) I just happened to use the \footnote inside the \text{}. Trying to use \AlignFootnote{} outside of the \text{} (Newton) really screws this up for some reason:

enter image description here

So in the Newton use case, it appears as if the content outside of the \text{} goes thru 4 non-measuring passes.

Attempted Fix:

Well the obvious thing to try was to use \text{\footnote{#1}}, but that not only has no effect on the second use case, it also messes up the first use case: both footnotes show up 4 times.

Questions:

  • Main question: Is there a way to detect the repeated passes outside of \text{} so that I don't have \footnotes duplicated without resorting to \footnotemark/\footnotetext?
  • Why is the minipage required? Without it the \footnotes don't show up at all. Is there some flushing type of macro required that would make them show up?

Code:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\AlignFootnote}[1]{%
    \ifmeasuring@
    \else
        \footnote{#1}%
    \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}
share|improve this question
1  
Related Question: Can I make footnote inside an equation?. –  Peter Grill Jan 23 '14 at 5:18

2 Answers 2

up vote 5 down vote accepted

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}

enter image description here

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}

enter image description here

share|improve this answer
    
ahhh, so \mathchoice is where the 4 repetitions are coming from. –  Peter Grill Nov 15 '12 at 7:43
    
Shouldn't you also do the footnote mark (but not \insert the footnote text) on the measuring run and textstyle (2nd) branch of mathchoice if you want the measuring to be right? (and then reset the counter appropriately?) –  David Carlisle Nov 15 '12 at 9:21
    
@DavidCarlisle align uses \displaystyle, so the second branch should not be necessary, if the \text is not in the numerator or denominator of a fraction or in a radical (which I believe would be very devious). I'll do some more tests. –  egreg Nov 15 '12 at 9:26
1  
@SydKerckhove I expanded my answer. But avoid footnotes in math, so the problem doesn't show up to begin with. –  egreg 2 days ago
1  
@SydKerckhove That's what I feared. Don't! ;-) A side comment is much better. –  egreg 2 days ago

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}

Output

enter image description here

Output with lua-visual-debug activated

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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