[XeTeX] bidi and hyperref and color in XeTeX

Jonathan Kew jfkthame at googlemail.com
Sat Aug 8 13:46:57 CEST 2009

Hi Vafa,

It's not forgotten, but it's also not something that can be trivially  
added as it stands, and I have quite limited time to spend on it at  
the moment. To improve the chances of getting this done, there are a  
couple of things you could do....

(1) Taking the \halign issue first, as I understand it, you'd like a  
version of the primitive that orders its columns from right to left  
instead of left to right, correct? That seems reasonable to me, and  
I'd be willing to add such a primitive. I wouldn't call it \semihalign  
(I assume the prefix is meant to imply "Semitic", but I don't think  
it's a good name for a XeTeX primitive); I'd probably go with  
something like \RLhalign.

The code you attached looks OK as far as it goes, but it is definitely  
not complete; for example, the first two changes reference modules  
@<insert |begin_R_code|...@> and @<insert matching |end_R_code|...@>,  
but these are nowhere to be seen. There must be additional definitions  
and code fragments that go elsewhere (also code to add the new  
primitive, print it, etc). And it also looks like it might have some  
dependency on other "Persian TeX" features (what's "Rtlang"?) which  
need to be eliminated if it's to apply to XeTeX.

If you can come up with a patch that includes all the changes needed  
for an \RLhalign primitive, separate from any other features, and  
applies cleanly to the xetex code, then I'll certainly try it out, and  
assuming no problems show up, I'd be happy to include this. (Compare  
the recently-added primitives implemented in xetex-latex3.ch, for  
example.) If I have to figure out the missing fragments and how to  
integrate them, it will take some unknown amount of time.... sorry,  
but that's the reality.

(2) Regarding \beginspecial and \endspecial, I'm trying to understand  
exactly how these would work. The idea is that \beginspecial takes  
both the "starting" and "ending" code; then during line-breaking (or  
hbox packaging?), \special nodes are added at the beginning and end of  
the lines so that the effect applies to the correct section of the  
text. I can see how that would work for simple uses of color in bidi,  
for example.

What about the effect of unboxing and re-line-breaking, though?  
Suppose I have a paragraph that includes a \beginspecial...\endspecial  
pair, and I set this paragraph with a large \hsize so it all occurs on  
one line. Then later I unbox it and re-set the text with a smaller  
\hsize; will the specials still do the right thing?

I would experiment with this, do some tracing of the node lists, etc.,  
but again, the code is not complete and usable; if you can provide an  
actual patch that implements these primitives, separate from any other  
features (what's cur_speech? that sounds like a Persian TeX-ism), then  
it will be a lot easier for me to evaluate.

(An aside: Fundamentally, I don't think specials are the best way to  
do text color, because of the difficulty of making them behave  
correctly in the presence of page-breaks, insertions, and similar  
complications. Treating color as a font attribute, as xetex does with  
the extended \font primitive, is a much simpler and more robust  
approach. But I realize this is currently limited in several ways: in  
particular, not available for TFM fonts, and limited to RGB colors.  
Perhaps the best solution, though, would be to enhance that mechanism.)


On 7 Aug 2009, at 04:50, Vafa Khalighi wrote:

> Sorry for repeating this again but I think it is forgotten. This is  
> the answer to the questions that Jonathan asked about the  
> \beginspecial and \endspecial primitives with the attached patch  
> which shows the main changes needed for implementing these and  
> \semihalign primitive.
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> The primitives \beginspecial and \endspecial are defined because when
> \special's range is more than a line in a paragraph and end of it,  
> is in the
> middle of another line (e.g. when 1.5 lines of a paragraph is  
> coloured), the
> coloured range in RTL will not be what we expect and  this is  
> because of the
> paragraph scan towards the lines which are adjusted from left. With  
> these
> two primitives (\beginspecial and \endspecial) paragraph scan  
> algorithm can
> colour the range of each line that was intended to be coloured and  
> as a
> consequent the problem will disappear.
> \beginspecial has two arguments, one of the argument is about the  
> start of
> special and the other argument is about the end of special  
> \endspecial does
> not have any arguments and its argument is the second argument of
> \beginspecial. So in your example \beginspecial and \endspecial  
> would be
> used in the following way:
> preceding text  
> \b‌e‌g‌i‌n‌s‌p‌e‌c‌i‌a‌l{c‌o‌l‌o‌r  
> p‌u‌s‌h r‌g‌b 1 0
> 0}{c‌o‌l‌o‌r p‌o‌p} r‌e‌d a‌n‌d m‌o‌r‌e   
> r‌e‌d  \e‌n‌d‌s‌p‌e‌c‌i‌a‌l
> ‌fo‌l‌l‌o‌w‌i‌n‌g t‌e‌x‌t w‌o‌u‌l‌d  
> w‌o‌r‌k l‌i‌k‌e y‌o‌u‌r example
> Therefore in the lines scan algorithm, in the end of each line, the  
> argument
> of \endspecial (second argument of \beginspecial) and in the   
> beginning of
> next line, the argument of \beginspecial (first argument) will be  
> added.
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> Could you please tell me that what you think about this? I just want  
> to see if you really can not fix it, then I have to modify TeX line  
> breaking algorithm. But I should be very careful with modifying TeX  
> line breaking algorithm because pierre mackay told me that "This was  
> just what he looked into in his first attempts at a bidi TeX, but  
> DEK looked at it and decided that it broke too many other aspects of  
> TeX. That was what inspired him to produce his own solution, which  
> became TeX-Xet. "
> <spcalign.zip>

More information about the XeTeX mailing list