How to replace string \ with string without backtick in emacs abbreviation mode?

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

My goal is to set abbreviations in emacs to replace some (TeX) macros with their Unicode characters, like \ alpha with Ξ± automatically, while I type TeX in emacs.

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

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

Abbreviations that can do what I want, i.e.:

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

or

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

do not apply when entering \ alpha or \ beta.

(I could get around this by replacing the alpha itself and erasing one previous character, but I would like to keep the alpha input option without a backslash and not apply this abbreviation rule.)

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

+4
source share
2 answers

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

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

The only problem is that in a regular expression that matches in reverse order, you cannot have optional characters at the beginning. Thus, either you change the syntax category \ (but then you do not need special processing of abbreviation tables), or you need to choose that all abbreviations in this table begin with a backslash or without it.

But why don't you use the input method to insert Unicode characters?

+5
source

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

+2
source

Source: https://habr.com/ru/post/1497022/


All Articles