[texhax] Eplain TeX: problem with \@optionalarg

Heiko Oberdiek heiko.oberdiek at googlemail.com
Sun Feb 13 19:29:04 CET 2011


On Sun, Feb 13, 2011 at 04:48:03PM +0000, Rodolfo Medina wrote:

> Heiko Oberdiek <heiko.oberdiek at googlemail.com> writes:
> 
> > On Sun, Feb 13, 2011 at 01:50:01PM +0000, Rodolfo Medina wrote:
> >
> >> it is suggested the following code:
> >> 
> >>      \makeatletter
> >>      % \mo{m}[o]
> >>      \def\mo#1{\def\mo at arg{#1}\@getoptionalarg\fin at mo}
> >> 
> >>      \def\fin at mo{\vskip1pc
> >>       \message{^^JArg: \mo at arg}%
> >>       \message{^^JOptional arg: \@optionalarg}%
> >>      }
> >> 
> >> Now, I wish to put a condition there:
> >> 
> >>    \ifx\@optionalarg\empty
> >>         \fin at mo
> >>    \else
> >>         \@getoptionalarg\fin at mo
> >>    \fi
> >
> > \@getoptionalarg defines \@optionalarg. Therefore \@getoptionalarg
> > must be called first. Then you can test inside \fin at mo.
> 
> 
> Thanks.  But how can I do that in practice?  

\def\mo#1{%
  \def\mo at arg{#1}%
  \@getoptionalarg\fin at mo
}
\def\fin at mo{%
  \ifx\@optionalarg\empty
    \message{^^JOptional argument empty or not given}%
  \else
    \vskip1pc %
    \message{^^JArg: \mo at arg}%
    \message{^^JOptional arg: \@optionalarg}%
  \fi
}

> To put that condition,
> \@optionalarg necessarily comes first!

And before you have to use \@getoptionalarg. Otherwise you
are using \@optionalarg of a different command before.

Viele Grüße
  Heiko Oberdiek


More information about the texhax mailing list