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

From: Keita Ikumi <[email-masked]>
Date: Sat, 3 May 2025 22:13:00 +0900 (JST)

>
>
> ------ Original Message ------
>  土曜日, 2025/5/3  17:37, Arash Esbati<[email-masked]> によって書かれました:
>
> 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))
Well, since docTeX-mode is already derived from 
LaTeX-mode, we can just do
(derived-mode-p 'LaTeX-mode)
:-)
> +                       "\\\\[\\1\\\\]"
> +                     "$$\\1$$")
> +                   t)
>      (set-mark (match-beginning 0)))
>     ;; \(...\) to \[...\]
>     ((and (eq last-command #'TeX-insert-dollar)
> --8<---------------cut here---------------end--------------->8---
>
> Best, Arash
>