LabCanvas

TikZ on Overleaf, in Obsidian, in Typst and on the web (TikZJax)

Quick answer

On Overleaf, TikZ works without installing anything: add \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).
Three rounded boxes in a row, Raw data, Cleaned and Figure, joined by arrows, and a dashed curved arrow labelled revise from Figure back to Raw data.
A small TikZ flowchart that compiles as it is on Overleaf, with arrows.meta and positioning loaded in the preamble
Preamble: \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}
Open in the TikZ editor
Full document
A complete file you can compile as it is.
\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:

  1. 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.
  2. Lower the sample counts. A 3D surface with samples=40 has 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.
  3. Compile with LuaLaTeX when the document has pgfplots. With compat=1.12 or 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.
  4. Externalize finished figures (next section), so that a figure is computed once and then included as a PDF.
  5. 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.

A 3D surface shaped like a ripple: a yellow peak in the middle surrounded by a purple circular trough, flattening towards the edges, in a box with x and y axes from −3 to 3.
A pgfplots surface compiled with LuaLaTeX (%! engine: lualatex): the same output, computed faster by the Lua backend
Preamble: \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}
Open in the TikZ editor
Full document
A complete file you can compile as it is.
\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
  • \tikzexternalize must be in the project’s main .tex file.
  • The folder given as prefix must exist and must contain a file before TikZ can write into it: create tikz/ and add any small file, such as an empty foo.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 \jobname to output, so the files are called output-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:

Obsidian TikZ plugins, November 2026
PluginHow it rendersStatus
TikZJax (artisticat1/obsidian-tikzjax)TikZJax (drgrice1’s fork) in the note; packages chemfig, tikz-cd, circuitikz, pgfplots, array, amsmath, amstext, amsfonts, amssymb, tikz-3dplotThe 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 VaultCall the TeX Live or MiKTeX installed on your computer, so any package worksNeed 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.

A grid with x and y axes, a blue sine curve, a red straight line labelled x/2 − 1/2 and a black dot labelled (π/2, 1) at the top of the sine curve.
Plain TikZ without packages or libraries: code like this also runs in TikZJax on a web page or in Obsidian
Preamble: \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}
Open in the TikZ editor
Full document
A complete file you can compile as it is.
\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 standalone class and include the result with #image("figure.pdf") or #image("figure.svg"); Typst’s image accepts 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 and CeTZ compared
TikZCeTZ
Runs inLaTeX (any engine), also ConTeXt and plain TeXTypst only
Plotspgfplots: 2D, 3D, logarithmic axes, error bars, colormapscetz-plot 0.1.4: function and data plots, bar and pie charts
DiagramsLibraries and packages for nearly every field: circuitikz, tikz-cd, chemfig, quantikz, forest, graph drawingfletcher 0.6.0 for diagrams with nodes and arrows (flowcharts, commutative diagrams), cetz-venn, a tree layout in CeTZ itself
SpeedA LaTeX run; large pictures take seconds, hence externalizingTypst compiles incrementally, so the preview follows the code quickly
Documentation and examplesA detailed reference manual (tikz.dev) and a large stock of answered questionsAn 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.

Two axes with arrow tips labelled x and y, an orange rectangle near the origin, a light blue circle labelled A, and a red S-shaped curve.
The TikZ version of the CeTZ example: \draw paths with nodes instead of line, rect, circle and content calls
Preamble: \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}
Open in the TikZ editor
Full document
A complete file you can compile as it is.
\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

  1. Overleaf documentation: plan limits (compile timeout)docs.overleaf.com
  2. Overleaf documentation: fixing and preventing compile timeoutsdocs.overleaf.com
  3. Overleaf documentation: reducing the compile time for diagrams (TikZ externalization)docs.overleaf.com
  4. Overleaf documentation: selecting a TeX Live version and LaTeX compilerdocs.overleaf.com
  5. Overleaf documentation: TeX Live on Overleafdocs.overleaf.com
  6. Overleaf learn: TikZ packageoverleaf.com
  7. Overleaf learn: Pgfplots packageoverleaf.com
  8. PGF/TikZ manual, §52 Externalization Librarytikz.dev
  9. pgfplots manual 1.18.3, §6.3.1 Lua (lua backend with LuaLaTeX, p. 535)mirrors.ctan.org
  10. TikZJax (kisonecat/tikzjax)github.com
  11. TikZJax demo and hosted filestikzjax.com
  12. TikZJax fork with packages and libraries (drgrice1/tikzjax)github.com
  13. Obsidian plugin TikZJax (artisticat1/obsidian-tikzjax)github.com
  14. Obsidian plugin TikZJax Next (jackvinati/tikzjax-next)github.com
  15. CeTZ on Typst Universe (0.5.3, 2026-10-21)typst.app
  16. CeTZ online manualcetz-package.github.io
  17. cetz-plot on Typst Universe (0.1.4)typst.app
  18. fletcher on Typst Universe (0.6.0)typst.app
  19. 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.

More TikZ guides

Tools

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