GNU bug report logs - #61410
texmathp and literal $

Previous Next

Package: auctex;

Reported by: Arash Esbati <arash <at> gnu.org>

Date: Fri, 10 Feb 2023 20:18:02 UTC

Severity: normal

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 61410 in the body.
You can then email your comments to 61410 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#61410; Package auctex. (Fri, 10 Feb 2023 20:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arash Esbati <arash <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Fri, 10 Feb 2023 20:18:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: auctex-bugs <bug-auctex <at> gnu.org>
Subject: texmathp and literal $
Date: Fri, 10 Feb 2023 21:16:22 +0100
Hi all,

please consider this small example:

--8<---------------cut here---------------start------------->8---
\documentclass{article}

\begin{document}

text \verb|$|

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
--8<---------------cut here---------------end--------------->8---

Now do:

  M-: (goto-char 58) RET
  C-c C-f C-t

and AUCTeX insert \mathtt{} at point.  Doing 'M-x texmathp RET' returns:

  math-mode is on: $ begins at buffer position 55

texmathp ignores the verb macro completely.  The similar scenario can be
created for a verbatim-like environment.  Can others reproduce this?
And if yes, any idea about course of action?

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#61410; Package auctex. (Sat, 11 Feb 2023 09:07:02 GMT) Full text and rfc822 format available.

Message #8 received at 61410 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 61410 <at> debbugs.gnu.org
Subject: Re: bug#61410: texmathp and literal $
Date: Sat, 11 Feb 2023 18:06:28 +0900
Hi Arash,

>>>>> Arash Esbati <arash <at> gnu.org> writes:
> texmathp ignores the verb macro completely.  The similar scenario can be
> created for a verbatim-like environment.  Can others reproduce this?

Yes. As far as I can see, texmathp.el doesn't pay attention to verbatim
constructs at all. I think that's an intention of Carsten Dominik.

> And if yes, any idea about course of action?

Maybe we can make texmathp syntax-aware (that is, to look into "string
quotes" syntax.) Currently, I'm not sure whether that's easy or not. Do
you think it's important to have this feature? (I'm neutral to the
importance.)

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-auctex <at> gnu.org:
bug#61410; Package auctex. (Sun, 12 Feb 2023 13:14:02 GMT) Full text and rfc822 format available.

Message #11 received at 61410 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 61410 <at> debbugs.gnu.org
Subject: Re: bug#61410: texmathp and literal $
Date: Sun, 12 Feb 2023 12:27:13 +0100
Hi Keita,

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> Yes. As far as I can see, texmathp.el doesn't pay attention to verbatim
> constructs at all. I think that's an intention of Carsten Dominik.

Thanks for confirming.  I'm not sure about the intention behind it, but
I think we should if we can fix this issue.

> Maybe we can make texmathp syntax-aware (that is, to look into "string
> quotes" syntax.) Currently, I'm not sure whether that's easy or not.

My simple idea was to have an extra check at the end of `texmathp'
itself in terms of: Pass the possible point for math-on to
`LaTeX-verbatim-p' and see what it returs.  I think the possibility for

  $ a \verb|$| $  <= invoke texmathp here

is next to zero while this

  $ a $ \verb|$| <= invoke texmathp here

or this

  \begin{verbatim}
  $
  \begin{end}
  <= invoke texmathp here

are not so far away, from user POV.

> Do you think it's important to have this feature? (I'm neutral to the
> importance.)

I'd say yes: Imagine you want to write a trivial example of bash command
in your document:

  \begin{verbatim}
  $ touch foo
  \begin{end}

currently breaks.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#61410; Package auctex. (Mon, 13 Feb 2023 14:14:02 GMT) Full text and rfc822 format available.

Message #14 received at 61410 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 61410 <at> debbugs.gnu.org
Subject: Re: bug#61410: texmathp and literal $
Date: Mon, 13 Feb 2023 15:11:55 +0100
[Message part 1 (text/plain, inline)]
Arash Esbati <arash <at> gnu.org> writes:

