Hi Ralf, 2014/1/11 Ralf Angeli <ang...@caeruleus.net>: > * Mosč Giordano (2014-01-11) writes: > >> thanks for your report. The problem is in the `texmathp' function, >> and in particular in the regexp used for searching math togglers, ie >> `texmathp-toggle-regexp'. Its value is >> "\\([^\\\\\\$]\\|\\`\\)\\(\\$\\$\\|\\$\\)", but this doesn't match a >> dollar preceded by two escapes. >> "\\(\\\\\\\\\\|[^\\\\\\$]\\|\\`\\)\\(\\$\\$\\|\\$\\)" should do the >> trick, but I'd like a confirmation by someone more experienced in >> regexps than me. Actually we should make sure there is an even number >> of escapes, not just two, then perhaps something like `TeX-escaped-p' >> might be needed. > > IIRC we used something like "[^\\]\\(\\\\\\\\\\)*" to check if something > is unescaped before we had `TeX-escaped-p'. Let's assume the logic for > the regexp is the following: > > match a pair of dollar signs or a single dollar sign under the condition > that a) in front of it there is no dollar sign or escape or b) if there > is a dollar sign in front if it, it is preceded by an odd number of > escapes or c) if there is an escape in front of it, it has to be > preceded by an odd number of escapes, so that there is an even number of > escapes in a row or d) the dollar sign(s) occur(s) at the start of the > buffer > > In that case the regexp could look like this: > > "\\([^\\$]\\|[^\\]\\(\\\\\\\\\\)*\\\\\\$\\|[^\\]\\(\\\\\\\\\\)+\\|\\`\\)\\(\\$\\$\\|\\$\\)" >
Thanks for your suggestions! Unfortunately, this regexp doesn't match the opening dollar in \\$something$ > Note: I think that the "[^\\\\\\$]" in the original regexp has too many > escapes. "[^\\$]" should suffice because you don't need to escape the > characters in a character alternative. > I think you're right, `re-builder' confirms your idea. > The regexp would become rather complicated, so it might be worth to > check if using `TeX-escaped-p' is the nicer alternative. Or somebody > has an idea how to simplify the regexp. > The attached patch uses the same logic of `TeX-escaped-p', but fails to recognize the math mode in \$$something$ because finds `$$' preceded by an escape. All in all, a single well conceived regexp probably is better. Bye, Mosè
diff --git a/texmathp.el b/texmathp.el index 350406b..d449f5f 100644 --- a/texmathp.el +++ b/texmathp.el @@ -171,7 +171,7 @@ customize (customize calls it when setting the variable)." (mapconcat 'regexp-quote switches "\\|") "\\)") texmathp-toggle-regexp - (concat "\\([^\\\\\\$]\\|\\`\\)\\(" + (concat "\\(" (mapconcat 'regexp-quote togglers "\\|") "\\)")))) @@ -285,9 +285,13 @@ 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 2) (match-beginning 2))) - (setq sw-match nil))) + ;; Make sure the togglers are unescaped. + (if (save-excursion + (goto-char (match-beginning 0)) + (zerop (mod (skip-chars-backward "\\\\") 2))) + (if (setq math-on (not math-on)) + (setq sw-match (cons (match-string 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
_______________________________________________ bug-auctex mailing list bug-auctex@gnu.org https://lists.gnu.org/mailman/listinfo/bug-auctex