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

From: Arash Esbati <[email-masked]>
Date: Fri, 25 Apr 2025 12:37:49 +0200

"Paul D. Nelson" <[email-masked]> writes:

> Looks good to me overall.

Thanks for checking

> One counterintuitive edge case: if I mark x and hit $ repeatedly, then I
> get $x$ -> \[x\] -> x -> etc.  On the other hand, if I mark $x$ and hit
> $, then I get $$x$$ -> $x$ -> etc.

I think this is by design.  In `TeX-insert-dollar-electric-region', we
have this test:

 ((and (eq last-command #'TeX-insert-dollar)
         (re-search-forward ...))
  ...

> I also wonder then whether TeX-insert-dollar (x2) should then similarly
> insert $$|$$ or \[|\] according to mode?

AUCTeX currently enters \[|\] when you hit \[ so I think the above would
be redundant.

> Tangentially, I wonder whether this feature might be more useful if it
> worked not just when operating on a region for the first time, but
> more generally on any math region, as a way to cycle between inline
> and displayed math.  I've had "make-inline" and "make-displayed"
> functions in my config for a long time now that I've tried
> unsuccessfully to think of an elegant way to package and contribute.

Hmm, maybe we can add them to AUCTeX itself.  Do you want to show the
code?

Best, Arash