Accented Letters On ASCII Keyboards Under X11
It is described how the xmodmap command can be used to enhance a keyboard with additional characters, in particular characters from the ISO8859-1 character set.
The keyboard of an X terminal or of a PC or workstation with an X11 server can be redefined to include additional characters, e.g. characters from the Latin1 (ISO 8859-1) character set. There is a long article in German language describing in full detail the steps to take. This is a highly condensed English version of that article.
The mapping of a physical key (represented in the software by a numerical value, the keycode) to a graphic or control character (the keysymbol) is arbitrarily configurable with the xmodmap command. As an X server has only one keyboard, a change of this mapping will immediately affect all windows on that server irrespective of the applications running there.
When assigning keys to additional characters, other characters will be removed from the keyboard unless provision is taken to enlarge the total number of characters on the keyboard. To this end, a key must be reserved to have the function that pressing this key together with another one yields a character from a different character set. This mode switch key can also be combined with the Shift key. If, for instance, the Alt key is selected as mode switch key, and the letter ä is put on the a key, one can write an ä by pressing Alt-a and an Ä by pressing Shift-Alt-a.
The choice of the mode switch key is arbitrary. You have only to avoid overloading a key you still need (e.g. both Alt keys if you are emacs user). Taking the CapsLock key for this purpose is quite popular because few people really need its normal function.
Now the input file for the xmodmap command needs directives for two purposes:
- to tell which key is selected as mode switch key.
- for each key with a graphic character, to tell the four characters that can be input with that key: without and with the Shift key and the mode switch key.
The xmodmap directives for the mode switch key are preconfigured in files you get by clicking on the links below, depending on your choice:
- each of the two Alt keys
- only the left or only the right Alt key
- the right Ctrl key which sometimes passes under the name "Option"
- the CapsLock key
The directives for the assignment of characters to the keys are also preconfigured in a file. The keyboard layout chosen is explained below in a diagram. There, each field contains in its lower left-hand corner the character yielded by pressing the key alone, above it the character yielded by the combination with the Shift key and at the right-hand side the result of the additional combination with the selected mode switch key.
The keyboard layout described by this directive file is designed to have all already existing characters on their previous places, thus also conforming to the labels on the keys, and to add as many additional characters as possible by the usage of the mode switch key.
It is not easy to distribute (most of) the Latin1 characters which are mostly accented vowels in a mnemonically reasonable way over a keyboard consisting mainly of consonants. Here, it was done according to the following rules:
- The umlauts (in fact, all vowels with diaeresis) are placed on the keys with the base vowel.
- German sharp ß is placed on the s.
- Vowels with acute accent or with grave accent are placed on the key right above (or right below, resp.) the keys with the base vowel.
- Vowels with circumflex accent are placed on a still unassigned key near the base vowel.
- The remaining characters are scattered as reasonably as possible.
And here is the result:
That the vowels with diaeresis have the most prominent places is, of course, due to German usage. French, Spanish or Italian users may wish to have vowels with circumflex (or acute or grave, resp.) accents on this place. This can be easily achieved by swapping all occurences of the string "circumflex" (or "acute" or "grave", resp.) with all occurences of the string "diaeresis" in the configuration file. Note, however, that the letter y cannot carry all accents in the Latin1 code: only the upper and lower case ý and the lower case ÿ are in the character set.
The German version of this article contains two more keyboard layouts that are more specifically tailored for German users, in particular by swapping the y and z keys as usual on German (QWERTZUIOPÜ) keyboards.
When you have the two sets of directives in a file file, enter the command
to redefine the keyboard. To make it a permanent change, insert the xmodmap command into your .xsession or .xinitrc file. It may be wise to have it preceded by the commands
xmodmap -pm >other_file
xmodmap -pke >>other_file
to save the keyboard status prior to execution of the xmodmap command that modifies the keyboard layout. The result of the second of these two commands can be used as input to xmodmap. If you look into this file, you will see that there the keysymbols are defined based on keycodes. Repeated execution of these directives will therefore always yield the same result.
The directive files for the redefinition of the keyboard you got from this server, however, contain keysymbol definitions based on previous keysymbols. In fact, the directive
keysym a = b
is just an abbreviation of
keycode x = b for all keycodes x that have now the keysymbol a assigned
This has the drawback that repeated execution of these directives will in general produce different results each time. It was done so because keycodes are so much dependent on a particular brand and type of keyboard that no directive file is conceivable that would be adequate for many users. Rewriting the directives to contain keycodes instead of keysymbols, if at all necessary, is left as an exercise to the reader.
Modifying your keyboard may be not enough to allow processing non-English language. The selection of fonts or the setting of environment variables may also be necessary. For details see the FAQ on internationalization (i18n).