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:


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

  • 9
    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{}. – raphink May 8 '11 at 13:21
  • And an alternative to \abc{} is {\abc}. – Friedrich May 2 '20 at 20:34

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

  • 12
    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
  • 2
    @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

I think this is worth mentioning here (from Drawbacks of xspace) because you can use def instead of newcommand and place a / after the name.


It's not usually recommended to use def if you can avoid it, but for simple commands to change the font of a string (for example), it's very handy.

Now use \abc/ in a sentence, and it won't eat up the trailing white space.

The / is a required part of the command's usage, and the compiler will throw an error if you forget:

Now use \abc incorrectly.

Use of \abc doesn't match its definition

This is great because it will ensure that you never forget the /. Using newcommand and {} on the other hand, does not offer the assurance or peace of mind that you won't forget it, and the compiler won't warn you. Consequently, your final document could be missing spaces if you didn't proofread it carefully.

  • 1
    Sometimes you actually intentionally don't want a space next to it, e.g. when the word is the last one in a sentence and the period should not be separated by a space.... – 1010011010 Apr 5 '15 at 21:39
  • 2
    This method is intended to leave the suffix spaces untouched, as the question asked. If you don't want a space, then don't include one after the command is called. \abc/. does not add a space before the period – MasterHD Apr 5 '15 at 23:02

When you create a macro without arguments you should invoke it with an empty statement. For example \abc{} in your case. See https://tex.stackexchange.com/a/31094/36596 for a very good explanation!

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.