TikZ on Overleaf, in Obsidian, in Typst and on the web (TikZJax)
Quick answer
\usepackage{tikz} (and the \usetikzlibrary lines you need) to the preamble of the main .tex file. Large figures are the risk, because the free plan stops a compilation after 10 seconds; fewer plot samples, LuaLaTeX for pgfplots, or externalizing finished figures fix that. In Obsidian, the TikZJax community plugin renders code blocks marked tikz with TeX compiled to WebAssembly. TikZJax does the same on any web page. Typst cannot run TikZ; its counterpart is the CeTZ package, or a TikZ figure embedded as an image (PDF or SVG).
\usepackage{tikz} \usetikzlibrary{arrows.meta, positioning}\begin{tikzpicture}[node distance=12mm, >=Stealth,
box/.style={draw, rounded corners, fill=teal!12, minimum width=22mm, minimum height=8mm,
text height=1.5ex, text depth=0.25ex}]
\node[box] (raw) {Raw data};
\node[box, right=of raw] (clean) {Cleaned};
\node[box, right=of clean] (fig) {Figure};
\draw[->, thick] (raw) -- (clean);
\draw[->, thick] (clean) -- (fig);
\draw[->, thick, dashed] (fig.south) to[bend left=25] node[below] {revise} (raw.south);
\end{tikzpicture}
Full document
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\begin{document}
\begin{tikzpicture}[node distance=12mm, >=Stealth,
box/.style={draw, rounded corners, fill=teal!12, minimum width=22mm, minimum height=8mm,
text height=1.5ex, text depth=0.25ex}]
\node[box] (raw) {Raw data};
\node[box, right=of raw] (clean) {Cleaned};
\node[box, right=of clean] (fig) {Figure};
\draw[->, thick] (raw) -- (clean);
\draw[->, thick] (clean) -- (fig);
\draw[->, thick, dashed] (fig.south) to[bend left=25] node[below] {revise} (raw.south);
\end{tikzpicture}
\end{document}Contents
TikZ on Overleaf: already installed
Overleaf compiles with TeX Live, which contains TikZ, pgfplots, circuitikz, tikz-cd and the other TikZ packages; new projects use the newest TeX Live (2026 at the time of writing), and the version can be changed per project. A complete document for the flowchart above:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
…
\end{tikzpicture}
\caption{Workflow.}
\end{figure}
\end{document}
The preamble lines belong in the main .tex file, even when the figure itself is in another file that you \input. pdfLaTeX is the default compiler; XeLaTeX and LuaLaTeX are under Settings → Compiler (the gear icon or the File menu), next to the TeX Live version. Overleaf’s own tutorials cover the basics of TikZ and pgfplots; this site goes into the details, for example arrows and plots.
Compile timeouts: 10 seconds on the free plan
Overleaf stops a compilation that runs longer than the limit of the plan: 10 seconds on the free plan and 240 seconds on the premium plans (Overleaf’s plan limits, November 2026). Overleaf’s troubleshooting page names complex TikZ and pgfplots drawings as one of the usual causes, because TeX redraws every picture on every compilation. What helps, roughly in order of effort:
- Fix errors first. With Stop on first error in the Recompile menu, an error stops the run at once instead of letting LaTeX carry on through many follow-up errors.
- Lower the sample counts. A 3D surface with
samples=40has 40 × 40 = 1600 patches; 25 × 25 is often indistinguishable on paper. For 2D plots of measured data, plot the data rather than thousands of computed points. - Compile with LuaLaTeX when the document has pgfplots. With
compat=1.12or newer, pgfplots then hands much of its work to Lua; its manual measures surface plots at 25–50 % of the pdfLaTeX time, with the same output. The surface below was compiled that way. - Externalize finished figures (next section), so that a figure is computed once and then included as a PDF.
- Move heavy figures to a separate project with
\documentclass[tikz]{standalone}and include its PDF: Overleaf can upload a file From another project → from output files, and\includegraphics[page=2]{figures.pdf}picks a figure.
Fast [draft] mode replaces included image files with boxes, which helps projects with many large photos, not TikZ code.

\usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18}Compile with LuaLaTeX% compiled with LuaLaTeX: pgfplots computes with Lua (faster, more accurate)
\begin{tikzpicture}
\begin{axis}[view={40}{35}, colormap name=viridis,
xlabel={$x$}, ylabel={$y$}, xtick={-2,0,2}, ytick={-2,0,2}]
\addplot3[surf, shader=interp, domain=-3:3, samples=40]
{cos(deg(2*sqrt(x^2 + y^2))) * exp(-(x^2 + y^2)/4)};
\end{axis}
\end{tikzpicture}
Full document
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
% compiled with LuaLaTeX: pgfplots computes with Lua (faster, more accurate)
\begin{tikzpicture}
\begin{axis}[view={40}{35}, colormap name=viridis,
xlabel={$x$}, ylabel={$y$}, xtick={-2,0,2}, ytick={-2,0,2}]
\addplot3[surf, shader=interp, domain=-3:3, samples=40]
{cos(deg(2*sqrt(x^2 + y^2))) * exp(-(x^2 + y^2)/4)};
\end{axis}
\end{tikzpicture}
\end{document}Externalizing TikZ figures on Overleaf
The external library works on Overleaf, with three details from Overleaf’s help page:
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/] % in the main .tex file
\tikzexternalizemust be in the project’s main.texfile.- The folder given as
prefixmust exist and must contain a file before TikZ can write into it: createtikz/and add any small file, such as an emptyfoo.txt. - The figure PDFs are generated files: hidden from the file list and deleted by Overleaf at intervals, after which the first compilation has to make them all again and may time out. Overleaf sets
\jobnametooutput, so the files are calledoutput-figure0.pdf,output-figure1.pdf…;\tikzsetnextfilename{name}gives a figure a stable name.
To make the figures permanent, Overleaf suggests compiling the project once on your own computer (pdflatex -shell-escape main.tex) and uploading the .pdf, .md5 and .dpth files of each figure into tikz/: uploaded files are never deleted, and a figure is only regenerated when its code changes. How the library works in general is on the export page.
TikZ in Obsidian: TikZJax plugins
Obsidian renders TikZ through community plugins (Settings → Community plugins → Browse). The ones based on TikZJax run TeX inside Obsidian, compiled to WebAssembly, so no TeX installation is needed:
| Plugin | How it renders | Status |
|---|---|---|
| TikZJax (artisticat1/obsidian-tikzjax) | TikZJax (drgrice1’s fork) in the note; packages chemfig, tikz-cd, circuitikz, pgfplots, array, amsmath, amstext, amsfonts, amssymb, tikz-3dplot | The established one: about 65,000 downloads; version 0.5.2, last updated 31 March 2024 |
| TikZJax Next (jackvinati/tikzjax-next) | A fork of the plugin above with a newer WebAssembly TeX: pgfplots, circuitikz, chemfig, tikz-cd, forest and many libraries built in, offline, on desktop and on iPhone/iPad; needs Obsidian 1.7.2+ | Version 0.2.3, updated October 2026; listed as not manually reviewed by Obsidian staff |
| LaTeX and TikZ Renderer, TikZ Native, LaTeX Vault | Call the TeX Live or MiKTeX installed on your computer, so any package works | Need a local TeX installation; listed as not manually reviewed |
With the TikZJax plugin, a note contains a code block whose language is tikz (three backticks followed by tikz, closed by three backticks). Inside it go the preamble lines and the document environment; the plugin uses the standalone class:
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
…
\end{tikzpicture}
\end{document}
Only the packages the plugin bundles can be loaded, so a figure that compiles on Overleaf may fail in Obsidian. Plain TikZ, like the plot below, works everywhere.

