TikZ diagrams¶
A note with latex-env: tikz and a caption: holds one ```tikz block. Obsidian renders it live through obsidian-tikzjax, and the export compiles it natively into a numbered, referencable vector figure.
The block is tikzjax-compatible. Everything before \begin{document} (packages, \usetikzlibrary, \pgfplotsset) is hoisted into the document preamble, and the picture between \begin{document} and \end{document} becomes the figure body. Declare the packages the block needs via nope-tlmgr, for example [pgfplots], so they are installed at export.
Source notes
---
title: "Feature: TikZ"
author: MrIwan
notitlepage: true
toc: false
nope-tlmgr:
- pgfplots
---
# TikZ
![[tikz-example]]
As shown in [[tikz-example]], TikZ figures are numbered and referencable like any other figure.
---
latex-env: tikz
caption: A pgfplots surface plot of a Gaussian derivative
---
```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}
```
Thanks
The ```tikz block format follows the obsidian-tikzjax plugin by artisticat1, so the same block renders live in Obsidian and exports here.