31

Possible Duplicate:
\newcommand and spacing

In my latex document I have defined a new command to force a consistency in naming of a product I talk in my document:

\newcommand{\fancyName}{\emph{ABC}} 

However I experience a problem that:

\fancyName is a wonderfull and fancy product.

is compiled to:

ABCis a wonderfull and fancy product.

without a space after \fancyName in the compiled text.

Does anybody know how to define a new command and avoid this issue?

2
  • guess it is a dublicate
    – Martin H
    Commented May 10, 2011 at 12:53
  • (La)TeX ignores all spaces after any macro, user defined or not. This is because the space might just be a separator to indicate the end of the macro name. As already states in the answer here and in the duplicate question: Either use {} after the macro, insert an explicit space using \ , ~ (unbreakable), or \space or add \xspace at the very end. It will add a space if the macro isn't used before a punctuation mark. Commented May 10, 2011 at 13:11

1 Answer 1

26

This is a well known "problem". You can either write \macro{} or maybe you consider using

\usepackage{xspace}
\newcommand{\fancyName}{\emph{ABC}\xspace}

xspace should create a space if the macro is used in text but no space if it is at the end of a sentence and followed by a full stop.

1
  • 8
    Another option is to add {} after the macro call, like \fancyName{}.
    – raphink
    Commented May 10, 2011 at 12:55

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