[texhax] Problem with color package

Michael Barr barr at math.mcgill.ca
Fri Dec 13 02:08:33 CET 2013


It is not surprising that using the color package, the word Test2 prints 
in red in the example:
\setbox0\hbox{\color{red} Test1}\box0 Test2

But it seems like a failure of the tex grouping mechanism when the same 
happens in this example:

{\setbox0\hbox{\color{red} Test1}\box0} Test2

Adding a group in another place does not improve things:

\setbox0\hbox{{\color{red} Test1}}\box0 Test2

but adding both sets of groupings does:

{\setbox0\hbox{{\color{red} Test1}}\box0} Test2

I got a partial (but not entirely convincing) explanation of this from 
Daniel Müllner.  But is there any way to force \color to confine itself to 
being inside a group.  And why does it need two levels of grouping to get 
it to work?

The following also work:
\setbox0\hbox{{{\color{red} Test1}}}\box0 Test2 
{{{\setbox0\hbox{\color{red} Test1}\box0\relax}}} Test2

Michael



-- 
        Every gun that is made, every warship launched, every rocket fired
signifies, in the final sense, a theft from those who hunger and are not
fed, those who are cold and are not clothed. -Dwight D. Eisenhower


More information about the texhax mailing list