How to enter Greek characters in Emacs

后端 未结 10 1320
说谎
说谎 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:35

    You can use another prefix, like:

    (global-set-key (kbd "C-x <ESC> a") "α")
    (global-set-key (kbd "C-x <ESC> b") "β")
    

    Or use global-abbrev-table as it's explained on the page you mentioned.

    0 讨论(0)
  • 2021-01-30 11:37

    Expanding the answer by @Oleg Pavliv:

    To solve this problem once and for all in your .emacs file, you need to choose a key pattern (like M-g + <latin letter>) and a memorizable correspondence table <greek letter> - <latin letter>. I suggest not to invent anything new, but to use the correspondences from the PostScript Symbol encoding. This leads me to the following:

    (global-set-key (kbd "M-g a") "α")
    (global-set-key (kbd "M-g b") "β")
    (global-set-key (kbd "M-g g") "γ")
    (global-set-key (kbd "M-g d") "δ")
    (global-set-key (kbd "M-g e") "ε")
    (global-set-key (kbd "M-g z") "ζ")
    (global-set-key (kbd "M-g h") "η")
    (global-set-key (kbd "M-g q") "θ")
    (global-set-key (kbd "M-g i") "ι")
    (global-set-key (kbd "M-g k") "κ")
    (global-set-key (kbd "M-g l") "λ")
    (global-set-key (kbd "M-g m") "μ")
    (global-set-key (kbd "M-g n") "ν")
    (global-set-key (kbd "M-g x") "ξ")
    (global-set-key (kbd "M-g o") "ο")
    (global-set-key (kbd "M-g p") "π")
    (global-set-key (kbd "M-g r") "ρ")
    (global-set-key (kbd "M-g s") "σ")
    (global-set-key (kbd "M-g t") "τ")
    (global-set-key (kbd "M-g u") "υ")
    (global-set-key (kbd "M-g f") "ϕ")
    (global-set-key (kbd "M-g j") "φ")
    (global-set-key (kbd "M-g c") "χ")
    (global-set-key (kbd "M-g y") "ψ")
    (global-set-key (kbd "M-g w") "ω")
    (global-set-key (kbd "M-g A") "Α")
    (global-set-key (kbd "M-g B") "Β")
    (global-set-key (kbd "M-g G") "Γ")
    (global-set-key (kbd "M-g D") "Δ")
    (global-set-key (kbd "M-g E") "Ε")
    (global-set-key (kbd "M-g Z") "Ζ")
    (global-set-key (kbd "M-g H") "Η")
    (global-set-key (kbd "M-g Q") "Θ")
    (global-set-key (kbd "M-g I") "Ι")
    (global-set-key (kbd "M-g K") "Κ")
    (global-set-key (kbd "M-g L") "Λ")
    (global-set-key (kbd "M-g M") "Μ")
    (global-set-key (kbd "M-g N") "Ν")
    (global-set-key (kbd "M-g X") "Ξ")
    (global-set-key (kbd "M-g O") "Ο")
    (global-set-key (kbd "M-g P") "Π")
    (global-set-key (kbd "M-g R") "Ρ")
    (global-set-key (kbd "M-g S") "Σ")
    (global-set-key (kbd "M-g T") "Τ")
    (global-set-key (kbd "M-g U") "Υ")
    (global-set-key (kbd "M-g F") "Φ")
    (global-set-key (kbd "M-g J") "Φ")
    (global-set-key (kbd "M-g C") "Χ")
    (global-set-key (kbd "M-g Y") "Ψ")
    (global-set-key (kbd "M-g W") "Ω")
    
    0 讨论(0)
  • 2021-01-30 11:38

    A cousin of Rasmus' answer for non-TeX/LaTeX needs:

    M-x set-input-method RET C-\ greek RET
    or
                     C-x RET C-\ greek RET
    

    OR

    M-x set-input-method RET C-\ greek-babel RET
    or
                     C-x RET C-\ greek-babel RET
    

    Either of these give you input methods where typing for instance the single keystroke, 'a' simply gets you an alpha (α), 'b' gets you a beta (β) and so forth.

    After that, all you have to type is

    C-\
    

    to toggle back and forth from your default input method to the greek method very quickly. Quite handy.

    But you have to watch out: The keys don't always match the sounds. For instance, typing hello gets you ηελλο. This is because they made it so the 'h' key becomes a greek eta (η), simply because the η looks like an h, and because the capital Greek eta (H) is the same as our 'H', even though it was pronounced differently.

    The advantage of the greek-babel input method over just the greek will be appreciated mostly by those who work with the more advanced/complicated Attic Greek, which used a lot of accents. (Attic was used in Athens in Plato's time ~400BC, although the accents and lower-case letters were added centuries later.) You can hit the two keys < o and you get ὁ. The backwards apostrophe is an 'h' sound, called a 'rough breathing' -- thus ὁ is pronounced 'ho'. Accents are super easy and FAST. And you can combine accents over the same character. For instance, hit the three keys > ' a and you get ἄ. If you don't need the accents, just use the greek input method.

    With both the greek and greek-babel input methods, you can also hit C-h C-\ to get a Help buffer on the input method, which includes a lovely table of all the possible keystroke combinations available to you. (C-x o to move to next window, so you can get to that info window and scroll down..)

    See also https://www.emacswiki.org/emacs/InputMethods

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-30 11:40

    M-x set-input-method RET TeX will allow you to write e.g. \beta to get β, \sum or \Sigma to get Σ etc.

    It can be toggled on and off with toggle-input-method, bound to C-\ and C-<.

    0 讨论(0)
  • 2021-01-30 11:44

    The easiest way to sporadically insert Greek characters in Emacs is to use abbrev-mode with this abbrev table of Greek letters.

    To use the above gist, start emacs and invoke M-x edit-abbrevs which will start the Abbrevs editor. Then cut and paste the definitions within it under the (global-abbrev-table) section (to make them globally available) or place them underneath another heading e.g. (text-mode-abbrev-table).

    Ensure to enable abbrev-mode in a given buffer with M-x abbrev-mode RET, or enable abbrev-mode globally by adding (setq-default abbrev-mode t) to your init file. Alternatively if you want to enable abbrev-mode only for e.g. text and derived modes, use (add-hook 'text-mode-hook (lambda () (abbrev-mode 1))).

    See the emacs wiki about abbrev-mode for more.

    0 讨论(0)
提交回复
热议问题