📜 ⬆️ ⬇️

Entering arbitrary characters using Compose Key: setting

Many people know that Linux has a special button: Compose. Its action is similar to the Windows Alt + NumPad combinations (for example, pressing Alt + 0169 gives the © symbol), but does not require keeping the symbol code table before your eyes :) If you configure the right Alt as Compose Key, then by pressing RAlt + O + C you get the same icon Copyright: ©.

In the article I will describe how to assign arbitrary keyboard shortcuts for characters. First of all, it will be convenient for mathematicians: you will not need to climb into the symbol table to enter "ε> 0 ∃δ (ε) ≕δ> 0: ∀x∈O (x₀) | f (x) <A |" in any application supporting unicode. In addition to mathematical symbols, all kinds of arrows (→ ⇖⇔⟲⟽), check marks (,), bullets (•) ★), quotes (""), long dash (-), fractions (⅓, ⅞), diacritics and everything your heart desires in immense unicode! :)

Turn on

The first thing you need to do to get access to Compose Key is to turn it on :) It's convenient enough to set the right Alt as a composite button: it is unlikely to be used often. Examples will be for Ubuntu, in other distributions there should not be much difference.

There are three ways to enable Compose Key:
  1. xorg.conf : Compose Key can be assigned in the “InputDevice” section of the /etc/X11/xorg.conf config. For example:
    Section "InputDevice"
    Driver "kbd"
    Option "CoreKeyboard"
    Option "XkbRules" "xorg"
    Option "XkbModel" "pc105"
    Option "XkbLayout" "us,ru"
    Option "XkbOptions" "grp:alt_shift_toggle,grp_led:scroll, compose:ralt "
    EndSection
  2. If you have Gnome installed, go to the menu in System → Preferences → Keyboard → Layouts → [Layout Options] and set “Compose key position” to the right Alt. I do not have Gnome at hand, copied from here :)
  3. If you have KDE4, then in System Settings → Regional & Language → Keyboard Layout → [Advanced] and in the “Compose key position” section, put a checkmark next to “Right Alt”
  4. John_Minority tells you that you can specify the following in the ~ / .xinitrc file: setxkbmap -options "compose:ralt..."

You may need to restart the X server. If everything is done correctly, check: press RALT, release, then (with shifo) O and C. The copyright icon © should turn out.
')
Config

The Internet is full of lists of available combinations, but none describes them completely. We will be smarter and will not remember anything: we will adjust everything for ourselves :)
The default combinations are in the giant file /usr/share/X11/locale/en_US.UTF-8/Compose. It can be used as a cheat sheet :) You don’t need to touch anything there: in the home folder we create the file ~ / .XCompose and we will describe our keyboard shortcuts there that will override all the standard ones.
The file syntax is simple: each line describes a combination, comments begin with a '#' character. Consider an example: add a line to the empty file ~ / .XCompose:
<Multi_key> <o> <C> : "℃" U2103 # DEGREE CELSIUS and save the file.

The combination of keys is described in angle brackets in a row. Compose in terms of the X server is called “Multi_key”. Next comes the colon, and in quotes there is a symbol (or a string!), Which is obtained by pressing these keys. The last one is the Unicode code of a character, it is not necessary to enter it. It is considered good form to give in the comment the original name of the symbol, which can be overlooked in the symbol table.
The added symbol will be available without restarting the X, but - only in new applications. Therefore, we launch a new text editor, and check by pressing and immediately releasing the combinations: RAlt, o, Shift + c. Hooray :)

An important point: all the names of keys in the config are case-sensitive: for example, <Multi_key> and <Multi_Key> are different keys, and the second option will not be recognized by X. Carefully!
The names of the keys for litas and numbers coincide with a single letter: <a> - <z>, <A> - <Z>, <0> - <9> are available to us. The arrows <Left>, <Right>, <Up>, <Down> (the first letter is large!) Can also be used. But how can you guess that the tilde is called <asciitilde> and nothing else?

Learn the names of the keys

Open the console, and do the following:
xev | fgrep "keysym"
The xev window will open. We make it active, check the current layout and gently press the tilde (yes, with shifty). The console now shows the name of the key:
state 0x11, keycode 49 (keysym 0x7e, asciitilde ), same_screen YES,
For Russian letters, there are also names:
state 0x2010, keycode 47 (keysym 0x6d6, Cyrillic_zhe ), same_screen YES,

Customize

Armed with all this information, you can immediately clear the whole family of arrows entered by the minus button and double-clicking the arrow in the desired direction:
<Multi_key> <minus> <Right> <Right> : "→"
<Multi_key> <minus> <Left> <Left> : "←"
<Multi_key> <minus> <Up> <Up> : "↑"
<Multi_key> <minus> <Down> <Down> : "↓"

However, it will immediately be seen that the "minus" on the numeric keypad does not work. We climb into xev, and find that it is called otherwise: “KP_Subtract”. Carefully!
You can add more aliases for the NumPad:
<Multi_key> <KP_Subtract> <Right> <Right> : "→"
<Multi_key> <KP_Subtract> <Left> <Left> : "←"
<Multi_key> <KP_Subtract> <Up> <Up> : "↑"
<Multi_key> <KP_Subtract> <Down> <Down> : "↓"

Now everything works.
There is one more rake: let's say we write the following to the file:
<Multi_key> <minus> <minus> : "–" U2013 # EN DASH
<Multi_key> <minus> <minus> <minus> : "—" U2014 # EM DASH

And we will try to enter EM-DASH (long dash): the second dash will give you a short dash. The reason is that the X server chooses the first successful sequence (EN DASH) and writes it. When compiling a file, you need to carefully monitor that no combination overlaps the others!
Therefore, doing this: for a short dash adds a point:
<Multi_key> <minus> <minus> <period> : "–" U2013 # EN DASH
<Multi_key> <minus> <minus> <minus> : "—" U2014 # EM DASH


One last thing: if you just want to expand the existing set of characters and do not change anything, at the beginning of the file we include the standard one:
include "/usr/share/X11/locale/en_US.UTF-8/Compose"

Turnkey solution

I will not give the entire table and paint its creation, just give a link to the project on Google code where you can download my creation and correct it for yourself. The file will be updated in the process of expanding the character set and finding bugs :)
The slope of the selected characters is quite habrakhabrovsky: IT and mathematics :)

Enjoy!

UPD: fixed a bug with intersecting © and Ⓒ. On the Google code lies the updated file and pkhp script that checks all sequences for intersection.

Source: https://habr.com/ru/post/80091/


All Articles