Tell me more ×
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 certain I have read that xspace can cause more problems than it solves. But I cannot find anything to that effect either on this site or the web. Are there any drawbacks or risks associated with it?

share|improve this question
5  
The example @lockstep refers to is \newcommand{\test}{\emph{test}\xspace} and still the problem exists: the italic correction is inserted in situations such as \test,, which is wrong. I never recommend (nor use myself) xspace. :) – egreg Dec 11 '12 at 17:59
agreed, @egreg I don't think it was one of my better ideas. – David Carlisle Dec 11 '12 at 18:57
@egreg: so you always insert spaces manually, or you do something clever? – Mohan Dec 11 '12 at 19:09
2  
\newcommand{\newentity}[3][/]{\@ifdefinable{#2}{\def#2#1{#3}}} and then \newentity{\foo}{\emph{foo}} will define \foo to require / after it; or \newentity[|]{\bar}{\textbf{bar}} would require \bar|. As usual \makeatletter and \makeatother are necessary around the definition of \newentity; \newentity will throw an error if the command is already defined. – egreg Dec 11 '12 at 22:54
show 2 more comments

1 Answer

up vote 32 down vote accepted

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.

share|improve this answer
9  
Please add this discussion to the package documentation. – Martin Schröder Dec 18 '12 at 19:16

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.