This page gives some tips about using emacs and Unicode. ⁖ how to type character such as {é, α, →}, how to switch input methods, finding Unicode character name or code point, typing Chinese, etc.
This page covers emacs 23 or later. You should use emacs 23 or later, because emacs 23 uses Unicode as its internal encoding and also supports fonts from the operating system. 〔☛ New Features in Emacs 23〕
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】. Examples: ¿ ¡ ¢ £ ¥ ¤ § ¶ ® © ª «» × ÷ ¬ ° ± µ ÀÁÂÃÄÅÆ Ç ÈÉÊË ÌÍÎÏ ÐÑ ÒÓÔÕÖ ØÙÚÛÜÝÞß àáâãäåæç èéêë ìíîï ðñòóôõö øùúûüýþÿ.
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.
How to insert a Unicode character by name?
Call ucs-insert 【Ctrl+x 8 Enter ↵】, then the name of the Unicode. For example, try insert “λ”. Its name is “GREEK SMALL LETTER LAMDA”.
You can use asterisk * to match chars. For example, call ucs-insert, then type *arrow then Tab ↹, then emacs will show all chars with “arrow” in their names.
How to insert a Unicode character by its hexadecimal value?
Call ucs-insert 【Ctrl+x 8 Enter ↵】, then the hex of the Unicode. For example, try insert “λ”. Its hex value is “3bb”.
How to insert a Unicode character by its decimal value?
Call eval-expression, then type (ucs-insert 955).
How to open a Unicode character palette?
You can put frequently used Unicode chars into a file and save it, and define a keystroke to open this file, so that you can copy & paste the chars you want. Here's how you can define a keystroke to open a file. Put the following in your emacs init file.
; open my Unicode template with F8 key (global-set-key (kbd "<f8>") (lambda () (interactive) (find-file "~/emacs.d/my_unicode_template.txt")))
Here's a example of a template: unicode.txt.
How to set a keystroke to insert a Unicode char?
For example, put the following code in your emacs init file.
(global-set-key (kbd "<f11>") "★") ; make F11 key insert a star
You can also set a key sequence. Like this:
(global-set-key (kbd "<f9> a") "α") ; F9 followed by a (global-set-key (kbd "<f9> b") "β")
With the above method, you can setup to type a whole set of Unicode chars.
Alternatively, you can use “key-translation-map”. For detail, see: Emacs: Remapping Keys Using key-translation-map. For OS-wide, see: How to Create a APL or Math Symbols Keyboard Layout.
How to use abbrev to input Unicode chars?
Put the following in your emacs init file:
(define-abbrev-table 'global-abbrev-table '(
("alpha" "α")
("beta" "β")
("gamma" "γ")
("theta" "θ")
("inf" "∞")
("ar1" "→")
("ar2" "⇒")
))
(abbrev-mode 1) ; turn on abbrev mode
Select the code above and call eval-region 【Alt+x】.
Now, type alpha , it will become “α ”.
If you do math a lot, use Emacs Unicode Math Symbols Input Mode (xmsi-mode).
How to type Chinese?
Call set-input-method 【Ctrl+x Enter ↵ Ctrl+\】, then give value chinese-py. (“chinese-py” is a basic Chinese input method.)
Then, you can start typing Chinese. For detail, see: Emacs Chinese Input for Studying Chinese.
To switch back, call toggle-input-method 【Ctrl+\】.
How to find out what's the current input method?
Call describe-variable 【F1 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.
Following is the output of describe-char on char “λ” in Emacs 23:
character: λ (955, #o1673, #x3bb)
preferred charset: unicode-bmp (Unicode Basic Multilingual Plane (U+0000..U+FFFF))
code point: 0x03BB
syntax: w which means: word
category: .:Base, G:2-byte Greek, c:Chinese, g:Greek, h:Korean, j:Japanese
buffer code: #xCE #xBB
file code: #xCE #xBB (encoded by coding system utf-8-unix)
display: by this font (glyph code)
uniscribe:-outline-DejaVu Sans Mono-normal-normal-normal-mono-13-*-*-*-c-*-iso10646-1 (#x301)
Unicode data:
Name: GREEK SMALL LETTER LAMDA
Category: Letter, Lowercase
Combining class: Ll
Bidi category: Ll
Old name: GREEK SMALL LETTER LAMBDA
Uppercase: Λ
Titlecase: Λ
Character code properties: customize what to show
name: GREEK SMALL LETTER LAMDA
old-name: GREEK SMALL LETTER LAMBDA
general-category: Ll (Letter, Lowercase)
canonical-combining-class: 0 (Spacing, split, enclosing, reordrant, and Tibetan subjoined)
bidi-class: L (Left-to-Right)
mirrored: N
uppercase: 923 (Λ)
titlecase: 923 (Λ)
There are text properties here:
fontified t
Unicode version 6 (released in 2010-10) added about 1k more symbols. Emacs 23.2 does not have info on these new symbols. (⁖ 😸 GRINNING CAT FACE WITH SMILING EYES) 〔☛ Unicode 6 Emoticons〕
You can get these info by downloading a Unicode data file and let emacs know where it is. Download it at: http://www.unicode.org/Public/UNIDATA/UnicodeData.txt, then, place the following code in your “.emacs”.
;; set Unicode data file location. (used by what-cursor-position and describe-char) (let ((x "~/emacs.d/UnicodeData.txt")) (when (file-exists-p x) (setq describe-char-unicodedata-file x)))
Select the above code, then call eval-region. Then, you will have full Unicode char info when calling describe-char.
See also: xub Unicode Browser mode for Emacs.