Re: indentation problem II
> Arash Esbati writes: >>> +(defun LaTeX-item-equation-matrix () >> >> Maybe the function name should be reconsidered since it has little >> to do with equation. > I admit that amsmath.el is not really consistent about name-space. > Other functions in that style also go with '-equation-'. We could clean > up, sometimes :-] Most use cases of `LaTeX-item-equation' are for extended environments based on equation environment, e.g. align and gather, so I think it's reasonable to have name with "equation". On the contrary, matrix type environments are not for writing equations. >> P.S. Oops, it's too late. You already have installed the commit in the >> git repo. > Thanks for your comments. Do you think we should touch the style with > any of the above? They aren't so important, so it wouldn't be worth changing now :-) Regards, Ikumi Keita #StandWithUkraine #StopWarInUkraine
Re: indentation problem II
Hi Keita, Ikumi Keita writes: >> Arash Esbati writes: >> diff --git a/style/amsmath.el b/style/amsmath.el >> index 5e7812e7..f72f8be8 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")) > > This part can be omitted. I only did that to reduce the line width which was about 80 or so. >> +(defun LaTeX-item-equation-matrix () > > Maybe the function name should be reconsidered since it has little > to do with equation. I admit that amsmath.el is not really consistent about name-space. Other functions in that style also go with '-equation-'. We could clean up, sometimes :-] >> +(insert (make-string n ?&)) > > Maybe > (insert-char ?& n) > is better. (Sorry, I wasn't aware of this usage of `insert-char' when I > wrote the similar code for `LaTeX-insert-ampersands'.) Thanks for the hint -- I wasn't aware of it as well. > P.S. Oops, it's too late. You already have installed the commit in the > git repo. Thanks for your comments. Do you think we should touch the style with any of the above? Best, Arash
Re: indentation problem II
Hi Arash, > Arash Esbati writes: > Thanks for your responses. Indeed, there is a big chance that inserting > a single & doesn't match the user expectation. This makes the change > even smaller: > diff --git a/style/amsmath.el b/style/amsmath.el > index 5e7812e7..f72f8be8 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")) This part can be omitted. > +(defun LaTeX-item-equation-matrix () Maybe the function name should be reconsidered since it has little to do with equation. > +(insert (make-string n ?&)) Maybe (insert-char ?& n) is better. (Sorry, I wasn't aware of this usage of `insert-char' when I wrote the similar code for `LaTeX-insert-ampersands'.) Regards, Ikumi Keita #StandWithUkraine #StopWarInUkraine P.S. Oops, it's too late. You already have installed the commit in the git repo.
Re: indentation problem II
Uwe Brauer writes: > I tested your code, nice, some observations Thanks for testing. > Gives this > \begin{equation} > \label{eq:testams:1} > \begin{pmatrix} > 1 & 8 \\ > & > \end{pmatrix} > \end{equation} > > Could the & be aligned? I'm not sure it makes sense to align those & since the alignment will be lost as soon as you type a character. > Now > \begin{equation} > \label{eq:testams:1} > \begin{pmatrix} > 1 & 8\\ >^cursor is there M-RE > \end{pmatrix} > \end{equation} > > space > \begin{equation} > \label{eq:testams:1} > \begin{pmatrix} > 1 & 8 \\ \\ > & > \end{pmatrix} > \end{equation} > > This is of course not good. Not sure what to say. I think the best choice is to avoid consecutive \\ and add additional vertical space in the optional argument of \\, e.g. \\[1\baselineskip] or so. > BTW the mini buffer comment space, might be a bit confusing because if > you use the space key you obtain [ ] > > Which is clearly not what you want 😉 What do you mean by comment space? I'm aware of SPACE providing completion in the minibuffer (like TAB or ?). The issue is that "\\" is defined like this in latex.el: '("\\" [ "Space" ]) '("\\*" [ "Space" ]) where it doesn't provide any completion but reads a string. Maybe we should change this to: '("\\" [TeX-arg-length "Space"]) '("\\*" [TeX-arg-length "Space"]) > But anyhow it is quite useful thanks Thanks, I will install it. Best, Arash
Re: indentation problem II
Hi I tested your code, nice, some observations \documentclass[12pt]{article} \usepackage{amssymb,amsfonts,amsmath,amsthm} \begin{document} Test starting equation \begin{equation} \label{eq:testams:1} \begin{pmatrix} 1 & 8 ^cursor is there M-RET \end{pmatrix} \end{equation} Gives this \begin{equation} \label{eq:testams:1} \begin{pmatrix} 1 & 8 \\ & \end{pmatrix} \end{equation} Could the & be aligned? Now \begin{equation} \label{eq:testams:1} \begin{pmatrix} 1 & 8\\ ^cursor is there M-RE \end{pmatrix} \end{equation} space \begin{equation} \label{eq:testams:1} \begin{pmatrix} 1 & 8 \\ \\ & \end{pmatrix} \end{equation} This is of course not good. Not sure what to say. BTW the mini buffer comment space, might be a bit confusing because if you use the space key you obtain [ ] Which is clearly not what you want 😉 \end{document} But anyhow it is quite useful thanks -- I strongly condemn Putin's war of aggression against the Ukraine. I support to deliver weapons to Ukraine's military. I support the ban of Russia from SWIFT. I support the EU membership of the Ukraine. smime.p7s Description: S/MIME cryptographic signature
Re: indentation problem II
> Uwe Brauer writes: > Thanks for your responses. Indeed, there is a big chance that inserting > a single & doesn't match the user expectation. This makes the change > even smaller: > diff --git a/style/amsmath.el b/style/amsmath.el > index 5e7812e7..f72f8be8 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 > Can you please elaborate what sounds complicated? The implementation, but looking at your code I see (setq n (how-many "[^\\]&" s e))) I could not imagine that such a function exists. so sounds complicated should be read as: Uwe's elisp knowledge is too small for such a task. 🙃 Uwe smime.p7s Description: S/MIME cryptographic signature
Re: indentation problem II
Uwe Brauer writes: "IK" == Ikumi Keita writes: > >> Hmm, it would basically be useful, but I think automatic insertion of >> ampersands at the first line should be suppressed because matrix-like >> environments are used when writing column-vector like >> \begin{pmatrix} >> 1 \\ >> 2 \\ >> 3 >> \end{pmatrix} >> , without "&". > > Right, the problem is, you can also have matrix like structures and > pmatrix does not take arguments, while array does. > > So there is no way of knowing whether a matrix or a single column vector > will be generated. > > Best course would be > > 1. You insert the first row which might be >1 & 4 & > > 2. And then M-ret, based on an analysis of that line inserts the >needed number of &, Thanks for your responses. Indeed, there is a big chance that inserting a single & doesn't match the user expectation. This makes the change even smaller: --8<---cut here---start->8--- diff --git a/style/amsmath.el b/style/amsmath.el index 5e7812e7..f72f8be8 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 --8<---cut here---end--->8--- > But that sounds quite complicated. Can you please elaborate what sounds complicated? Best, Arash
Re: indentation problem II
>>> "IK" == Ikumi Keita writes: > Hi Arash, >> Arash Esbati writes: >> 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? > Hmm, it would basically be useful, but I think automatic insertion of > ampersands at the first line should be suppressed because matrix-like > environments are used when writing column-vector like > \begin{pmatrix} > 1 \\ > 2 \\ > 3 > \end{pmatrix} > , without "&". Right, the problem is, you can also have matrix like structures and pmatrix does not take arguments, while array does. So there is no way of knowing whether a matrix or a single column vector will be generated. Best course would be 1. You insert the first row which might be 1 & 4 & 2. And then M-ret, based on an analysis of that line inserts the needed number of &, But that sounds quite complicated. Uwe smime.p7s Description: S/MIME cryptographic signature
Re: indentation problem II
Hi Arash, > Arash Esbati writes: > 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? Hmm, it would basically be useful, but I think automatic insertion of ampersands at the first line should be suppressed because matrix-like environments are used when writing column-vector like \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix} , without "&". Regards, Ikumi Keita #StandWithUkraine #StopWarInUkraine
Re: indentation problem II
Hi Keita, Ikumi Keita writes: >> Uwe Brauer 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"
Re: indentation problem II
>>> "IK" == Ikumi Keita writes: Hi Keita, > Hi Uwe, >> Uwe Brauer 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? I expect this #+begin_src \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_src smime.p7s Description: S/MIME cryptographic signature
Re: indentation problem II
Hi Uwe, > Uwe Brauer 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} Regards, Ikumi Keita #StandWithUkraine #StopWarInUkraine