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 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.

share|improve this question
add comment

4 Answers

up vote 12 down vote accepted

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
lorem ipsum\Todo{...} dolor sit amet

where \Todo is defined as:

\usepackage{xspace}
\newcommand{\Todo}[1]{\todo{#1}\xspace}
share|improve this answer
    
... 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
add comment

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.

share|improve this answer
    
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
1  
@Heisenb0rg: Ah, the analogy with \footnote is good. Didn't think of that. –  Hendrik Vogt Feb 23 '11 at 9:04
add comment

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.

share|improve this answer
add comment

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)

share|improve this answer
    
Having \xspace inside the \todo doesn't make much sense. I might have meant: \newcommand{\mytodo}[1]{\todo{#1}\xspace}. –  Martin Scharrer Feb 23 '11 at 8:55
    
@Martin H: Good hint. However, it doesn't work in this form. But \newcommand{\mytodo}[1]{\todo{#1}\xspace} does. EDIT: Oops, duplicate. Martin Sch. was faster... –  Heisenb0rg Feb 23 '11 at 8:57
add comment

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.