Keyboards

March 31, 2022


I’ve recently changed some keyboard-related things.

$ setxkbmap -layout us,ca -variant altgr-intl,multix -option grp:shifts_toggle -option compose:sclk
The command I use in my ~/.xinitrc file to configure my keyboard.

Contents

Canadian French

There are some small things that I dislike about ca(fr), the layout for Canadian French. The main issue I have with it is simply with the characters it has available: most notably, it has a cedilla ⟨¸⟩ dead key, even though it would only be used with the letter ⟨c⟩ (that is, ⟨ç⟩, as in français). There also aren’t dedicated keys for ⟨è⟩ or ⟨à⟩, which aren’t uncommon characters; I have to type `e or `a for those, respectively. (There is a dedicated key for the common ⟨é⟩, so I’ll give them that.)

After a bit of investigating, I found out about ca(multix).

It’s named “Canadian (intl.)”—seemingly not targeted towards French, but it does have the dedicated keys I was looking for! It also has some characters moved to places that I’m more familiar with, due my experience with using the us(basic) layout. For example, the at sign ⟨@⟩ is entered with Shift2 using ca(multix), as it is with us(basic). With ca(fr), it’s AltGr2 instead, where Shift2 is a double quote ⟨"⟩.

Fancy Characters

Sometimes—not often, I’ll admit, but sometimes—I want to type some more exotic characters. These might be the em dash ⟨—⟩, degree symbol ⟨°⟩, multiplication sign ⟨×⟩, division sign ⟨÷⟩, minus sign ⟨−⟩ (different from the “hyphen-minus” ⟨-⟩ found in ASCII), and perhaps a superscript two ⟨²⟩, to name… nearly all of them.

Most of those characters are normally typed with AltGr, the “Level 3” modifier key, which is missing from the us(basic) layout. Instead, I get two Alts!

I found a layout variant called us(altgr-intl).

I get to use my keyboard’s right Alt as AltGr, giving me access to a bunch of fancy characters. For example, I can type the degree symbol using ShiftAltGr;, or the multiplication sign using AltGr=.

Great for discussing the temperature and math, I guess.

ah yes, lovely weather today, a nice warm 4² ÷ 2 × 3 °C!

Finally, I can write this with ease! I've always wanted this!

I still use HTML entities (e.g., ± for ⟨±⟩) whenever I can, but it’s nice to know I would be able to type out some of these characters when not writing markup.

The Compose Key

What about my em dash? It still isn’t in the us(altgr-intl) layout.

Compose to the rescue!

The Compose key is a special key on some keyboards that allows entering a sequence of characters in order to form a single character, useful when that single character isn’t found on your keyboard. For example, Composetm results in ⟨™⟩.

One of those special characters is the em dash, entered with Compose---! However, the keyboard I use, being a pretty typical US keyboard, doesn’t have a Compose key. Luckily, as this situation isn’t all that uncommon (I said my keyboard was typical!), XKB provides the option to use existing keys as substitutes.

I chose the compose:sclk option.

That means that when I press Scroll Lock, it’s interpreted as Compose! There are quite a few options for Compose substitutes, but I chose compose:sclk specifically because (1) my keyboard has it, (2) it’s a single keystroke, and (3) I wouldn’t normally use it for anything.

There are quite a few options for Compose substitutes:
$ grep "compose:" /usr/share/X11/xkb/rules/base.lst

The Compose key covers a lot of characters. I actually no longer need to use us(altgr-intl), since all of the characters I wanted from it are available with Compose. For example, I can type the multiplication sign ⟨×⟩ with Composexx, so I don’t need to be able to use AltGr=. However, I find that using Compose is often just a tad more cumbersome—three keystrokes instead of two in the prior example.

The Minus Sign

Even with the Compose key, I’m still lacking the ability to type the minus sign!

Fortunately, I can define my own Compose sequences. I can create a file named .XCompose in my home directory to add my own Compose sequence for the minus sign:

include "%L"

<Multi_key> <minus> <minus> <equal> : "−" U2212 # MINUS SIGN
The contents of my ~/.XCompose file.

First, I include the default Compose sequences: %L expands to the name of the locale-specific Compose file—in the case of my locale, en_CA.UTF-8, that’s /usr/share/X11/locale/en_US.UTF-8/Compose. Then I define one more sequence for the minus sign, Compose--=.

(For more details on Compose files, see Compose(5)!)

At last, the en dash, em dash, and minus sign!