Subject: bug#78588: closed (Re: bug#78588: [PATCH] Fix math macro folding to not consume subsequent brackets)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 30 May 2025 15:22:02 +0000

Your bug report

#78588: [PATCH] Fix math macro folding to not consume subsequent brackets

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 [email-masked].

-- 
78588: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78588
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#78588: [PATCH] Fix math macro folding to not consume subsequent brackets
From: Arash Esbati <[email-masked]>
To: "Paul D. Nelson" <[email-masked]>
Cc: [email-masked]
Date: Fri, 30 May 2025 17:21:04 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

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

> Folding $x \in [0,1]$ doesn't work as intended: [0,1] gets folded as if it
> were an optional argument to \in.
>
> The issue is that, when called on 'math macros, TeX-fold-item-end calls
> TeX-find-macro, which skips past any {...} or [...].
>
> The attached patch makes an expection in TeX-fold-item-end for 'math
> macros, so that only the macro name itself (e.g., "\in") is folded.
>
> This only affects the folding of macros in the list
> TeX-fold-math-spec-list-internal, and looking through that list, I
> didn't spot any for which this change would have an undesired effect.

I installed that change.  Again, many thanks, closing.

Best, Arash

Subject: [PATCH] Fix math macro folding to not consume subsequent brackets
From: "Paul D. Nelson" <[email-masked]>
To: [email-masked]
Date: Sun, 25 May 2025 17:55:05 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi again,

Folding $x \in [0,1]$ doesn't work as intended: [0,1] gets folded as if it
were an optional argument to \in.

The issue is that, when called on 'math macros, TeX-fold-item-end calls
TeX-find-macro, which skips past any {...} or [...].

The attached patch makes an expection in TeX-fold-item-end for 'math
macros, so that only the macro name itself (e.g., "\in") is folded.

This only affects the folding of macros in the list
TeX-fold-math-spec-list-internal, and looking through that list, I
didn't spot any for which this change would have an undesired effect.

Any feedback welcome.

Thanks, best,

Paul

>From 83db375da4ea71b5abae3c010f2160f87086e850 Mon Sep 17 00:00:00 2001
From: Paul Nelson <[email-masked]>
Date: Sun, 25 May 2025 17:54:15 +0200
Subject: [PATCH] Fix math macro folding to not consume subsequent brackets

* tex-fold.el (TeX-fold-item-end): Add special handling for math
macros to only fold the macro name itself, not following
arguments.  For instance, in "$x \in [0,1]$", this prevents
folding [0,1] as an optional argument to \in.
---
 tex-fold.el | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tex-fold.el b/tex-fold.el
index 766270ef..78e5b822 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -901,6 +901,12 @@ TYPE can be either `env' for environments, `macro' for macros or
            (goto-char (1+ start))
            (LaTeX-find-matching-end)
            (point))
+          ((eq type 'math)
+           (goto-char (1+ start))
+           (if (zerop (skip-chars-forward "A-Za-z@"))
+               (forward-char)
+             (skip-chars-forward "*"))
+           (point))
           (t
            (goto-char start)
            (TeX-find-macro-end)))))
-- 
2.39.3 (Apple Git-145)