[XeTeX] newcommand with optional arguments
Sven Siegmund
sven.siegmund at gmail.com
Tue Mar 4 09:09:43 CET 2008
Hello guys,
Thanks vor the valuable discussion. In fact I do not understand why
Stephen's code ...
\newcommand{\nuu}[2][]{%
\textit{#2}\ %
\ifx#1\empty
\else
`#1'
\fi
}
... does not work if I write \nuu[22]{this} but does work when I write
\nuu[goat]{mudi}. The result of
\nuu{this} \nuu[22]{this} \nuu[goat]{mudi}
is
this this mudi 'goat'
Ross's "bullet proof" codes have simirar bugs as the first solution
suggested by Ulrike.
\makeatletter
\def\myempty@{}
\makeatother
\let\testtheargument\relax
\newcommand{\nuu}[2][]{%
\def\testtheargument{#1}%
\textit{#2}%
\expandafter\ifx\expandafter\myempty@\testtheargument\myempty@
\typeout{no 1st argument for \string\nuu{#2}}%
\else
\ `#1'
\fi
}
There \nuu{this} \nuu[22]{this} \nuu[goat]{mudi} becomes
this '' this '22' mudi 'goat'
The same result is achieved when using this another Ross's code:
\newcommand{\nuu}[2][]{%
\def\testtheargument{#1}%
\textit{#2}%
\ifx\testtheargument\myempty@
\typeout{no 1st argument for \string\nuu{#2}}%
\else
\ `#1'
\fi
}
I really do not understand these commands. But practically until now I
don't have nothing better that Stephen's code which works ok except I
want to write something purely numerical as the optional argument. /-:
S.
More information about the XeTeX
mailing list