\usepackage{tikz}\begin{tikzpicture}[domain=0:4, scale=0.9]
% only TikZ itself: this also runs in TikZJax (web pages, Obsidian)
\draw[very thin, gray!40] (0,-1.2) grid (4,2.2);
\draw[->] (-0.2,0) -- (4.3,0) node[right] {$x$};
\draw[->] (0,-1.3) -- (0,2.4) node[above] {$y$};
\draw[blue, thick, samples=60] plot (\x, {sin(\x r)}) node[right] {$\sin x$};
\draw[red, thick, samples=60] plot (\x, {0.5*\x - 0.5}) node[right] {$x/2 - 1/2$};
\fill (1.5708,1) circle [radius=1.5pt] node[above right] {$(\pi/2, 1)$};
\end{tikzpicture}
Full document
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[domain=0:4, scale=0.9]
% only TikZ itself: this also runs in TikZJax (web pages, Obsidian)
\draw[very thin, gray!40] (0,-1.2) grid (4,2.2);
\draw[->] (-0.2,0) -- (4.3,0) node[right] {$x$};
\draw[->] (0,-1.3) -- (0,2.4) node[above] {$y$};
\draw[blue, thick, samples=60] plot (\x, {sin(\x r)}) node[right] {$\sin x$};
\draw[red, thick, samples=60] plot (\x, {0.5*\x - 0.5}) node[right] {$x/2 - 1/2$};
\fill (1.5708,1) circle [radius=1.5pt] node[above right] {$(\pi/2, 1)$};
\end{tikzpicture}
\end{document}TikZJax on web pages
TikZJax, by Jim Fowler, runs TeX in the browser: the Pascal source of TeX is compiled to WebAssembly, a LaTeX format with TikZ preloaded is loaded, and the DVI output is converted to SVG on the page. To use the hosted version, add two lines to the <head> and put the TikZ code in a script tag of type text/tikz:
<link rel="stylesheet" type="text/css" href="https://tikzjax.com/v1/fonts.css">
<script src="https://tikzjax.com/v1/tikzjax.js"></script>
<script type="text/tikz">
\begin{tikzpicture}
\draw (0,0) circle (1in);
\end{tikzpicture}
</script>
The script tag is replaced by the SVG. The first picture on a page costs a download (the script alone is about 450 kB, plus the TeX engine and format) and a TeX run in the reader’s browser. The fork drgrice1/tikzjax, which the Obsidian plugin uses, is meant to be hosted yourself and adds data-tex-packages (for amsmath, pgfplots, tikz-cd, tikz-3dplot, array and a few others), data-tikz-libraries and a cache, so an unchanged picture is not compiled again.
For a figure that does not change, rendering once at build time is lighter for readers: convert it to SVG with dvisvgm or pdftocairo (see export), or download a PNG from the LabCanvas TikZ editor.
Typst and TikZ: CeTZ, or the figure as an image
Typst does not run TeX, so TikZ code cannot go into a Typst document. There are two routes:
- Keep the TikZ figure: compile it with the
standaloneclass and include the result with#image("figure.pdf")or#image("figure.svg"); Typst’simageaccepts PDF and SVG files. - Redraw it with CeTZ (version 0.5.3 of October 2026 on Typst Universe, needs Typst 0.15), a drawing package for Typst “inspired by TikZ and Processing”. The same picture in both, CeTZ first (shown as code: our renderer runs LaTeX only, but we compiled it with Typst 0.15):
#import "@preview/cetz:0.5.3"
#cetz.canvas({
import cetz.draw: *
// axes with arrow tips and labels
line((0, 0), (4, 0), mark: (end: ">"))
content((4, 0), $x$, anchor: "west", padding: .1)
line((0, 0), (0, 2.5), mark: (end: ">"))
content((0, 2.5), $y$, anchor: "south", padding: .1)
// a rectangle, a filled circle with a label, and a curve
rect((0.4, 0.3), (1.6, 1), fill: orange.lighten(60%))
circle((2.8, 1.3), radius: 0.6, fill: blue.lighten(80%))
content((2.8, 1.3), [A])
bezier((0.3, 2.1), (3.8, 0.3), (1.5, 3), (2.5, -0.5), stroke: red)
})
The ideas carry over: coordinates in centimetres with y upwards, named elements with anchors, arrow tips (“marks”), styles. The syntax is Typst’s: function calls with named arguments instead of paths and options in brackets, and a Bézier curve lists its end point before the control points. In TikZ, a label is usually a node on the path; in CeTZ it is a separate content call.
| TikZ | CeTZ | |
|---|---|---|
| Runs in | LaTeX (any engine), also ConTeXt and plain TeX | Typst only |
| Plots | pgfplots: 2D, 3D, logarithmic axes, error bars, colormaps | cetz-plot 0.1.4: function and data plots, bar and pie charts |
| Diagrams | Libraries and packages for nearly every field: circuitikz, tikz-cd, chemfig, quantikz, forest, graph drawing | fletcher 0.6.0 for diagrams with nodes and arrows (flowcharts, commutative diagrams), cetz-venn, a tree layout in CeTZ itself |
| Speed | A LaTeX run; large pictures take seconds, hence externalizing | Typst compiles incrementally, so the preview follows the code quickly |
| Documentation and examples | A detailed reference manual (tikz.dev) and a large stock of answered questions | An API reference and an online manual that its authors call a work in progress |
For a paper written in LaTeX, stay with TikZ. For a document written in Typst, draw new figures in CeTZ and bring complex existing TikZ figures over as PDF or SVG images; translating them means rewriting every drawing command.

