TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a document in which certain frequently-occurring entity names are replaced with macros, e.g.:

\newcommand{\entity}{\emph{Name of Entity}}
Lorem ipsum dolor sit \entity, consequat consectetur.

If I define the command like this I get correct formatting if \entity is immediately followed by punctuation (as above) but incorrect formatting otherwise (e.g. Lorem \entity ipsum becomes "Lorem Name of Entityipsum"). If I include the space in the definition of \entity (note space between closing brackets):

\newcommand{\entity}{\emph{Name of Entity} }

I get the opposite behaviour, proper spacing only when not followed by punctuation.

I assume there's some magick command I'm not including in the macro to achieve something sensible?

share|improve this question
Have a look at tex.stackexchange.com/questions/25820/… – lockstep Mar 22 '12 at 16:20
lockstep's link is good; you want to look at the answer that suggests \xspace. – barbara beeton Mar 22 '12 at 16:22
Also have a look at the accepted answer. ;-) – lockstep Mar 22 '12 at 16:23
@lockstep -- \xspace is exactly what I'm after, thanks. Would you care to add that as an answer so I can mark it accepted? – Doches Mar 22 '12 at 16:32
@Doches It seems nobody but me likes the "delimited macro" approach. ;-) – lockstep Mar 22 '12 at 16:33
up vote 6 down vote accepted

Although I personally prefer the "delimited macro" approach described here, you will probably want to use the \xspace macro provided by the package of the same name.

share|improve this answer

Put a backslash or an empty group after \entity when you want a space.

\newcommand{\entity}{\emph{Name of Entity}}
Lorem \entity\ ipsum
Lorem \entity{} ipsum
share|improve this answer
That works, but I'd greatly prefer a way to make the macro behave sensibly that doesn't require me to manually encode spaces. – Doches Mar 22 '12 at 16:20
You could put the "\ " in the command declaration of course if you know that you always want the space there... – jonalv Mar 22 '12 at 16:25
That's the problem I'm trying to solve, @jonalv -- I would like to use the same macro with and without a following space, and would like LaTeX to figure out which is which. If I define \entity as \newcommand{\entity}{\emph{Name of Entity} } I also get this behaviour ("\ " seems equivalent in command definitions to " "). – Doches Mar 22 '12 at 16:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.