简体   繁体   English

如何在 Emacs 中输入希腊字符

[英]How to enter Greek characters in Emacs

This page indicates that Greek letters can be inserted into Emacs by using Mi .页面表示可以使用Mi将希腊字母插入 Emacs。 However, Emacs 23.2.1 in a Debian Squeeze variant inserts the "tab" character when Mi is pressed.但是,Debian Squeeze 变体中的 Emacs 23.2.1 在按下Mi时会插入“制表符”字符。 How can I insert Greek letters such α and β in Emacs?如何在 Emacs 中插入希腊字母,例如 α 和 β?

Mx set-input-method RET TeX will allow you to write eg \beta to get β , \sum or \Sigma to get Σ etc. Mx set-input-method RET TeX将允许您编写例如\beta来获得β\sum\Sigma来获得Σ等。

It can be toggled on and off with toggle-input-method , bound to C-\ and C-< .可以使用toggle-input-method来打开和关闭它,绑定到C-\C-<

You can use ucs-insert bound to Cx 8 RET to insert any Unicode characters by name or by value.您可以使用绑定到Cx 8 RETucs-insert按名称或按值插入任何 Unicode 字符。

For example to insert a lambda you can do例如插入一个 lambda 你可以做

  • Cx 8 RET GREEK SMALL LETTER LAMBDA RET → λ Cx 8 RET GREEK SMALL LETTER LAMBDA RET → λ
  • Cx 8 RET 03bb RET → λ Cx 8 RET 03bb RET → λ

A tab-completion is also available.也可以使用制表符完成。

Cx 8 RET * lambda TAB will list every unicode characters ended by a lambda. Cx 8 RET * lambda TAB将列出以 lambda 结尾的每个 unicode 字符。

You can set your input method to Greek:您可以将输入法设置为希腊语:

M-x set-input-method RET greek

or或者

C-x RET C-\ greek

(which is the same). (这是相同的)。 To set the input method back press C-\ ( toggle-input-method ).要设置输入法,请按C-\ ( toggle-input-method )。

Expanding the answer by @Oleg Pavliv:扩展@Oleg Pavliv 的答案:

To solve this problem once and for all in your .emacs file, you need to choose a key pattern (like Mg + <latin letter> ) and a memorizable correspondence table <greek letter> - <latin letter> .要在.emacs文件中一劳永逸地解决这个问题,您需要选择一个键模式(如Mg + <latin letter> )和一个可记忆的对应表<greek letter> - <latin letter> I suggest not to invent anything new, but to use the correspondences from the PostScript Symbol encoding.我建议不要发明任何新东西,而是使用 PostScript Symbol 编码中的对应关系。 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") "Ω")

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.或者使用你提到的页面上解释的global-abbrev-table

The easiest way to sporadically insert Greek characters in Emacs is to use abbrev-mode with this abbrev table of Greek letters .在 Emacs 中偶尔插入希腊字符的最简单方法是使用abbrev-mode这个希腊字母缩写表

To use the above gist, start emacs and invoke Mx edit-abbrevs which will start the Abbrevs editor.要使用上述要点,请启动 emacs 并调用Mx edit-abbrevs这将启动 Abbrevs 编辑器。 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 eg (text-mode-abbrev-table) .然后在(global-abbrev-table)部分下剪切并粘贴其中的定义(以使它们全局可用)或将它们放在另一个标题下,例如(text-mode-abbrev-table)

Ensure to enable abbrev-mode in a given buffer with Mx abbrev-mode RET , or enable abbrev-mode globally by adding (setq-default abbrev-mode t) to your init file.确保使用Mx abbrev-mode RET在给定缓冲区中启用 abbrev-mode,或者通过将(setq-default abbrev-mode t)添加到您的 init 文件来全局启用 abbrev-mode。 Alternatively if you want to enable abbrev-mode only for eg text and derived modes, use (add-hook 'text-mode-hook (lambda () (abbrev-mode 1))) .或者,如果您只想为文本和派生模式启用缩写模式,请使用(add-hook 'text-mode-hook (lambda () (abbrev-mode 1)))

See the emacs wiki about abbrev-mode for more.有关更多信息,请参阅有关 abbrev-mode 的 emacs wiki

Cx 8 RET , as described by @Daimrod above, is fine for a one-off insertion.如上面@Daimrod 所述, Cx 8 RET适合一次性插入。

