0

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.

  • 2
    Did you check the output of \arnold \arnold? – Mico Aug 11 at 8:33
  • 3
    or even just \arnold text... – Andrew Swann Aug 11 at 8:36
  • 3
    the {} in that position does nothing useful at all. – David Carlisle Aug 11 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 Aug 11 at 8:58
  • If you have a command that needs an argument, its 'call' syntax \arnold{foo} already has the pair of braces built-in that one can add to avoid the space getting lost in an argument-less macro \foo{}. TeX only ignores spaces directly after a control word (basically any normal macro name like \foo or \arnold except for special one-character macros like \?). If there are braces or anything else in between the space and the macro, the spaces will be present in the output. – moewe Aug 11 at 9:00
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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