1

I read an article on this website introducing \NewDocumentCommand. However, it does not answer such a question: does it breaks the limit that one \newcommand can have at most 9 arguments?

I found almost the same question here where the author @egreg advices to use a comma-separated list of values, i.e.

\foo{1,2,3,4,5,6,7,8,9,10}

However, I do think that in this way we cannot own all the power of \NewDocumentCommand. I wonder if this is the only way to solve the problem.

PS: I did not meet such a question in reality, and this is just a wonder. I wrote a function with 8 arguments just now, and I am now scared at the situation where some day I want to write a function of more than 9 arguments.

CY Qian
  • 107
  • 1
    No, the 9 argument limit is from TeX. You can't have one macro with more than 9 arguments. You can emulate that in other ways though (for example here: https://tex.stackexchange.com/q/2132/134574) – Phelype Oleinik Mar 06 '21 at 23:29
  • 1
    Will you remember the order of the arguments and their meaning one month after working out the definition? – egreg Mar 06 '21 at 23:30
  • @egreg Yes I believe I can, as I can make comments to it... PS. when we write C++ or python or mathematica problems, we will always have a lot of arguments, but we can still remember their meaning as a result of comments... – CY Qian Mar 06 '21 at 23:33
  • @PhelypeOleinik So can we advice the team to change the style of accessing the n-th argument into something like... \arg{number here} or ##n to ###n Thank you! – CY Qian Mar 06 '21 at 23:43
  • 1
    @CYQian C++ or python arguments are usded by name within a function body, tex ones by number and the syntax #<single-digit> is built in to the tex grammar you can't really make #<digit><digit> do anything – David Carlisle Mar 06 '21 at 23:43
  • 1
    @CYQian expl3 is written in TeX it can not change the fundamental tex grammar, – David Carlisle Mar 06 '21 at 23:45
  • 1
    @CYQian What if I want to use a nested definition (for which I need ##)? Or what if I want to have an actual command called \arg?. That can't be reasonably implemented, sorry (also 9 arguments is just awful to use: I prefer a command that remembers a bunch of defaults and I just give it what it actually needs for each run) – Phelype Oleinik Mar 06 '21 at 23:48
  • 1
    @CYQian I normally forget the order of atan2 (and it has just two arguments! ;-)). Jokes apart, I think the better solution would be to use a key-value package and have something like \macro{x=1, y=0, } etc with sane defaults. That mimics Python named argument and is a breeze to remember. https://tex.stackexchange.com/questions/26771/a-big-list-of-every-keyval-package – Rmano Mar 07 '21 at 10:20

0 Answers0