Coloring combining characters without changing color of a base character
For completeness sake, here is an answer using ConTeXt's font colour schemes feature (using Arabic, but should apply to any scripts):
First write a font “goodies” file containing categories of glyphs names (glyph name are font dependant, so you've to check the font you are using) that should share the same colour (it is just a lua script):
-- save as 'amiri.lfg'
return {
name = "Amiri",
version = "1.00",
comment = "Goodies that complement the Amiri font.",
author = "Khaled Hosny",
colorschemes = {
default = {
[1] = { -- category 1
"uni064E", "uni064B",
},
[2] = { -- category 2
"uni064F", "uni064C",
},
[3] = { -- category 3, etc.
"uni0650", "uni064D",
},
}
}
}
Update: With ConTeXt 2012.03.02 it is now possible to use Unicode character numbers instead of glyph names, so the the lfg
file will not be font dependant (using glyph names is still good to access un-encoded glyphs, which is font dependant by definition).
-- save as 'amiri.lfg'
return {
name = "Amiri",
version = "1.00",
comment = "Goodies that complement the Amiri font.",
author = "Khaled Hosny",
colorschemes = {
default = {
[1] = { -- category 1
0x064E, 0x064B,
},
[2] = { -- category 2
0x064F, 0x064C,
},
[3] = { -- category 3, etc.
0x0650, 0x064D,
},
}
}
}
Then you can use it from your ConTeXt document, using usual font and colour conventions:
% overload ‘arabic‘ font feature set to load the goodies
\definefontfeature[arabic][arabic]
[goodies=amiri, % name of the goodies file
colorscheme=default] % name of the scheme we defined
% define color scheme 1, categories 1, 2 and 3
\definecolor[colorscheme:1:1][r=1]
\definecolor[colorscheme:1:2][g=1]
\definecolor[colorscheme:1:3][b=1]
% color scheme 2
\definecolor[colorscheme:2:1][c=.55]
\definecolor[colorscheme:2:2][m=.55]
\definecolor[colorscheme:2:3][y=.55]
\setupalign[r2l]
\starttext
% load the font
\definedfont[name:amiri*arabic at 36pt]
\setfontcolorscheme[1]
ضَرَبَ ضُرِبَ ضَرْبًا
\setfontcolorscheme[2]
ضَرَبَ ضُرِبَ ضَرْبًا
\stoptext
In PDFTeX/XeTeX colouring is done by inserting pdfliteral nodes around coloured items, these nodes would then interfere with mark positioning in this case, something like:
<base><start-color><mark><stop-color>
LuaTeX can use an alternate mechanism thanks to its "attribute" registers; attributes is a way to annotate input without interfering with pdfliterals and likes and can be employed for many things including colouring. But attributes is a low level mechanism and need to be employed by higher level packages.
In ConTeXt, attributes are used out of box, so it just works:
\definefontfeature[hebrew][arabic][script=hebr]
\definefont[hebrew][name:sblhebrew*hebrew]
\starttext
\textdir TRT
\hebrew
\color[red]{א}\color[blue]{֣}\color[green]{֚}ב\color[blue]{ָ}\color[green]{ג}֦ד\color[green]{֘}
\stoptext
In LuaLaTeX you need luacolor
to use the attributes mechanism,
\documentclass{minimal}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{luacolor}
\newfontface\hebrew[Script=Hebrew]{SBL Hebrew}
\begin{document}
\textdir TRT
\hebrew
\textcolor{red}{א}\textcolor{blue}{֣}\textcolor{green}{֚}ב\textcolor{blue}{ָ}\textcolor{green}{ג}֦ד\textcolor{green}{֘}
\end{document}
P.S. I don't have Arial here and the only font I've with those marks is SBL Hebrew, so I used it for testing.