Re: pop empty color page stack 0 warning



Michael Ehrt <m.ehrt@xxxxxxxx> wrote:

On 23 Dez., 11:15, r...@xxxxxxxxxxxx (Robin Fairbairns) wrote:
 Heiko Oberdiek <oberd...@xxxxxxxxxxxxxxx> writes:

This warning usually indicates a bug regarding color support,
when \setbox is used without respecting LaTeX color interface
(that adds an additional grouping level).
[...]
Other environments have the same problem, too.
Reason: the package probably predates LaTeX's color support.

not sure of that estimate of the reason, but i've no doubt your
analysis is correct.

i'm currently working on a bug report; when i make a new release
(hopefully before 2009) i'll incorporate your code and check other
similar environments.

thanks for the swift replies.
Out of curiosity, since this 'only' causes a warning - does it cause
any undesirable side effects the way it is right now?

In general, yes. The empty stack warning indicates that the low level
color specials are out of order. Apart from warnings this can cause
wrong colors (luckily for you, not in your minimal document).

LaTeX's color support basically works in pairs: inside a group
the color is set and afterwards (\aftergroup) restored,
in pseudo code:
\color := \set@color + \aftergroup\reset@color

Adangerous case is \setbox, using color without
LaTeX's color wrappers:
\setbox0=\hbox{\color...}
The result is:
\setbox0=\hbox{\set@xxxxxxxx}\reset@color
% use of the box zero, one or more times

Now the color specials are wrong:
* Box is discarded:
==> \reset@color is executed always
* Box is used once:
\reset@color
\box with \set@color
==> wrong order
* Box is used many times:
\reset@color
\box with \set@color
\box with \set@color
...
==> wrong order and missing \reset@color specials

Therefore the LaTeX wrappers add a group around the contents
of the box to prevent leaking of color specials:
\setbox0=\hbox{\begingroup\color...\endgroup}
The result is:
\setbox0=\hbox{\begingroup\set@xxxxxxxx\endgroup\reset@color}
Especially \reset@color is now inside the box where it belongs.

Yours sincerely
Heiko <oberdiek@xxxxxxxxxxxxxxx>
.