28

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?

25

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

  • 1
    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
  • 1
    @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
  • I used \xspaceaddexceptions{[]\{\}} because opening brackets are also symbols which cause some whitespace in my text. – PLG Apr 21 '16 at 5:48
23

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{]\}}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.