GNU bug report logs - #26010
Indenting in tabulars and \&

Previous Next

Package: auctex;

Reported by: Arash Esbati <arash <at> gnu.org>

Date: Tue, 7 Mar 2017 13:26:01 UTC

Severity: normal

Done: Arash Esbati <arash <at> gnu.org>

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 26010 in the body.
You can then email your comments to 26010 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#26010; Package auctex. (Tue, 07 Mar 2017 13:26:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arash Esbati <arash <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Tue, 07 Mar 2017 13:26:02 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: auctex-bugs <bug-auctex <at> gnu.org>
Subject: Indenting in tabulars and \&
Date: Tue, 07 Mar 2017 14:24:15 +0100
Hi all,

please consider the following 2 examples and how they are filled: First
example works as expected, second one not because of \&:

--8<---------------cut here---------------start------------->8---
\documentclass{article}

\usepackage{longtable}

\begin{document}

Hit `C-c C-q C-e' inside env:
\begin{tabular}{ll}
  These lines will & appear \\
  at the end
  & of the table     
\end{tabular}
results in:
\begin{tabular}{ll}
  These lines will & appear \\
  at the end
                   & of the table
\end{tabular}

Hit `C-c C-q C-e' inside env:
\begin{tabular}{ll}
  These lines will appear \& 
  at the end \\
  of the &
  table
\end{tabular}
results in:
\begin{tabular}{ll}
  These lines will appear \& 
                             at the end \\
  of the &
           table
\end{tabular}

\end{document}
--8<---------------cut here---------------end--------------->8---

AUCTeX doesn't see the control symbol \&, it just takes the ampersand as
a column separator.  This issue is caused in the last part of the
function `LaTeX-indent-tabular':

--8<---------------cut here---------------start------------->8---
    (cond (...
	  (t
	   (+ 2
              (let ((any-col (save-excursion
                               (when (re-search-backward "\\\\\\\\\\|&" beg-pos t)
                                 (current-column)))))
                (if (and any-col (string= "&" (match-string 0)))
                    any-col
		  beg-col)))))))
--8<---------------cut here---------------end--------------->8---

I'm not aware of any way to fix this *only* by tweaking the regexp here:

    (re-search-backward "\\\\\\\\\\|&" beg-pos t)

Any idea?

Otherwise, I suggest the following change in `LaTeX-indent-tabular':

--8<---------------cut here---------------start------------->8---
    (cond (...
	  (t
	   (+ 2
              (let ((any-col (save-excursion
                               (when (re-search-backward "\\\\\\\\\\|[^\\]&" beg-pos t)
                                 (current-column)))))
                (if (and any-col (string= "&" (substring (match-string-no-properties 0) -1)))
                    (1+ any-col)
		  beg-col)))))))
--8<---------------cut here---------------end--------------->8---

Comments welcome.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#26010; Package auctex. (Tue, 07 Mar 2017 17:50:01 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 26010 <at> debbugs.gnu.org
Subject: Re: bug#26010: Indenting in tabulars and \&
Date: Wed, 08 Mar 2017 02:49:41 +0900
Hi Arash,

> I'm not aware of any way to fix this *only* by tweaking the regexp here:

>     (re-search-backward "\\\\\\\\\\|&" beg-pos t)

> Any idea?

