문제

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