Embedding GraphViz in LaTeX documents
I am embedding some GraphViz diagrams in my documents, but I didn't want a round trip to a different editor buffer and the shell to edit/compile/insert the diagram.
Based on graphviz.tex code by Derek Rayside I have created a custom LaTeX function that will automatically compile and embed inline GraphViz code (man those wacky capitilisations are getting boring!)
You embed a graph like so:
\digraph[scale=0.5]{MyGraph}{rankdir=LR; a->b; b->c}
Be careful not to have any double newlines or your dot file will have some bogus \par comments in it (which I should replace with newlines in the function...). Another possible enhancement would be to add a dynamic dot command to set the maximum diagram height & width to the current page/column dimensions.You need my graphviz.sty and you need the following in your document preamble:
\usepackage[pdftex]{graphicx}
\usepackage{graphviz}
Remember to run texhash if you install the style in a system-wide location.
Note this assumes pdflatex. Modifying the command for regular latex is an exercise left for the reader.
10:09 PM, 25 Mar 2007 by Mark Aufflick Permalink | Short Link
Thank you
I really like this, and I fiddled around with dot2tex as suggested in your comment to yourself. Here are my results. I've never written a latex sty file before, so please feel free to improve it.
% graphviz.sty
% by Mark Aufflick
% 2006-03-25
% mark@aufflick.com
% http://mark.aufflick.com/
%
% based on graphviz.tex by Derek Rayside 2003
% add the following lines to your preamble:
% \usepackage[pdftex]{graphicx}
% \usepackage{graphviz}
% parameters to \digraph:
% 1 - parameters for \includegraphics (optional; default value is "scale=1")
% 2 - name of the digraph
% 3 - body of the digraph
% assumes pdflatex. to modify this command for regular latex,
% replace all .pdf with .ps, and the command becomes simply:
% dot -Tps #1.dot
\ProvidesPackage{dottotex}
\newcommand{\dottotex}[2]{
\newwrite\dotfile
\immediate\openout\dotfile=#1.dot
\immediate\write\dotfile{digraph #1 {\string#2}}
\immediate\closeout\dotfile
\write18{bash -c "`which neato` -Txdot #1.dot | `which dot2tex` -tmath --figonly --usepdflatex -ftikz --tikzedgelabels --styleonly -o #1tikz.tex"}
\IfFileExists{#1tikz.tex}
% the tex exists: include it
{ \include{#1tikz} }
% the tex was not created - show a hint
{ \fbox{ \begin{tabular}{l}
The file \texttt{#1tikz.tex} hasn't been created from
\texttt{#1.dot} yet. \\
We attempted to create it with:\\
`\texttt{neato -Txdot #1.dot | dot2tex --figonly --usepdflatex -ftikz --tikzedgelabels --styleonly -o #1tikz.tex}` \\
but that seems not to have worked. You need to execute `\texttt{pdflatex}` with \\
the `\texttt{-shell-escape}` option.
\end{tabular}}
}
}
by Unregistered Visitor on 04/02/09








Todo
Change this style to use the excellent dot2tex: http://www.fauskes.net/nb/introducing-dot2tex/
by Mark Aufflick on 05/21/07