[dvipdfmx] Color stacks and transformations

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Mar 17 11:56:42 CET 2021


On 16/03/2021 18:05, Joseph Wright wrote:
> On the 'restore the color' business, I am slightly confused by the 
> intent. I can see it does what you describe, in for example
> 
>      \leavevmode
>      \special{x:gsave}%
>      \special{pdf:bc [1 0 0]}%
>      Hello
>      \special{x:grestore}%
>      world
>      \special{pdf:ec}%
>      \bye
> 
> but that behaviour contrasts with pdfTeX
> 
>      \leavevmode
>      \pdfsave
>      \pdfcolorstack 0 push{1 0 0 rg}%
>      Hello
>      \pdfrestore
>      world
>      \pdfcolorstack 0 pop
>      \bye
> 
> which admittedly is a lot more aggressive all-round here. However, both 
> of these demos look unbalanced to me: I'd expect in a well-behaved real 
> example that the color stack would be popped *inside* the graphics state 
> save/restore pair.

I think I see the logic here on a bit of reflection. If you look at the 
pdfTeX example, after \pdfrestore the 'live' color and the color stack 
have deviated. With the dvipdfmx approach, that doesn't happen: they 
stay in sync.

One can of course argue things either way: as I've said, if you start 
from the expectation that color stack push/pop must be properly nested 
inside any graphics state, then what happens if you don't do that is 
simply undefined. On the other hand, if you take the view that the color 
stack should 'do the right thing' and be independent of graphics state, 
then the dvipdfmx approach makes lots of sense.

So I don't think you can say either is 'more correct' than the other, 
only that it's probably a good idea to document the difference. (I think 
in LaTeX examples, the color stack is always properly nested inside 
graphics states, so you don't actually see any issue one way or the other.)

Joseph


More information about the dvipdfmx mailing list.