0

When I define a variable:

\def\company{ACME}

And use it:

The company \company is...

I usually have the trailing space eaten by the command resulting in The company ACMEIs

So I do the following:

The company \company~is...

Is there a better option?

nowox
  • 1,375

1 Answers1

1

As @Zxcvasdf already explained, you can use \company{} instead of \company. If you don't want to type {} all the time (maybe because they are hard to type with your keyboard layout or you need \company very often) you can also use the xspace package. It provides the command \xspace which produces a space whenever it is needed.

\documentclass{article}
\usepackage{xspace}
\def\company{ACME\xspace}
\begin{document}
    The company \company is great! % <- space is inserted 
    I like the company \company.   % <- no space is inserted
\end{document}

Result

Let me briefly comment on why you should not use ~ here for inserting a space: ~ produces a non-breaking space, i.e. there cannot be a line break between these two words. Sometimes this is good style, e.g. in See Figure~\ref{fig} because you do not want to have Figure and the referenced number in different lines, but here there is no reason why you should not allow a line break.

Οὖτις
  • 2,897
  • 1
  • 5
  • 18
  • 1
    Note that in general \xspace is not recommended as there are unhandled edge cases. Even its creator recommends not using \xpsace. It is best to use \company{} – daleif Mar 03 '23 at 08:39
  • 1
    https://tex.stackexchange.com/questions/86565/drawbacks-of-xspace/86620#86620 – David Carlisle Mar 03 '23 at 08:49