Hi Keita,

Ikumi Keita <[email protected]> writes:

>>>>>> Arash Esbati <[email protected]> writes:
>>>>> texmathp-toggle-regexp
>>>>> ;; Next line changed:
>>>>> ;; (concat "\\([^\\$]\\|\\`\\)"
>>>>> (concat "\\(\\`\\|\\)"
>
>> so I really didn't touch that regexp (I was in a hurry anyways).
>
> Hmm, I'm not sure whether I understand. Do you mean that the regexp
> "\\(\\`\\|\\)" was proposed by Gabriele? But as far as I can see, this
> regexp first appeared in your message
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=81327#14
> in this thread, so I thought you invented it.

Sorry for the confusion.  I meant: I just touched the functions enough
to show you my idea and let Gabriele test it.  It was far away from a
change set.

> Anyway, I agree the basic idea to use `TeX-escaped-p'. I expect it would
> work without much overhead.

Yes, that is also my thinking.  I had yet another look and my first
approach would be something like this:

--8<---------------cut here---------------start------------->8---
diff --git a/texmathp.el b/texmathp.el
index 7dd443a0..8b42de0d 100644
--- a/texmathp.el
+++ b/texmathp.el
@@ -196,7 +196,9 @@ customize (customize calls it when setting the variable)."
           (concat "\\(?:[^\\]\\|\\`\\)"
                   (regexp-opt switches t))
           texmathp-toggle-regexp
-          (concat "\\([^\\$]\\|\\`\\)"
+          (concat (unless (and (derived-mode-p 'TeX-mode)
+                               (fboundp 'TeX-escaped-p))
+                    "\\([^\\$]\\|\\`\\)")
                   (regexp-opt togglers t)))))

 (defcustom texmathp-tex-commands nil
@@ -312,9 +314,19 @@ 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 if the library is used stand-alone or with tex.el
+            ;; provided by AUCTeX:
+            (if (and (derived-mode-p 'TeX-mode)
+                     (fboundp 'TeX-escaped-p))
+                (unless (TeX-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)))
+              (if (setq math-on (not math-on))
+                  (setq sw-match (cons (match-string-no-properties 2)
+                                       (match-beginning 2)))
+                (setq sw-match nil))))
           (and math-on sw-match (setq match sw-match))))

     ;; Store info, show as message when interactive, and return
--8<---------------cut here---------------end--------------->8---

The nasty part is that this approach doesn't solve the issue for people
using the library stand-alone, i.e., without AUCTeX.  So I think we
should copy `TeX-escaped-p' into texmathp.el as in internal function and
use that.  We can address also the issues Gabriele mentioned in his
other mail:

• texmathp-onoff-regexp' carries the same defective prefix: We will take
  care of that during the next iteration.

• (TeX-escaped-p (1- (point)))' examines the last character of the
  match: This is already addressed above, I hope.

Best, Arash



_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex
  • bug#81... Gabriele Nicolardi via bug-auctex via Bug reporting list for AUCTeX
    • b... Ikumi Keita
      • ... Gabriele Nicolardi via bug-auctex via Bug reporting list for AUCTeX
        • ... Arash Esbati
          • ... Arash Esbati
            • ... Ikumi Keita
              • ... Arash Esbati
                • ... Ikumi Keita
                • ... Gabriele Nicolardi via bug-auctex via Bug reporting list for AUCTeX
                • ... Arash Esbati
                • ... Ikumi Keita
                • ... Arash Esbati
                • ... Arash Esbati

Reply via email to