[tex-eplain] Position of optional argument

Rodolfo Medina rodolfo.medina at gmail.com
Fri Feb 11 21:09:49 CET 2011


On Sun, Apr 26, 2009 at 07:16:55PM +0100, Rodolfo Medina wrote:

>>> I've been using the eplain \@getoptionalarg and \@optionalarg commands in a
>>> certain macro.  It turns out to me that the optional argument must be put
>>> *before* the non optional argument.
>>>
>>> How can I set things - if possible - so to put it after it?



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



> Rodolfo:

>>>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?



Dan Luecking <luecking at uark.edu> writes:

>> 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.
>
>
> Thanks!  But, if I put:
>
> \ifx\@optionalarg\empty
>         \@test
> \else
>         \expandafter\@getoptionalarg\expandafter\@test
> \fi
>
> , it doesn't seem to work either, and neither
>
> \ifx\@optionalarg\empty
>         \@test
> \else
>         \@getoptionalarg\@test
> \fi
>
> .  How can I then have such a condition working?


luecking <luecking at uark.edu> writes:

> \@test is also looking for an argument and sees an \else instead
> of its intended argument. You can add another \expandafter:
>
>   \ifx\@optionalarg\empty
>        \expandafter\@test
>   \else
>         \expandafter\@getoptionalarg\expandafter\@test
>   \fi
>
> Or your can use a conditional definition:
>
>   \ifx\@optionalarg\empty
>          \let\next\@test
>   \else
>          \def\next{\@getoptionalarg\@test}
>   \fi \next


Unfortunately, it doesn't work either!
Rodolfo



More information about the tex-eplain mailing list