Working with conditionals
![](https://secure.gravatar.com/avatar/3b89ade8854fe10b5e3f8c87c6fa82f5.jpg?s=120&d=mm&r=g)
I have the folowing function for a title: \def\Title[#1]{ \testpage[10] \startalignment[center] { \blank[2*big] \switchtobodyfont[1.5em] \bf\em#1 } \blank \stopalignment } What I would like is that there is an optional second parameter. When it is there, it is used in the testpage command. Otherwise the default value is used. How would I do this? -- Cecil Westerhof
![](https://secure.gravatar.com/avatar/3abe5a26c84c897ec3b38d6a6c3ec04a.jpg?s=120&d=mm&r=g)
\def\Title{\dodoubleempty\doTitle}
\def\doTitle[#1][#2]{
\ifsecondargument
\testpage[#2]
\else
\testpage[10]
\fi
\startalignment[center]
{
\blank[2*big]
\switchtobodyfont[1.5em]
\bf\em#1
}
\blank
\stopalignment
}
Vianney
On Mon, Jan 3, 2011 at 10:46, Cecil Westerhof
I have the folowing function for a title: \def\Title[#1]{ \testpage[10] \startalignment[center] { \blank[2*big] \switchtobodyfont[1.5em] \bf\em#1 } \blank \stopalignment }
What I would like is that there is an optional second parameter. When it is there, it is used in the testpage command. Otherwise the default value is used. How would I do this?
-- Cecil Westerhof ___________________________________________________________________________________ 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 : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
![](https://secure.gravatar.com/avatar/386a116d129cdc597f2bb6210bbaff7a.jpg?s=120&d=mm&r=g)
2011/1/3 Vianney le Clément
\def\Title{\dodoubleempty\doTitle} \def\doTitle[#1][#2]{ \ifsecondargument \testpage[#2] \else \testpage[10] \fi \startalignment[center] { \blank[2*big] \switchtobodyfont[1.5em] \bf\em#1 } \blank \stopalignment }
Vianney
On Mon, Jan 3, 2011 at 10:46, Cecil Westerhof
wrote: I have the folowing function for a title: \def\Title[#1]{ \testpage[10] \startalignment[center] { \blank[2*big] \switchtobodyfont[1.5em] \bf\em#1 } \blank \stopalignment }
What I would like is that there is an optional second parameter. When it is there, it is used in the testpage command. Otherwise the default value is used. How would I do this?
-- Cecil Westerhof ___________________________________________________________________________________ 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 : http://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 : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
You can also use a key/value approach, which is more flexible \unprotect \def\Title[#1]{ \getparameters[CecWes@@][param1={default},param2={default2}, param3={default3},#1] \testpage[10] \startalignment[center] { \blank[2*big] \switchtobodyfont[1.5em] \bf\em\getvalue{CecWes@@param1} } \blank \stopalignment } \protect \starttext .... %% param1= FOO, param2=BOO, param3=default3 %% the order is not important \Title[param2={BOO},param1={BOO}] ..... \stoptext -- luigi
![](https://secure.gravatar.com/avatar/386a116d129cdc597f2bb6210bbaff7a.jpg?s=120&d=mm&r=g)
On Mon, Jan 3, 2011 at 11:05 AM, luigi scarso
You can also use a key/value approach, which is more flexible
\unprotect \def\Title[#1]{ \getparameters[CecWes@@][param1={default},param2={default2}, param3={default3},#1] \testpage[10] \startalignment[center] { \blank[2*big] \switchtobodyfont[1.5em] \bf\em\getvalue{CecWes@@param1} } \blank \stopalignment } \protect
\starttext .... %% param1= FOO, param2=BOO, param3=default3 %% the order is not important \Title[param2={BOO},param1={BOO}] sorry, typo ^^^ \Title[param2={BOO},param1={FOO}]
-- luigi
participants (3)
-
Cecil Westerhof
-
luigi scarso
-
Vianney le Clément