1.9.0
Function snippets
You can now run JavaScript code in snippets! To do this, make your replacement
a function. For example, the snippet
{trigger: "date", replacement: () => (new Date().toDateString()), options: "t"},
will expand "dateTab" to the current date, such as "Mon Jan 15 2023".
Function snippets work with regex and visual snippets as well.
For regex snippets, Latex Suite will pass in the RegExpExecArray
returned by the matching regular expression to your replacement function. This lets you access the value of capture groups inside your function. For example, the regex snippet
{trigger: /iden(\d)/, replacement: (match) => {
const n = match[1];
let arr = [];
for (let j = 0; j < n; j++) {
arr[j] = [];
for (let i = 0; i < n; i++) {
arr[j][i] = (i === j) ? 1 : 0;
}
}
let output = arr.map(el => el.join(" & ")).join(" \\\\\n");
output = `\\begin{pmatrix}\n${output}\n\\end{pmatrix}`;
return output;
}, options: "mA"},
will expand "iden4" to a 4×4 identity matrix:
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{pmatrix}
. More generally, it will expand "idenN" to an N×N identity matrix.
For more information on function snippets, see the docs here. (Closes #16, thanks to #241 by @duanwilliam)
Other minor improvements
- Added new identity matrix default snippet
- Fixed/improved snippet placeholder mark decorations appearing when not necessary