auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX] One bug of "forcing a dollar"


From: Ralf Angeli
Subject: Re: [AUCTeX] One bug of "forcing a dollar"
Date: Mon, 19 Sep 2005 14:53:08 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

* Adam Johnson (2005-09-18) writes:

> I have the following code,
>
> -------------------------------------
> \begin{align}
>   ax+b \\
> %\end{align*}
> %\begin{align*}
>   c+d
> \end{align}
>
> abc $
> -------------------------------------
>
> I cannot input the last "$".  Emacs prompts for a "forcing dollar".  It's 
> seemed that the commented line
>         %\begin{align*}
> still can be recognized.

Thanks for the report.  Here is a patch for texmathp.el which
makes math environment recognition aware of comments:

--8<---------------cut here---------------start------------->8---
--- texmathp.el 17 Sep 2005 11:59:54 +0200      5.15
+++ texmathp.el 19 Sep 2005 14:41:42 +0200      
@@ -316,17 +316,29 @@
   (catch 'exit
     (save-excursion
       (and (null texmathp-environments) (throw 'exit nil))
-      (let (end-list env)
+      (let ((orig-comment-flag (progn (save-excursion
+                                       (beginning-of-line)
+                                       (skip-chars-forward " \t")
+                                       (looking-at comment-start))))
+           end-list env)
        (while (re-search-backward "\\\\\\(begin\\|end\\)[ \t]*{\\([^}]+\\)}"
                                   bound t)
-         (setq env (buffer-substring-no-properties
-                    (match-beginning 2) (match-end 2)))
-         (cond ((string= (match-string 1) "end")
-                (setq end-list (cons env end-list)))
-               ((equal env (car end-list))
-                (setq end-list (cdr end-list)))
-               ((member env texmathp-environments)
-                (throw 'exit (cons env (point))))))
+         (let ((current-comment-flag
+                (when (save-match-data
+                        (re-search-backward comment-start-skip
+                                            (line-beginning-position) t))
+                  ;; We need a t for comparison with `orig-comment-flag',
+                  ;; not a number.
+                  t)))
+           (when (eq orig-comment-flag current-comment-flag)
+             (setq env (buffer-substring-no-properties
+                        (match-beginning 2) (match-end 2)))
+             (cond ((string= (match-string 1) "end")
+                    (setq end-list (cons env end-list)))
+                   ((equal env (car end-list))
+                    (setq end-list (cdr end-list)))
+                   ((member env texmathp-environments)
+                    (throw 'exit (cons env (point))))))))
        nil))))
 
 (defun texmathp-match-macro (bound)
--8<---------------cut here---------------end--------------->8---

It would be a little bit nicer if we could use `TeX-in-commented-line'
and `TeX-in-comment' but this would make texmathp.el dependent on
tex.el.  Is texmathp.el still supposed to be self-contained?

Anyway, the patch will have to wait till AUCTeX 11.80 is released.

-- 
Ralf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]