Inside a minipage I use footnotes that should be printed at the end of the minipage.
I also use marginnote
and re-define \marginpar
to be \marginnote
, because I use them inside other floats (primarily, figure floats).
Moreover, I use todonotes
to print, well, todos in the margin.
If I use everything together, a todonote in a minipage "swallows" all the footnotes that have already been typed but not printed yet and prints the footnotes at its own bottom, i.e. at the bottom of the todonote.
MWE
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{marginnote} % Enhanced marginpar
\usepackage{todonotes}
%
% We need to redefine \marginpar.
% \marginpar does not work inside floats, but \marginnote does.
% Also \todo uses \marginpar internally and this way it actually uses \marginnote.
% See manual for marginnote and sec. 1.6.8 in the manual for todonotes.
%
\renewcommand{\marginpar}{\marginnote}
\begin{document}
\begin{figure}[htbp]\centering
\begin{minipage}{.5\linewidth}
This is a sentence with a footnote.\footnote{It only serves as an example.}
Now a sentence with \todo{The footnote ends up in the margin.}a \texttt{todo}-note follows.
However, the last footnote is printed at the end of the minipage\footnote{Because it is inserted after the \texttt{todo}-note.}.
\end{minipage}
\end{figure}
\end{document}
The output:
How do I correct this behavior? N.b., I do note need or use footnotes inside a todonote or any other margin note. Hence, a feasable solution could be to disable footnotes for margin notes, if this is possible.
Extended MWE to bugfix the answer below
The originally proposed answer (see below) has some bugs as pointed out by the following extended MWE: a) It also draws a separation line, if the minipage does not contain any footnote. b) The footnotes are completely lost, if a list environment is used inside the minipage.
\documentclass[american]{article}
\usepackage[TS1,T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{marginnote}
\usepackage{todonotes}
%
% We need to redefine \marginpar.
% \marginpar does not work inside floats, but \marginnote does.
% Also \todo uses \marginpar internally and this way it actually uses \marginnote.
% See manual for marginnote and sec. 1.6.8 in the manual for todonotes.
%
\renewcommand{\marginpar}{\marginnote}
\newsavebox{\mpfootsave}
\makeatletter
\newcommand{\mytodo}[1]{%
\setbox\mpfootsave=\vbox{\unvbox\@mpfootins}%
\todo[caption={}]{#1}%
\setbox\@mpfootins=\vbox{\unvbox\mpfootsave}%
}
\makeatother
\begin{document}
\begin{figure}[htbp]\centering
\begin{minipage}{.7\linewidth}
This is a sentence with a footnote.\footnote{It only serves as an example.}
Now a sentence with \mytodo{The footnote ends up in the margin.}a \texttt{todo}-note follows.
However, the last footnote is printed at the end of the minipage\footnote{Because it is inserted after the \texttt{todo}-note.}.
\end{minipage}
\end{figure}
\begin{figure}[htbp]\centering
\begin{minipage}{.7\linewidth}
The solution works only partially, if there is no footnote after the last \mytodo{Like this}\texttt{todo}-note.
The seperation line is printed even if there is no footnote at all.
\end{minipage}
\end{figure}
\begin{figure}[htbp]\centering
\begin{minipage}{.7\linewidth}
\begin{enumerate}
\item
Even with an enumeration, the \mytodo{Another todo}solution works.
But only if the footnote comes last.\footnote{It only serves as an example.}
\end{enumerate}
\end{minipage}
\end{figure}
\begin{figure}[htbp]\centering
\begin{minipage}{.7\linewidth}
\begin{enumerate}
\item
But the solution\footnote{Actually, the proposed solution.} fails in combination with an enumeration, if a \mytodo{Yet another todo}\texttt{todo}-note appears after the last footnote.
\end{enumerate}
\end{minipage}
\end{figure}
\end{document}
Result: