[XeTeX] Colored Arabic in Tables

Ross Moore ross at ics.mq.edu.au
Wed Mar 11 23:58:18 CET 2009

On 12/03/2009, at 8:02 AM, Ross Moore wrote:

> Hi Francois, and others,

>> first before the tabularx env. To my unexpert eyes, this could be a
>> problem with the \addfontfeature macro in fontspec, or a strange
>> bug in
>> tabularx. Bidi and arabxetex are not guilty in any case ;)
> Replacing {tabularx} by {tabular} the problem does not appear.
> So certainly the problem is triggered by some action taken in
> the coding for a {tabularx}.

Here's a patch to establish compatibility of fontspec's
\addfontfeature  macro with {tabularx}'s strategy of first
measuring the width of columns, before actually building
the table.

Put the following coding in your preamble, after  fontspec.sty
has been loaded.

>> \makeatletter
>>  \let\realaddfontfeature\addfontfeature
>>  \def\TXaddfontfeature{%
>>    \ifx\@footnotetext\TX at ftntext
>>     \expandafter\realaddfontfeature
>>    \else \expandafter\@gobble\fi}
>>  \def\fs at tabularx{\let\addfontfeature\TXaddfontfeature \realtabularx}
>>  \AtBeginDocument{\@ifpackageloaded{tabularx}%
>>     {\let\realtabularx\tabularx \let\tabularx\fs at tabularx}}
>> \makeatother

The stuff between  \makeatletter ... \makeatother could be
put into a .sty file.

Basically  \addfontfeature  becomes a variable capable
of having alternative expansions according to:

  (a) whether or not  tabularx  has been loaded;

  (b) are we inside a {tabularx};

  (c) are we currently measuring or typesetting.

If (a) and (b) are true and we are measuring, then
\addfontfeature  does nothing but gobble its argument
--- this is done by hacking a little at  \tabularx .
Otherwise it acts normally.

Other array-like environments do measuring first, similar
to what {tabularx} does; e.g. most AMS math displays.
So similar tests and hacks might be needed for these too.

> Is there a solution/workaround?
> Yes.
> First declare *outside* the table any special font requirements
> that you'll be wanting to use inside a {tabularx}.
> Associate these fonts with a macro name, and then use this macro
> to get the font+attributes.

This remains useful advice.
But now there is also a way to automatically tackle
such problems, once they have been properly identified.


Best regards,


Ross Moore                                       ross at maths.mq.edu.au
Mathematics Department                           office: E7A-419
Macquarie University                             tel: +61 (0)2 9850 8955
Sydney, Australia  2109                          fax: +61 (0)2 9850 8114

More information about the XeTeX mailing list