Are there compelling reasons to stick with \newcommand or should one always use \NewDocumentCommand instead, even when not using any of the additional features offered by xparse?

In addition and more specifically,

  • If I already require xparse to define one of the macros of my document/package/class, is it a good idea to use \NewDocumentCommand for all my other macro definitions?

  • Will \newcommand eventually get deprecated/discouraged in favor of \NewDocumentCommand with LaTeX3?

  • You should use \newcommand which will never be deprecated. \NewDocumentCommand is from the experimental LaTeX3 and more a command for package writers.
    – user2478
    Feb 14 '13 at 7:25
  • 2
    @Herbert I have to disagree here. yes \DeclareNewCommand is from the latex3 code in the version that runs on top of current LaTeX but the days that we classified all of that as experimental is long gone. These days there is a large stable part (kernel code of expl3 and some packages of which xparse is one). Also xparse is "user interface" for LaTeX2e-like syntax. Feb 14 '13 at 22:17
  • @Frank: then you should change the description of what LaTeX3 will be ;-)
    – user2478
    Feb 15 '13 at 6:43

\NewDocumentCommand is part of xparse, which is 'LaTeX3-in-2e' code. The team have marked this part as 'stable', meaning that we will maintain this code for use with LaTeX2e in an ongoing sense. As such, there is no danger of \NewDocumentCommand vanishing.

Conceptually, \NewDocumentCommand is intended for 'package authors' to define commands, while \newcommand is rather more fluid as it is also used to create variables (macros used as storage). This makes \newcommand a better choice if what you are defining is a variable: we do not have a 'document level' LaTeX3 command for this concept at present. So the decision will depend to some extent on how you see the macros you are defining (commands with no arguments and variables are pretty hard to distinguish!).

Predicting the future is risky, but I think it's extremely unlikely that any stand-alone LaTeX3 format would not define \newcommand, even if the recommendation might be to use other methods. In any case, there are lots of other concepts that I suspect mean that for some arbitrary LaTeX2e document, you won't just be able to process with a stand-alone LaTeX3 format without adjustment.

  • Sorry to dredge up an old thread, but \NewDocumentCommand can create a command that takes no arguments, so this way would (presumeably) be preferred for things like \maketitle (not variables). Has there been any further discussion on this since February that can be referenced? Jun 11 '13 at 3:54
  • @SeanAllred I know it can, but what I mean is that 'insert a token list' can be viewed as a command with no arguments or the use of a token list variable.
    – Joseph Wright
    Jun 11 '13 at 6:14
  • Ahhh, I see. I.e. what is actually stopping something like make title from being used as, say, a stack. Gotcha. Jun 11 '13 at 11:22
  • 4
    @JosephWright is this answer still valid? The xparse package documentation dated 23rd of August, 2018 states: “The xparse package provides a high-level interface for producing document-level commands. In that way, it is intended as a replacement for the LATEX 2 ε \newcommand macro.” Sep 11 '18 at 18:44

To expand Joseph's answer about commands and values: Macros defined with \NewDocumentCommand are robust, they don't get expanded when e.g. moved to the .toc. This is a good thing for commands like \cite which should do something in the .toc but in general is not wanted for values which can change in a document and where you want to transport the current content to the .toc and not only the name of the command. As an example:





\section{\testA, \testB}


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.