2

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.

Don Hosek
  • 14,078
  • 1
    You know that any new idea, no matter how great it is (especially if it's great) will take a generation to be accepted. That is, until the practitioners, protectors, and defenders literally die off, it won't happen. That said, you leave my \newcommand alone!! (Either that, or \let\oldcommand\newcommand \let\newcommand\NewDocumentCommand) – Steven B. Segletes May 27 '21 at 19:28
  • 3
    Joseph had just an article in tugboat about it, and there is his blog https://www.texdev.net/2020/08/20/newdocumentcommand-versus-newcommand-versus – Ulrike Fischer May 27 '21 at 19:30
  • probably yes, especially as you don't need to mention xparse any more: \NewDocumentCommand is in the format just as \newcommand is. – David Carlisle May 27 '21 at 20:01
  • What others said plus \RenewDocumentCommand{\thechapter}{...} is wrong because \thechapter will be \protected and often you don't want \the<counter> to be \protected. – Phelype Oleinik May 27 '21 at 20:33
  • @PhelypeOleinik You mean where, in the question, I raised the edge case – Don Hosek May 27 '21 at 20:37
  • @DavidCarlisle Grr to xparse issuing a LaTeX3 error rather than LaTeX error. The appendix about dealing with errors gets a little organizationally weird thanks to that. – Don Hosek May 27 '21 at 20:39
  • @DonHosek Right, I misread. Sorry :) – Phelype Oleinik May 27 '21 at 20:43
  • 1
    You can use \NewExpandableDocumentCommand though instead of \newcommand to get the non protected, expandable version – David Carlisle May 27 '21 at 20:43
  • @DavidCarlisle So the plan is that it will be LaTeX error in a future release? – Don Hosek May 27 '21 at 20:57
  • There was some rationalization of the messages but I may have mis-remembered the details (it's still latex3 in latex-dev) I'll delete that comment now and check – David Carlisle May 27 '21 at 21:45

0 Answers0