Tag/tag.png

Needs Updating
This article needs updating to include the latest versions of Ubuntu. More info...

In Ubuntu 22.04 the control for selecting a compose key has been moved from Tweaks to Settings -> Keyboard.


Introduction

An alternative to the Gnome CharacterMap application is to use Compose Key sequences. Once the required sequences have been learned this can be the most effective way to type often used special characters. A Compose Key is usually defined as a single keyboard key. Once you have defined a key to use as your compose key - example the right-alt key - you should substitute your defined key for the AltGr key in the examples documented below.

First check your keyboard layout

Ubuntu versions from 20.04 with Gnome desktop

The compose key must first be enabled via Gnome Tweaks

  • Open the Activities overview and start typing Tweaks.
  • Click Tweaks to open the application.
  • Click the Keyboard & Mouse tab.

  • Click Disabled next to the Compose Key setting.
  • Turn the switch on in the dialog and pick the keyboard shortcut you want to use.
  • Tick the checkbox of the key that you want to set as the Compose key.
  • Close the dialog.
  • Close the Tweaks window.

from https://help.gnome.org/users/gnome-help/stable/tips-specialchars.html.en#compose

Ubuntu versions from 8.10 to 10.04 with Gnome desktop

  • select System -> Preferences -> Keyboard

  • The [Keyboard Preferences] window is displayed.
  • Choose the Layouts tab

  • From [Layouts] tab click Options... (or Layout Options... pre 10.04)

  • Expand the listing of Compose key position options [+].

  • if no box is ticked then the Shift+AltGr (Right Alt Key) is the Compose key (also called the Multi_Key in Xwindow documentation).

  • Expand the listing of Key to chose 3rd level options [+].

  • If no box is ticked then AltGr should be the 'Third level chooser'. If there is a box labeled "Right Alt, Shift+Right Alt key is Multi_Key" then that is the default assumed here.

If any other box is ticked then remember to use that key rather than AltGr and Shift+AltGr for the instructions on this page.

For Sun keyboards with a real compose key as found on type 4, 5, 6 and 7 keyboards the correct behaviour can be enforced with the Menu Compose key position setting.

Xubuntu with XFCE and LXDE [all versions to 14.04]

For Xubuntu 8.10, edit /etc/default/console-setup; for Xfce4 in Ubuntu 12.04.2 the file in question is /etc/default/keyboard. You will see a line containing the keyword XKBOPTIONS. Edit the line to read:

  • XKBOPTIONS="compose:rwin"

(again, replace rwin by ralt if you prefer AltGr as the compose key; also Shift+AltGr as it will definitely not clash with other settings) A restart of the Xserver (logout) will be required to effect the change.

KDE

KDE's UserBase has a tutorial on configuring and using the Compose key.

Keys

There are three methods of entering characters not displayed on keycaps by using combinations of keys: the third and fourth level chooser, compose keys, and unicode composition.

The mapping of characters to composite keys will depend on your keyboard and locale. This mapping is defined by files in /usr/share/X11/locale. For example /usr/share/X11/locale/en_US.UTF-8/Compose applies to a US English keyboard and UTF-8. With such a variety of combinations the most certain method of confirming keyboard behaviour is to experiment by opening a text editor and typing.

The examples below refer to a UK English keyboard.

Third and fourth level choosers

There are four levels of keyboard entry. Selecting a level involves holding a set of modifier keys down, this changes the function of all the other keys on the keyboard. The levels are, by default:

Level

Modifier

Keys produced

1

None

Lowercase letters, numbers, etc.

2

Shift

Uppercase letters, symbols printed on keyboard, etc.

3

AltGr

Extra symbols not printed on the keyboard, some dead keys.

4

AltGr-Shift

Even more symbols, more dead keys.

Dead keys are keys that appear to do nothing at first; they apply an accent to the next letter you type.

Holding down the AltGr key and pressing another key will produce a third level character. Holding down the AltGr and Shift keys (the order can be important) and pressing another key will produce a fourth level character. In the following list, the first, second. third and fourth levels are shown for a UK keyboard layout. Note that some combinations are dead keys; an additional key-press is required whereupon a diacritic will be added to the final character keyed.

