RSS Feed

RSS
Comments RSS

HOWTO – Ububtu, a customizable Compose Key System

In my previous blog entry, I introduced both Unicode character entry and Compose Key entry of special characters.  One thing that becomes apparent is that there might be some characters or symbols missing from the default GTK+ code in Gnome.   Unfortunately, this is in compiled code and cannot be changed.  One option is to use Compose Key sequences for most special character entries and Unicode character entry for the occasional odd symbol.  However, if that “odd symbol” is one you intend to use often, you might wish you had a Compose Key sequence for it.   This can be accomplished, at a small price.

Situation, say you are an electronics enthusiast and have a need to type the Ohms symbol, Ω, quite often.  This symbol is not in the default GTK+ Compose Key sequences, and there is no way to add them easily into that source.   An option is to use the <Shft><Ctrl><u>03A9 Unicode method entry to get the Ohms symbol.  Sure, this works fine, but could be tedious if done on a regular basis.  What we need is a way to get this into a nice, intuitive, Compose Key sequence.  The solution is to take advantage of the fact that there is an alternate source for the Compose Key definition table and that this can be modified to add in missing symbols that you may need to use often.   This is the .XCompose file, which I will show here how to create and edit.

The method we will use is to override the default Gnome method with the orignal Xwindow method, which is also available on your system, but must be configured and activated.  It is called the Xwindow Input Method (XIM).  The system must be told to use this method instead by setting the GTK_IM_MODULE environment variable.   This is done with the following command from the shell prompt:

export GTK_IM_MODULE="xim"

For this environment variable setting to be automatically set every time you log into the system, add this line to the .gnomerc or .Xsession file in your home directory.  If these files do not exist, then create one (.gnomerc) by entering the following text in any text editor and saving the file as .gnomerc (do not neglect to include the leading dot!):

#!/bin/bash
export GTK_IM_MODULE=”xim”

Next, you want your own copy of the XIM Compose Key file to have and modify to your own liking.   We do this by copying a system copy of the file to our home directory and giving it the name .XCompose (this file name is CASE SENSITIVE!):

cp /usr/share/X11/locale/en_US.UTF-8/Compose ~/.XCompose

Finally, you will want to edit your .XCompose file to add in the symbols and keybindings  you are interested in.   For instance, here are the lines I added to bind the Unicode 03A9 for the Ohms symbol to <Multi_key> (AltGR in my case, whatever you have set as your Compose Key in your case) <o><m> (get it?) and <m><o>, also some other symbols I find handy.

<Multi_key> <o> <m>                   : “Ω”   U03A9 # OHM SYMBOL
<Multi_key> <p> <i>                    : “π”   U03C0 # PI SYMBOL
<Multi_key> <d> <t>                    : “Δ”   U0394 # DELTA SYMBOL

Is there a downside to overriding the default Gnome GTK+ Compose Key tables?  Yes, there is.  You loose the <Shft><Ctrl><u> keybinding to be able to do Unicode entry anywhere in the Gnome interface.  However, if your aim is to exclusively use Compose Key sequences and to update your data table to include any missing ones you might need, then it is not a bad trade off.

Finally, a tip on editing the .XCompose file.  Just how do you enter a represenation of the missing symbol into the file if you have already activated XIM which disables the <Shft><Ctrl><u> Unicode entry method?  Edit the file in an editor such as Vi that has its own Unicode entry method or use the Gnome “Character Map” utility to get a copy of the symbol into an editor that does not have a method of its own.   In Vi (or Vim), go into text insert mode and type <Ctrl><v><u>+unicode to enter Unicode symbols.

Once you have set the environment variable and created your file, log out and then back in to activate everything and you are all set to have a Compose Key system that you can customize to suit your own needs.

Much of this information was extracted from the following source and should be referred to for further information on the subject:
https://help.ubuntu.com/community/ComposeKey

4 Responses to “HOWTO – Ububtu, a customizable Compose Key System”

  • Nicely done, Bill. A tutorial that even a relative Linux neophyte like myself can follow.

    73,
    ldb
    K5WLF

  • So, I am currently running Ubuntu 10.10 (just installed last night), and have the ability to both use unicode entry with the Ctrl+Shift+U sequence, as well as custom compose keys.

    This is something I discovered some time ago, and only recently revisited due to switching from Debian to Ubuntu. I don’t remember why this works anymore, but anyhow…

    1) Install the uim-gtk2.0 package (and uim-qt, if you want).

    2) That’s basically it. ツ You can then set your compose keys and whatnot in the System→Preferences→Keyboard menu.

    There’s also another way to setup your .XCompose file; you can source the global file, then add your own definitions below that, so you have a more compact compose file (though it becomes subject to upstream’s modifications, which may or may not be something you want).

    Anyway, mine looks something like this:

    # Load the defaults first, so that you can overwrite sequences you don’t like
    include “/usr/share/X11/locale/en_US.UTF-8/Compose”

    : “…” U2026 # HORIZONTAL ELLIPSIS
    : “↓” downarrow # DOWNWARDS ARROW
    # etc. etc.

  • Gah! The comment box stripped out the angled brackets for the example .XCompose file. It matters little, since my point was the use of the include statement.

    Cheers!

  • So, I’m sorta putting this here for my own reference, but it’s pertinent:

    I just upgraded to Ubuntu 11.04, and the compose keys got broken. Basically, somebody rearranged the keyboard preferences, and you can’t use them to set the compose keys anymore (among other things). The option is probably available graphically, but until I find it, you can revert to the old school way of doing it. Namely,

    setxkbmap -option compose:ralt
    setxkbmap -option ctrl:nocaps

    The first of these will set the compose key to the Right Alt key, which is what I use. The second command sets the Caps Lock key to function just like another Ctrl key.

    Put the appropriate lines into your ~/.profile, and you’re up an running again!









*