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.

1
  • I think you are right. Sorry, Martin, Hendrik is correct, and so is egreg.
    – Heisenb0rg
    Jan 25, 2017 at 23:04

4 Answers 4

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.

4
  • 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, 2011 at 8:55
  • 2
    @Heisenb0rg: Ah, the analogy with \footnote is good. Didn't think of that. Feb 23, 2011 at 9: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, 2015 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 5, 2022 at 11:55
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
6
  • ... and lorem ipsum \todo{...} dolor sit amet, which I'd prefer. Feb 23, 2011 at 9: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. Feb 23, 2011 at 9:07
  • @MartinScharrer Please, remove the suggestion of using \xspace; it does more damages than it helps.
    – egreg
    Jan 17, 2015 at 14:19
  • @egreg: Ok, done! Jan 20, 2015 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: ctan.math.ca/tex-archive/macros/latex/contrib/todonotes/…
    – Canageek
    May 13, 2015 at 20:05
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.

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)

0

You must log in to answer this question.

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