These commands are part of the LaTeX3 Project xparse
package. This question is to satisfy curiosity…
From xparse
documentation released on 25 Nov 2014:
\DeclareDocumentCommand
will always create the new definition, irrespective of any existing with the same name.
\NewDocumentCommand
will issue an error if has already been defined.
Is this the equivalent of \def
and \newcommand
?
In what situation would I need this?
Best Answer
Not quite:
\DeclareDocumentCommand
has the same syntax as\NewDocumentCommand
, unlike\def
with respect to\newcommand
. But the documentation seems clear about it: with\DeclareDocumentCommand
, there is no check that the command name you give as argument already has a definition.Don't forget there's also
\RenewDocumentCommand
.I know a few ones, but I usually recommend using
\NewDocumentCommand
. Don't use\DeclareDocumentCommand
. I hope the team will also provide\NewExpandableDocumentCommand
.What's the usage of
\DeclareDocumentCommand
? Every time you have to do\let\foo\relax
and\DeclareRobustCommand\foo{...}
, then it's time to\DeclareDocumentCommand
. If you don't know what I mean, then use\NewDocumentCommand
and live happier.