Means of Composing Accented Characters in X Window System

From Process of Elimination

   This article is featured on DIGG, which has resulted in a lot of bandwidth consumption.
   Please consider finding a relevant ad on the Google ad-bar and going to it as a way of supporting this site.


Introduction to the Problem

For years now, and especially after learning the German language, I have always wanted to know how to type accented keys in an open source environment, without having to crutch on a tool similar to gucharmap by copy and pasting my desired characters. I had been willing to use a method similar to Microsoft Windows' ALT + ASCII combination for entering exotic characters, but I had not found such a way to do that, at least in a way that is cross-toolkit and portable.

Solution for Gtk+ and GNOME

Months ago, I found a way to do so to a limited degree; however, I found it grossly insufficient due to its lack of ease and only working with applications that use Gtk+. It does involve an application like gucharmap, however, and it does parallel Windows' ALT + ASCII combination. This new method uses Unicode character sequences and works as follows:

  1. load GNOME's gucharmap utility;
  2. obtain a desired hex code for the desired character--e.g., 00FC for a lowercase u-umlaut; and
  3. from within a Gtk+ application, type Control + Shift + (character code).

This method may be performed in standard text-input boxes, and only works with Gtk+; users of KDE, Qt, Motif, Xaw, and other toolkits are therefore out of luck. Due to the lack of portability, there is a better and more intuitive solution than the previous.

Using the Compose (Multi_key)

Although using the Compose key (Multi_key) is an intuitive solution, it does not let users insert every sort of special character, so it is primarily useful for individuals wishing to compose a text in language other than what the keyboard was purposed; and depending upon one's keyboard layout, it may require sacrificing a frequently unused key to become the new Compose key.

Determining the Keysym for Desired Compose Key

The method to determine the keycode is simple:

  1. load the xev utility from a terminal;
  2. depress the desired key a few times;
  3. watch for output along the lines of (keysym 0xYYYY, ZZZZZZ); and
  4. write down the ZZZZZZ information.
Sample Keysyms
Key Name Code
Scroll Lock Scroll_Lock
Pause Pause
Right Windows Key Super_R
Left Windows Key Super_L

Binding Keysym to Compose

There is a temporary method to bind a keysym to Compose. Within a virtual terminal, type the following where $KEYSYM is the keysym for the key:

  • xmodmap -e "keysym $KEYSYM = Multi_key"

This method of assignment is not persistent and will disappear after the X session has ended.

One can semi-permanently bind the keysym to Compose by adding keysym $KEYSYM = Multi_key to ~/.xmodmaprc. Unfortunately there are some difficulties with making this file be interpreted upon the start of an X session, so other documentation must be consulted on how to have X automatically parse ~/.xmodmaprc.

Using Compose

To use Compose, one depresses the key assigned to Compose and then depresses a special sequence to create a composite or accented character:

Example Sequences
Source Result
a * å
~ n ñ

More key combinations are available in these files. Consult a document that looks most familiar to the locale used--e.g., speakers of English would probably consult en_US.UTF-8.

The possibilities with the Compose key are truly boundless, so enjoy. Students or translators using an open source environment will probably find this tip useful. This method is toolkit-portable and therefore the recommended solution.