GNU bug report logs - #65648
13.2; indentation of nested environments

Previous Next

Package: auctex;

Reported by: Paul Nelson <ultrono <at> gmail.com>

Date: Thu, 31 Aug 2023 04:57:01 UTC

Severity: normal

Found in version 13.2

Done: Ikumi Keita <ikumi <at> ikumi.que.jp>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 65648 in the body.
You can then email your comments to 65648 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Thu, 31 Aug 2023 04:57:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Nelson <ultrono <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Thu, 31 Aug 2023 04:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: bug-auctex <at> gnu.org
Subject: 13.2; indentation of nested environments
Date: Thu, 31 Aug 2023 06:55:39 +0200
Take a LaTeX buffer with a nested environment where the inner \begin{}
follows some non-whitespace:

#+begin_src latex
\begin{equation*}
  g=\begin{pmatrix}
    a & b \\
    c & d \\
  \end{pmatrix}
\end{equation*}
#+end_src

After =M-x mark-whole-buffer= and =M-x indent-region=, the outer
\end{} is indented too much:

#+begin_src latex
\begin{equation*}
  x=\begin{pmatrix}
      a & b \\
      c & d \\
    \end{pmatrix}
  \end{equation*}
#+end_src

The issue is that indentation for the outer \end{} is anchored to that
for the inner \end{}, which is calculated relative to the position of
the inner \begin{}.  It should instead be calculated relative to the
beginning of the line (excluding whitespace) on which the inner
\begin{} occurs (the "x=" in this example).

A practical workaround for the user is to make sure that \begin{} is
always the first non-whitespace on its line (and to enforce that
requirement on coauthors via ~(defun fix-tex-buffer ...)~), but that
seems suboptimal.

The following seems to resolve the issue:

