2

I can define a todo command like this:

\newcommand\todo[1]{\textcolor{red}{TODO: #1}}

This command does not work for multiple paragraphs with line breaks in between:

\todo{hello
world}

How can I create such a command that would work on multiple paragraphs?

I am aware of the todonotes package, but would like to know if it's possible with the \newcommand macro.

2
  • 2
    The limitation here is your use of \textcolor{color}{text}, it does not support more than one paragraph You can instead use \newcommand\todo[1]{{\color{red}TODO: #1}}, but I'd go for todonotes or fixme (I use the latter in a modified form that looks like the former)
    – daleif
    Oct 11, 2019 at 7:44
  • Ah, thanks! What an easy fix!
    – reggie
    Oct 11, 2019 at 7:50

2 Answers 2

1

As @daleif has said in comments, the problem is that \textcolor does not allow \par in its argument. Internally, the macro is defined as:

\def\textcolor#1#{\@textcolor{#1}}
\def\@textcolor#1#2#3{\protect\leavevmode{\color#1{#2}#3}}

If \@textcolor would have been defined as \long, you should not have this problem. So you could, in principle redefine this macro, but @daleif´s solution is much more convenient.

\documentclass{article}
\usepackage{xcolor}

\newcommand{\todo}[1]{\textcolor{red}{TODO: #1}}

\begin{document}

\makeatletter
\long\def\@textcolor#1#2#3{\protect\leavevmode{\color#1{#2}#3}}
\makeatother

\todo{Hello 

 world}

\end{document}
1

The limitation here is the use of \textcolor{color}{text} it can only handle up to a single paragraphs worth of text. Simpler method:

\newcommand\todo[1]{{\color{red}TODO: }}

Here the extra {} acts as a group such that the color does not escape.

I would though, take a look at todonotes or fixme instead of doing too many homemade solutions. Fixme can be configured to print the text in the margin in such a way that you can use \fxnote practically everywhere. Since todonotes use \marginpar (at least it did the last time I looked) it has several limitations on where it can be used. Both can also make a list of all the notes in the document '

You must log in to answer this question.

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