It's eight years since someone asked Always use \NewDocumentCommand instead of \newcommand? and as I approach the chapter on defining new commands in my LaTeX book, I'm wondering if it makes sense for the default command that users should use for creating their own commands and shortcuts should be \NewDocumentCommand et al. The edge case appears to be where you might want to have the contents of the command expand at write to aux time, e.g., \renewcommand{\thechapter}{...} instead of \RenewDocumentCommand{\thechapter}{...} but it seems to me that the vast majority of cases that a document writer is defining new commands, she would be better served with the xparse commands rather than the older LaTeX2.09-style commands.
Asked
Active
Viewed 145 times
2
Don Hosek
- 14,078
\newcommandalone!! (Either that, or\let\oldcommand\newcommand \let\newcommand\NewDocumentCommand) – Steven B. Segletes May 27 '21 at 19:28\RenewDocumentCommand{\thechapter}{...}is wrong because\thechapterwill be\protectedand often you don't want\the<counter>to be\protected. – Phelype Oleinik May 27 '21 at 20:33LaTeX3 errorrather thanLaTeX error. The appendix about dealing with errors gets a little organizationally weird thanks to that. – Don Hosek May 27 '21 at 20:39\NewExpandableDocumentCommandthough instead of \newcommand to get the non protected, expandable version – David Carlisle May 27 '21 at 20:43LaTeX errorin a future release? – Don Hosek May 27 '21 at 20:57