A Compose Key for the Mac

  1. Install Karabiner-Elements :

brew install --cask karabiner-elements

2. Launchpad -> Karabiner-Elements. Under 'Simple modifications' (the first page), click Add item, and then set the 'From key' to be "right control" and the To key to be "non_us_backslash".

3. In a Terminal, go to $HOME/Library/KeyBindings/. Create a new, blank DefaultKeyBinding.dict file:

nano DefaultKeyBinding.dict

...and then paste into it the contents of this file:

DefaultKeyBinding.dict

(Make sure you paste the contents, not download the file. That is, view that file in your browser, then select all, then copy, then paste into the nano session.

4. Log out and log back in (or reboot completely, it's up to you: basically, just make sure all applications are closed down and then restarted, or the dictionary changes won't take effect).

 

At this point, the F13 key is now mapped as your 'compose key'. Press it, let go, and then type a key-combination to 'construct' or compose an accented character. For example, F13+/+L will give you Ł, whilst F13+,+c will give you ç and F13+s+s will get you ß

You do not need to keep the compose key depressed whilst the other characters are being typed: you merely need to press it once, let go, then type the other characters.

If you prefer to use another key than F13 as your compose key, your options are somewhat limited on the Mac, because the Control, Option and Command keys are all mapped to fairly serious general operating system duties and so are effectively out of bounds. Your keyboard may also not have an F13 key in the first place, if you aren't using an extended keyboard with numeric keypad.

This is fixable: you can choose your own compose key, provided only that you know its 'key binding number' (which you can determine from this page). Be careful not to 'kidnap' a function or other key that's already doing important duty for your operating system. To avoid this, you might consider adding a 'modifier' to it. Thus, for example, the 0 key on the numeric keypad obviously has an important function all by itself which you probably wouldn't want to lose... but Ctrl+0 isn't a common key combo, so might be safer to re-purpose.

Well, the Ctrl key modifier is represented by the character ^ and the 0 on the numeric keypad is represented by binding number #0, so the string ^#0 represents the simultaneous key presses Ctrl and number-pad-zero.

Armed with that information, edit the DefaultKeyBinding.dict file once more and replace the keybinding number shown in the second line with the key-combo you've cooked up to represent your compose key. In my case, for example, I'd change this:

{
   "\UF710" = {
        "\U0020" = {
            "\U0020" = ("insertText:",...etc etc...

...to this:

{
   "^#0" = {
        "\U0020" = {
            "\U0020" = ("insertText:",...etc etc...

 

I've bolded and made red the new text: it's right at the top of the file, in the first two lines. Save the new file, then log out/log back in, or at least quit all applications and relaunch them. Then try out your new compose key sequences.