My question is motivated by writing TeX in emacs, but is unrelated to the TeX system itself.

My goal is to set up abbreviations in emacs to replace some (TeX) macros with their unicode characters, for example \alpha with α automatically while I'm typing TeX in emacs.

I planned to achieve this using the abbrev system. While the following abbreviation works fine (replaces test with \test):

("test" "\\test" nil 0)

The abbreviations that could do what I want, i.e.:

("\\alpha" "A" nil 0)

or

("\\\\beta" "B" nil 0)

are not applying when I type \alpha or \beta.

(I could sidestep this by replacing "alpha" itself and erasing one preceding character, but I would like to preserve the option of typing alpha without the backslash and not applying this abbrev rule.)

What is the correct form of the abbreviation that replaces \alpha with α?

有帮助吗?

解决方案

You need to change the property :regexp of your abbrev table.

(abbrev-table-put <your-abbrev-table> :regexp "\\(\\\\[a-z0-9@]+\\)")

The only problem is, in a regexp that is matched looking backwards, you can't have optional characters at the beginning. So, either you change the syntax category of \ (but then you don't need any special handling of abbrev tables), or you have to choose to have your all abbrevs in this table start with or without a backslash.

But why don't you use an input method to insert unicode characters?

其他提示

This already exists. Use the function set-input-method and select TeX.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top