graphviz.sty allows you to write GraphViz code directly in your LaTeX source.
You must have the GraphViz program in your path. See http://graphviz.org for more details.
Copy graphviz.sty to your texmf directory.
LaTeX distribution folder can be found
- On Mac OS X with the MacTeX distribution: ~/Library/texmf/tex/latex
- On Linux it's usually: /usr/share/texmf-texlive/tex/latex/
- Copy graphviz.sty to you LaTeX distribution folder
- run $ texhash
Add the following lines to your preamble:
\usepackage[pdftex]{graphicx}
\usepackage{graphviz}
If the options "[pdflatex]" is causing troubles, replace it with
\PassOptionsToPackage{pdftex}{graphicx}
\usepackage{graphicx}
graphviz.sty supports two environments, digraph
(which produces oriented graphs):
\begin{digraph}[scale=0.5]{MyDiGraph}
rankdir=LR;
a->b;
b->c;
\end{digraph}
and graphviz
for non-oriented graphs:
\begin{graphviz}{MyGraph}
a--b;
b--c;
\end{graphviz}
Parameters for digraph
or graphviz
environment:
- optional parameters:
scale
-- default value is "scale=1"layout
-- for changing graphviz layout filter (possible values "layout=dot|neato|twopi|circo|fdp|sfdp" see graphviz documentation for more details), default is "layout=dot"output
-- default ispdf
, you can use "output=ps|png|pdf" or which everformat \includegraphics supports. When output istex
graph is converted withdot2tex
tool (you have to addtikz
package to your preamble) -- this is an experimental feature
- name of the
digraph
. This is obligatory argument, it's the name produced output file. If you have two environments with same name file will be overwritten by the later.
To include an external GraphViz dot file named mydotfile.dot:
\includedot[scale=0.5]{mydotfile}
Parameters for \includedot
:
- optional arguments (in
[args]
) are the same as above - name of the dot file (w/out file extension, which must be ".dot")
You must use the -shell-escape
option for pdflatex
. This enables LaTeX to execute system commnds which is for security reasons disabled in most LaTeX distributions by default.
$ pdflatex -shell-escape *.tex
If you are having problems with generating output see LaTeX *.log for this:
runsystem(bash -c "dot -Tpdf graph1.dot > graph1.pdf")...executed.
To modify this command for regular latex
change output to ps
\begin{digraph}[output=ps]{MyGraph}
rankdir=LR;
a->b;
b->c;
\end{digraph}
graphviz.sty is based on graphviz.tex by Derek Rayside (2003).
2006-03-25: Modified by Mark Aufflick
- website: http://mark.aufflick.com/
2011-02-21: Modified by Mike Prentice
- use of PDF output directly from dot.
- added includedot layout.
2012-02-17: Modified by Tomas Barton
- Improved check for generated file, allowed backslash and other "unsafe" characted in digraph code
- Added output option
- changed \digraph command to
digraph
andgraph
environment which follows much more LaTeX conventions - supports conversion with
dot2tex