If you want to bind a key to insert a given Unicode character: Load library ucs-cmds.el , then use C-1 Cx 8 RET .如果要绑定键以插入给定的 Unicode 字符:加载库ucs-cmds.el ,然后使用C-1 Cx 8 RET That inserts the character you choose and also creates a command with the same name, which you can bind to a key.这将插入您选择的字符,并创建一个具有相同名称的命令,您可以将其绑定到一个键。

For example, C-1 Cx 8 RET GREEK SMALL LETTER LAMBDA RET defines command greek-small-letter-lambda , which inserts that character when called.例如, C-1 Cx 8 RET GREEK SMALL LETTER LAMBDA RET定义命令greek-small-letter-lambda ,它在调用时插入该字符。

You can create multiple such commands at once, using macro ucsc-make-commands , also from ucs-cmds.el .您可以使用宏ucsc-make-commands一次创建多个此类命令,同样来自ucs-cmds.el For example, to create individual commands for each of the Greek letters, just do this:例如,要为每个希腊字母创建单独的命令,只需执行以下操作:

  (ucsc-make-commands "^greek [a-z]+ letter")

Then you can bind, say, command greek-small-letter-beta to Cc b or whatever:然后,您可以将命令greek-small-letter-beta绑定到Cc b或其他任何内容:

  (global-set-key (kbd "C-c b") 'greek-small-letter-beta)

A cousin of Rasmus' answer for non-TeX/LaTeX needs: Rasmus 的表弟对非 TeX/LaTeX 需求的回答:

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.这些中的任何一个都为您提供输入方法,例如键入单个击键,“a”只是为您提供一个 alpha (α),“b”为您提供一个 beta (β) 等等。

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 ηελλο.例如,输入 hello 会得到 ηελλο。 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.这是因为他们把“h”键变成了希腊语 eta (η),仅仅是因为 η 看起来像一个 h,而且大写的希腊语 eta (H) 与我们的“H”相同,尽管它发音不同。

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. greek-babel 输入法相对于希腊语的优势将主要被那些使用更高级/复杂的 Attic Greek 的人所欣赏,它使用了很多口音。 (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 ὁ. (Attic 在柏拉图时代约公元前 400 年在雅典使用,尽管重音和小写字母是在几个世纪后添加的。)您可以按两个键 < o 并得到 ὁ。 The backwards apostrophe is an 'h' sound, called a 'rough breathing' -- thus ὁ is pronounced 'ho'.后撇号是“h”音,称为“粗呼吸”——因此ὁ发音为“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 ἄ.例如,按三个键 > ' a 你会得到ἄ。 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 Ch C-\ to get a Help buffer on the input method, which includes a lovely table of all the possible keystroke combinations available to you.使用 greek 和 greek-babel 输入法,您还可以点击 Ch C-\ 以获取有关输入法的帮助缓冲区,其中包括一个可爱的表格,其中列出了您可用的所有可能的击键组合。 (Cx o to move to next window, so you can get to that info window and scroll down..) (Cx o 移动到下一个窗口,因此您可以进入该信息窗口并向下滚动..)

See also https://www.emacswiki.org/emacs/InputMethods另请参阅https://www.emacswiki.org/emacs/InputMethods

The TeX input method is great for entering symbols in general, but if you're typing them with any frequency (eg 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. TeX 输入法通常非常适合输入符号,但是如果您以任何频率输入它们(例如,如果您在某些函数式编程语言中输入λ ),每次输入\lambda想要插入一个希腊字母。

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.另一方面,希腊语输入法可以有效地处理希腊字母,并且是一个干净的解决方案,因为它利用了 Emacs 的内置希腊语支持,但它作为默认输入法并不是很有用。

You can combine the benefits of both approaches like so (put somewhere in your Emacs init config):您可以像这样结合两种方法的好处(放在您的 Emacs 初始化配置中的某个位置):

(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 ,.这使用 TeX 输入法作为默认输入法,但增加了一条规则,以便在前缀,. is used.用来。

Examples:例子:

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

Sources:资料来源:

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

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

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

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

To find out how to enter a single character that you already see somewhere on the screen, you can copy-paste that character to some emacs buffer/file, and then call Mx describe-char .了解如何输入您已经在屏幕某处看到的单个字符,您可以将该字符复制粘贴到某个 emacs 缓冲区/文件中,然后调用Mx describe-char With α, it yields有了 α,它产生

[...] to input: type "Cx 8 RET 3b1" or "Cx 8 RET GREEK SMALL LETTER ALPHA" [...]

PS: re your profile , try also ['a'] * 28 PS:重新你的个人资料,也试试['a'] * 28

In Spacemacs在 Spacemacs

M-m i u

That gives you a helm to search by name the symbol you want.这使您可以按名称搜索所需的符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM