2

I have read the answers to

Space after LaTeX commands

but the alternative that I currently use is not mentioned:

\newcommand{\arnold}{Arnold Schwarzenegger{}}

which of course is less typing and less error-prone than adding {} after invoking the command. I haven't encountered any problems so far; on the contrary, I noticed that it some complex cases where \xspace inserts an unwanted space, {} gets it right.

So I was just wondering why apparently no one else is using this, and if it might cause problems which I am not aware of.

Edit: After the comments I realised that I always used this approach with a command that has a parameter, so my example should have been

\newcommand{\arnold}[1]{Arnold #1 Schwarzenegger}

That'll teach me to always check my examples no matter how similar to my code they seem to be.

So it's actually the argument that causes the correct spacing rather than the {}. If someone would explain to me why the argument makes a difference, I would be entirely happy.

6
  • 2
    Did you check the output of \arnold \arnold?
    – Mico
    Commented Aug 11, 2019 at 8:33
  • 3
    or even just \arnold text... Commented Aug 11, 2019 at 8:36
  • 4
    the {} in that position does nothing useful at all. Commented Aug 11, 2019 at 8:42
  • With your modified macro, viz., \newcommand{\arnold}[1]{Arnold #1 Schwarzenegger}, \arnold{} text inserts two spaces -- and not just one -- between "Arnold" and "Scharzenegger". Still not right, is it?
    – Mico
    Commented Aug 11, 2019 at 8:58
  • 1
    you ask about adding {} to the replacement text but your modified example doesn't use {} in the replacement text at all so does not fit the title of the question. Commented Aug 11, 2019 at 9:07

1 Answer 1

4

The question is why a space in the source does not produce a space in the output. A space after \arnold is taken to end the command name and is not tokenised so will not produce any output. So in the no-argument form

\arnold text

expands to

Arnold Schwarzenegger{}text

which will typeset as "Arnold Schwarzeneggertext" with the {} doing nothing useful.

Conversely in the form with an argument, it is still true that a space after \arnold is not tokenised so

\arnold {} text

and

\arnold{} text

are parsed the same way and both expand to

 Arnold␣␣Schwarzenegger␣text

so the space after the argument is just treated as a normal word space, but you will get two space tokens space between Arnold and Schwarzenegger.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .