Keyboard Entry of Polytonic Greek
and Biblical Hebrew in GNU/Linux

by Vern S. Poythress

Aug., 2008

I am a biblical scholar who writes in English, but who also needs to be able to type Greek and Hebrew into a word processor. I am offering these informal notes concerning my own experience developing keyboard entry for Greek and Hebrew in GNU/linux.

Modern Greek and modern (unpointed) Hebrew can already be entered from the keyboard because of the internationalization of GNU/linux. But it is more challenging to deal with unicode polytonic (classical) Greek or biblical Hebrew (with vowel points and accents). The Summer Institute of Linguistics has provided a keyboard driver that enables scholars to type unicode Hebrew in Windows 2000 and Windows XP. But I have not been able to find in one place all the necessary information with respect to GNU/linux. So I am providing here what I have learned.

Getting Unicode Greek and Hebrew fonts

Some older specialized Greek and Hebrew fonts differ from one another in their encoding. Texts using these fonts cannot be searched in a uniform way, because each font has its own idiosyncratic coding. The answer to this is unicode, which provides an international standard for encoding all languages.

In the long run, you should definitely use unicode-encoded Greek and Hebrew. But the transition to unicode has taken awhile, and is only now coming to fruition.

First, you need unicode-based Greek and Hebrew fonts. There are several. SBL Hebrew, available through the SBL website, will probably become the standard for biblical Hebrew. But there are restrictions on its commercial use. I recommend Ezra SIL Hebrew as a font without such restrictions. For Greek, New Athena Unicode or Gentium or FreeSerif will do. I understand that SBL is working on a Greek unicode font, but I do not think it is yet available, as of Aug., 2008.

Installing your Greek and Hebrew fonts

Now you must install the fonts that you have downloaded. Some are contained in zip files, and for these you must first extract the included .ttf files. From the command line, go to the directory into which you downloaded the file, and type

unzip filename.zip

where "filename.zip" is the name of the file. Or extract the files using your file manager Nautilus or Konqueror. Now you need to install the font files (with .ttf suffix). Most up-to-date GNU/linux distributions have a simple utility for doing font installation. Use that if you want. Or, in Fedora Core 8 or 9 or Ubuntu 8.04 (my system), look for the directory ~/.fonts (i.e., /home/username/.fonts, where "username" is your username). If this directory does not exist, create it (mkdir /home/username/.fonts). Then copy the .ttf files to ~/.fonts. Then restart Xwindows (by logging out and then back in) so that these new fonts will be recognized.

Finding your characters in the unicode charts

To have more information about the unicode coding for the characters, you will probably also want to have the unicode code charts for Greek and Hebrew. On the internet, go to the Unicode home page (www.unicode.org), and then to the Unicode Character Code Charts. Click on Greek (under the European Alphabets), and print out the pdf file that is displayed. Do the same for Greek Extended (under the European section), Hebrew, and Hebrew Presentation Forms (under Middle Eastern Scripts).

Entering characters one by one

Once your fonts are installed, you can start OpenOffice or KWord and it will have your fonts on its list of fonts to choose. But if you just choose the font and start typing, the text will still come out as Latin characters. You can insert a single unicode character by clicking on the "Insert" menu, and under that "Special Character ..." Pick the font that you want (it must be a unicode font that includes Greek or Hebrew glyphs), and then search for the particular character in the unicode tables that are displayed for that font. Click on the character, and then "OK" (OpenOffice) or "Insert" (KWord). (The last I checked, Abiword can't yet do this. It will come.)

But of course if you have many characters to insert, this route becomes tedious. That is why you may want to have "keyboard maps" that allow you to type in whole words and sentences at once.

Adding keymaps

Dealing with keymaps was the most challenging part for me.

Step 1. Fix the locale. Open a command line (terminal emulator), and type "locale". Then press the <Enter> key. If your main language is English, you should get as the first line of the output:

LANG=en_US.UTF-8

If this is what you get, all is well.  You can go to Step 2.  If not, you can change the locale by entering the following command:

export LANG=en_US.UTF-8

This tells your system that you are unicode-capable (the "UTF-8" part) and that your base language is US English (the "en_US" part). To make this change carry over after you reboot, you need to get root privileges and then add a line to /etc/bashrc or /etc/profile:

export LANG=en_US.UTF-8

Also eliminate any line in /etc/bashrc or /etc/profile that sets LANG to another value. You may also need to check /home/username/.bashrc to see whether it sets the LANG value for a particular user.  (If you just want to have this feature for one user, rather than for all users, you would change the file /home/username/.bashrc rather than /etc/profile.)

Step 2. Obtain keymaps. I made some special keymap files that you can download for the purpose: gr.new and il.new.  Or download all the files I have provided in one zipfile. These files tell your computer how various keys of your keyboard correspond to Greek characters (gr.new) and Hebrew characters (il.new).  If you do not like the way I set up the keymaps, you can edit these files with a text editor.

Step 3. Find the place to install the keymaps. The question is where. In Fedora Core 8 or 9 or Ubuntu 8.04, navigate to /usr/share/X11/xkb/symbols (This subdirectory should exist. If it does not exist in your linux distribution, try a file search to locate the subdirectory "xkb".) The subdirectory xkb should have a subdirectory called "symbols," in which will be text files like ad, af, al, am, gr, il, and others.  Each of these is for a particular language.

Step 4.  Back up your current keymaps for safety.  That way, if the changes do not work, you can always go back to the original setup that you had before.

Here is one way of doing a backup with a command line:

cd
mkdir keymapbk
cp -v /usr/share/X11/xkb/symbols/gr keymapbk/gr.orig
cp -v /usr/share/X11/xkb/symbols/il keymapbk/il.orig

Step 5. Install the keymaps. Navigate to where you downloaded the new keymaps (the ones that I supplied), obtain root privileges, and from the command line do:

cp -v gr.new /usr/share/X11/xkb/symbols/gr
cp -v il.new /usr/share/X11/xkb/symbols/il

Step 6. Alter your desktop manager so that it knows about multiple keymaps. There are at least three ways of doing this.

    a.  If you use KDE 3, go to the KDE Control Center (Menu -> Control Center), choose "Regional & Accessibility" and then "Keyboard  Layout."  Click to put an "X" in "Enable keyboard layouts" if one is not already there.  Pick from the list of "Available layouts" "Greece" and then click "Add."  Do the same for "Israel."  Click "Apply."  Later on you can tweak some of the options under "Switching Options" and "Xkb Options" if you like.  You switch between the keymaps by clicking on an icon in your panel that has the two letter abbreviation for the current language.  Right-clicking on it gives you more options.

    b.  If you use Gnome, go to an empty spot on the panel and right-click on it.  Choose Add to Panel -> Keyboard Indicator.  Click on "Add."  The icon should appear.  Click on "Close" to close out the "Add to Panel" window.  Then right click on the newly added icon for Keyboard Layout (if your base language is US English, the icon will have the letters "USA").  Select "Keyboard Preferences."  Select the tab labeled "Layouts."  Then add the "Greece" and "Israel" layouts.  See <http://oriya.sarovar.org/docs/getting_started/node32.html> for more detail (but this webpage tells how to add the Oriya language; you will have to adapt it for your needs). 

    c.  I myself prefer to deal directly with an important configuration file, /etc/X11/xorg.conf (the Xwindows configuration file), because that will affect all the desktop managers at once.  You can edit /etc/X11/xorg.conf so it knows about the new keymaps. Here is how.

Obtain root privileges. Backup xorg.conf for safety:

cp -v /etc/X11/xorg.conf /etc/X11/xorg.conf.bak

Open /etc/X11/xorg.conf with your favorite text editor:

emacs /etc/X11/xorg.conf

Scroll down to the Section labeled 'Section "InputDevice"'. There are sometimes two such sections, one for the keyboard and the other for the mouse. Find the one for the keyboard. After some comment lines beginning with '#' it will say 'Identifier "Keyboard0"' or something similar. It should also have lines like

Driver "kbd"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"

If there is a line

Option "XkbVariant" "nodeadkeys"

make it a nonoperating comment by adding '#' at the beginning of the line. Also comment out

Option "XkbLayout" "us"

by adding a leading '#'.

Now add two new lines:

Option "XkbLayout"   "us,gr,il"
Option "XkbOptions" "grp:alt_shift_toggle,grp_led:scroll,compose:lwin"

The keyboard section should now look about like this:

Section "InputDevice"
    Identifier  "Keyboard0"
    Driver      "kbd"
    Option      "XkbModel" "pc105"
#    Option      "XkbLayout" "us"
    Option      "XkbLayout" "us,gr,il"
    Option     "XkbOptions" "grp:alt_shift_toggle,grp_led:scroll,compose:lwin"
EndSection

Finally, save the altered file (ctrl-X s y in emacs). Exit your text editor (ctrl-X ctrl-C in emacs).

Note: if you earlier activated the KDE or Gnome Keyboard Layout switchers, you will have to turn these back off (reverse your steps) for this third way to work.

This third way will also work with Xfce-4. Xfce Desktop offers an applet to control keyboard layouts, just as Gnome and KDE do. If you want it, right click on the main panel, click "Add New Item," then scroll down to "Keyboard Layout Switcher." Click on it, and click "Add." Select either "image" or "text," depending on whether you want the country flag or the country abbreviation to be displayed in the icon. Click "Close" when you are done.

Xfce requires that you first set the file xorg.conf in the way described above. It currently does not permit you to add or subtract languages directly from your desktop.

Step 7. Restart Xwindows so that it knows about these alterations.

Explanation

The alterations you just made tell Xwindows that it is supposed to search for and use three distinct keymaps, "us" (normal latin alphabet), "gr" (Greek), and "il" (Hebrew). (Here I am once again assuming that your main language is English.  Users working mainly in other languages may want something else besides "us.")  If you used the keyboard layout utilities in KDE or Gnome or Xfce, you switch between layouts by clicking on the icon symbolizing the current layout.  If you directly edited xorg.conf, you switch between the three by pressing down the right "Alt" key and the right "Shift" key at the same time.  (That is the meaning of the expression "grp:alt_shift_toggle" that you added in the xorg.conf file.) When you do that, the LED for "Scroll Lock" should light up on your keyboard. When you do it a second time, the keyboard shifts to Hebrew. When you do it a third time, the keyboard shifts back to English and the scroll lock LED goes off. Xfce permits you to use either its Keyboard Layout Switcher or the keyboard shortcut Right-Alt-Shift.

If the scroll lock LED does come on, it means that the keyboard is shifting between the keyboard layouts. (Technically, there is no change in what the keyboard as a physical attachment puts out. Rather, software changes the interpretation of the keyboard outputs.) Now within a wordprocessor, you still have to tell the wordprocessor to use an appropriate font. Choose "SBL Hebrew" as your font before starting to type Hebrew.

Troubleshooting

If you chose to edit xorg.conf, and if the scroll lock does not come on at all, the whole system is probably not working, and you will have to trouble-shoot to see whether the extra lines that you added in xorg.conf and the key extra files in /usr/share/X11/xkb/symbols/ are really where they are supposed to be. Try deleting one of the three keymaps in xorg.conf, under the line

Option "XkbLayout" "us,gr,il"

Make the line read

Option "XkbLayout" "us,gr"

See whether you can at least get it to toggle between two layouts. If this won't work, try copying the original gr file back to its original location, and see whether things will work.  Or try

Option "XkbLayout" "us,il"

This uses two keyboard maps, the standard US latin map and Hebrew.

If you are doing much of this type of tinkering, you may find it convenient to use a special command, setxkbmap. To use the command, open a command line terminal, and use the syntax:

setxkbmap us,gr,il -option grp:alt_shift_toggle,grp_led:scroll,compose:lwin

Use this command to make on the fly whatever alterations you want in the list of keymaps and in the keys that control the toggling. The effects should show immediately within applications like OpenOffice and KWord. When you are through tinkering, be sure to put what you want to be final into the file xorg.conf. (The syntax in xorg.conf is somewhat different from that of setxkbmap.  But the two are related. The examples I have given above should suffice to show what the appropriate lines in xorg.conf should be.)

The challenge of polytonic Greek

Suppose that the system is working.  You probably still do not have polytonic Greek working right.  You can get Greek letters to appear with no accents, and you can probably get letters to appear with an acute accent, but not with a grave or a circumflex.  The "Compose" file supplied by Fedora or Ubuntu will probably have to be replaced with the one that I have supplied ("Compose.new").  Do the replacement as follows.

Get root privileges.

Find the location of the xkb subdirectory, as you did above.  In Fedora 8 and 9 and Ubuntu 8.04, it is at /usr/share/X11/xkb.

Navigate to the place where you have my special file with the filename "Compose.new."

Issue the following commands:

mv -v /usr/share/X11/locale/en_US.UTF-8/Compose /usr/share/X11/locale/en_US.UTF-8/Compose.orig
cp -v Compose.new /usr/share/X11/locale/en_US.UTF-8/Compose

Now polytonic Greek should work correctly in KWord. Currently there is another problem related to the GTK functions used by Open Office. Thanks are due to Adriaan Pater for informing me that these can be cured by adding a line to the file /etc/profile. (If you want the change only for one user, add the line instead to /home/username/.bashrc.) Here is how to do it.

Get root privileges.

Open /etc/profile with your favorite text editor.

At the end of the file, add an extra line:

export GTK_IM_MODULE=xim

Make sure that there is a carriage return at the end of this line.

Now save the edited file and exit from your text editor.

The change will appear the next time you reboot. To make an immediate change, open a terminal and enter the command:

export GTK_IM_MODULE=xim

Other options

If you like, you can choose another combination of keys to do the toggling among keymaps. "grp:lwin_toggle" uses the left "Windows" key to toggle among the keymaps.

Keymaps

I have chosen the keymaps for Greek to suit my own convenience.  (My apologies to native Greek and Hebrew speakers, who expect something else.) Here is a list of equivalences:

Greek US Greek (caps) US
alpha α a cap alpha Α A
beta β b cap beta Β B
gamma γ g cap gamma Γ G
delta δ d cap delta Δ D
epsilon ε e cap epsilon Ε E
zeta ζ z cap zeta Ζ Z
eta η h cap eta Η H
theta θ q cap theta Θ Q
iota ι i cap iota Ι I
kappa κ k cap kappa Κ K
lambda λ l cap lambda Λ L
mu μ m cap mu Μ M
nu ν n cap nu Ν N
xi ξ x cap xi Ξ X
omicron ο o cap omicron Ο O
pi π p cap pi Π P
rho ρ r cap rho Ρ R
sigma σ s cap sigma Σ S
finalsigma ς v
tau τ t cap tau Τ T
upsilon υ u cap upsilon Υ U
phi φ f cap phi Φ F
chi χ c cap chi Χ C
psi ψ y cap psi Ψ Y
omega ω w cap omega Ω W
Greek question mark ; ;   or  ? Greek colon ? :
iota subscript   j
acute accent ' (apostrophe) or / (slash) diaeresis "
grave accent ` (grave) circumflex accent ~ (shifted tilde key)
rough breathing 9 or shift-9 '('
smooth breathing 0 or shift-0 ')'
diaeresis " (double quote)

Adriaan Pater has kindly provided keyboard pictures with each key labeled appropriately.  There is one picture for Greek and one for Hebrew

If you like, you can edit the file "gr" in order to change some of the key assignments. However, if you rename the file when you edit it, Xwindows will no longer find it. If you want to do the renaming nonetheless, make sure that you not only edit xorg.conf appropriately, but edit internal cross references within the gr file. Within gr there are several keymaps built on one another, and the more extended ones build on the simpler ones.

For Greek, when you are keying in accents and breathing, note the following.  (1) The accents must be keyed in before the character for which they are accents. Similarly, iota subscript, counterintuitively, must be keyed before the character to which it is attached. (2) The accents will not appear on screen until the vowel to which they belong is keyed in. (3) When several accents belong to the same vowel, they should be keyed in more or less in a right-to-left order. Thus omega with rough breathing, acute, and iota subscript should be keyed in with iota subscript (j) first, then acute (apostrophe), then rough breathing (left parenthesis). If you don't use this order, the full result may not come out. (This could be changed by editing the file /usr/share/X11/locale/en_US.UTF-8/Compose, but that is for another day.)

For Hebrew I have constructed a keymap that actualizes the keyboard described by John Hudson in his Tiro manual for Hebrew. You can edit the file "il" if you want to change some of the key assignments.

This Hebrew keymap has four "levels." But not every key has an output on all four levels. The first level is normal. Just press the 'm' key to get m on the normal level. The second level is the "shifted" level.  Hold down the shift key and then press the 'm' key (or whatever key you need). The third, called "ALTGR" in John Hudson's documentation, is supposed to be accessed by holding down the right alt key or right alt + ctrl. But OpenOffice already appropriates the right alt key for other uses. I have therefore set up the keymaps so that the right "windows" key is used instead. Hold down the right "windows" key, which in a typical keyboard is right next to the right alt key, and which has a Microsoft logo on it. While holding it down, press the key that you need. Thus the meteg accent can be added by holding down the right windows key and then pressing the 1 (numeral 1) key. The fourth level is accessed by simultaneously holding down the right windows key and the right shift key, and then pressing the key that you want.  On some systems, the shift key must be held down first, and then the right windows key.

Hebrew US key
alef א shifted-period
bet ב b
gimel ג g
dalet ד d
he ה h
vav ו w
zayin ז z
het ח x
tet ט v
yod י y
kaf כ k
finalkaf ך K
lamed ל l
mem מ m
finalmem ם M
nun נ n
finalnun ן N
samekh ס s
ayin ע shifted comma
pe פ p
finalpe ף P
tsadi צ c
finaltsadi ץ C
qof ק q
resh ר r
sin (no dot) ש S
sin (with dot) f
shin (with dot) j
tav ת t
patah  אַ a
hataf patah  אֲ rwin-shift A
qamats  אָ A (shift a)
hataf qamats  אֳ rwin-shift O
segol  אֶ e
hataf segol  אֱ rwin-shift E
tsere  אֵ E
hiriq  אִ i
holam  אֹ o
qubuts   אֻ u
sheva  אְ semicolon
dagesh אּ equal sign '='
dehi א֭ rwin 6
etnahta א֑ rwin equal-sign
geresh א֜ shift 4
gershayim א֞ shift 5
iluy א֬ shift 7
mahapakh א֤ rwin backslash
maqaf ־ hyphen '-'
merkha א֥ rwin 4
merkha kefula א֦ rwin 5
meteg or silluq אֽ rwin 1
munah א֣ rwin 7
pashta א֙ rwin-shift 6
qadma א֨ shift 3
rafe אֿ rwin-shift hyphen
revia א֗ Q
sof pasuq ׃ rwin-shift semicolon
tevir א֛ rwin 8
tipeha א֖ rwin 3
yerah א֪ rwin 0
yetiv א֚ rwin right-bracket
zaqef qatan א֔ rwin-shift left-bracket
zaqef gadol א֕ rwin-shift 8
zarqa א֘ shift 2

For a list of keys for all the other accents according to il, see John Hudson's Tiro manual for Hebrew.  Adriaan Pater has provided a picture of a keyboard for Hebrew.

For Hebrew, care should be taken to enter pointing and accents in the order specified in the SBL Hebrew manual. This manual comes along with the SBL Hebrew download. Once unzipped, it is named "SBLHebrew-Manual.pdf." The section entitled "Mark ordering" gives the information.

Other special characters

I have found that on occasion I need to enter accented Roman characters, such as e with an acute accent or o with an umlaut. You can do this in OpenOffice or in KWord in the way that I have already described, by using the main Menu, selecting "Insert," and then "Special Character." Or you can introduce an international keyboard, or add a French or German language keyboard. But for my use, the simplest solution is to stay with the US keyboard, and use a "multi-key" key or "compose" key preceding the accent. Here is how to do it in Gnome.

Step 1. From your menu, select System/Preferences/Keyboard.

Step 2. Select the "Layouts" tab. Click on "Layout Options ..." near the bottom right. Click on "Compose key position." Check on "Left Win-key is Compose," or whichever option that you want as your compose key. Click "Close" twice to exit.

Xfce is automatically set up to use the compose key, once you have edited the file /etc/X11/xorg.conf in the way indicated above.

Now, open OpenOffice Writer or KWord. To compose an e with an acute accent, press the compose key (in my case, the left Windows key), then single quote ('), then "e." To compose e with grave accent, press compose, then grave (`), then "e." To compose o with umlaut, press compose, then double quote (shift single quote), then "o." The cent sign is compose, slash, "c." The sign for British pound is compose, minus, "L." c with cedilla is compose, comma, "c." The Euro symbol is compose, "=", "c." Similarly with other special characters. By opening the "Compose.new" file with a text editor, you can see many other combinations. The expression "Multi-key" is the same as "compose."


Vern S. Poythress, Ph.D., Th.D.
Westminster Theological Seminary
Philadelphia, Pennsylvania


Copyright (c) 2007 by Vern Sheridan Poythress.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found at the Free Software Foundation website.