A simple plugin for Obsidian that converts KaTeX notation to MathJax, ensuring seamless use of mathematical expressions copied from sources like OpenAI's ChatGPT.
ChatGPT and other platforms often render mathematical expressions using KaTeX, while Obsidian uses MathJax for mathematical notation. This discrepancy can lead to formatting issues when copying and pasting content.
This plugin eliminates the hassle by automatically converting KaTeX expressions to MathJax, making it easier to integrate ChatGPT-generated content or other KaTeX-based math into your Obsidian vault.
Default paste conversion: Automatically converts KaTeX expressions on paste (toggleable via settings).
Command Palette Actions:
Works seamlessly with clipboard operations.
Fine-grained settings to control conversion heuristics (see below).
Open Settings → Community Plugins → Convert KaTeX to MathJax to adjust:
Automatically convert KaTeX to MathJax when pasting.
Example Paste:
\(a^2 + b^2 = c^2\)
Result:
$a^2 + b^2 = c^2$
$$ … $$Ensures multi-line math environments are recognized as display math.
Example Paste:
\begin{bmatrix}1 & 0 \\ 0 & 1\end{bmatrix}
Result:
$$
\begin{bmatrix}1 & 0 \\ 0 & 1\end{bmatrix}
$$
( … ) as mathConverts outermost parentheses to inline math if contents look LaTeX-like.
Example Paste:
(x^2 + 1)
Result:
$x^2 + 1$
[ … ] as mathSame as parentheses, but for square brackets.
Example Paste:
[a,b]
Result:
$[a,b]$
Wraps common inline LaTeX tokens into $…$.
Examples
90^\circ → $90^{\circ}$\sqrt{4} → $\sqrt{4}$\frac{1}{2} → $\frac{1}{2}$x_i, y^2 → $x_i$, $y^2$$$ … $$Automatically converts isolated math-heavy lines into display math.
Example Paste:
a^2 + b^2 = c^2
Result:
$$
a^2 + b^2 = c^2
$$
Download or build the plugin files (main.js and manifest.json).
Copy them into your Obsidian vault directory:
VaultFolder/.obsidian/plugins/obsidian-convert-katex-to-mathjax/
Restart Obsidian.
Enable the plugin in Settings > Community Plugins.
Open the Command Palette (Ctrl + P / Cmd + P) and search for the following commands:
If you'd like to make changes or contribute:
git clone https://github.com/your-repo/convert-katex-to-mathjax.git
cd convert-katex-to-mathjax
npm install
npm run dev
Contributions, suggestions, and bug reports are welcome! Feel free to submit a pull request (PR) or open an issue in the repository.
If you find this plugin helpful and would like to support its development, consider buying me a coffee:
This project is licensed under the MIT License.