In MS Windows, if you hold down the rAlt key while typing 0164 on your keyboard’s number pad, then release the rAlt key, you’ll get the ¤ character. People sometimes miss that capability on Unix-like systems (read: Linux or *BSD). There’s a solution to the problem, however: the compose key.

The keyboard section in my xorg.conf file looks something like this:

Section "InputDevice" Identifier "Keyboard0" Driver "kbd" Option "XkbOptions" "compose:ralt" EndSection

That line that starts Option sets the rAlt key as my compose key. With that I can produce any of a dizzying array of digraphs and other special characters that don’t actually appear on my keyboard in just about any application in my X session. For instance, to produce that ¤ character, I would use the following key combination:

<rAlt>x o

In other words, I would hold down the Alt key to the right of my spacebar, press the x key, then release the Alt key, and finally press the o key. Thus, holding down the compose key (set to rAlt) for the first character of a combination of characters like xo produces a non-keyboard character like ¤ . Similarly, I can use "A for Ä, "o for ö, ~n for ñ, oo for °, and ss for ß.

This, to me, seems like an improvement over the MS Windows way of doing it. The key combinations used are more mnemonically effective than simply trying to remember hundreds of numeric values. They’re also more “discoverable”, in that after learning a few one might begin to recognize patterns that allow one to accurately guess at combinations one doesn’t yet have memorized.

(edit: The following notes about setxkbmap and .xinitrc were added on Thursday, 7 October, 2010.)

If you are using a more recent version of X.org, it is entirely possible your system is working fine without any xorg.conf file at all. You can use the setxkbmap command to specify a compose key instead:

setxkbmap -option compose:ralt

If you use startx to start your X session, you can use the .xinitrc file in your user account’s home directory to automatically execute this every time X is started. To do so, just add that command to the file before the line that specifies which window manager to fire up. You just need to add an ampersand at the end of the line.

The following is an example of the contents of an .xinitrc file — actually, the contents of my .xinitrc file at present:

xbattbar -at 1 top & setxkbmap -option compose:ralt & exec ahwm

The first line gives me a nifty line across the top of my screen that tells me how the laptop’s battery is doing. The last line tells X to use a window manager called AHWM.

A complete listing of default compose key sequences can be found in a file called Compose somewhere on most Unix-like systems. On FreeBSD, it should be located in a subdirectory of:

/usr/local/lib/X11/locale/

The subdirectory corresponds to the character set used in your user environment. On my laptop, I’m using the US English UTF-8 character set; that information is stored in the LANG variable:

> printenv LANG UTF-8

Thus, my default compose key sequences are defined in:

/usr/local/lib/X11/locale/en_US.UTF-8/Compose

Your mileage may vary.