14

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 )?

12

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.

  • 1
    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. – leftaroundabout Nov 8 '15 at 12:44
1

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

...

  • 2
    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. – Tikhon Jelvis Nov 7 '14 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.