Re: [AUCTeX-devel] Extending `LaTeX-array-count-columns'

2016-12-14 Thread Arash Esbati
Hi Ikumi,

Ikumi Keita  writes:

>> 2 thing occurred to me when hitting `M-RET' in tabular environments:
>> Current code in `LaTeX-array-count-columns' cannot handle multi column
>> specs like `*{num}{spec}' and optional args to column specs S and s from
>> siunitx.el.  I have a patch to handle both issues.
>
> Instead of modifying LaTeX-array-count-columns, how about putting such
> customized function in array.el and preparing to call it in a fashion
> like
>
>   (LaTeX-insert-ampersands
>LaTeX-array-skipping-regexp 'NEW-FUNCTION-NAME)
>
> in TeX-add-style-hook?  Syntaxes like
> \begin{tabular}[t]{*{4}{l}l}
> and

Thanks for your response.  This syntax is actually standard LaTeX, e.g.:

\documentclass{article}

\begin{document}
\_
\begin{tabular}[t]{@{}*{2}{l}r}
  1 & 2 & some longish text \\
  1 & 2 & some text \\ \hline
\end{tabular}
\_
\end{document}

The lack of support for this was the main motivation for me to extend
`LaTeX-array-count-columns'.

> \begin{tabular}{X[foo = bar]}
> are not supported in the standard LaTeX.  If such enhancements continue
> to pile up in future to cover syntaxes provided by other packages,
> LaTeX-array-count-columns might become much complicated and be hard to
> read and maintain.

I agree.  But I found that supporting this syntax inside
`LaTeX-array-count-columns' was rather easy.

> Of course such approach has drawbacks.  As well as being redundant to
> have similar codes at multiple locations, when someone improves
> LaTeX-array-count-columns, that person has to look in all style/*.el
> files and apply the same change to all the customized functions.
>
> So I won't object if you choose your original approach.  How do you
> think about that?

I think we are not closing that door.  If someone wants to write a style
for tabu.sty, he/she can (and probably should) go the route you're
suggesting.

In general, I also think that `latex.el' should support vanilla LaTeX,
but since the overhead for `\begin{tabular}{X[foo = bar]}' support is
quite low, I think we can leave it in `LaTeX-array-count-columns'.

I should also mention that one could write

\documentclass{article}

\begin{document}
\_
\begin{tabular}[t]{@{}*2lr}
  1 & 2 & some longish text \\
  1 & 2 & some text \\ \hline
\end{tabular}
\_
\end{document}

Note the missing braces around 2 and l.  While LaTeX compiles this
happily, my code chokes due to missing braces.  But I consider this a
feature :-)

WDYT?

Best, Arash

___
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel


Re: [AUCTeX-devel] Extending `LaTeX-array-count-columns'

2016-12-14 Thread Ikumi Keita
Hi Arash,

> 2 thing occurred to me when hitting `M-RET' in tabular environments:
> Current code in `LaTeX-array-count-columns' cannot handle multi column
> specs like `*{num}{spec}' and optional args to column specs S and s from
> siunitx.el.  I have a patch to handle both issues.

Instead of modifying LaTeX-array-count-columns, how about putting such
customized function in array.el and preparing to call it in a fashion
like

  (LaTeX-insert-ampersands
   LaTeX-array-skipping-regexp 'NEW-FUNCTION-NAME)

in TeX-add-style-hook?  Syntaxes like
\begin{tabular}[t]{*{4}{l}l}
and
\begin{tabular}{X[foo = bar]}
are not supported in the standard LaTeX.  If such enhancements continue
to pile up in future to cover syntaxes provided by other packages,
LaTeX-array-count-columns might become much complicated and be hard to
read and maintain.

Of course such approach has drawbacks.  As well as being redundant to
have similar codes at multiple locations, when someone improves
LaTeX-array-count-columns, that person has to look in all style/*.el
files and apply the same change to all the customized functions.

So I won't object if you choose your original approach.  How do you
think about that?

Bye,
Ikumi Keita

___
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel


Re: [AUCTeX-devel] Extending `LaTeX-array-count-columns'

2016-12-14 Thread Arash Esbati
Hi Mosè,

Mosè Giordano  writes:

> 2016-12-14 12:34 GMT+01:00 Arash Esbati :
>>
>> 2 thing occurred to me when hitting `M-RET' in tabular environments:
>> Current code in `LaTeX-array-count-columns' cannot handle multi column
>> specs like `*{num}{spec}' and optional args to column specs S and s from
>> siunitx.el.  I have a patch to handle both issues.  Can people please
>> test this code against their tabular's and see if it does the right
>> thing?  My test file is:
>>
>> [...]

> I briefly tested the file, and seems to work nicely, thanks for your work!
>
> As usual, I strongly suggest you to add the appropriate tests for the
> new feature.

Thanks for testing!  I can take the file I posted with some other
environments and add it as `tabular-ampersand-count.tex' under
auctex.git/tests/latex.  Is this what you have in mind?  I can't see how
to insert the test into `latex-test.el'.  Any hints?

I have to patch longtable.el and siunitx.el before.

Best, Arash

___
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel


Re: [AUCTeX-devel] Extending `LaTeX-array-count-columns'

2016-12-14 Thread Mosè Giordano
Hi Arash,

2016-12-14 12:34 GMT+01:00 Arash Esbati :
> Hi all,
>
> 2 thing occurred to me when hitting `M-RET' in tabular environments:
> Current code in `LaTeX-array-count-columns' cannot handle multi column
> specs like `*{num}{spec}' and optional args to column specs S and s from
> siunitx.el.  I have a patch to handle both issues.  Can people please
> test this code against their tabular's and see if it does the right
> thing?  My test file is:
>
> --8<---cut here---start->8---
> \documentclass{article}
>
> \usepackage{siunitx}
> \usepackage{array}
> \usepackage{tabularx}
> \newcolumntype{Y}{>{\tiny\scshape}r}
>
> \begin{document}
>
> Eval first:
> \begin{verbatim}
> (defun LaTeX-array-count-columns (start end)
>   "Count number of ampersands to be inserted.
> The columns are specified by the letters found in the string
> `LaTeX-array-column-letters' and the number of those letters within the
> text between START and END is basically considered to be the number of
> columns.  The arguments surrounded between braces such as p{30pt} do not
> interfere the count of columns.
>
> Return one less number than the columns, or nil on failing to count the
> right number."
>   (save-excursion
> (let (p (cols 0))
>   (goto-char start)
>   (while (< (setq p (point)) end)
>
> ;; The below block accounts for one unit of move for
> ;; one column.
> (setq cols (+ cols
>   (if (looking-at-p "\\*[ \t\r\n%]*{[ \t\r\n%0-9]+}")
>   (progn
> (re-search-forward
>  "\\*[ \t\r\n%]*{[ \t\r\n%]*\\([0-9]+\\)[ 
> \t\r\n%]*}" end t)
> (string-to-number (match-string-no-properties 1)))
> (skip-chars-forward
>  LaTeX-array-column-letters end
> (skip-chars-forward (concat
>  "^" LaTeX-array-column-letters "*"
>  TeX-grop LaTeX-optop) end)
> (when (or (eq (following-char) ?\{)
>   (eq (following-char) ?\[))
>   (forward-list 1))
>
> ;; Not sure whether this is really necessary or not, but
> ;; prepare for possible infinite loop anyway.
> (when (eq p (point))
>   (setq cols nil)
>   (goto-char end)))
>   ;; The number of ampersands is one less than column.
>   (if cols (1- cols)
> \end{verbatim}
>
> Standard procedure:
> \begin{tabular}[t]{*{4}{l}l}
>   1 & 2 & 3 & 4 & 5 \\
> 
> \end{tabular}
>
> Add some commands before cells:
> \begin{tabular}[b]{*{4}{>{\scriptsize}l}>{\huge}l}
>   1 & 2 & 3 & 4 & 5 \\
> 
> \end{tabular}
>
> \begin{tabular}{*{4}{>{\scriptsize}l} |l|}
>   1 & 2 & 3 & 4 & 5 \\
> 
> \end{tabular}
>
> Custom column spec `Y':
> \begin{tabular}[t]{* { 2 } {>{\scriptsize}l} | Y | * { 2 } {r}}
>   1 & 2 & 3 & 4 & 5 \\
> 
> \end{tabular}
>
> Eval first for `siunitx.el':
> \begin{verbatim}
> (set (make-local-variable 'LaTeX-array-column-letters)
>  (concat LaTeX-array-column-letters "sS"))
> \end{verbatim}
>
> Ignore optional `[...]' after S and s:
> \begin{tabular}{
>   s
>   S[table-number-alignment = center]
>   s[table-number-alignment = left]
>   S[table-number-alignment = right]
>   }
>   {Some Values} & {Some Values} & {Some Values} & {Some Values} \\
> &&&
> \end{tabular}
>
> \begin{tabular}{%
>   S[table-format = 1.1e1]
>   S[fixed-exponent = 3 ,
> table-format = 2.1 ,
> table-omit-exponent ] }
>   1 & 2 \\
> &
> \end{tabular}
> \end{document}
> --8<---cut here---end--->8---
>
> Any comments welcome.

I briefly tested the file, and seems to work nicely, thanks for your work!

As usual, I strongly suggest you to add the appropriate tests for the
new feature.

Bye,
Mosè

___
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel


Re: [AUCTeX-devel] Visit master file when creating a new file

2016-12-14 Thread Mosè Giordano
Hi Arash and all,

2016-12-11 23:29 GMT+01:00 Arash Esbati :
> Hi Mosè,
>
> Mosè Giordano  writes:
>
>> this question http://emacs.stackexchange.com/q/29081/620 shows that it
>> could be useful to visit the master file when creating a new file, in
>> order to grab some variables from it, like the major mode.  What do
>> you think?  Anything against this feature?
>
> Sounds reasonable to me.

Good.  If no objection will come in the next few days I'll apply the
attached patch.

Bye,
Mosè
diff --git a/tex.el b/tex.el
index e192899..1b5f2cb 100644
--- a/tex.el
+++ b/tex.el
@@ -2513,7 +2513,9 @@ name of master file if it cannot be determined otherwise."
 	   (file-name-directory buffer-file-name)))
 
 (defun TeX-add-local-master ()
-  "Add local variable for `TeX-master'."
+  "Add local variable for `TeX-master'.
+
+Get `major-mode' from master file and enable it."
   (when (and (buffer-file-name)
 	 (string-match TeX-one-master
 			   (file-name-nondirectory (buffer-file-name)))
@@ -2526,20 +2528,27 @@ name of master file if it cannot be determined otherwise."
 		   "End:")))
 	  (beginning-of-line 1)
 	  (insert prefix "TeX-master: " (prin1-to-string TeX-master) "\n"))
-  (let ((comment-prefix (cond ((eq major-mode 'texinfo-mode) "@c ")
-  ((eq major-mode 'doctex-mode) "% ")
-  (t "%%% ")))
-	(mode (concat (and (boundp 'japanese-TeX-mode) japanese-TeX-mode
-			   "japanese-")
-			  (substring (symbol-name major-mode) 0 -5
+  (let* ((mode (if (stringp TeX-master)
+		   (with-current-buffer
+			   (find-file-noselect
+			(TeX-master-file TeX-default-extension))
+			 major-mode)
+		 major-mode))
+	 (comment-prefix (cond ((eq mode 'texinfo-mode) "@c ")
+   ((eq mode 'doctex-mode) "% ")
+   (t "%%% ")))
+	 (mode-string (concat (and (boundp 'japanese-TeX-mode) japanese-TeX-mode
+   "japanese-")
+  (substring (symbol-name mode) 0 -5
 	(newline)
 	(when (eq major-mode 'doctex-mode)
 	  (insert comment-prefix TeX-esc "endinput\n"))
 	(insert
 	 comment-prefix "Local Variables:\n"
-	 comment-prefix "mode: " mode "\n"
+	 comment-prefix "mode: " mode-string "\n"
 	 comment-prefix "TeX-master: " (prin1-to-string TeX-master) "\n"
-	 comment-prefix "End:\n")
+	 comment-prefix "End:\n")
+	(funcall mode)
 
 (defun TeX-local-master-p ()
   "Return non-nil if there is a `TeX-master' entry in local variables spec.
___
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel


[AUCTeX-devel] Extending `LaTeX-array-count-columns'

2016-12-14 Thread Arash Esbati
Hi all,

2 thing occurred to me when hitting `M-RET' in tabular environments:
Current code in `LaTeX-array-count-columns' cannot handle multi column
specs like `*{num}{spec}' and optional args to column specs S and s from
siunitx.el.  I have a patch to handle both issues.  Can people please
test this code against their tabular's and see if it does the right
thing?  My test file is:

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

\usepackage{siunitx}
\usepackage{array}
\usepackage{tabularx}
\newcolumntype{Y}{>{\tiny\scshape}r}

\begin{document}

Eval first:
\begin{verbatim}
(defun LaTeX-array-count-columns (start end)
  "Count number of ampersands to be inserted.
The columns are specified by the letters found in the string
`LaTeX-array-column-letters' and the number of those letters within the
text between START and END is basically considered to be the number of
columns.  The arguments surrounded between braces such as p{30pt} do not
interfere the count of columns.

Return one less number than the columns, or nil on failing to count the
right number."
  (save-excursion
(let (p (cols 0))
  (goto-char start)
  (while (< (setq p (point)) end)

;; The below block accounts for one unit of move for
;; one column.
(setq cols (+ cols
  (if (looking-at-p "\\*[ \t\r\n%]*{[ \t\r\n%0-9]+}")
  (progn
(re-search-forward
 "\\*[ \t\r\n%]*{[ \t\r\n%]*\\([0-9]+\\)[ 
\t\r\n%]*}" end t)
(string-to-number (match-string-no-properties 1)))
(skip-chars-forward
 LaTeX-array-column-letters end
(skip-chars-forward (concat
 "^" LaTeX-array-column-letters "*"
 TeX-grop LaTeX-optop) end)
(when (or (eq (following-char) ?\{)
  (eq (following-char) ?\[))
  (forward-list 1))

;; Not sure whether this is really necessary or not, but
;; prepare for possible infinite loop anyway.
(when (eq p (point))
  (setq cols nil)
  (goto-char end)))
  ;; The number of ampersands is one less than column.
  (if cols (1- cols)
\end{verbatim}

Standard procedure:
\begin{tabular}[t]{*{4}{l}l}
  1 & 2 & 3 & 4 & 5 \\

\end{tabular}

Add some commands before cells:
\begin{tabular}[b]{*{4}{>{\scriptsize}l}>{\huge}l}
  1 & 2 & 3 & 4 & 5 \\

\end{tabular}

\begin{tabular}{*{4}{>{\scriptsize}l} |l|}
  1 & 2 & 3 & 4 & 5 \\

\end{tabular}

Custom column spec `Y':
\begin{tabular}[t]{* { 2 } {>{\scriptsize}l} | Y | * { 2 } {r}}
  1 & 2 & 3 & 4 & 5 \\

\end{tabular}

Eval first for `siunitx.el':
\begin{verbatim}
(set (make-local-variable 'LaTeX-array-column-letters)
 (concat LaTeX-array-column-letters "sS"))
\end{verbatim}

Ignore optional `[...]' after S and s:
\begin{tabular}{
  s
  S[table-number-alignment = center]
  s[table-number-alignment = left]
  S[table-number-alignment = right]
  }
  {Some Values} & {Some Values} & {Some Values} & {Some Values} \\
&&&
\end{tabular}

\begin{tabular}{%
  S[table-format = 1.1e1]
  S[fixed-exponent = 3 ,
table-format = 2.1 ,
table-omit-exponent ] }
  1 & 2 \\
&
\end{tabular}
\end{document}
--8<---cut here---end--->8---

Any comments welcome.

Best, Arash

___
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel