Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

2 Answers 2

up vote 15 down vote accepted

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}{}{}
share|improve this answer
    
perfect, thank you! –  Jonathan Aug 25 '12 at 14:43
    
Out of curiosity, what do \[be]sphack do (or perhaps more appropriately, which package are they from)? –  Sean Allred Mar 3 at 17:41
1  
@SeanAllred They're defined in the LaTeX kernel –  egreg Mar 3 at 17:41

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}
share|improve this answer
    
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 Aug 25 '12 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 Aug 25 '12 at 14:40
    
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. –  Bruno Le Floch Aug 25 '12 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 Aug 25 '12 at 19:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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