I am using Auctex in Aquamacs. Everytime I type underline "_", it will show as $_{}$
automatically which is very annoying. I am wondering how could I turn off this function. Thanks.

- 21,702
- 4
- 53
- 89

- 93
- 7
-
2This (very useful, actually) feature is not enabled by default. As explained by Gilles, this is controlled by `TeX-electric-sub-and-superscript`, you somehow set it to `t` in your init file. – giordano Jan 10 '17 at 13:19
1 Answers
You can always insert a character literally by typing C-q
first (quoted-insert
).
Many “electric” characters (that's what Emacs usually calls characters whose insertion has extra effects such as inserting extra braces, reindenting, etc.) are designed to revert to a plain insertion if you pass a numeric prefix argument, i.e. type ESC 1 _
or M-1 _
to insert one underscore. I don't know if this is the case specifically for the command you're using.
To see the effect of the _
key, type C-h k
(describe-key
) followed by _
. That will give you a description of the command, and perhaps a way to customize it. By default, in AUCTeX, _
runs TeX-insert-sub-or-superscript
which just inserts a _
unless TeX-electric-sub-and-superscript
is turned on, and even then it only inserts braces if already in math mode.
It turns out that you're using cdlatex, where _
is bound to cdlatex-sub-superscript
. If you want to keep using cdlatex but deactivate the electric behavior of _
, you can remove _
from the cdlatex keymap after the package is loaded:
(defun my-after-load-cdlatex ()
(define-key cdlatex-mode-map "_" nil)
t)
(eval-after-load "cdlatex" '(my-after-load-cdlatex))
You may wish to activate AUCTeX's less invasive electric _
by setting TeX-electric-sub-and-superscript
:
(setq TeX-electric-sub-and-superscript t)

- 21,702
- 4
- 53
- 89
-
Hi Gilles, thank you for your answer. I tries `C-h k` followed by `_`. The response is given below: > _ runs the command cdlatex-sub-superscript (found in cdlatex-mode-map), which is an interactive Lisp function in 'cdlatex.el'. At this moment, `C-q _` works for me. But how could I do to keep underline bound with brace`{}` and dollars works and only works in math environment? Thank you. – Raymond Jan 11 '17 at 02:02
-