I am using the todonotes
package and I wanted to add a note inside a section title like:
\section{This is the section heading\todo{We should rethink the section title.}}
However, this is throwing the “Not in outer par mode” error. I understand why, but I wonder if there is a way to do this.
I had previously asked about putting todo inside a caption, and the proposed solution of \todo[inline]{...}
works in that case, but not inside \section{...}
EDIT: After some help, I realized that the error is in the generation of the table of contents. Here is a MWP:
\documentclass{book}
\usepackage{todonotes}
\long\def\intodo#1{\todo[inline]{#1}}
\begin{document}
\tableofcontents
\chapter{Chapter 1}
\section{Another Section Name \intodo{We should rethink the section title for this as well.}}
\end{document}
The error that I get is:
./test.toc:2: Leaders not followed by proper glue.
<to be read again>
\hfill
l.2 ...e]{We should rethink the section title}}{3}
Best Answer
Similar to Fran's idea, with a macro, but redefining it in the ToC to disable its meaning there, such that
\section[short title]{Other \todo}
is not needed (but possible).In order to get nice output in the ToC, the
\intodo
command should be robust.The
inline
option is not necessary in this approach, since the ToDo - Content does not enter theToC
area.Here's the output if the
inline
option is not used:A variant using the fact that the TOC is typeset in a group to begin with: (proposed by @egreg)