27

I'm writing a larger document and I use the todonotes package to add reminders. For some reason, when I add a note, the space after the note's insertion point is removed. Here's minimal example:

\documentclass[12pt,a4paper,oneside]{book}
\usepackage[textsize=scriptsize,textwidth=2cm,shadow]{todonotes}
\begin{document}
Lorem ipsum dolor sit amet,\todo{stolen space} consectetuer adipiscing elit.
\end{document}

And here's the result I'm getting:

Image of a line with a todo note

And a blown up section of the missing space:

Blown up section, where the space is missing

I thought this might just be an artifact experienced while the notes are active, which would be acceptable since the final document will not have any notes, so I tried to disable them by \usepackage[disable,textsize=scriptsize,textwidth=2cm,shadow]{todonotes}. Now the notes are gone, but the space is still missing. It's bad.

Am I doing something wrong, or is this a shortcoming of the todonotes package?

Also, I have noticed when I add {} to the end of the note (\todo{correct? spacing}{}), the missing space magically re-appears. However, I'm not sure it's a good solution.

Werner
  • 603,163
Heisenb0rg
  • 2,153

4 Answers4

20

I short look in the source of todonotes reveals that both the enabled and disabled version have a \ignorespaces at the end, so yes, it is a feature not a bug. Apparently this is the preference of the package author.

The manual doesn't mention anything about spaces and there is no option to disable the \ignorespaces. Therefore you will need to add the space manually by yourself (as long you don't use your own copy of todonotes.sty with both \ignorespaces removed).

Possible ways to keep the space (some already mentioned in the other answers):

lorem ipsum \todo{...}dolor sit amet
lorem ipsum \todo{...} dolor sit amet
lorem ipsum\todo{...}\ dolor sit amet
lorem ipsum{\todo{...}} dolor sit amet
Martin Scharrer
  • 262,582
  • ... and lorem ipsum \todo{...} dolor sit amet, which I'd prefer. – Hendrik Vogt Feb 23 '11 at 09:06
  • @Hendrik: Yes, you are right. I added that. I think now that this is the preferred form of the package author and the reason he added \ignorespaces. – Martin Scharrer Feb 23 '11 at 09:07
  • @MartinScharrer Please, remove the suggestion of using \xspace; it does more damages than it helps. – egreg Jan 17 '15 at 14:19
  • @egreg: Ok, done! – Martin Scharrer Jan 20 '15 at 22:54
  • 3
    @MartinScharrer The current version of the todonotes manual lists it as a known issue, so I don't think this is the choice of the author: See 1.6.2: http://ctan.math.ca/tex-archive/macros/latex/contrib/todonotes/todonotes.pdf – Canageek May 13 '15 at 20:05
  • The last one was very helpful for a macro, as an additional space might end up before punctuation. It should eat the space before it, not the one after it. – Simon Kohlmeyer Aug 22 '16 at 00:07
14

My best guess is that this is a feature of todonotes and that you're supposed to put a space between the , and \todo. I've tested: This gives correct spacing.

Hendrik Vogt
  • 37,935
  • 1
    I was under the impression \todo worked the same way as \footnote so I never even tried to add a space in front of the command... Thanks for opening my eyes. – Heisenb0rg Feb 23 '11 at 08:55
  • 2
    @Heisenb0rg: Ah, the analogy with \footnote is good. Didn't think of that. – Hendrik Vogt Feb 23 '11 at 09:04
  • 1
    @HendrikVogt The current version of the todonotes manual lists it as a known issue, so I don't think this is the choice of the author: See 1.6.2: he current version of the todonotes manual lists it as a known issue, so I don't think this is the choice of the author: See 1.6.2: – Canageek May 13 '15 at 20:05
  • As of 2022, this appears to be fixed. Spaces are preserved after a \todo{} now. Apparently it was not a feature after all, but a bug. – Fritz Apr 05 '22 at 11:55
4

You can also wrap \@bsphack ... \@esphack around \todo as described in Patching commands to remove surrounding whitespace and the answers explaining how to properly patch commands :)

Concretely, adding

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

to the preamble unintrusively converts \todo to a command that does not take up any space.

Jonathan
  • 2,310
1

This might be a result also observed after commands such as \LaTeX where spaces are 'killed'. So even with the disable option the command is still in the code and apparently somehow interpreted.

A solution might be to add the xspace package and to use

\newcommand{\mytodo}[1]{\todo{#1}\xspace}

(untested)

Martin H
  • 18,164