This page is a tutorial on using emacs and Unicode. ➢ for example: how to type math symbol, how to switch input methods, finding Unicode character name or code point, how to set file encoding, ….
How to set default file encoding?
Put this in your emacs init:
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)
UTF-8 is becoming the standard for file encoding. I recommend it highly.
See also:
How to set a key to insert math symbol?
For example, put the following code in your emacs init file.
;; set keys to insert math symbol (define-key key-translation-map (kbd "<f9> p") (kbd "φ")) (define-key key-translation-map (kbd "<f9> x") (kbd "ξ")) (define-key key-translation-map (kbd "<f9> i") (kbd "∞")) (define-key key-translation-map (kbd "<f9> <right>") (kbd "→"))
For detail, see: Emacs: Remapping Keys Using key-translation-map.
For OS-wide, see: How to Create a APL or Math Symbols Keyboard Layout.
For list of math symbols and Unicode search, see Unicode Characters Search ☢ ☯ ☭ ∑ ∞ ♀ ♂ ♥
How to use abbrev to input Unicode chars?
Put the following in your emacs init file:
(define-abbrev-table 'global-abbrev-table '( ("alpha" "α") ("inf" "∞") ("ar" "→") )) (abbrev-mode 1) ; turn on abbrev mode
Select the code above and call eval-region.
〔➤see Emacs: How to Evaluate Emacs Lisp Code〕
Now, type ar , it will become → .
For detail, see: Emacs: Abbrev Mode Tutorial.
If you type math symbols often, use Emacs: xah-math-input.el.
How to type this character é ?
Here's a table on how to type these chars:
| Character | Key Press |
|---|---|
| é | 【Ctrl+x 8 ' e】 |
| à | 【Ctrl+x 8 ` a】 |
| î | 【Ctrl+x 8 ^ i】 |
| ñ | 【Ctrl+x 8 ~ n】 |
| ü | 【Ctrl+x 8 " u】 |
To see all characters you can type this way, press 【Ctrl+x 8 Ctrl+h】. Example: ¿ ¡ ¢ £ ¥ ¤ § ¶ ® © ª «» × ÷ ¬ ° ± µ ÀÁÂÃÄÅÆ Ç ÈÉÊË ÌÍÎÏ ÐÑ ÒÓÔÕÖ ØÙÚÛÜÝÞß àáâãäåæç èéêë ìíîï ðñòóôõö øùúûüýþÿ.
If you need to type these chars often, call set-input-method and give “latin-9-prefix”. That will allow you to type these chars without typing 【Ctrl+x 8】 first.
A better way is to install
Emacs: xah-math-input.el.
With that, to type é, just type e' followed by a activation key.
How to insert a Unicode character by name?
Call insert-char 【Ctrl+x 8 Enter ↵】, then the name of the Unicode. For example, try insert →. Its name is “RIGHTWARDS ARROW”.
You can use asterisk * to match chars. For example, call insert-char, then type *arrow then Tab ↹, then emacs will show all chars with “arrow” in their names.
Note: in emacs 24, ucs-insert is renamed to insert-char. ucs-insert is obsolete since 24.3.
How to insert a Unicode character by its hexadecimal value?
Call insert-char 【Ctrl+x 8 Enter ↵】, then the hex of the Unicode. For example, try insert →. Its hex value is “2192”.
How to insert a Unicode character by its decimal value?
Call eval-expression, then type (insert-char 8594) for →.
A more convenient way is to install Emacs: xah-math-input.el.
How to type Chinese?
Call set-input-method, then give value chinese-py. (“chinese-py” is a basic Chinese pinyin input method.)
To switch back, call toggle-input-method 【Ctrl+\】.
For detail, see: Emacs Chinese Input for Studying Chinese.
How to find out what's the current input method?
Call describe-variable 【Ctrl+h v】 then type current-input-method.
I have this character α on the screen. How to find out its Unicode's hex value or name?
You can find out a char's info by placing your cursor on the character then call describe-char.
describe-char in Emacs 24.5.See also: xub Unicode Browser mode for Emacs.
How to get emacs to display missing emoticon 😸?
See: Emacs: Set Font.
See also, list of unicod emoticons at Unicode Emoticons, Faces 😃 😄 😱 😸 👸 👽 👍.
Emacs File/Character Encoding/Decoding FAQ
Emacs Lisp: Unicode Representation in String
Unicode Characters Search ☢ ☯ ☭ ∑ ∞ ♀ ♂ ♥