How to enter Greek characters in Emacs

后端 未结 10 1325
说谎
说谎 2021-01-30 11:20

This page indicates that Greek letters can be inserted into Emacs by using M-i. However, Emacs 23.2.1 in a Debian Squeeze variant inserts the \"tab\" character when

10条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 11:38

    The TeX input method is great for entering symbols in general, but if you're typing them with any frequency (e.g. if you're typing λ in some functional programming language), it will quickly become a drag to type \lambda every time you want to insert a Greek letter.

    On the other hand, the Greek input method can be efficient for Greek letters, and is a clean solution since it leverages Emacs's built-in Greek support, but it isn't very useful as a default input method.

    You can combine the benefits of both approaches like so (put somewhere in your Emacs init config):

    (progn
      ;; conveniently enter math and greek symbols
    
      ;; leverage built-in input methods support in emacs to enter greek letters
      ;; by using the prefix ",."
      ;; adapted from https://emacs.stackexchange.com/a/53810
      (set-input-method "greek")
      (setq greek-map (quail-map))
    
      ;; add a translation rule to the TeX input method to delegate to
      ;; the greek input method
      (set-input-method "TeX")
      (quail-defrule ",." greek-map)
    
      ;; set default input method to TeX so that it can be activated
      ;; with C-\, e.g. to enter math or other symbols in general
      (setq default-input-method "TeX"))
    

    This uses the TeX input method as the default, but augments it with a rule to temporarily delegate to the Greek input method when the prefix ,. is used.

    Examples:

    ,.a => α
    ,.l => λ
    ,.v => ω
    \to => →
    \circ = ∘
    ^2 => ²
    _i => ᵢ
    

    Sources:

    https://emacs.stackexchange.com/a/53810

    https://stackoverflow.com/a/10197062/323874

    https://stackoverflow.com/a/49765665/323874

    https://emacs.stackexchange.com/a/419

提交回复
热议问题