26

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.

  • I think you are right. Sorry, Martin, Hendrik is correct, and so is egreg. – Heisenb0rg Jan 25 '17 at 23:04
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.

  • 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 8:55
  • 2
    @Heisenb0rg: Ah, the analogy with \footnote is good. Didn't think of that. – Hendrik Vogt Feb 23 '11 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 '15 at 20:05
19

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
  • ... and lorem ipsum \todo{...} dolor sit amet, which I'd prefer. – Hendrik Vogt Feb 23 '11 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. – Martin Scharrer Feb 23 '11 at 9: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: ctan.math.ca/tex-archive/macros/latex/contrib/todonotes/… – Canageek May 13 '15 at 20:05
3

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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