Snippets sharing thread #50
Replies: 23 comments 18 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.
-
I have some snippets as follow:
|
Beta Was this translation helpful? Give feedback.
-
My favourite often-used one for switching big and small letters at the beginning of the word by typing ## after the word: |
Beta Was this translation helpful? Give feedback.
-
Equations & MathsThese snippets only work while inside a LaTeX equation. Equation AlignmentThese snippets help align LaTeX equations by replacing
Equation NumbersYou can tag your equations with numbering using
UnitsTo keep it brief, here is an example and a table summarizing the unit-related snippets.
Inserts the LaTeX code for millivolts with the
OperatorsUseful operators for presentation
Note: Ignore the lack of the ampersand, it works in Obsidian but isn't rendering properly on Gitub. Text EditingAll of the following work during normal text editing, indicated by the General Text Replacements
TODO lines
Callout Figures if you have them setup with CSS
Bonus 'Figure' CSS .callout[data-callout="figure"] {
--callout-color: 220, 220, 220;
--callout-icon: none;
.callout-content {
font-size: 0.8em;
text-align: center;
display: block !important;
margin-left: auto !important;
margin-right: auto !important;
margin: auto auto !important;
}
.callout-title {
font-size: 0.8em;
text-align: center;
display: block !important;
margin-left: auto !important;
margin-right: auto !important;
margin: auto auto !important;
}
} Repost ItemsInserting Maths EquationsQuick & easy LaTeX math equations.
CodeblocksVarious snippets to insert code blocks for programming languages with options for visual selection or direct cursor placement.
|
Beta Was this translation helpful? Give feedback.
-
Description: Create Example:
// Create n*m matrix quicklier
// (\d)(\d) --> row & column
// (y|Y|f|F|h|H|d|D|n|N) --> brack style
// lowercase <--> inline math $...$
// uppercase <--> interline math $$...$$
{trigger: /(\d)(\d)(y|Y|f|F|h|H|d|D|n|N)\3/, replacement: (match) => {
const n = match[1];
const m = match[2];
const bracket = match[3];
let arr = [];
let bracketstr; // different bracket string means different LaTeX enviroment
let output;
for (let j = 0; j < n; j++) { // Temporarily filled by 114514
arr[j] = [];
for (let i = 0; i < m; i++) {
arr[j][i] = `\${${j * m + i}:114514}`;
}
}
switch(bracket) {
case 'y': case 'Y': bracketstr = "pmatrix"; break; // 圆括号 yuan
case 'f': case 'F': bracketstr = "bmatrix"; break; // 方括号 fang
case 'h': case 'H': bracketstr = "Bmatrix"; break; // 花括号 hua
case 'd': case 'D': bracketstr = "vmatrix"; break; // 单竖线 determinant
case 'n': case 'N': bracketstr = "Vmatrix"; break; // 双竖线 norm
default: bracketstr = "shit"; break; //
}
if (bracket >= 'Z') { // lowercase <--> inline math $...$
output = arr.map(el => el.join(" & ")).join(" \\\\ ");
output = `\\begin{${bracketstr}} ${output} \\end{${bracketstr}}\${1919810:}`;
}
else { // uppercase <--> interline math $$...$$
output = arr.map(el => el.join(" & ")).join(" \\\\ \n");
output = `\\begin{${bracketstr}}\n${output} \n\\end{${bracketstr}}\${1919810:}`;
}
return output;
}, options: "rmA"}, |
Beta Was this translation helpful? Give feedback.
-
对原来的优化,只有一个字母后面跟随数字才会被转换成角标。否则很多 对选中的改颜色,默认是红色。 两种 |
Beta Was this translation helpful? Give feedback.
-
In my humble opinion, these two colors are sufficient for my requirements for math highlighting. // 1-red
// 2-orange
{trigger: "1", replacement: (sel) =>{
const color_new = "red";
const color_old_1 = "orange";
const color_prefix = /\\color{\b[^{\s{}]*\b}/g;
if (sel.match(color_prefix)) {
if (sel.includes(color_old_1))
return sel.replace(color_old_1, color_new);
sel = sel.replace(color_prefix, "");
sel = sel.replace(/{\s+(.*)\s+}/g, "$1");
return sel;
}
else {
return "{\\color{" + color_new + "} " + sel + " }";
}
}, options: "mvA"},
{trigger: "2", replacement: (sel) =>{
const color_new = "orange";
const color_old_1 = "red";
const color_prefix = /\\color{\b[^{\s{}]*\b}/g;
if (sel.match(color_prefix)) {
if (sel.includes(color_old_1))
return sel.replace(color_old_1, color_new);
sel = sel.replace(color_prefix, "");
sel = sel.replace(/{\s+(.*)\s+}/g, "$1");
return sel;
}
else {
return "{\\color{" + color_new + "} " + sel + " }";
}
}, options: "mvA"}, |
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.
-
You can share custom snippets you've written with others here!
Beta Was this translation helpful? Give feedback.
All reactions