2

I would like to add a warning in my log when using the \todo command. To do so i did:

\documentclass{book}

\usepackage[colorinlistoftodos,prependcaption,textsize=tiny]{todonotes}

\let\oldtodo\todo
\renewcommand{\todo}[2]{\oldtodo[#1]{#2} \message{Warning: TODO: #2.^^J}}

\begin{document}

\todo{}{Maybe write something meaningful}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

\end{document}

and everything is fine. However, if i change the renew line in:

\renewcommand{\todo}[2][inline]{\oldtodo[#1]{#2} \message{Warning: TODO: #2.^^J}}

I receive the error

! TeX capacity exceeded, sorry [input stack size=5000].
1

Add \usepackage{letltxmacro} to your Preamble.

Instead of \let use \LetLtxMacro.

Explanation: The command has an optional argument.

Thus:

\documentclass{book}

\usepackage[colorinlistoftodos,prependcaption,textsize=tiny]{todonotes}
\usepackage{letltxmacro}

\LetLtxMacro\oldtodo\todo
%\renewcommand{\todo}[2]{\oldtodo[#1]{#2} \message{Warning: TODO: #2.^^J}}

\renewcommand{\todo}[2][inline]{\oldtodo[#1]{#2} \message{Warning: TODO: #2.^^J}}

\begin{document}

\todo{}{Maybe write something meaningful}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

\end{document}
| improve this answer | |
0

The problem is that, internally, the todo package also redefines the \todo command and when you define it as well you get into an infinite loop. Because of this it is better to define a new command, say \Todo, and leave the \todo command alone.

You're also not properly dealing with the optional argument for \todo. The code below fixes both of these problems and it writes

Warning: TODO: Maybe write something meaningful

into the log file. Here is the code:

\documentclass{book}

\usepackage[colorinlistoftodos,prependcaption,textsize=tiny]{todonotes}

\newcommand{\Todo}[2][inline]{%
  \if\relax\detokenize{#1}\relax\todo{#2}%
  \else\todo[#1]{#2}%
  \fi%
  \message{Warning: TODO: #2.^^J}%
}

\begin{document}

\Todo{Maybe write something meaningful}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
sed do eiusmod tempor incididunt ut labore et dolore magna 
aliqua.

\end{document}
| improve this answer | |

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