GNU bug report logs -
#62445
13.1.10; bug in preview-region applied to repeated math environments
Previous Next
Reported by: Paul Nelson <ultrono <at> gmail.com>
Date: Sat, 25 Mar 2023 16:16:01 UTC
Severity: normal
Found in version 13.1.10
Done: Arash Esbati <arash <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 62445 in the body.
You can then email your comments to 62445 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Sat, 25 Mar 2023 16:16:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Paul Nelson <ultrono <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-auctex <at> gnu.org
.
(Sat, 25 Mar 2023 16:16: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)]
Emacs : GNU Emacs 29.0.50 (build 3, x86_64-apple-darwin21.6.0, NS
appkit-2113.60 Version 12.6 (Build 21G115))
of 2022-11-06
Package: 13.1.10
Take the following document:
#+begin_src latex
\documentclass{amsart}
\begin{document}
$x$ $x$
\end{document}
#+end_src
Run ~preview-region~ on the region consisting of the first $x$. This works
as expected.
Next, run ~preview-region~ on the region consisting of just the second
$x$. This does not preview the second $x$. Instead, it refreshes the
overlay on the first $x$.
The relevant output:
#+begin_quote
./_region_.tex:5: Preview: Snippet 1 started.
<-><->
l.5 $
x$
Preview: Tightpage -32891 -32891 32891 32891
./_region_.tex:5: Preview: Snippet 1 ended.(282168+0x374556).
<-><->
l.5 $x$
#+end_quote
The issue here is that there's not enough context for
~preview-parse-messages~ to determine which $x$ to overlay.
One workaround would be to apply ~preview-region~ to a region containing
both $x$'s (or to use ~preview-buffer~, etc). This workaround wasn't ideal
for my use-case (see parenthetical comment at the bottom).
I think a fix would be to store the beginning of the region being previewed
in a buffer-local variable and, if needed, bump the point when searching
for where to place the overlay. Details:
- Add the following line somewhere in preview.el:
#+begin_src elisp
(defvar-local preview-region--begin nil "Start of region being
processed.")
#+end_src
- Add the following line to ~preview-region~, just before the invocation of
~preview-generate-preview~:
#+begin_src elisp
(setq-local preview-region--begin begin)
#+end_src
- Add this to ~preview-parse-messages~, just before the second ~cond~ block:
#+begin_src elisp
(when (< (point) preview-region--begin)
(goto-char preview-region--begin))
#+end_src
I've made these changes in my local version and they have worked for me.
(This bug was an issue for me because I had set up a timer that searches
the visible portion of a TeX buffer for unrendered math environments and
runs ~preview-region~ on contiguous unpreviewed blocks. This led to many
situations where ~preview-region~ was called on math regions, such as the
second $x$ in the above example, that had already been previewed in the
current line. My original workaround was to enlarge the region sent to
~preview-region~ to contain any repeated math regions that appear earlier
in a given line. This worked, but often resulted in many fragments getting
unnecessarily refreshed.)
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Sat, 25 Mar 2023 16:42:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 62445 <at> debbugs.gnu.org (full text, mbox):
Paul Nelson <ultrono <at> gmail.com> writes:
> Emacs : GNU Emacs 29.0.50 (build 3, x86_64-apple-darwin21.6.0, NS
> appkit-2113.60 Version 12.6 (Build 21G115))
> of 2022-11-06
> Package: 13.1.10
>
> Take the following document:
>
> #+begin_src latex
> \documentclass{amsart}
> \begin{document}
> $x$ $x$
> \end{document}
> #+end_src
>
>
> Run ~preview-region~ on the region consisting of the first $x$. This works
> as expected.
>
> Next, run ~preview-region~ on the region consisting of just the second
> $x$. This does not preview the second $x$. Instead, it refreshes the
> overlay on the first $x$.
>
> The relevant output:
>
> #+begin_quote
> ./_region_.tex:5: Preview: Snippet 1 started.
> <-><->
>
> l.5 $
> x$
> Preview: Tightpage -32891 -32891 32891 32891
> ./_region_.tex:5: Preview: Snippet 1 ended.(282168+0x374556).
> <-><->
>
> l.5 $x$
>
> #+end_quote
>
>
> The issue here is that there's not enough context for
> ~preview-parse-messages~ to determine which $x$ to overlay.
I'd just add -file-line-error to the options you are calling TeX with.
That makes for more reliable error message interpretation.
--
David Kastrup
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Sat, 25 Mar 2023 16:47:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 62445 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thanks for your response. Here is my complete *_region_ output* for the
example I described. -file-line-error already seems to be included.
Please let me know if I missed something.
Running `Preview-LaTeX' on `~/doit/_region_' with ``pdflatex
-file-line-error --synctex=1
"\nonstopmode\nofiles\PassOptionsToPackage{active,tightpage,auctex}{preview}\AtBeginDocument{\ifx\ifPreview\undefined\RequirePackage[displaymath,floats,graphics,textmath,sections,footnotes,showlabels]{preview}[2004/11/05]\fi}"
"\input" "\detokenize{" _region_.tex "}"''
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded
format=pdflatex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
No auxiliary output files.
(./_region_.tex !name(test.tex)
(/usr/local/texlive/2020/texmf-dist/tex/latex/amscls/amsart.cls
Document Class: amsart 2017/10/31 v2.20.4
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def)
No file _region_.aux.
(/Users/paulnelson/.emacs.d/elpa/auctex-13.1.10/latex/preview.sty
(/usr/local/texlive/2020/texmf-dist/tex/generic/luatex85/luatex85.sty)
(/Users/paulnelson/.emacs.d/elpa/auctex-13.1.10/latex/prtightpage.def)
(/Users/paulnelson/.emacs.d/elpa/auctex-13.1.10/latex/prauctex.def
No auxiliary output files.
(/Users/paulnelson/.emacs.d/elpa/auctex-13.1.10/latex/prauctex.cfg))
(/Users/paulnelson/.emacs.d/elpa/auctex-13.1.10/latex/prfootnotes.def)
(/Users/paulnelson/.emacs.d/elpa/auctex-13.1.10/latex/prshowlabels.def)
Preview: Fontsize 10pt
Preview: PDFoutput 1
) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/umsb.fd)
!name(test.tex) !offset(-2)
./_region_.tex:5: Preview: Snippet 1 started.
<-><->
l.5 $
x$
Preview: Tightpage -32891 -32891 32891 32891
./_region_.tex:5: Preview: Snippet 1 ended.(282168+0x374556).
<-><->
l.5 $x$
[1{/usr/local/texlive/2020/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
!name(test.tex) !offset(-4)
\newlabel{tocindent-1}{0pt}
\newlabel{tocindent0}{0pt}
\newlabel{tocindent1}{0pt}
\newlabel{tocindent2}{0pt}
\newlabel{tocindent3}{0pt}
)
(see the transcript file for additional
information)</usr/local/texlive/2020/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb>
Output written on _region_.pdf (1 page, 8292 bytes).
SyncTeX written on _region_.synctex.gz.
Transcript written on _region_.log.
TeX Output exited as expected with code 1 at Sat Mar 25 17:42:58
Running `Preview-PDF2DSC' with ``pdf2dsc _region_.pdf
_region_.prv/tmpAnnFJy/preview.dsc''
Preview-PDF2DSC finished at Sat Mar 25 17:42:58
Running `Preview-Ghostscript' with ``/usr/local/bin/gs
-sOutputFile\=_region_.prv/tmpAnnFJy/pr1-\%d.pbm -q -dNOPAUSE -dNOSAFER
-DNOPLATFONTS -dPrinted -dTextAlphaBits\=4 -dGraphicsAlphaBits\=4
-sDEVICE\=pnmraw -r238.169x239.282''
Preview-Ghostscript finished at Sat Mar 25 17:42:58
On Sat, Mar 25, 2023 at 5:41 PM David Kastrup <dak <at> gnu.org> wrote:
> Paul Nelson <ultrono <at> gmail.com> writes:
>
> > Emacs : GNU Emacs 29.0.50 (build 3, x86_64-apple-darwin21.6.0, NS
> > appkit-2113.60 Version 12.6 (Build 21G115))
> > of 2022-11-06
> > Package: 13.1.10
> >
> > Take the following document:
> >
> > #+begin_src latex
> > \documentclass{amsart}
> > \begin{document}
> > $x$ $x$
> > \end{document}
> > #+end_src
> >
> >
> > Run ~preview-region~ on the region consisting of the first $x$. This
> works
> > as expected.
> >
> > Next, run ~preview-region~ on the region consisting of just the second
> > $x$. This does not preview the second $x$. Instead, it refreshes the
> > overlay on the first $x$.
> >
> > The relevant output:
> >
> > #+begin_quote
> > ./_region_.tex:5: Preview: Snippet 1 started.
> > <-><->
> >
> > l.5 $
> > x$
> > Preview: Tightpage -32891 -32891 32891 32891
> > ./_region_.tex:5: Preview: Snippet 1 ended.(282168+0x374556).
> > <-><->
> >
> > l.5 $x$
> >
> > #+end_quote
> >
> >
> > The issue here is that there's not enough context for
> > ~preview-parse-messages~ to determine which $x$ to overlay.
>
> I'd just add -file-line-error to the options you are calling TeX with.
> That makes for more reliable error message interpretation.
>
> --
> David Kastrup
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Wed, 03 Apr 2024 18:34:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 62445 <at> debbugs.gnu.org (full text, mbox):
Paul Nelson <ultrono <at> gmail.com> writes:
> I think a fix would be to store the beginning of the region being
> previewed in a buffer-local variable and, if needed, bump the point
> when searching for where to place the overlay. Details:
>
> - Add the following line somewhere in preview.el:
> #+begin_src elisp
> (defvar-local preview-region--begin nil "Start of region being processed.")
> #+end_src
>
> - Add the following line to ~preview-region~, just before the
> invocation of ~preview-generate-preview~:
> #+begin_src elisp
> (setq-local preview-region--begin begin)
> #+end_src
>
> - Add this to ~preview-parse-messages~, just before the second ~cond~ block:
> #+begin_src elisp
> (when (< (point) preview-region--begin)
> (goto-char preview-region--begin))
> #+end_src
>
> I've made these changes in my local version and they have worked for
> me.
Hi Paul,
thanks for your report and the analysis. Can you provide a patch for
this change? We can then install it, if it still works for you and
you're happy with it.
Best, Arash
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Wed, 03 Apr 2024 20:24:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 62445 <at> debbugs.gnu.org (full text, mbox):
Hi Arash,
I'll be happy to provide a patch for this.
Before doing so, let me clarify my motivation and ask for some advice.
I (and at least 6 others) have been using the package
https://github.com/ultronozm/czm-preview.el, which implements this fix
together with some other features. The implementation relies on 10
pieces of advice applied to preview-* and TeX-* functions. I'd like
to eliminate the use of advice, so that the package is less brittle.
Fixing this bug would be one step towards that goal; the others would
involve adding hooks and customization options to preview.el (without
modifying its current operation -- I don't want to introduce
instability).
Thus, to create this patch, I'll isolate the relevant modifications
from my overridden versions of preview-region and
preview-parse-messages. Later, in a separate report, I'll ask for
some (e.g.) hooks to be added to the same functions. If those changes
make it into an AUCTeX release, then I'll be able to eliminate some
advice from my package.
Does this sound like a reasonable plan? Any other suggestions?
Thanks, best,
Paul
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Wed, 03 Apr 2024 21:44:03 GMT)
Full text and
rfc822 format available.
Message #20 received at 62445 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
Paul Nelson <ultrono <at> gmail.com> writes:
> I'll be happy to provide a patch for this.
That's a good start :-)
> Before doing so, let me clarify my motivation and ask for some advice.
> I (and at least 6 others) have been using the package
> https://github.com/ultronozm/czm-preview.el, which implements this fix
> together with some other features.
Yes, I noticed you were working on different lisp libraries around TeX 👍
> The implementation relies on 10 pieces of advice applied to preview-*
> and TeX-* functions. I'd like to eliminate the use of advice, so that
> the package is less brittle. Fixing this bug would be one step
> towards that goal; the others would involve adding hooks and
> customization options to preview.el (without modifying its current
> operation -- I don't want to introduce instability).
This is definitely important. You may have noticed that the general
author of preview is now inactive, and the library is in sort of
maintenance mode, so we have to be careful.
> Thus, to create this patch, I'll isolate the relevant modifications
> from my overridden versions of preview-region and
> preview-parse-messages. Later, in a separate report, I'll ask for
> some (e.g.) hooks to be added to the same functions. If those changes
> make it into an AUCTeX release, then I'll be able to eliminate some
> advice from my package.
>
> Does this sound like a reasonable plan? Any other suggestions?
It sounds like a plan; gradually bringing in stuff you need is the way
to go. Looking forward to your changes.
Best, Arash
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Mon, 08 Apr 2024 11:22:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 62445 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi Arash,
OK, very well. Please find attached my best attempt at a patch for
this (any feedback or corrections welcome).
Thanks, best,
Paul
[0001-fix-bug-with-preview-region-applied-to-repeated-math.patch (application/x-patch, attachment)]
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Mon, 08 Apr 2024 12:45:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 62445 <at> debbugs.gnu.org (full text, mbox):
Hi Paul,
Paul Nelson <ultrono <at> gmail.com> writes:
> OK, very well. Please find attached my best attempt at a patch for
> this (any feedback or corrections welcome).
Thanks. I have 2 questions, see below:
> From 9d3266304f62fa3b21751b27200aab17454add6c Mon Sep 17 00:00:00 2001
> From: Paul Nelson <ultrono <at> gmail.com>
> Date: Mon, 8 Apr 2024 13:11:52 +0200
> Subject: [PATCH] fix bug with preview-region applied to repeated math
> environments
>
> See https://www.mail-archive.com/bug-auctex <at> gnu.org/msg04327.html.
Can you try to adjust the commit message as described here:
https://git.savannah.gnu.org/cgit/emacs.git/tree/CONTRIBUTE#n172
If not, I will try to fix that afterwards.
> ---
> preview.el.in | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/preview.el.in b/preview.el.in
> index 09836d9..72c5e58 100644
> --- a/preview.el.in
> +++ b/preview.el.in
> @@ -3268,6 +3268,8 @@ Return a new string."
> (setq result (concat result string))
> result))
>
> +(defvar-local preview--region-begin nil)
> +
> (defun preview-parse-messages (open-closure)
> "Turn all preview snippets into overlays.
> This parses the pseudo error messages from the preview
> @@ -3538,6 +3540,14 @@ name(\\([^)]+\\))\\)\\|\
> (goto-char (point-min))
> (forward-line (1- line)))
> (setq lpoint (point))
> +
> + ;; The following addresses the bug described at
> + ;; https://www.mail-archive.com/bug-auctex <at> gnu.org/msg04327.html
> + (and preview--region-begin
> + (< (point)
> + preview--region-begin)
> + (goto-char preview--region-begin))
> +
> (cond
> ((search-forward (concat string after-string)
> (line-end-position) t)
> @@ -4033,6 +4043,7 @@ stored in `preview-dumped-alist'."
> "<none>")
> (TeX-current-offset begin)))
> (setq TeX-current-process-region-p t)
> + (setq-local preview--region-begin begin)
Why `setq-local'? You define `preview--region-begin' with
`defvar-local', why not just `setq' it?
Best, arash
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#62445
; Package
auctex
.
(Mon, 08 Apr 2024 15:52:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 62445 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi Arash,
I've adjusted the commit message as best I could (it wasn't 100% clear
to me whether the summary line should appear "twice", both in the
subject and in the first line of the commit message), and can't
remember any reason not to just use setq, so I've changed it to that.
Any further feedback is welcome.
Thanks, best,
Paul
On Mon, Apr 8, 2024 at 2:44 PM Arash Esbati <arash <at> gnu.org> wrote:
>
> Hi Paul,
>
> Paul Nelson <ultrono <at> gmail.com> writes:
>
> > OK, very well. Please find attached my best attempt at a patch for
> > this (any feedback or corrections welcome).
>
> Thanks. I have 2 questions, see below:
>
> > From 9d3266304f62fa3b21751b27200aab17454add6c Mon Sep 17 00:00:00 2001
> > From: Paul Nelson <ultrono <at> gmail.com>
> > Date: Mon, 8 Apr 2024 13:11:52 +0200
> > Subject: [PATCH] fix bug with preview-region applied to repeated math
> > environments
> >
> > See https://www.mail-archive.com/bug-auctex <at> gnu.org/msg04327.html.
>
> Can you try to adjust the commit message as described here:
>
> https://git.savannah.gnu.org/cgit/emacs.git/tree/CONTRIBUTE#n172
>
> If not, I will try to fix that afterwards.
>
> > ---
> > preview.el.in | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/preview.el.in b/preview.el.in
> > index 09836d9..72c5e58 100644
> > --- a/preview.el.in
> > +++ b/preview.el.in
> > @@ -3268,6 +3268,8 @@ Return a new string."
> > (setq result (concat result string))
> > result))
> >
> > +(defvar-local preview--region-begin nil)
> > +
> > (defun preview-parse-messages (open-closure)
> > "Turn all preview snippets into overlays.
> > This parses the pseudo error messages from the preview
> > @@ -3538,6 +3540,14 @@ name(\\([^)]+\\))\\)\\|\
> > (goto-char (point-min))
> > (forward-line (1- line)))
> > (setq lpoint (point))
> > +
> > + ;; The following addresses the bug described at
> > + ;; https://www.mail-archive.com/bug-auctex <at> gnu.org/msg04327.html
> > + (and preview--region-begin
> > + (< (point)
> > + preview--region-begin)
> > + (goto-char preview--region-begin))
> > +
> > (cond
> > ((search-forward (concat string after-string)
> > (line-end-position) t)
> > @@ -4033,6 +4043,7 @@ stored in `preview-dumped-alist'."
> > "<none>")
> > (TeX-current-offset begin)))
> > (setq TeX-current-process-region-p t)
> > + (setq-local preview--region-begin begin)
>
> Why `setq-local'? You define `preview--region-begin' with
> `defvar-local', why not just `setq' it?
>
> Best, arash
[0001-Fix-preview-region-bug-with-repeated-math-envs.patch (application/octet-stream, attachment)]
Reply sent
to
Arash Esbati <arash <at> gnu.org>
:
You have taken responsibility.
(Mon, 08 Apr 2024 19:38:03 GMT)
Full text and
rfc822 format available.
Notification sent
to
Paul Nelson <ultrono <at> gmail.com>
:
bug acknowledged by developer.
(Mon, 08 Apr 2024 19:38:03 GMT)
Full text and
rfc822 format available.
Message #34 received at 62445-done <at> debbugs.gnu.org (full text, mbox):
Paul Nelson <ultrono <at> gmail.com> writes:
> I've adjusted the commit message as best I could (it wasn't 100% clear
> to me whether the summary line should appear "twice", both in the
> subject and in the first line of the commit message), and can't
> remember any reason not to just use setq, so I've changed it to that.
> Any further feedback is welcome.
Hi Paul,
thanks for considering my remarks. I slightly changed your last
proposal and installed it on master (b4dde3e325); I hope it's Ok for
you.
Again, many thanks for your contribution and sorry for the delay at our
end. I'm closing this report.
Best, Arash
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 07 May 2024 11:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 2 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.