2

This is a question a friend of mine had; figured posting here might give quick responses.

Old version in new language, après Name

How do I define the mapping ^ |--> ^ while ^^ |--> ^{}. Similarly, for _.

Old Version

Is there a way to modify the electric braces for superscript and subscript to behave as follows:

  • Insert no empty pair of braces when a carat ^ or underscore _ is entered.

  • Insert a empty pair of braces when a carat ^ (resp. underscore _) is entered following a ^ carat (resp. _ underscore) sign.

Any answer would be helpful.

/p/s/ The motivation is to minimise having to jump out of braces when the subscript or superscript is just really a character long.

  • Your question is unclear to me. Do you mean the mapping ^-->nothing and ^^-->{} or ^-->^ and ^^-->^{} ? – Name Feb 1 '15 at 17:33
  • Yes, that is exactly what I would like to have. Thanks. – kan Feb 1 '15 at 18:15
  • Just a clarification. Do you mean ^-->^? – Name Feb 1 '15 at 18:50
  • Yup, otherwise, that was me being silly. – kan Feb 1 '15 at 19:27
3

This does what you asked for. It also put the cursor between the braces.

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

(defun my-latex-hook ()
  (require 'tex-site)
  (define-key LaTeX-mode-map "^" 
    (lambda () 
      (interactive) 
      (if (equal (preceding-char) ?^) 
          (progn (insert "{}")(backward-char)) 
        (insert "^")))))

The credit is due to @abo-abo for his/her answer https://emacs.stackexchange.com/a/3882/2609 from which I got this idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.