Insert Math Symbol in Emacs

Typing math symbols is often a tedious task. You either search through a bunch of symbol panels and click the one you want, or type TeX macros that you may or may not remember, or execute complex key bindings to enter a limited set of symbols. I recently learned about TeXmacs’ solution to symbol insertion: you type a symbol that’s more or less similar to the one you have in mind and use TAB to mutate it into the one desired. Say you want to enter ⊂ , you type < and hit TAB several times, go through ≤ , ∈ , ⊏ and finally arrive at ⊂ . It’s easy to remember, fast to insert, and can encode a lot of symbols.

TeXmacs is great, but I want to do the same thing in Emacs. Here is a demo of the command I use:

It has two features mimicking TeXmacs: 1) you can hit a key (say TAB ) and go through each variant of the symbol before point. 2) you can add an “accent modifier” after the symbol and hit the same key ( TAB ) to accent it. In the above demo I accented ⊃ into ⊇ by adding a _ accent modifier and hitting TAB .

Bind transform-previous-char to some key, and that key would do both tasks: transform and accent. You can also hit C-n/p to go back and forth when transforming. If you want to customize the symbols, look at transform-list and accent-list . And make sure accent modifiers is not in transform-list , in that case it is always treated as a modifier, rather than a variant.

There are some minor limitations. First, my command doesn’t support multi-character symbols; second, accent modifiers are order sensitive, e.g., you have to apply / after _ .

I have set up some default variant and accents.

Variant *×·⊗⊙ +⊕ |⊦⊨ /÷ \∖ <∈⊂⊏ >∋⊃⊐ =≈ v∨∪ ^∧∩ 0∅ Rℝ Zℤ Qℚ Nℕ Cℂ aαΑ∀ bβΒ gγΓ dδΔ eεΕ∃ zζΖ hηΗ qθΘ iιΙ kκΚ lλΛ mμΜ nνΝ∩ xξΞ oοΟ pπΠ rρΡ sσΣ tτΤ yυΥ fφΦ cχΧ uψΨ∪ wωΩ Accent _: <≤ ⊂⊆ ⊏⊑ >≥ ⊃⊇ ⊐⊒ /: =≠ <≮ ≤≰ ∈∉ ⊂⊄ ⊆⊈ >≯ ≥≱ ∋∌ ⊃⊅ ⊇⊉

Finally, the code. You can also find it in my config. Make sure you enable lexical binding.