# \newcommand and spacing

How can I define my own shorthand command, but making sure that the spacing afterwards is correct?

\newcommand{\abc}{\textsc{abc}} produces 'ABC,' but has the problem 'ABCmoretexthere' (i.e. no space before the next word).

Vice versa

\newcommand{\abc}{\textsc{abc} } produces 'ABC moretexthere' but has the problem 'ABC ,' (i.e. one space before the comma).

How can I make both work?

-

You can use the package xspace:

\usepackage{xspace}
\newcommand{\abc}{\textsc{abc}\xspace}


This command decides whether to insert a space or not, usually this works well.

-
Thank you, works like a charm. –  Ben May 8 '11 at 12:20
And if you don't want to use xspace, or if there's cases where you don't want to apply the trailing spaces, you can add {} to your macro call, like \abc{}. –  ℝaphink May 8 '11 at 13:21

You can use the package xspace. To avoid the known bug you have to use

\usepackage{xspace}[2006/05/08]
\makeatletter
% usually \check@icr is \@empty and therefore
\begingroup
\text@command\relax
\global\let\xspace@check@icr\check@icr
\endgroup