[Tex/LaTex] Arabic with colored vowels and colored suffix … possible


is it possible to do this with XelaTex? (Im using texmaker):

enter image description here

I already tried some of the suggestions posted here, for instance by using Arabtex. But I wanted to this with arabic type text and not transliterating everything.
If not what program is out there that can produce this?

Thanks in advance!

Best Answer

I give it a try, although the answer may not yet be complete/final.

The reference to ConTeXt mentioned by @Alan Munn contains a solution to the question of diacritical marks (vowels), including the use of unicode characters instead of translitteration. But it uses general rules to colour all glyphs of a given type in the same way, not individual ones in a word.

I restrict to the use of XeLaTeX and the problem of colouring of endings (or any part of words) with and without translitteration. Since the design of ArabTeX more than 20 years ago, there exists the possibility to "fake" initial/medial/final positions for arabic letters by means of a hyphen. This continues to work also for unicode glyphs.

\documentclass{minimal} \usepackage{xcolor} \usepackage{arabxetex} 
\newfontfamily\arabicfont[Script=Arabic, Scale=1.5]{Scheherazade}

\def\r{\color{red}} \def\b{\color{blue}}
\def\kerningmsg{\textLR{\textit{\color{black}with kerning!}\ }}

\rshift Vocalised.
mu`allimu-{\r wna} ka_tiru{\r wna}

ma`a mu`allimi-{\r yna} ka_tiri{\r -yna}

ma`a mu`allimi-\kern-1pt{\r yna} ka_tiri{\r -yna} \kerningmsg

\rshift No vocalisation.
mu`allimu-{\r wna} ka_tiru{\r wna}

ma`a mu`allimi-{\r yna} ka_tiri{\r yna}

\rshift Vocalised from unicode.
مُعَلِّمُ-{\r-ونَ} كَثئر-{\r\-ون} 

\rshift Vocalisation removed from unicode.
مُعَلِّمُ-{\r-ونَ} كَثئر-{\r ون}


Save this in arabcolour.tex. Make sure you have a recent distribution of TeXlive or the necessary XeTeX, xcolor and arabxetex packages installed.

The result, generated with xelatex arabcolour, looks very similar to the model given in the original question. But read on below!

Screenshot from PDF file

A well trained eye will see that the ya in the second line has been separated too much from the begin of the word. "kerning" helps here, and you probably have to try on an individual word-by-word basis what is best to glue the words together again. It may vary with different fonts, who give less usefull results (see the ha variant in Amiri font from here - The joining of the waw becomes impossible with this font.).

example given in other answer

Personally I find the transliteration input more readable. Although I tried to define shortcuts for the colour change, the left-right/right-left changes make the "WYSIWYG" an irony and may depend on editors and even on the exact position of a linebreak. The source does not look the same as here in gedit for example, even if copy+paste should preserve the contents logically, and you can try. Hint: When constructing your own words, first type the full sentences, then insert the {\r…} parts for highlighting in one go.

I believe that this is the maximum you will get with XeLaTeX however. So the complete answer is likely to be a combination of ConTeXt mentioned above and this one, be it with transliteration or not.

Related Question