3

Consider the following (xpatch-fu from https://tex.stackexchange.com/a/68741/17423)

\documentclass{article}

\usepackage[marginpar]{todo}
\usepackage{xpatch}
\makeatletter
\xpretocmd{\todo}{\@bsphack}{}{}
\xapptocmd{\todo}{\@esphack}{}{}
\makeatother

\begin{document}
Some text %
\todo{this text shouldn't be displayed}
more text
\end{document}

gives (without my attempt to fix)

enter image description here

As you can see, the interword spacing between text and more is doubled. Looking at the use of the macro, this makes perfect sense as to why, but this is certainly undesirable behavior (at least for the marginpar option).

My fix is entirely ineffective and actually inserts everything after \todo into the input stream. :(

How can I get the behavior I need?


with above xpatch-fu

output

Sean Allred
  • 27,421
  • I'm not sure I understand the question, but the two spaces you get correspond to the the one after Some text and the one after the \todo command. Why not removing one of those two spaces? – jub0bs Mar 03 '14 at 17:18
  • @Jubobs That was planned. I can't be sure that the people who use the class are going to trim trailing spaces—or even know why it's necessary—so I'm trying to bake the better behavior into the class file. – Sean Allred Mar 03 '14 at 17:20
  • 3
    This looks like a duplicate: http://tex.stackexchange.com/q/68737/ – cgnieder Mar 03 '14 at 17:21
  • 1
    It certainly looked like a duplicate, but unfortunately it isn't. I have updated my question. – Sean Allred Mar 03 '14 at 17:53

1 Answers1

5

Add the following lines in your preamble:

\makeatletter
\xapptocmd{\@displaytodo}{\ignorespaces}{}{}
\xapptocmd{\@donetodo}{\ignorespaces}{}{}
\xapptocmd{\@@displaynothing}{\ignorespaces}{}{}
\makeatother

and you should achieve what you want.

The macro \todo isn't patchable directly, so we patch all the macros called by it.

MWE:

\documentclass{article}

\usepackage[marginpar]{todo}
\usepackage{xpatch}
\makeatletter
\xapptocmd{\@displaytodo}{\ignorespaces}{}{}
\xapptocmd{\@donetodo}{\ignorespaces}{}{}
\xapptocmd{\@@displaynothing}{\ignorespaces}{}{}
\makeatother

\begin{document}
Some text %
\todo{this text shouldn't be displayed}
more text
\end{document} 

Output:

enter image description here

karlkoeller
  • 124,410