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

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

[elpa] externals/auctex 9ede1fa203 03/77: Improve insertion of & in matr


From: Tassilo Horn
Subject: [elpa] externals/auctex 9ede1fa203 03/77: Improve insertion of & in matrix-like environments
Date: Fri, 26 Aug 2022 16:06:31 -0400 (EDT)

branch: externals/auctex
commit 9ede1fa203a898886b7d3f90fe2e56394b710c45
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>

    Improve insertion of & in matrix-like environments
    
    * style/amsmath.el (LaTeX-item-equation-matrix): New function.
    ("amsmath"): Use the function for matrix-like environments in
    `LaTeX-item-list'.
---
 style/amsmath.el | 42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/style/amsmath.el b/style/amsmath.el
index 5e7812e7b7..f72f8be8fd 100644
--- a/style/amsmath.el
+++ b/style/amsmath.el
@@ -57,7 +57,8 @@
     "align*" "gather*" "flalign*" "multline*" "equation*"
     "split"
     "cases"
-    "matrix" "smallmatrix" "pmatrix" "bmatrix" "Bmatrix" "vmatrix" "Vmatrix"
+    "matrix" "smallmatrix"
+    "bmatrix" "Bmatrix" "pmatrix" "vmatrix" "Vmatrix"
     "subequations"
     '("subarray" "Alignment"))
 
@@ -126,13 +127,13 @@
                    ("alignedat" . LaTeX-item-equation-alignat)
                    ("flalign"  . LaTeX-item-equation)
                    ("flalign*" . LaTeX-item-equation)
-                   ("matrix" .  LaTeX-item-equation)
-                   ("pmatrix" .  LaTeX-item-equation)
-                   ("bmatrix" .  LaTeX-item-equation)
-                   ("Bmatrix" .  LaTeX-item-equation)
-                   ("vmatrix" .  LaTeX-item-equation)
-                   ("Vmatrix" .  LaTeX-item-equation)
-                   ("smallmatrix" . LaTeX-item-equation)
+                   ("matrix" .  LaTeX-item-equation-matrix)
+                   ("pmatrix" .  LaTeX-item-equation-matrix)
+                   ("bmatrix" .  LaTeX-item-equation-matrix)
+                   ("Bmatrix" .  LaTeX-item-equation-matrix)
+                   ("vmatrix" .  LaTeX-item-equation-matrix)
+                   ("Vmatrix" .  LaTeX-item-equation-matrix)
+                   ("smallmatrix" . LaTeX-item-equation-matrix)
                    ("subarray" . LaTeX-item-equation)
                    ("cases"    . LaTeX-item-equation))
                  LaTeX-item-list))
@@ -225,6 +226,31 @@ If SUPPRESS is non-nil, do not insert line break macro."
       (LaTeX-newline)
       (indent-according-to-mode))))
 
+(defun LaTeX-item-equation-matrix ()
+  "Insert contents to terminate a line in matrix environments.
+Put line break macro on the last line and insert suitable number
+of ampersands if possible.  This number is extracted from the
+first line of the environment."
+  (end-of-line 0)
+  (just-one-space)
+  (TeX-insert-macro "\\")
+  (forward-line 1)
+  (indent-according-to-mode)
+  (let* ((p (point))
+         (s (save-excursion
+              (LaTeX-find-matching-begin)
+              (point)))
+         (e (save-excursion
+              (goto-char s)
+              (search-forward "\\\\" p t)))
+         n)
+    (save-excursion
+      (goto-char s)
+      (setq n (how-many "[^\\]&" s e)))
+    (when (and n (> n 0))
+      (save-excursion
+        (insert (make-string n ?&))))))
+
 (defun LaTeX-item-equation-alignat (&optional suppress)
   "Insert contents to terminate a line in multi-line equations environment.
 Put line break macro on the last line.  Next, if the current



reply via email to

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