\usepackage{tikz}\begin{tikzpicture}
% axes with arrow tips and labels
\draw[->] (0,0) -- (4,0) node[right] {$x$};
\draw[->] (0,0) -- (0,2.5) node[above] {$y$};
% a rectangle, a filled circle with a label, and a curve
\draw[fill=orange!40] (0.4,0.3) rectangle (1.6,1);
\draw[fill=blue!20] (2.8,1.3) circle [radius=0.6] node {A};
\draw[red] (0.3,2.1) .. controls (1.5,3) and (2.5,-0.5) .. (3.8,0.3);
\end{tikzpicture}
Full document
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% axes with arrow tips and labels
\draw[->] (0,0) -- (4,0) node[right] {$x$};
\draw[->] (0,0) -- (0,2.5) node[above] {$y$};
% a rectangle, a filled circle with a label, and a curve
\draw[fill=orange!40] (0.4,0.3) rectangle (1.6,1);
\draw[fill=blue!20] (2.8,1.3) circle [radius=0.6] node {A};
\draw[red] (0.3,2.1) .. controls (1.5,3) and (2.5,-0.5) .. (3.8,0.3);
\end{tikzpicture}
\end{document}Common errors and how to fix them
| LaTeX says (or you see) | Cause and fix |
|---|---|
| Environment tikzpicture undefined. | TikZ is not loaded: add \usepackage{tikz} to the preamble of the main .tex file (on Overleaf too; nothing needs to be installed). |
| Package PGF Math Error: Unknown function `of' (in 'of a'). | right=of a and the other “=of” placements need the positioning library: \usetikzlibrary{positioning}. |
| Overleaf stops with a compile timeout (no LaTeX error) | The free plan allows 10 seconds. Lower samples in pgfplots (especially 3D), switch the compiler to LuaLaTeX for pgfplots, externalize finished figures, or compile heavy figures in a separate project and include their PDF. |
| Externalized figures are not created on Overleaf, or disappear later (no error) | \tikzexternalize must be in the main .tex file and the prefix folder must contain a file. Overleaf deletes generated files at intervals: upload locally generated .pdf, .md5 and .dpth files to keep them. |
| A tikz block in Obsidian shows an error or nothing (no error) | The TikZJax plugin only has the packages it bundles (chemfig, tikz-cd, circuitikz, pgfplots, array, the AMS packages, tikz-3dplot), and the block needs \begin{document} … \end{document}. For other packages, use a plugin that calls a local TeX installation. |
Frequently asked questions
Does Overleaf support TikZ?
Yes. Overleaf compiles with TeX Live, which includes TikZ, pgfplots, circuitikz, tikz-cd and the other TikZ packages. Write \usepackage{tikz} and your \usetikzlibrary lines in the preamble of the main .tex file; nothing needs to be installed.
Why does my TikZ figure time out on Overleaf?
The free plan stops each compilation after 10 seconds (premium plans after 240), and TikZ redraws every figure on every run. Reduce plot samples, use LuaLaTeX for pgfplots, externalize finished figures with \tikzexternalize[prefix=tikz/] in the main file, or compile figures in a separate standalone project.
How do I use TikZ in Obsidian?
Install the TikZJax community plugin (or TikZJax Next), then write the figure in a code block marked tikz, with \usepackage lines for the packages you need and the picture between \begin{document} and \end{document}. Only the packages the plugin bundles are available.
Can I use TikZ in Typst?
Not directly: Typst does not run TeX. Either embed a TikZ figure, converted to PDF or SVG, with #image("figure.pdf"), or redraw it with CeTZ, the Typst drawing package inspired by TikZ (#import "@preview/cetz:0.5.3").
What is TikZJax?
TikZJax is TeX and TikZ compiled to WebAssembly, so that TikZ code in a web page or an Obsidian note is turned into an SVG in the browser. Add tikzjax.js and fonts.css from tikzjax.com to the page and put the code in <script type="text/tikz">. Only the packages it bundles are available.
References
- Overleaf documentation: plan limits (compile timeout)docs.overleaf.com
- Overleaf documentation: fixing and preventing compile timeoutsdocs.overleaf.com
- Overleaf documentation: reducing the compile time for diagrams (TikZ externalization)docs.overleaf.com
- Overleaf documentation: selecting a TeX Live version and LaTeX compilerdocs.overleaf.com
- Overleaf documentation: TeX Live on Overleafdocs.overleaf.com
- Overleaf learn: TikZ packageoverleaf.com
- Overleaf learn: Pgfplots packageoverleaf.com
- PGF/TikZ manual, §52 Externalization Librarytikz.dev
- pgfplots manual 1.18.3, §6.3.1 Lua (lua backend with LuaLaTeX, p. 535)mirrors.ctan.org
- TikZJax (kisonecat/tikzjax)github.com
- TikZJax demo and hosted filestikzjax.com
- TikZJax fork with packages and libraries (drgrice1/tikzjax)github.com
- Obsidian plugin TikZJax (artisticat1/obsidian-tikzjax)github.com
- Obsidian plugin TikZJax Next (jackvinati/tikzjax-next)github.com
- CeTZ on Typst Universe (0.5.3, 2026-10-21)typst.app
- CeTZ online manualcetz-package.github.io
- cetz-plot on Typst Universe (0.1.4)typst.app
- fletcher on Typst Universe (0.6.0)typst.app
- Typst reference: image (accepts SVG and PDF files)typst.app
The facts on this page were checked against these sources, and every picture is the code with it typeset with TeX Live 2026. Code on this page: CC0 1.0, copy it freely.
Try the code in your browserEvery snippet on this page opens in the free TikZ editor: it is typeset with TeX Live as you type, with errors pointed at their line.
Open the TikZ editor