Cannot use inline todonotes in a figure caption

First I reduced the provided example a bit more, until it was closer to a minimal working example (MWE)

\documentclass{article}
\usepackage{todonotes}
\usepackage{hyperref}

\begin{document}
\listoffigures

\begin{figure}
\caption{Why 42, and not 43? \todo[inline]{A note in a float}}
\end{figure}

\end{document}

Then the problem was identified as trying to draw the inserted todonote in the list of figures, where it is not allowed to draw such things.

There are two ways of inserting todonotes in captions. The one I prefer is the following where the todonote is placed outside of the caption.

\begin{figure}
\caption{A figure caption.}
\todo[inline]{Need to insert the figure}
\end{figure}

An alternative approach is to specify a text for the list of figures without the todonote.

\caption[Short caption]{Why 42, and not 43? \todo[inline]{A note in a float}}

Both approaches are given in the example below.

\documentclass{article}
\usepackage{todonotes}
\usepackage{hyperref}

\begin{document}
\listoffigures

\begin{figure}
% The line below casuses problems, as the inline note will be inserted in the list of figures
% which causes an error.
%\caption{Why 42, and not 43? \todo[inline]{A note in a float}}

% The line below works, as a different text (short caption) is given to the list of figures.
\caption[Short caption]{Why 42, and not 43? \todo[inline]{A note in a float}}
\end{figure}

 % The prefered way of inserting todo notes is to place them outside the caption.
\begin{figure}
\caption{A figure caption.}
\todo[inline]{Need to insert the figure}
\end{figure}

\end{document}

Just use \protect. It's a fragile command

\begin{figure}
\caption{Why 42, and not 43? \protect \todo[inline]{A note in a float}}
\end{figure}

Tags:

Todonotes