On 2024-10-16 17:48, Wolfgang Schuster wrote:
Rik Kabel schrieb am 16.10.2024 um 23:18:
<stuff deleted for brevity in replying.>

When you have argument after square brackets you have to use #: to continues scanning for arguments of the command. For the mandatory argument you should just use #2 and keep #= for the optional arguments which are only used when text enclosed in curly braces appears. The #* between the third and fourth argument allows spaces between them.

%%%% begin example
\tolerant\protected\def\Bi[#1]#:#2#*#=#*#=%
  {(1=#1)%
   (2=#2)%
   (3=#3)%
   (4=#4)}

\starttext

[\Bi[one]{two}{three}{four}]

[\Bi [one] {two} {three} {four}]

[\Bi [one] {two} {three}]

[\Bi [one] {two}]

[\Bi {two}]

[\Bi [one] {two}]

\stoptext
%%%% end example

To check whether a argument is empty or not you can use the \ifparameter command with the parameter to check (i.e. #1) as argument (don't forget the \or) but \doifempty etc. work as well.

%%%% begin example
\tolerant\protected\def\Bi[#1]#:#2#*#=#*#=%
  {\ifparameter#1\or
     First argument is used.
   \else
     First argument is missing or empty.
   \fi}

\starttext

\Bi {bar}

\Bi [] {bar}

\Bi [foo] {bar}

\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
___________________________________________________________________________________

Excellent, and thank you for the explanation. I guess #? is still available.

(I had tried with #:, but not in combination with [#1] and #= for the last parameter).

--
Rik