Is there a universal way to write Unicode characters?

I sometimes want to write special Unicode characters, like an em-dash (—), in various programs like vim, Chrome (like just now!), or LibreOffice.

In LibreOffice, I can achieve this via a dedicated dialog box found under the Insert menu. Other programs don’t seem to have a built-in way. My solution in these cases is to look up the character on Wikipedia, copy it, and paste it in.

Is there a universal way to write Unicode characters in any program that accepts text input in Linux without having to copy and paste from somewhere where it’s already printed?

Asked By: drs

||

Either you can enable an Compose key, or you can press CtrlShiftU followed by the Unicode hexadecimal number of the character (leading zeroes can be skipped). For example, Æ is CtrlShiftU, then C6. This works on GNOME Terminal, Terminator, Google Chrome and a number of other applications, with Xterm (and according to comments, Emacs) not working.

On GNOME, to enable Compose, go to the Keyboard settings, then ShortcutsTypingAlternative Characters Key and map it to something (say, Right Alt). Then you press the Compose key, and - thrice to get an em-dash: —. (The arrows in this paragraph are all Compose->.)

enter image description here

Answered By: muru

The best way is still to type the character on your keyboard. Thanks to XKB, you can bind arbitrary Unicode characters to key combinations. For instance, with user XKB customization, I can type directly: ← → ↑ ↓ … € ½ « » — − ± ≠ ∩ ∪ ⊂ ∧ ∨ ∀ ∃ √ ∞ ≤ ≥, etc.

Note: in the particular case of GNU Emacs, Unicode composition can be done via Ctrlx+8+Return. See Ctrlx+8+Ctrlh for additional methods.

“Unicode input” on Wikipedia gives information about ISO 14755 Unicode input depending on the context, in particular for X11 with some toolkits and for specific applications (Emacs, Opera, Vim).

Alternatively, you can use the Compose key with user-defined settings (as the default settings are far from being complete). Documentation is provided by the Compose(5) man page. For instance, write a file $HOME/.XCompose containing:

include "%L"
<Multi_key> <bracketleft> <c>           : "⌈" U2308 # LEFT CEILING
<Multi_key> <bracketright> <c>          : "⌉" U2309 # RIGHT CEILING
<Multi_key> <bracketleft> <f>           : "⌊" U230A # LEFT FLOOR
<Multi_key> <bracketright> <f>          : "⌋" U230B # RIGHT FLOOR

The include "%L" line first loads the default (locale-specific) Compose file, and the next four lines add user-defined settings, such as: Compose+[+c gives the left-ceiling character “⌈” (U+2308).

Answered By: vinc17

As described in detail in this post, there’s a great way to do add unicode keys without having to remember any awkward key combinations or use any drop down menus.

It boils down to using Autokey, which can take any set of key strokes as a trigger to run a script or paste a phrase. In this case, your phrase is simply the unicode character you want.

As the post describes, a good way to do it is to follow LaTeX, but with a forward slash rather than backslash. For example, typing /delta anywhere (browser, libre office, etc) will automatically get converted to δ.

Answered By: hugke729
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.