You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The TeX--XeT algorithm reverses whatsits and as a result, the \special pairs will be placed in the wrong order. For instance, color or links or any other thing which is achieved via driver is fundamentally broken in right to left mode.
For instance, the following minimal Plain TeX document illustrates the issue with color.
\TeXXeTstate=1
This is \beginR\special{color push rgb 1 0 0}RED COLOR\special{color pop}\endR{} as you can see.
\bye
As mentioned above, this is Engine issue. Peter was working towards fixing this (See this TeXLive commit and this one.
The bidi package fixes this in a limited way; if the colored text only is on a single line then text will be colored correctly. However, if the colored text is more than a line (it breaks across several lines), then the resulting colored text is wrong.
This can be fixed in the macro level as the following example illustrates.
\documentclass{article}
\usepackage{xepersian}
\settextfont{Yas}
\makeatletter\long\def\bidi@addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\bgroup\catcode`!=3\catcode`?=3\gdef\bidi@replacestrings#1#2{\long\def\bidi@replacestringsA##1#1##2!{%\ifx!##2!\bidi@addto\bidi@tmpb{##1}\else\bidi@addto\bidi@tmpb{##1#2}\bidi@replacestringsA##2!\fi}%\edef\bidi@tmpb{\expandafter}\expandafter\bidi@replacestringsA\bidi@tmpb?#1!%\long\def\bidi@replacestringsA##1?{\def\bidi@tmpb{##1}}\expandafter\bidi@replacestringsA\bidi@tmpb
}
\egroup\newbox\bidi@color@start@box\newbox\bidi@color@end@box\setbox\bidi@color@start@box=\hbox{\special{color pop}}
\setbox\bidi@color@end@box=\hbox{\special{color push rgb 1 0 0}}%\def\bidicolor#1{\def\bidi@tmpb{#1}\bidi@replacestrings{ }{\bidi@specialspace}%
{\copy\bidi@color@start@box\bidi@tmpb\copy\bidi@color@end@box}%
}
\def\bidi@specialspace{%\discretionary{\copy\bidi@color@end@box}{\copy\bidi@color@start@box}{\kern\fontdimen2\font}%\nobreak\hskip 0pt plus\fontdimen3\font minus\fontdimen4\font
}
\makeatother\begin{document}
این یک متن معمولی است
\bidicolor{این متن با رنگ قرمز نوشته میشود که در یک سطر قرار میگیرد}
و این متن بعد آن است که به سطر بعد میرود و
\bidicolor{%
حالا یک متن رنگی مینویسیم که در چندین سطر قرار بگیرید تا کارایی رنگی کردن متن را ببینیم کنون ای خردمند وصف خرد بدین جایگه گفتن اندرخورد
کنون تا چه داری بیار از خرد که گوش نیوشنده زو برخورد
خرد بهتر از هر چه ایزد بداد ستایش خرد را به از راه داد
خرد رهنمای و خرد دلگشای خرد دست گیرد به هر دو سرای
ازو شادمانی وزویت غمیست وزویت فزونی وزویت کمیست
خرد تیره و مرد روشن روان نباشد همی شادمان یک زمان
چه گفت آن خردمند مرد خرد که دانا ز گفتار از برخور
}
و ادامه متن که با رنگ سیاه نوشته میشود همانطوری که میبینید هیچ مشکلی ندارد و رنگ چکه نمیکند.
\end{document}
The only disadvantage of this is that there is no hyphenation but that is rarely a problem since we do not really have hyphenation in right to left text.
Perhaps this approach can be extended to support any packages which uses \special (e.g. color, xcolor, hyperref, etc).
The text was updated successfully, but these errors were encountered:
The TeX--XeT algorithm reverses whatsits and as a result, the
\special
pairs will be placed in the wrong order. For instance, color or links or any other thing which is achieved via driver is fundamentally broken in right to left mode.For instance, the following minimal Plain TeX document illustrates the issue with color.
As mentioned above, this is Engine issue. Peter was working towards fixing this (See this TeXLive commit and this one.
The
bidi
package fixes this in a limited way; if the colored text only is on a single line then text will be colored correctly. However, if the colored text is more than a line (it breaks across several lines), then the resulting colored text is wrong.This can be fixed in the macro level as the following example illustrates.
The only disadvantage of this is that there is no hyphenation but that is rarely a problem since we do not really have hyphenation in right to left text.
Perhaps this approach can be extended to support any packages which uses
\special
(e.g.color
,xcolor
,hyperref
, etc).The text was updated successfully, but these errors were encountered: