Snippets sharing thread #50
Replies: 36 comments 38 replies
-
Here are my favorite custom snippets, for your pleasure. I have plenty of text mode snippets, because this plugin is useful for more than just formatting math! Text Mode Snippets
Math Mode Snippets
Feel free to use any of these, and please let me know of any bugs and edge cases! Thanks again to @artisticat1 for this plugin. |
Beta Was this translation helpful? Give feedback.
-
Here are some useful sums that I use (I like the limits above/below look) and defaulting to common sums.
For those who are tired of typing \mathbb{R}^{m \times n} or other common set dimension stuff then this is for you.
|
Beta Was this translation helpful? Give feedback.
-
include a latex font size command when beginning new latex sections
|
Beta Was this translation helpful? Give feedback.
-
Kerbless's additionsEntering math mode as quick latex for obsidian.
Functions.
|
Beta Was this translation helpful? Give feedback.
-
Basic question. Where am I supposed to write these custom snippets to have them working in my Obsidian notes? |
Beta Was this translation helpful? Give feedback.
-
Arrows in specific directions! {trigger: "lra", replacement: "\\longrightarrow", options: "mA"},
{trigger: "(nna|uua)", replacement: "\\uparrow", options: "mAr"},
{trigger: "nea", replacement: "\\nearrow", options: "mA"},
{trigger: "(eea|rra)", replacement: "\\rightarrow", options: "mAr"},
{trigger: "sea", replacement: "\\searrow", options: "mA"},
{trigger: "(ssa|dda)", replacement: "\\downarrow", options: "mAr"},
{trigger: "swa", replacement: "\\swarrow", options: "mA"},
{trigger: "(wwa|lla)", replacement: "\\leftarrow", options: "mAr"},
{trigger: "nwa", replacement: "\\nwarrow", options: "mA"}, Codeblocks! The {trigger: "cbl", replacement: "```$0\n```", options: "tA"},
{trigger: "dvcbl", replacement: "```dataview\n$0\n```", options: "tA"},
{trigger: "rscbl", replacement: "```rust\n$0\n```", options: "tA"},
{trigger: "tscbl", replacement: "```typescript\n$0\n```", options: "tA"},
{trigger: "jscbl", replacement: "```javascript\n$0\n```", options: "tA"},
{trigger: "tikzcbl", replacement: "```tikz\n\\definecolor{bg}{HTML}{1e1e1e}\n\\usetikzlibrary{arrows.meta}\n\n\\begin{document}\n\\LARGE\n\\begin{tikzpicture}[very thick,scale=2,>=Stealth]\n\n$0\n\n\\end{tikzpicture}\n\\end{document}\n```$1", options: "tA"},
{trigger: "chbl", replacement: "```tikz\n\\definecolor{bg}{HTML}{1e1e1e}\n\\usepackage{chemfig}\n\n\\begin{document}\n\\LARGE\n\n\\chemfig{$0}\n\n\\end{document}\n```$1", options: "tA"}, Miscellaneous niceties! Warnings:
{trigger: "adm", replacement: "$$\n\\begin{align}\n$0\n\\end{align}\n$$", options: "tAw"},
{trigger: "lor", replacement: "\\lor", options: "mA"},
{trigger: "land", replacement: "\\land", options: "mA"},
{trigger: "lxor", replacement: "\\oplus", options: "mA"},
{trigger: "neg", replacement: "\\neg", options: "mA"},
{trigger: "col", replacement: ":-: | ", options: "t"},
{trigger: "nin", replacement: "\\notin", options: "mA"},
{trigger: "deg", replacement: "^{\\circ}", options: "mA"},
{trigger: "fah", replacement: "\\text{F} ", options: "mA"},
{trigger: "cel", replacement: "\\text{C} ", options: "mA"},
{trigger: "mod", replacement: "\\mod ", options: "mAw"},
{trigger: "max", replacement: "\\max", options: "mAw"},
{trigger: "min", replacement: "\\min", options: "mAw"}, |
Beta Was this translation helpful? Give feedback.
-
I wanna help. How to do that |
Beta Was this translation helpful? Give feedback.
-
Hi everyone ! Special modes {trigger: "#d", replacement: "\\displaystyle ", options: "mA"},
{trigger: "#t", replacement: "\\text{$0}", options: "mA"},
{trigger: "#b", replacement: "\\mathbf{$0}", options: "mA"},
{trigger: "#n", replacement: "\\mathrm{$0}", options: "mA"}, over / underlining: {trigger: ",b", replacement: "\\bar{$0}$1", options: "mA"},
{trigger: ",h", replacement: "\\hat{$0}$1", options: "mA"},
{trigger: ",H", replacement: "\\widehat{$0}$1", options: "mA"},
{trigger: ",d", replacement: "\\dot{$0}$1", options: "mA"},
{trigger: ",t", replacement: "\\tilde{$0}$1", options: "mA"},
{trigger: ",T", replacement: "\\widetilde{$0}$1", options: "mA"},
{trigger: ",D", replacement: "\\ddot{$0}$1", options: "mA", priority: 2},
{trigger: ",v", replacement: "\\vec{$0}$1", options: "mA"},
{trigger: ",V", replacement: "\\overrightarrow{$0}$1", options: "mA"}, Sums and products {trigger: "sum", replacement: "\\sum", options: "mA"},
{trigger: "\\sum", replacement: "\\sum_{ $0 }^{ $1 }", options: "m"},
{trigger: "prod", replacement: "\\prod", options: "mA"},
{trigger: "\\prod", replacement: "\\prod_{ $0 }^{ $1 }", options: "m"},
{trigger: "lim", replacement: "\\lim_{ ${0:n} \\to ${1:\\infty} } $2", options: "m"}, Some set-theory operators {trigger: "empty", replacement: "\\emptyset", options: "m"},
{trigger: "set", replacement: "\\{ $0 \\}$1", options: "m"},
{trigger: "oo", replacement: "\\infty ", options: "m"},
{trigger: "fa", replacement: "\\forall ", options: "m"},
{trigger: "ex", replacement: "\\exists ", options: "m"},
{trigger: "sub", replacement: "\\subset ", options: "m"},
{trigger: "sub=", replacement: "\\subseteq ", options: "m"},
{trigger: "sup", replacement: "\\supset ", options: "m"},
{trigger: "\\", replacement: "\\setminus ", options: "m"},
{trigger: "sq", replacement: "\\square", options: "m"}, Overall result: my config is a lot shorter and cleaner than the default, despite having added things. And you, do you think the default has too much automatic bindings ? |
Beta Was this translation helpful? Give feedback.
-
I like my notes to never contain the latex command when there is an equivalent unicode character. For example, my notes never contain Using the unicode characters rather than the command creates identical output for mathjax, katex, temml, and latex itself using the unicode-math package. Using unicode characters means that the conceal functionality creates less distraction when navigating through an equation, because most of the conceal "replacements" are already used directly in the note. To input the unicode characters I have some (messy) snippets to replace "\alpha" with "α", etc. I also have some (messy) replacements for the greek bold characters, so again I can use only one character. However, (and here is my point): Does anyone else have snippets I can use that work with unicode characters and would like to share, as it'll be a while before I can sort my snippets out, and would prefer to use the work of someone who has already done this. |
Beta Was this translation helpful? Give feedback.
-
I think I posted my snippet as an issue haha sorry for the inconvenience {trigger: "Ntor", replacement: "<${0:x}{1}, ${0:x}{2}, \cdots ,${0:x}_{n}>", options: "mA"} I use this one to denote vectors in n dimension spaces |
Beta Was this translation helpful? Give feedback.
-
Just beginning to experiment with regex, decided to create a replacement for a column vector using dots as separation instead of tabbing through each item.
Would it be possible to generalize this to an N dimensional vector without having to make each case a separate snippet? |
Beta Was this translation helpful? Give feedback.
-
Questions using a callout, checkbox and tag:
Solutions using a collapsable callout
|
Beta Was this translation helpful? Give feedback.
-
Repeated indicies to write subscripts
|
Beta Was this translation helpful? Give feedback.
-
I have no clue what mk and dm stand for so I changed how to enter math mode. Type one $ for inline, then another $ for Block.
|
Beta Was this translation helpful? Give feedback.
-
Hi there! |
Beta Was this translation helpful? Give feedback.
-
Here are some of my snippets that I find cool: Alignment related stuff{trigger: "adm", replacement: "$$\n\\begin{flalign}\n$0&&\n\\end{flalign}\n$$", options: "tAw"}, // start a Display math block with left alignment
{trigger: "A", replacement: "\\begin{flalign}\n${VISUAL}&&\n\\end{flalign}", options: "mA"}, // align visual
{trigger: "flalign", replacement: "\\begin{flalign}\n$0\n\\end{flalign}", options: "mA"}, // just a flalign Modes{trigger: "M", replacement: "$${VISUAL}$", options: "tA"}, // change display mode for visual
{trigger: "D", replacement: "$$${VISUAL}$$", options: "tA"}, Tag related stuffIn our lectures, we often use LaTeX tags in order to reuse stuff, so I added snippets to quickly do that // enter Display Math mode with a tag and a ^ thingy attached to it
{trigger: "tdm", replacement: "$$\n$1\n\\tag{$0}$$\n^$0", options: "tA"},
// add a tag (will replace "tag" in math mode with "\tag{type here}"
{trigger: "tag", replacement: "\\tag{$0}$1", options: "mA"},
// add an equivalent to a tag in text mode (will just type "(number)" and add a ^ thingy to it)
{trigger: "((\\d)+)tg", replacement: "$([[0]])$^[[0]]", options: "rA"},
// easily link tags (will create a link to a ^ thingy)
{trigger: "((\\d)+)lk", replacement: "\[\[#^[[0]]\]\]", options: "rA"}, Math operations{trigger: "ulim", replacement: "\\overline{\\lim}_{ ${0:n} \\to ${1:\\infty} } $2", options: "mA"}, // upper limit
{trigger: "llim", replacement: "\\underline{\\lim}_{ ${0:n} \\to ${1:\\infty} } $2", options: "mA"}, // lower limit
{trigger: "nthr", replacement: "\\sqrt[${0:n}]{ $1 }$2", options: "mA"}, // nth root
{trigger: "nthd", replacement: "{$0}^{(${1:n})}", options: "mA"}, // nth derivative Other symbols{trigger: "ne\\xi sts", replacement: "\\ \\ \\nexists", options: "mA", priority: 1}, // does not exist
{trigger: "qed", replacement: "$\\blacksquare$", options: "t"}, // q.e.d., uses amsmath
{trigger: "bs", replacement: "\\ \\ ", options: "m"}, // big space lmao
{trigger: "<=>", replacement: "\\iff", options: "mA"}, // \iff
{trigger: "seq", replacement: "\\{ $0 \\}$1", options: "mA"}, // sequence |
Beta Was this translation helpful? Give feedback.
-
Some useful snippets I use Most of these snippets use regex as the trigger, and js as the replacement, returning tabstops, as I have no idea how to achieve what I want otherwise. Though, as I'm not terribly well versed in both regex and js, someone can definitely improve on these MatricesCreate an n by m matrix, use tab to go to the next tabstop {
trigger: /(\d)(\d)([p|b|B|v|V]?)mat/,
replacement: (match) => {
const n = match[1], m = match[2], c = match[3];
let arr = [];
for (let j = 0; j < n; j++) {
arr[j] = [];
for (let i = 0; i < m; i++) {
arr[j][i] = `\${${i + j * m}:${String.fromCharCode(97 + i + j * m)}}`;
}
}
let output = arr.map((el) => el.join(" & ")).join(" \\\\\n");
output = `\\begin{${c}matrix}\n${output} \n\\end{${c}matrix}`;
return output;
},
options: "MA",
description: "N x M matrix",
},
{
trigger: /(\d)(\d)([p|b|B|v|V]?)mat/,
replacement: (match) => {
const n = match[1], m = match[2], c = match[3];
let arr = [];
for (let j = 0; j < n; j++) {
arr[j] = [];
for (let i = 0; i < m; i++) {
arr[j][i] = `\${${i + j * m}:${String.fromCharCode(97 + i + j * m)}}`;
}
}
let output = arr.map((el) => el.join(" & ")).join(" \\\\ ");
output = `\\begin{${c}matrix} ${output} \\end{${c}matrix}`;
return output;
},
options: "nA",
description: "N x M matrix",
}, So when I write \begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{bmatrix} And \begin{matrix}
a & b & c & d \\
e & f & g & h
\end{matrix} It has a few bugs, such as not supporting more than 26 elements (I could fix it, but decided not to because I don't usually see matrices bigger than 5 by 5, which is 25 elements) Subscripts/Superscripts{
trigger: /\^([a-zA-Z0-9]{2,})/,
replacement: (match) => {
return `\^{${match[1]}\$0}`;
},
options: "rmA",
},
{
trigger: "_([a-zA-Z0-9]{2,})",
replacement: (match) => {
return `_{${match[1]}\$0}`;
},
options: "rmA",
}, It allows single character after { trigger: "++", replacement: "^+", options: "mA" },
{ trigger: "--", replacement: "^-", options: "mA" }, Useful when working with limits nth root{
trigger: "([0-9|n|m|k]{1,})sq",
replacement: (match) => {
return `\\sqrt[${match[1]}]{ $0 }`;
},
options: "rmA",
},
{
trigger: ";sq",
replacement: (match) => {
return `\\sqrt[\$0]{ $1 }`;
},
options: "rmA",
},
Entering nth root with the default snippet is kinda clunky Arrows{ trigger: "->", replacement: "\\rightarrow", options: "mA" },
{ trigger: "<-", replacement: "\\leftarrow", options: "mA" },
{ trigger: "<->", replacement: "\\leftrightarrow ", options: "mA" },
{ trigger: "-^", replacement: "\\uparrow", options: "mA" },
{ trigger: "-v", replacement: "\\downarrow", options: "mA" },
{ trigger: "^-v", replacement: "\\updownarrow", options: "mA" },
{ trigger: "v-^", replacement: "\\updownarrow", options: "mA" },
{ trigger: "=>", replacement: "\\Rightarrow", options: "mA" },
{ trigger: "=<", replacement: "\\Leftarrow", options: "mA" },
{ trigger: "<=>", replacement: "\\Leftrightarrow", options: "mA" },
{ trigger: "\\leq>", replacement: "\\Leftrightarrow", options: "mA" },
{ trigger: "=^", replacement: "\\Uparrow", options: "mA" },
{ trigger: "=v", replacement: "\\Downarrow", options: "mA" },
{ trigger: "^=v", replacement: "\\Updownarrow", options: "mA" },
{ trigger: "v=^", replacement: "\\Updownarrow", options: "mA" },
{ trigger: "|->", replacement: "\\mapsto", options: "mA" },
{ trigger: "|-->", replacement: "\\longmapsto", options: "mA" },
{ trigger: "/>", replacement: "\\nearrow", options: "mA" },
//{trigger: "/^", replacement: "\\nearrow", options: "mA"},
{ trigger: "\\>", replacement: "\\searrow", options: "mA" },
//{trigger: "\\v", replacement: "\\searrow", options: "mA"},
{ trigger: "</", replacement: "\\swarrow", options: "mA" },
//{trigger: "v/", replacement: "\\swarrow", options: "mA"},
{ trigger: "<\\", replacement: "\\nwarrow", options: "mA" },
//{trigger: "^\\", replacement: "\\nwarrow", options: "mA"}, I don't use most of these, but might as well do everything in one go |
Beta Was this translation helpful? Give feedback.
-
This is just the idea. For real life shortcuts (that I use), you can see one of my replies to this message (I’ll try to keep the reply up-to-date with what I use). I made this JS + visual shortcut to call sympy : {
trigger: "s",
replacement: (sel) => {
return require('child_process').execSync(`python -c "
#import numpy as np
import sys
sys.set_int_max_str_digits(2**31-1)
# This is like running sympy.init_session(), but without the printed lines
from sympy import *
a, b, c, d, x, y, z, t = symbols('a b c d x y z t')
k, m, n, o, p, q, r, s = symbols('k m n o p q r s', integer=True)
f, g, h = symbols('f g h', cls=Function)
init_printing()
pl = lambda x: print(latex(x)) # Alias to print in LaTeX format
pl(${sel})
# Alternative versions
# pl(factor(${sel}))
# pl(expand(${sel}))
# pl(simplify(${sel}))
"`).toString().trim()
},
options: "v"
} For example, you can type « This can also lead to more specific shortcuts like one to call I also recommend to use the |
Beta Was this translation helpful? Give feedback.
-
I couldn't notice that I had written a whole set of arrow snippets in {trigger: "lla", replacement: "$\\longleftarrow$ ", options: "tA"}, // <--
{trigger: "Lla", replacement: "$\\Longleftarrow$ ", options: "tA"}, // <==
{trigger: "lra", replacement: "$\\longrightarrow$ ", options: "tA"}, // -->
{trigger: "Lra", replacement: "$\\Longrightarrow$ ", options: "tA"}, // ==>
{trigger: "<--", replacement: "$\\longleftarrow$ ", options: "t"}, // <--
{trigger: "<==", replacement: "$\\Longleftarrow$ ", options: "t"}, // <==
{trigger: "-->", replacement: "$\\longrightarrow$ ", options: "t"}, // -->
{trigger: "==>", replacement: "$\\Longrightarrow$ ", options: "t"}, // ==>
{trigger: "llra", replacement: "$\\longleftrightarrow$ ", options: "tA"}, // <-->
{trigger: "Llra", replacement: "$\\Longleftrightarrow$ ", options: "tA"}, // <==>
{trigger: "<-->", replacement: "$\\longleftrightarrow$ ", options: "t"}, // <-->
{trigger: "<==>", replacement: "$\\Longleftrightarrow$ ", options: "t"}, // <==>
{trigger: "(!|N|n)lla", replacement: "$\\cancel{ \\longleftarrow }$ ", options: "rtA"}, // ⛔<--
{trigger: "(!|N|n)Lla", replacement: "$\\cancel{ \\Longleftarrow }$ ", options: "rtA"}, // ⛔<==
{trigger: "(!|N|n)lra", replacement: "$\\cancel{ \\longrightarrow }$ ", options: "rtA"}, // ⛔-->
{trigger: "(!|N|n)Lra", replacement: "$\\cancel{ \\Longrightarrow }$ ", options: "rtA"}, // ⛔==>
{trigger: "(!|N|n)llra", replacement: "$\\cancel{ \\longleftrightarrow }$ ", options: "rtA"}, // ⛔<-->
{trigger: "(!|N|n)Llra", replacement: "$\\cancel{ \\Longleftrightarrow }$ ", options: "rtA"}, // ⛔<==> {trigger: ";la", replacement: "\\leftarrow", options: "mA"}, // ->
{trigger: "lla", replacement: "\\longleftarrow", options: "mA"}, // -->
{trigger: "Lla", replacement: "\\Longleftarrow", options: "mA"}, // ==>
{trigger: ";ra", replacement: "\\rightarrow", options: "mA"}, // <-
{trigger: "lra", replacement: "\\longrightarrow", options: "mA"}, // <--
{trigger: "Lra", replacement: "\\Longrightarrow", options: "mA"}, // <==
{trigger: ";lra", replacement: "\\leftrightarrow", options: "mA"}, // <->
{trigger: "llra", replacement: "\\longleftrightarrow", options: "mA"}, // <-->
{trigger: "Llra", replacement: "\\Longleftrightarrow", options: "mA"}, // <==>
{trigger: "(!|N|n)Lra", replacement: "\\cancel{ \\Longrightarrow } ", options: "rmA"}, // ⛔==>
{trigger: "(!|N|n)Lla", replacement: "\\cancel{ \\Longleftarrow } ", options: "rmA"}, // ⛔<==
{trigger: "(!|N|n)Llra", replacement: "\\cancel{ \\Longleftrightarrow } ", options: "rmA"}, // ⛔<==>
{trigger: "(!|N|n)lra", replacement: "\\cancel{ \\longrightarrow } ", options: "rmA"}, // ⛔-->
{trigger: "(!|N|n)lla", replacement: "\\cancel{ \\longleftarrow } ", options: "rmA"}, // ⛔<--
{trigger: "(!|N|n)llra", replacement: "\\cancel{ \\longleftrightarrow } ", options: "rmA"}, // ⛔<==> These snippets are time-saving, concise and of high-efficiency, of which I can't help using arrows to substitue other frequently-used "conjuction-words" (so, because, and then, that's why, which is (not) equivalent/equal to...). So, what kind of "wastes" time is that I have to change the direction and "double-single line" style of the existing arrow. Preliminary and simple though, the following snippets can change the direction and "double-single line" style of selected arrow by only pressing 1-2 keys. {trigger: "r", replacement: (sel) =>{
if (sel.match("longright")) {sel = sel.replace("longright","Longright"); return sel; }
if (sel.match("Longright")) {sel = sel.replace("Longright","longright"); return sel; }
sel = sel.replace("Left","Right");
sel = sel.replace("left","right");
return sel;
}, options: "mvA"},
{trigger: "l", replacement: (sel) =>{
if (sel.match("longleft")) {sel = sel.replace("longleft","Longleft"); return sel; }
if (sel.match("Longleft")) {sel = sel.replace("Longleft","longleft"); return sel; }
sel = sel.replace("Right","Left");
sel = sel.replace("right","left");
return sel;
}, options: "mvA"}, |
Beta Was this translation helpful? Give feedback.
-
Combining with Highlightr plugin, I wrote https://gist.github.com/YaoYYoung/926e9152ac93857fda874050a9d9ee6e But the issue in this file is that the constant values in similar function snippets are the same, causing snippet lines to expand unexpectedly, which I am working to resolve. Here is a demo video: emoji-highlight.mp4 |
Beta Was this translation helpful? Give feedback.
-
Giga Align Snippet: Because Regular Alignment is for MortalsBehold, my magnum opus: the Giga Align Snippet. Why settle for basic alignment when you can have a snippet that over-engineers the process to the point of existential dread? This snippet doesn't just align equations—it aligns your soul (or at least tries to). {
trigger: "A",
replacement: (sel) =>
{
const config = {
operators:
{
basic: ['=', '>', '<'],
latex: ['\\geq', '\\iff', '\\impliedby', '\\implies', '\\in', '\\leq', '\\neq'],
special: ['\\int', '\\prod', '\\sum']
},
templates:
{
align: (content) => `$$\n\\begin{align}\n${content}\n\\end{align}\n$$`
}
};
const utils = {
getAllOperators()
{
return [...config.operators.basic, ...config.operators.latex];
},
createOperatorPattern()
{
const operators = this.getAllOperators()
.map(op => op.replace(/\\/g, '\\\\'));
return new RegExp(`(?:\\$\\$[^$]+\\$\\$|\\$[^$]+\\$)`, 'g');
},
isWithinSpecialOperator(str, pos)
{
return config.operators.special.some(op =>
{
const opIndex = str.lastIndexOf(op, pos);
if (opIndex === -1) return false;
let bracketCount = 0;
for (let i = opIndex; i < str.length; i++)
{
if (str[i] === '{') bracketCount++;
if (str[i] === '}') bracketCount--;
if (bracketCount === 0 && i >= pos) return true;
}
return false;
});
},
formatEquation(equation)
{
equation = equation.replace(/^\$\$?\s*|\s*\$\$?$/g, '');
const lines = equation.split(/(?:\\\\)?\s*\n\s*|\s*\\\\\s*/);
let result = lines.map(line =>
{
let processed = line.trim();
let firstOp = null;
let firstOpIndex = Infinity;
for (const op of this.getAllOperators())
{
const index = processed.indexOf(op);
if (index !== -1 && index < firstOpIndex)
{
firstOpIndex = index;
firstOp = op;
}
}
if (firstOp && !this.isWithinSpecialOperator(processed, firstOpIndex))
{
processed = processed.replace(firstOp, `&${firstOp}`);
}
return processed;
});
return result;
},
};
const processEquations = (sel) =>
{
const pattern = utils.createOperatorPattern();
const matches = sel.match(pattern);
if (!matches) return null;
const allEquations = matches.flatMap(eq => utils.formatEquation(eq));
const formattedEquations = allEquations.filter(eq => eq.trim())
.map((eq, index, arr) => `${eq}${index < arr.length - 1 ? ' \\\\' : ''}`)
.join('\n');
return config.templates.align(formattedEquations);
};
return processEquations(sel);
},
options: "tvA"
} Features:
Usage:
Disclaimer:
Example:Giga Mess Result: |
Beta Was this translation helpful? Give feedback.
-
Making square root a little more ergonomic (IMHO) {
trigger: "([2-9|n|m|k]?)sqr", replacement: (match) => {
let order = match[1];
if (order != "") order = `[${order}]`;
return "\\sqrt" + order + "{$0}";
},
options: "rmA"
}, |
Beta Was this translation helpful? Give feedback.
-
This in my humble opinion, is the peak of LaTeX (and maybe even society as a whole): {trigger: "\\sus", replacement: "ඞ", options: "mA"} |
Beta Was this translation helpful? Give feedback.
-
My logic operator snippets: {trigger: "ng", replacement: "\\neg", options: "mA"},
{trigger: "nt", replacement: "\\lnot", options: "mA"},
{trigger: "land", replacement: "\\wedge", options: "mA"},
{trigger: "nand", replacement: "\\barwedge", options: "mA"},
{trigger: "lor", replacement: "\\vee", options: "mA"},
{trigger: "nor", replacement: "\\bar{\\vee}", options: "mA"},
{trigger: "xor", replacement: "\\barvee", options: "mA"},
{trigger: "xnor", replacement: "\\bar{\\veebar}", options: "mA"},``` |
Beta Was this translation helpful? Give feedback.
-
Ok, this is it. I'm fed up of having to go to the config and scroll all the way to the place where that single snippet i'm testing is. |
Beta Was this translation helpful? Give feedback.
-
Tables with TikzJaxFor those using TikZJax to quickly create a table. // Create an n*m table
// Example: !tikztable23 -> creates a 2*3 table
// Use Tab to go to next cell
// For different line lengths and cell sizes, change text width, text depth, and text height parameters
{trigger: /!tikztable(\d)(\d)/, replacement: (match) => {
const cols = parseInt(match[1], 10);
const rows = parseInt(match[2], 10);
let matrixContent = [];
for (let r = 0; r < rows; r++) {
let rowCells = [];
for (let c = 0; c < cols; c++) {
rowCells.push(`\${${r * cols + c + 1}:x}`);
}
matrixContent.push(rowCells.join(" & "));
}
const matrixStr = matrixContent.join(" \\\\\n ") + " \\\\";
let horizontalLines = [];
for (let r = 1; r < rows; r++) {
horizontalLines.push(`\\draw ([xshift=-.5\\pgflinewidth]mat-${r}-1.south west) -- ([xshift=-.5\\pgflinewidth]mat-${r}-${cols}.south east);`);
}
let verticalLines = [];
for (let c = 1; c < cols; c++) {
verticalLines.push(`\\draw ([yshift=.5\\pgflinewidth]mat-1-${c}.north east) -- ([yshift=.5\\pgflinewidth]mat-${rows}-${c}.south east);`);
}
const code = `\\usetikzlibrary{matrix}
\\tikzset{
table/.style={
matrix of nodes,
row sep=-\\pgflinewidth,
column sep=-\\pgflinewidth,
nodes={rectangle,text width=3em,align=center},
text depth=1.25ex,
text height=2.5ex,
nodes in empty cells
},
}
\\begin{document}
\\begin{tikzpicture}
\\matrix (mat) [table,
%Change width for specific columns here
%column 1/.style={nodes={text width=3em}},
%column 2/.style={nodes={text width=20em}}
]
{
${matrixStr}
};
${horizontalLines.join("\n")}
${verticalLines.join("\n")}
\\end{tikzpicture}
\\end{document}`;
return "```tikz\n" + code + "\n```";
}, options: "rA"}, Costum colored underline and overbracePrinting notes with colored underlines etc with the equation above colored white makes them impossible to read. These snippets are workarounds so that the default obsidian colored equation is untouched, resulting in readable PDFs. Underline: mark eq and press {trigger: "W", replacement: "\\underset{\\color{${0:red}} \\displaystyle ${1:x+y} }{ \\underset{\\color{${2:red}}\\rule{${3:1.4}cm}{0.5pt}}{${VISUAL}}}$4", options: "mA"}, Overbrace: mark eq and press {trigger: "Q", replacement: "\\overset{ \\color{orange} \\displaystyle \\overbrace{ \\phantom{\\rule{${0:1.4}cm}{0.5pt}} }^{^{\\displaystyle ${1:x}}} }{ ${VISUAL} }$2", options: "mA"}, Change the first argument of \mathbb and \mathcal{trigger: /([A-Z])\1/, replacement: "\\mathbb{[[0]]}", options: "mA"},
{trigger: /\\mathbb{([A-Z])}\1/, replacement: "\\mathcal{[[0]]}", options: "mA"}, Pressing a capital letter, e.g. |
Beta Was this translation helpful? Give feedback.
-
I have a ton of custom snippets on my dotfiles repo, stored in their own files to be more distinct from the default presets. Some highlights: Quotes{trigger: "(?<=\n)\"", replacement: "\\text{$0 } $1", options: "mrA"}, // Text at the beginning of a line
{trigger: "\"", replacement: "\\text{ $0 } $1", options: "mA", priority: -1}, // Text that isn't at the beginning of a line This lets me type something like this:
And it becomes: \text{My favorite fraction is } \dfrac{1}{3}\text{ because I think it's neat } The two different snippets means there's no leading space at the beginning of a line, thanks to regex. Easy block letters{ trigger: /([A-GI-KM-Z])\1/, replacement: "\\mathbb{[[0]]}", options: "mA" }, This means that if I type any two of the same capital letter in succession, it automatically uses Types of setsIn a similar vein to the last one, this means I can immediately say some type of set - like positive real numbers, or { trigger: /\\mathbb{(\w)}([\+\-\d])/, replacement: "\\mathbb{[[0]]}^[[1]]", options: "mA" }, Multiple linesI like using {trigger: "ml", replacement: "$$\n\\begin{gather}\n$0\n\\end{gather}\n$$$1", options: "tAw" }, DerivativesThis gives me automatic derivative fractions, when I write something like {trigger: /dd([a-ce-z])/, replacement: "\\dfrac{d}{d[[0]]}\\left[ $0 \\right]$1", options: "mA"},
{trigger: /d([a-ce-z])d([a-ce-z])/, replacement: "\\dfrac{d[[0]]}{d[[1]]}$1", options: "mA"}, Nth rootVery simple one, but I find it super useful: it means { trigger: /(\d)rt/, replacement: "\\sqrt[[[0]]]{$0} $1", options: "mA"}, // Nth root While I'm here, I'll refer you to #359, which I cloned locally and use daily. I absolutely recommend it! And, if you want to see any of my other snippets, check the repo! |
Beta Was this translation helpful? Give feedback.
-
Copy Links Easier I write weekly reports, which contain many website links. Therefore, I need to easily copy and open (manipulate) these links in at least four formats:
Here are snippets: {trigger: "c", replacement: sel => {
// if selected texts contain link, then pressing `c` will copy the link;
let out_link = /((?<!!)\[(.*?)\]\((.*?)\))/g;
let inlink_1 = /\[\[([^\]]*?)\|([^\]]*?)\]\]/g;
let inlink_2 = /(\[\[([^\]]*?)\]\])/g;
let purelink = /((https?|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|])/g;
if (sel.match(out_link)) { navigator.clipboard.writeText(String(sel.match(out_link))); return sel; }
if (sel.match(inlink_1)) { navigator.clipboard.writeText(String(sel.match(inlink_1))); return sel; }
if (sel.match(inlink_2)) { navigator.clipboard.writeText(String(sel.match(inlink_2))); return sel; }
if (sel.match(purelink)) { navigator.clipboard.writeText(String(sel.match(purelink))); return sel; }
// if not, then do nothing.
return sel;
}, options: "vtA"}, {trigger: "e", replacement: sel => {
if (sel = sel.replaceAll(/\$(\d.*?)\$/g, "\${{ $1 }}\$$")) ; // sensitive_math
// if selected texts contain links, then pressing `e` will open these links;
let purelink = /((https?|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|])/g;
let pureLinks = sel.matchAll(purelink) || [];
pureLinks.forEach(url => window.open(url[0])); // [0] <-> url
// if not, then do nothing.
return sel;
}, options: "v"}, |
Beta Was this translation helpful? Give feedback.
-
"smart" math block insertion:
{trigger: "\\math", replacement: (sel) => {
const editor = app.workspace.activeEditor.editor;
const cursor = editor.getCursor();
const currentLine = editor.getLine(cursor.line);
const lines = currentLine.split('\n');
let indentStr = '';
lines.map(line => {
// Match all leading groups of four spaces OR tabs
const m = line.match(/^(( {4}|\t)+)/);
if (m) {
indentStr += m[0]; // append all matched indent characters
}
if (/^>/.test(line.trimStart())) {
indentStr += '>'; // add one > to indentStr
}
if (/^-/.test(line.trimStart())) {
indentStr += '\t'; // add one tab to indentStr
}
return line; // no change if no indent
})
let output = `\n${indentStr}$$\t\n${indentStr}$0 \n${indentStr}$$$1`;
return output;
}, options: "tA"}, |
Beta Was this translation helpful? Give feedback.
-
I made a snippet for automatic elementary row operations. Row Swap
Performing an operation like Example: Typing this:
...and pressing
Row Addition
Performing an operation like Example: Typing this:
...and pressing
Row Multiplication
Similarly, to multiply a row by a scalar, you can type Example: Typing this:
...and pressing
Handling Variables and Complex ExpressionsThe snippets are intelligent: if they encounter variables or complex LaTeX commands within the matrix, they will fall back to showing the formula instead of the calculated value.
Snippet CodeClick to view the snippet code{
"trigger": /(\\begin{pmatrix}((?!\\end{pmatrix})[\s\S])*\\end{pmatrix})\s*rowswap(\d+)\s*,\s*(\d+)/,
"replacement": function(match) {
function parseMatrix(matrixString) {
const content = matrixString.replace(/\\begin{pmatrix}|\\end{pmatrix}/g, '').trim();
if (!content) return [];
return content.split(/\\\\/g).map(row => row.trim().split('&').map(cell => cell.trim()));
}
function formatMatrix(matrixArray) {
const body = matrixArray.map(row => row.join(' & ')).join(' \\\\\n\t');
return `\\begin{pmatrix}\n\t${body}\n\\end{pmatrix}`;
}
const originalMatrixStr = match[1];
const i_one_based = parseInt(match[3]);
const j_one_based = parseInt(match[4]);
const i = i_one_based - 1;
const j = j_one_based - 1;
const matrix = parseMatrix(originalMatrixStr);
if (i >= 0 && j >= 0 && i < matrix.length && j < matrix.length) {
[matrix[i], matrix[j]] = [matrix[j], matrix[i]];
}
const arrow = `\\xrightarrow{R_{${i_one_based}} \\leftrightarrow R_{${j_one_based}}}`;
const newMatrix = formatMatrix(matrix);
return `${originalMatrixStr} \n${arrow}\n${newMatrix}`;
},
"options": "rm",
"description": "After a pmatrix, type rowswap(i),(j) to automatically perform the swap."
},
{
"trigger": /(\\begin{pmatrix}((?!\\end{pmatrix})[\s\S])*\\end{pmatrix})\s*rowadd(\d+)\s*([+-])\s*(.+?)\s*\*\s*(\d+)/,
"replacement": function(match) {
function parseMatrix(matrixString) {
const content = matrixString.replace(/\\begin{pmatrix}|\\end{pmatrix}/g, '').trim();
if (!content) return [];
return content.split(/\\\\/g).map(row => row.trim().split('&').map(cell => cell.trim()));
}
function formatMatrix(matrixArray) {
const body = matrixArray.map(row => row.join(' & ')).join(' \\\\\n\t');
return `\\begin{pmatrix}\n\t${body}\n\\end{pmatrix}`;
}
// Helper to check if a string is a simple number
function parseNumber(str) {
const s = str.trim();
if (s !== '' && isFinite(s)) {
return Number(s);
}
return NaN;
}
const originalMatrixStr = match[1];
const i_one_based = parseInt(match[3]);
const sign = match[4];
const scalar = match[5].trim();
const j_one_based = parseInt(match[6]);
const i = i_one_based - 1;
const j = j_one_based - 1;
const matrix = parseMatrix(originalMatrixStr);
if (i >= 0 && j >= 0 && i < matrix.length && j < matrix.length && i !== j) {
const numScalar = parseNumber(scalar);
matrix[i] = matrix[i].map((destCell, colIndex) => {
const sourceCell = matrix[j][colIndex];
const numDest = parseNumber(destCell);
const numSource = parseNumber(sourceCell);
// If all parts are numbers, calculate the result
if (!isNaN(numDest) && !isNaN(numSource) && !isNaN(numScalar)) {
const result = (sign === '+') ? (numDest + numScalar * numSource) : (numDest - numScalar * numSource);
return result.toString();
} else {
// Otherwise, build the string expression
if (sourceCell.trim() === '0') return destCell;
if (destCell.trim() === '0') {
const sourceDisplay = (sourceCell.includes('+') || sourceCell.includes('-')) ? `(${sourceCell})` : sourceCell;
return (sign === '+') ? `${scalar} \\cdot ${sourceDisplay}` : `-${scalar} \\cdot ${sourceDisplay}`;
}
const destDisplay = (destCell.includes('+') || destCell.includes('-')) ? `(${destCell})` : destCell;
const sourceDisplay = (sourceCell.includes('+') || sourceCell.includes('-')) ? `(${sourceCell})` : sourceCell;
return `${destDisplay} ${sign} ${scalar} \\cdot ${sourceDisplay}`;
}
});
}
const arrow = `\\xrightarrow{R_{${i_one_based}} \\to R_{${i_one_based}} ${sign} ${scalar}R_{${j_one_based}}}`;
const newMatrix = formatMatrix(matrix);
return `${originalMatrixStr} \n${arrow}\n${newMatrix}`;
},
"options": "rm",
"description": "After a pmatrix, type rowadd(i)+k*(j) to automatically perform the addition."
},
{
"trigger": /(\\begin{pmatrix}((?!\\end{pmatrix})[\s\S])*\\end{pmatrix})\s*rowmult(\d+)\s*\*\s*([^ \t\n\r]+)/,
"replacement": function(match) {
function parseMatrix(matrixString) {
const content = matrixString.replace(/\\begin{pmatrix}|\\end{pmatrix}/g, '').trim();
if (!content) return [];
return content.split(/\\\\/g).map(row => row.trim().split('&').map(cell => cell.trim()));
}
function formatMatrix(matrixArray) {
const body = matrixArray.map(row => row.join(' & ')).join(' \\\\\n\t');
return `\\begin{pmatrix}\n\t${body}\n\\end{pmatrix}`;
}
// Helper to check if a string is a simple number
function parseNumber(str) {
const s = str.trim();
if (s !== '' && isFinite(s)) {
return Number(s);
}
return NaN;
}
const originalMatrixStr = match[1];
const i_one_based = parseInt(match[3]);
const scalar = match[4].trim();
const i = i_one_based - 1;
const matrix = parseMatrix(originalMatrixStr);
if (i >= 0 && i < matrix.length) {
const numScalar = parseNumber(scalar);
matrix[i] = matrix[i].map(cell => {
const numCell = parseNumber(cell);
// If both parts are numbers, calculate the result
if (!isNaN(numCell) && !isNaN(numScalar)) {
return (numCell * numScalar).toString();
} else {
// Otherwise, build the string expression
if (cell.trim() === '0') return '0';
const cellDisplay = (cell.includes('+') || cell.includes('-')) ? `(${cell})` : cell;
return `${scalar} \\cdot ${cellDisplay}`;
}
});
}
const arrow = `\\xrightarrow{R_{${i_one_based}} \\to ${scalar}R_{${i_one_based}}}`;
const newMatrix = formatMatrix(matrix);
return `${originalMatrixStr} \n${arrow}\n${newMatrix}`;
},
"options": "rm",
"description": "After a pmatrix, type rowmult(i)*k to automatically perform the multiplication."
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
You can share custom snippets you've written with others here!
Beta Was this translation helpful? Give feedback.
All reactions