Footnotemark and footnotetext – wrong number

footnotes

I wrote the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{footnote}
\usepackage[italian]{babel}
\usepackage{soul}
% serve (forse insieme a graphicx) per aggiungere freccia e testo/equazione sopra segno uguale =
\usepackage{mathtools}
% serve per plottare freccia grande, vuota, ruotata (vedi file: quadrato con frecce)

\newcommand{\eqstackrel}[1]{\stackrel{\substack{\mathclap{#1}\\[0.5ex]\displaystyle\uparrow\\ ~}}{ = } }
%serve per aggiungere testo sopra segno uguale =


\title{\textbf{Elementi di Calcolo delle Probabilità}}
\author{}
\date{}

\begin{document}
\maketitle  %serve per stampare il titolo ed eventualmente altro

Ecco del testo\footnote{Ecco una nota al testo.}

\begin{align}
P(R_2 | B_1) &= \left( 1 - P(R_1 | R_2) \right) \frac{P(R_2)}{1 - P(R_1)}
\eqstackrel{P(B | A) = P(B) \quad \text{rel. 126 a pag. 49}}
\\
&= \left( 1 - P(R_1) \right) \frac{P(R_2)}{1 - P(R_1)} \\
&= P(R_2)
\eqstackrel{\text{per hp\footnotemark}}
\\
&= \frac{R}{R + B}
\end{align}
\footnotetext{aaa}


\end{document}

The problem is that the footnote has a wrong number; in particular the previous footnote has the number 1, instead the footnote introduced by footmark has the number 4. How can I fix it?

Best Answer

The culprit is \mathclap. I suggest not using \mathclap (but \clap).

\documentclass{article}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{footnote}
\usepackage[italian]{babel}
\usepackage{mathtools}

\newcommand{\eqstackrel}[1]{\stackrel{\substack{
\clap{$\scriptstyle #1$}\\[0.5ex]\displaystyle\uparrow\\ ~}}{ = } }

\begin{document}
Ecco del testo\footnote{Ecco una nota al testo.}

\begin{align}
P(R_2 | B_1) &= \left( 1 - P(R_1 | R_2) \right) \frac{P(R_2)}{1 - P(R_1)}
\eqstackrel{P(B | A) = P(B) \quad \text{rel. 126 a pag. 49}}
\\
&= \left( 1 - P(R_1) \right) \frac{P(R_2)}{1 - P(R_1)} \\
&= P(R_2)
\eqstackrel{\text{per hp\footnotemark}}
\\
&= \frac{R}{R + B}
\end{align}
\footnotetext{aaa}

\end{document}

Output of the above code


Since you have loaded footnote, I suggest to put the {align} in a {savenotes} and use \footnote directly. However, the command \footnote must not be put in the command \text but just after.

\documentclass{article}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{footnote}
\usepackage[italian]{babel}
\usepackage{mathtools}

\newcommand{\eqstackrel}[1]{\stackrel{\substack{
\clap{$\scriptstyle #1$}\\[0.5ex]\displaystyle\uparrow\\ ~}}{ = } }

\begin{document}
Ecco del testo\footnote{Ecco una nota al testo.}

\begin{savenotes}
\begin{align}
P(R_2 | B_1) &= \left( 1 - P(R_1 | R_2) \right) \frac{P(R_2)}{1 - P(R_1)}
\eqstackrel{P(B | A) = P(B) \quad \text{rel. 126 a pag. 49}}
\\
&= \left( 1 - P(R_1) \right) \frac{P(R_2)}{1 - P(R_1)} \\
&= P(R_2)
\eqstackrel{\text{per hp}\footnote{aaa}}
\\
&= \frac{R}{R + B}
\end{align}
\end{savenotes}

\end{document}