How to disable underscore (_) subscripting in Emacs, TeX input method
So here is the solution I just found: Make a personalized copy of the TeX input method, with all of the undesirable entries removed. Then when using M-x set-input-method
, select the personalized version instead of TeX
.
I would have tried this earlier, but the built-in documentation for set-input-mode
and its ilk does not provide sufficient guidance to the actual source for the input-methods for me to find it. It was only after doing another search on SO and finding this: Emacs: Can't activate input method that I was able to get enough information to do this on my own.
Details:
In Emacs, open
/usr/share/emacs/22.1/leim/leim-list.el
and find the entry for the input method you want to customize. The entry will be something like the following form:(register-input-method "TeX" "UTF-8" 'quail-use-package "\\" "LaTeX-like input method for many characters." "quail/latin-ltx")
Note the file name prefix referenced in the last element in the form above. Find the corresponding Elisp source file; in this case, it is a relative path to the file
quail/latin-ltx.el[.gz]
. Open that file in Emacs, and check it out; it should have the entries for the method remappings, both desired and undesired.Make a user-local copy of that Elisp source file amongst your other Emacs customizations. Open that local copy in Emacs.
In your local copy, find the
(quail-define-package ...)
form in the file, and change the name of the package; I usedFSK-TeX
as my new name, like so:(quail-define-package "FSK-TeX" "UTF-8" "\\" t ;; <-- The first argument here is the important bit to change. "LaTeX-like input method for many characters but not as many as you might think. ...)
Go through your local copy, and delete all the S-expressions for mappings that you don't want.
In your .emacs configuration file, register your customized input method, using a form analogous to the one you saw when you looked at
leim-list.el
in step 1:(register-input-method "FSK-TeX" "UTF-8" 'quail-use-package "\\" "FSK-customized LaTeX-like input method for many characters." "~/ConfigFiles/Elisp/leim/latin-ltx")
Restart Emacs and test your new input-method; in my case, by doing
M-x set-input-method FSK-TeX
, typing a_0, and confirming thata_0
shows up in the buffer.
So, there's at least one answer that is less awkward once you have it installed than some of the workarounds listed in the question (and as it turns out, are also officially documented in the Emacs 22 manual as a way to cut off input method processing).
However, I am not really happy with this solution, since I would prefer to inherit future changes to TeX mode, and just have my .emacs
remove the undesirable entries on startup.
So I will wait to see if anyone else comes up with a better answer than this.
The evil plugin for vim-like modal keybinding allows to map two subsequent presses of the _
key to the insertion of a single _
character:
(set-input-method 'TeX)
(define-key evil-insert-state-local-map (kbd "_ _")
(lambda () (interactive) (insert "_")))
(define-key evil-insert-state-local-map (kbd "^ ^")
(lambda () (interactive) (insert "^")))
When _
and then 1
is pressed, we get ₁
as before, but
when _
and then _
is pressed, we get _
.
Analogous for ^
.
I did not test this myself, but this seems to be the exact thing you are looking for:
"How to disable underscore subscript in TeX mode in emacs" - source
Two solutions are given in this blogpot:
By the author of the blogpost:
(setq font-lock-maximum-decoration nil)
(from maximum)Mentioned as comment:
(eval-after-load "tex-mode" '(fset 'tex-font-lock-subscript 'ignore))