emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/auctex 42150568f1 06/48: Allow user to insert "$" (bug#


From: Tassilo Horn
Subject: [elpa] externals/auctex 42150568f1 06/48: Allow user to insert "$" (bug#57626)
Date: Fri, 18 Nov 2022 14:27:42 -0500 (EST)

branch: externals/auctex
commit 42150568f1d8ef9a556ecdc3f107e7f4cb02e7a9
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>

    Allow user to insert "$" (bug#57626)
    
    * tex.el (TeX-insert-dollar): Let user to insert "$" when `texmathp'
    thinks that the math mode didn't start with dollar, considering it
    isn't actually in math mode.
    Fix doc string along with the above change.
    * texmathp.el: Add cases* env issue in BUGS section of header
    comments.
---
 tex.el      | 92 +++++++++++++++++++++++++++++++------------------------------
 texmathp.el | 17 ++++++++----
 2 files changed, 58 insertions(+), 51 deletions(-)

diff --git a/tex.el b/tex.el
index a52bf3cbf3..9a57d45895 100644
--- a/tex.el
+++ b/tex.el
@@ -5942,9 +5942,8 @@ point.  You can choose between \"$...$\" and 
\"\\(...\\)\"."
 (defun TeX-insert-dollar (&optional arg)
   "Insert dollar sign.
 
-If current math mode was not entered with a dollar, refuse to
-insert one.  Show matching dollar sign if this dollar sign ends
-the TeX math mode and `blink-matching-paren' is non-nil.
+Show matching dollar sign if this dollar sign ends the TeX math
+mode and `blink-matching-paren' is non-nil.
 
 When outside math mode, the behavior is controlled by the variable
 `TeX-electric-math'.
@@ -5996,51 +5995,54 @@ With optional ARG, insert that many dollar signs."
                      (buffer-substring
                       (point) (progn (end-of-line) (point))))))))
      (t
-      ;; Math mode was not entered with dollar - we cannot finish it
-      ;; with one.
-      (message "Math mode started with `%s' cannot be closed with dollar"
-               (car texmathp-why)))))
+      ;; Math mode was not entered with dollar - we assume that
+      ;; `texmathp' was wrong and behave as if not in math
+      ;; mode. (bug#57626)
+      (TeX--insert-dollar-1))))
    (t
     ;; Just somewhere in the text.
+    (TeX--insert-dollar-1))))
+
+(defun TeX--insert-dollar-1 ()
+  "Do the job of `TeX-insert-dollar' in non-math mode."
+  (cond
+   ((and TeX-electric-math (TeX-active-mark)
+         (/= (point) (mark)))
+    (if (> (point) (mark))
+        (exchange-point-and-mark))
     (cond
-     ((and TeX-electric-math (TeX-active-mark)
-           (/= (point) (mark)))
-      (if (> (point) (mark))
-          (exchange-point-and-mark))
-      (cond
-       ;; $...$ to $$...$$
-       ((and (eq last-command #'TeX-insert-dollar)
-             (re-search-forward "\\=\\$\\([^$][^z-a]*[^$]\\)\\$" (mark) t))
-        (replace-match "$$\\1$$" t)
-        (set-mark (match-beginning 0)))
-       ;; \(...\) to \[...\]
-       ((and (eq last-command #'TeX-insert-dollar)
-             (re-search-forward "\\=\\\\(\\([^z-a]*\\)\\\\)" (mark) t))
-        (replace-match "\\\\[\\1\\\\]" t)
-        (set-mark (match-beginning 0)))
-       ;; Strip \[...\] or $$...$$
-       ((and (eq last-command #'TeX-insert-dollar)
-             (or (re-search-forward "\\=\\\\\\[\\([^z-a]*\\)\\\\\\]" (mark) t)
-                 (re-search-forward "\\=\\$\\$\\([^z-a]*\\)\\$\\$" (mark) t)))
-        (replace-match "\\1" t)
-        (set-mark (match-beginning 0)))
-       (t
-        ;; We use `save-excursion' because point must be situated
-        ;; before opening symbol.
-        (save-excursion (insert (car TeX-electric-math)))
-        (exchange-point-and-mark)
-        (insert (cdr TeX-electric-math))))
-      ;; Keep the region active.
-      (TeX-activate-region))
-     (TeX-electric-math
-      (insert (car TeX-electric-math))
-      (save-excursion (insert (cdr TeX-electric-math)))
-      (if blink-matching-paren
-          (save-excursion
-            (backward-char)
-            (sit-for blink-matching-delay))))
-     ;; In any other case just insert a single $.
-     ((insert "$")))))
+     ;; $...$ to $$...$$
+     ((and (eq last-command #'TeX-insert-dollar)
+           (re-search-forward "\\=\\$\\([^$][^z-a]*[^$]\\)\\$" (mark) t))
+      (replace-match "$$\\1$$" t)
+      (set-mark (match-beginning 0)))
+     ;; \(...\) to \[...\]
+     ((and (eq last-command #'TeX-insert-dollar)
+           (re-search-forward "\\=\\\\(\\([^z-a]*\\)\\\\)" (mark) t))
+      (replace-match "\\\\[\\1\\\\]" t)
+      (set-mark (match-beginning 0)))
+     ;; Strip \[...\] or $$...$$
+     ((and (eq last-command #'TeX-insert-dollar)
+           (or (re-search-forward "\\=\\\\\\[\\([^z-a]*\\)\\\\\\]" (mark) t)
+               (re-search-forward "\\=\\$\\$\\([^z-a]*\\)\\$\\$" (mark) t)))
+      (replace-match "\\1" t)
+      (set-mark (match-beginning 0)))
+     (t
+      ;; We use `save-excursion' because point must be situated
+      ;; before opening symbol.
+      (save-excursion (insert (car TeX-electric-math)))
+      (exchange-point-and-mark)
+      (insert (cdr TeX-electric-math))))
+    (TeX-activate-region))
+   (TeX-electric-math
+    (insert (car TeX-electric-math))
+    (save-excursion (insert (cdr TeX-electric-math)))
+    (if blink-matching-paren
+        (save-excursion
+          (backward-char)
+          (sit-for blink-matching-delay))))
+   ;; In any other case just insert a single $.
+   ((insert "$")))
   (TeX-math-input-method-off))
 
 (defcustom TeX-math-input-method-off-regexp
diff --git a/texmathp.el b/texmathp.el
index f02824cec1..ad0089863a 100644
--- a/texmathp.el
+++ b/texmathp.el
@@ -1,6 +1,6 @@
 ;;; texmathp.el -- Code to check if point is inside LaTeX math environment  
-*- lexical-binding: t; -*-
 
-;; Copyright (C) 1998-2021  Free Software Foundation, Inc.
+;; Copyright (C) 1998-2022  Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
 ;; Maintainer: auctex-devel@gnu.org
@@ -85,14 +85,19 @@
 ;;
 ;;  BUGS:
 ;;
-;;  If any of the the special macros like \mbox or \ensuremath has optional
-;;  arguments, math mode inside these optional arguments is *not* influenced
-;;  by the macro.
+;;  o If any of the the special macros like \mbox or \ensuremath has
+;;    optional arguments, math mode inside these optional arguments is
+;;    *not* influenced by the macro.
 ;;
-;;  Nested \(\) and \[\] can confuse texmathp.  It returns nil at AAA
-;;  in the following examples:
+;;  o Nested \(\) and \[\] can confuse texmathp.  It returns nil at AAA
+;;    in the following examples:
 ;;  \[ x=y \mbox{abc \(\alpha\) cba} AAA \]
 ;;  \[ x=y \begin{minipage}{3cm} abc \[\alpha\] cba \end{minipage} AAA \]
+;;
+;;  o In the "text column" of cases* environment, texmathp doesn't
+;;    consider it's non-math mode.  The same applies for variants of
+;;    cases* environents, both provided by mathtools package.
+;;
 ;;--------------------------------------------------------------------------
 
 ;;; Code:



reply via email to

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