Inputting french, pinyin and other.
Being in China, I lately had to customize my keyboard layout so I can input french accents on my qwerty keyboard. I am using the standard X input method to do it and I found out it was really powerful.
First I defined a file called .Xmodmap in my HOME directory. It looks like
keycode 113 = Mode_switch keycode 116 = Multi_key keysym q = q Q acircumflex Acircumflex keysym e = e E eacute Eacute keysym r = r R egrave Egrave keysym u = u U ucircumflex Ucircumflex keysym i = i I icircumflex Icircumflex keysym o = o O ocircumflex Ocircumflex keysym a = a A agrave Agrave keysym d = d D ediaeresis Ediaeresis keysym f = f F ecircumflex Ecircumflex keysym h = h H ugrave Ugrave keysym j = j J udiaeresis Udiaeresis keysym k = k K idiaeresis Idiaeresis keysym c = c C ccedilla Ccedilla keysym z = z Z guillemotleft keysym x = x X guillemotright keysym period = period greater U2026 keysym 5 = 5 percent EuroSign keysym 6 = 6 asciicircum dead_circumflex keysym 7 = 7 ampersand dead_caron dead_breve keysym 0 = 0 parenright dead_abovering keysym minus = minus underscore dead_macron U2014 keysym semicolon = semicolon colon dead_diaeresis keysym apostrophe = apostrophe quotedbl dead_acute keysym grave = grave asciitilde dead_grave dead_tilde keysym comma = comma less dead_cedilla
(This file is loaded automatically by GNOME at boot but if you want to test it right after you modify it, you have to run “xmodmap .Xmodmap”)
The second line defines the right « Window » key as being the Compose key. Some keyboards have a Compose key but many don’t so we have to define it.
Here are samples of what you can do with this key.
Compose + ‘ then e = é
Compose + ` then a = à
Compose + ^ then u = û
Compose + ” then i = ï
Compose + o then e = œ
Compose + a then e = æ
Compose + o then c = ©
Compose + = then E = €
Compose + = then Y = ¥
Compose + % then o = ‰
Compose + ? then ? = ¿
Compose + ! then ! = ¡
Compose + ( then 1 then ) = ①
Compose + 1 then 2 = ½
Many such sequences are possible. They are defined in /usr/share/X11/locale/en_US.UTF-8/Compose (may be slightly different on your system). Have a look at it. You may copy this file to your HOME directory, rename it .XCompose and define new sequences you like. Very powerful.
I have defined (in .Xmodmap) the position of uncommon dead keys such as ¯ (macron) or ˇ (caron) because the sequence defined by default is not easy to remember. So now I can input the four tons of chinese pinyin (transcription of chinese). Easy!
āēīōūǖ
áéíóúǘ
ǎěǐǒǔǚ
àèìòùǜ
For some characters that are not often used, the Compose method is ok, but inputting quickly is not possible this way. So I defined another method. The first line of my .Xmodmap file defines the right Alt key as Mode_switch, which as the name shows, allows to switch mode.
Let’s take this line:
keysym e = e E eacute Eacute
On the right part of the equal, the first character is the one which is input directly. The second one is input with Shift. The third one is input with right Alt. The fourth with right Alt and Shift. So Alt + e gives directly me é (an e with an acute accent). Alt + Shift + e gives É (accents are required on capital letters in French!).
Alt + e = é (most common accent for e)
Alt + r = è
Alt + d = ë
Alt + f = ê
Alt + a = à
Alt + q = â
Alt + u = û
Alt + h = ù
Alt + j = ü
Alt + i = î
Alt + k = ï
After a few hours of use, we can easily get used to it and it gets very fast to type.
In addition, I defined neat and useful characters such as :
Alt + z = «
Alt + x = »
Alt + . = …
Alt + _ = —
To know the code number of keys, one can use xev which is a program that captures X events and print informations about it.
It is useful to know that GTK applications don’t load the whole list of Compose sequences by default, just a subset. For example Compose + o then r = ® is not recognized. One has to right click and choose « X Input Method » in the « Input Methods » section or to run a program with GTK_IM_MODULE=xim (e.g. GTK_IM_MODULE=xim gedit).
But SCIM seems to also enable XIM at the same time hopefully. So all those combinations work when using SCIM.
mathieu@mathieu-desktop:~$ cat /etc/X11/Xsession.d/78custom-scim_init export XMODIFIERS="@im=SCIM" export GTK_IM_MODULE="scim" export XIM_PROGRAM="scim -d"
This files starts SCIM at boot and allows to use SCIM as input method automatically for each GTK application. This way, it is very comfortable and easy to input Japanese, Chinese and French.
(This is a log for me of all informations needed for future reinstall of my system. Hope that can help someone else though)