Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/12497189/emacs-latex-amount-of-columns-for-tables-matrices-arrays#comment16835580_12498189">As suggested</a> you can make a <a href="http://capitaomorte.github.com/yasnippet/" rel="nofollow noreferrer">YASnippet</a> that according to the amount of letters in the second argument <code>array</code> automatically adds the appropriate amount of <code>&amp;</code>s to the first row of the array:</p> <pre class="lang-lisp prettyprint-override"><code># -*- mode: snippet -*- # name: array # key: arr # expand-env: ((yas/indent-line 'fixed)) # -- \begin{array}{${1:cc}}$0 ${1:$ (let ((row "")) (dotimes (i (- (string-width yas/text) 1) row) (setq row (concat row "&amp; ")))) }\\\\ \end{array} </code></pre> <p>The manual <a href="http://capitaomorte.github.com/yasnippet/snippet-development.html#mirrors-with-transformations" rel="nofollow noreferrer">exemplifies this technique</a>. The line with <code>(yas/indent-line 'fixed)</code> is to avoid AUCTeX indenting the row. The reason for placing the exit point of the snippet (<code>$0</code>) at the end of the declaration of the array rather than at the beginning of the first row is that when placed at the beginning of the first row the exit point does not behave as expected.</p> <p>The following snippet will also add as many rows as there are columns:</p> <pre class="lang-lisp prettyprint-override"><code># -*- mode: snippet -*- # name: array # key: arr # expand-env: ((yas/indent-line 'fixed)) # -- \begin{array}{${1:cc}}$0 ${1:$ (let ((row "") (allrows "")) (dotimes (i (- (string-width yas/text) 1)) (setq row (concat row "&amp; "))) (dotimes (i (string-width yas/text) allrows) (setq allrows (concat allrows row "\\\\\\\\\n")))) }\end{array} </code></pre> <p>A problem with this snippet is that it adds <code>\\</code> even if there only one column but such arrays may be rare.</p> <p>There seems to be problems with adding lisp comments to embedded lisp code in snippets so I simply add a commented version of only the lisp code to explain it:</p> <pre class="lang-lisp prettyprint-override"><code>;; Make an empty row with as many columns as symbols in $1 (the $1 in ;; the snippet which is what yas/text refer to) (let ((row "") (allrows "")) ;; Make an empty row with as many columns as symbols in $1 (dotimes (i (- (string-width yas/text) 1)) (setq row (concat row "&amp; "))) ;; Make as many rows as symbols in $1 (dotimes (i (string-width yas/text) allrows) (setq allrows (concat allrows row "\\\\\\\\\n")))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload