Time for action – adding intelligent spacing to command output
We will load the package xspace
. Its only purpose is to fulfill this need.
Modify the previous example to get the following code:
\documentclass{article} \usepackage{xspace} \newcommand{\TUG}{\textsc{TeX Users Group}\xspace} \begin{document} \section{The \TUG} The \TUG is an organization for people who are interested in \TeX\ or \LaTeX. \end{document}
Typeset, see that the spacing between the words is correct, even without the backslash:
What just happened?
\usepackage{xspace}
tells LaTeX to load the package called xspace
and to read in all of its definitions. From now on we may use all commands contained in that package. This package provides the command \xspace
that inserts a space depending on the following character: If a dot, a comma, an exclamation, or a quotation mark follows, it won't insert a space, but if a normal letter follows, then it will. Usually, that's exactly what we want.
Imagine you've mentioned the TUG several...