Quick Images with TikZ

How do you create high-quality technical images for documents, your website or posts on Stack Exchange? I have used tools in an ad-hoc manner for a while and have become frustrated lately. Once you have used TikZ Check out the awesome gallery of examples and the comprehensive manual. with LaTeX most other tools feel inferior. The only problem is: TikZ is a LaTeX package and can not be used on its own. So how to convert TikZ to, say, PNG comfortably?

TeX-guru Martin Scharrer comes to the rescue: he wrote the package standalone for exactly this use case. Based on his explanation on tex.SE I built a small bash script that does all the repetitive work for you. With one simple command, this

1
2
3
4
5
6
7
8
%p% \usetikzlibrary{arrows,automata,positioning}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,auto]
  \node[state,initial]    (q_0)                {$q_0$};
  \node[state,accepting]  (q_1) [right of=q_0] {$q_1$};

  \path[->] (q_0) edge [bend left]  node {$a$} (q_1)
            (q_1) edge [bend left]  node {$b$} (q_0);
\end{tikzpicture}

becomes this in a matter of seconds:

A graphic created with TikZ
[source]

You can find some more examples here.

Get tikz2png on Github and enjoy!

Update: There is tikz2svg now as well.

Originally posted on lmazy.verrech.net.


Quick Images with TikZ - March 29, 2012 - Raphael Reitzig