#+begin_src example
diff --git a/latex.el b/latex.el
index d855b5c..9648714 100644
--- a/latex.el
+++ b/latex.el
@@ -8922,9 +8922,13 @@ COL for efficiency."

 (defun LaTeX-indent-tabular ()
   "Return indent column for the current tabular-like line."
-  (cl-destructuring-bind
-      (beg-pos . beg-col)
-      (LaTeX-env-beginning-pos-col)
+  (let (beg-pos beg-col bol-col)
+    (save-excursion
+      (LaTeX-find-matching-begin)
+      (setq beg-pos (point))
+      (setq beg-col (current-column))
+      (LaTeX-back-to-indentation)
+      (setq bol-col (current-column)))
     (let ((tabular-like-end-regex
            (format "\\\\end{%s}"
                    (regexp-opt
@@ -8935,7 +8939,7 @@ COL for efficiency."
                             LaTeX-indent-environment-list)
                       out)))))
       (cond ((looking-at tabular-like-end-regex)
-             beg-col)
+             bol-col)

             ((looking-at "\\\\\\\\")
              (+ 2 beg-col))
#+end_src

Here I've inlined the call to ~LaTeX-env-beginning-pos-col~
(modification seemed inappropriate) and added the computation of
"bol-col", which is then used in place of "beg-col" when indenting the
inner \end{}.


Emacs  : GNU Emacs 30.0.50 (build 2, x86_64-apple-darwin21.6.0, NS
appkit-2113.60 Version 12.6 (Build 21G115))
 of 2023-08-11
Package: 13.2

current state:
==============
(setq
 AUCTeX-date "2023-08-28"
 window-system 'ns
 LaTeX-version "2e"
 TeX-style-path '("/usr/local/var/auctex"
"/Users/paulnelson/.emacs.d/elpaca/builds/auctex/auctex/style"
                  "/Users/paulnelson/.emacs.d/auctex/auto"
"/Users/paulnelson/.emacs.d/auctex/style" "auto" "style")
 TeX-auto-save t
 TeX-parse-self t
 TeX-master t
 TeX-command-list '(("TeX" "%(PDF)%(tex) %(file-line-error)
%`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %t"
                     TeX-run-TeX nil (plain-tex-mode ams-tex-mode
texinfo-mode) :help "Run plain TeX")
                    ("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil
(latex-mode doctex-mode) :help "Run LaTeX")
                    ("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t"
TeX-run-compile nil (texinfo-mode) :help
                     "Run Makeinfo with Info output")
                    ("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir)
--html %t" TeX-run-compile nil (texinfo-mode) :help
                     "Run Makeinfo with HTML output")
                    ("AmSTeX" "amstex %(PDFout) %`%(extraopts)
%S%(mode)%' %(output-dir) %t" TeX-run-TeX nil (ams-tex-mode)
                     :help "Run AMSTeX")
                    ("ConTeXt" "%(cntxcom) --once --texutil
%(extraopts) %(execopts)%t" TeX-run-TeX nil (context-mode)
                     :help "Run ConTeXt once")
                    ("ConTeXt Full" "%(cntxcom) %(extraopts)
%(execopts)%t" TeX-run-TeX nil (context-mode) :help
                     "Run ConTeXt until completion")
                    ("BibTeX" "bibtex %(O?aux)" TeX-run-BibTeX nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode context-mode) :help "Run BibTeX")
                    ("Biber" "biber %(output-dir) %s" TeX-run-Biber nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help "Run Biber")
                    ("Texindex" "texindex %s.??" TeX-run-command nil
(texinfo-mode) :help "Run Texindex")
                    ("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command
nil (texinfo-mode) :help "Run Texi2dvi or Texi2pdf")
                    ("View" "%V" TeX-run-discard-or-function t t :help
"Run Viewer")
                    ("Print" "%p" TeX-run-command t t :help "Print the file")
                    ("Queue" "%q" TeX-run-background nil t :help "View
the printer queue" :visible TeX-queue-command)
                    ("File" "%(o?)dvips %d -o %f " TeX-run-dvips t
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help "Generate PostScript file")
                    ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Convert DVI file to PostScript")
                    ("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Convert DVI file to PDF with dvipdfmx")
                    ("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Convert PostScript file to PDF")
                    ("Glossaries" "makeglossaries %(d-dir) %s"
TeX-run-command nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run makeglossaries to create glossary file")
                    ("Index" "makeindex %(O?idx)" TeX-run-index nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run makeindex to create index file")
                    ("upMendex" "upmendex %(O?idx)" TeX-run-index t
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run upmendex to create index file")
                    ("Xindy" "texindy %s" TeX-run-command nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run xindy to create index file")
                    ("Check" "lacheck %s" TeX-run-compile nil
(latex-mode) :help "Check LaTeX file for correctness")
                    ("ChkTeX" "chktex -v6 %s" TeX-run-compile nil
(latex-mode) :help "Check LaTeX file for common mistakes")
                    ("Spell" "(TeX-ispell-document \"\")"
TeX-run-function nil t :help "Spell-check the document")
                    ("Clean" "TeX-clean" TeX-run-function nil t :help
"Delete generated intermediate files")
                    ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help
                     "Delete generated intermediate and output files")
                    ("Other" "" TeX-run-command t t :help "Run an
arbitrary command"))
 )




Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 08:25:02 GMT) Full text and rfc822 format available.

Message #8 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 03 Sep 2023 17:24:39 +0900
Hi Paul,

>>>>> Paul Nelson <ultrono <at> gmail.com> writes:
> A practical workaround for the user is to make sure that \begin{} is
> always the first non-whitespace on its line (and to enforce that
> requirement on coauthors via ~(defun fix-tex-buffer ...)~), but that
> seems suboptimal.

> The following seems to resolve the issue:

Thanks for your proposal. I think it can be a practical solution for
bug#54949[1] as well.

The proposal gives one failure for regression test, namely the case Uwe
Brauer raised last year[2]. Current AUCTeX indents
----------------------------------------------------------------------
\begin{equation}
  \begin{aligned}
&n u m=\left[\begin{array}{ll}
2 & 25
\end{array}\right] \\
&d e n=\left[\begin{array}{lll}
1 & 4 & 25
\end{array}\right]
\end{aligned}
\end{equation}
----------------------------------------------------------------------
into
----------------------------------------------------------------------
\begin{equation}
  \begin{aligned}
    &n u m=\left[\begin{array}{ll}
                   2 & 25
                 \end{array}\right] \\
    &d e n=\left[\begin{array}{lll}
                   1 & 4 & 25
                 \end{array}\right]
  \end{aligned}
\end{equation}
----------------------------------------------------------------------
while this proposal gives
----------------------------------------------------------------------
\begin{equation}
  \begin{aligned}
    &n u m=\left[\begin{array}{ll}
                   2 & 25
    \end{array}\right] \\
    &d e n=\left[\begin{array}{lll}
                   1 & 4 & 25
    \end{array}\right]
  \end{aligned}
\end{equation}
----------------------------------------------------------------------
, which seems me another reasonable behavior. Uwe, what do you think
about it? Is this result acceptable for you?

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54949
[2] https://lists.gnu.org/r/auctex-devel/2022-01/msg00055.html

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 08:46:02 GMT) Full text and rfc822 format available.

Message #11 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>,
 Paul Nelson <ultrono <at> gmail.com>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 03 Sep 2023 10:44:54 +0200
[Message part 1 (text/plain, inline)]
>>> "IK" == Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> Hi Paul,
>>>>>> Paul Nelson <ultrono <at> gmail.com> writes:
>> A practical workaround for the user is to make sure that \begin{} is
>> always the first non-whitespace on its line (and to enforce that
>> requirement on coauthors via ~(defun fix-tex-buffer ...)~), but that
>> seems suboptimal.

>> The following seems to resolve the issue:

> Thanks for your proposal. I think it can be a practical solution for
> bug#54949[1] as well.

> The proposal gives one failure for regression test, namely the case Uwe
> Brauer raised last year[2]. Current AUCTeX indents
> ----------------------------------------------------------------------
> \begin{equation}
>   \begin{aligned}
> &n u m=\left[\begin{array}{ll}
> 2 & 25
> \end{array}\right] \\
> &d e n=\left[\begin{array}{lll}
> 1 & 4 & 25
> \end{array}\right]
> \end{aligned}
> \end{equation}
> ----------------------------------------------------------------------
> into
> ----------------------------------------------------------------------
> \begin{equation}
>   \begin{aligned}
>     &n u m=\left[\begin{array}{ll}
>                    2 & 25
>                  \end{array}\right] \\
>     &d e n=\left[\begin{array}{lll}
>                    1 & 4 & 25
>                  \end{array}\right]
>   \end{aligned}
> \end{equation}
> ----------------------------------------------------------------------
> while this proposal gives
> ----------------------------------------------------------------------
> \begin{equation}
>   \begin{aligned}
>     &n u m=\left[\begin{array}{ll}
>                    2 & 25
>     \end{array}\right] \\
>     &d e n=\left[\begin{array}{lll}
>                    1 & 4 & 25
>     \end{array}\right]
>   \end{aligned}
> \end{equation}
> ----------------------------------------------------------------------
> , which seems me another reasonable behavior. Uwe, what do you think
> about it? Is this result acceptable for you?

Frankly, rather not. Here is why.
The proposed change would lead to 


\begin{equation}*
  \begin{aligned}**
    &n u m=\left[\begin{array}{ll}***
                   2 & 25
    \end{array}\right] \\
    &d e n=\left[\begin{array}{lll}
                   1 & 4 & 25
    \end{array}\right]
  \end{aligned}
\end{equation}



The first to begin, end on the same column, which is how it should be.

However the last one, starting with \begin{array}
*does not* end on the same column.

So I personally find this proposed behavior inferior. It makes it more
difficult to spot errors.



> [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54949
> [2] https://lists.gnu.org/r/auctex-devel/2022-01/msg00055.html

> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine

-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of the Ukraine.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/
[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 11:32:01 GMT) Full text and rfc822 format available.

Message #14 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: Uwe Brauer <oub <at> mat.ucm.es>
Cc: 65648 <at> debbugs.gnu.org, Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 3 Sep 2023 13:30:52 +0200
Hi Ikumi and Uwe,

Thanks to both of you for your feedback.

I agree that it's better to have begin/end line up when all else is
equal, but with the current state of AUCTeX (since this bug was
introduced), it is a severe user error to put \begin{array} on a line
following non-whitespace.  The reason is the same as in my original
message, or in what one gets from Uwe's example by deleting the inner
aligned environment and applying M-x indent-region:

#+begin_src latex
\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
              \end{array}\right]
          \end{equation}
#+end_src

In Uwe's criticism, the user already messed up (with the current state
of AUCTeX) by forgetting to put a newline before \begin{array}.  Their
mistake is covered up because they were lucky enough to enclose the
array environment in an aligned environment, but this does not forgive
the mistake, and I'm not convinced by this example that AUCTeX's
current approach is superior to the proposed one.  My ranking of the
available alternatives:
1. Some better proposal
2. My proposal
3. Current state

To emphasize, the user error is severe because the resulting
indentation errors propagate through the buffer, making indent-region
useless when applied globally.  On the other hand, this user error is
committed repeatedly in every .tex file I encounter in practice.
Moreover, the underlying bug cannot always be circumvented just by
putting each \begin at the start of its own line, as the following
example shows:

#+begin_src latex
The matrix $\begin{pmatrix}
              a & b \\
              c & d
            \end{pmatrix}$ has determinant
            \begin{equation}
              a d - b c.
            \end{equation}
#+end_src

The "user workaround" here is to put the entire pmatrix environment on
one line.  I've been using and automating such workarounds for years
-- writing my own linters that "fix" a tex buffer to avoid such "user
errors" -- but don't think new users should be forced to do so, and
can emphasize with some of Robert's comments in Ikumi's reference [1].

As a final remark, one can fix my original example by adjusting the
"equation" entry of LaTeX-indent-environment-list to
LaTeX-indent-tabular, but not this last example.

Thanks, best,

Paul




Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 17:13:02 GMT) Full text and rfc822 format available.

