6

I am trying to use inline todo notes from the todonotes package inside figure captions. However I get the following error when I generate the listoffigures.

! Leaders not followed by proper glue.
<to be read again>
                   \hfill
l.2 ...inline]{A note in a float}}}{8}{figure.1.1}

I find this strange since the docs say this is one of the intended use cases for inline todo notes (see pg.6)!

Here is my MWE TeX file:

\documentclass[11pt,a4paper,draft,twoside]{scrbook}

\usepackage{fixltx2e}
\usepackage{fontspec}
\usepackage{libertine}
\usepackage{microtype}

\usepackage{graphicx}
\usepackage{float}

\usepackage[backgroundcolor=green!40,textsize=scriptsize,obeyFinal]{todonotes}

\author{Suvayu}
\date{\today}
\title{Title}

\usepackage[draft=false,bookmarks]{hyperref}
\hypersetup{
  % hidelinks,
  colorlinks,
  pagebackref,
  linkcolor=black,
}
\usepackage{bookmark}           % smarter bookmarks

\begin{document}

\maketitle
\clearpage\null\newpage

\setcounter{tocdepth}{3}
\addcontentsline{toc}{chapter}{\contentsname}
\tableofcontents
\newpage
\addcontentsline{toc}{chapter}{\listfigurename}
\listoffigures

%% Chapter 1
\chapter{What is the answer to the ultimate question?}

The answer is 42!\todo[inline]{A note \emph{not} in a float}

\begin{figure}[htb]
\centering
\includegraphics[width=\textwidth]{graphics/timelt2ps_hMom_Pt___hMom_Eta___hIPchi2_time.pdf}
\caption{Why 42, and not 43? \todo[inline]{A note in a float}}
\end{figure}

\end{document}

Unfortunately I do not know what is the custom when it comes to included graphics files in MWEs, so I left it out. I guess including any pdf would do. Some observations:

  • when I remove the \listoffigures, the error goes away,
  • when I add a short caption with \caption[short]{long \todo[inline]{note}} then the error seems to go away again.

So I guess the problem comes from typesetting the listoffigures. For the moment I have a workaround, but I would like to understand what is going wrong, and how to resolve similar issues in the future. I'm particularly interested since my search for ! Leaders not followed by proper glue. led to this page; it makes me even more curious!

4

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}
  • Your second workaround is already mentioned in my question, and the first workaround is an alternate way to achieve the same. I understood that basic reason already. I was hoping someone could explain why, specially when the todonotes docs mention this use case. It would also be very helpful to know what the error actually means, specially given the cryptic FAQ I found; but maybe that should be a separate question. If you don't have an explanation, I'll accept the answer in a couple of days anyway. – suvayu Jul 26 '15 at 8:50
  • I will fix the example in the documentation in the next release of the package. Regarding why the problem occours I don't know enough to answer that. – midtiby Jul 26 '15 at 13:40
  • sorry for the delay in accepting the answer, and thanks for updating the todonotes docs. – suvayu Jul 30 '15 at 12:30
  • @midtiby I think the answer I just added explains why the problem occurs (or at least puts you in the right direction). – Joel Feb 25 '16 at 6:36
3

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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