On Mon, 5 Feb 2007, Aditya Mahajan wrote: > 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?
I found another way, I hope that it has no gotcha's \def\finalcommand[#1][#2]#3% {1 :-> (#1), 2 :-> (#2), 3 :-> (#3)} \def\command% {\dodoubleempty\docommand} \def\docommand[#1][#2]% {\def\useoneargument##1{\finalcommand[#1][#2]{##1}} \def\fakeoneargument{\finalcommand[#1][#2]{}} \doifnextcharelse\bgroup{\useoneargument}{\fakeoneargument}} Aditya _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context