Warning: include(../../INCLUDE/menu_small_screen.php): failed to open stream: No such file or directory in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 10

Warning: include(): Failed opening '../../INCLUDE/menu_small_screen.php' for inclusion (include_path='/var/www/sda/2/9/julien.scordia/include:.:/usr/php5/lib/php') in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 10

Warning: include(../../INCLUDE/menu_small_screen_not_fixed.php): failed to open stream: No such file or directory in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 11

Warning: include(): Failed opening '../../INCLUDE/menu_small_screen_not_fixed.php' for inclusion (include_path='/var/www/sda/2/9/julien.scordia/include:.:/usr/php5/lib/php') in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 11

Warning: include(../../INCLUDE/header.php): failed to open stream: No such file or directory in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 12

Warning: include(): Failed opening '../../INCLUDE/header.php' for inclusion (include_path='/var/www/sda/2/9/julien.scordia/include:.:/usr/php5/lib/php') in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 12

Warning: include(../../INCLUDE/menu.php): failed to open stream: No such file or directory in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 14

Warning: include(): Failed opening '../../INCLUDE/menu.php' for inclusion (include_path='/var/www/sda/2/9/julien.scordia/include:.:/usr/php5/lib/php') in /var/www/sda/2/9/julien.scordia/computer/programming/linux/may_21__2013__defining_a_keyboard_shortcut_for_a_unicode_symbol_showing_tensor_product.php on line 14

May 21, 2013: defining a keyboard shortcut for a unicode symbol showing tensor product

In KDE system settings -> Keyboard -> Advanced, it is possible to activate:
Entering new shortcuts concerns X, not KDE. This is explained here. X is here listening for our actions, not KDE (as it can be shown by typing “$ xev” in a console).
In the X system, apart from classical keys, we have two important ones to recall: the “modifier keys”, and a “compose key” (that we have just activated).

Key modification

There are four level of key modification easily activated:
In fact, there are six level per key, that can be displayed with:
$ xmodmap -pk
(“$ man xmodmap” for more information, of course).
Levels 1, 2, 5, and 6 correspond to: unshifted, shifted, ALTGR, ALTGR+shift. According to the previously mentioned page, levels 3 and 4 do not seem to be accessible directly (I have not examined the subject further on).
For example, the character I use for vector product is obtained by ALTGR+”.”. Its unicode is 00D7:
$ unicode ×
UTF-8: c3 97  UTF-16BE: 00d7  Decimal: ×
Category: Sm (Symbol, Math)
Bidi: ON (Other Neutrals)
I can then find the corresponding key in X configuration with:
$ xmodmap -pk|grep x00D7
     59         0x003b (semicolon)      0x002e (period) 0x003b (semicolon)      0x002e (period) 0x00d7 (multiply)       0x10022c5 (U22C5)       0x00d7 (multiply)       0x10022c5 (U22C5)
Note that unicode “code points” (see here) are in hexadecimal form. U22C5 corresponds to the scalar product sign obtained with ALTGR+SHIFT+”.”:
$ unicode 22C5
UTF-8: e2 8b 85  UTF-16BE: 22c5  Decimal: ⋅
Category: Sm (Symbol, Math)
Bidi: ON (Other Neutrals)
It is possible to redefine the character corresponding to a keyboard press with xmodmap. Today I will rather use key composition to be able to enter a tensor product sign.

Key composition

The characters that can be obtained with the compose key are stored at /usr/share/X11/locale/en_US.UTF-8/Compose. It is possible to add composition sequences in ~/.XCompose. An example of such a file is given here, where there are already a lot of mathematical symbols. To get the tensor product sign:
$ unicode 2297
UTF-8: e2 8a 97  UTF-16BE: 2297  Decimal: ⊗
Category: Sm (Symbol, Math)
Bidi: ON (Other Neutrals)
for more convenience, I change the line:
<Multi_key> <parenleft> <x> <x> <parenright>    : "⊗"  U2297    # CIRCLED TIMES
<Multi_key> <o> <x>    : "⊗"  U2297    # CIRCLED TIMES
even if it overwrites the following sequence in /usr/share/X11/locale/en_US.UTF-8/Compose:
<Multi_key> <o> <x> »······: "¤" currency # CURRENCY SIGN
After restarting an application (an “X client”), e.g. Konsole, the new composition sequence works correctly; there is no need to log out or to restart X.
I have observed that at least two characters after <Multi_key> are necessary for the composition to work correctly. For example, the following one does not work:
<Multi_key> <e> : "Э" U042D # CYRILLIC CAPITAL LETTER E
contrary to:
<Multi_key> <e> <e> : "Э" U042D # CYRILLIC CAPITAL LETTER E

Other useful combinations in the file given at here

Note about number of characters (i.e. number of cursor positions) behind a unicode character when using a monospace font

I have discovered recently that some unicode characters take two character width when used with a fixed size font (“monospace” font), instead of one. This is typically the case in a terminal. With a variable size font, they appear as one character as expected. It is not specially related to their size: for example,
Yet they have the same size, as it is seen from a snapshot of my KDE Konsole:\begin_inset Separator latexpar\end_inset
There is a larger tensor product available as ⨂ corresponding to sign U+2A02, but as it takes two character width in Konsole, I prefer to use U2297.

Update on September 12, 2014, on (K)ubuntu 14.04

The compositions in file /usr/share/X11/locale/en_US.UTF-8/Compose are taken into account, but not my ~/.XCompose file, as well in ‘konsole‘ as in ‘xterm‘ or ‘gnome-terminal‘. After some experiments, I have finally found that using the program named ‘im-config‘ is enough:
$ which im-config
$ wajig whichpkg /usr/bin/im-config
im-config: /usr/bin/im-config
$ wajig describe -v im-config
im-config: Input method configuration framework
im-config package provides the framework to configure and to switch the input method on X Window System. This input method is the essential mechanism for Japanese, Chinese and Korean (CJK) languages to enter their non-ASCII native characters.
Many modern input methods such as IBus support not only one of these CJK languages but support almost all languages simultaneously by dynamically switching keyboard modes with GUI helper program.
By installing this package, the most desirable input method and its backend conversion engine are automatically configured with both the X Window System Input Method (XIM), GTK+ input method module, Qt input method module, and clutrer input method module.
You can further customize your input method with ’im-config’ command.
To know the current configuration:
$ im-config -m
And to list the available configurations:
$ im-config -l
ibus xim
The solution I have found is to switch to xim input method:
$ im-config -n xim
Note that it is necessary to logout for the new configuration to be taken into account.