[Tex/LaTex] Writing Biblical Hebrew texts with different coloring for consonants, vowel and accent signs

characterscolorhebrewpolyglossiapunctuation

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) Via testfont /table I checked which ligatures where available in the font and then changed their entries in the .vpl file:

(CHARACTER O 33
    (CHARWD R 0.777781)
    (CHARHT R 0.683332)
    (MAP
        (SPECIAL pdf:direct: 1.0 0 0 rg)
        (SETCHAR O 2)
        (SPECIAL pdf:direct: 0 0 0 rg)
    )
)

then compiled them via vptovf back into .vf files and then pdflatex 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).

tftopl phvr8r.tfm > myfont.vpl

should give you the human readable virtual property lists. Which can now be edited. For example the lines

(MAPFONT D 0 (FONTNAME phvr8r))
(MAPFONT D 1 (FONTNAME pcrr8r))

load phvr8r (our base font) and pcrr8r (Courier). Now you have to know which characters you want to change.

(CHARACTER O 65
   (CHARWD R 0.8)
   (MAP
      (SELECTFONT D 1)
      (SETCHAR O 045)
      (MOVELEFT R 0.200)
      (SELECTFONT D 0)
      (SETCHAR O 051)
      )
   )

This picks character (octal 045) from font 1 moves left a bit and picks character (octal 051) 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) via

vptovf myfont

It'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:

\font\myfont=myfont
\hsize 2in
\myfont
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis hendrerit dictum nisi
a suscipit. Proin velit arcu, tincidunt et gravida ac, pretium vel nunc. Suspendisse
scelerisque malesuada orci, quis volutpat diam ornare nec. Duis ligula est, posuere
non auctor ut, sodales elementum lacus. Nam egestas, diam et varius ornare, nisi
mauris posuere turpis, eu adipiscing diam mauris consequat nulla. Cras id lacus non
ante malesuada sodales. 
\bye

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.

Related Question