Changes

Jump to navigation Jump to search
1,080 bytes added ,  20:20, 4 July 2005
no edit summary
[[Commands with optional arguments]]
>
 
== Processing a comma-separated list of values ==
 
Suppose you defined a command like this one somewhere in your document:
<texcode>
\def\IHaveTo#1#2{I have to #1 on #2.\par}
</texcode>
So calling
<texcode>
\IHaveTo{tidy up}{Monday}
</texcode>
Will print out
I have to tidy up on Monday.
 
But sometimes you have to repeat some task more than once. In this case you can define a new command:
<texcode>
\def\MyMumOrderedMeTo[#1]#2%
{\processcommalist[#1]{\IHaveTo{#2}}}
</texcode>
Calling
<texcode>
\MyMumOrderedMeTo[Monday,Wednesday,Saturday]{tidy up}
</texcode>
will spare you some typing <i>(however not tidying up!)</i>:
 
I have to tidy up on Monday.
I have to tidy up on Wednesday.
I have to tidy up on Saturday.
 
In case a command <tt>\IHaveTo</tt> is already defined in a slightly different way:
<texcode>
\def\IHaveTo[#1]#2{I have to #2 on #1.\par}
</texcode>
you can define <tt>\MyMumOrderedMeTo</tt> as:
<texcode>
\def\MyMumOrderedMeTo[#1]#2%
{\begingroup
\def\processitem##1{\IHaveToDo[##1]{#2}}%
\processcommalist[#1]\processitem
\endgroup}
</texcode>
Anonymous user

Navigation menu