11

During the work with tex files with auctex+emacs (LateX-mode), I use more frequently _ (underline) instead of - (minus sign). The same as ^ instead of 6. The inconvenience is that I should press more frequently the shift-key.

It would be desirable to customize emacs in such a way that when emacs is in LateX-mode (and just in this mode), when I type - the the emacs types _ and when I type _ the emacs types -. i.e., the following key-bindings:

- gives _

_ gives -

6 gives ^

^ gives 6

Is it possible?

Malabarba
  • 22,878
  • 6
  • 78
  • 163
Name
  • 7,689
  • 4
  • 38
  • 84

1 Answers1

16

Something like this:

(add-hook 'LaTeX-mode-hook 'my-latex-hook)

(defun my-latex-hook ()
  (require 'tex-site)
  (define-key LaTeX-mode-map "-" (lambda () (interactive) (insert "_")))
  (define-key LaTeX-mode-map "_" (lambda () (interactive) (insert "-")))
  (define-key LaTeX-mode-map "6" (lambda () (interactive) (insert "^")))
  (define-key LaTeX-mode-map "^" (lambda () (interactive) (insert "6"))))
abo-abo
  • 13,943
  • 1
  • 29
  • 43