* 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
* Re: ConTeXt Marcro Quesiton
2007-02-06 0:15 ConTeXt Marcro Quesiton Aditya Mahajan
@ 2007-02-06 0:33 ` Aditya Mahajan
2007-02-06 9:21 ` Hans Hagen
0 siblings, 1 reply; 7+ messages in thread
From: Aditya Mahajan @ 2007-02-06 0:33 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ConTeXt Marcro Quesiton
2007-02-06 0:33 ` Aditya Mahajan
@ 2007-02-06 9:21 ` Hans Hagen
2007-02-06 15:36 ` Aditya Mahajan
0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2007-02-06 9:21 UTC (permalink / raw)
To: mailing list for ConTeXt users
Aditya Mahajan wrote:
>
>> Can someone suggest a better way to do this?
>>
>
> I found another way, I hope that it has no gotcha's
>
search for group(ed)(empty|argument) in cont-sys.tex
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ConTeXt Marcro Quesiton
2007-02-06 9:21 ` Hans Hagen
@ 2007-02-06 15:36 ` Aditya Mahajan
2007-02-07 13:28 ` Wolfgang Schuster
0 siblings, 1 reply; 7+ messages in thread
From: Aditya Mahajan @ 2007-02-06 15:36 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Tue, 6 Feb 2007, Hans Hagen wrote:
> Aditya Mahajan wrote:
>>
>>> Can someone suggest a better way to do this?
>>>
>>
>> I found another way, I hope that it has no gotcha's
>>
> search for group(ed)(empty|argument) in cont-sys.tex
Did you mean syst-gen.tex? I tied dodoublegroupempty but it did not
work in one case (see previous post) and I can not figure out why.
Aditya
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ConTeXt Marcro Quesiton
2007-02-06 15:36 ` Aditya Mahajan
@ 2007-02-07 13:28 ` Wolfgang Schuster
2007-02-07 18:57 ` Hans Hagen
0 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Schuster @ 2007-02-07 13:28 UTC (permalink / raw)
To: ntg-context
On Tue, 6 Feb 2007 10:36:42 -0500 (EST)
Aditya Mahajan <adityam@umich.edu> wrote:
> On Tue, 6 Feb 2007, Hans Hagen wrote:
>
> > Aditya Mahajan wrote:
> >>
> >>> Can someone suggest a better way to do this?
> >>>
> >>
> >> I found another way, I hope that it has no gotcha's
> >>
> > search for group(ed)(empty|argument) in cont-sys.tex
>
> Did you mean syst-gen.tex? I tied dodoublegroupempty but it did not
> work in one case (see previous post) and I can not figure out why.
>
> Aditya
Hi Aditya,
I tried something similiar and copied a example from core-rul.tex
The following macro use a method copied from textrule and the second
argument between the braces should be optional. I looked into the log
file created with tracingmacros and it seems TeX cannot find the
optional argument.
\long\def\startDEBITS#1\stopDEBITS
{\bgroup
\def\debit{\dosingleempty\dodebit}%
\def\dodebit[##1]%
{\def\dododebit####1{\dodododebit[##1]{####1}}%
\dosinglegroupempty\dododebit}%
\def\dodododebit[##1]##2%
{\hbox to\hsize{\strut##1\hfill##2}}%
\vbox{\hsize4cm\hrule#1\hrule}%
\egroup}
\starttext
%\tracingmacros1
\startDEBITS
\debit [Text] {100} ttt
\debit [Text] {200} xxx
\stopDEBITS
%\tracingmacros0
\stoptext
Hans, can you give us a hint what we are doing wrong or can you make a
simple example to show us how we can create optional arguments between
braces.
Wolfgang
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ConTeXt Marcro Quesiton
2007-02-07 13:28 ` Wolfgang Schuster
@ 2007-02-07 18:57 ` Hans Hagen
2007-02-09 0:30 ` Aditya Mahajan
0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2007-02-07 18:57 UTC (permalink / raw)
To: mailing list for ConTeXt users
Wolfgang Schuster wrote:
> On Tue, 6 Feb 2007 10:36:42 -0500 (EST)
> Aditya Mahajan <adityam@umich.edu> wrote:
>
>
>> On Tue, 6 Feb 2007, Hans Hagen wrote:
>>
>>
>>> Aditya Mahajan wrote:
>>>
>>>>> Can someone suggest a better way to do this?
>>>>>
>>>>>
>>>> I found another way, I hope that it has no gotcha's
>>>>
>>>>
>>> search for group(ed)(empty|argument) in cont-sys.tex
>>>
>> Did you mean syst-gen.tex? I tied dodoublegroupempty but it did not
>> work in one case (see previous post) and I can not figure out why.
>>
>> Aditya
>>
>
> Hi Aditya,
>
> I tried something similiar and copied a example from core-rul.tex
>
> The following macro use a method copied from textrule and the second
> argument between the braces should be optional. I looked into the log
> file created with tracingmacros and it seems TeX cannot find the
> optional argument.
>
> \long\def\startDEBITS#1\stopDEBITS
> {\bgroup
> \def\debit{\dosingleempty\dodebit}%
> \def\dodebit[##1]%
> {\def\dododebit####1{\dodododebit[##1]{####1}}%
> \dosinglegroupempty\dododebit}%
> \def\dodododebit[##1]##2%
> {\hbox to\hsize{\strut##1\hfill##2}}%
> \vbox{\hsize4cm\hrule#1\hrule}%
> \egroup}
>
> \starttext
>
> %\tracingmacros1
> \startDEBITS
> \debit [Text] {100} ttt
> \debit [Text] {200} xxx
> \stopDEBITS
> %\tracingmacros0
>
> \stoptext
>
> Hans, can you give us a hint what we are doing wrong or can you make a
> simple example to show us how we can create optional arguments between
> braces.
>
\long\def\startDEBITS#1\stopDEBITS
{\vbox \bgroup
\hsize4cm
\def\debit
{\dosingleempty\dodebit}
\def\dodebit[##1]%
{\def\dododebit{\dodododebit[##1]}%
\permitspacesbetweengroups
\dosinglegroupempty\dododebit}
\def\dodododebit[##1]##2%
{\dontleavehmode\hbox to\hsize{\strut##1\hfill##2}}
\hrule#1\hrule
\egroup}
\starttext
\startDEBITS
\debit [Text]{100} ttt
\debit [Text] {200} xxx
\stopDEBITS
the magic is in \permitspacesbetweengroups
i suppose some \par needs to be added someplace
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ConTeXt Marcro Quesiton
2007-02-07 18:57 ` Hans Hagen
@ 2007-02-09 0:30 ` Aditya Mahajan
0 siblings, 0 replies; 7+ messages in thread
From: Aditya Mahajan @ 2007-02-09 0:30 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Wed, 7 Feb 2007, Hans Hagen wrote:
> Wolfgang Schuster wrote:
>> On Tue, 6 Feb 2007 10:36:42 -0500 (EST)
>> Aditya Mahajan <adityam@umich.edu> wrote:
>>
>>
>>> On Tue, 6 Feb 2007, Hans Hagen wrote:
>>>
>>>
>>>> Aditya Mahajan wrote:
>>>>
>>>>>> Can someone suggest a better way to do this?
>>>>>>
>>>>>>
>>>>> I found another way, I hope that it has no gotcha's
>>>>>
>>>>>
>>>> search for group(ed)(empty|argument) in cont-sys.tex
>>>>
>>> Did you mean syst-gen.tex? I tied dodoublegroupempty but it did not
>>> work in one case (see previous post) and I can not figure out why.
>>>
>>> Aditya
>>>
>>
>> Hi Aditya,
>>
>> I tried something similiar and copied a example from core-rul.tex
>>
>> [snip]
>>
>> Hans, can you give us a hint what we are doing wrong or can you make a
>> simple example to show us how we can create optional arguments between
>> braces.
>>
> the magic is in \permitspacesbetweengroups
Magic indeed. It works for my case also. I will post an improved
theorem macors to make use of this magic.
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).