[XeTeX] newcommand with optional arguments

Sven Siegmund sven.siegmund at gmail.com
Tue Mar 4 10:19:52 CET 2008


And I think the ultimate aolution to all this fuss may be what is written here:

http://tex.loria.fr/texlive-htmldoc/eplain/eplain_6.html#SEC50

But again: I do not really understand these TeX source codes...

S.
------------

You test for an optional argument by using \@getoptionalarg. It takes
one argument, a control sequence to expand after reading the argument,
if present. If an optional argument is present, the control sequence
\@optionalarg expands to it; otherwise, \@optionalarg is \empty. You
must therefore have the category code of @ set to 11 (letter). Here is
an example:
\catcode`@=\letter
\def\cmd{\@getoptionalarg\finishcmd}
\def\finishcmd{%
  \ifx\@optionalarg\empty
    % No optional argument present.
  \else
    % One was present.
  \fi
}

If an optional argument contains another optional argument, the inner
one will need to be enclosed in braces, so TeX does not mistake the
end of the first for the end of the second.


More information about the XeTeX mailing list