`1234567890-=
¬!"£$%^&*()_+
|¹²³€½¾{[]}\¸
|¡⅛£¼⅜⅝⅞™±°¿˛

qwertyuiop[]
QWERTYUIOP{}
@łe¶ŧ←↓→øþ¨~
ΩŁE®Ŧ¥↑ıØÞ°¯

asdfghjkl;'#
ASDFGHJKL:@~
æßðđŋħjĸł´^`
ƧЪŊĦJ&Ł˝ˇ˘

\zxcvbnm,./
|ZCVBNM<>?
|«»¢“”nµ ·
¦<>©‘’Nº×÷˙

Compose key

Keying the combination Shift+AltGr (in that order), releasing these keys, then entering two other keys will produce a special character. Many of these will be the reasonable result of overtyping the character keys, eg.

Shift+AltGr  ~  a -->  ã  (&atilde; in HTML)
Shift+AltGr  /  o -->  ø  (&oslash; in HTML)
Shift+AltGr  o  c -->  ©  (&copy; in HTML)
Shift+AltGr  c  o -->  ǒ  (&#334; in HTML)

Note that the order of the "composed" characters and the state of the shift key can be important. Also, not all versions of Gnome/Ubuntu use the same table of compose key sequences (see below).

If the Shift+AltGr key does not work as expected see 'First check your keyboard layout' above.

Compose key sequences

To discover all the Compose key combinations possible and, if required set your own preferred combinations:

Gnome

The compose key sequences used by Gnome are derived from the X compose tables of XFree86 version 4.0 with further modifications to provide a Gnome standard for all locales. They are hard coded into the program in source file gtk+-2.10.7/gtk/gtkimcontextsimple.c

  • GtkComposeTable lists the Multi_key part of the Gnome Compose Key table.

  • GtkDeadKeyTable lists the dead key combinations of the Gnome Compose Key table.

XIM

The Gnome hard coding can be overruled in favour of the original Xwindow Input Method (XIM) by setting the environment variable GTK_IM_MODULE. This can be set in the /etc/environment file, but if the machine has more than one user then it is best set from the home directory on a per user basis by modifying ~/.gnomerc or ~/.Xsession

export GTK_IM_MODULE="xim"

Look at /usr/share/X11/locale/compose.dir to find the appropriate compose table for your locale, eg:

#       This file contains compose table file names.  The first word is the
#       compose table file name and the second word is the full locale
#       name.
#...
en_US.UTF-8/Compose             en_GB.UTF-8

then looking at /usr/share/X11/locale/en_US.UTF-8/Compose

# UTF-8 (Unicode) compose sequence
#...
<Multi_key> <p> <exclam>          : "¶"   paragraph # PILCROW SIGN
<Multi_key> <P> <exclam>          : "¶"   paragraph # PILCROW SIGN
<Multi_key> <plus> <minus>        : "±"   plusminus # PLUS-MINUS SIGN
<Multi_key> <question> <question> : "¿"   questiondown # INVERTED QUESTION MARK
<Multi_key> <minus> <d>           : "đ"   dstroke # LATIN SMALL LETTER D WITH STROKE

<Multi_Key> is the Compose (Shift+AltGr) key

To create your own set of compose keys copy the file /usr/share/X11/locale/en_US.UTF-8/Compose (or if you prefer the equivalent file for your locale) to your home directory as .XCompose  # cp /usr/share/X11/locale/en_US.UTF-8/Compose ~/.XCompose  and edit this file.

Unicode composition

Another means to enter non-keycap characters is to enter them as Unicode character number.

Press Shift+Ctrl+U, release U, enter the hexadecimal (0123456789abcdef) Unicode character code point, then release Shift+Ctrl. An underlined u followed by the number will be displayed as you type.

Alternatively, press (and release) Shift+Ctrl+U, then, while underlined u is displayed, enter the hexadecimal Unicode character code point followed by <Return>.

Shift+Ctrl+U 00f4   ô   (&ocirc;)
Shift+Ctrl+U 2203   ∃  (&exist;)

References

http://en.wikipedia.org/wiki/Compose_key - History about the Compose Key.

http://www.unicode.org/charts/charindex.html - The authority for unicode matters

https://www.x.org/releases/X11R7.7/doc/libX11/i18n/compose/en_US.UTF-8.html - Complete list of Xlib Compose Keys for en_US.UTF-8 (as of X11R7.7)

http://www.haypocalc.com/wiki/Touche_compose (en français)


ComposeKey (last edited 2022-08-14 18:14:11 by gunnarhj)