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.

Consider:

\documentclass{article}
\usepackage{xspace}
\begin{document}
(something\xspace)

[something\xspace]

\{something\xspace\}
\end{document}

Or more to the point:

\documentclass{article}
\usepackage{xspace}
\newcommand{\something}{something\xspace}
\begin{document}
(\something)

[\something]

\{\something\}
\end{document}

Either of these yields:

xspace output image

So the question is, why does \xspace produce a space before ] and } but not )? I find this very annoying. I would much rather it produces no space in any of these three circumstances. I know I can get rid of the space by using \xspace{} or \something{}, but it sort of defeats the purpose, which is primarily to define my own macros so that I don't need to think about whether I need {} afterwards, and can just use the macro as if it were a word.

Do people consider this a bug? And if so, how should I report it?

share|improve this question
add comment

2 Answers

up vote 15 down vote accepted

The author(s) of xspace didn't included ] and \} in the list of exceptions. Why? No Idea. But there is \xspaceaddexceptions which allows you to add them:

\documentclass{article}
\usepackage{xspace}
\xspaceaddexceptions{]\}}
\newcommand{\something}{something\xspace}
\begin{document}
(\something)

[\something]

\{\something\}
\end{document}

Result:

Result

share|improve this answer
    
effectively the author(s) didn't include } and ] in the list of exceptions; I copied the original list in my answer. Since you answered first and both our answers are basically the same, I don't mind deleting mine. I just wanted you to notice that you can remove the "It seems that" part of your answer. –  Gonzalo Medina Apr 7 '11 at 16:47
    
@Gonzalo: Thanks. I don't think any of the answers must be deleted. You also have the complete list of characters which is interesting. –  Martin Scharrer Apr 7 '11 at 16:53
    
Thanks, I upvoted both but accepted this, since it was first. –  frabjous Apr 9 '11 at 19:19
add comment

xspace uses a list of exceptions to decide when to add a space; the original definition of the list is:

\def\@xspace@exceptions@tlp{%
,.’/?;:!~-)\ \/\bgroup\egroup\@sptoken\space\@xobeysp
\footnote\footnotemark
}

As you see, ) is included in the lsit, but } and ] are not, so xspace will add a space. If you want to remove the space for this characters, add } and ] to the list by using \xspaceaddexceptions{]\}}.

share|improve this answer
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.