4

The xspace package fails when used together with ---:

\documentclass{minimal}
\usepackage{xspace}
\begin{document}

  \newcommand{\twosslvbf}{2 SS l (VBF)\xspace}

  \twosslvbf is OK.

  \twosslvbf --- not OK? % space between ")" and "-" missing

\end{document}

Is there an easy way to repair this? (Or am I using an old version?)

1 Answer 1

3

The hyphen is one of the "exceptions" (like full stop, comma...) where \xspace does not set a space. You can eliminate it from the predetermined list of exceptions through

\usepackage{xspace}
\xspaceremoveexception{-}

in the preamble.

Of course this might have other unwanted effects, for you mostly do not want a space before a hyphen. To correct this behaviour, I copy-paste from the xspace documentation the following trick which ensures that an en- and em-dash have a space after them while a hyphen doesn't:

\documentclass{article}

\usepackage{xspace}
\xspaceremoveexception{-}
\makeatletter
\renewcommand*\@xspace@hook{%
\ifx\@let@token-%
\expandafter\@xspace@dash@i
\fi
}
\def\@xspace@dash@i-{\futurelet\@let@token\@xspace@dash@ii}
\def\@xspace@dash@ii{%
\ifx\@let@token-%
\else
\unskip
\fi
-%
}
\makeatother

\newcommand{\gm}{Grassmann\xspace}

\begin{document}
\gm is OK. % normal space

\gm-valued spinor works too. % no space, as it should.

\gm -- followed by en-sash % space

\gm --- Who was this guy? % space
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .