Emacs: Set Key to Insert Math Symbols, Emoji

By Xah Lee. Date: . Last updated: .

Set a key to insert unicode char

Here's the best way to set a key to insert Unicode: Emoji πŸ˜„ or Unicode: Math Symbols βˆ‘ ∫ π² ∞ .

put this in your Emacs Init File:

;; F8 insert bullet char
(define-key key-translation-map (kbd "<f8>") "β€’")

Here's how to set a key sequence to insert different Unicode characters.

;; set keys to insert math symbol
(define-key key-translation-map (kbd "<f5> p") "Ο†")
(define-key key-translation-map (kbd "<f5> x") "ΞΎ")
(define-key key-translation-map (kbd "<f5> i") "∞")
(define-key key-translation-map (kbd "<f5> <right>") "β†’")

;; set keys to insert emoji
(define-key key-translation-map (kbd "<f5> 1") "πŸ˜…")
(define-key key-translation-map (kbd "<f5> 2") "❀")

Warning: Problem Using global-set-key

You could also use global-set-key, but it has problems.

;; using global-set-key to insert unicode arrow. This won't work when in isearch
(global-set-key (kbd "<f8>") (lambda () (interactive) (insert "β†’")))

When you do interactive search Ctrl+s, then when you type your key, it'll exit the search instead of inserting the char.

Translation Keymaps (ELISP Manual)