Compose key magic
There are some amusing things in Linux which are hard to discover because they are invisible. Entering Unicode characters and sequences with a Compose key is one of those hidden features which can make user’s life much easier.
How it works
It’s simple and easy. You press and release a special key called “Compose” (or, “Multi_key”) and then, two or three character keys – a mnemonic ASCII sequence identifies a Unicode character you want to see. For example, the sequence of letter keys “o” and “c” produces the copyright symbol (©) and it is much easier to remember than Unicode 00A9.
Where is my Compose key?
There is no Compose key defined in X.org by default. Before using it, you need to do some configuration to tell X which key you want to use as a Compose. Usually, right “Win” (“Super”) key is a good choice.
In KDE, open “Keyboard layout” configuration panel (Control Center → Regional & Accessibility → Keyboard Layout) and select “Enable xkb options” checkbox on “Xkb options” tab. Then scroll the options list down to “Compose key position” section and select a checkbox for a key you want to use as a Compose.
Alternatively, you can edit /etc/X11/Xorg.conf (as a root) to add the line to the keyboard section:
Option "XkbOptions" "compose:rwin"
After configuration is done, restart X (simply hit Ctrl+Alt+Backspace).
Note that you’ll need Unicode fonts installed (to see all exotic characters) and a default locale with UTF-8 support (e.g. en_US.UTF-8 for US English). This seems to be the default in modern Linux distributions.
Predefined characters
Diacritics, ligatures and currency symbols
Entering extended latin letters with diacritic marks follows the pattern:
Compose diacritic_character letter
The diacritic characters are:
'(apostrophe) ⇒ A letter with acute (Áá)"(double quote) ⇒ A letter with diaeresis (Ää)`(grave) ⇒ A letter with grave (Àà)_(underscore) ⇒ A letter with macron (Āā)^(circumflex) ⇒ A letter with circumflex (Ââ)~(tilde) ⇒ A letter with tilde (Ãã),(comma) ⇒ A letter with cedilla (Çç).(period) ⇒ A letter with dot above (Ȧȧ)!(exclamation) ⇒ A letter with dot below (Ạạ)?(question) ⇒ A letter with hook (Ảả)/(slash),-(minus) ⇒ A letter with stroke (Øø, Đđ);(semicolon) ⇒ A letter with ogonek (Ąą)+(plus) ⇒ A letter with horn (Ơơ)=(equals) ⇒ A letter with double acute (Őő)o⇒ A letter with ring (Åå)c⇒ A letter with caron (Ǎǎ)b⇒ A letter with breve (Ăă)
Some characters may be combined to create mixed diacritical marks, e.g. Compose _ " a produces ǟ (‘a’ with diaeresis and macron), and so on.
Other letters and ligatures:
Compose A/a E/e⇒ Æ/æCompose O/o E/e⇒ Œ/œCompose T/t H/h⇒ Þ/þCompose N/n G/g⇒ Ŋ/ŋCompose s s⇒ ßCompose e e⇒ ə
Currency symbols:
Compose c /⇒ ¢Compose C =⇒ €Compose L =⇒ ₤Compose F r⇒ ₣Compose Y =⇒ ¥Compose o x⇒ ¤
Punctuation marks and other symbols
Quotation marks:
Compose , '⇒ ‚Compose , "⇒ „Compose < '⇒ ‘Compose > '⇒ ’Compose < "⇒ “Compose > "⇒ ”Compose < <⇒ «Compose > >⇒ »Compose . <⇒ ‹Compose . >⇒ ›
Others:
Compose . .⇒ ·Compose - - -⇒ — (em-dash)Compose - - .⇒ – (en-dash)Compose ? ?⇒ ¿Compose ! !⇒ ¡Compose + -⇒ ±Compose : -⇒ ÷Compose 1 2⇒ ½Compose 1 4⇒ ¼Compose 3 4⇒ ¾Compose _ 0-9⇒ ₀ – ₉ (subscript digit)Compose ^ 0-9⇒ ⁰ – ⁹ (superscript digit)Compose ( 0-9 )⇒ ⓪ – ⑨ (circled digit)Compose o c⇒ ©Compose o r⇒ ®Compose o o⇒ °Compose o s⇒ §Compose x x⇒ ×Compose P P⇒ ¶Compose T M⇒ ™Compose m u⇒ µCompose % o⇒ ‰
Defining custom Compose sequences
Default Compose sequences are defined in ‘Compose‘ text file in the current locale directory (/usr/share/X11/locale/xxx). This file contains the rules to define Compose keyboard sequences and corresponding Unicode characters:
# UTF-8 (Unicode) compose sequence # David.Monniaux (at) ens.fr # # $XFree86: xc/nls/Compose/en_US.UTF-8,v 1.11 2004/01/06 13:14:04 pascal Exp $ ... <Multi_key> <less> <less> : "«" guillemotleft # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK <Multi_key> <greater> <greater> : "»" guillemotright # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK <Multi_key> <less> <apostrophe> : "‘" U2018 # LEFT SINGLE QUOTATION MARK ...
To define new Compose sequence, we should add another rule using the syntax:
<Multi_key> <key1> [<key2> ...] : "character"
For instance, for a smiley character (☺, Unicode 263A), the rule could be
<Multi_key> <colon> <parenright> : "☺" # Compose : )
There is a number of utilities (like KCharSelect in KDE) for to select the Unicode characters and insert them into the file via clipboard.
It is possible to add new rules just into this system file (if you are root), but it’s better to create ‘.XCompose‘ file in the user home directory:
# ~/.XCompose # This file defines custom Compose sequence for Unicode characters # Import default rules from the system Compose file: include "/usr/share/X11/locale/en_US.UTF-8/Compose" <Multi_key> <colon> <parenright> : "☺" U263A # Compose : ) <Multi_key> <minus> <less> : "←" U2190 # Compose - < <Multi_key> <minus> <greater> : "→" U2192 # Compose -> ...
You also can assign whole strings to the Compose sequences — for instance, syntax constructions of your favorite programming language or HTML tags:
<Multi_key> <less> <p> : "<p></p>" # Compose < p <Multi_key> <less> <a> : "<a href=""></a>" # Compose < a ...



