[XeTeX] color directives in RL context

Jonathan Kew jonathan_kew at sil.org
Tue Apr 17 13:02:52 CEST 2007


On 17 Apr 2007, at 10:05 am, François Charette wrote:

> caapv 208 wrote :
>> No, I have dumped .xdv file and confirmed that the
>> culprit is actually more in the side of the compiler
>> rather than in that of the driver.
>> .dvi (.xdv) do not contain any information for font
>> directionality, and \special{color push rgb 1 0 0}
>> are stored there only with the positional information.
>> With Omega, it is .ofm which supplies the necessary
>> directionality information.
> OK, then the issue is of a different nature than I had imagined...
> Perhaps Jonathan has an idea whether this could reasonably be
> implemented in xetex?

The problem is that the TeX--XeT bidi support works by reversing  
hlists before they're output to the DVI file. Therefore, by the time  
the DVI driver processes the text, it's in "visual order" (i.e. left- 
to-right). If you control color by inserting \specials in the TeX  
source, these don't get any special [sorry] treatment by TeX; they  
just stay in place in the (reversed) list.

The result of this is that a mid-line color-change \special is still  
in the middle of the line, once it's in the DVI file; but the driver  
has no way of knowing that this was a right-to-left line. It's just a  
list of characters (or glyphs), ordered from left to right, with a  
\special in the middle. So although the user intended the \special to  
change the color of the *logical* second part (i.e., the left half)  
of the line, the driver will end up changing the color of the  
*visual* second (right) half.

Fixing this for \special-controlled color would require some kind of  
directional extensions to the DVI file, and perhaps the font/glyph  
information; I guess Omega has some way of dealing with this, but I  
don't know the details.

The alternative (and in my view preferable) approach is to treat  
color as an inherent attribute of the font, so that it stays with the  
glyphs regardless of how they get rearranged by the bidi processing  
(or any other processing). This also solves issues with insertions,  
page-breaks, etc., which can be tricky for the driver to get right  
for \special-based color in complex cases.

XeTeX allows color to be specified on the font, and this should work  
properly with bidi. However, I think there are currently some  
differences between xdv2pdf and xdvipdfmx regarding exactly how this  
is implemented, and how it interacts with \special color if that is  
also used in the same document. I need to re-examine this...

An example that shows font color working with R-L text is:

\documentclass{article}
\usepackage[xetex]{color} % <= 'xetex' works with either xdv2pdf or  
xdvipdfmx
\usepackage{fontspec}
\setmainfont{Times New Roman}
\TeXXeTstate=1
\begin{document}
\everypar={\setbox0=\lastbox \beginR \box0 }

black black black black black black black black black black black black
black black black black black \addfontfeature{Color=0000FF}blue blue  
blue blue blue
blue blue blue blue blue blue blue blue blue blue blue blue
\end{document}

(Feel free to replace the English words with Arabic or Hebrew, and an  
appropriate font!)

JK





More information about the XeTeX mailing list