Drawbacks of xspace
I originally implemented xspace a long time ago (for LaTeX 2.09) as, like most LaTeX beginners, I'd had a document where I had omitted a {}
or \
and so had a missing space in the final document.
The original version used a very simple nested test for following punctuation, but it could get the test wrong in some (well rather a lot really) of cases. Morten made the tests a lot better so the current version makes the correct choice in more cases and is more easily customised, however making the tests more complicated highlights the problem with this kind of package.
The rule in TeX is really quite simple, after a command name that uses letters (as opposed to single character command names using non-letters such as \$
) white space is ignored.
It is easy to forget to use \
or {}
but the result of forgetting is very predictable, you lose white space in the result. Conversely with xspace
the macro will get the correct space most of the time, but it isn't easy to predict when it will get it wrong, and so it's much harder to learn to enter the markup in a way that is always correct rather than having to always visually check for missing space, which rather negates the purpose of the command.
So, if you find it useful, fine, it's there. But personally I wouldn't recommend it.
It has been mentioned on the site before, however, it seems to me that it can have its place here. You can define your commands in such a way that you can't forget the space at all. This is done by defining:
\def\ES/{Einstein}
(you can't use \newcommand
for this). This way, the proper syntax in-document is
The physisist \ES/ proved the so-called \ES/'s theorem.
You can test yourself that the space in \ES/ proved
does not get eaten, because in real, the trailing /
is not part of the name of the macro, but rather a sort-of "obligatory fixed-valued argument", that is called macro delimiter in TeX's jargon. If you omit this /
and try to write \ES proved
, you get a not-so-cryptic error message
Use of \ES doesn't match its definition
which means exactly what it says: You defined \ES
it to be followed by /
and this is missing.
However, the best thing to do is not to define shorthands like \ES
for Einstein. Then you don't need xspace
and you can't reach any such problems.