How to insert $$ and place the cursor between them in autopilot mode

I often use AuCTeX to create my latex documents, so I often use the $ dollar sign.

If autopair is turned on in auxiliary mode, on insertion ( it automatically inserts ) (there are some exceptions where it is not, for example, if you insert it after \ , but I like exceptions) and place the cursor between them, so you have (<cursor>) , now if you type a + b) , you will get (a+b) , not (a+b)) .

I would like to have a similar behavior with $ , which only works in TeX-mode when I turn on autopair-mode .

I tried adding followint to my .emacs:

 (add-hook 'TeX-mode-hook #'(lambda () (push '(?$ . ?$) (getf autopair-extra-pairs :everywhere)))) 

but for some reason this does not work.

The problem is that you usually have many $...$ expressions, and when you insert one $ , all the text before that $ gets the wrong color, which is annoying, and then after closing the initial $ text is fixed after the original $ .

+7
source share
3 answers

Not sure about AuCTeX, but it works for latex-mode

 (eval-after-load "tex-mode" '(modify-syntax-entry ?$ "\"" latex-mode-syntax-table)) 

I donโ€™t know what syntax table for AuCTeX.

+2
source

FYI, I have a Github code for auto-detecting dollar signs and \ [\] in latex.

https://github.com/tomathan/autopair-latex/blob/master/autopair-latex.el

Hope this helps!

+2
source

My solution is essentially the same as event_jr (I tried, but that didn't work for me). The main thing is to change the syntax entry in $ so that it is designated as "(lines). Check the end of http://code.google.com/p/autopair/issues/detail?can=1&start=0&num=100&q=&colspec=ID% 20Type% 20Status% 20Priority% 20Milestone% 20Owner% 20Summary & groupby = & sort = & id = 18

0
source

All Articles