ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* system macros/doquadrupleemtpy
@ 2008-09-03 14:41 Thomas A. Schmitz
  2008-09-03 16:58 ` Aditya Mahajan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Thomas A. Schmitz @ 2008-09-03 14:41 UTC (permalink / raw)
  To: mailing ConTeXt users list for

Hi all,

I'm trying to define a macro \Command which can either have four or  
five arguments. If it has five, I want to define them as

\Command1[#1][#2][#3][#4]{#5}

if it has four, as

\Command2[#1][#2][#3]{4#}

I thought this would be the way to go:

\def\Command{%
	\doquadrupleempty\doCommand}

\def\doCommand{%
  	\iffifthargument%
  		\doquadrupleargument\Command1%
  	\else%
  		\dotripleargument\Command2%
  	\fi}

but that gives me errors about "too many }s". So I'm wondering: am I  
on the wrong track? Can this be done at all?

Thanks, and best

Thomas
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: system macros/doquadrupleemtpy
  2008-09-03 14:41 system macros/doquadrupleemtpy Thomas A. Schmitz
@ 2008-09-03 16:58 ` Aditya Mahajan
  2008-09-04  7:39   ` Thomas A. Schmitz
  2008-09-03 18:32 ` Peter Rolf
  2008-09-04  6:45 ` Wolfgang Schuster
  2 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2008-09-03 16:58 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Wed, 3 Sep 2008, Thomas A. Schmitz wrote:

> Hi all,
>
> I'm trying to define a macro \Command which can either have four or
> five arguments. If it has five, I want to define them as
>
> \Command1[#1][#2][#3][#4]{#5}
>
> if it has four, as
>
> \Command2[#1][#2][#3]{4#}
>
> I thought this would be the way to go:
>
> \def\Command{%
> 	\doquadrupleempty\doCommand}

You need something with possibly five arguments so you should use quint 
rather than quad:

\def\Command%
    {\doquintupleargument\doCommand}

> \def\doCommand{%
>  	\iffifthargument%
>  		\doquadrupleargument\Command1%
>  	\else%
>  		\dotripleargument\Command2%
>  	\fi}


The usual way is

\def\doCommand[#1][#2][#3][#4][#5]%
    {\doifelsenothing{#5}%See below
     {\Command1[#1][#2][#3][#4][#5]}
     {\Command2[#1][#2][#3][#4]}}

I use \doifelsenothing rather than \doiffirthargument. If I give

\Command[...][...][...][...][] with \doifelsenothing \Commnad2 will be 
called while with \iffifthargument \Command1 will be called. Use whichever 
is more appropriate for your problem.


> but that gives me errors about "too many }s". So I'm wondering: am I
> on the wrong track? Can this be done at all?

The above code is untested, but I am pretty sure that it will work.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: system macros/doquadrupleemtpy
  2008-09-03 14:41 system macros/doquadrupleemtpy Thomas A. Schmitz
  2008-09-03 16:58 ` Aditya Mahajan
