This Obsidian.md plugin lets you use MathJax preambles and switch them based on note paths.
- A preamble file can be any plain text file in your vault, including
.md
,.sty
,.tex
, and more. - For each note, the preamble to be applied can be specified via either of the following ways:
- Folder preamble: Specify a preamble to be applied for all notes under a folder, similarly to Templater's folder templates. If you want a preamble to apply to the entire vault, set it as a folder preamble for the vault root ("/").
- Properties (YAML front matter): Add a link (
[[...]]
) or a path (relative to the vault root) to a preamble as "preamble" property.
- Markdown code blocks (
) and math blocks (...
$$ ... $$
) will be automanically trimmed, so it's easy to edit preambles in Obsidian's markdown editor. - When a preable file is modified, the changes will be immediately reflected to currently opened note. You don't need to reload the app to see the effect.
Note
Once a command is defined via \newcommand
, it will not be removed unless it's overwritten by another \newcommand
or \renewcommand
. If you want to remove the effect of a certain command, you need to reload the app.
So suppose you want to use different probability symbols for different paths, say,
-
$\mathbb{P} \left( \cdots \right)$ forFolder A
-
$\mathrm{Pr} \left[ \cdots \right]$ forNote B
Now you need to create two preamble files. Preambles can be any plain text files, but I recommend using markdown files because they can be easily edited from within Obsidian. In this example, the preamble for Folder A
can be written in either of the following syntaxes:
-
No formatting
\newcommand{\P}[1]{\mathbb{P} \left( #1 \right)}
-
Math block syntax
$$ \newcommand{\P}[1]{\mathbb{P} \left( #1 \right)} $$
-
Inline math syntax
$\newcommand{\P}[1]{\mathbb{P} \left( #1 \right)}$
-
Code block syntax
``` \newcommand{\P}[1]{\mathbb{P} \left( #1 \right)} ```
I recommend using either of the $...$
or $$...$$
syntaxes. See here for details.
So now, we have the following two preambles:
-
Preamble A.md
$$ \newcommand{\P}[1]{\mathbb{P} \left( #1 \right)} $$
-
Preamble B.md
$$ \newcommand{\P}[1]{\mathrm{Pr} \left[ #1 \right]} $$
Before being able to use the preambles, you need to register them in the plugin settings.
Now, recall we wanted to apply Preamble A.md
for all notes inside Folder A
. This can be achieved by setting Preamble A.md
as the folder preamble for Folder A
.
In order to apply a preamble to a single note (as opposed to an entire folder), you can add a link to the preamble as the preamble
property of that note.
This plugin supports the normal markdown views (Reading view/Live preview), embeds, hover page preview, PDF export and Canvas, but slides (the core Slides plugin and the Advanced Slides plugin) are not supported.
However, you can still manually load markdown preambles with either of the $...$
or $$...$$
syntax into your slides by embedding them. For this reason, I recommend using this preamble format.
![[preamble]]
Slide 1
---
Slide 2
---
...
Since this plugin is still in beta, it's not on the community plugin browser yet.
But you can install the latest beta release using BRAT:
- Install BRAT and enable it.
- Go to
Options
. In theBeta Plugin List
section, click on theAdd Beta plugin
button. - Copy and paste
RyotaUshio/obsidian-mathjax-preamble
in the pop-up prompt and click on Add Plugin. - (Optional but highly recommended) Turn on
Auto-update plugins at startup
at the top of the page. - Go to
Community plugins > Installed plugins
. You will find “MathJax Preamble Manager” in the list. Click on the toggle button to enable it.
Here's a list of other math-related plugins I've developed:
- LaTeX-like Theorem & Equation Referencer
- No More Flickering Inline Math
- Better Math in Callouts & Blockquotes
- Auto-\displaystyle Inline Math
If you find my plugins useful, please support my work by buying me a coffee!