My LaTeX Tikz Template

Sometimes I would like to create a single picture with Tikz for later usage on Wikipedia or my Blog. This is my LaTeX Tikz template I use in such a situation:

The templates

latex-document.tex

\documentclass[varwidth=true, border=2pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning} 

\begin{document}
\begin{tikzpicture}
    % Your Codes should be here
\end{tikzpicture}
\end{document}

Standalone

Preview-Environment

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning} 

\begin{document}
\begin{preview}
\begin{tikzpicture}
    % Your Codes should be here
\end{tikzpicture}
\end{preview}
\end{document}

Makefile

SOURCE = latex-document.tex

DELAY = 80
DENSITY = 300

make:
	pdflatex $(SOURCE).tex -output-format=pdf
	make clean

clean:
	rm -rf  $(TARGET) *.class *.html *.log *.aux

animatedGif:
	pdfcrop $(SOURCE).pdf
	convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
	make clean

transparentGif:
	convert $(SOURCE).pdf -transparent white result.gif
	make clean

svg:
	pdf2svg $(SOURCE).pdf $(SOURCE).svg
	# Necessary, as pdf2svg does not always create valid svgs:
	inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
	# Alternatively, only this one (produces worse results):
	#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg

Requirements

Test if you meet these requirements

Make sure that you have a valid LaTeX installation. pdflatex --version should output something like:

pdfTeX 3.1415926-2.3-1.40.12 (TeX Live 2011)
kpathsea version 6.0.1
Copyright 2011 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.5.2; using libpng 1.5.2
Compiled with zlib 1.2.5; using zlib 1.2.5
Compiled with xpdf version 3.02pl5

Make sure you can execute Makefiles. make --version should output something like this:

GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i486-pc-linux-gnu

The command inkscape --version should return:

Inkscape 0.47 r22583 (Apr  4 2010)

And pdf2svg --version should return:

Usage: pdf2svg <in file.pdf> <out file.svg> [<page no>]

How to use it

You have to place the Makefile in the same folder as latex-document.tex. If you have done this and if you meet the requirements, you can execute:

  • make: Generates a PDF file from latex-document.tex
  • make svg: Generates a SVG file from the generated PDF file
  • make transparentGif: Generates a transparent Gif from the PDF file
  • make animatedGif: If you have used multiple slides, this will create an animated Gif file. See How to visualize Graph algorithms with LaTeX for an example.

See also

You can leave a response, or trackback from your own site.

Leave a Reply