[texhax] TeX commands as abbreviations

Karsten Heymann karsten.heymann at googlemail.com
Thu Nov 1 15:23:03 CET 2007


Hi Martin,

2007/11/1, martin f krafft <madduck at madduck.net>:
> also sprach Morten Høgholm <morten.hoegholm at gmail.com> [2007.11.01.1442 +0100]:
> > <http://www.tex.ac.uk/cgi-bin/texfaq2html?label=xspace>
>
> Unfortunately, this does not quite explain the behaviour I now see.
>
> For instance, with
>
>   \newcommand{\foreign}[1] {\emph{#1}}
>   \newcommand{\vs}[1] {\foreign{vs.}\xspace}
>
> "Variance \vs process theory" becomes "Variance vs. rocess theory".
> Properly spaced, but it still eats a character.
>
> I thus went to the source and found that \xspace consumes the next
> character and does nothing if it's not in the exception list. Should
> it not push the character back onto the stream?

The Problem is the [1]. It means "consume the next item after the
command and provide it as #1 to the macro's body". Simply do

\newcommand*{\vs} {\foreign{vs.}\xspace}

Or train yourself to always write \vs\ or \vs{}, so you get used to it
and don't fall over other commands like \LaTeX which are defined
without \xspace. Remembering TeXs behaviour on commands without
arguments is hard enough, having some which don't need handling
doesn't make it easier ;-)

Yours,
Karsten


More information about the texhax mailing list