# LaTeX and TikZ Renderer for Obsidian [](https://github.com/agostino-code/obsidian-tikz/releases) [](https://opensource.org/licenses/MIT) [](https://obsidian.md) Render **any LaTeX and TikZ diagram** directly inside your [Obsidian](https://obsidian.md) notes using your **local LaTeX installation** (`latex`, `dvisvgm`). Unlike WebAssembly-based solutions with limited package support, this plugin invokes your system's native TeX distribution. This means you can use **any package installed on your computer** — including `pgfplots`, `circuitikz`, `chemfig`, `tikz-cd`, `forest`, `quantikz`, and more!
---
### 2. Electronic Circuits (`circuitikz`)
````latex
```tikz
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[american, voltage shift=0.5]
\draw (0,0)
to[isource, l=$I_0$, v=$V_0$] (0,3)
to[short, -*, i=$I_0$] (2,3)
to[R=$R_1$, i>_=$i_1$] (2,0) -- (0,0);
\draw (2,3) -- (4,3)
to[R=$R_2$, i>_=$i_2$] (4,0)
to[short, -*] (2,0);
\end{circuitikz}
\end{document}
```
````
---
### 3. 3D Function Plots (`pgfplots`)
````latex
```tikz
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colormap/viridis]
\addplot3[surf, samples=18, domain=-3:3] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{document}
```
````
---
### 4. Commutative Diagrams (`tikz-cd`)
````latex
```tikz
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
T \arrow[drr, bend left, "x"] \arrow[ddr, bend right, "y"] \arrow[dr, dotted, "{(x,y)}" description] & & \\
K & X \times_Z Y \arrow[r, "p"] \arrow[d, "q"] & X \arrow[d, "f"] \\
& Y \arrow[r, "g"] & Z
\end{tikzcd}
\end{document}
```
````
---
### 5. Chemical Structures (`chemfig`)
````latex
```tikz
\usepackage{chemfig}
\begin{document}
\chemfig{[:-90]HN(-[::-45](-[::-45]R)=[::+45]O)>[::+45]*4(-(=O)-N*5(-(<:(=[::-60]O)-[::+60]OH)-(<[::+0])(<:[::-108])-S>)--)}
\end{document}
```
````
---
## 🔧 Troubleshooting
### Windows: "MiKTeX session could not be initialized"
If you encounter a MiKTeX session initialization error on Windows, register the MiKTeX DLLs manually in an Administrator Command Prompt (adjust version if different):
```cmd
cd %LOCALAPPDATA%\Programs\MiKTeX\miktex\bin\x64
regsvr32 MiKTeX240400-core-PS.dll
regsvr32 MiKTeX240400-core.dll
regsvr32 MiKTeX240400-packagemanager.dll
regsvr32 MiKTeX240400-packagemanager-PS.dll
```
### Executable not found in PATH
If the "Test Toolchain" button reports that `latex` or `dvisvgm` cannot be found:
- Provide the full absolute path in the plugin settings (e.g. `C:\Program Files\MiKTeX\miktex\bin\x64\latex.exe` or `/Library/TeX/texbin/latex`).
- Ensure the directory containing your TeX executables is in your system's environment `PATH`.
---
## 🔒 Security & Desktop Architecture
This plugin is configured as desktop-only (`"isDesktopOnly": true`) because it relies on your local TeX distribution:
- **Process Execution (`child_process.execFile`)**: The plugin executes your locally installed LaTeX compiler and `dvisvgm`. Commands are invoked strictly via `execFile` with segregated argument arrays (no shell interpolation), protecting against shell injection.
- **Filesystem Access (`fs/promises`)**: Temporary `.tex`, `.dvi`/`.xdv`/`.pdf`, and `.svg` files are created exclusively inside an isolated temporary directory within your system's `tmpdir()` (e.g. `tmpdir()/tikz-XXXXXX`). This directory is deleted in a `finally` block immediately after conversion.
- **Offline & Private**: The plugin performs zero external network calls and executes no dynamic script tags. Diagram source code is rendered locally on your machine and cached within local browser IndexedDB.
---
## 📄 License & Acknowledgements
- Licensed under the [MIT License](LICENSE.md).
- Forked from the [Obsidian TikZJax plugin](https://github.com/artisticat1/obsidian-tikzjax) by [@artisticat1](https://github.com/artisticat1).
- Inspired by the [TikZJax](https://github.com/kisonecat/tikzjax) project by [@kisonecat](https://github.com/kisonecat).