User Tools

Site Tools


wiki:linux:composekey

The Linux "Compose" Key

1.0 Introduction

If you ever need to type 'foreign' characters -and if you want to tag classical music files properly, you definitely do!- then you need to know how to do it on Linux.

On Windows, it's easy: you just learn a lot of arcane code numbers (such 0233 for é), then when you need one, you just hold down Alt, type those numbers on the numeric keypad and finally let go of the ALt key). After your first brush with Wagner or Berlioz, you'll be typing é, ß, ü and the rest of them fairly easily. Provided you know and remember all the right numeric codes, of course: after several years of doing this on Windows PCs, I've got quite a repertoire of well-remembered Alt-codes to deal with most German or French situations!

On Linux, it's actually easier than this though, because there are no weird numerical codes to remember. You just tell Linux you want to combine “ and u, and you get ü. Or combine ' [single quote] and e to get é. Or combine , [comma] and c to get ç. Even rather exotic combinations (such as < and z to get ž; or o and u to get ů) are easily do-able. Those later characters are common enough in Czech, for example, so fans of Leoš Janáček will need to use them quite often! And whilst in my Windows days I was fluent with those Alt-codes needed for French and German characters, my Alt-key muscle memory certainly didn't extend to these exotic specimens! I was forever reduced to resorting to slow, point-and-click trips to the Character Map utility! But on Linux, these fantastical characters are trivially easy to construct, to the point where I can type a string of words such as “A já byl, bratříčku, až do svatby zpit!” almost as fast as I can type plain English.

In short, you tell Linux to combine two easily-typed characters to create one that's a bit more exotic. Combining, compositing… composing: by a bit of an etymological stretch, the key which you use to trigger Linux into doing this combining of characters is called the 'Compose Key'.

