10

These commands are part of the LaTeX3 Project xparsepackage. 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?

  • 3
    No but the equivalent of \long\def and \newcommand ;-) – touhami Jul 27 '15 at 6:55
  • 1
    @touhami Just to clarify for future reference: \long\def being just a \def that accepts \par tokens (both explicit and implicit paragraphs) in its input... – Jonathan Komar Jan 11 '17 at 12:26
15

Is this the equivalent of \def and \newcommand?

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.

In what situation would I need this?

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.

  • I just dished out €140 for David Bausum's TeX Reference Manual, so I will be delving into all kinds of things that could make me unhappy :D I will follow your advice for now though and live happier. – Jonathan Komar Jul 27 '15 at 7:14

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.