2

I have a quite specific question and I haven't found it in the documentation of xparse or in the forum. In the documentation of xparse, page 3, there are three examples:

\NewDocumentCommand{\foo}{o}{#1}
\NewDocumentCommand{\foobar}{o}{#1}
\NewDocumentCommand{\foobaz}{o}{#1}

in which {\foo}, {\foobar} and {\foobaz} are written in braces {...}.

Later, on page 4, there are other examples, but, now they are not in the braces {...}:

\NewDocumentCommand \foo { m o m } { ... }
\NewDocumentCommand \foobar { m o } { ... }
\NewDocumentCommand \foobar { m !o } { ... }

And this is where my question comes in. When is it necessary to put the name of the command between the {braces}?

  • It is not necessary. As the argument (the macro name) for \NewDocumentCommand is a single token, TeX will treat either the same way. Personally, I prefer the unbraced version, as it looks (to me, of course) better and less likely that someone will try to define \NewDocumentCommand{\foo123} when the braces aren't there, as it happens quite often for \newcommand... – Phelype Oleinik Dec 26 '19 at 12:58
  • @PhelypeOleinik Hi, so the same rule applies for \newcommand, \def, etc ... this examples are a little unfortunate at this point :( – Pablo González L Dec 26 '19 at 13:13
  • 1
    @PabloGonzálezL \newcommand yes but not \def that can not have braces around the command name. – David Carlisle Dec 26 '19 at 13:20
  • 2
    Not to \def. \def{\foo}{...} will raise an error because it's a TeX primitive. \newcommand (and family) and \NewDocumentCommand (and family) will grab the command name as argument and eventually pass it unbraced to the underlying \def. On the other hand, \def\foo123{...} will work. The examples mix styles (they probably shoudn't), so you get misleading examples. – Phelype Oleinik Dec 26 '19 at 13:21
  • @PhelypeOleinik The mix of examples was causing me confusion, with the link given by David Carlisle more than clear, I vote to mark this question as duplicated and close it. – Pablo González L Dec 26 '19 at 13:32

0 Answers0