[XeTeX] newcommand with optional arguments
Ross Moore
ross at ics.mq.edu.au
Tue Mar 4 06:20:31 CET 2008
Hi Manuel,
On 04/03/2008, at 11:36 AM, Manuel Pégourié-Gonnard wrote:
> Hi,
>
> Ross Moore a écrit :
>>
>> A more bullet-proof approach is:
>>
>> \makeatletter
>> \def\myempty@{}
>> \makeatother
>> \let\testtheargument\relax
>>
>
> \makataletter here ? To use \myempty at ...
Yes; so that the exceptional case becomes un-typeable,
at least in a normal LaTeX document.
>> \newcommand{\nuu}[2][]{%
>> \def\testtheargument{#1}%
>> \textit{#2}%
>> \expandafter\ifx\expandafter\myempty@\testtheargument\myempty@
>
> Using \def and the expandafters is equivalent to using just #1,
> with to
> problems added :
> - #1 should not contain any # now;
Yes, there can be an extra complication here,
depending upon how that # is intended to be used.
If, for example, it is as \# , then it has already
been tokenized, so it'll be OK; but others not so.
> - the test becomes non fully expandable;
> (which should not be a problem in this case, however).
Yes, again; another complication in some circumstances.
>
> If you choose to use a \def, the simpler and best solution is
> \def\arg at one{#1}
> \ifx\arg at one\@empty
Indeed; which is why I quickly followed my first post
with a correction. :-)
> \ETC.
>
>> But even this has the side-effect of leaving \testtheargument
>> with a value different from what it was before \nuu is encountered.
>>
> This should not be a problem, since \testtheargument should be used
> only for this.
Yes, but when it comes to generalising the code for
other similar purposes, with more complicated testing
and processing, ...
>> This technicality is overcome using the following:
>>
> Useless, IMHO.
... it can pay to be very careful.
>
>> And this may not be the end of the story; but enough for now.
>>
> Well, if you want to test wether an argument is empty or not, the
> best is to
> use the ifmtarg package : it's reliable (no problems with \ifs or
> string
> beginning with \empty) and fully expandable (this can be important).
Yes; that can well be.
Donald Arseneau writes good stuff; often needing to be studied
very carefully to understand exactly how/why it works.
> The only
> particularity is that one string consisting only of space tokens is
> considered
> empty.
>
> By the way, all this discussion has little (if at all) to do with
> XeTeX, and
> would surely be more natural in comp.text.tx or so...
True. But the question arose here, and was answered (incorrectly) here,
so a correction and further discussion should be made on this list.
It would be wrong to have the posting with the original answer as
the final message in this thread.
>
> Manuel.
Cheers,
Ross
------------------------------------------------------------------------
Ross Moore ross at maths.mq.edu.au
Mathematics Department office: E7A-419
Macquarie University tel: +61 +2 9850 8955
Sydney, Australia 2109 fax: +61 +2 9850 8114
------------------------------------------------------------------------
More information about the XeTeX
mailing list