惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

elpa/gnu.git, branch externals/auctex

* latex.el (LaTeX-what-macro): Improve macro recognition. - elpa/gnu.git Preserve `crm--choose-completion-string' - elpa/gnu.git - GNU ELPA Accept '-' as macro modifier - elpa/gnu.git Add new styles - elpa/gnu.git ; * tex-info.el (outline-heading-alist): Silence the compiler. - elpa/gnu.git Update style/simpleicons.el to package v16.29.0 - elpa/gnu.git Update NEWS.org for new preview feature - elpa/gnu.git Fix custom prompt with a default-value - elpa/gnu.git Fix prompt with a default-value - elpa/gnu.git Make `TeX-listify' an obsolete alias - elpa/gnu.git Fix 'syntax-propertize because of narrowing!' error - elpa/gnu.git Update style/ltx-talk.el to class v0.6.0 - elpa/gnu.git elpa/gnu.git - GNU ELPA elpa/gnu.git - GNU ELPA elpa/gnu.git - GNU ELPA elpa/gnu.git - GNU ELPA elpa/gnu.git - GNU ELPA Return context for RefTeX also for macros - elpa/gnu.git ; Fix last change - elpa/gnu.git Add in-buffer completion for citation keys - elpa/gnu.git ; Adjust Copyright years - elpa/gnu.git Improve query of the optional float placement - elpa/gnu.git Sort predefined environment hooks - elpa/gnu.git Sort predefined hooks - elpa/gnu.git Allow additional properties for in-buffer completion - elpa/gnu.git Use ConTeXt Mark XL instead of LMTX - elpa/gnu.git ; * tex.el (TeX-output-dir): Fix last change. - elpa/gnu.git * tex.el (TeX-output-dir): Fix docstring acc. to last change. - elpa/gnu.git ; * NEWS.org (Changed): Announce last change. - elpa/gnu.git Change default value of `ConTeXt-Mark-version' - elpa/gnu.git
Robustify check for escaped math switches/togglers - elpa...
Arash Esbati · 2026-09-03 · via elpa/gnu.git, branch externals/auctex

* texmathp.el (texmathp--escaped-p): New function. (texmathp-compile): Remove the regexp-based check if a math switch or toggler is escaped. (texmathp, texmathp-match-switch): Use the new function instead. (Bug#81327) * tests/latex/texmathp-test.el (texmathp-escaped-toggle-onoff): New test.

@@ -1,6 +1,6 @@

;;; texmathp-test.el --- tests for texmathp -*- lexical-binding: t; -*-

-;; Copyright (C) 2020-2021 Free Software Foundation, Inc.

+;; Copyright (C) 2020-2026 Free Software Foundation, Inc.

;; This file is part of AUCTeX.

@@ -68,4 +68,28 @@ c")

(LaTeX-mode)

(texmathp)))))

+;; bug#81327

+(ert-deftest texmathp-escaped-toggle-onoff ()

+ "Test if the math toggle or onoff-regexp is actually unescaped."

+ (should (with-temp-buffer

+ ;; LaTeX: \begin{tabular}{c}$a$\\$b$\end{tabular}

+ (insert "\\begin{tabular}{c}$a$\\\\$b$\\end{tabular}")

+ (LaTeX-mode)

+ (search-backward "b$")

+ (texmathp)))

+

+ (should (with-temp-buffer

+ ;; LaTeX: a\\\(b\)c

+ (insert "a\\\\\\(b\\)c")

+ (LaTeX-mode)

+ (search-backward "b")

+ (texmathp)))

+

+ (should-not (with-temp-buffer

+ ;; LaTeX: a\\(b\\)c

+ (insert "a\\\\(b\\\\)c")

+ (LaTeX-mode)

+ (search-backward "b")

+ (texmathp))))

+

;;; texmathp-test.el ends here

diff --git a/texmathp.el b/texmathp.el
index 7dd443a0150..a95fe948d9f 100644
--- a/texmathp.el
+++ b/texmathp.el

@@ -172,6 +172,18 @@

("dsuspend" env-off))

"The default entries for `texmathp-tex-commands', which see.")

+(defun texmathp--escaped-p (&optional pos)

+ "Return t if the character at position POS is escaped.

+If POS is omitted, examine the character at point.

+A character is escaped if it is preceded by an odd number of

+escape characters, namely \"\\\" in (La)TeX.

+

+This is a copy of `TeX-escaped-p' provided by tex.el in order to keep

+this library usable stand-alone."

+ (save-excursion

+ (when pos (goto-char pos))

+ (not (zerop (mod (skip-chars-backward (regexp-quote "\\")) 2)))))

+

(defun texmathp-compile ()

"Compile the value of `texmathp-tex-commands' into the internal lists.

Call this when you have changed the value of that variable without using

@@ -192,12 +204,8 @@ customize (customize calls it when setting the variable)."

((memq type '(arg-on arg-off)) (push (car entry) texmathp-macros))

((memq type '(sw-on sw-off)) (push (car entry) switches))

((memq type '(sw-toggle)) (push (car entry) togglers))))

- (setq texmathp-onoff-regexp

- (concat "\\(?:[^\\]\\|\\`\\)"

- (regexp-opt switches t))

- texmathp-toggle-regexp

- (concat "\\([^\\$]\\|\\`\\)"

- (regexp-opt togglers t)))))

+ (setq texmathp-onoff-regexp (regexp-opt switches t)

+ texmathp-toggle-regexp (regexp-opt togglers t))))

(defcustom texmathp-tex-commands nil

"List of environments and macros influencing (La)TeX math mode.

@@ -312,9 +320,12 @@ See the variable `texmathp-tex-commands' about which commands are checked."

(save-excursion

(goto-char (cdr match))

(while (re-search-forward texmathp-toggle-regexp pos t)

- (if (setq math-on (not math-on))

- (setq sw-match (cons (match-string-no-properties 2) (match-beginning 2)))

- (setq sw-match nil)))

+ ;; Check the toggle is unescaped (bug#81327):

+ (unless (texmathp--escaped-p (match-beginning 1))

+ (if (setq math-on (not math-on))

+ (setq sw-match (cons (match-string-no-properties 1)

+ (match-beginning 1)))

+ (setq sw-match nil))))

(and math-on sw-match (setq match sw-match))))

;; Store info, show as message when interactive, and return

@@ -447,9 +458,11 @@ Limit searches to BOUND. The return value is like (\"\\macro\" . (point))."

(defun texmathp-match-switch (bound)

"Search backward for any of the math switches.

Limit searched to BOUND."

- ;; The return value is like ("\\(" . (point)).

+ ;; The return value is like ("\\(" . (point)) only if "\\(" isn't

+ ;; escaped (bug#81327):

(save-excursion

- (if (re-search-backward texmathp-onoff-regexp bound t)

+ (if (and (re-search-backward texmathp-onoff-regexp bound t)

+ (not (texmathp--escaped-p)))

(cons (buffer-substring-no-properties (match-beginning 1) (match-end 1))

(match-beginning 1))

nil)))