In his answer to a recent question of mine, @egreg advised \newcommand instead of \NewDocumentCommand to define a container for a text. And I'm aware of this (10 years old!) question where:
Joseph Wright answers “Conceptually,
\NewDocumentCommandis intended for 'package authors' to define commands”. But it is so simpler to define optional arguments (and even starred variants) with\NewDocumentCommandthat I don't see why not advise it to document authors.Ulrike Fischer answers “Macros defined with
\NewDocumentCommandare robust, they don't get expanded when e.g. moved to the.toc”. But the issue with\NewDocumentCommandexample she gave there can be avoided with\NewExpandableDocumentCommand:\documentclass{article} % \usepackage{xparse} % <- useless nowadays\begin{document} \NewDocumentCommand\testA{}{ABC} \newcommand\testB{ABC} \NewExpandableDocumentCommand{\testC}{}{ABC} % <- added by me
\tableofcontents
\RenewDocumentCommand\testA{}{CDE} \renewcommand\testB{CDE} \RenewExpandableDocumentCommand{\testC}{}{CDE} % <- added by me
\section{\testA, \testB , \testC % <- added by me }
\end{document}
Hence I wonder why not use:
\NewDocumentCommand(and friends) as document author?\NewExpandableDocumentCommandto define a container for a text?
I agree that it wouldn't be ideal to mix \NewExpandableDocumentCommands and
\NewDocumentCommands in the same preamble, the former for variables
(i.e. container of text i.e. macros used as storage) and the latter for
commands. But mixing \newcommands and \NewDocumentCommands would look
worse.
Moreover, the arguments in this answer also are in favor of \NewDocumentCommand and \NewExpandableDocumentCommand.
So I know this has been already discussed but, since xparse is now in the kernel, I'd like to know if there are still strong arguments against \NewDocumentCommand and \NewExpandableDocumentCommand for document authors (I'm inclined to promote them in my LaTeX's courses).
Edit
(Here is a bit of context that might explain the current question.)
My concern here is what to teach to beginners or intermediate users of LaTeX. I used to teach \newcommand{\dst}{Dostoïevsky} as an example of a nice feature of LaTeX for a student who has to write a long report on Dostoïevsky. And, of course, I didn't stop there: for students in history, I used to teach:
\newcommand{\century}[1]{\textsc{#1}\ieme{}~siècle}(sorry in French, “siècle” being “century” and with thebabel-frenchfeature\ieme),- and even
\newcommand{\century}[2][\ieme]{\textsc{#2}#1~siècle}since, in French, there is an exception only for the 1st century (ignoring negative centuries):\century[\ier]{i}.
And I was after a way to replace this by the more modern, flexible and, I hoped, uniform way of defining variables/commands: the “xparse”' way.



\NewExpandableDocumentCommandfor just "container for text" is just the extra overhead (which on any reasonable computer nowadays will only be noticeable if you use it tens of thousands of times) – Phelype Oleinik May 16 '23 at 13:24\documentclass{article} \newcommand\testA{blub}\NewExpandableDocumentCommand\testB{}{blub} \begin{document}xxx {\tracingmacros=1 \testA } xxx {\tracingmacros=1 \testB } \end{document}– Ulrike Fischer May 16 '23 at 13:29\expandafterand\noexpandand such things inThe TeXbookand try to create some commands there by\def(just as an alternative and training method of\NewDocumentCommandand\NewExpandableDocumentCommand) – koleygr May 16 '23 at 13:29\NewDocumentCommand{\foo}{}{text}(so without any argument) to not behave just as\NewExpandableDocumentCommand{\foo}{}{text}? – Denis Bitouzé May 16 '23 at 13:29textwas just text and did not have any commands that require protection? – David Carlisle May 16 '23 at 13:47\NewExpandableDocumentCommandfor the former and\NewDocumentCommandfor the latter. – Denis Bitouzé May 16 '23 at 19:26\NewExpandableDocumentCommandas simple as\newcommand's one. – Denis Bitouzé May 16 '23 at 19:28\defor\protected\def. I need nothing more. – wipet May 16 '23 at 20:17\people{dst}, which would also have the benefit that spaces are not swallowed, something newbies don't like. – Ulrike Fischer May 16 '23 at 20:21\peoplewould be designed to accept other arguments than justdst. In such a case, its definition would be out of the scope of a LaTeX course for beginners (some of the students are in their first year at university). For courses to intermediate LaTeX users, I insist on semantic information. – Denis Bitouzé May 16 '23 at 20:33\defis too risky to be explained to beginners and even intermediate users: they might do\def\par{whatever}. – Denis Bitouzé May 17 '23 at 05:33\def\par{whatever}or\def\fi{finito}without any problems in OpTeX because it uses its internal namespace. But, I understand, now we are talking about LaTeX which includes very old concept without different name spaces. – wipet May 17 '23 at 05:58