Suppose I create a command with xparse

NewDocumentCommand{\myCommand}{ m O{} }{ #1 and #2 }

Could I later in my document change the default value of arg two? Maybe something along these lines?

\def\@myCommand@args@II{New Default}

(II denotes the second argument)

So that later on, \myCommand{Hello} produces "Hello and New Default"

  • Probably specifying the default with a macro that you can later change the definition of.
    – egreg
    Sep 26, 2021 at 14:19
  • @egreg good point--I should be able to use O{\ArgDefault} in the argument spec. Sep 26, 2021 at 14:30
  • Will \myCommand be component of a moving argument? Will \myCommand be, e.g., component of a sectioning-command which ends up in the table of contents and in the bookmarks and in page-headers as well? "moving arguments" in LaTeX are macro-arguments which are carried out at several points of time during compilation so that at one point in time the definition of a macro-token which is component of such a "moving argument" might differ from the definition which the macro-token in question has at another point in time although at each point in time you wish to obtain the same textual phrase... Sep 27, 2021 at 9:38

1 Answer 1


You might do

\NewDocumentCommand{\myCommand}{ m O{\DefaultArgForMyCommand} }{ #1 and #2 }
\NewDocumentCommand{\DefaultArgForMyCommand}{}{}% initially empty

and then do


when you want that the optional argument changes its default value.

However, I can't recommend doing this unless you know without any possible doubt what's the value of \DefaultArgForMyCommand at any given point (I'm not sure you can).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .