Jupyter Magic
tikzfigure ships an IPython extension that lets you write raw TikZ code
directly in a notebook cell with the %%tikz magic - no Python API
required. This is useful for quick sketches or for pasting existing TikZ
snippets.
Loading the extension
Section titled “Loading the extension”Load the extension once per session with %load_ext:
%load_ext tikzfigureBasic usage
Section titled “Basic usage”After loading the extension, any cell starting with %%tikz is compiled
as a tikzpicture environment and the resulting image is displayed
inline:
%%tikz\begin{tikzpicture} \node[shape=circle, color=white, fill=blue] (n1) at (0, 0) {A}; \node[shape=circle, color=white, fill=blue] (n2) at (5, 0) {B}; \draw[->, line width=2, color=gray] (n1) to (n2);\end{tikzpicture}
Passing options
Section titled “Passing options”Options after %%tikz control display - for example, --width sets the
display width in pixels:
%%tikz --width 400\begin{tikzpicture} \node[shape=circle, shape=circle, color=black, fill=orange!40] (node0) at (1, 0.5) {Hello};\end{tikzpicture}
Available options:
| Option | Description |
|---|---|
-w, --width | Display width in pixels |
-H, --height | Display height in pixels |
-s, --save | Save output to a file |
-v, --verbose | Show compilation details |
When to use the magic vs. the Python API
Section titled “When to use the magic vs. the Python API”%%tikz magic | Python API | |
|---|---|---|
| Best for | Existing TikZ snippets, quick sketches | Programmatic / data-driven figures |
| Requires | IPython / Jupyter | Any Python environment |
| Output | Inline image | Inline image, PDF, PNG |