[texhax] A macro programming question

Donald Arseneau asnd at triumf.ca
Mon Apr 12 16:35:35 CEST 2010


Vafa Khalighi <vafakh84 at gmail.com> writes:

> > To add to the other solutions... this one only defines one
> > macro and works with both { } and \bgroup \egroup...
> >
> > \def\hboxR{\begingroup
> >  \everyhbox{%
> >   \aftergroup\endgroup
> >   \everyhbox{}%
> >    \beginR
> >   \bgroup
> >   \aftergroup\endR
> >   \aftergroup\egroup
> >  }\hbox}
> >
> >
> \setbox0=\hboxR{This is a test.}
> \box0
> 
> Would not work here, because TeX expects a box. How can one fix this?

Indeed a big shortcoming.

One solution is to use another layer of \hbox{ } instead of 
\begingroup \endgroup

 \def\hboxR{\hbox\bgroup
  \everyhbox{%
   \aftergroup\egroup
   \everyhbox{}%
    \beginR
   \bgroup
   \aftergroup\endR
   \aftergroup\egroup
  }\hbox}

There is still the problem that \hboxR is an expandable macro
instead of a primitive.  Since \beginR indicates that you
have etex enabled, use 

\protected\def\hboxR...


-- 
Donald Arseneau                          asnd at triumf.ca


More information about the texhax mailing list