TikZ
At some point a man has to realize that they went down a rabbit-hole without any way to escape it. TikZ is one such rabbit-hole and, yes, I am that man.
In broad terms TikZ is a programming language within LaTeX, to generate graphics from code.
Standalone TikZ
The standalone package for LaTeX is inteded as a way to put graphics such as those generated by TikZ into a standalone document to be included in other documents. We are going to use it to generate a pdf with the TikZ graphic.
% graphic.tex
\documentclass[border=0pt, tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\end{tikzpicture}
\end{document}
To compile we simply run:
pdflatex graphic.tex
Convert to SVG
To convert this pdf into a svg file we are going to use the pdf2svg command-line converter:
pdf2svg graphic.tex
Et voilà! We produced an svg file from TikZ Source Code.
Quick and Easy
Consider the following script for quick compilation:
#!/bin/bash
# check for input file
input="$1"
if [ -z "$input" ]; then
echo "Usage: $0 <input>"
exit 1
fi
if [ ! -f "$1.tex" ]; then
echo "File not found: $1.tex"
exit 1
fi
# compile
echo "Compiling $1.tex..."
pdflatex -interaction=batchmode "$1.tex" > /dev/null
if [ $? -ne 0 ]; then
echo "Error: pdflatex failed!"
exit 1
fi
echo "Converting to $1.svg..."
pdf2svg "$1.pdf" "$1.svg"
echo "Done!"
# cleanup
rm "$1.aux" "$1.log"