Always use \NewDocumentCommand instead of \newcommand?

\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.


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:

\documentclass{article}
\usepackage{xparse}

\begin{document}
\NewDocumentCommand\testA{}{ABC}
\newcommand\testB{ABC}

\tableofcontents

\RenewDocumentCommand\testA{}{CDE}
\renewcommand\testB{CDE}

\section{\testA, \testB}

\end{document}

Tags:

Macros

Latex3