Message #17 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>,
 Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 03 Sep 2023 18:40:43 +0200
[Message part 1 (text/plain, inline)]
>>> "PN" == Paul Nelson <ultrono <at> gmail.com> writes:
Hi Paul

> Hi Uwe,
> Thanks for your response.  First I'll respond to the minor points:

>> You say indent-region
>> 
>> I am referring here to the LaTeX-filling-functions, such as
>> LaTeX-fill-environment,  LaTeX-fill-section etc

> There's no important difference here between indent-region and the
> LaTeX fill commands -- unless I'm mistakaen, they all ultimately call
> LaTeX-indent-line, one line at a time.  The same issue occurs for
> both.

>> Since I receive a *lot* of theses badly (in the sense above)
>> environments in the incorrect form
>> So I came up with a solution heavily rewritten and improved by Arash

> I'm likewise often enough in this situation, motivating my proposal.
> My workaround is "czm-tex-edit-fix-buffer", available at the very
> bottom of https://github.com/ultronozm/czm-tex-edit.el/blob/main/czm-tex-edit.el,
> which makes each \begin and \end in the buffer appear on their own
> line.  I suspect it's similar enough to what you use.

I just had a look, very interesting, you also have a function 
czm-tex-edit-make-equation-numbered 

I also came up with something similar, again, heavily rewritten by Arash

(defun my-change-dollar-to-equation ()
  (interactive)
  (save-excursion
  (replace-regexp "\\$\\$\\(\\(.\\|\n\\)*?\\)\\$\\$"
                  "\\\\begin{equation}\\1\\\\end{equation}")))

