Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I hope this is just a matter of taste, but is there any reason not to separate a command from its first parameter with a space? (Or multiple parameters with intervening spaces for that matter.)

\chapter{Introduction}
\chapter {Introduction}

\setcounter{chapter}{2}
\setcounter {chapter} {2}

I like the second ones better. This makes prose more readable to me. I was wondering if this can get me into trouble, though.

share|improve this question
5  
I don't think there is any difference in the cases that you mentioned. The are potential issues when a trailing parameter is optional (as is the case for the xstring package for example) -- in which case a space preceding the trailing optional parameter will cause the trailing parameter to not be treated as a parameter, but instead will be treated as text following the macro. –  Peter Grill May 5 at 2:30
1  
In another context, there might be a LaTeX to Some other language converter, that desperately depends on \command{}, i.e. without spaces between command name and arguments. –  Christian Hupfer May 5 at 4:49
2  
From TeX's point of view, there's no difference; spaces after control words are ignored. Also ignored are spaces before arguments (in the normal case of undelimited arguments, the common ones for LaTeX commands). –  egreg May 5 at 6:54
1  
@PeterGrill The space after \chapter and \setcounter in the question does not exist when TeX has tokenized the input, so it can't be mistaken as an argument. –  egreg May 5 at 6:56

1 Answer 1

up vote 12 down vote accepted

The space after a command name is absorbed while parsing the command name and does not make a token at all. The space between the } { does make a character token, but space tokens are skipped when looking for macro arguments so it is fine to put in the spaces if you wish.

\setcounter {chapter} {2}

Note there is a difference between these spaces; if you go

\newcommand\foo{%
    \setcounter {chapter} {2}%
}

In that here, the space after \setcounter really isn't there in the definition of \foo but the space after {chapter} is there, there is a character token so TeX needs to record its value (32) and catcode (10) (although I have a feeling it optimises spaces somewhere, no doubt someone will post the exact line of tex.web) in any case the definition is one or two bytes bigger because of the space. It is unlikely that your documents are big enough that an extra byte will make you run out of memory, but this was a real issue when LaTeX was designed, which is why if you look at the sources of latex and most of the core packages you will see a coding style in which all removable braces and spaces are removed. That doesn't necessarily mean it's a good coding style now:-)

share|improve this answer

Your Answer

 
discard

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.