> My simple idea was to have an extra check at the end of `texmathp'
> itself in terms of: Pass the possible point for math-on to
> `LaTeX-verbatim-p' and see what it returs.

Following up myself, I was thinking about something like in the attached
patch.  Any comments welcome.

Best, Arash
[texmathp.diff (text/x-patch, inline)]
diff --git a/texmathp.el b/texmathp.el
index ad008986..d4b0b007 100644
--- a/texmathp.el
+++ b/texmathp.el
@@ -283,7 +283,7 @@ See the variable `texmathp-tex-commands' about which commands are checked."
                        (if (eq major-mode 'doctex-mode)
                            "[\n\r]%*[ \t]*[\n\r]"
                          "[\n\r][ \t]*[\n\r]")
-                                          nil 1 texmathp-search-n-paragraphs)
+                       nil 1 texmathp-search-n-paragraphs)
                       (match-beginning 0)
                     (point-min))))
          (mac-match (texmathp-match-macro bound))
@@ -321,12 +321,24 @@ See the variable `texmathp-tex-commands' about which commands are checked."
 
     ;; Store info, show as message when interactive, and return
     (setq texmathp-why match)
-    (and (called-interactively-p 'any)
-         (message "math-mode is %s: %s begins at buffer position %d"
-                  (if math-on "on" "off")
-                  (or (car match) "new paragraph")
-                  (cdr match)))
-    (and math-on t)))
+    ;; Check also if the is match inside a verbatim construct and
+    ;; return immediately nil.  This relies on the function
+    ;; `LaTeX-verbatim-p'.  We add a check here in case this library
+    ;; is used stand-alone without latex.el provided by AUCTeX:
+    (if (and (fboundp 'LaTeX-verbatim-p)
+             (save-excursion (LaTeX-verbatim-p (cdr match))))
+        (progn
+          (setq texmathp-why `(nil . ,(cdr match)))
+          (when (called-interactively-p 'any)
+            (message "math-mode is off: Math command in verbatim construct at buffer position %d"
+                     (cdr match)))
+          nil)
+      (and (called-interactively-p 'any)
+           (message "math-mode is %s: %s begins at buffer position %d"
+                    (if math-on "on" "off")
+                    (or (car match) "new paragraph")
+                    (cdr match)))
+      (and math-on t))))
 
 (defun texmathp-match-environment (bound)
   "Find out if point is inside any of the math environments.

Information forwarded to bug-auctex <at> gnu.org:
bug#61410; Package auctex. (Mon, 13 Feb 2023 16:40:01 GMT) Full text and rfc822 format available.

Message #17 received at 61410 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 61410 <at> debbugs.gnu.org
Subject: Re: bug#61410: texmathp and literal $
Date: Tue, 14 Feb 2023 01:39:49 +0900
Hi Arash,

>>>>> Arash Esbati <arash <at> gnu.org> writes:

> Following up myself, I was thinking about something like in the attached
> patch.  Any comments welcome.

This looks good to me. It takes care of all possible difficulties I
worried. :-)

Bye,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Reply sent to Arash Esbati <arash <at> gnu.org>:
You have taken responsibility. (Mon, 13 Feb 2023 21:43:02 GMT) Full text and rfc822 format available.

Notification sent to Arash Esbati <arash <at> gnu.org>:
bug acknowledged by developer. (Mon, 13 Feb 2023 21:43:02 GMT) Full text and rfc822 format available.

Message #22 received at 61410-done <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 61410-done <at> debbugs.gnu.org
Subject: Re: bug#61410: texmathp and literal $
Date: Mon, 13 Feb 2023 22:42:07 +0100
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> This looks good to me. It takes care of all possible difficulties I
> worried. :-)

What, maximum score? ;-) I installed the change incl. a test with commit
de6aa05d7 and closing this report.  Many thanks for your comments.

Best, Arash




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 14 Mar 2023 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 149 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.