Subject: Re: bug#78006: Improving `TeX-electric-math' behavior

From: Arash Esbati <[email-masked]>
Date: Sat, 03 May 2025 10:37:47 +0200

Hi Keita,

Ikumi Keita <[email-masked]> writes:

> I think we should use `derived-mode-p' here instead of comparing
> `major-mode' directly.

Thanks for your response.  Something like this?

--8<---------------cut here---------------start------------->8---
diff --git a/tex.el b/tex.el
index 3d28b2c6..0d47988c 100644
--- a/tex.el
+++ b/tex.el
@@ -6188,10 +6188,13 @@ See `TeX-electric-math'."
              (re-search-forward "\\=\\$\\$\\([^z-a]*\\)\\$\\$" (mark) t)))
     (replace-match "\\1" t)
     (set-mark (match-beginning 0)))
-   ;; $...$ to $$...$$
+   ;; $...$ to $$...$$ or \[...\] dep. on mode:
    ((and (eq last-command #'TeX-insert-dollar)
          (re-search-forward "\\=\\$\\([^z-a]*\\)\\$" (mark) t))
-    (replace-match "$$\\1$$" t)
+    (replace-match (if (derived-mode-p '(LaTeX-mode docTeX-mode))
+                       "\\\\[\\1\\\\]"
+                     "$$\\1$$")
+                   t)
     (set-mark (match-beginning 0)))
    ;; \(...\) to \[...\]
    ((and (eq last-command #'TeX-insert-dollar)
--8<---------------cut here---------------end--------------->8---

Best, Arash