Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 43 down vote accepted

You can use the package xspace:


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

share|improve this answer
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

% usually \check@icr is \@empty and therefore
% not appropriate for \xspaceaddexceptions.

See latex bug report tools/3895

share|improve this answer
N.B. This bug should be fixed in the next release of LaTeX2e, scheduled for TeX Live 2011. –  Will Robertson May 8 '11 at 12:00
Thank you for the addition. How can I close this thread? –  Ben May 8 '11 at 12:25
@Ben: You don't. Questions remain open forever, unless they are irrelevant or duplicate or something like that. You have accepted an answer, and that more or less closes the discussion in practice. Marco's answer stays unless he decides to delete it. Have you seen the FAQ: tex.stackexchange.com/faq? –  Ryan Reich May 8 '11 at 12:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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