ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* ConTeXt Marcro Quesiton
@ 2007-02-06  0:15 Aditya Mahajan
  2007-02-06  0:33 ` Aditya Mahajan
  0 siblings, 1 reply; 7+ messages in thread
From: Aditya Mahajan @ 2007-02-06  0:15 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-02-09  0:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-06  0:15 ConTeXt Marcro Quesiton Aditya Mahajan
2007-02-06  0:33 ` Aditya Mahajan
2007-02-06  9:21   ` Hans Hagen
2007-02-06 15:36     ` Aditya Mahajan
2007-02-07 13:28       ` Wolfgang Schuster
2007-02-07 18:57         ` Hans Hagen
2007-02-09  0:30           ` Aditya Mahajan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).