[texhax] A macro programming question
Paul Isambert
zappathustra at free.fr
Sun Apr 11 18:15:39 CEST 2010
Wolfgang Schuster a écrit :
> Am 11.04.10 10:30, schrieb Paul Isambert:
>> A little hack on Wolfgang's solution to allow space after the box
>> specification:
> Doesn't LaTeX’s \@ifnextchar take care of this, the ConTeXt equivalent
> \doifnextcharelse
Yes, but I've recently turned into an advocate of the idea that you
should avoid format-dependent macros (except perhaps plain's) as much as
possible.
>> Wolfgang's code for the box material is troublesome if \endR has to
>> retrieve values locally set in that material; however I can't see
>> another solution. We can't use a \toks to store the material, since
>> it should be closed by an explicit "}", whereas the box can be closed
>> by \egroup. Looping over the material and adding it character by
>> character in a macro or token list until we find an \egroup or "}"
>> won't do if for instance we stumble upon "\def\foo{...}", because we
>> won't be able to add the braces... unless we use e-TeX, whose
>> "default-engine-ness" should probably be taken for granted now, but
>> that's another matter.
> Can you show a eTeX solution?
No I can't :) The brace problem is indeed easily solved with e-TeX (add
a brace with catcode 12 then use \scantokens to read everything anew),
but, beside other problems, the scanning approach is flawed from the
start, since one should be able to say:
\def\foo{\bgroup foo\egroup}
\hbox\foo
and scanning that will get everything wrong. So only Donald's approach
works, and it suffers from the same group hack as yours, so I guess we
can't do better (but after all I'm just a wizard's apprentice, and I
hope I'll be proven wrong by a master). Not to mention the impossibility
of using \hboxR in a assignment, as remarked by Philipp.
>> I can't understand why you make everything happen inside a group,
>> Wolfgang. Is that because you use \toks0 as a scratch? Then wouldn't
>> it simpler to use our own token list and remove the group?
> I wanted just something simple without too many extra defintions.
That's what I'd thought, just wanted to be sure.
Paul
More information about the texhax
mailing list