How can I find out how many arguments (i.e. {} pairs) are used when 'calling' a macro? (my favorite error, that I extend a macro, i.e. it needs one more argument, then I use it to compile a text prepared for a macro having one less argument. I receive a variety of errors, depending of the environment of the macro call in the text.)
In other words: can I find out within the macro, whether it was called with the right number of {} arguments?
\usepackage{xparse} \NewDocumentCommand\macro{gggg}{\IfValueTF{#4}{<your definition with #1, #2, #3, and #4>}{<what you want to output in case of error>}
. You just have to write the letterg
the numer of times of the argument (gggg
in case of four arguments), and also\IfValueTF{#4}
should have also the last argument. For instance, if you want seven arguments, you canggggggg
and\IfValueTF{#7}
. But it's not perfect, and you better do whatever other approach to get to where you want. – Manuel Jul 16 '16 at 18:11