I have got the following problem: I am using Biblical Hebrew texts written in XeTeX but I would like to color consonants as well as vowel and accent signs differently. I have read Coloring combining characters without changing color of a base character, but the ways suggested to have it done seem too laborious.
So, is there a more straight forward way to assign – more or less permanently – each unicode sign (or maybe an entire consecutive unicode sign range) an inidvidual color? For instance, as in the linked example, I would like all consonants to appear in black, all vowels signs in red and all accent signs in blue.
Best Answer
I once tried to color ligatures for proofreading. I wanted them to stand out better. LaTeX automatically uses ligatures for ffl ffi and such combination of letters. However there are typesetting rules in German where the ligatures are not used. So to actually see where LaTeX inserted ligatures a discussion started on de.comp.text.tex lead to the idea of using Tex's virtual fonts to do the trick.
I managed to do this with the MiKTeX distribution back in 2006, so please bear with me if I don't get all the details right. Basically I changed the glyphs color per virtual fonts.
I used the command line tool
vftovp
to convert the exisiting.vf
files into.vpl
files. (virtual property lists) Viatestfont /table
I checked which ligatures where available in the font and then changed their entries in the.vpl
file:then compiled them via
vptovf
back into.vf
files and thenpdflatex
produced.pdfs
with colored ligatures. The two special commands switch the color to red and then back to black. This a very crude hack! But it worked back then. As the whole LaTeX font business is not for the faint-hearted it probably takes some experimenting with the current TeX-distributions.If you have to create a new virtual font you choose a font you want as a base font. In your case the Hebrew font. As I don't know much about XeTeX I continue this example with a helvetica clone (
phvr8r
).should give you the human readable virtual property lists. Which can now be edited. For example the lines
load
phvr8r
(our base font) andpcrr8r
(Courier). Now you have to know which characters you want to change.This picks character (octal
045
) from font1
moves left a bit and picks character (octal051
) from the other font. I don't know anything about the Hebrew fonts, but if the glyphs are combined like this you could intersperse commands for color changes like in the first example.Then you create the virtual font (a
.vf
and a.tfm
file) viaIt's ready for use now. But the tricky part is often that within the TDS (TeX Directory Structure) the font files have to be in the right subdirectory to be found by TeX. And often the filename database (FNDB) of the TeX-distribution must be refreshed after this type of change.
I don't know if XeTeX knows something like plain-TeX, there a simple test file looks like this:
With LaTeX and pdfLaTeX typically a
pdftex.map
and the font definition files.fd
have to be adjusted or created. The best approach is to use the exisiting files from the base font and make small modifications to them to learn about all the pitfalls. The\pdfmapline
command could be of some use in the latex document to add your modified font.The UK TeX FAQ has an entry about virtual fonts.