@ 2008-09-03 18:32 ` Peter Rolf
  2008-09-04  6:45 ` Wolfgang Schuster
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Rolf @ 2008-09-03 18:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thomas A. Schmitz schrieb:
> Hi all,
> 
> I'm trying to define a macro \Command which can either have four or  
> five arguments. If it has five, I want to define them as
> 
> \Command1[#1][#2][#3][#4]{#5}
> 
> if it has four, as
> 
> \Command2[#1][#2][#3]{4#}
> 
> I thought this would be the way to go:
> 
> \def\Command{%
> 	\doquadrupleempty\doCommand}
> 
> \def\doCommand{%
>   	\iffifthargument%
>   		\doquadrupleargument\Command1%
>   	\else%
>   		\dotripleargument\Command2%
>   	\fi}
> 
> but that gives me errors about "too many }s". So I'm wondering: am I  
> on the wrong track? Can this be done at all?
>

Hi Thomas!

Hard to say for me whats wrong, but I think its a bad idea to use such
optional parameter commands in a nested way. Also there is no need for a
second parameter number check.

How about something like

\def\doCommand%
  {\iffifthargument
     \CommandA[#1][#2][#3][#4]{#5}%
   \else\iffourthargument
       \CommandB[#1][#2][#3]{#4}%
     \else
       % some error handling
     \fi
   \fi}


Best wishes, Peter

> Thanks, and best
> 
> Thomas
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : https://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
> 

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: system macros/doquadrupleemtpy
  2008-09-03 14:41 system macros/doquadrupleemtpy Thomas A. Schmitz
  2008-09-03 16:58 ` Aditya Mahajan
  2008-09-03 18:32 ` Peter Rolf
@ 2008-09-04  6:45 ` Wolfgang Schuster
  2008-09-04  8:21   ` Thomas A. Schmitz
  2 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Schuster @ 2008-09-04  6:45 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Wed, Sep 3, 2008 at 4:41 PM, Thomas A. Schmitz
<thomas.schmitz@uni-bonn.de> wrote:
> Hi all,
>
> I'm trying to define a macro \Command which can either have four or
> five arguments. If it has five, I want to define them as
>
> \Command1[#1][#2][#3][#4]{#5}
>
> if it has four, as
>
> \Command2[#1][#2][#3]{4#}
>
> I thought this would be the way to go:
>
> \def\Command{%
>        \doquadrupleempty\doCommand}
>
> \def\doCommand{%
>        \iffifthargument%
>                \doquadrupleargument\Command1%
>        \else%
>                \dotripleargument\Command2%
>        \fi}
>
> but that gives me errors about "too many }s". So I'm wondering: am I
> on the wrong track? Can this be done at all?
>
> Thanks, and best
>
> Thomas

\def\Commanda
  {\doquadrupleempty\doCommanda}

\def\doCommanda[#1][#2][#3][#4]%
  {\iffourthargument
     \def\next{\doCommandafive[#1][#2][#3][#4]}%
   \else
     \def\next{\doCommandafour[#1][#2][#3]}%
   \fi\next}

\def\doCommandafive[#1][#2][#3][#4]#5%
  {five arguments}

\def\doCommandafour[#1][#2][#3]#4%
  {four arguments}


\def\Commandb
  {\doquadrupleempty\doCommandb}

\def\doCommandb[#1][#2][#3][#4]%
  {\iffourthargument
     \def\next{\dodoCommandb[#1][#2][#3][#4]}%
   \else
     \def\next{\dodoCommandb[#1][#2][#3][]}%
   \fi\next}

\def\dodoCommandb[#1][#2][#3][#4]#5%
  {\doifelsenothing{#4}
     {four arguments}
     {five arguments}}

\starttext

\Commanda[1][2][3][4]{5}

\Commanda[1][2][3]{4}

\Commandb[1][2][3][4]{5}

\Commandb[1][2][3]4

\Commandb[1][2][3][]{4} % feature

\stoptext

Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: system macros/doquadrupleemtpy
  2008-09-03 16:58 ` Aditya Mahajan
@ 2008-09-04  7:39   ` Thomas A. Schmitz
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas A. Schmitz @ 2008-09-04  7:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Aditya, Peter,

as always, thanks a lot for your help. Peter, you're certainly right  
that it's difficult to diagnose my problem - I'm sending only  
snippets, no example. But it's a fairly complex thing here for my  
presentation module and difficult to reduce in size.

On Sep 3, 2008, at 6:58 PM, Aditya Mahajan wrote:

> On Wed, 3 Sep 2008, Thomas A. Schmitz wrote:
>
>> Hi all,
>>
>> I'm trying to define a macro \Command which can either have four or
>> five arguments. If it has five, I want to define them as
>>
>> \Command1[#1][#2][#3][#4]{#5}
>>
>> if it has four, as
>>
>> \Command2[#1][#2][#3]{4#}
>>
>> I thought this would be the way to go:
>>
>> \def\Command{%
>> 	\doquadrupleempty\doCommand}
>
> You need something with possibly five arguments so you should use  
> quint
> rather than quad:
>
> \def\Command%
>    {\doquintupleargument\doCommand}
>
>> \def\doCommand{%
>> 	\iffifthargument%
>> 		\doquadrupleargument\Command1%
>> 	\else%
>> 		\dotripleargument\Command2%
>> 	\fi}
>
>
> The usual way is
>
> \def\doCommand[#1][#2][#3][#4][#5]%
>    {\doifelsenothing{#5}%See below
>     {\Command1[#1][#2][#3][#4][#5]}
>     {\Command2[#1][#2][#3][#4]}}
>
> I use \doifelsenothing rather than \doiffirthargument. If I give
>
> \Command[...][...][...][...][] with \doifelsenothing \Commnad2 will be
> called while with \iffifthargument \Command1 will be called. Use  
> whichever
> is more appropriate for your problem.
>
OK, that does make sense, but now I also see where my problem lies.  
When I define

\doCommand[#1][#2][#3][#4]#5

and then have

\Command2[#1][#2][#3]#4

TeX picks up a closing bracket as #4. I suspect that my problem lies  
in the definition \doCommand[#1][#2][#3][#4]#5 . The two definitions  
don't match; when I look at \doCommand, the closing bracket is indeed  
argument #4, from TeX's point of view. Maybe I need to reverse the  
order of my arguments and make it

\doCommand#1[#2][#3][#4][#5] ?

but I'm not sure if this would play with quintupleempty...

Anyway, thanks a lot for your help. I'll look further into it and will  
maybe come back with a real example later if I can't figure it out.

Thomas
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

* Re: system macros/doquadrupleemtpy
  2008-09-04  6:45 ` Wolfgang Schuster
@ 2008-09-04  8:21   ` Thomas A. Schmitz
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas A. Schmitz @ 2008-09-04  8:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users


On Sep 4, 2008, at 8:45 AM, Wolfgang Schuster wrote:

> \def\Commanda
>  {\doquadrupleempty\doCommanda}
>
> \def\doCommanda[#1][#2][#3][#4]%
>  {\iffourthargument
>     \def\next{\doCommandafive[#1][#2][#3][#4]}%
>   \else
>     \def\next{\doCommandafour[#1][#2][#3]}%
>   \fi\next}
>
> \def\doCommandafive[#1][#2][#3][#4]#5%
>  {five arguments}
>
> \def\doCommandafour[#1][#2][#3]#4%
>  {four arguments}
>
>
> \def\Commandb
>  {\doquadrupleempty\doCommandb}
>
> \def\doCommandb[#1][#2][#3][#4]%
>  {\iffourthargument
>     \def\next{\dodoCommandb[#1][#2][#3][#4]}%
>   \else
>     \def\next{\dodoCommandb[#1][#2][#3][]}%
>   \fi\next}
>
> \def\dodoCommandb[#1][#2][#3][#4]#5%
>  {\doifelsenothing{#4}
>     {four arguments}
>     {five arguments}}
>
> \starttext
>
> \Commanda[1][2][3][4]{5}
>
> \Commanda[1][2][3]{4}
>
> \Commandb[1][2][3][4]{5}
>
> \Commandb[1][2][3]4
>
> \Commandb[1][2][3][]{4} % feature
>
> \stoptext
>
> Wolfgang

YES! That's the end of my suffering!! Thanks a lot, Wolfgang, you're  
my hero. Makes sense, too, now that I look at it. Now I'm gonna find  
out what \next does...

Thanks!

Thomas

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


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

end of thread, other threads:[~2008-09-04  8:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-03 14:41 system macros/doquadrupleemtpy Thomas A. Schmitz
2008-09-03 16:58 ` Aditya Mahajan
2008-09-04  7:39   ` Thomas A. Schmitz
2008-09-03 18:32 ` Peter Rolf
2008-09-04  6:45 ` Wolfgang Schuster
2008-09-04  8:21   ` Thomas A. Schmitz

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).