[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master de6aa05d: Make `texmathp' aware of verbatim macros/environments
From: |
Arash Esbati |
Subject: |
master de6aa05d: Make `texmathp' aware of verbatim macros/environments |
Date: |
Mon, 13 Feb 2023 16:22:47 -0500 (EST) |
branch: master
commit de6aa05d741d393d020f9fa46a0fd2ad050992b6
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>
Make `texmathp' aware of verbatim macros/environments
* tests/latex/texmathp-test.el (texmathp-verbatim): New test.
* texmathp.el (texmathp): Use `LaTeX-verbatim-p' to check if the
math command is inside a verbatim construct. (bug#61410)
---
tests/latex/texmathp-test.el | 22 ++++++++++++++++++++++
texmathp.el | 27 ++++++++++++++++++++-------
2 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/tests/latex/texmathp-test.el b/tests/latex/texmathp-test.el
index 3fb6f549..121af22c 100644
--- a/tests/latex/texmathp-test.el
+++ b/tests/latex/texmathp-test.el
@@ -48,4 +48,26 @@
(LaTeX-mode)
(texmathp))))
+;; bug#61410
+(ert-deftest texmathp-verbatim ()
+ "Test for math command inside verbatim which is ignored."
+ (let ((TeX-install-font-lock #'font-latex-setup))
+ (should-not (with-temp-buffer
+ (insert "a $b$ \\verb|$| c ")
+ (LaTeX-mode)
+ (font-lock-ensure)
+ (texmathp)))
+
+ (should-not (with-temp-buffer
+ (insert "\
+a $b$
+
+\\begin{verbatim}
+$
+\\end{verbatim}
+c")
+ (LaTeX-mode)
+ (font-lock-ensure)
+ (texmathp)))))
+
;;; texmathp-test.el ends here
diff --git a/texmathp.el b/texmathp.el
index ad008986..1030ed85 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,25 @@ 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 match is 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
+ ;; (bug#61410):
+ (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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master de6aa05d: Make `texmathp' aware of verbatim macros/environments,
Arash Esbati <=