11

I'm using the todonotes package to add little margin notes to my text, however writing

Hello\todo{test} World!

removes the interword space as is already pointed out in this question. So I tried

\pretocmd{\todo}{\@bsphack}{}{}
\apptocmd{\todo}{\@esphack}{}{}

and this adds the interword space but simply outputs all parameters instead of passing them to \todo.

Full MWE:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{todonotes}

\makeatletter
\pretocmd{\todo}{\@bsphack}{}{}
\apptocmd{\todo}{\@esphack}{}{}
\makeatother

\begin{document}
Hello\todo{test} World!
\end{document}

2 Answers 2

16

Since \todo is defined with \newcommand to have an optional argument, the macro to patch is really

\\todo

(with a backslash in its name), so it's difficult to specify it: you can patch it using \csname or do it with the xpatch package:

\documentclass{article}

\usepackage{todonotes}
\usepackage{xpatch}

\makeatletter
\xpretocmd{\todo}{\@bsphack}{}{}
\xapptocmd{\todo}{\@esphack}{}{}
\makeatother

\begin{document}
Hello\todo{test} World!
\end{document}

With etoolbox you'd have to write

\expandafter\pretocmd\csname\string\todo\endcsname{\@bsphack}{}{}
\expandafter\apptocmd\csname\string\todo\endcsname{\@esphack}{}{}
2
  • Out of curiosity, what do \[be]sphack do (or perhaps more appropriately, which package are they from)? Commented Mar 3, 2014 at 17:41
  • 1
    @SeanAllred They're defined in the LaTeX kernel
    – egreg
    Commented Mar 3, 2014 at 17:41
8

You can achieve this easier. Since the definition of \todo simply is

\newcommand{\todo}[2][]{\@todo[#1]{#2}}%

you can just redefine it (in a slightly safer way than the original definition, see Bruno Le Floch's comment to this answer (thanks!)):

\documentclass{article}
\usepackage{todonotes}

\makeatletter
\renewcommand{\todo}[2][]{\@bsphack\@todo[{#1}]{#2}\@esphack}%
\makeatother
\begin{document}

Hello\todo{test} World!

\end{document}
4
  • yes, but I was hoping to solve the problem without redefining the command explicitly so that (a) I'd learn more and (b) I'm less vulnerable to future changes to the structure of the command ;)
    – Jonathan
    Commented Aug 25, 2012 at 14:24
  • I wouldn't worry about (b) too much. \todo obviously is a simple wrapper for the actual notes command. So I guess \todo's definition is unlikely going to change.
    – cgnieder
    Commented Aug 25, 2012 at 14:40
  • 1
    Well, the definition of \todo is currently not very good since the first argument cannot contain ]. The normal technique to include those in optional arguments is to add braces around the first argument: \todo[{...[]...}]{...}, but \@todo will see \@todo[...[]...]{...}, and the first argument of \@todo will be [...[] (delimited by the first ]), which is not as expected. A better choice would be to use \@todo[{#1}]{#2} in the definition of \todo. Commented Aug 25, 2012 at 18:56
  • @BrunoLeFloch \todo has only one option where I think that could matter: the caption option, but I agree. If one chooses to redefine \todo one should do it right. I'll edit my answer.
    – cgnieder
    Commented Aug 25, 2012 at 19:03

You must log in to answer this question.

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