Hi,

I wand to write a macro, that handles both [] and {} as optional 
arguments. For example, I have a command with three optionl arguments

[#1][#2]#3

I want

\command                to give #1=\empty, #2 = \empty, #3 = \empty

\command [1]            to give #1=1, #2 empty, #3 empty,

\command [1] {3}        to give #1=1, #2 empty, #3 = 3

\command [1] [2] {3}    to give #1=1, #2=2, #3=3

\command {3}            to give #1=empty, #2=empty, #3=3.

I tried the following macro, it works except for \command[1][2]{3}.

\def\finalcommand[#1][#2]#3%
   {1 :-> (#1), 2 :-> (#2), 3 :-> (#3)}

\def\command%
   {\dodoubleempty\docommand}

\def\docommand[#1][#2]%
   {\dodoublegroupempty{\finalcommand[#1][#2]}}

\starttext

\command

\command [1]

\command [1] {3}

\command [1] [2] {3}

\command {3}

\stoptext

which gives

1 :-> (), 2 :-> (), 3 :-> ()
1 :-> (1), 2 :-> (), 3 :-> ()
1 :-> (1), 2 :-> (), 3 :-> (3)
1 :-> (1), 2 :-> (2), 3 :-> () 3 <--------- This does not work
1 :-> (), 2 :-> (), 3 :-> (3)

Can someone suggest a better way to do this?

Aditya

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to