Spacing – Why Does \xspace Behave Differently for Parentheses vs. Braces/Brackets?

spacingxspace

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?

Best Answer

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

Related Question