TransWikia.com

Create an adapted color macro for RTL mode (xelatex)

TeX - LaTeX Asked on December 30, 2020

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
letold@rule@rule
def@rule[#1]#2#3{ifrtlcolortextcolor{rtlcolor}{old@rule[#1]{#2} 
 {#3}}elseold@rule[#1]{#2}{#3}fi}
makeatother

defrtlcolor#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

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP