GNU bug report logs -
#78585
[PATCH] TeX-fold-verbs: improve macro recognition
Previous Next
To reply to this bug, email your comments to 78585 AT debbugs.gnu.org.
There is no need to reopen the bug first.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-auctex <at> gnu.org
:
bug#78585
; Package
auctex
.
(Sun, 25 May 2025 12:54:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
"Paul D. Nelson" <ultrono <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-auctex <at> gnu.org
.
(Sun, 25 May 2025 12:54:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi all,
This patch adds a couple "boundary checks" to the verbatim folding code
I contributed earlier.
Here's a sample document illustrating what could go wrong:
--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{pythontex}
\NewDocumentCommand{\pyvm}{ m }{\mbox{\pyv{#1}}}
\begin{document}
$\pyvm{42}$
\end{document}
--8<---------------cut here---------------end--------------->8---
With the previous code, folding would trigger on \pyvm{42} as if it were
\pyv with delimiter m. The fix is to require a word boundary in the
macro-matching regexp.
The other change is a bounds check. I made this change locally a few
months ago, and think it was motivated by a parsing error, but
unfortunately forgot to save a minimal reproduction.
Any feedback welcome.
Thanks, best,
Paul
[0001-TeX-fold-verbs-improve-delimiter-and-macro-handling.patch (text/x-patch, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#78585
; Package
auctex
.
(Mon, 26 May 2025 12:24:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 78585 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
"Paul D. Nelson" <ultrono <at> gmail.com> writes:
> This patch adds a couple "boundary checks" to the verbatim folding code
> I contributed earlier.
>
> Here's a sample document illustrating what could go wrong:
>
> \documentclass{article}
> \usepackage{pythontex}
> \NewDocumentCommand{\pyvm}{ m }{\mbox{\pyv{#1}}}
>
> \begin{document}
>
> $\pyvm{42}$
>
> \end{document}
Yes, I see what you mean.
> With the previous code, folding would trigger on \pyvm{42} as if it were
> \pyv with delimiter m. The fix is to require a word boundary in the
> macro-matching regexp.
>
> The other change is a bounds check. I made this change locally a few
> months ago, and think it was motivated by a parsing error, but
> unfortunately forgot to save a minimal reproduction.
>
> Any feedback welcome.
See below.
> From f84918335e0ae99921f68458c4bc6b91bd243bad Mon Sep 17 00:00:00 2001
> From: Paul Nelson <ultrono <at> gmail.com>
> Date: Sun, 25 May 2025 14:51:33 +0200
> Subject: [PATCH] TeX-fold-verbs: improve delimiter and macro handling
>
> * tex-fold.el (TeX-fold--verb-data): Add check to ensure
> backward-sexp doesn't jump before macro boundaries when matching
> braces.
> (TeX-fold-verbs): Require word boundary after macro name in
> regexp to prevent folding partial macro matches (e.g., \pyv in
> \pyvm).
> ---
> tex-fold.el | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/tex-fold.el b/tex-fold.el
> index 2c10cc27..766270ef 100644
> --- a/tex-fold.el
> +++ b/tex-fold.el
> @@ -1362,13 +1362,17 @@ only in LaTeX modes."
> ?\{
> end-delim-char))
> (start-delim (char-to-string start-delim-char))
> - (verb-arg-start
> - (1+ (progn
> - (goto-char bound-end)
> - (if (string= start-delim TeX-grop)
> - (progn (backward-sexp) (point))
> - (forward-char -1)
> - (search-backward start-delim bound-start t)))))
> + (start-delim-pos
> + (save-excursion
> + (goto-char bound-end)
> + (if (string= start-delim TeX-grop) ; "{"
> + (when-let* ((matching-brace (save-excursion (backward-sexp)
> + (point))))
> + (and (>= matching-brace bound-start) matching-brace))
> + ;; delimiter is, e.g., "|"
> + (goto-char (1- bound-end))
> + (search-backward start-delim bound-start t))))
> + (verb-arg-start (1+ start-delim-pos))
> (verb-arg-end (1- bound-end)))
> (list bound-start
> bound-end
> @@ -1384,7 +1388,8 @@ Replaces the verbatim content with its own text."
> (regexp-opt
> (append
> (LaTeX-verbatim-macros-with-braces)
> - (LaTeX-verbatim-macros-with-delims))))))
> + (LaTeX-verbatim-macros-with-delims)))
> + "\\_>")))
Why do you use the "\\_>" boundary? I would have expected "\\b" or
"\\>"? Am I missing something?
Best, Arash
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#78585
; Package
auctex
.
(Mon, 26 May 2025 16:13:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 78585 <at> debbugs.gnu.org (full text, mbox):
Hi Arash,
Thanks for your feedback.
>> @@ -1384,7 +1388,8 @@ Replaces the verbatim content with its own text."
>> (regexp-opt
>> (append
>> (LaTeX-verbatim-macros-with-braces)
>> - (LaTeX-verbatim-macros-with-delims))))))
>> + (LaTeX-verbatim-macros-with-delims)))
>> + "\\_>")))
>
> Why do you use the "\\_>" boundary? I would have expected "\\b" or
> "\\>"? Am I missing something?
I had in mind stuff like:
(string-match "\\\\verb\\*\\_>" "\\verb*") ; t
(string-match "\\\\verb\\*\\>" "\\verb*") ; nil
(string-match "\\\\verb\\*\b" "\\verb*") ; nil
(I'll confess that I am not too familiar with what sorts of verbatim
macro names are out there, but figured ending on a symbol boundary would
be relatively safe.)
Paul
Reply sent
to
Arash Esbati <arash <at> gnu.org>
:
You have taken responsibility.
(Tue, 27 May 2025 08:53:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
"Paul D. Nelson" <ultrono <at> gmail.com>
:
bug acknowledged by developer.
(Tue, 27 May 2025 08:53:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 78585-done <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
"Paul D. Nelson" <ultrono <at> gmail.com> writes:
> I had in mind stuff like:
>
> (string-match "\\\\verb\\*\\_>" "\\verb*") ; t
> (string-match "\\\\verb\\*\\>" "\\verb*") ; nil
> (string-match "\\\\verb\\*\b" "\\verb*") ; nil
>
> (I'll confess that I am not too familiar with what sorts of verbatim
> macro names are out there, but figured ending on a symbol boundary would
> be relatively safe.)
Ah, yes, thanks, there are also starred versions. I installed your
patch and therefore closing this report. Thanks again for your
contribution.
Best, Arash
This bug report was last modified 7 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.