Hi Arash, 2016-12-14 12:34 GMT+01:00 Arash Esbati <arash.esbati...@gmail.com>: > 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