A plugin for Obsidian that aims to make typesetting LaTeX math as fast as handwriting.
Inspired by Gilles Castel's setup using UltiSnips.
The plugin's main feature is snippets, which help you write LaTeX quicker through shortcuts and text expansion! For example, type
- "sqx" instead of "\sqrt{x}"
- "a/b" instead of "\frac{a}{b}"
- "par x y " instead of "\frac{\partial x}{\partial y}"
See Gilles Castel's writeup for more information.
The plugin comes with a set of default snippets, loosely based on Gilles Castel's. You can modify them, remove them, and write your own.
To get started, type "dm" to enter display math mode. Try typing the following:
-
"xsr" → "x^{2}".
-
"x/y Tab" → "\frac{x}{y}".
-
"sin @t" → "\sin \theta".
Have a look at the cheatsheet for a list of commonly used default snippets.
Once these feel familiar, you can check out the default snippets for more commands. e.g.
-
"par Tab f Tab x Tab" → "\frac{\partial f}{\partial x}".
-
"dint Tab 2pi Tab sin @t Tab @t Tab" → "\int_{0}^{2\pi} \sin \theta \, d\theta".
You can also add your own snippets! For more info on writing snippets, see here. You can view snippets written by others and share your own snippets here.
Aside from snippets, the plugin also comes with several other features that aim to make writing LaTeX easier.
Lets you type "1/x" instead of "\frac{1}{x}".
For example, it makes the following expansions:
x/
→\frac{x}{}
(a + b(c + d))/
→\frac{a + b(c + d)}{}
and moves the cursor inside the brackets.
Once done typing the denominator, press Tab to exit the fraction.
While inside a matrix, array, align, or cases environment,
- Pressing Tab will insert the "&" symbol.
- Pressing Enter will insert "\\" and move to a new line.
- Pressing Shift + Enter will move to the end of the next line (which you can use to exit the matrix).
This feature must be enabled in the plugin settings.
Make your equations more readable by hiding LaTeX markup and instead displaying it in a pretty format.
For example, "\dot{x}^{2} + \dot{y}^{2}" will be displayed as "ẋ² + ẏ²".
"\sqrt{ 1-\beta^{2} }" will be displayed as "√{ 1-β² }".
To reveal the LaTeX syntax, move your cursor over it.
To make it easier to navigate and exit equations,
- Pressing Tab while the cursor is at the end of an equation will move the cursor outside the
$
symbols. - Otherwise, pressing Tab will advance the cursor to the next closing bracket:
)
,]
,}
,>
, or|
.
When your cursor is inside inline math, a popup window showing the rendered math will be displayed.
Sometimes you want to annotate math, or cancel or cross out terms. Selecting some math with the cursor and typing
- "U" will surround it with "\underbrace".
- "O" will surround it with "\overbrace".
- "C" will surround it with "\cancel".
- "K" will surround it with "\cancelto".
- "B" will surround it with "\underset".
When a snippet containing "\sum", "\int" or "\frac" is triggered, any enclosing brackets will automatically be enlarged with "\left" and "\right".
To help make your equations more readable,
- Matching brackets will be displayed in the same color.
- When your cursor is adjacent to a bracket, that bracket and its pair will be highlighted.
- When your cursor is inside brackets, the enclosing brackets will be highlighted.
The plugin also adds the following commands to the Command palette:
- Box current equation — surround the equation the cursor is currently in with a box, using "\boxed{ ... }".
- Select current equation – select the equation the cursor is currently in.
Snippets are shortcuts that allow you to insert certain text based on certain triggers. For example, the default snippet
{trigger: "@l", replacement: "\\lambda", options: "mA"}
will expand "@l" to "\lambda".
Snippets can be edited in the plugin settings. The structure of a snippet is as follows:
{
trigger: string | RegExp,
replacement: string,
options: string,
priority?: number,
description?: string,
flags?: string,
}
trigger
: The text that triggers this snippet.- Triggers can also be regular expressions. See here for more info.
replacement
: The text to replace thetrigger
with.- Replacements can also be JavaScript functions. See here for more info.
options
: See below.priority
(optional): This snippet's priority. Snippets with higher priority are run first. Can be negative. Defaults to 0.description
(optional): A description for this snippet.flags
(optional): Flags for regex snippets.
t
: Text mode. Only run this snippet outside mathm
: Math mode. Only run this snippet inside math. Shorthand for bothM
andn
M
: Block math mode. Only run this snippet inside a$$ ... $$
blockn
: Inline math mode. Only run this snippet inside a$ ... $
blockA
: Auto. Expand this snippet as soon as the trigger is typed. If omitted, the Tab key must be pressed to expand the snippetr
: Regex. Thetrigger
will be treated as a regular expressionv
: Visual. Only run this snippet on a selection. The trigger should be a single characterw
: Word boundary. Only run this snippet when the trigger is preceded (and followed by) a word delimiter, such as.
,,
, or-
.c
: Code mode. Only run this snippet inside a``` ... ```
block
Insert tabstops for the cursor to jump to by writing "$0", "$1", etc. in the replacement
.
For examples and more details on writing snippets, including regex snippets and function snippets, have a look at the documentation.
You can view snippets written by others and share your own snippets here.
Warning
Snippet files are interpreted as JavaScript and can execute arbitrary code. Always be careful with snippets shared from others to avoid running malicious code.
Trigger | Replacement |
---|---|
mk | $ $ |
dm | $$ $$ |
sr | ^{2} |
cb | ^{3} |
rd | ^{ } |
_ | _{ } |
sq | \sqrt{ } |
x/y Tab | \frac{x}{y} |
// | \frac{ }{ } |
" | \text{ } |
text | \text{ } |
x1 | x_{1} |
x,. | \mathbf{x} |
x., | \mathbf{x} |
xdot | \dot{x} |
xhat | \hat{x} |
xbar | \bar{x} |
xvec | \vec{x} |
xtilde | \tilde{x} |
xund | \underline{x} |
ee | e^{ } |
invs | ^{-1} |
When running a snippet that moves the cursor inside brackets {}, press Tab to exit the brackets.
Trigger | Replacement | Trigger | Replacement |
---|---|---|---|
@a | \alpha | eta | \eta |
@b | \beta | mu | \mu |
@g | \gamma | nu | \nu |
@G | \Gamma | xi | \xi |
@d | \delta | Xi | \Xi |
@D | \Delta | pi | \pi |
@e | \epsilon | Pi | \Pi |
:e | \varepsilon | rho | \rho |
@z | \zeta | tau | \tau |
@t | \theta | phi | \phi |
@T | \Theta | Phi | \Phi |
@k | \kappa | chi | \chi |
@l | \lambda | psi | \psi |
@L | \Lambda | Psi | \Psi |
@s | \sigma | ||
@S | \Sigma | ||
@o | \omega | ||
ome | \omega |
For Greek letters with short names (2-3 characters), just type their name, e.g. "pi" → "\pi".
- @tth05's Obsidian Completr for the basis of the tabstop code.
- Dynamic Highlights for reference.
- Quick Latex for Obsidian for inspiration.
Any contributions and PRs are welcome!
If you like this plugin and want to say thanks, you can buy me a coffee here.