TeX - LaTeX Asked by ojs on September 27, 2021
I am trying to find out is there a good way to paint combining characters without changing the color of the base character they are combined with. My actual problem case is to make some Hebrew inflection charts with colored prefixes and suffixes. Problem area there is to being able to color vowel points, cantillation and other diacritical marks without changing the color of the base consonant. As a clarification, in following image from Wikipedia, consonants are in black, vowels in red and cantillation in blue.
As an illustration what I would like to be able to produce, I quickly photoshopped following example.
In my search so far, I have found that there has been discussion about this question in XeTeX mailing list in 2007. Back then there was not perfect solution. However a workaround with two overlapping words with different colors was proposed. Also there was noted that coloring solution for ArabTeX could be ported for Hebrew.
Unfortunately the workaround is quite laborious solution as you have to write every word twice, and also it doubles the chances to write something wrong. As what comes to the idea of porting ArabTeX, I am far too inexperienced with TeX that I could give that a try.
So I am hoping that there has been some development with this problem since 2007 with XeTeX or this can be achieved gracefully with some other tools.
Also please note me if you happen to know that this can be achieved word processors such as Word, OpenOffice.org Writer etc, as I am not aware if they can handle this either. (I know that Word can paint all diacritics, but I am not aware if it can paint just some diacritics.)
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}
newfontfacehebrew[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.
Correct answer by Khaled Hosny on September 27, 2021
To exemplify Caramdir's comment, the following minimal example produces base and combining characters of different color when compiled with XeLaTeX or LuaLaTeX:
documentclass{minimal}
usepackage{fontspec}
usepackage{xcolor}
setmainfont[Script=Hebrew]{Arial}
begin{document}
textcolor{red}{א}textcolor{blue}{֣}textcolor{green}{֚}בtextcolor{blue}{ָ}textcolor{green}{ג}֦דtextcolor{green}{֘}
end{document}
Answered by Philipp on September 27, 2021
One possible solution would be to exploit the babel Hebrew support. Recall that cp1255, for instance, has the following declaration:
DeclareInputText{200}{hebqamats}
Using renewcommand
, you could redefine hebqamats
to include coloring commands prior to the insertion of the actual glyph. In order to avoid infinite loops, you'd of course have to refer to the glyph by its cp1255 character code (200).
Answered by user4602 on September 27, 2021
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
Answered by Khaled Hosny on September 27, 2021
I will here sum up a solution hinted at in a mailing list post linked to in the OP's question (the link in the question is dead; working link here: XeTeX mailing list link, 2007 July, 6989).
It is possible to achieve this in XeLaTeX without the use of any additional packages if you have access to a font editor software. However, there is some manual work involved and it is probably too tedious if you have more than a handful of cases.
The trick is to make a duplicate of the base letter and make it invisible, then use negative kerning to overlay the invisible base + colored mark with the normal (black) base.
The procedure is as follows (exact steps depend on the font editor):
{color{red} INVISIBLE BASE + MARK}kern-1.42ex NORMAL BASE
. You will need to adjust the value for kerning, which you can calculate from the width of the base / x-height.I have successfully used this procedure with the font editor Glyphs and XeLaTeX to make colored bases with black diacritics (so the inverse of the OP's question).
Answered by lvcivs on September 27, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP