# Coloring Arab vowels/marks without losing connection

In Arabic script you add short vowels/diacritics (marks) above/below the consonants. How do yo go about coloring them (on a case by case basis) without losing connection/breaking the letters/vowels in a word?

In the MWE below I'm trying to color the letter b in the (transliterated) word balad without also coloring a that stands above the consonant in the word.

Lastly, in the small sample below I manage to get a work solution by adding an extension/prolongation to the letter b (using _ and adding to this the 'zero width join' unicode character \char"200D suffix), but this is somewhat a hack and adds unnecessary (and unwanted) strokes to the text.

MWE

\documentclass[a4paper,12pt,twoside]{memoir}
\usepackage{xcolor}

\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{arabxetex}
\let\textarabic\relax      % required for polyglossia/arabxetex
\let\Arabic\relax          %
\setotherlanguages{arabic}

\begin{document}

1.
\begin{arab}[voc]
balad
\end{arab}

2.
\begin{arab}[voc]
\textcolor{red}{b_}\char"200D alad
\end{arab}

\end{document}


I found this (link) old post using pdfLaTeX, with the package arabtex and style acolor.sty, solving it in a more generic manner (where all vowels/marks are colored). However I can't seem to get this working in the MWE above, and unsure if this solution for arabtex also will work with the above MWE in arabxetex

Typing in XeLaTeX with memoir in Overleaf.

## 2 Answers

arabluatex is able to do this. Of course, you need to use lualatex to compile your document. Please refer to the documentation (currently sec. 7 on p. 35) for more information.

\documentclass[12pt]{article}

\usepackage{arabluatex}

\begin{document}

\begin{arab}
\arbcolor[red]{b}.alad
\end{arab}

\end{document}


• Spot in, that's the result I'm looking for. However, it's always a tradeoff between LuaLaTeX (arabluatex) and XeLaTeX (arabxetex), and for the project at hand, I'm typing it in the later, i.e. XeLaTeX with packages arabxetex and polyglossia. Looking for a working solution with this setup. – imdk4242 Jul 29 at 22:07
• I get your point. Using the taṭwīl should get you out of trouble easily, but with a somewhat poor visual result. As for the zero width joiner, depending on the font you are using, you may get unwanted additional marks printed. (But I haven't tested this solution under xelatex) – Robert Alessi Jul 29 at 22:20
• I have tried the same setup in XeLaTeX without a positive result. \arabcolor{} is not a predefined command in arabxetex, and manually coloring (and using the syntax with .) breaks the stroke of the word. – imdk4242 Jul 30 at 8:29
• @imdk4242 You might be interested in reading this – Robert Alessi Aug 3 at 7:17
• @imdk4242 I just did, but for some reason, the @ mechanism didn't work there. Let's wait for a couple of days. – Robert Alessi Aug 3 at 19:51

I know it is not perfect with all arabic letters and in all the situations but it is just a start:

\def\red#1#2{\hspace{5pt}\char"200D #2\hspace{-5pt}\textcolor{red}{#1-}-}

\documentclass[a4paper,12pt,twoside]{memoir}
\usepackage{xcolor}

\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{arabxetex}
\let\textarabic\relax      % required for polyglossia/arabxetex
\let\Arabic\relax          %
\setotherlanguages{arabic}

\def\red#1#2{\hspace{5pt}\char"200D #2\hspace{-5pt}\textcolor{red}{#1-}-}
\begin{document}

\begin{arab}[voc]
balad

\red balad

\end{arab}

\end{document}


• I already tried this out, and as you can see (in the picture you uploaded), the stroke after the first letter b is prolonged compared with the above one with no color. So the trick is to get the (2.) to look identical with the (1.) AND only coloring the first letter (without the mark/vowel). – imdk4242 Jul 29 at 21:31
• @imdk4242 answer updated. that's all what I get! – Hafid Boukhoulda Jul 30 at 0:14
• I truly appreciate the input, however this hack is not a scalable solution, and won't work. The MWE is exactly that, it shows the single Arabic letter B in its initial position for illustrative purposes... I need to color different letters in different position with different short vowels/diacritics (marks). – imdk4242 Jul 30 at 8:33
• @imdk4242 sorry! – Hafid Boukhoulda Jul 30 at 8:38