Denis Bitouzé
2016-02-29 17:36:19 UTC
Hi,
I just came across the following yasnippet (see
https://groups.google.com/d/msg/smart-snippet/8Og-1U5zJ2E/3aIMTNmwrKAJ):
--8<---------------cut here---------------start------------->8---
# -*- mode: snippet -*-
# name: nxm matrix
# key: pm
# type: command
# --
(insert "\\begin{pmatrix}\n")
(let ((width (read-number "Matrix width?" 3))
(height (read-number "Matrix height?" 3))
(snippet-text ""))
(dotimes (i height)
(dotimes (j width)
(setq snippet-text (format "%s ${%d:m%d%d} %s"
snippet-text
(1+ (+ (* height i) j))
(1+ i)
(1+ j)
(if (= j (1- width))
(if (/= i (1- height)) "\\\\\\"
"")
"&"))))
(setq snippet-text (format "%s\n" snippet-text)))
(yas/expand-snippet (format "%s\\end{pmatrix}" snippet-text)))
--8<---------------cut here---------------end--------------->8---
What's nice: you are able to specify the dimensions of the matrix and
the resulting template provides placeholders.
What about similar feature provided by AUCTeX for e.g. tabulars?
All the best.
I just came across the following yasnippet (see
https://groups.google.com/d/msg/smart-snippet/8Og-1U5zJ2E/3aIMTNmwrKAJ):
--8<---------------cut here---------------start------------->8---
# -*- mode: snippet -*-
# name: nxm matrix
# key: pm
# type: command
# --
(insert "\\begin{pmatrix}\n")
(let ((width (read-number "Matrix width?" 3))
(height (read-number "Matrix height?" 3))
(snippet-text ""))
(dotimes (i height)
(dotimes (j width)
(setq snippet-text (format "%s ${%d:m%d%d} %s"
snippet-text
(1+ (+ (* height i) j))
(1+ i)
(1+ j)
(if (= j (1- width))
(if (/= i (1- height)) "\\\\\\"
"")
"&"))))
(setq snippet-text (format "%s\n" snippet-text)))
(yas/expand-snippet (format "%s\\end{pmatrix}" snippet-text)))
--8<---------------cut here---------------end--------------->8---
What's nice: you are able to specify the dimensions of the matrix and
the resulting template provides placeholders.
What about similar feature provided by AUCTeX for e.g. tabulars?
All the best.
--
Denis
Denis