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.

Full log


View this message in rfc822 format

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 61410 <at> debbugs.gnu.org
Subject: 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.

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

Previous Next


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