You can use the standalone class to produce tight PDF files for one or multiple TikZ pictures. I originally wrote it to simplify the creation of the many pictures of my thesis. Since v1.0 it includes a convert option which can convert the produced PDF into a graphics file automatically (using external software, which requires the -shell-escape compiler option).
This is very similar to Compile a LaTeX document into a PNG image that's as short as possible, but SVG needs some extra care.
You can write your TikZ pictures the following way:
\documentclass[tikz,convert={outfile=\jobname.svg}]{standalone}
%\usetikzlibrary{...}% tikz package already loaded by 'tikz' option
\begin{document}
\begin{tikzpicture}% Example:
\draw (0,0) -- (10,10); % ...
\draw (10,0) -- (0,10); % ...
\node at (5,5) {Lorem ipsum at domine standalonus};
\end{tikzpicture}
\end{document}
Then either you compile the file as usual with pdflatex or another latex and convert the PDF to a SVG manually or compile it with the -shell-escape option and let standalone convert it for you.
Manual conversion can be done with a number of tools. It is simpler under Linux, because these tools are easily available there, but should be possible under Windows as well. (The convert options isn't really tested under Windows, btw.)
By default standalone uses Image Magick's convert, which can do PDF to SVG but will not always give you good results.
The pdf2svg tool seems to be better suited, but isn't supported out-of-the-box by standalone yet. It can of course be used manually as shown in Exporting all equations from a document as individual svg files.
You can configure standalone to use pdf2svg directly by using the command key of the convert option. Unfortunately, there is a small bug in standalone preventing it. I just fixed that and will upload the new version today.
With this you can write:
\documentclass[crop,tikz,convert={outext=.svg,command=\unexpanded{pdf2svg \infile\space\outfile}},multi=false]{standalone}[2012/04/13]
%\usetikzlibrary{...}% tikz package already loaded by 'tikz' option
\makeatletter
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (10,10); % ...
\draw (10,0) -- (0,10); % ...
\draw (5,0) -- (0,10); % ...
\node at (5,5) {Lorem ipsum at domine standalonus};
\end{tikzpicture}
\end{document}
The \unexpanded is required because LaTeX expands class options. You can also add \noexpand before every macro instead.
If you need this more often you can also use a standalone.cfg file which enables this for all (local) standalone files. Simply create this file as follows in the same directory:
% Local standalone.cfg file
\input{standalone/standalone.cfg}% Load main standalone.cfg file
\standaloneconfig{convert={command={pdf2svg \infile\space\outfile}}}
I might add a special pdf2svg key in the next version as well, so you only need to write the following then:
\documentclass[crop,tikz,convert=pdf2svg]{standalone}[2012/04/13]
% ...
standaloneclass. See Compile a LaTeX document into a PNG image that's as short as possible which should be easily adjustable for SVG graphics. – Martin Scharrer Apr 13 '12 at 11:27\def\pgfsysdriver{pgfsys-tex4ht.def}before loading tikz) then you can runhtlatexon the file to produce SVGs directly. I prefer to run them throughscour(a python script for cleaning up SVGs) before posting them on the web. It works well in my experience so long as there isn't too much text. – Andrew Stacey Apr 13 '12 at 11:41dvisvgmcan be used. – Henrik Hansen Apr 13 '12 at 13:00pdf2svgtool did you use? There is a commercial tool (by PDFTron). There is also an opensource tool (current version: 0.2.1). – Paul Gaborit Sep 15 '12 at 09:49XML Parsing Error: mismatched tag. Expected: . Location: file:///C:/Documents%20and%20Settings/User/Desktop/SVGexamples/EX-1.svg Line Number 253, Column 22: x" class="sqrt" > ---------------------^
The zzfile.ps file contains just a single square root of x symbol.
– Santo D'Agostino Sep 16 '12 at 19:53