Subject: Re: bug#78587: [PATCH] TeX-find-macro-end

From: Arash Esbati <[email-masked]>
Date: Mon, 26 May 2025 15:20:28 +0200

Hi Paul,

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

> I noticed that TeX-find-macro-end doesn't work as expected way on, e.g.,
>
>   \begin{enumerate}[a)]
>
> The issue arose organically when folding such macros.
>
> To see the basic issue, evaluate the following in scratch:
>
> (mapcar
>  (lambda (str)
>    (with-temp-buffer
>      (LaTeX-mode)
>      (insert str)
>      (char-to-string (char-before (TeX-find-macro-end-helper (point-min))))))
>  '("\begin{enumerate}[a]"
>    "\begin{enumerate}[(a)]"
>    "\begin{enumerate}[a)]"))
>
> This returns ("]" "]" ")") but should return ("]" "]" "]").
>
> The attached patch seems to address the issue by using a stripped syntax
> table, which seems like a standard approach in tex.el.  Any feedback
> would be welcome.

What do get with your patch when you eval this form:

--8<---------------cut here---------------start------------->8---
(mapcar
 (lambda (str)
   (with-temp-buffer
     (LaTeX-mode)
     (insert str)
     (char-to-string (char-before (TeX-find-macro-end-helper (point-min))))))
 '("\begin{enumerate}[a]"
   "\begin{enumerate}[(a)]"
   "\begin{enumerate}[a)]"
   "\begin{enumerate}[a{]}]"))
--8<---------------cut here---------------end--------------->8---

Best, Arash