0

I read this answer which said:

LaTeX does nothing special to allow both forms, it is just on the general TeX macro syntax rules that braces can be omitted if a macro argument is a single token.

I'm just curious, is there a "best practice" or "safer" way between both, if we are talking about (lua)latex? Because I saw a lot of command definitions where people use curly braces around the command name and where they don't. Or is this just a personal preference and nothing more?

Does the answer changes for definitions like \newenvironment or \NewDocumentCommand?

P.S. I'm still new to some stuff so to be more specific, I'm talking about LaTeX2e (but I don't know about differences with just LaTeX).

2

2 Answers 2

2

There's no real difference between

\newcommand{\foo}{...}

and

\newcommand\foo{...}

but usually I stick with the former, because it conforms to the syntax in Lamport's manual. LuaLaTeX or not is unimportant.

For \NewDocumentCommand it's exactly the same. But, of course, you can't do

\newenvironment foo{...}{...}

because the argument is usually a string of more than one character.

Similarly, \setlength\foo{...} is the same as \setlength{\foo}{...}, but

\setcounter foo{...}

would make TeX scream in disgust. 😉

Even if somebody swears that \frac12 is better than \frac{1}{2} you'll never find the former in my typescripts.

1
  • You'll never find \frac12 in my typescripts too:).
    – wipet
    Nov 10, 2022 at 17:02
0

This is mostly the same question as this one.

I understand that in math, where there could be ambiguous commands like \frac110 I absolutely must use curly braces, but with commands that I asked about there's no difference at all. Specifically, when providing a single token argument like \mycommandname. So it indeed comes down to what you prefer. And the only thing that we all know should exist is consistency, that is, you should stick with one way of doing things. And of course readability is something you should keep in mind too.

You must log in to answer this question.

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