jetxee, January 31, 2008 @ 1:44 pm:
Great! I looked for a way to easily define new Compose sequences on per-user basis. This is the solution! Thanks!
I used to rebuild latin-plus GTK Input method extension before to implement my own compose sequences. ~/.XCompose sounds much easier.
DD, February 23, 2008 @ 11:07 pm:
Are you able to perform customisations in ~/.XCompose without setting GTK’s input method to “xim” (i.e. export GTK_IM_MODULE=xim)?
I tried this, looked around, etc… and it doesn’t seem to work out.
Alex, February 24, 2008 @ 7:06 am:
Yeah, custom sequencies do not work in GTK apps. I don’t use a lot of them (only Firefox, etc) so noticed it after writing this post. It’s very well may be because of input method settings, thanks! I would have to learn more about GTK input stuff.
Strangely, they work in OOffice. Does it mean it uses its own input functions, independent from GTK?
Pingback by up, up, up and away » Blog Archive » Compose/AllChars, February 27, 2008 @ 11:41 am:
[...] if you are using *nix you have the possibility to use Compose key to write special symbols [...]
daniel, March 28, 2008 @ 5:10 pm:
Very good work!
There is a solution for the GTK issue. Take a look at
http://hdante.blogspot.com/2007/05/kiel-oni-skribas-typing-esperanto.html
As I wrote in my comment there, you can write to /etc/X11/Xsession.d/00×11-common_set-gtk-im instead of /etc/environment, so you only have to restart X instead the whole system.
Pingback by US-Intl layout, problem with one letter - openSUSE Forums, July 25, 2008 @ 1:24 pm:
[...] Re: US-Intl layout, problem with one letter What I do for diacritics is enable the Compose key so that I have the standard compose sequences that Xorg knows about. In YaST > Hardware > Keyboard find the Menu is Compose checkbox and turn it on. Menu is the normally useless key next to the Windows key. Or use the Windows key for Compose. (And for good measure, if you hate the Caps Lock key like I do, turn on Caps Lock is additional Ctrl.) Now you can enter diacritics with 3 key sequences: Euro sign ? is Compose = C c cedilla ç is Compose , c and so forth. Here are all the supported Compose sequences: Compose key magic « Cyberborean Chronicles [...]
Pingback by Quality Obsession » Blog Archive » How to insert Special Characters in Linux, June 15, 2009 @ 1:26 pm:
[...] Read more about how to use compose here Ubuntu blog.cyberborean.org [...]
Pingback by How-To: How enable “compose” key in Ubuntu 9.10 « mundane idiosyncrasies, December 2, 2009 @ 12:03 am:
[...] You can find the list of possible key combinations here, also from this blog. [...]
Pingback by How-To: How enable “compose” key in Ubuntu 9.10 (to type special characters) « mundane idiosyncrasies, December 2, 2009 @ 12:09 am:
[...] You can find the list of possible key combinations here, also from this blog. [...]
Pingback by Entrada de acentos y japonés en Emacs/GTK+/KDE en Ubuntu 9.10 (Karmic Koala) « XMLEye, December 13, 2009 @ 4:00 pm:
[...] Con esta tecla se pueden escribir caracteres “raros” y cadenas completas (véase esta página) mucho más fácilmente. Por ejemplo, § (el símbolo de sección) es pulsar y soltar la tecla [...]