February 25, 2012 - Linux Compose Key

One thing I really don't like about how the universe works is how becoming frustrated with trying to do something seems to be the only way an open mind can conspire to learn something new and do something useful.

Today, that frustration was the inability to type in lat-long coordinates in Google Maps.  I type a location that should be in Illinois, and Google thinks I mean a street in Cancun. Google is perfectly happy with signed-decimal coordinates (positive degrees for North latitude and East longitude, negative degrees for South latitude and West longitude), but it hasn't got a clue about coordinates entered in degrees-minutes-seconds (D-M-S) unless the Unicode degree sign is used, along with the ASCII single- and double-quotes for minutes and seconds.  The main problem with entering a degree sign is that, on American keyboards, it's extremely inconvenient and unintuitive at best.

In Linux, or at least in X11, any Unicode character can be entered by typing Control+Shift+u, the Unicode character's hexadecimal value (267b for the black generic recycle symbol â™», for example), and a space.  But that doesn't help because I'd still have to memorize more hex values.

The trick, I learned, is to enable the Compose key on my keyboard.  Most how-tos for it use the right Windows key as the compose key, but most laptops don't have two Windows keys.  (Some don't even have the one Windows key in the main typewriter keypad.)  The best substitution is the right Alt key, often used as the AltGr key.

One how-to says that /etc/X11/xorg.conf should be edited, but that's outdated.  Debian has split xorg.conf into multiple dot-conf files under /usr/share/X11/xorg.conf.d/, and Ubuntu uses HAL and /etc/defaults/console-setup to configure the keyboard in X11.  Nevertheless, it can be done.

The secret is to enable the XKB option "compose:ralt" (use the right Alt key as the Compose key).

First was to try it out and make sure it did what I wanted:

  • setxkbmap -model pc105 -layout us -variant dvorak-classic -option compose:ralt
    • This is specific to my setup: I touch-type Dvorak, and I prefer the classic layout which rearranges the number keys as well.  I copied all but the -option from my keyboard configuration in /etc/defaults/console-setup.
    • For people who expect the standard QWERTY layout on a PC, the command would be: setxkbmap -model pc104 -layout us -option compose:ralt

I was then able to type a degree sign by pressing Compose+o, o.  That makes loads more sense, and I could still type as normal.  Next was to make the change permanent.

If you use  KDE or GNOME (the two major Linux desktop environments), there should be a regional/language settings section in the control center or desktop configuration tool.  Under that is keyboard settings, and under that is XKB options, and theoretically under that is Compose key position.  (Both major desktops are resource hogs that get in my way, so this wasn't an option for me.)

If you use /etc/X11/xorg.conf or if you have a keyboard section in one of the /usr/share/X11/xorg.conf.d/*.conf files, then you can edit the option in.  As a sample I found elsewhere, with the relevant line boldfaced:

  1. # Your section in xorg.conf about the keyboard looks similar to this:
  2. Section "InputDevice"
  3.         Identifier      "Keyboard0"
  4.         Driver          "kbd"
  5.         Option          "XkbModel"      "pc104"
  6.         Option          "XkbLayout"     "us"
  7.         Option          "XkbOptions"    "compose:ralt"
  8. EndSection

You have to do this as root, because regular users can't change this file.  Look up the su, sudo, gksu, and kdesu commands.  On some systems, you have to log in as root and give root's password, but on others root is disabled, so you have to be a sudoer and give your own password instead.

Anyway, this wasn't relevant in my case because the whole keyboard section of my xorg.conf was commented out during my last upgrade.  The comments said:

  • # commented out by update-manager, HAL is now used and auto-detects devices
  • # Keyboard settings are now read from /etc/default/console-setup

I do have to give props for at least being commented in a useful manner, but the whole reason I wrote this entry is because I didn't find it elsewhere on the 'Net.  So here it is; we come to it at last.

  • Type cookie you idiot.

In the file /etc/defaults/console-setup (which can only be edited by root), I have this block of text:

  1. # The following variables describe your keyboard and can have the same
  2. # values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
  3. # in /etc/X11/xorg.conf.
  4. XKBMODEL="pc105"
  5. XKBLAYOUT="us"
  6. XKBVARIANT="dvorak-classic"
    1. (This is because, again, I touch-type Dvorak. I don't expect many folks would have this.)
  7. XKBOPTIONS="compose:ralt"

This change doesn't take effect until restarting X (logging out and back in), but at last, it's easy to type the most common special characters.

I hope one of you out there in Internet land finds this useful.


For WindowMaker, you have to either edit the xorg.conf/xorg.conf.d file, or add the setxkbmap command to your ~/GNUstep/Library/WindowMaker/autostart file if you don't have one.

  --ArielMT.....Sat Mar 17 18:29:03 -0700 2012



2110 medium
Full list of journal entries