[texhax] A macro programming question

Wolfgang Schuster schuster.wolfgang at googlemail.com
Sun Apr 11 12:32:52 CEST 2010


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
does this and I can shorten the \hboxR macro to

\def\hboxR
{\scratchtoks\emptytoks
\doifnextbgroupelse\dohboxR\nohboxR}

\def\dohboxR
{\hbox\the\scratchtoks\bgroup\beginR\bgroup\aftergroup\endR\aftergroup\egroup\let\next=}

\def\nohboxR#1%
{\appendtoks#1\to\scratchtoks
\doifnextbgroupelse\dohboxR\nohboxR}

and with LuaTeX I can shorten this even further

\def\hboxR
{\scratchtoks\emptytoks
\doifnextbgroupelse\dohboxR\nohboxR}

\def\dohboxR
{\ruledhbox dir TRT \the\scratchtoks}

\def\nohboxR#1%
{\appendtoks#1\to\scratchtoks
\doifnextbgroupelse\dohboxR\nohboxR}

> 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?
> 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.

Wolfgang



More information about the texhax mailing list