ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: ConTeXt Marcro Quesiton
Date: Mon, 5 Feb 2007 19:33:06 -0500 (EST)	[thread overview]
Message-ID: <alpine.WNT.0.82.0702051930350.2248@nqvgln> (raw)
In-Reply-To: <alpine.WNT.0.82.0702051900420.2248@nqvgln>

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

  reply	other threads:[~2007-02-06  0:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-06  0:15 Aditya Mahajan
2007-02-06  0:33 ` Aditya Mahajan [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.WNT.0.82.0702051930350.2248@nqvgln \
    --to=adityam@umich.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).