# How can I add characters to an input method?

I often use the TeX input method to type Unicode characters like λ, which is quite handy. However, some of the characters I want to type are not supported like various subscripts (say ᵢ), script characters (like 𝒞) and other various symbols (like ⦅ and ⦆).

How can I extend the TeX input method to support some of these characters with custom input string (ie _i for ᵢ)?

• This EmacsWiki article shows show to do it: emacswiki.org/emacs/TeXInputMethod Nov 11 '14 at 21:40
• Also, this file from ac-math github.com/vitoshka/ac-math/blob/master/ac-math.el can be easily changed into a new and much more complete TeX-esque input method. Nov 11 '14 at 21:45
• Both of those links look useful. Could you put them into an actual answer (ideally with the relevant bits quoted here) so that this question can be marked as answered? Thanks! Nov 11 '14 at 21:46

As explained in this EmacsWiki article, you can append stuff to an input method like this:

(let ((quail-current-package (assoc "TeX" quail-package-alist)))
(quail-define-rules ((append . t))
("_i" ?ᵢ)
("^\\alpha" ?ᵅ)))


I also find it convenient to use ; instead of the cumbersome \ as a prefix for my symbols, so I do the following

(let ((quail-current-package (assoc "TeX" quail-package-alist)))
(quail-defrule ";" (quail-lookup-key "\\")))


Finally, note that the file ac-math.el contains a list of unicode math characters and the corresponding TeX macro names, and can be easily changed into a new and much more complete TeX-esque input method (I can even type \gamma\dot to get γ̇.)

ADDENDUM Using the new package math-symbol-lists (available on MELPA) one can define a comprehensive mathematical input method as follows:

(package-initialize)
(require 'math-symbol-lists)
(quail-define-package "math" "UTF-8" "Ω" t)
(quail-define-rules ; whatever extra rules you want to define...
("\\from"    #X2190)
("\\to"      #X2192)
("\\lhd"     #X22B2)
("\\rhd"     #X22B3)
("\\unlhd"   #X22B4)
("\\unrhd"   #X22B5))
(mapc (lambda (x)
(if (cddr x)
(quail-defrule (cadr x) (car (cddr x)))))
(append math-symbol-list-basic math-symbol-list-extended))


To activate the input method, type C-u C-\ math RET. Then, typing \mscrC yields 𝒞, \lParen yields ⦅, etc.

ADDENDUM 2 There is now a package on Melpa that provides a very comprehensive TeX-like input method.

• The appending-to-input-method thing doesn't seem to work (invalid Quail map nil). I've switched to a custom input method with math-symbol-lists now, that works nicely. Nov 8 '15 at 12:44
• If anyone else is running into the invalid Quail map nil error, you can fix it by toggling on the input mode in your .emacs file before calling quail-define-rules. I assume you could toggle it back off afterwards too. (setq default-input-method "TeX") (toggle-input-mode) Jul 27 '20 at 17:08

I was using insert-char to insert Unicode chars. However I didn't appreciate the default completion for that command. So here's one that completes with helm:

(defun helm-insert-char ()
(interactive)
(helm :sources
((name . "Unicode char name")
(candidates . ,(ucs-names))
(action . insert))))


And here are the types of lambdas that I can insert: λ, Λ, ƛ, ƛ. I've bound the command to f2 u, so the sequence to insert these was:

f2 u lambda` RET

f2 u M-p C-n RET

f2 u M-p C-n C-n RET

...

• That looks like a useful trick, but it doesn't really answer my question. I specifically want to modify or extend an input method because it fits very well into my existing workflow. Nov 7 '14 at 21:06