(defun my-change-dollar-to-equation-label ()
  "Courtesy from Arash Esbati
[[https://groups.google.com/groups/search?as_umsgid=86fspsavpa.fsf <at> gnu.org][Email from Arash Esbati: Re: change $$ to equations with automatic labels]]:
This function not only replaces displayed plain TeX equations with a `$$' equations with
the `\begin{{equation}' environment, but it also inserts an
appropriate label via `reftex-label'"
  (interactive)
  (let ((p (point-marker))
        (s (make-marker))
        (e (make-marker)))
    (goto-char (point-min))
    (while (re-search-forward (concat "^" (regexp-quote "$$")) nil t)
      ;; Start doing something if we are in a math evn:
      (when (texmathp)
        (set-marker s (point))
        ;; Search for the closing $$ pair:
        (re-search-forward (concat "^" (regexp-quote "$$")))
        (set-marker e (point))
        (delete-backward-char 2)
        (insert "\\end{equation}")
        (delete-horizontal-space)
        (goto-char s)
        (delete-backward-char 2)
        (insert "\\begin{equation}")
        (delete-horizontal-space)
        ;; Indent the environment:
        (goto-char e)
        (indent-according-to-mode)
        (goto-char s)
        (indent-according-to-mode)
        ;; Check if there is already a \label:
        (unless (re-search-forward "\\\\label{" e t)
          (goto-char s)
          (forward-line)
          (indent-according-to-mode)
          (reftex-label)
          (LaTeX-newline)
          (indent-according-to-mode))))
    (goto-char p)
    (set-marker p nil)
    (set-marker s nil)
    (set-marker e nil)))


I think it might be a good idea somehow to try to combine these
functions. I also proposed/asked to add them to auctex, till now there
was not enough interest and it was considered a corner case.


> The point of this bug fix is not really for me -- I get around it
> through a combination of being diligent about inserting environments
> and the linting function that I linked above -- but for new users who
> I don't think should have to do that.

That of course is true.

> OK, on to the main point.  My claim is that if you care about your
> example, namely

> #+begin_src latex
> \begin{equation}*
>   \begin{aligned}**
>     &n u m=\left[\begin{array}{ll}***
>                    2 & 25
>     \end{array}\right] \\
>     &d e n=\left[\begin{array}{lll}
>                    1 & 4 & 25
>     \end{array}\right]
>   \end{aligned}
> \end{equation}
> #+end_src


> then you should care even more about the following simpler, more
> natural, and (in my experience) more common example:

> #+begin_src latex
> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                    2 & 25
>     \end{array}\right] \\
> \end{equation}.
> #+end_src


> Let's put three of those examples in a row and format them according
> to current AUCTeX and my proposal.

> Current AUCTeX:

> #+begin_src latex
> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                 2 & 25
>               \end{array}\right] \\
>           \end{equation}

>           \begin{equation}
>             n u m=\left[\begin{array}{ll}
>                           2 & 25
>                         \end{array}\right] \\
>                     \end{equation}

>                     \begin{equation}
>                       n u m=\left[\begin{array}{ll}
>                                     2 & 25
>                                   \end{array}\right] \\
>                               \end{equation}
> #+end_src


> My proposal:

> #+begin_src latex
> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                 2 & 25
>   \end{array}\right] \\
> \end{equation}

> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                 2 & 25
>   \end{array}\right] \\
> \end{equation}

> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                 2 & 25
>   \end{array}\right] \\
> \end{equation}
> #+end_src

Ok I see your point now

> The current AUCTeX indentation here is obviously broken; the primary
> purpose of my proposal is to fix that.  I should emphasize that such
> behavior arises in ways other than via indent-region or filling
> commands, since many actions (inserting newlines, closing out
> environments via C-c ], ...) ultimately invoke LaTeX-indent-line.

> The difference between my proposal and the "optimum" that we agree on, namely

> #+begin_src latex
> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                 2 & 25
>               \end{array}\right] \\
> \end{equation}
> #+end_src

> seems to me a secondary matter, or a fine-tuning.  The "user fix"
> (always putting \begin on a fresh line) for the deficiency with my
> proposal is the same as for the deficiency with current AUCTeX, but
> the impact of the former seems to me much less catastrophic than that
> of the latter.

>> What's about a new variable then.
>> 
>> (defvar LaTeX-fill-sloppy t
>> "When t, Paul's proposal, when nil, Uwe's proposal, that is the old behavior")
>> 
>> Or does this make the code more difficult to maintain?

> It seems possible to fine-tune the indentation code to give the
> "optimum", at the cost of making that code slightly less efficient due
> to additional checks for matching \begin's.  I think that if any "new
> variable" should be given, then its purpose should be to determine
> whether to give such a fine-tuning, and not whether to fix the noted
> "obviously broken" behavior.

I think the maintainers should decide that. I am in favor of such a
variable, however I don't know enough of the code to really judge it.

To summarise, you convinced me, sigh. 
Not sure what the others think.

In case it gets adapted, then I will see how I can and will deal
with the new behavior maybe using some of your functions, and if I don't
succeed, I will complain again, 😉😇

Uwe 

> Thanks, best,

> Paul


-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of the Ukraine.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/
[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 17:14:01 GMT) Full text and rfc822 format available.

Message #20 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>,
 Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: [off-topic your packages] (was: bug#65648: 13.2; indentation of
 nested environments)
Date: Sun, 03 Sep 2023 18:45:57 +0200
[Message part 1 (text/plain, inline)]
>>> "PN" == Paul Nelson <ultrono <at> gmail.com> writes:
Hi Paul


> Hi Uwe,
> Thanks for your response.  First I'll respond to the minor points:

>> You say indent-region
>> 
>> I am referring here to the LaTeX-filling-functions, such as
>> LaTeX-fill-environment,  LaTeX-fill-section etc

> There's no important difference here between indent-region and the
> LaTeX fill commands -- unless I'm mistakaen, they all ultimately call
> LaTeX-indent-line, one line at a time.  The same issue occurs for
> both.

>> Since I receive a *lot* of theses badly (in the sense above)
>> environments in the incorrect form
>> So I came up with a solution heavily rewritten and improved by Arash

> I'm likewise often enough in this situation, motivating my proposal.
> My workaround is "czm-tex-edit-fix-buffer", available at the very
> bottom of https://github.com/ultronozm/czm-tex-edit.el/blob/main/czm-tex-edit.el

Just a short comment, why don't to combine both package to one single
repository, since czm-tex-edit.el requires dynexp.el?
That would make it a bit easier to install.


I will try to test them in the coming days.

[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 17:21:02 GMT) Full text and rfc822 format available.

Message #23 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: Uwe Brauer <oub <at> mat.ucm.es>
Cc: 65648 <at> debbugs.gnu.org, Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 3 Sep 2023 18:25:08 +0200
Hi Uwe,

Thanks for your response.  First I'll respond to the minor points:

> You say indent-region
>
> I am referring here to the LaTeX-filling-functions, such as
>  LaTeX-fill-environment,  LaTeX-fill-section etc

There's no important difference here between indent-region and the
LaTeX fill commands -- unless I'm mistakaen, they all ultimately call
LaTeX-indent-line, one line at a time.  The same issue occurs for
both.

> Since I receive a *lot* of theses badly (in the sense above)
> environments in the incorrect form
> So I came up with a solution heavily rewritten and improved by Arash

I'm likewise often enough in this situation, motivating my proposal.
My workaround is "czm-tex-edit-fix-buffer", available at the very
bottom of https://github.com/ultronozm/czm-tex-edit.el/blob/main/czm-tex-edit.el,
which makes each \begin and \end in the buffer appear on their own
line.  I suspect it's similar enough to what you use.

The point of this bug fix is not really for me -- I get around it
through a combination of being diligent about inserting environments
and the linting function that I linked above -- but for new users who
I don't think should have to do that.

OK, on to the main point.  My claim is that if you care about your
example, namely

#+begin_src latex
\begin{equation}*
  \begin{aligned}**
    &n u m=\left[\begin{array}{ll}***
                   2 & 25
    \end{array}\right] \\
    &d e n=\left[\begin{array}{lll}
                   1 & 4 & 25
    \end{array}\right]
  \end{aligned}
\end{equation}
#+end_src

then you should care even more about the following simpler, more
natural, and (in my experience) more common example:

#+begin_src latex
\begin{equation}
  n u m=\left[\begin{array}{ll}
                   2 & 25
    \end{array}\right] \\
\end{equation}.
#+end_src

Let's put three of those examples in a row and format them according
to current AUCTeX and my proposal.

Current AUCTeX:
#+begin_src latex
\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
              \end{array}\right] \\
          \end{equation}

          \begin{equation}
            n u m=\left[\begin{array}{ll}
                          2 & 25
                        \end{array}\right] \\
                    \end{equation}

                    \begin{equation}
                      n u m=\left[\begin{array}{ll}
                                    2 & 25
                                  \end{array}\right] \\
                              \end{equation}
#+end_src

My proposal:
#+begin_src latex
\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
  \end{array}\right] \\
\end{equation}

\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
  \end{array}\right] \\
\end{equation}

\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
  \end{array}\right] \\
\end{equation}
#+end_src

The current AUCTeX indentation here is obviously broken; the primary
purpose of my proposal is to fix that.  I should emphasize that such
behavior arises in ways other than via indent-region or filling
commands, since many actions (inserting newlines, closing out
environments via C-c ], ...) ultimately invoke LaTeX-indent-line.

The difference between my proposal and the "optimum" that we agree on, namely
#+begin_src latex
\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
              \end{array}\right] \\
\end{equation}
#+end_src
seems to me a secondary matter, or a fine-tuning.  The "user fix"
(always putting \begin on a fresh line) for the deficiency with my
proposal is the same as for the deficiency with current AUCTeX, but
the impact of the former seems to me much less catastrophic than that
of the latter.

> What's about a new variable then.
>
> (defvar LaTeX-fill-sloppy t
>   "When t, Paul's proposal, when nil, Uwe's proposal, that is the old behavior")
>
> Or does this make the code more difficult to maintain?

It seems possible to fine-tune the indentation code to give the
"optimum", at the cost of making that code slightly less efficient due
to additional checks for matching \begin's.  I think that if any "new
variable" should be given, then its purpose should be to determine
whether to give such a fine-tuning, and not whether to fix the noted
"obviously broken" behavior.

Thanks, best,

Paul




Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 17:30:02 GMT) Full text and rfc822 format available.

Message #26 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>,
 Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 03 Sep 2023 17:30:57 +0200
[Message part 1 (text/plain, inline)]
>>> "PN" == Paul Nelson <ultrono <at> gmail.com> writes:
Hi Paul


> Hi Ikumi and Uwe,
> Thanks to both of you for your feedback.

Thanks for your proposal

> I agree that it's better to have begin/end line up when all else is
> equal, but with the current state of AUCTeX (since this bug was
> introduced), it is a severe user error to put \begin{array} on a line
> following non-whitespace.  The reason is the same as in my original
> message, or in what one gets from Uwe's example by deleting the inner
> aligned environment and applying M-x indent-region:

> #+begin_src latex
> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                 2 & 25
>               \end{array}\right]
>           \end{equation}
> #+end_src


I am a bit confused. So let me try to sort it out.

You say indent-region

I am referring here to the LaTeX-filling-functions, such as 
 LaTeX-fill-environment,  LaTeX-fill-section etc


Now I presume we all agree that 
the correct form of the above example should be


\begin{equation}
   n u m=\left[
      \begin{array}{ll}
                 2 & 25
      \end{array}
\right]
\end{equation}

Then 

 LaTeX-fill-environment 
results in 

 \begin{equation}
   n u m=\left[
     \begin{array}{ll}
       2 & 25
     \end{array}
   \right]
 \end{equation}




> In Uwe's criticism, the user already messed up (with the current state
> of AUCTeX) by forgetting to put a newline before \begin{array}.  Their
> mistake is covered up because they were lucky enough to enclose the
> array environment in an aligned environment, but this does not forgive
> the mistake, and I'm not convinced by this example that AUCTeX's
> current approach is superior to the proposed one.  

So are you saying that your proposal in my example would result in a
better result? If so I disagree.

My ranking of the
> available alternatives:



> 1. Some better proposal

Since I receive a *lot* of theses badly (in the sense above)
environments in the incorrect form
\begin{equation}
   n u m=\left[\begin{array}{ll}
                 2 & 25
               \end{array}\right]
\end{equation}


So I came up with a solution heavily rewritten and improved by Arash

(defun my-change-begin-array-to-newline-begin-array (); important function before running filling functions
  (interactive)
    (while (re-search-forward "\\\\begin{array}\\(\\(.\\|\n\\)*?\\)" nil t)
      (replace-match "\n\\\\begin{array}\\1" nil nil)))

(defun my-change-end-array-to-newline-end-array (); important function before running filling functions
  (interactive)
  (save-excursion
    (while (re-search-forward"\\\\end{array}\\(\\(.\\|\n\\)*?\\)" nil t)
      (replace-match "\\\\end{array}\n\\1" nil nil))))

However it should 

> 2. My proposal
> 3. Current state

> To emphasize, the user error is severe because the resulting
> indentation errors propagate through the buffer, making indent-region
> useless when applied globally. 

Frankly in my opinion, one should *not* use this function or
LaTeX-fill-buffer
globally.

Unfortunately because of bad practise, or laziness a lot of users or
their editors do not provide very well formatted environments.



>  On the other hand, this user error is
> committed repeatedly in every .tex file I encounter in practice.
> Moreover, the underlying bug cannot always be circumvented just by
> putting each \begin at the start of its own line, as the following
> example shows:

> #+begin_src latex
> The matrix $\begin{pmatrix}
>               a & b \\
>               c & d
>             \end{pmatrix}$ has determinant
>             \begin{equation}
>               a d - b c.
>             \end{equation}
> #+end_src

Frankly one should not use $ in LateX file and in this example, from my
point of view, since there is already a \begin{pmatrix}

The correct syntaxes should be

\begin{math}
  \begin{pmatrix}
    a & b \\
    c & d
  \end{pmatrix}
\end{math}

> The "user workaround" here is to put the entire pmatrix environment on
> one line.  I've been using and automating such workarounds for years
> -- writing my own linters that "fix" a tex buffer to avoid such "user
> errors" -- but don't think new users should be forced to do so, and
> can emphasize with some of Robert's comments in Ikumi's reference [1].

That seems to me much less readable than my solution.

> As a final remark, one can fix my original example by adjusting the
> "equation" entry of LaTeX-indent-environment-list to
> LaTeX-indent-tabular, but not this last example.

What's about a new variable then.
 
(defvar LaTeX-fill-sloppy t
  "When t, Paul's proposal, when nil, Uwe's proposal, that is the old behavior")

Or does this make the code more difficult to maintain?

Uwe 


-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of the Ukraine.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/
[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 18:25:02 GMT) Full text and rfc822 format available.

Message #29 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: Uwe Brauer <oub <at> mat.ucm.es>
Cc: 65648 <at> debbugs.gnu.org, Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: [off-topic your packages] (was: bug#65648: 13.2; indentation of
 nested environments)
Date: Sun, 3 Sep 2023 20:23:59 +0200
Hi Uwe,

> Just a short comment, why don't to combine both package to one single
> repository, since czm-tex-edit.el requires dynexp.el?
> That would make it a bit easier to install.
>
>
> I will try to test them in the coming days.
>

Thanks for your feedback on this.  I only recently got around to
splitting packages off from my config.  In case you're really in the
mood for testing, here are the latex-related ones thus far:

https://github.com/ultronozm/czm-tex-edit.el
https://github.com/ultronozm/czm-tex-fold.el
https://github.com/ultronozm/czm-tex-ref.el
https://github.com/ultronozm/czm-tex-jump.el
https://github.com/ultronozm/czm-preview.el
https://github.com/ultronozm/czm-tex-compile.el
https://github.com/ultronozm/dynexp.el
https://github.com/ultronozm/spout.el
https://github.com/ultronozm/czm-tex-util.el

I think you're right that it doesn't make much sense for
"czm-tex-edit" to depend upon "dynexp" -- I guess I should move the
common function to "czm-tex-util", which is where I've put helpers for
most of the other packages -- but it seemed better to me to allow some
dependencies between packages than to merge them all together or
introduce redundancy.

Any additional feedback would be welcome.

Paul




Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 03 Sep 2023 19:43:02 GMT) Full text and rfc822 format available.

Message #32 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>,
 Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: [off-topic your packages]
Date: Sun, 03 Sep 2023 21:42:19 +0200
[Message part 1 (text/plain, inline)]
>>> "PN" == Paul Nelson <ultrono <at> gmail.com> writes:

> Hi Uwe,
>> Just a short comment, why don't to combine both package to one single
>> repository, since czm-tex-edit.el requires dynexp.el?
>> That would make it a bit easier to install.
>> 
>> 
>> I will try to test them in the coming days.
>> 

> Thanks for your feedback on this.  I only recently got around to
> splitting packages off from my config.  In case you're really in the
> mood for testing, here are the latex-related ones thus far:

Wow, I really think you should combine them to a single repository,
makes also testing simpler. I will travel tomorrow, so not sure when I
will test them.

I just skimmed the README's
> https://github.com/ultronozm/czm-tex-edit.el

for me the most interesting, several functions, I have also implemented,
or tried to implement, so I am curious to see, how your functions differ.

> https://github.com/ultronozm/czm-tex-fold.el
well, I don't use that very often


> https://github.com/ultronozm/czm-tex-ref.el

I am a convinced user of reftex, the feature I need most is, that it
inserts the file name as a prefix to every label. Since I regularly
insert equations from other files, so that feature is very important to me.
> https://github.com/ultronozm/czm-tex-jump.el

Seems interesting

> https://github.com/ultronozm/czm-preview.el

I have not used preview for some time, so I am not sure whether I will
have a look


> https://github.com/ultronozm/czm-tex-compile.el

I will check
> https://github.com/ultronozm/dynexp.el

I am using cdlatex very often, any change in that behavior will for the
moment break my workflow.

> https://github.com/ultronozm/spout.el
I will check

> https://github.com/ultronozm/czm-tex-util.el

Hm what is that for?

> I think you're right that it doesn't make much sense for
> "czm-tex-edit" to depend upon "dynexp" -- I guess I should move the
> common function to "czm-tex-util", which is where I've put helpers for
> most of the other packages -- but it seemed better to me to allow some
> dependencies between packages than to merge them all together or
> introduce redundancy.

> Any additional feedback would be welcome.

I think the first one I will check in the coming days, more then later
> Paul

-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of the Ukraine.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/
[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Mon, 04 Sep 2023 07:48:03 GMT) Full text and rfc822 format available.

Message #35 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Uwe Brauer <oub <at> mat.ucm.es>, Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Mon, 04 Sep 2023 16:47:12 +0900
[Message part 1 (text/plain, inline)]
Hi Uwe and Paul, thank you for your discussion.

>>>>> Paul Nelson <ultrono <at> gmail.com> writes:
> There's no important difference here between indent-region and the
> LaTeX fill commands -- unless I'm mistakaen, they all ultimately call
> LaTeX-indent-line, one line at a time.

That's right. The doc strings of `LaTeX-fill-region',
`LaTeX-fill-environment', `LaTeX-fill-section' and `LaTeX-fill-buffer'
say "Fill and indent ...".

> Let's put three of those examples in a row and format them according
> to current AUCTeX and my proposal.

[...]

> The current AUCTeX indentation here is obviously broken;

Indeed :-(

>>>>> Uwe Brauer <oub <at> mat.ucm.es> writes:
> To summarise, you convinced me, sigh. 
> Not sure what the others think.

OK, I don't object.

>>> What's about a new variable then.
>>> 
>>> (defvar LaTeX-fill-sloppy t
>>> "When t, Paul's proposal, when nil, Uwe's proposal, that is the old behavior")
>>> 
>>> Or does this make the code more difficult to maintain?

>> It seems possible to fine-tune the indentation code to give the
>> "optimum", at the cost of making that code slightly less efficient due
>> to additional checks for matching \begin's.  I think that if any "new
>> variable" should be given, then its purpose should be to determine
>> whether to give such a fine-tuning, and not whether to fix the noted
>> "obviously broken" behavior.

> I think the maintainers should decide that. I am in favor of such a
> variable, however I don't know enough of the code to really judge it.

I tried to implement the idea of such customize option as
`LaTeX-indent-always-align-end-with-begin'. See the attached patch.

When this option is non-nil, the "optimum" indentation
\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
              \end{array}\right]
\end{equation}
is obtained while
Let $E = \begin{bmatrix}
           1 & 0\\
           0 & 1
         \end{bmatrix}$ be the
         identity matrix.
is formatted badly.

When the option is nil, Paul's proposal takes effect so
\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
  \end{array}\right]
\end{equation}
and
Let $E = \begin{bmatrix}
           1 & 0\\
           0 & 1
\end{bmatrix}$ be the
identity matrix.
are obtained.

This is only a tentative patch. Comments are welcome.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

[tentative-patch (text/x-diff, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Mon, 04 Sep 2023 08:36:02 GMT) Full text and rfc822 format available.

Message #38 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Mon, 4 Sep 2023 10:34:52 +0200
[Message part 1 (text/plain, inline)]
Hi Ikumi,

Thanks for sharing your tentative patch.

The "always-align nil" behavior looks good to me.

As for the "always-align t" case, there are still some natural "broken"
examples, as you know:

#+begin_src latex
\begin{equation*}
  g = \begin{pmatrix}
        a & b \\
        c & d \\
      \end{pmatrix},
      \quad
      h = \begin{pmatrix}
            x & y \\
            z & w \\
          \end{pmatrix}.
\end{equation*}
#+end_src

#+begin_src latex
The matrix $\begin{pmatrix}
              a & b \\
              c & d
            \end{pmatrix}$ has determinant
            \begin{equation*}
              a d - b c.
            \end{equation*}

            The matrix $\begin{pmatrix}
                          a & b \\
                          c & d
                        \end{pmatrix}$ has determinant
                        \begin{equation*}
                          a d - b c.
                        \end{equation*}

                        The matrix $\begin{pmatrix}
                                      a & b \\
                                      c & d
                                    \end{pmatrix}$ has determinant
                                    \begin{equation*}
                                      a d - b c.
                                    \end{equation*}
#+end_src


With a bit more massaging, it should be possible to avoid these.  I had in
mind modifying LaTeX-indent-level-count (or the block surrounding where it
is called) in \end{TABULAR} cases, adjusting by the difference between the
matching \begin and its beginning of line.

Paul
[Message part 2 (text/html, inline)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sat, 09 Sep 2023 06:53:01 GMT) Full text and rfc822 format available.

Message #41 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Paul Nelson <ultrono <at> gmail.com>, Uwe Brauer <oub <at> mat.ucm.es>
Cc: 65648 <at> debbugs.gnu.org
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sat, 09 Sep 2023 15:52:42 +0900
[Message part 1 (text/plain, inline)]
Hi Paul and Uwe,

>>>>> Paul Nelson <ultrono <at> gmail.com> writes:
> As for the "always-align t" case, there are still some natural "broken"
> examples, as you know:
> #+begin_src latex
> \begin{equation*}
>   g = \begin{pmatrix}
>         a & b \\
>         c & d \\
>       \end{pmatrix},
>       \quad
>       h = \begin{pmatrix}
>             x & y \\
>             z & w \\
>           \end{pmatrix}.
> \end{equation*}
> #+end_src
> #+begin_src latex
> The matrix $\begin{pmatrix}
>               a & b \\
>               c & d
>             \end{pmatrix}$ has determinant
>             \begin{equation*}
>               a d - b c.
>             \end{equation*}

>             The matrix $\begin{pmatrix}
>                           a & b \\
>                           c & d
>                         \end{pmatrix}$ has determinant
>                         \begin{equation*}
>                           a d - b c.
>                         \end{equation*}

>                         The matrix $\begin{pmatrix}
>                                       a & b \\
>                                       c & d
>                                     \end{pmatrix}$ has determinant
>                                     \begin{equation*}
>                                       a d - b c.
>                                     \end{equation*}
> #+end_src

I've been gradually inclined to the attached approach. Namely, align "&"
as well as \end{foo} relative to beg-col, not beg-pos. In this way, the
above examples turn into
----------------------------------------------------------------------
\begin{equation*}
  g = \begin{pmatrix}
    a & b \\
    c & d \\
  \end{pmatrix},
  \quad
  h = \begin{pmatrix}
    x & y \\
    z & w \\
  \end{pmatrix}.
\end{equation*}
----------------------------------------------------------------------
and
----------------------------------------------------------------------
The matrix $\begin{pmatrix}
  a & b \\
  c & d
\end{pmatrix}$ has determinant
\begin{equation*}
  a d - b c.
\end{equation*}

The matrix $\begin{pmatrix}
  a & b \\
  c & d
\end{pmatrix}$ has determinant
\begin{equation*}
  a d - b c.
\end{equation*}

The matrix $\begin{pmatrix}
  a & b \\
  c & d
\end{pmatrix}$ has determinant
\begin{equation*}
  a d - b c.
\end{equation*}
----------------------------------------------------------------------

This patch indents as
\begin{equation}
  n u m=\left[\begin{array}{ll}
    2 & 25
  \end{array}\right]
\end{equation}
, not the form Paul proposed
\begin{equation}
  n u m=\left[\begin{array}{ll}
                2 & 25
  \end{array}\right]
\end{equation}
. Maybe Uwe doesn't like the former indentation, but it is more similar
to the behavior of other (non-tabular type) environments.

> With a bit more massaging, it should be possible to avoid these.  I had in
> mind modifying LaTeX-indent-level-count (or the block surrounding where it
> is called) in \end{TABULAR} cases, adjusting by the difference between the
> matching \begin and its beginning of line.

A similar idea crossed my brain, too. The best position to modify would be
`LaTeX-indent-calculate-last'.
It would make the indent algorithm more complex, so I began to search
for more simple solution.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

[0001-temporal-commit.patch (text/x-diff, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sat, 09 Sep 2023 17:00:01 GMT) Full text and rfc822 format available.

Message #44 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sat, 9 Sep 2023 18:58:45 +0200
[Message part 1 (text/plain, inline)]
Looks good to me (I prefer it over my original suggestion).  Thanks!

On Sat, Sep 9, 2023 at 8:52 AM Ikumi Keita <ikumi <at> ikumi.que.jp> wrote:

> Hi Paul and Uwe,
>
> >>>>> Paul Nelson <ultrono <at> gmail.com> writes:
> > As for the "always-align t" case, there are still some natural "broken"
> > examples, as you know:
> > #+begin_src latex
> > \begin{equation*}
> >   g = \begin{pmatrix}
> >         a & b \\
> >         c & d \\
> >       \end{pmatrix},
> >       \quad
> >       h = \begin{pmatrix}
> >             x & y \\
> >             z & w \\
> >           \end{pmatrix}.
> > \end{equation*}
> > #+end_src
> > #+begin_src latex
> > The matrix $\begin{pmatrix}
> >               a & b \\
> >               c & d
> >             \end{pmatrix}$ has determinant
> >             \begin{equation*}
> >               a d - b c.
> >             \end{equation*}
>
> >             The matrix $\begin{pmatrix}
> >                           a & b \\
> >                           c & d
> >                         \end{pmatrix}$ has determinant
> >                         \begin{equation*}
> >                           a d - b c.
> >                         \end{equation*}
>
> >                         The matrix $\begin{pmatrix}
> >                                       a & b \\
> >                                       c & d
> >                                     \end{pmatrix}$ has determinant
> >                                     \begin{equation*}
> >                                       a d - b c.
> >                                     \end{equation*}
> > #+end_src
>
> I've been gradually inclined to the attached approach. Namely, align "&"
> as well as \end{foo} relative to beg-col, not beg-pos. In this way, the
> above examples turn into
> ----------------------------------------------------------------------
> \begin{equation*}
>   g = \begin{pmatrix}
>     a & b \\
>     c & d \\
>   \end{pmatrix},
>   \quad
>   h = \begin{pmatrix}
>     x & y \\
>     z & w \\
>   \end{pmatrix}.
> \end{equation*}
> ----------------------------------------------------------------------
> and
> ----------------------------------------------------------------------
> The matrix $\begin{pmatrix}
>   a & b \\
>   c & d
> \end{pmatrix}$ has determinant
> \begin{equation*}
>   a d - b c.
> \end{equation*}
>
> The matrix $\begin{pmatrix}
>   a & b \\
>   c & d
> \end{pmatrix}$ has determinant
> \begin{equation*}
>   a d - b c.
> \end{equation*}
>
> The matrix $\begin{pmatrix}
>   a & b \\
>   c & d
> \end{pmatrix}$ has determinant
> \begin{equation*}
>   a d - b c.
> \end{equation*}
> ----------------------------------------------------------------------
>
> This patch indents as
> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>     2 & 25
>   \end{array}\right]
> \end{equation}
> , not the form Paul proposed
> \begin{equation}
>   n u m=\left[\begin{array}{ll}
>                 2 & 25
>   \end{array}\right]
> \end{equation}
> . Maybe Uwe doesn't like the former indentation, but it is more similar
> to the behavior of other (non-tabular type) environments.
>
> > With a bit more massaging, it should be possible to avoid these.  I had
> in
> > mind modifying LaTeX-indent-level-count (or the block surrounding where
> it
> > is called) in \end{TABULAR} cases, adjusting by the difference between
> the
> > matching \begin and its beginning of line.
>
> A similar idea crossed my brain, too. The best position to modify would be
> `LaTeX-indent-calculate-last'.
> It would make the indent algorithm more complex, so I began to search
> for more simple solution.
>
> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine
>
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sat, 09 Sep 2023 18:10:02 GMT) Full text and rfc822 format available.

Message #47 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>,
 Paul Nelson <ultrono <at> gmail.com>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sat, 09 Sep 2023 21:09:28 +0300
[Message part 1 (text/plain, inline)]
> Hi Paul and Uwe,

Hi Keita

> I've been gradually inclined to the attached approach. Namely, align "&"
> as well as \end{foo} relative to beg-col, not beg-pos. In this way, the
> above examples turn into
> ----------------------------------------------------------------------
> \begin{equation*}
>   g = \begin{pmatrix}
>     a & b \\
>     c & d \\
>   \end{pmatrix},
>   \quad
>   h = \begin{pmatrix}
>     x & y \\
>     z & w \\
>   \end{pmatrix}.
> \end{equation*}

Thanks, but:
I applied the patch, recompiled, restarted emacs, and then

\begin{equation*}
  g = \begin{pmatrix}
    a & b \\
    c & d \\
  \end{pmatrix},
  \quad
  h = \begin{pmatrix}
    x & y \\
    z & w \\
  \end{pmatrix}.
\end{equation*}

Either with 

    1. LaTeX-indent-always-align-end-with-begin nil

    2. LaTeX-indent-always-align-end-with-begin t
       
Is filled as

\begin{equation*}
  g = \begin{pmatrix}
    a & b \\
    c & d \\
  \end{pmatrix}, \quad h = \begin{pmatrix}
    x & y \\
    z & w \\
  \end{pmatrix}.
\end{equation*}


That does not look correct to me, sorry the \begin{matrix} should be on
a newline.

Is this a bug?

Regards

Uwe 
[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sat, 09 Sep 2023 18:35:02 GMT) Full text and rfc822 format available.

Message #50 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: Uwe Brauer <oub <at> mat.ucm.es>
Cc: 65648 <at> debbugs.gnu.org, Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sat, 9 Sep 2023 20:33:45 +0200
[Message part 1 (text/plain, inline)]
Hi Uwe,

I don't see the behavior you describe; on my end, filling does not change
the latex you provided.  I've tried it with LaTeX-fill-environment and
indent-region.

Also, with this patch, the setting LaTeX-indent-always-align-end-with-begin
no longer seems relevant.  Maybe you tried applying the patch on top of an
earlier one, rather than directly to the master commit?

Paul
[Message part 2 (text/html, inline)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sat, 09 Sep 2023 19:14:02 GMT) Full text and rfc822 format available.

Message #53 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>,
 Ikumi Keita <ikumi <at> ikumi.que.jp>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sat, 09 Sep 2023 22:13:07 +0300
[Message part 1 (text/plain, inline)]
>>> "PN" == Paul Nelson <ultrono <at> gmail.com> writes:
Hi Paul

> Hi Uwe,
> I don't see the behavior you describe; on my end, filling does not change
> the latex you provided.  I've tried it with LaTeX-fill-environment and
> indent-region.

> Also, with this patch, the setting LaTeX-indent-always-align-end-with-begin
> no longer seems relevant.  Maybe you tried applying the patch on top of an
> earlier one, rather than directly to the master commit?

Well, I run make clean, reset, pulled again applied the patch to commit 
2151c3831fcff9

Run make, 
make install 

Tried again, 

But I do see this behavior, I am now puzzled, and have to investigate
that further.


> Paul

-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of the Ukraine.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/
[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 10 Sep 2023 05:51:02 GMT) Full text and rfc822 format available.

Message #56 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Uwe Brauer <oub <at> mat.ucm.es>
To: Uwe Brauer <oub <at> mat.ucm.es>
Cc: 65648 <at> debbugs.gnu.org, Ikumi Keita <ikumi <at> ikumi.que.jp>,
 Paul Nelson <ultrono <at> gmail.com>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 10 Sep 2023 08:49:54 +0300
[Message part 1 (text/plain, inline)]
> Hi Paul



> Well, I run make clean, reset, pulled again applied the patch to commit 
> 2151c3831fcff9

> Run make, 
> make install 

> Tried again, 

> But I do see this behavior, I am now puzzled, and have to investigate
> that further.


It seems also to happen without the patch, uff, right now I don't have
the time to debug this, maybe next week.

Uwe 


-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of the Ukraine.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/
[smime.p7s (application/pkcs7-signature, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Sun, 10 Sep 2023 06:23:01 GMT) Full text and rfc822 format available.

Message #59 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Uwe Brauer <oub <at> mat.ucm.es>
Cc: 65648 <at> debbugs.gnu.org, Paul Nelson <ultrono <at> gmail.com>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Sun, 10 Sep 2023 15:21:53 +0900
Hi Uwe,

Paul's inference is right. I made the patch anew, it's intended for the
clean master branch.

>>>>> Uwe Brauer <oub <at> mat.ucm.es> writes:

>> Well, I run make clean, reset, pulled again applied the patch to commit 
>> 2151c3831fcff9

>> Run make, 
>> make install 

>> Tried again, 

>> But I do see this behavior, I am now puzzled, and have to investigate
>> that further.

> It seems also to happen without the patch, uff, right now I don't have
> the time to debug this, maybe next week.

Hmm, then something other than AUCTeX is interfering?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Tue, 12 Sep 2023 06:07:02 GMT) Full text and rfc822 format available.

Message #62 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 65648 <at> debbugs.gnu.org, Uwe Brauer <oub <at> mat.ucm.es>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Tue, 12 Sep 2023 15:05:52 +0900
Hi Paul and all,

>>>>> Paul Nelson <ultrono <at> gmail.com> writes:
> Looks good to me (I prefer it over my original suggestion).  Thanks!

Thanks. If there's no objection, I'll polish my proposal and install it.
Any comments?

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-auctex <at> gnu.org:
bug#65648; Package auctex. (Thu, 14 Sep 2023 05:35:01 GMT) Full text and rfc822 format available.

Message #65 received at 65648 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: 65648 <at> debbugs.gnu.org
Cc: Uwe Brauer <oub <at> mat.ucm.es>, Paul Nelson <ultrono <at> gmail.com>
Subject: Re: bug#65648: 13.2; indentation of nested environments
Date: Thu, 14 Sep 2023 14:34:16 +0900
>>>>> Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
> Hi Paul and all,
>>>>> Paul Nelson <ultrono <at> gmail.com> writes:
>> Looks good to me (I prefer it over my original suggestion).  Thanks!

> Thanks. If there's no objection, I'll polish my proposal and install it.
> Any comments?

Done. I'll close this bug.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




bug closed, send any further explanations to 65648 <at> debbugs.gnu.org and Paul Nelson <ultrono <at> gmail.com> Request was from Ikumi Keita <ikumi <at> ikumi.que.jp> to control <at> debbugs.gnu.org. (Thu, 14 Sep 2023 05:36:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 12 Oct 2023 11:24:14 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 211 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.