5

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}
3
  • Please add a MWE. The following works fine: \documentclass{article} \usepackage{todonotes} \begin{document} \section{This is the section heading\todo{We should rethink the section title.}} bla \end{document} Feb 25, 2017 at 1:14
  • The inline option works for me, please see my answer.
    – Masroor
    Feb 25, 2017 at 1:46
  • You can actually use the \todo command in the \section macros etc. unless it is not written to the ToC.
    – user31729
    Feb 25, 2017 at 11:48

3 Answers 3

6

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 the ToC area.

\documentclass{article}
\usepackage{todonotes}

\DeclareRobustCommand{\intodo}[1]{%
  \todo[inline]{#1}%
}

\addtocontents{toc}{\begingroup\protect\renewcommand{\protect\intodo}[1]{}}
\AtEndDocument{%
  \addtocontents{toc}{\endgroup}
}

\begin{document}
\tableofcontents
\section{Section Name 
\intodo{We should rethink the section title}}
Some text 
\section{Another Section Name\intodo{We should rethink the section title for this as well.}}
More some text 
\end{document}

enter image description here

Here's the output if the inline option is not used:

enter image description here

A variant using the fact that the TOC is typeset in a group to begin with: (proposed by @egreg)

\documentclass{book}

\usepackage{todonotes}
\usepackage{etoolbox}

\newrobustcmd\intodo[1]{\todo[inline]{#1}}

\makeatletter
% fix \intodo so it does nothing in the TOC
\patchcmd{\@starttoc}
  {\begingroup}
  {\begingroup\let\intodo\@gobble}
  {}{}
\makeatother

\begin{document}

\tableofcontents

\chapter{Chapter 1}

\section{Another Section Name \intodo{We should rethink the section title for this as well.}}

\end{document}
7
  • The inline version is working fine, but I cannot get it to work without the inline option. Can you help with the definition, if you don't mind? For example, how to define a rtodo as a robust todo without the inline option. Thanks much.
    – ozsu
    Feb 26, 2017 at 23:53
  • @oszu: Try \DeclareRobustCommand{\rtodo}[1]{\todo{#1}}
    – user31729
    Feb 27, 2017 at 0:11
  • Thanks, I did that. I also added \addtocontents{toc}{\begingroup\protect\renewcommand{\protect\rtodo}[1]{}} \AtEndDocument{% \addtocontents{toc}{\endgroup} } But it is throwing the following error not in the first paragraph in the section, but in the second paragraph: LaTeX Warning: Marginpar on page 9 moved. ./Chap11.tex:381: LaTeX Error: Not in outer par mode.
    – ozsu
    Feb 27, 2017 at 0:25
  • @ozsu: You can't use it in a \caption -- floating environments like figure etc. and \marginpar usage is contradictory. The robustness of a command won't help you here!
    – user31729
    Feb 27, 2017 at 0:29
  • But the DeclareRobustCommand{\intodo}[1]{\todo[inline]{#1}} works. Is there any particular reason the non-inline version should not work?
    – ozsu
    Feb 27, 2017 at 1:56
4

You are trying to insert the todo note in the table of contents as well.

Using \section[title for toc]{title for text\intodo{note text}} will work as expected.

\documentclass{article}
\usepackage{todonotes}
\long\def\intodo#1{\todo[inline]{#1}}
\begin{document}
\tableofcontents
\section[Section Name]{Section Name 
\intodo{We should rethink the section title}}
Some text 
\section[Another Section Name]{Another Section Name
\intodo{We should rethink the section title for this as well.}}
More some text 
\end{document}

BTW, I would start the \intodo macro with a \bigskip.

1
  • Nice Idea (+1) -- I have stolen your \intodo macro ;-)
    – user31729
    Feb 25, 2017 at 11:16
2

Use the inline option. Or better yet, you may even define a macro for this if you have many inline todo's.

See the code below:

\documentclass{article}

\usepackage{todonotes}
\long\def\intodo#1{\todo[inline]{#1}}

\begin{document}

\section{Section Name\todo[inline]{We should rethink the section title}}

\section{Another Section Name \intodo{We should rethink the section title for this as well.}}

\end{document}
2
  • OK, I narrowed down my error. I am using the book class and here is the same example as @Masroor in book style \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}' And the error is in the table of contents generation: ./test.toc:2: Leaders not followed by proper glue. <to be read again> \hfill l.2 ...e]{We should rethink the section title}}{3}'
    – ozsu
    Feb 25, 2017 at 1:50
  • To make sure that this comment stuff is depicted properly, I edited my original question with the same content.
    – ozsu
    Feb 25, 2017 at 1:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .