I am confused by the behaviour of \xspace in combination with the \todo command. I didn't expect \xspace to leave a space when I cut off all spaces by a comment sign %. Usually this works as expected, cf. counterexample.
However, in my context it doesn't work and I cannot really figure out why.
MWE (edit: added counterexample)
\documentclass{scrbook}
\setlength{\parindent}{0pt}
\usepackage{todonotes}
\usepackage{xspace}
% define mtodo WITH xspace
\newcommand{\mtodo}[1]{\todo[fancyline,noline]{#1}\xspace}
% define mmtodo WITHOUT xspace
\newcommand{\mmtodo}[1]{\todo[fancyline,noline]{#1}}
% counterexample
\newcommand{\mylabel}[1]{\label{#1}\xspace}
\begin{document}
% with xspace (mtodo)
\mtodo{Margin Note 1}%
This is an\mtodo{Margin Note 2} example with xspace.\\
This is an example with xspace.
% without xspace (mmtodo)
\mmtodo{Margin Note 1}%
This is an\mmtodo{Margin Note 2} example without xspace.\\
This is an example without xspace.
% without xspace (mmtodo)
\mylabel{label1}%
This is a\mylabel{label1} counterexample.\\
This is a counterexample.
\end{document}

\xspace. Don't use it. – egreg Jan 17 '15 at 13:38