Charlie Harvey

Typing the λ (lambda) character with the compose key on Xorg

I am working my way through a book called Types and Programming Languages, by Benjamin C. Pierce at the moment. I’ve just started the chapter on lambda calculus and I thought it would be fun to be able to include the λ character in my notes. I realize that this sounds a little like displacement activity and perhaps it was a bit.

As it turned out it took a considerable amount of searching to find how to add this new keybinding to the x windows compose key. Surprising given the amount of interest in functional programming that there seems to be on the interwebs these days. It seems like there are λs all over the place!

The problem was simple to sort, at least for Xorg on Debian Squeeze. Here are the steps to solve it.

  1. Edit the file /etc/environment to tell GTK that you want to use the X input method (xim). I haven’t noticed this having any knock-on effects on anything else. Add the following at the end of the file. export GTK_IM_MODULE=xim.
  2. You need to know your locale, so type locale at the commandline. Mine says this $ locale LANG=en_GB.utf8 LANGUAGE= LC_CTYPE="en_GB.utf8" LC_NUMERIC="en_GB.utf8" LC_TIME="en_GB.utf8" LC_COLLATE="en_GB.utf8" LC_MONETARY="en_GB.utf8" LC_MESSAGES="en_GB.utf8" LC_PAPER="en_GB.utf8" LC_NAME="en_GB.utf8" LC_ADDRESS="en_GB.utf8" LC_TELEPHONE="en_GB.utf8" LC_MEASUREMENT="en_GB.utf8" LC_IDENTIFICATION="en_GB.utf8" LC_ALL=
  3. You want to know the Compose key mappings for your locale, so grep the compose.dir file for them thus, substituting in your locale. Note that I had to change the spelling of my locale, which may be something broken with my installation. $ grep en_GB.UTF-8 /usr/share/X11/locale/compose.dir en_US.UTF-8/Compose en_GB.UTF-8 en_US.UTF-8/Compose: en_GB.UTF-8
  4. Now make a file called .XCompose in your home directory. In that you can define your keymapping (I used .\ because I think it looks like λ). You also need to include your existing compose file (the one from the previous step) or you won’t be able to type other cool characters. $ cat .XCompose include "/usr/share/X11/locale/en_US.UTF-8/Compose" <Multi_key> <period> <backslash> : "λ" U03BB # GREEK SMALL LETTER LAMBDA
  5. Finally you need to restart your X server, ctrl-alt-backspace works on Gnome, I believe or ctrl-alt-q works on XMonad

Various posts were useful in figuring this out, check the relateds to the right. Now I can quite easily write this sort of thing. tru = λt. λf. t fls = λt. λf. f test = λl. λm. λn. l m n … Displacement activity over :-)


Comments

  • Be respectful. You may want to read the comment guidelines before posting.
  • You can use Markdown syntax to format your comments. You can only use level 5 and 6 headings.
  • You can add class="your language" to code blocks to help highlight.js highlight them correctly.

Privacy note: This form will forward your IP address, user agent and referrer to the Akismet, StopForumSpam and Botscout spam filtering services. I don’t log these details. Those services will. I do log everything you type into the form. Full privacy statement.