Skip to content

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.

Load the extension once per session with %load_ext:

%load_ext tikzfigure

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}

png

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}

png

Available options:

OptionDescription
-w, --widthDisplay width in pixels
-H, --heightDisplay height in pixels
-s, --saveSave output to a file
-v, --verboseShow compilation details
%%tikz magicPython API
Best forExisting TikZ snippets, quick sketchesProgrammatic / data-driven figures
RequiresIPython / JupyterAny Python environment
OutputInline imageInline image, PDF, PNG