> Otherwise, I suggest the following change in `LaTeX-indent-tabular':
>     (cond (...
> 	  (t
> 	   (+ 2
>               (let ((any-col (save-excursion
>                                (when (re-search-backward "\\\\\\\\\\|[^\\]&" beg-pos t)
>                                  (current-column)))))
>                 (if (and any-col (string= "&" (substring (match-string-no-properties 0) -1)))
>                     (1+ any-col)
> 		  beg-col)))))))
> Comments welcome.

I think the form `(string= ...)' can be replaced with
`(= ?& (char-before (match-end 0)))'.

And here is another solution keeping the regexp untouched:
    (cond (...
	   (t
	    (+ 2
	       (let ((any-col (save-excursion
				(when (and
				       (re-search-backward "\\\\\\\\\\|&" beg-pos t)
				       (= ?& (char-after))
				       (not (TeX-escaped-p)))
				  (current-column)))))
		 (or any-col
		   beg-col))))))))

Using `TeX-escaped-p' might be overkilling since we allow loose usages of
(looking-at "\\\\\\\\") and (re-search-backward "\\\\\\\\... ) in this
function.

Bye,
Ikumi Keita




Information forwarded to bug-auctex <at> gnu.org:
bug#26010; Package auctex. (Tue, 07 Mar 2017 19:29:01 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 26010 <at> debbugs.gnu.org
Subject: Re: bug#26010: Indenting in tabulars and \&
Date: Tue, 07 Mar 2017 20:27:46 +0100
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

>> Otherwise, I suggest the following change in `LaTeX-indent-tabular':
>>     (cond (...
>> 	  (t
>> 	   (+ 2
>>               (let ((any-col (save-excursion
>>                                (when (re-search-backward "\\\\\\\\\\|[^\\]&" beg-pos t)
>>                                  (current-column)))))
>>                 (if (and any-col (string= "&" (substring (match-string-no-properties 0) -1)))
>>                     (1+ any-col)
>> 		  beg-col)))))))
>> Comments welcome.

Hi Keita,

many thanks for checking and your response.

> I think the form `(string= ...)' can be replaced with
> `(= ?& (char-before (match-end 0)))'.

Yes, this is even more elegant.

> And here is another solution keeping the regexp untouched:
>     (cond (...
> 	   (t
> 	    (+ 2
> 	       (let ((any-col (save-excursion
> 				(when (and
> 				       (re-search-backward "\\\\\\\\\\|&" beg-pos t)
> 				       (= ?& (char-after))
> 				       (not (TeX-escaped-p)))
> 				  (current-column)))))
> 		 (or any-col
> 		   beg-col))))))))
>
> Using `TeX-escaped-p' might be overkilling since we allow loose usages of
> (looking-at "\\\\\\\\") and (re-search-backward "\\\\\\\\... ) in this
> function.

I agree, this seems overkill.  `[^\\]' is also used in
`LaTeX-hanging-ampersand-position' which is right above
`LaTeX-indent-tabular' in latex. el -- these functions would look more
in line with `[^\\]' in regexp.  This is the current suggestion:

  (cond (...
       (t
        (+ 2
            (let ((any-col (save-excursion
                             (when (re-search-backward "\\\\\\\\\\|[^\\]&" beg-pos t)
                               (current-column)))))
              (if (and any-col (= ?& (char-before (match-end 0)))
                  (1+ any-col)
               beg-col)))))))

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#26010; Package auctex. (Tue, 07 Mar 2017 20:28:02 GMT) Full text and rfc822 format available.

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

From: Mosè Giordano <mose <at> gnu.org>
To: Arash Esbati <arash <at> gnu.org>
Cc: 26010 <at> debbugs.gnu.org
Subject: Re: bug#26010: Indenting in tabulars and \&
Date: Tue, 7 Mar 2017 21:26:50 +0100
Hi Arash,

2017-03-07 14:24 GMT+01:00 Arash Esbati <arash <at> gnu.org>:
> AUCTeX doesn't see the control symbol \&, it just takes the ampersand as
> a column separator.  This issue is caused in the last part of the
> function `LaTeX-indent-tabular':

Good catch.  I like the solution proposed by Keita, with or without
`TeX-escaped-p' (but I slightly prefer using these generic functions).
If you're going to install the fix, please add a test as well.

Bye,
Mosè




Reply sent to Arash Esbati <arash <at> gnu.org>:
You have taken responsibility. (Wed, 08 Mar 2017 10:47:02 GMT) Full text and rfc822 format available.

Notification sent to Arash Esbati <arash <at> gnu.org>:
bug acknowledged by developer. (Wed, 08 Mar 2017 10:47:02 GMT) Full text and rfc822 format available.

Message #19 received at 26010-close <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Mosè Giordano <mose <at> gnu.org>
Cc: 26010-close <at> debbugs.gnu.org
Subject: Re: bug#26010: Indenting in tabulars and \&
Date: Wed, 08 Mar 2017 11:45:24 +0100
Mosè Giordano <mose <at> gnu.org> writes:

> 2017-03-07 14:24 GMT+01:00 Arash Esbati <arash <at> gnu.org>:
>> AUCTeX doesn't see the control symbol \&, it just takes the ampersand as
>> a column separator.  This issue is caused in the last part of the
>> function `LaTeX-indent-tabular':
>
> Good catch.  I like the solution proposed by Keita, with or without
> `TeX-escaped-p' (but I slightly prefer using these generic functions).
> If you're going to install the fix, please add a test as well.

Hi Mosè,

thanks for your response.  I've installed a patch incl. a test; I went
for Keita's suggestion without `TeX-escaped-p', commit 991b582.  I close
this one then.

Best, Arash




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 05 Apr 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 169 days ago.

Previous Next


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