GNU bug report logs - #78006
Improving `TeX-electric-math' behavior

Previous Next

Package: auctex;

Reported by: Arash Esbati <arash <at> gnu.org>

Date: Wed, 23 Apr 2025 07:27:01 UTC

Severity: normal

Done: Arash Esbati <arash <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Arash Esbati <arash <at> gnu.org>
Subject: bug#78006: closed (Re: bug#78006: Improving `TeX-electric-math'
 behavior)
Date: Sat, 03 May 2025 20:44:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

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

which was filed against the auctex package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 78006 <at> debbugs.gnu.org.

-- 
78006: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78006
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 78006-done <at> debbugs.gnu.org
Subject: Re: bug#78006: Improving `TeX-electric-math' behavior
Date: Sat, 03 May 2025 22:43:22 +0200
Keita Ikumi <ikumikeita <at> jcom.home.ne.jp> writes:

> Well, since docTeX-mode is already derived from 
> LaTeX-mode, we can just do
> (derived-mode-p 'LaTeX-mode)
> :-)

Ah, thanks.  I installed that change and therefore closing this report.
Thanks to you all for your comments.

Best, Arash

[Message part 3 (message/rfc822, inline)]
From: Arash Esbati <arash <at> gnu.org>
To: "auctex-bugs" <bug-auctex <at> gnu.org>
Subject: Improving `TeX-electric-math' behavior
Date: Wed, 23 Apr 2025 09:25:25 +0200
Hi all,

currently, we have this in AUCTeX manual[1]:

  User Option: TeX-electric-math

  In addition, when the variable is non-nil and there is an active
  region outside math mode, typing $ will put around the active region
  symbols for opening and closing inline equation and keep the region
  active, leaving point after the closing symbol.  By pressing
  repeatedly $ while the region is active you can toggle between an
  inline equation, a display equation, and no equation.  To be precise,
  ‘$...$’ is replaced by ‘$$...$$’, whereas ‘\(...\)’ is replaced by
  ‘\[...\]’.

Using $$...$$ in LaTeX is discouraged, so I think AUCTeX shouldn't
promote this as well, so I suggest this change to
`TeX-insert-dollar-electric-region':

--8<---------------cut here---------------start------------->8---
diff --git a/tex.el b/tex.el
index 3d28b2c6..5d184942 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 (memq major-mode '(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---

I think this needs some more massaging in order to make it work for
ConTeXt users as well, but this should get us going for other modes.

What do people think?  If Ok, I would install it and update the manual
accordingly.

Best, Arash

Footnotes:
[1]  https://elpa.gnu.org/packages/doc/auctex.html#index-TeX_002delectric_002dmath



This bug report was last modified 19 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.