18

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

Tikhon Jelvis
  • 6,152
  • 2
  • 27
  • 40
  • 1
    This EmacsWiki article shows show to do it: http://www.emacswiki.org/emacs/TeXInputMethod – Augusto Nov 11 '14 at 21:40
  • 1
    Also, this file from `ac-math` https://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. – Augusto Nov 11 '14 at 21:45
  • 1
    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! – Tikhon Jelvis Nov 11 '14 at 21:46

2 Answers2

16

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.

Augusto
  • 436
  • 3
  • 8
  • 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 08 '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)` – Tikhon Jelvis Jul 27 '20 at 17:08
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

...

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
abo-abo
  • 13,943
  • 1
  • 29
  • 43
  • 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 07 '14 at 21:06