Raku allows the use of unicode characters as variable names. Many operators are defined with unicode symbols (in particular the set/bag operators) as well as some quoting constructs. Hence it is good to know how to enter these symbols into editors, the Raku shell and the command line, especially if the symbols aren't available as actual characters on a keyboard.
General information about entering unicode under various operating systems and environments can be found on the Wikipedia unicode input page.
XCompose (Linux) §
Xorg includes digraph support using a Compose key . The default of AltGr + Shift
can be remapped to something easier such as Capslock
. In GNOME 2 and MATE this can be setup under Preferences → Keyboard → Layouts → Options → Position of Compose Key
. So, for example, to input »+«
you could type CAPSLOCK > > + CAPSLOCK < <
.
XCompose allows customizing the digraph sequences using a .XCompose
file and https://github.com/kragen/xcompose/blob/master/dotXCompose is an extremely complete one. In GNOME, XCompose was overridden and replaced with a hardcoded list, but it is possible to restore XCompose by setting GTK_IM_MODULE=xim
in your environment. It might be necessary to install a xim bridge as well, such as uim-xim
.
Getting compose working in all programs§
You may have issues using the compose key in all programs. In that case you can try ibus
.
input_module=xim export GTK_IM_MODULE=$input_module export XMODIFIERS=@im=$input_module export QT_IM_MODULE=$input_module
If you want this to be for all users you can put this in a file /etc/profile.d/compose.sh
, which is the easiest way, since you won't have to deal with how different GUI environments set up their environment variables.
If you use KDE you can put this file in ~/.config/plasma-workspace/env/compose.sh
and that should work. Other desktop environments will be different. Look up how to set environment variables in yours or use the system-wide option above.
ibus §
If you have problems entering high codepoint symbols such as 🐧 using the xim
input module, you can instead use ibus. You will have to install the ibus package for your distribution. Then you will have to set it to start on load of your Desktop environment. The command that needs to be run is:
ibus-daemon --xim --verbose --daemonize --replace
Setting --xim
should also allow programs not using ibus to still use the xim input method and be backward compatible.
XKB (Linux) §
The X Window System receives keyboard events using the XKB extension, which makes it possible to read the output of various kinds of keyboards, provided that there's a configuration file available.
XKB provides the concept of multi-layout or shift levels. For example the symbol a
is the output of the key marked as "A" at level 1; the symbol A
belongs to the level 2 layout, which is normally reached using the shift key. There are more levels available; one can configure a certain key, let's say the right alt key (or AltGr), as a switch to a third level. The combination of the level-3 modifier and the shift key would switch to a fourth layout: level 4. XKB provides for the possibility to add a level 5 switch key which, used in combination with the shift key, would switch to a level 6 layout.
For an in-depth explanation see this page .
The advantage of this method is that input of characters usually unreachable on a normal keyboard is as easy as pressing the combination of the shift plus another key to output an uppercase letter.
Single-user configuration§
For a personal configuration it's enough to create a .xkb file and a symbol file in a symbols
subdirectory. The .xkb file can be created with this command:
setxkbmap -print > raku.xkb
Here's an example of such a file:
xkb_keymap { xkb_keycodes { include "evdev+aliases(qwerty)" }; xkb_types { include "complete" }; xkb_compat { include "complete" }; xkb_symbols { include "pc+raku(raku)+inet(evdev)+level3(ralt_switch)+compose(caps)" }; };
This file declares the keycodes generated by the keyboard and the symbols produced on the screen.
In this case there's a PC-type keyboard whose configuration is in the file symbols/raku
, which may contain several variants among which the chosen is the one named raku
. The evdev generic input event interface manages the event collection. This configuration uses the right Alt key as a third level switch and the Caps Lock as the Compose key.
Once chosen the base directory for the configuration files (it might be $HOME/.config/xkb
for example) and put the raku.xkb in it, one has to create a symbols directory and put a key layout file in it. Here's an example of such a file, named raku
:
default partial alphanumeric_keys modifier_keys xkb_symbols "basic" { name[Group1]= "English (US)"; key <TLDE> { [ grave, asciitilde ] }; key <AE01> { [ 1, exclam ] }; key <AE02> { [ 2, at ] }; key <AE03> { [ 3, numbersign ] }; key <AE04> { [ 4, dollar ] }; key <AE05> { [ 5, percent ] }; key <AE06> { [ 6, asciicircum ] }; key <AE07> { [ 7, ampersand ] }; key <AE08> { [ 8, asterisk ] }; key <AE09> { [ 9, parenleft ] }; key <AE10> { [ 0, parenright ] }; key <AE11> { [ minus, underscore ] }; key <AE12> { [ equal, plus ] }; key <AD01> { [ q, Q ] }; key <AD02> { [ w, W ] }; key <AD03> { [ e, E ] }; key <AD04> { [ r, R ] }; key <AD05> { [ t, T ] }; key <AD06> { [ y, Y ] }; key <AD07> { [ u, U ] }; key <AD08> { [ i, I ] }; key <AD09> { [ o, O ] }; key <AD10> { [ p, P ] }; key <AD11> { [ bracketleft, braceleft ] }; key <AD12> { [ bracketright, braceright ] }; key <AC01> { [ a, A ] }; key <AC02> { [ s, S ] }; key <AC03> { [ d, D ] }; key <AC04> { [ f, F ] }; key <AC05> { [ g, G ] }; key <AC06> { [ h, H ] }; key <AC07> { [ j, J ] }; key <AC08> { [ k, K ] }; key <AC09> { [ l, L ] }; key <AC10> { [ semicolon, colon ] }; key <AC11> { [ apostrophe, quotedbl ] }; key <AB01> { [ z, Z ] }; key <AB02> { [ x, X ] }; key <AB03> { [ c, C ] }; key <AB04> { [ v, V ] }; key <AB05> { [ b, B ] }; key <AB06> { [ n, N ] }; key <AB07> { [ m, M ] }; key <AB08> { [ comma, less ] }; key <AB09> { [ period, greater ] }; key <AB10> { [ slash, question ] }; key <BKSL> { [ backslash, bar ] }; }; partial alphanumeric_keys xkb_symbols "raku" { include "raku(basic)" name[Group1]= "English (raku operators, with AltGr)"; key <TLDE> { [ grave, asciitilde, dead_grave, leftsinglequotemark ] }; //‘ key <AE01> { [ 1, exclam, U00B9 ] }; //¹ key <AE02> { [ 2, at, U00B2 ] }; //² key <AE03> { [ 3, numbersign, U00B3, U2026 ] }; //³… key <AE04> { [ 4, dollar, U2074 ] }; //⁴ key <AE05> { [ 5, percent, U2075 ] }; //⁵ key <AE06> { [ 6,asciicircum, U2076 ] }; //⁶ key <AE07> { [ 7, ampersand, U2077 ] }; //⁷ key <AE08> { [ 8, asterisk, U2078, multiply ] }; //⁸× key <AE09> { [ 9, parenleft, U2079 ] }; //⁹ key <AE10> { [ 0, parenright, U2070 ] }; //⁰ key <AE11> { [ minus, underscore, U2212, U207B ] }; //⁻− key <AE12> { [ equal, plus, U2261, U207A ] }; //≡⁺ key <BKSL> { [ backslash, bar, U2262, U221E ] }; //≢∞ key <AD03> { [ e, E, EuroSign, U1D452 ] }; //€𝑒 key <AD05> { [ t, T, U03C4, U2296 ] }; //τ⊖ key <AD07> { [ u, U, U222A, U2229 ] }; //∪∩ key <AD09> { [ o, O, U2218 ] }; //∘ key <AD10> { [ p, P, U03C0 ] }; //π key <AD11> { [ bracketleft, braceleft, U2260, U201E ] }; //≠„ key <AD12> { [ bracketright, braceright, U2245, U201A ] }; //≅‚ key <AC01> { [ a, A, U2208, U2209 ] }; //∈∉ key <AC02> { [ s, S, U220B, U220C ] }; //∋∌ key <AC09> { [ l, L, UFF62, UFF63 ] }; //「」 key <AC10> { [ semicolon, colon, U201C, U201D ] }; //“” key <AC11> { [apostrophe, quotedbl, rightsinglequotemark ] }; //’ key <AB02> { [ x, X, U2284, U2285 ] }; //⊄ ⊅ key <AB03> { [ c, C, U2282, U2283 ] }; //⊂ ⊃ key <AB05> { [ b, B, U228E, U228D ] }; //⊎⊍ key <AB06> { [ n, N, U269B ] }; //⚛ key <AB08> { [ comma, less, guillemotleft, U2264 ] }; //«≤ key <AB09> { [ period, greater, guillemotright, U2265 ] }; //»≥ key <AB10> { [ slash, question, division, U2216 ] }; //÷∖ include "level3(ralt_switch)" };
This file contains two layouts: the first is the basic layout of a US keyboard with just two shift levels, the second one includes the first and adds several Unicode symbols to some of the keys using two additional shift levels. The format of this file is documented here.
For a different keyboard one needs to change the first layout, marked basic
, with the one pertaining to the specific national layout. Usually these layouts are located in the /usr/share/X11/xkb/symbols
directory. After that one has to modify the second layout to conform to the specific language key layout.
If one's base directory is $HOME/.config/xkb, this command will load the new configuration:
xkbcomp -I$HOME/.config/xkb $HOME/.config/xkb/raku.xkb $DISPLAY
(There might be some warnings for symbols not defined)
While this is a non-invasive method, one has to load manually the configuration file whenever is needed.
System-wide configuration§
The advantage of this method is that since it modifies the system files, the user can choose the new layout using the usual interface provided by their desktop manager and make it permanent.
The drawbacks are that one has to have root access to the system and that a system upgrade might overwrite one's layout file.
To modify the system-wide configuration one has to locate the specific file describing their language mapping and add the raku
part shown in the previous section.
In order for the new layout to show in the system menus one has to add a specific description in the evdev
rule file, usually in /usr/share/X11/xkb/rules/evdev.xml
. Locate the section corresponding the one's language keyboard layout. For example the us
layout starts like this:
[…] <layoutList> <layout> <configItem> <name>us</name> <!-- Keyboard indicator for English layouts --> <shortDescription>en</shortDescription> <description>English (US)</description> <languageList> <iso639Id>eng</iso639Id> </languageList> </configItem> <variantList> <variant> <configItem> […]
One has to add the newly defined variant:
<variant> <configItem> <name>raku</name> <description>raku (Raku operators, with AltGr)</description> <languageList> <iso639Id>eng</iso639Id> </languageList> </configItem> </variant>
After logging out and in again, the new variant should appear in the list of the layouts and variants. Alternatively one can now load the layout with this command:
setxkbmap -layout us -variant raku
This actually reloads the raku
variant of the us
keyboard, but unfortunately disables other keyboard layouts in case of multi-keyboard use.
KDE§
If you are using KDE, open the start menu and type in “Autostart” and click Autostart which should be the first result. In the settings window that opens, click Add program, type in ibus-daemon
and click OK. Then go into the Application tab of the window that pops up. In the Command
field, enter in the full ibus-daemon command as shown above, with the --desktop
option set to --desktop=plasma
. Click OK. It should now launch automatically when you log in again.
How to enter Unicode characters using a two-key combination§
Using the XCompose input method it is possible to enter Unicode characters using simple two-key combinations. Here's an example of a configuration which would enable entering all the Unicode characters used by Raku. This example uses both Super keys as dead keys
. For example, to enter the π
symbol one has to press and release the right Super
(or "Windows") key, then press and release the p
key.
<Super_R> <less> : "«" guillemotleft <Super_R> <greater> : "»" guillemotright <Super_R> <minus> : "⁻" U207B <Super_R> <0> : "⁰" U2070 <Super_R> <1> : "¹" U00B9 <Super_R> <2> : "²" U00B2 <Super_R> <3> : "³" U00B3 <Super_R> <4> : "⁴" U2074 <Super_R> <5> : "⁵" U2075 <Super_R> <6> : "⁶" U2076 <Super_R> <7> : "⁷" U2077 <Super_R> <8> : "⁸" U2078 <Super_R> <9> : "⁹" U2079 <Super_R> <asterisk> : "×" U00D7 <Super_R> <slash> : "÷" U00F7 <Super_R> <E> : "𝑒" U1D452 <Super_R> <p> : "π" U03C0 <Super_R> <t> : "τ" U03C4 <Super_R> <grave> : "‘" U2018 <Super_R> <apostrophe> : "’" U2019 <Super_R> <comma> : "‚" U201A <Super_R> <colon> : "“" U201C <Super_R> <quotedbl> : "”" U201D <Super_R> <L> : "„" U201E <Super_R> <period> : "…" U2026 <Super_R> <bracketleft> : "≡" U2261 <Super_R> <bracketright> : "≢" U2262 <Super_L> <8> : "∞" U221E <Super_L> <O> : "∅" U2205 <Super_L> <e> : "∈" U2208 <Super_L> <E> : "∉" U2209 <Super_L> <3> : "∋" U220B <Super_L> <numbersign> : "∌" U220C <Super_L> <minus> : "−" U2212 <Super_L> <slash> : "∖" U2216 <Super_L> <o> : "∘" U2218 <Super_L> <U> : "∩" U2229 <Super_L> <u> : "∪" U222A <Super_L> <asciitilde> : "≅" U2245 <Super_L> <equal> : "≠" U2260 <Super_L> <less> : "≤" U2264 <Super_L> <greater> : "≥" U2265 <Super_L> <c> : "⊂" U2283 <Super_L> <C> : "⊃" U2283 <Super_L> <v> : "⊄" U2284 <Super_L> <V> : "⊅" U2285 <Super_R> <d> : "⊆" U2286 <Super_R> <D> : "⊇" U2287 <Super_R> <f> : "⊈" U2288 <Super_R> <F> : "⊉" U2289 <Super_R> <U> : "⊍" U228D <Super_R> <u> : "⊎" U228E <Super_L> <t> : "⊖" U2296 <Super_L> <L> : "「" UFF62 <Super_L> <l> : "」" UFF63
One can add these lines to their ~/.XCompose file. To activate the changes one needs to exit their X session and login back again. Note that since Ubuntu Gnome uses one Super
key for its own purposes, one might want to substitute one or both the Super_* keys with, for example, Meta_R.
WinCompose (Windows) §
WinCompose adds compose key functionality to Windows. It can be installed either via the WinCompose releases page on GitHub, or with the Chocolatey package manager.
Once the program is installed and running, right click the tray icon and select Options → Composing → Behavior → Compose Key
to set your desired key.
WinCompose has multiple sources to choose from in Options → Composing → Sequences
. It is recommended to enable XCompose
and disable Xorg
, as there are a handful of operators which Xorg
does not provide sequences for, and Xorg
also has sequences which conflict with operator sequences present in XCompose
. Sequences can be viewed by right clicking the tray icon and selecting Show Sequences
. If you wish to add your own sequences, you can do so by either adding/modifying .XCompose
in %USERPROFILE%
, or editing user-defined sequences in the options menu.
Terminals, shells, and editors:§
XTerm§
Unicode support is enabled in XTerm primarily by setting its utf8
and utf8Fonts
options to 1
, along with its locale
option to UTF-8
, in ~/.Xdefaults
. Here is a sample configuration that supports displaying enough of unicode to program in Raku:
XTerm*faceName: xft:Noto Mono:style=Regular XTerm*faceNameDoublesize: xft:Noto Emoji:style=Regular XTerm*faceSize: 10 XTerm*locale: UTF-8 XTerm*titleModes: 16 XTerm*utf8: 1 XTerm*utf8Fonts: 1 XTerm*utf8Title: true
URxvt§
Similarly to XTerm, unicode support is enabled in URxvt primarily by setting its locale
option to en_US.UTF-8
in ~/.Xdefaults
. Here is a sample configuration that supports displaying enough of unicode to program in Raku:
URxvt*font: xft:Noto Mono:pixelsize=14:style=Regular,\ xft:Noto Emoji:pixelsize=14:style=Regular URxvt*letterSpace: -1 URxvt*locale: en_US.UTF-8 URxvt*skipBuiltInGlyphs: true
Unix shell§
At the bash shell, one enters unicode characters by using entering Ctrl-Shift-u
, then the unicode code point value followed by enter. For instance, to enter the character for the element-of operator (∈) use the following key combination (whitespace has been added for clarity):
Ctrl-Shift-u 2208 Enter
This also the method one would use to enter unicode characters into the raku
REPL, if one has started the REPL inside a Unix shell.
Screen§
GNU Screen does sport a digraph command but with a rather limited digraph table. Thanks to bindkey and exec an external program can be used to insert characters to the current screen window.
bindkey ^K exec .! digraphs
This will bind control-k to the shell command digraphs. You can use digraphs if you prefer a Raku friendly digraph table over RFC 1345 or change it to your needs.
Vim §
In Vim, unicode characters are entered (in insert-mode) by pressing first Ctrl-V
(also denoted ^V
), then u
and then the hexadecimal value of the unicode character to be entered. For example, the Greek letter λ (lambda) is entered via the key combination:
^Vu03BB
You can also use Ctrl-K
/^K
along with a digraph to type in some characters. So an alternative to the above using digraphs looks like this:
^Kl*
The list of digraphs Vim provides is documented here; you can add your own with the :digraph
command.
Further information about entering special characters in Vim can be found on the Vim Wikia page about entering special characters.
vim-raku§
The vim-raku plugin for Vim can be configured to optionally replace ASCII based ops with their Unicode based equivalents. This will convert the ASCII based ops on the fly while typing them.
Emacs §
In Emacs, unicode characters are entered by first entering the chord C-x 8 RET
at which point the text Unicode (name or hex):
appears in the minibuffer. One then enters the unicode code point hexadecimal number followed by the enter key. The unicode character will now appear in the document. Thus, to enter the Greek letter λ (lambda), one uses the following key combination:
C-x 8 RET 3bb RET
Further information about unicode and its entry into Emacs can be found on the Unicode Encoding Emacs wiki page.
You can also use RFC 1345 character mnemonics by typing:
C-x RET C-\ rfc1345 RET
Or C-u C-\ rfc1345 RET
.
To type special characters, type &
followed by a mnemonic. Emacs will show the possible characters in the echo area. For example, Greek letter λ (lambda) can be entered by typing:
&l*
You can use C-\
to toggle input method.
Another input method you can use to insert special characters is TeX. Select it by typing C-u C-\ TeX RET
. You can enter a special character by using a prefix such as \
. For example, to enter λ, type:
\lambda
To view characters and sequences provided by an input method, run the describe-input-method
command:
C-h I TeX
Some characters useful in Raku§
Smart quotes§
These characters are used in different languages as quotation marks. In Raku they are used as quoting characters
Constructs such as these are now possible:
say 「What?!」; say ”Whoa!“; say „This works too!”; say „There are just too many ways“; say “here: “no problem” at all!”; # You can nest them!
This is very useful in shell:
raku -e 'say ‘hello world’'
since you can just copy and paste some piece of code and not worry about quotes.
Guillemets§
These characters are used in French and German as quotation marks. In Raku they are used as interpolation word quotes, hyper operators and as an angle bracket alternative in POD6.
symbol | unicode code point | ascii equivalent |
---|---|---|
« | U+00AB | << |
» | U+00BB | >> |
Thus constructs such as these are now possible:
say (1, 2) »+« (3, 4); # OUTPUT: «(4 6)» - element-wise add [1, 2, 3] »+=» 42; # add 42 to each element of @array say «moo»; # OUTPUT: «moo» my $baa = "foo bar"; say «$baa $baa ber».raku; # OUTPUT: «("foo", "bar", "foo", "bar", "ber")»
Set/bag operators§
The set/bag operators all have set-theory-related symbols, the unicode code points and their ascii equivalents are listed below. To compose such a character, it is merely necessary to enter the character composition chord (e.g. Ctrl-V u
in Vim; Ctrl-Shift-u
in Bash) then the unicode code point hexadecimal number.
operator | unicode code point | ascii equivalent |
---|---|---|
∈ | U+2208 | (elem) |
∉ | U+2209 | !(elem) |
∋ | U+220B | (cont) |
∌ | U+220C | !(cont) |
≡ | U+2261 | (==) |
≢ | U+2262 | !(==) |
⊆ | U+2286 | (<=) |
⊈ | U+2288 | !(<=) |
⊂ | U+2282 | (<) |
⊄ | U+2284 | !(<) |
⊇ | U+2287 | (>=) |
⊉ | U+2289 | !(>=) |
⊃ | U+2283 | (>) |
⊅ | U+2285 | !(>) |
∪ | U+222A | (|) |
∩ | U+2229 | (&) |
∖ | U+2216 | (-) |
⊖ | U+2296 | (^) |
⊍ | U+228D | (.) |
⊎ | U+228E | (+) |
Mathematical symbols§
Wikipedia contains a full list of mathematical operators and symbols in unicode as well as links to their mathematical meaning.
Greek characters§
Greek characters may be used as variable names. For a list of Greek and Coptic characters and their unicode code points see the Greek in Unicode Wikipedia article.
For example, to assign the value 3 to π, enter the following in Vim (whitespace added to the compose sequences, listed in between « and », for clarity):
my $«Ctrl-V u 03C0» = 3; # same as: my $π = 3; say $«Ctrl-V u 03C0»; # same as: say $π;
Superscripts and subscripts§
A limited set of superscripts and subscripts can be created directly in unicode by using the U+207x
, U+208x
and (less often) the U+209x
ranges. However, to produce a value squared (to the power of 2) or cubed (to the power of 3), one needs to use U+00B2
and U+00B3
since these are defined in the Latin1 supplement Unicode block.
Thus, to write the Taylor series expansion around zero of the function exp(x)
one would input into e.g. vim the following:
exp(x) = 1 + x + x«Ctrl-V u 00B2»/2! + x«Ctrl-V u 00B3»/3! + ... + x«Ctrl-V u 207F»/n! # which would appear as exp(x) = 1 + x + x²/2! + x³/3! + ... + xⁿ/n!
Or to specify the elements in a list from 1
up to k
:
A«Ctrl-V u 2081», A«Ctrl-V u 2082», ..., A«Ctrl-V u 2096» # which would appear as A₁, A₂, ..., Aₖ