Author: Juraj Sipos
XKB and Xmodmap
First, I must say that Linux (Unix) uses two approaches to configure the keyboard layout (they are both independent of each other): XKB and Xmodmap. XKB is an extension of X, many people say that it is better, but too robust and perhaps less understandable by beginners. Xmodmap is one of the oldest ways how to configure your keyboard layouts – a little easier approach, especially good for experimentation, but no only that.
XKB, too, allows a number of easy solutions, but if we look at hundreds of Linux distributions and Window Managers including BSD, Xmodmap solution basically works the same way everywhere – whether on PC-BSD, SuSE Linux, Debian Linux, Slackware Linux, etc. The same can be said about XKB, too, but only from the system perspective. In the comfortable environment like GNOME/KDE, things are always a little easier than in other WM’s. This is not a problem for experienced users, but for beginners it may sometime be a difficult task to find a way how to type some special – that is, very exotic characters.
But let us forget all these technical discussions on how the above two approaches differ from each other – for now it is important to know that Xmodmap does not require any additional editing of /etc/X11/xorg.conf file; the user will just load the Xmodmap map by running the command: xmodmap /home/use /xmodmap.map. It will work on every X server. The only condition to successfully type any special character on your Linux/Unix box is to use the UTF encoding.
The Xmodmap utility is a command (xmodmap) that will load the xmodmap map (a text file with definitions for keyboard layouts). You can thus assign a number of characters to your keyboard keys and redesign your keyboard layout the way that is suitable for you. After you restart your X, you will be again working with the XKB approach, which is the default setup for Linux/Unix today. If you do not restart your X, you may reload another Xmodmap map.
Xmodmap approach is perhaps a little easier than XKB – especially when talking about Unix in global, because if you would like to learn Devanagari (Indian script used for writing), all you need is to have the .Xmodmap file in your home directory (the “dot” means that the file is a system file and that it will be loaded automatically) with the following contents only: keysym k = U0915 k
Linux (X) should load the .Xmodmap configuration file automatically and you, after pressing the letter “k”, should see the character “क”. “U0915 k” means that when you press a key with this definition (the letter “k” on the English keyboard), you will see the sign क (its UTF code is U0915) and after applying the shift key you will see our Latin character “k”. If you want a capital character of any available choice, write it capitalized into the Xmodmap map: U0915 K.
Do you want to remap a letter (or more) on your keyboard? Any code you put into the .Xmodmap file will be available for you after your X Window system starts, or even after you load your Xmodmap map manually – it can be additionally loaded by running the following command from the Terminal Window in your X environment: xmodmap /home/user/xmodmap.map
As I have a Hindu website, I am interested in Sanskrit, in its transliteration and how to use it easily in Linux/Unix. Transliteration is a conversion of one script (a writing system) from one writing system to another one, which can also render the phonetics; the term transcription is also used. In our cultural environment one writing system is mostly the Latin alphabet (romanization), when scholars (in scientific disciplines such as lexicography, etc.) use one system of transliteration, for example, Romaji – romanization of Japanese, or IAST for Sanskrit (International Alphabet of Sanskrit Transliteration).
For systems of transcription such as IAST, which also renders the phonetics, we must use special characters such as ā Ā ṝ Ṝ ṇ Ṇ ṣ Ṣ ṁ, so our standard Latin alphabet is not sufficient anymore.
It is also important to say that Sanskrit as a language is different from Hindi and both languages can be written into the Devanagari script. In India, there are many languages, and in addition to Hindi or Konkani, for example, the Devanagari script is also used in Nepal. For the reader to understand this – Sanskrit as a language can also be written in Tibetan scripts, the Tamil script, or even in the Siddham script, which the Shingon Buddhist school uses in Japan.
Researchers often work with transliteration (as well as with tools that automate the conversion process to Latin and vice versa) for various reasons. It is more convenient for people of a different cultural background – especially for Europeans and Americans. And if you are not familiar with some exotic languages, you can at least read them, so in case someone starts a research project aimed at mapping similar words between Indian and Slavic languages, for example, no one can deny the significance of transliteration and no time needs to be wasted by learning the complex and difficult “hieroglyphic” letters.
On the basis of this Xmodmap map any researcher or student can build his or her own keyboard layout. This Xmodmap map provides four keyboard layouts and you may toggle them by Caps Lock:
1) Standard (English) Keyboard (after you load the Xmodmap map with the command: xmodmap /home/user/xmodmap.map);
2) keyboard for IAST transliteration – Sanskrit;
3) user-defined keyboard only with “p p” strings to be later changed;
4) Devanagari – keyboard layout with the script to write Sanskrit and other Indian languages including Hindi.
If you press the Caps Lock key while working with the last keyboard (Devanagari) layout, you will return to the first (Standard English) keyboard.
This Xmodmap map requires UTF codes
However, if you need other languages such as Chinese, Telugu, Urdu, etc. – either to use the original writing system of such languages, or their transliterated form (in Latin), you should know something about UTF codes (that you must write into this Xmodmap map).
To type a variety of special characters, you need to have their UTF codes – use search engines, as they provide very rich resources. You can also alternatively look into the file
/usr/include/X11/keysymdef.h in Linux, or (/usr/local/include/X11/keysymdef.h in FreeBSD). The Latin letter ā (with a macron – a horizontal line above it) is defined in keysymdef.h as follows:
# define XK_amacron 0x03e0 / * U 0101 LATIN SMALL LETTER A
“U101″ is the Unicode code for the character ā.
If the keyboard map is not loaded automatically, or even in case one instance of it has already been loaded, you may load any other Xmodmap map and use any special characters defined in it: xmodmap /home/user/xmodmap.map2
The previously loaded keyboard layout will be deactivated and you will work with the keyboard layout map you have just loaded.
The Xmodmap map presented by this article allows 8 letters to be assigned to one keyboard key. As it allows toggling between four keyboards, I will explain one line of the definitions of keys in it:
keycode 0x1F = i I U012B U012A p p U0917 U0918
“keycode 0x1F” is a key that has standardly the letter “i I” assigned to it on our English keyboard. You may also use xkeycaps (xev, too) to find out which letter is assigned to which key – xkeycaps is a program that tells you everything about how characters are assigned to your (or any) keyboard. Thus, if you load this Xmodmap map, you will get the standard English keyboard layout at first. After pressing Caps Lock one time, you will toggle the keyboard to IAST transliteration – you will see the Latin small letter ī (with macron) when you press the letter “i”; after pressing the Shift key, you will see the Latin capitalized letter Ī (with macron). This also pertains to the letters like a, m, t, so try this out – ā Ā ṣ Ṣ ṁ, etc. Pressing Caps Lock again will toggle you to a user-defined keyboard layout that assigns “p p” characters to keys (not to all of them). The last time you press Caps Lock will allow you to write in the Devanagari script – after pressing the key “i”, you will see the sign ग.
Any available UTF codes you use in this Xmodmap map will appear on your screen in a good text editor (tested in gedit and OpenOffice.org) when you type them; however, some very special characters also require special fonts to be installed, as, of course, hardly any distributor of Linux expects that users want to write in Egyptian hieroglyphs.
Some “techie” information related to Xmodmap
This map was tested on my Debian, OpenBSD, Ubuntu, and FreeBSD box. I must say that in GNOME/KDE the third keyboard map (“p p”) may not work probably due to the reason that the GNOME/KDE desktop has its own system for localization. But after I uninstalled the Slovak Keyboard (GNOME> Preferences> Keyboard), all four keyboard layouts worked properly with this Xmodmap map.
In the worst case you need to press the Caps Lock key only twice (one time for the romanization of Sanskrit and second time for the Devanagari script); if you press it the third time, you are back in the first – English keyboard.
Some notes on how to use this keyboard layout with IAST transliteration
IAST is the International Alphabet for Sanskrit Transliteration, but it can also be used for transliteration of Devanagari, thus also languages such as Hindi and many others.
This Xmodmap map is a sample map and its primary purpose is to let users redefine their keyboards according to their needs. The keyboard map for IAST (after loading the map, you press the Caps Lock only once) corresponds to the English keyboard (which is the first keyboard layout) and it will allow you to type the following special (Latin) letters (“First” is the English keyboard layout, which is activated as soon as this Xmodmap map is loaded; for it to work, the Caps Lock key does not need to be pressed):
First: a A d D r R t T u U i I s S h H l L n N
IAST: ā Ā ḍ Ḍ ṛ Ṛ ṭ Ṭ ū Ū ī Ī ṣ Ṣ ḥ Ḥ ḷ Ḷ ñ Ñ
As the letter “n N” has several more alternatives (ṅ Ṅ ñ Ñ), the other instances of the letter “N” can be typed by using the apostrophe/tilde key and then the keys that start with and follow the number 1 on the standard keyboard layout:
Apostrophe / tilde (`~) corresponds to sign ṇ Ṇ
Number 1 corresponds to: ṅ Ṅ
Number 2 corresponds to: ṝ Ṝ
Number 3 corresponds to: ś Ś
Number 4 corresponds to: ḹ Ḹ
Users can type the Candrabindu sign in the IAST keyboard layout by pressing the key 0x15 on their keyboard (where the English keyboard has the equal sign combined with the plus sign): ̐.
Some lines in this Xmodmap map, such as the “keycode 0x15 = equal plus U0310 plus“, which contain only four items, can be extended to eight items.
Even though we work with the Latin alphabet, systems of transliteration vary. But users will be able to make their own keyboard layout and thus also any system of romanization used for transliteration of languages.
About the Author
I published some books of poetry and I live in Europe. I have a website about FreeBSD and I propagate freedom.
- Linux Terminal: An lsof Primer
- How to check if you are vulnerable to shellshock
- Ripping DVD with Handbrake on Linux
- Linux: Timeouting commands in shell scripts
- Switching to Linux, Checklist
Find me on Google+