* Jens Kubieziel (2005-11-01) writes:

> when typing sub- or superscripts in math mode I often need curly braces.
> So I want to customize AUCTeX that everytime when I press `_' or `^' it
> automagically appends `{}' and places the cursor inside. I guess this
> can be done like described in 'Style Files' in auctex.info. But actually
> I'm not sure how to do it in detail (without any lisp knowledge).

How about the attached patch?  Maybe the respective variable and
function should be named `TeX-insert-exp-and-subscript' instead of
`TeX-electric-exp-and-subscript' because the functionality does not
really feel like true electricity.  Other suggestions for the name?

Also, does anybody know why `TeX-electric-escape'/`TeX-electric-macro'
is implemented in a way that Emacs has to be restarted for a change of
`TeX-electric-escape' to take effect?  If nobody objects I can change
it, so that typing `\' will always call `TeX-electric-macro' (maybe
renamed) and the function will then check the value of
`TeX-electric-escape'.

> Furthermore I'm looking for a way to expand math operators with indices
> to its last values.
> Example: I typed $\sum_{i=1}^n ...$. Later I type `$\sum_' and now I want
> AUCTeX to print `\sum_{i=1}^n '. How can this be done?

Hm, isn't something like this only useful in special cases?

-- 
Ralf
--- tex.el	28 Oct 2005 18:09:08 +0200	5.541
+++ tex.el	01 Nov 2005 17:09:02 +0100	
@@ -3277,6 +3277,11 @@
   :group 'TeX-macro
   :type 'boolean)
 
+(defcustom TeX-electric-exp-and-subscript nil
+  "If non-nil insert braces after typing `^' and `_' in math mode."
+  :group 'TeX-macro
+  :type 'boolean)
+
 (defcustom TeX-newline-function 'newline
   "Function to be called upon pressing `RET'."
   :group 'TeX-indentation
@@ -3285,6 +3290,13 @@
 		 (const reindent-then-newline-and-indent)
 		 (sexp :tag "Other")))
 
+(defun TeX-electric-exp-and-subscript (arg)
+  (interactive "*p")
+  (self-insert-command arg)
+  (when (and TeX-electric-exp-and-subscript (texmathp))
+    (insert "{}")
+    (backward-char)))
+
 (defun TeX-newline ()
   "Call the function specified by the variable `TeX-newline-function'."
   (interactive) (funcall TeX-newline-function))
@@ -3311,6 +3323,8 @@
     (define-key map "\C-c\C-m" 'TeX-insert-macro)
     (if TeX-electric-escape
 	(define-key map "\\" 'TeX-electric-macro))
+    (define-key map "^"      'TeX-electric-exp-and-subscript)
+    (define-key map "_"      'TeX-electric-exp-and-subscript)
     (define-key map "\e\t"   'TeX-complete-symbol) ;*** Emacs 19 way
     
     (define-key map "\C-c'"    'TeX-comment-or-uncomment-paragraph) ;*** Old way
_______________________________________________
auctex mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/auctex

Reply via email to