I often use AuCTeX to make my latex documents so i use the dollar $
sign a lot.
If autopair minor mode is enabled, when you insert a (
it automatically inserts a )
(there are some exceptions where it doesn't, for example, if you insert it after a \
, but i like the exceptions) and put the cursor between them, so you have (<cursor>)
, now if you type a+b), you get (a+b)
and not (a+b))
.
I would like to have a similar behaviour with $
that works only in TeX-mode
when i enable autopair-mode
.
I've tried adding the followint to my .emacs:
(add-hook 'TeX-mode-hook
#'(lambda ()
(push '(?$ . ?$)
(getf autopair-extra-pairs :everywhere))))
but it does not work for some reason.
The problem is that you usually have a lot of expression $...$
and when you insert a single $
, all the text before that $
gets a wrong coloration which is annoying and then after you close the initial $
the text after the initial $
gets fixed.
Not sure about AuCTeX, but this works for latex-mode
(eval-after-load "tex-mode" '(modify-syntax-entry ?$ "\"" latex-mode-syntax-table))
Not sure what the right syntax-table is for AuCTeX.
FYI, I have code on Github for autopairing dollar signs and \[\] in Latex.
https://github.com/tomathan/autopair-latex/blob/master/autopair-latex.el
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With