[texhax] variable opt arg delimiters [was: Defining a ...]

Uwe Lueck uwe.lueck at web.de
Thu Dec 30 17:01:35 CET 2010

I wrote:
> A better proposal than using different category codes is
> programming macros with optional arguments obeying
> a convention that makes a choice of delimiters available to users.
> Any macro package replacing \@ifnextchar[ by some
> \ifx\let at token\opt at arg@delim could be run this way.
>
> If no LaTeXY will adopt this, I will call it LüTeX :-)

I had thought of posting such a "feature request" earlier,
refrained from it for not having found a good idea how
to implement it. If I now found it so simple, I must have
overlooked a problem ...

This would mean that so many \foo in the LaTeX kernel
reading their optional argument by \@foo[#1] must be replaced.

At least I have now thought how such macros would have to
look like instead (sketch, \SetOptArgDels chooses delimiters,
\foo is an example command with one optional argument):

\def\SetOptArgDels#1#2{%
\let\opt at arg@del at l#1%
\def\foo{%
\@ifnextchar\opt at arg@del at l
{\@foo{DEFAULT}}}
\def\@foo#1...

-- where one had \def\@foo[#1]... so far.

Maybe this already is in xparse? Sorry, I cannot afford more right now ...

Fortunately,

1. there would be no need to change preamble-only commands,

2. as I realize at reading Heiko's comment, the "ambiguity" only
arises with macros whose *last* (e.g., only) arguments are optional.

Cheers,

Uwe.