2

This is a complement to these questions:

My aim is to create a macro like \color which can be used in RTL mode (right to left) and in all circumstances to color text and drawing stuff without issues:

Here my attempt (which use fontspec Color key to color text and normal \color to color rules and drawings but this need to patch every drawing stuff like \rule, tikzpicture,... )

\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont{Amiri}

\usepackage[rldocument]{bidi}

\makeatletter
% patch \rule commmand
\let\old@rule\@rule
\def\@rule[#1]#2#3{\ifrtlcolor\textcolor{rtlcolor}{\old@rule[#1]{#2} 
 {#3}}\else\old@rule[#1]{#2}{#3}\fi}
\makeatother

\def\rtlcolor#1{%
\rtlcolortrue
\colorlet{rtlcolor}{#1}
\addfontfeature{Color=#1}
 }

\begin{document}

Right to left text {\rtlcolor{red} RED TEXT \rule{5pt}{5pt} right to left text  
right to left text right to left text right to left text right to left text } out of group 

\end{document}

enter image description here

3
  • 2
    Why is switching to luatex not an option for you? You are now fighting since weeks with the insufficient rtf model of xelatex. Feb 4 '19 at 11:04
  • Most of rtl writers use xelatex rather then lualatex because of the great support from bidi package
    – Salim Bou
    Feb 4 '19 at 11:24
  • 3
    That's now. But seeing the lack of development in xetex/bidi/polyglossia compared to the changes in bidi/babel and the luatex engine I would say it would make more sense to spent your time to improve luatex. Feb 4 '19 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.