Use YASnippet to Input Greek Characters
Sometimes, single characters like α
and β
are more recognizable than words like alpha
and beta
.
I think it is particularly useful when writing formulae in LaTeX or other text environments.
There are many general ways to input unicode characters quickly. For instance,
most intelligent input methods will suggest α as a candidate when you input alpha. In addition,
Emacs includes a built-in function insert-char
, which is bound to C-x 8 RET
by default.
YASnippet is another way I think is more convenient for frequently used symbols.
For example, put the following content in the file ~/.emacs.d/snippets/text-mode/char-alpha
.
# -*- mode: snippet -*- # name: char-alpha # key: \alpha # -- α
Then, when you type \alpha<TAB>
, the string expands to α
. Of course,
this only works in text mode and its derived mode. But you can easily
enable this feature in any mode, say prog-mode
, by adding a line
text-mode
to the file ~/.emacs.d/snippets/prog-mode/.yas-parents
. Remember to
remove the last newline character in the file char-alpha
. Otherwise,
it will expand to \alpha<NewLine>
.
I create a csv file whose rows are greek letters and their name in latex, which looks like
α, alpha β, beta γ, gamma δ, delta ϵ, epsilon ε, varepsilon ...
Based on this list, the following simple Python script can produce all the required snippets for greek letters.
filename = 'greek.csv' with open(filename, 'r') as fpr: greeklines = fpr.readlines() snippetTemplate = r"""# -*- mode: snippet -*- # name: char-{name} # key: \{name} # -- {char}""" charNameTuples = [line.strip().split(", ") for line in greeklines] for char, name in charNameTuples: with open(f"char-{name}", "w", encoding="utf8") as fpr: fpr.write(snippetTemplate.format(name=name, char=char))
Of couse, this method can be used to input any unicode letters, not limited to greek letters.