[tex-eplain] optional arguments
Oleg Katsitadze
olegkat at gmail.com
Sat Aug 29 06:59:28 CEST 2009
Hi Russell,
On Fri, Aug 28, 2009 at 11:46:01PM -0400, Russell Lyons wrote:
> Thanks very much for your quick and clear reply, including solution.
My pleasure :).
> is there a simple way to define a macro so that the optional
> argument is second, not first, as is usually the case? What about
> optional arguments that can come first or last, as in \sidx itself?
Here are some examples:
\input eplain
\makeatletter
\def\t#1{\def\t at arg{#1}\@getoptionalarg\fin at t}
\def\fin at t{ARG: \t at arg, OPTARG: \@optionalarg}
\def\tt#1{\def\tt at arg{#1}\@getoptionalarg\fin at tt}
\def\fin at tt#1{ARG1: \tt at arg, OPTARG: \@optionalarg, ARG2: #1}
\def\T{\@getoptionalarg\fin at T}
\def\fin at T#1{\let\T at optarg\@optionalarg \def\T at arg{#1}\@getoptionalarg\@fin at T}
\def\@fin at T{OPTARG1: \T at optarg, ARG: \T at arg, OPTARG2: \@optionalarg}
\makeatother
\t{targ}[toptarg]
\t{targ}
\vskip1pc
\tt{ttarg1}[ttoptarg]{ttarg2}
\tt{ttarg1}{ttarg2}
\vskip1pc
\T[optarg1]{arg}[optarg2]
\T{arg}[optarg2]
\T[optarg1]{arg}
\T{arg}
\bye
More information about the tex-eplain
mailing list