diff --git a/texmathp.el b/texmathp.el index f13e237..6280231 100644 --- a/texmathp.el +++ b/texmathp.el @@ -172,7 +172,7 @@ customize (customize calls it when setting the variable)." (mapconcat 'regexp-quote switches "\\|") "\\)") texmathp-toggle-regexp - (concat "\\([^\\\\\\$]\\|\\`\\)\\(" + (concat "\\([^$]\\|\\`\\)\\(" (mapconcat 'regexp-quote togglers "\\|") "\\)")))) @@ -285,7 +285,10 @@ See the variable `texmathp-tex-commands' about which commands are checked." (if (not math-on) (save-excursion (goto-char (cdr match)) - (while (re-search-forward texmathp-toggle-regexp pos t) + (while (and (re-search-forward texmathp-toggle-regexp pos t) + ;; Check if the toggle is un-escaped. Use the same test + ;; of `TeX-escaped-p'. + (save-excursion (zerop (mod (skip-chars-backward "\\\\") 2)))) (if (setq math-on (not math-on)) (setq sw-match (cons (match-string 2) (match-beginning 2))) (setq sw-match nil)))