29

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?

Skarab
  • 1,731
  • guess it is a dublicate – Martin H May 10 '11 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. – Martin Scharrer May 10 '11 at 13:11

1 Answers1

24

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.

Martin H
  • 18,164