TUGboat 42:1 (2021)
The Communications of the TeX Users Group

Title: \NewDocumentCommand versus \newcommand versus

Summary: extended comparison of the xparse \NewDocumentCommand to traditional alternatives.

Full text of article: publicly available now.

Author: Joseph Wright

Publication: TUGboat volume 42, number 1 (2021), pages 41-43

DOI (this page): 10.47397/tb/42-1/tb130wright-newdoccmd
(previous doi - next doi)

Category: Software & Tools

Difficulty: Intermediate Plus

Abstract: Creating new document commands in LaTeX has traditionally been the job of \newcommand. Over the last decade, the LaTeX team have developed xparse, a generic document command parser, as a way to unify many ideas and provide a single consistent way to create document commands.

In this article, I want to look at why to use this ‘xparse’ approach, and how it compares to existing solutions, both in the LaTeX kernel and the wider package sphere. Here, I’m going to avoid talking about ‘simple’ shortcuts (things such as \newcommand\myname{Joseph}): these are best left to \newcommand. Instead, I want to deal with commands which take arguments and have some element of ‘programming’ to them.

What I’ll seek to highlight here is that using \NewDocumentCommand, we get a single consistent and reliable way to create a variety of commands. There’s no need to worry about clashes between approaches, and it all ‘just works’.


TUGboat 42:1, 2021 (issue 130)   [generated 2021-09-30]
TUG home page; webmaster; facebook; twitter;   (via DuckDuckGo)