diff --git a/tex.el b/tex.el
index af57c9b..f5666ae 100644
--- a/tex.el
+++ b/tex.el
@@ -5153,24 +5153,16 @@ See also `TeX-font-replace' and `TeX-font-replace-function'."
   :group 'TeX-macro
   :type 'boolean)
 
-(defcustom TeX-math-close-double-dollar nil
-  "If non-nil close double dollar math by typing a single `$'."
+(defcustom TeX-electric-math nil
+  ""
   :group 'TeX-macro
-  :type 'boolean)
-
-(defcustom TeX-math-close-single-dollar nil
-  "If non-nil, when outside math mode insert opening and closing dollar
-signs for TeX inline equation and put the point between them, just by
-typing a single `$'."
-  :group 'TeX-macro
-  :type 'boolean)
-
-(defcustom TeX-electric-dollar nil
-  "When outside math mode, if non-nil and there is an active
-region, typing `$' will put a pair of single dollar around it and
-leave point after the closing dollar."
-  :group 'TeX-macro
-  :type 'boolean)
+  :type '(choice (const nil)
+		 (const :tag )
+		 (const :tag "$...$" '("$" . "$"))
+		 (const :tag "\\(...\\)" '("\\(" . "\\)"))
+		 (cons :tag "Other"
+		       (string :tag "Insert before point")
+		       (string :tag "Insert after point"))))
 
 (defun TeX-insert-dollar (&optional arg)
   "Insert dollar sign.
@@ -5201,9 +5193,13 @@ sign.  With optional ARG, insert that many dollar signs."
 	     (string-equal (substring (car texmathp-why) 0 1) "\$"))
 	;; Math mode was turned on with $ or $$ - so finish it accordingly.
 	(progn
-	  (if TeX-math-close-double-dollar
-	      (insert (car texmathp-why))
-	    (insert "$"))
+	  (insert "$")
+	  ;; Compatibility, `TeX-math-close-double-dollar' has been removed
+	  ;; after AUCTeX 11.87.
+	  (if (boundp 'TeX-math-close-double-dollar)
+	      (message
+	       (concat "`TeX-math-close-double-dollar' has been removed,"
+		       "\nplease use `TeX-electric-math' instead.")))
 	  (when (and blink-matching-paren
 		     (or (string= (car texmathp-why) "$")
 			 (zerop (mod (save-excursion
@@ -5221,23 +5217,45 @@ sign.  With optional ARG, insert that many dollar signs."
       (insert "$")))
    (t
     ;; Just somewhere in the text.
-    (if (and TeX-electric-dollar (TeX-active-mark))
-	(progn
-	  (if (> (point) (mark))
-	      (exchange-point-and-mark))
-	  (insert "$")
+    (cond
+     ((and TeX-electric-math (TeX-active-mark))
+      (if (> (point) (mark))
+	  (exchange-point-and-mark))
+      ;; Keep the region active.
+      (let ((deactivate-mark nil))
+	(cond
+	 ;; $...$ to $$...$$
+	 ((and (eq last-command 'TeX-insert-dollar)
+	       (re-search-forward "\\$\\([^$].*[^$]\\)\\$" (mark) t))
+	  (replace-match "$$\\1$$")
+	  (push-mark (match-beginning 0) t))
+	 ;; \(...\) to \[..\]
+	 ((and (eq last-command 'TeX-insert-dollar)
+	       (re-search-forward "\\\\(\\(.*\\)\\\\)" (mark) t))
+	  (replace-match "\\\\[\\1\\\\]")
+	  (push-mark (match-beginning 0) t))
+	 ;; Remove \[...\] or $$...$$
+	 ((and (eq last-command 'TeX-insert-dollar)
+	       (or (re-search-forward "\\$\\$\\([^$].*[^$]\\)\\$\\$" (mark) t)
+		   (re-search-forward "\\\\\\[\\(.*\\)\\\\\\]" (mark) t)))
+	  (replace-match "\\1")
+	  (push-mark (match-beginning 0) t))
+	 (t
+	  ;; We use `save-excursion' because point must be situated before
+	  ;; opening symbol.
+	  (save-excursion (insert (car TeX-electric-math)))
 	  (exchange-point-and-mark)
-	  (insert "$"))
-      (if TeX-math-close-single-dollar
+	  (insert (cdr TeX-electric-math))))))
+     (TeX-electric-math
+      (insert (car TeX-electric-math))
+      (save-excursion (insert (cdr TeX-electric-math)))
+      (if blink-matching-paren
 	  (progn
-	    (insert "$$")
-	    (if blink-matching-paren
-		(progn
-		  (backward-char 2)
-		  (sit-for blink-matching-delay)
-		  (forward-char))
-	      (backward-char)))
-	(insert "$")))))
+	    (backward-char)
+	    (sit-for blink-matching-delay)
+	    (forward-char))))
+     ;; In any other case just insert a single $.
+     ((insert "$")))))
   (TeX-math-input-method-off))
 
 (defvar TeX-math-input-method-off-regexp
diff --git a/tex.el b/tex.el
index af57c9b..6d772d5 100644
--- a/tex.el
+++ b/tex.el
@@ -5158,19 +5158,28 @@ See also `TeX-font-replace' and `TeX-font-replace-function'."
   :group 'TeX-macro
   :type 'boolean)
 
-(defcustom TeX-math-close-single-dollar nil
-  "If non-nil, when outside math mode insert opening and closing dollar
-signs for TeX inline equation and put the point between them, just by
-typing a single `$'."
+(defcustom TeX-electric-inline-math nil
+  "If non-nil, when outside math mode `TeX-insert-dollar' will
+insert symbols for opening and closing inline equation and put
+the point between them.  If there is an active region,
+`TeX-insert-dollar' will put around it symbols for opening and
+closing inline equation and keep the region active, with point
+after closing symbol.  If you press `$' again, you can toggle
+between inline equation, display equation, and no equation.
+
+If nil, `TeX-insert-dollar' will simply insert \"$\" at point,
+this is the default.
+
+This variable is a cons cell whose CAR is the string to insert
+before point, the CDR is the string to insert after point.  You
+can choose between \"$...$\" and \"\\(...\\)\"."
   :group 'TeX-macro
-  :type 'boolean)
-
-(defcustom TeX-electric-dollar nil
-  "When outside math mode, if non-nil and there is an active
-region, typing `$' will put a pair of single dollar around it and
-leave point after the closing dollar."
-  :group 'TeX-macro
-  :type 'boolean)
+  :type '(choice (const :tag "$" nil)
+		 (const :tag "$...$" '("$" . "$"))
+		 (const :tag "\\(...\\)" '("\\(" . "\\)"))
+		 (cons :tag "Other"
+		       (string :tag "Insert before point")
+		       (string :tag "Insert after point"))))
 
 (defun TeX-insert-dollar (&optional arg)
   "Insert dollar sign.
@@ -5181,6 +5190,9 @@ the TeX math mode and `blink-matching-paren' is non-nil.  Ensure
 double dollar signs match up correctly by inserting extra dollar
 signs when needed.
 
+When outside math mode, the behavior is controlled by the variable
+`TeX-electric-inline-math'.
+
 With raw \\[universal-argument] prefix, insert exactly one dollar
 sign.  With optional ARG, insert that many dollar signs."
   (interactive "P")
@@ -5221,23 +5233,48 @@ sign.  With optional ARG, insert that many dollar signs."
       (insert "$")))
    (t
     ;; Just somewhere in the text.
-    (if (and TeX-electric-dollar (TeX-active-mark))
-	(progn
-	  (if (> (point) (mark))
-	      (exchange-point-and-mark))
-	  (insert "$")
-	  (exchange-point-and-mark)
-	  (insert "$"))
-      (if TeX-math-close-single-dollar
+    (cond
+     ((and TeX-electric-inline-math (TeX-active-mark))
+      (if (> (point) (mark))
+	  (exchange-point-and-mark))
+      (cond
+       ;; $...$ to $$...$$
+       ((and (eq last-command 'TeX-insert-dollar)
+	     (re-search-forward "\\=\\$\\([^$][^z-a]*[^$]\\)\\$" (mark) t))
+	(replace-match "$$\\1$$")
+	(push-mark (match-beginning 0) t))
+       ;; \(...\) to \[...\]
+       ((and (eq last-command 'TeX-insert-dollar)
+	     (re-search-forward "\\=\\\\(\\([^z-a]*\\)\\\\)" (mark) t))
+	(replace-match "\\\\[\\1\\\\]")
+	(push-mark (match-beginning 0) t))
+       ;; Strip \[...\] or $$...$$
+       ((and (eq last-command 'TeX-insert-dollar)
+	     (or (re-search-forward "\\=\\\\\\[\\([^z-a]*\\)\\\\\\]" (mark) t)
+		 (re-search-forward "\\=\\$\\$\\([^z-a]*\\)\\$\\$" (mark) t)))
+	(replace-match "\\1")
+	(push-mark (match-beginning 0) t))
+       (t
+	;; We use `save-excursion' because point must be situated before opening
+	;; symbol.
+	(save-excursion (insert (car TeX-electric-inline-math)))
+	(exchange-point-and-mark)
+	(insert (cdr TeX-electric-inline-math))))
+      ;; Keep the region active.
+      (if (featurep 'xemacs)
+	  (zmacs-activate-region)
+	(setq activate-mark t
+	      deactivate-mark nil)))
+     (TeX-electric-inline-math
+      (insert (car TeX-electric-inline-math))
+      (save-excursion (insert (cdr TeX-electric-inline-math)))
+      (if blink-matching-paren
 	  (progn
-	    (insert "$$")
-	    (if blink-matching-paren
-		(progn
-		  (backward-char 2)
-		  (sit-for blink-matching-delay)
-		  (forward-char))
-	      (backward-char)))
-	(insert "$")))))
+	    (backward-char)
+	    (sit-for blink-matching-delay)
+	    (forward-char))))
+     ;; In any other case just insert a single $.
+     ((insert "$")))))
   (TeX-math-input-method-off))
 
 (defvar TeX-math-input-method-off-regexp
