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
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
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 -----------------------------------------------------------------
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
On Tue, 6 Feb 2007 10:36:42 -0500 (EST)
Aditya Mahajan
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
Wolfgang Schuster wrote:
On Tue, 6 Feb 2007 10:36:42 -0500 (EST) Aditya Mahajan
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 -----------------------------------------------------------------
On Wed, 7 Feb 2007, Hans Hagen wrote:
Wolfgang Schuster wrote:
On Tue, 6 Feb 2007 10:36:42 -0500 (EST) Aditya Mahajan
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
participants (3)
-
Aditya Mahajan
-
Hans Hagen
-
Wolfgang Schuster