Pablo Rodriguez via ntg-context schrieb am 26.04.2024 um 17:29:
Dear list,

I have the following sample:

   \starttext
   \def\MyCommand{\doquadruplegroupempty\doMyCommand}

   \def\doMyCommand#1#2#3#4{%
     \iffourthargument
       #4%
     \orelse\ifthirdargument
       #3%
     \else
       #2%
     \fi}

   \MyCommand{}{second}{third}{fourth},\\
   \MyCommand{}{second}{third}{fourth} e,\\

   \MyCommand{}{second}{third},\\
   \MyCommand{}{second}{third} e,\\

   \MyCommand{}{second},\\
   \MyCommand{}{second} e,\\
   \stoptext

I don‘t know why only the command gets the space after right only when
the four arguments are provided.

What is wrong in my definition above?

There is nothing wrong, this is just a side effect of the scanner used with the \do...groupempty commands. To have more control about this behavior use the \tolerant modifier for \def to change it.

%%%% begin example
\tolerant\def\CommandA#_#*#_#*#_#*#_{(#1)(#2)(#3)(#4)}
\tolerant\def\CommandB#_#,#_#,#_#,#_{(#1)(#2)(#3)(#4)}
        
\starttext

A: \CommandA{a}          xxx\par
B: \CommandB{a}          xxx\blank

A: \CommandA{a}{b}       xxx\par
B: \CommandB{a}{b}       xxx\blank

A: \CommandA{a}{b}{c}    xxx\par
B: \CommandB{a}{b}{c}    xxx\blank

A: \CommandA{a}{b}{c}{d} xxx\par
B: \CommandB{a}{b}{c}{d} xxx\blank

\stoptext
%%%% end example

Another way to avoid this is to create a command with a key-value list.

%%%% begin example
\tolerant\def\Command[#1]%
  {\begingroup
   \getdummyparameters[#1]%
   \doifsomething{\dummyparameter{a}}{(\dummyparameter{a})}%
   \doifsomething{\dummyparameter{b}}{(\dummyparameter{b})}%
   \doifsomething{\dummyparameter{c}}{(\dummyparameter{c})}%
   \doifsomething{\dummyparameter{d}}{(\dummyparameter{d})}%
   \endgroup}

\starttext

\Command[a=1,b=2,c=3,d=4] xxx\par
\Command[a=1,c=3] xxx\par

\stoptext
%%%% end example
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to