Remove spaces after a custom definition

This is exactly what the xspace package is for. The manual says:

»After defining \newcommand{\gb}{Great Britain\xspace}, the command \gb will determine when to insert a space after itself and when not.«


Adding to what's already been said, while using xspace, I have discovered that if a macro which contains \xspace as its last argument is followed by text inside {}, then it does not insert a space between the two. In such a situation, one has to use the macro followed by an additional \ and then the text inside {}.

For instance, if I have a macro defined as -- \newcommand{\sdst}{steady-state\xspace} and I use it as -- \sdst {DYNAMICS} then the result would be "steady-stateDYNAMICS" (note the absence of space); whereas, if I use it as -- \sdst\xspace {DYNAMICS} OR \sdst\ {DYNAMICS} then I will get the desired result as -- "steady-state DYNAMICS" (note the inserted space). Just thought I should mention this xspace quirk I noticed during my use of it!

See this insightful comment by the package author David Carlisle, regarding the "oddities of xspace".

Tags:

Macros

Spacing