[tex-eplain] Position of optional argument

Dan Luecking luecking at uark.edu
Fri Feb 11 02:10:35 CET 2011


At 02:36 PM 2/10/2011, Rodolfo Medina wrote:
>Oleg Katsitadze <olegkat at gmail.com> writes:
>
> > Try this:
> >
> >     \input eplain
> >     \makeatletter
> >     \def\test#1{%
> >       \def\test at arg{#1}%
> >       \@getoptionalarg\@test
> >     }
> >     \def\@test{%
> >       \message{^^JArg: \test at arg}%
> >       \message{^^JOptional arg: \@optionalarg}%
> >     }
> >     \makeatother
>
>If, in the above code, in place of `\@getoptionalarg\@test' I put:
>   \ifnum0=0
>       \@getoptionalarg\@test
>   \else
>   \fi
>then, strangely, it doesn't seem to work any more.  I can't explain why.  Can
>anybody?

Not so strange, as \@getoptionalarg looks ahead, sees
\else rather than [, and concludes there is no optional arg.

You have to get rid of the \else and the \fi before
\@getoptionalarg is expanded. Try this instead:
   \ifnum0=0
     \expandafter\@getoptionalarg\expandafter\@test
   \else
   \fi

The first expandafter expands the second which expands the
\else. The expansion of \else removes everything up to and
including \fi and the way is clear to see a following [
(if there is one).

You can omit the \else if there is nothing between it and \fi.


Dan


Daniel H. Luecking
Department of Mathematical Sciences
Fayetteville, Arkansas
http://www-cs-faculty.stanford.edu/~knuth/iaq.html 



More information about the tex-eplain mailing list