[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: indentation problem II
From: |
Arash Esbati |
Subject: |
Re: indentation problem II |
Date: |
Thu, 21 Apr 2022 10:37:57 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 |
Hi Keita,
Ikumi Keita <ikumi@ikumi.que.jp> writes:
>>>>>> Uwe Brauer <oub@mat.ucm.es> writes:
>> That seems to me also a strange result.
>
> It seems to me an ordinary result in array environment, "&" signs are
> vertically aligned. What other result do you expect?
>
>> \begin{equation}\label{Mn}
>> \begin{array}{rcl}
>> \lim_{n\rightarrow\infty} M^n &=& \lim_{n\rightarrow\infty} PJ^nP^{-1} \\
>> \\
>> &=&
>> \begin{pmatrix}
>> 1 & 1 \\
>> 0 & \tfrac{999}{10} \\
>> \end{pmatrix}
>> \begin{pmatrix}
>> e^{-100t} & 0 \\
>> 0 & e^{-\tfrac{t}{10}} \\
>> \end{pmatrix}
>> \begin{pmatrix}
>> 1 & -\tfrac{10}{999} \\
>> 0 & \tfrac{10}{999} \\
>> \end{pmatrix} \\
>> \\
>> &=&
>> \begin{pmatrix}
>> e^{-100t} &
>> \tfrac{10}{999}(e^{-\tfrac{t}{10}} - e^{-100t}) \\
>> 0 & e^{-\tfrac{t}{10}} \\
>> \end{pmatrix}
>> \end{array}
>> \end{equation}
>> \end{document}
Hitting 'M-RET' in a pmatrix inserts only the line break \\ and not any
ampersands. I don't use these environments so I have no experience
about what is convenient, but what do think about this change? Is it an
improvement?
--8<---------------cut here---------------start------------->8---
diff --git a/style/amsmath.el b/style/amsmath.el
index 5e7812e7..8f1eb030 100644
--- a/style/amsmath.el
+++ b/style/amsmath.el
@@ -57,7 +57,13 @@
"align*" "gather*" "flalign*" "multline*" "equation*"
"split"
"cases"
- "matrix" "smallmatrix" "pmatrix" "bmatrix" "Bmatrix" "vmatrix" "Vmatrix"
+ '("matrix" LaTeX-amsmath-env-matrix)
+ '("smallmatrix" LaTeX-amsmath-env-matrix)
+ '("pmatrix" LaTeX-amsmath-env-matrix)
+ '("bmatrix" LaTeX-amsmath-env-matrix)
+ '("Bmatrix" LaTeX-amsmath-env-matrix)
+ '("vmatrix" LaTeX-amsmath-env-matrix)
+ '("Vmatrix" LaTeX-amsmath-env-matrix)
"subequations"
'("subarray" "Alignment"))
@@ -126,13 +132,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))
@@ -246,6 +252,41 @@ START and END."
(let ((num (string-to-number (buffer-substring-no-properties start end))))
(if (integerp num) (+ num num -1))))
+(defun LaTeX-amsmath-env-matrix (env)
+ "Insert matrix ENV with one ampersand."
+ (LaTeX-insert-environment env)
+ (LaTeX-item-equation-matrix t))
+
+(defun LaTeX-item-equation-matrix (&optional suppress)
+ "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.
+
+If SUPRESS is non-nil, do not insert a line break and only one
+single ampersand. "
+ (if suppress
+ (save-excursion (insert "&"))
+ (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 n
+ (save-excursion
+ (insert (make-string n ?&)))))))
+
(defvar LaTeX-amsmath-package-options '("intlimits" "nointlimits"
"sumlimits" "nosumlimits"
"namelimits" "nonamelimits"
--8<---------------cut here---------------end--------------->8---
Best, Arash
- indentation problem II, Uwe Brauer, 2022/04/15
- Re: indentation problem II, Ikumi Keita, 2022/04/19
- Re: indentation problem II, Uwe Brauer, 2022/04/21
- [Culprit found prettify-symbols-mode] (was: indentation problem II), Uwe Brauer, 2022/04/21
- Re: indentation problem II,
Arash Esbati <=
- Re: indentation problem II, Ikumi Keita, 2022/04/21
- Re: indentation problem II, Uwe Brauer, 2022/04/21
- Re: indentation problem II, Arash Esbati, 2022/04/21
- Re: indentation problem II, Uwe Brauer, 2022/04/21
- Re: indentation problem II, Uwe Brauer, 2022/04/21
- Re: indentation problem II, Arash Esbati, 2022/04/22
- Re: indentation problem II, Ikumi Keita, 2022/04/22
- Re: indentation problem II, Arash Esbati, 2022/04/22
- Re: indentation problem II, Ikumi Keita, 2022/04/22