There is no set key for doing this composing. Some distros set a default; OpenSuse Leap 15 does not. The way you set the compose key also varies by what desktop environment you are using: KDE does it one way, Gnome another, XFCE yet another (and I can't speak for what yet other desktop environments do!) What follows is therefore a quick run-down on how to configure the compose key in OpenSuse 15 using KDE, Ubuntu 18.04 using Gnome and Fedora 29 using XFCE: hopefully that covers the majority of distros and DEs out there!

2.0 OpenSuse 15 KDE

In KDE Plasma, you switch on compose functionality and choose your compose key simply by clicking Start → Settings → System Settings. Under the Hardware options, there's an item called Input Devices. Launch that and select the Keyboard option from the resulting panel of options. Then, in the right-hand part of the screen, click the Advanced tab.

About the sixteenth item down will be one called “Position of Compose key”. Click the '>' to the left of that to expand it. You should see something looking like this:

At this point, you simply click the square box next to the key you want to use for 'composing'. In the above screenshot, I've chosen the Right Alt key for this job -largely because it's readily to hand and mostly un-used by anything else, so I can dedicate it to doing something I do quite a lot of (i.e., typing foreign characters). You may prefer, however, to use a different key -or even make the compose key only kick in when it's pressed in combination with some other key. You could, for example, switch on both the 'Left Ctrl' and 'Right Alt' options and thus make your 'compose key' only work when both of those keys are pressed together.

Once you have defined what your compose key (or combination of keys) is, click [Apply]. Then, test it out in a program such as Kwriter, Kate or Konsole. Type o then u, and you should get ou, as normal and as you'd expect. But type your compose key(s), let go, type o, then type u, you should get ů.

Note that you don't hold down the compose key whilst attempting to produce a foreign character (unlike in Windows, where you have to hold down the right-alt key whilst tapping out the character numeric codes before letting go of everything). You simply press your compose key, let go, and then type the two symbols which together make up the letter you want.

Some handy key combinations are:

  • Type compose, double-quotes, and then a vowel to get an umlaut-version of that vowel (eg, ä, ü, Ö and so on)
  • Type compose, s, s to get the 'eszet' symbol: ß
  • Type compose, less than, and then a letter to get that letter with a caron (eg, š, ě, ž and so on)
  • Type compose, greater than, and then a letter to get that letter with a circumflex accent (eg, ê, â, ô and so on)
  • Type compose, apostrophe and a letter to get an acute-accented letter (é, ú, ó and so on)
  • Type compose, back-tick and a letter to get a grave-accented letter (è, ù, ò and so on)
  • Type compose, a, e to get elided æ
  • Type compose, hyphen, Y to get ¥ (the Japanese yen symbol)
  • Type compose, hyphen, l to get £ (the British pound symbol, for those not using UK keyboards. A capital L gets you ₤ [two bars, rather than one])
  • Type compose, equals, e to get € (the Euro symbol)
  • Type compose, . and . (two full-stops) to get … (a proper elipsis, rather than … three full stops!)

3.0 Ubuntu 18.04 Gnome

Ubuntu's version of Gnome introduced with 18.04 (when Canonical dumped their in-house Unity desktop environment) does not come with a native option for defining a compose key. Instead, you have to install the Gnome Tweaks tool:

sudo apt install gnome-tweaks

Once installed, you can click 'Activities' and then start typing 'twe…' to reveal the Gnome Tweaks launcher. Click that to run the program. From the left-hand list, select Keyboard & Mouse. You'll see now this screen:

Note how the 'Compose Key' item is marked as 'Disabled'. Simply click that word (it's actually a click-able button, though doesn't look much like one to start with!), and this pop-up will appear:

Click the 'On/Off' switch in the pop-up's title bar to switch the compose function on; then in the main part of the pop-up, pick which key you want to trigger the compose functionality -in my case, I've again for the 'right-alt' key. Note that you don't have quite the flexibility at this point that you have in KDE: you can't, for example, easily select a combination of key presses (such as shift+right-alt) to trigger composing. Still, it's simple enough to select single key compose triggers using this technique.

4.0 Fedora 29 XFCE

There is no GUI way of setting a compose key in the XFCE environment, unfortunately. Instead, you issue this command in a terminal:

sudo nano /etc/X11/xorg.conf.d/00-keyboard.conf

That displays the initial, minimal but functional keyboard configuration settings, like so:

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us"
EndSection

If you add the line Option “XkbOptions” “compose:ralt” into the body of that 'InputClass' section of text, like so:

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us"
        Option "XkbOptions" "compose:rctrl"
EndSection

…save the file and then log out and log back on (to force the re-start of the X server, thus causing it to pick up the revised keyboard settings). The new compose key functionality can then be tested to work in pretty much any text-handling program you fancy:

In my example above, I have again specified 'ralt' to be the compose key -that is, the right Alt key. But if you want other keys to do the deed, issue this command:

grep "compose" /usr/share/X11/xkb/rules/base.lst

…and that will show you the complete list of keys which can act the part.

5.0 Conclusion

To sum up, the compose key in Linux is a 'trigger' key that causes the next two key-presses to be combined into a single foreign character (or symbol). You can choose what key(s) should act as this trigger. KDE has a nice, graphical way of setting the compose key built-in. Gnome has a nice, graphical way of doing it once you've installed the gnome-tweaks package. And XFCE has a number of ways of doing it, but editing the X keyboard configuration file is perhaps the simplest and clearest way of doing it.

For anyone that likes Italian opera, German Gesamtkunstwerk or French études and wants them tagged properly, it's important to be able to type foreign characters easily. That also applies if you are merely an Australian who has moved to the UK bringing your US-layout keyboards with you and find it tricky to type £ signs easily! Linux's ability to do on-the-fly key combinations thanks to the compose key is priceless. I think it's a lot easier, quicker and more flexible than the Windows Alt-codes way of doing it, at least!

wiki/linux/composekey.txt · Last modified: 2019/02/14 17:35 by dizwell