Why does \xspace behave differently for parenthesis vs. braces/brackets?
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:
The xspace
package 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 list, 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{]\}}
.