summaryrefslogtreecommitdiff
path: root/graphics/dot2tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/dot2tex
Initial commit
Diffstat (limited to 'graphics/dot2tex')
-rw-r--r--graphics/dot2tex/LICENSE19
-rw-r--r--graphics/dot2tex/README83
-rw-r--r--graphics/dot2tex/changelog.txt124
-rw-r--r--graphics/dot2tex/doc/docgraphs/balls.dot13
-rw-r--r--graphics/dot2tex/doc/docgraphs/ex1.dot3
-rw-r--r--graphics/dot2tex/doc/docgraphs/ex1b.dot4
-rw-r--r--graphics/dot2tex/doc/docgraphs/ex2.dot4
-rw-r--r--graphics/dot2tex/doc/docgraphs/ex3.dot8
-rw-r--r--graphics/dot2tex/doc/docgraphs/ex4.dot10
-rw-r--r--graphics/dot2tex/doc/docgraphs/lblstyle.dot11
-rw-r--r--graphics/dot2tex/doc/docgraphs/nodesize.dot7
-rw-r--r--graphics/dot2tex/doc/docgraphs/pgfarrows.dot18
-rw-r--r--graphics/dot2tex/doc/docgraphs/preproc1.dot6
-rw-r--r--graphics/dot2tex/doc/docgraphs/pstarrows.dot15
-rw-r--r--graphics/dot2tex/doc/docgraphs/simple.dot5
-rw-r--r--graphics/dot2tex/doc/docgraphs/simplelbl.dot9
-rw-r--r--graphics/dot2tex/doc/docgraphs/topaths1.dot8
-rw-r--r--graphics/dot2tex/doc/docgraphs/valignmode1.dot7
-rw-r--r--graphics/dot2tex/doc/pdf/balls.pdfbin0 -> 8600 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/consistent.pdfbin0 -> 25453 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/dot2texiex1.pdfbin0 -> 57298 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/dot2texiex2.pdfbin0 -> 27066 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/ex1comb.pdfbin0 -> 20299 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/ex1gstyle.pdfbin0 -> 6645 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/ex1huge.pdfbin0 -> 10897 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/ex2.pdfbin0 -> 16944 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/fsm1.pdfbin0 -> 15246 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/lblstyle.pdfbin0 -> 16846 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/nodewidth1.pdfbin0 -> 13869 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/nodewidth2.pdfbin0 -> 13865 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/pgfarrows.pdfbin0 -> 15294 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/pgftikzsimple.pdfbin0 -> 16381 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/preproc1a.pdfbin0 -> 25966 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/preproc1b.pdfbin0 -> 26060 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/pstarrows.pdfbin0 -> 6445 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/texmode.pdfbin0 -> 28672 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/texmodeb.pdfbin0 -> 28658 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/tikzedgelabels.pdfbin0 -> 23877 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/topaths1.pdfbin0 -> 9106 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/valignmode0.pdfbin0 -> 10653 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/valignmode1.pdfbin0 -> 10643 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/valignmode2.pdfbin0 -> 10630 bytes
-rw-r--r--graphics/dot2tex/doc/pdf/valignmode3.pdfbin0 -> 10625 bytes
-rw-r--r--graphics/dot2tex/doc/usage.tex1738
-rw-r--r--graphics/dot2tex/doc/usage.txt1313
-rw-r--r--graphics/dot2tex/dot2tex.pdfbin0 -> 445837 bytes
-rw-r--r--graphics/dot2tex/dot2tex/__init__.py0
-rw-r--r--graphics/dot2tex/dot2tex/dot2tex4
-rw-r--r--graphics/dot2tex/dot2tex/dot2tex.py2586
-rw-r--r--graphics/dot2tex/examples/automata.dot32
-rw-r--r--graphics/dot2tex/examples/balls.dot24
-rw-r--r--graphics/dot2tex/examples/distances.dot25
-rw-r--r--graphics/dot2tex/examples/ex1.dot14
-rw-r--r--graphics/dot2tex/examples/graphanndtti.tex44
-rw-r--r--graphics/dot2tex/examples/graphofgraphs.dot26
-rw-r--r--graphics/dot2tex/examples/gvcols.tex655
-rw-r--r--graphics/dot2tex/examples/latexmarkup.dot32
-rw-r--r--graphics/dot2tex/examples/pgfarrows.dot27
-rw-r--r--graphics/dot2tex/examples/pgfsnakes.dot26
-rw-r--r--graphics/dot2tex/examples/poltab.dot33
-rw-r--r--graphics/dot2tex/examples/pstarrows.dot25
-rw-r--r--graphics/dot2tex/examples/showpoints.dot89
-rw-r--r--graphics/dot2tex/examples/subgraphs.dot47
-rw-r--r--graphics/dot2tex/examples/tank.dot47
-rw-r--r--graphics/dot2tex/examples/tikzautomata.dot34
-rw-r--r--graphics/dot2tex/examples/tikzshapes.dot38
-rw-r--r--graphics/dot2tex/examples/transp.dot118
-rw-r--r--graphics/dot2tex/setup.py50
68 files changed, 7381 insertions, 0 deletions
diff --git a/graphics/dot2tex/LICENSE b/graphics/dot2tex/LICENSE
new file mode 100644
index 0000000000..c0d5342da8
--- /dev/null
+++ b/graphics/dot2tex/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2007, Kjell Magne Fauske
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
diff --git a/graphics/dot2tex/README b/graphics/dot2tex/README
new file mode 100644
index 0000000000..6a6dae2149
--- /dev/null
+++ b/graphics/dot2tex/README
@@ -0,0 +1,83 @@
+dot2tex - A Graphviz to LaTeX converter
+=======================================
+
+Copyright (C) 2007 Kjell Magne Fauske
+License: MIT (See LICENSE for details.)
+Version: 2.7.0
+URL: http://www.fauskes.net/code/dot2tex/
+
+Dot2tex is a tool for converting graphs rendered by Graphviz to formats
+that can be used with LaTeX.
+
+The purpose of dot2tex is to give graphs generated by Graphviz a more
+LaTeX friendly look and feel. This is accomplished by converting xdot
+output from Graphviz to a series of TikZ and PGF, or PSTricks commands.
+This approach allows:
+
+ * Typesetting labels with LaTeX, allowing mathematical notation.
+ * Using native PSTricks and PGF/TikZ commands for drawing arrows.
+ * Using backend specific styles to customize the output
+
+Installation
+============
+
+Before you install dot2tex you have to have a working Python environment
+installed on your system. Dot2tex has been developed and tested with
+Python 2.4, but it will probably run fine using Python 2.3. In addition
+you'll need the following modules:
+
+ * pyparsing (http://pyparsing.wikispaces.com/). A recent version is required.
+ Older version like for instance 1.3.2 does not work with dot2tex.
+ * pydot (http://dkbza.org/pydot.html)
+ * preview (http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html)
+ A stand-alone part of the preview-latex/AUCTeX bundle.
+ Required for preprocessing graphs with LaTeX.
+
+From source
+-----------
+
+Download a zip or a tarball from the download_ page. It is also available on
+CTAN_. Unpack the file to a directory and run ``python`` on the ``setup.py``
+file::
+
+ $ python setup.py install
+
+This will create a dot2tex module in your Python module directory and a wrapper
+script in your ``SCRIPTS`` directory. Note that a few warnings will be
+displayed. You can safely ignore them. The warnings are shown because there is
+some extra information in the ``setup.py`` file that distutils does not understand.
+
+.. _download: http://www.fauskes.net/code/dot2tex/download/
+.. _CTAN: http://www.ctan.org/tex-archive/help/Catalogue/entries/dot2tex.html
+
+Using easy_install
+------------------
+
+The easiest way to install dot2tex is to use `easy_install`_::
+
+ $ easy_install dot2tex
+
+The command will locate dot2tex and download it automatically. Note that
+documentation and examples are not installed by default. `Easy_install`_
+will also create a wrapper script or EXE file for you and install dependencies
+if necessary.
+
+.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
+
+Binary packages
+---------------
+
+Binary packages are available for Debian_ and OpenSUSE_.
+
+.. _Debian: http://packages.qa.debian.org/d/dot2tex.html
+.. _OpenSUSE: http://download.opensuse.org/repositories/home:/jimfunk/
+
+
+What's new in version 2.7.0
+===========================
+
+- Added the --codeonly option. When this option is used, only draw commands
+ are generated. Intended for use with the dot2texi package.
+- Minor improvements to the documentation.
+
+For a full list of changes see changelog.txt
diff --git a/graphics/dot2tex/changelog.txt b/graphics/dot2tex/changelog.txt
new file mode 100644
index 0000000000..b4a86c94d9
--- /dev/null
+++ b/graphics/dot2tex/changelog.txt
@@ -0,0 +1,124 @@
+Dot2TeX change log
+------------------
+
++ New feature
+* Changed/Improved feature
+! Fixed bug
+- Removed feature
+
+The last digit in the version number denotes bug-fix releases.
+
+v 2.7.0
+ + Added the --codeonly option. When this option is used, only draw
+ commands are generated. Intended for use with the dot2texi package.
+ * Minor improvements to the documentation.
+ + Added graphanndtti.tex example.
+
+v 2.6.1
+ ! Fixed missing header in the file dot2tex/dotex
+ ! Fixed various typos in the documentation
+
+v 2.6.0
+ + Added the --autosize option. Equivalent to
+ > dot2tex --preproc ex.dot | dot2tex
+ + Added the --prog option for choosing between dot, neato, circo, towpi
+ and fdp, when the input is in plain dot format.
+ + Added the special d2toptions graph attribute. Allows you to specify
+ dot2tex options in command line format.
+ * Added a dot2tex wrapper script and changed setup.py to make it fully
+ compatible with both setuptools and distutils. A dot2tex module will
+ now be put in the site-packages directory and a wrapper script in the
+ scripts directory.
+ ! Fixed typo in error message.
+ + Added --runtests option to run doc tests (experimental).
+ ! Fixed issue with wrong template when both the --preview and --figonly
+ options were used.
+
+v 2.5.0
+ + Added the TikZ output format (-f tikz)
+ + Added the lblstyle attribute for styling graph, node and edge labels.
+ (PGF and TikZ only)
+ + Added the --tikzedgelabels option for placing edge labels without
+ using xdot edge label information (tikz and pgf output format only).
+ + Added a topath edge attribute for using TikZ' to paths (tikz and
+ pgf only).
+ * Information about the selected output format is now stored in the graph
+ generated in preprocessing mode. No longer necessary to specify an
+ output format in the final run.
+ ! Edges with the same source and dest are now handled correctly in
+ preprocessing mode. Only the edge defined last was preprocessed.
+ + Added the --nodeoptions and --edgeoptions options and corresponding
+ d2tnodeoptions and d2tedgeoptions graph attribute (tikz only).
+ + Added the exstyle attribute. Ignored in preprocessing mode. (pgf and
+ tikz only)
+
+v 2.0.3
+ ! Special TeX char escape code rewritten. Now works as intended.
+ The $ character was not properly escaped.
+ ! Added & to list of special characters.
+
+
+v 2.0.2
+ ! Fixed a severe bug in the interpretation of color attributes in edges.
+ Colors were not reset after a change to a single edge color.
+
+v 2.0.1
+ ! Node margins are now interpreted correctly for nodes with size < minsize.
+ ! Nodes now grow correctly to fit labels when size > minsize
+ * Updated documentation with an example on how to change node sizes.
+
+v 2.0.0
+ ! Fixed a number of preprocessing bug related to how node attributes are
+ interpreted.
+ + Added automata.dot example.
+
+v 2.0.0b
+ * Changed the name of the --preview option to --crop.
+ + Added the --preproc option for preprocessing labels with preview.sty.
+ + Added the --debug option. Writes detailed debug information to dot2tex.log.
+ ! The ^ char is now properly escaped.
+ * Default PGF/TikZ template now requires PGF v >= 1.09.
+ + Added new template tags to support preprocessing mode.
+ + Templates for preprocessing, output and figonly mode can now be put
+ in the same file.
+ + Added the --alignstr option.
+ + Added the --valignmode option.
+ + Added the --usepdflatex option.
+
+v 1.5.0
+ # Released 2006-10-22
+ * Added a few more helpfull error messages.
+ + Added the --figonly option.
+ ! The $ character is now properly escaped.
+ ! Fixed a few issues when converting between Graphviz to backend styles.
+ ! Fixed scoping issues when drawing edges in duplicate mode.
+
+v 1.5.0b2
+ ! Added more intelligent detection of xdot input. Older versions of
+ Graphviz does not include the 'xdotversion' attribute in the
+ output.
+
+v 1.5.0b
+ + Styles are now transfered to the PSTricks and PGF/TikZ backend.
+ + Added a force straight line option to avoid using curves for
+ straight edges.
+ * PGF/TikZ is now set as the default backend.
+ ! Fixed a line ending issue in data converted internally to the xdot format.
+ + Added the -V version command line switch
+ + Added the --encoding option
+ + Added option for switching node and graph draw order.
+ ! Fixed bug in PGF/TikZ color handling
+ + Added the --preview option to crop graphs
+ + Added --figpreamble and --figpostamble options and graph attributes.
+ + Added --docpreamble option and d2tdocpreamble graph attribute
+ + Added --graphstyle option
+ + Added --gvcols option
+ * Changed default PGF/TikZ arrow type to >=latex'
+
+v 1.0.1
+ * Fixed bug in gvcols.tex
+
+v 1.0.0
+ * First public release.
+
+
diff --git a/graphics/dot2tex/doc/docgraphs/balls.dot b/graphics/dot2tex/doc/docgraphs/balls.dot
new file mode 100644
index 0000000000..0a8a82d5c4
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/balls.dot
@@ -0,0 +1,13 @@
+// This graph uses special PGF/TikZ styles to create some interesting
+// visual effects. To get the snaked edges run dot2tex with the -s option
+// to force straight edges. Example
+// $ fdp -Txdot balls.dot | dot2tex -s > balls.tex
+graph G {
+ node [shape=circle, fixedsize=True, width="0.2", style="ball color = green", label=""];
+ edge [style="snake=zigzag, green"];
+ a_1 -- c -- a_2;
+ c [style="ball color=black"];
+ edge [style="snake=snake, blue", color=red];
+ node [style="ball color = red", label=""];
+ a_3 -- c -- a_4 --a_3;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/ex1.dot b/graphics/dot2tex/doc/docgraphs/ex1.dot
new file mode 100644
index 0000000000..aa26d70308
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/ex1.dot
@@ -0,0 +1,3 @@
+digraph G {
+ a_1-> a_2 -> a_3 -> a_1;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/ex1b.dot b/graphics/dot2tex/doc/docgraphs/ex1b.dot
new file mode 100644
index 0000000000..89503eebad
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/ex1b.dot
@@ -0,0 +1,4 @@
+digraph G {
+ node [shape=circle];
+ a_1-> a_2 -> a_3 -> a_1;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/ex2.dot b/graphics/dot2tex/doc/docgraphs/ex2.dot
new file mode 100644
index 0000000000..dbbeb14dea
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/ex2.dot
@@ -0,0 +1,4 @@
+digraph G {
+ a_1 [texlbl="$\frac{\gamma}{x^2}$"];
+ a_1-> a_2 -> a_3 -> a_1;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/ex3.dot b/graphics/dot2tex/doc/docgraphs/ex3.dot
new file mode 100644
index 0000000000..69dcd79a40
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/ex3.dot
@@ -0,0 +1,8 @@
+digraph G {
+ start;
+ end;
+ node [texmode="math"];
+ a_1;
+ a_2;
+ start -> a_1 -> a_2 -> end;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/ex4.dot b/graphics/dot2tex/doc/docgraphs/ex4.dot
new file mode 100644
index 0000000000..b382ad1cd9
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/ex4.dot
@@ -0,0 +1,10 @@
+digraph G {
+ a_1 [texlbl="$\frac{\gamma}{2x^2+y^3}$"];
+ a_1 -> a_2 -> a_3 -> a_1
+ node [texmode="math"];
+ a_1 -> b_1 -> b_2 -> a_3;
+ b_1 [label="\\frac{\\gamma}{x^2}"];
+ node [texmode="verbatim"]
+ b_4 [label="\\beta"]
+ a_3 -> b_4 -> a_1;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/lblstyle.dot b/graphics/dot2tex/doc/docgraphs/lblstyle.dot
new file mode 100644
index 0000000000..2215b7abc0
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/lblstyle.dot
@@ -0,0 +1,11 @@
+digraph G {
+ node [shape=circle];
+ a -> b [label="label",lblstyle="draw=red,cross out"];
+ b -> c [label="test",lblstyle="below=0.5cm,rotate=20,fill=blue!20"];
+ a [label="aa",lblstyle="blue"];
+ b [lblstyle="font=\Huge"];
+ c [label="ccc", lblstyle="red,rotate=90"];
+ rankdir=LR;
+ label="Graph label";
+ lblstyle="draw,fill=red!20";
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/nodesize.dot b/graphics/dot2tex/doc/docgraphs/nodesize.dot
new file mode 100644
index 0000000000..96c5ca5de9
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/nodesize.dot
@@ -0,0 +1,7 @@
+digraph G {
+ node [shape=rectangle];
+ a_1 [margin="0"]; // will have no effect
+ a_2 [margin="0.7,0.4"];
+ a_3 [width="2",height="1"];
+ a_1-> a_2 -> a_3 -> a_1;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/pgfarrows.dot b/graphics/dot2tex/doc/docgraphs/pgfarrows.dot
new file mode 100644
index 0000000000..eec85a0c87
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/pgfarrows.dot
@@ -0,0 +1,18 @@
+// Examples of PGF/TikZ style arrows. See chapter 14.1 in the PGF/TikZ manual
+// for all availale arrow styles.
+// To generate this graph you can write:
+// $ circo -Txdot pgfarrows.dot | dot2tex.py > pgfarrows.tex
+digraph G {
+ graph [mindist=0.5];
+ node [texmode="math", fixedsize=true, shape=circle, width=0.4, style="fill=green!20"];
+ c -> n_1 [style="-stealth"];
+ c -> n_2 [style="-to"];
+ c -> n_3 [style="-latex"];
+ c -> n_4 [style="-diamond"];
+ c -> n_5 [style="-o"];
+ c -> n_6 [style="{-]}"];
+ c -> n_7 [style="-triangle 90"];
+ c -> n_8 [style="-hooks"];
+ c -> n_9 [style="->>"];
+ c [style="fill=red!80"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/preproc1.dot b/graphics/dot2tex/doc/docgraphs/preproc1.dot
new file mode 100644
index 0000000000..9bf7edf33a
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/preproc1.dot
@@ -0,0 +1,6 @@
+digraph G {
+ node [shape=circle];
+ a_1 [texlbl="$x^2+\frac{\sin y}{y^2+\cos \beta}+\gamma_3$"];
+ a_1 -> a_2 [label=" ", texlbl="$x_1+x_3^2+z+c+v~~$"];
+ a_2 -> a_1;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/pstarrows.dot b/graphics/dot2tex/doc/docgraphs/pstarrows.dot
new file mode 100644
index 0000000000..03e592ef8f
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/pstarrows.dot
@@ -0,0 +1,15 @@
+// Examples of Pstricks style arrows.
+// To generate this graph you can write:
+// $ circo -Txdot pstarrows.dot | dot2tex.py -fpst > pstarrows.tex
+digraph G {
+ d2tdocpreamble="\usepackage{pstricks-add}";
+ graph [mindist=0.5];
+ node [texmode="math", fixedsize=true, shape=circle, width=0.4];
+ c -> n_1 [style="arrows=->"];
+ c -> n_2 [style="arrows=->>"];
+ c -> n_3 [style="arrows=-<"];
+ c -> n_4 [style="arrows=-*"];
+ c -> n_5 [style="arrows=-{]}"];
+ c -> n_6 [style="arrows=-o"];
+ c -> n_7 [style="arrows=-H"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/simple.dot b/graphics/dot2tex/doc/docgraphs/simple.dot
new file mode 100644
index 0000000000..a16a7cf61a
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/simple.dot
@@ -0,0 +1,5 @@
+graph G {
+ mindist = 0.5;
+ node [shape="circle"];
+ a -- b -- c -- a;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/simplelbl.dot b/graphics/dot2tex/doc/docgraphs/simplelbl.dot
new file mode 100644
index 0000000000..c424a3e2c4
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/simplelbl.dot
@@ -0,0 +1,9 @@
+graph G {
+ mindist = 0.5;
+ node [shape="circle"];
+ d2tfigpreamble = "\tikzstyle{mystyle}=[fill=blue!20]";
+ edge [lblstyle="mystyle"];
+ a -- b [label="ab"];
+ b -- c [label="bc"];
+ c -- a [label="ca"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/topaths1.dot b/graphics/dot2tex/doc/docgraphs/topaths1.dot
new file mode 100644
index 0000000000..7fc64c5db8
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/topaths1.dot
@@ -0,0 +1,8 @@
+digraph G {
+ mindist = 0.5;
+ node [shape="circle"];
+ a -> b [topath="bend right"];
+ c -> b [topath="bend left"];
+ c -> a [topath="out=10,in=-90"];
+ b -> b [topath="loop above"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/docgraphs/valignmode1.dot b/graphics/dot2tex/doc/docgraphs/valignmode1.dot
new file mode 100644
index 0000000000..ad18b9fcd1
--- /dev/null
+++ b/graphics/dot2tex/doc/docgraphs/valignmode1.dot
@@ -0,0 +1,7 @@
+digraph G {
+ node [fontsize=10];
+ node0 [label="{left|right}", shape=record];
+ node1 [shape=rectangle, label="node 1"];
+ node0 -> node1;
+ rankdir=LR;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/doc/pdf/balls.pdf b/graphics/dot2tex/doc/pdf/balls.pdf
new file mode 100644
index 0000000000..11e0454e7e
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/balls.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/consistent.pdf b/graphics/dot2tex/doc/pdf/consistent.pdf
new file mode 100644
index 0000000000..2e503cc201
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/consistent.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/dot2texiex1.pdf b/graphics/dot2tex/doc/pdf/dot2texiex1.pdf
new file mode 100644
index 0000000000..8d87082736
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/dot2texiex1.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/dot2texiex2.pdf b/graphics/dot2tex/doc/pdf/dot2texiex2.pdf
new file mode 100644
index 0000000000..fb6296deb3
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/dot2texiex2.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/ex1comb.pdf b/graphics/dot2tex/doc/pdf/ex1comb.pdf
new file mode 100644
index 0000000000..d56e038a4c
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/ex1comb.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/ex1gstyle.pdf b/graphics/dot2tex/doc/pdf/ex1gstyle.pdf
new file mode 100644
index 0000000000..308e3caff4
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/ex1gstyle.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/ex1huge.pdf b/graphics/dot2tex/doc/pdf/ex1huge.pdf
new file mode 100644
index 0000000000..840a5ee5e0
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/ex1huge.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/ex2.pdf b/graphics/dot2tex/doc/pdf/ex2.pdf
new file mode 100644
index 0000000000..8e9cfac903
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/ex2.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/fsm1.pdf b/graphics/dot2tex/doc/pdf/fsm1.pdf
new file mode 100644
index 0000000000..7d24858079
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/fsm1.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/lblstyle.pdf b/graphics/dot2tex/doc/pdf/lblstyle.pdf
new file mode 100644
index 0000000000..b0511c6a56
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/lblstyle.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/nodewidth1.pdf b/graphics/dot2tex/doc/pdf/nodewidth1.pdf
new file mode 100644
index 0000000000..3b1bc450e7
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/nodewidth1.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/nodewidth2.pdf b/graphics/dot2tex/doc/pdf/nodewidth2.pdf
new file mode 100644
index 0000000000..e589035285
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/nodewidth2.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/pgfarrows.pdf b/graphics/dot2tex/doc/pdf/pgfarrows.pdf
new file mode 100644
index 0000000000..254dc67636
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/pgfarrows.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/pgftikzsimple.pdf b/graphics/dot2tex/doc/pdf/pgftikzsimple.pdf
new file mode 100644
index 0000000000..c83eb4f734
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/pgftikzsimple.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/preproc1a.pdf b/graphics/dot2tex/doc/pdf/preproc1a.pdf
new file mode 100644
index 0000000000..fc8b9cc8fd
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/preproc1a.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/preproc1b.pdf b/graphics/dot2tex/doc/pdf/preproc1b.pdf
new file mode 100644
index 0000000000..c4c52be243
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/preproc1b.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/pstarrows.pdf b/graphics/dot2tex/doc/pdf/pstarrows.pdf
new file mode 100644
index 0000000000..3ac7bc1909
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/pstarrows.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/texmode.pdf b/graphics/dot2tex/doc/pdf/texmode.pdf
new file mode 100644
index 0000000000..645b9ab4d9
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/texmode.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/texmodeb.pdf b/graphics/dot2tex/doc/pdf/texmodeb.pdf
new file mode 100644
index 0000000000..eb64e06203
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/texmodeb.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/tikzedgelabels.pdf b/graphics/dot2tex/doc/pdf/tikzedgelabels.pdf
new file mode 100644
index 0000000000..7a455f7899
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/tikzedgelabels.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/topaths1.pdf b/graphics/dot2tex/doc/pdf/topaths1.pdf
new file mode 100644
index 0000000000..b190e25dbb
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/topaths1.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/valignmode0.pdf b/graphics/dot2tex/doc/pdf/valignmode0.pdf
new file mode 100644
index 0000000000..2eb52a2769
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/valignmode0.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/valignmode1.pdf b/graphics/dot2tex/doc/pdf/valignmode1.pdf
new file mode 100644
index 0000000000..80c20af70c
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/valignmode1.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/valignmode2.pdf b/graphics/dot2tex/doc/pdf/valignmode2.pdf
new file mode 100644
index 0000000000..c962a892d8
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/valignmode2.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/pdf/valignmode3.pdf b/graphics/dot2tex/doc/pdf/valignmode3.pdf
new file mode 100644
index 0000000000..36317ed8af
--- /dev/null
+++ b/graphics/dot2tex/doc/pdf/valignmode3.pdf
Binary files differ
diff --git a/graphics/dot2tex/doc/usage.tex b/graphics/dot2tex/doc/usage.tex
new file mode 100644
index 0000000000..5822c406e8
--- /dev/null
+++ b/graphics/dot2tex/doc/usage.tex
@@ -0,0 +1,1738 @@
+\documentclass[10pt,a4paper,english]{article}
+\usepackage{babel}
+\usepackage{ae}
+\usepackage{aeguill}
+\usepackage{shortvrb}
+\usepackage[latin1]{inputenc}
+\usepackage{tabularx}
+\usepackage{longtable}
+\setlength{\extrarowheight}{2pt}
+\usepackage{amsmath}
+\usepackage{graphicx}
+\usepackage{color}
+\usepackage{multirow}
+\usepackage{float}\usepackage{ifthen}
+\usepackage[DIV12]{typearea}
+% generated by Docutils <http://docutils.sourceforge.net/>
+\newlength{\admonitionwidth}
+\setlength{\admonitionwidth}{0.9\textwidth}
+\newlength{\docinfowidth}
+\setlength{\docinfowidth}{0.9\textwidth}
+\newlength{\locallinewidth}
+\newcommand{\optionlistlabel}[1]{\bf #1 \hfill}
+\newenvironment{optionlist}[1]
+{\begin{list}{}
+ {\setlength{\labelwidth}{#1}
+ \setlength{\rightmargin}{1cm}
+ \setlength{\leftmargin}{\rightmargin}
+ \addtolength{\leftmargin}{\labelwidth}
+ \addtolength{\leftmargin}{\labelsep}
+ \renewcommand{\makelabel}{\optionlistlabel}}
+}{\end{list}}
+\newlength{\lineblockindentation}
+\setlength{\lineblockindentation}{2.5em}
+\newenvironment{lineblock}[1]
+{\begin{list}{}
+ {\setlength{\partopsep}{\parskip}
+ \addtolength{\partopsep}{\baselineskip}
+ \topsep0pt\itemsep0.15\baselineskip\parsep0pt
+ \leftmargin#1}
+ \raggedright}
+{\end{list}}
+% begin: floats for footnotes tweaking.
+\setlength{\floatsep}{0.5em}
+\setlength{\textfloatsep}{\fill}
+\addtolength{\textfloatsep}{3em}
+\renewcommand{\textfraction}{0.5}
+\renewcommand{\topfraction}{0.5}
+\renewcommand{\bottomfraction}{0.5}
+\setcounter{totalnumber}{50}
+\setcounter{topnumber}{50}
+\setcounter{bottomnumber}{50}
+% end floats for footnotes
+% some commands, that could be overwritten in the style file.
+\newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}}
+\newcommand{\titlereference}[1]{\textsl{#1}}
+% end of "some commands"
+\ifthenelse{\isundefined{\hypersetup}}{
+\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
+}{}
+\title{dot2tex - A Graphviz to LaTeX converter}
+\author{}
+\date{}
+\hypersetup{
+pdftitle={dot2tex - A Graphviz to LaTeX converter},
+pdfauthor={Kjell Magne Fauske}
+}
+\raggedbottom
+\begin{document}
+\maketitle
+%___________________________________________________________________________
+\begin{center}
+\begin{tabularx}{\docinfowidth}{lX}
+\textbf{Author}: &
+ Kjell Magne Fauske \\
+\textbf{Version}: &
+ 2.7.0 \\
+\textbf{Licence}: &
+ MIT \\
+\end{tabularx}
+\end{center}
+
+\setlength{\locallinewidth}{\linewidth}
+
+
+Dot2tex is a tool for converting graphs generated by \href{http://www.graphviz.org/}{Graphviz} to formats suitable for use with LaTeX. Currently dot2tex can generate code for use with \href{http://tug.org/PSTricks/main.cgi/}{PSTricks} and \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html}{PGF/TikZ}.
+
+The purpose of dot2tex is to give graphs a more LaTeX look and feel. This is accomplished by:
+\begin{itemize}
+\item {}
+Typesetting labels with LaTeX, allowing mathematical notation.
+
+\item {}
+Using native \href{http://tug.org/PSTricks/main.cgi/}{PSTricks} and \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html}{PGF/TikZ} commands for drawing arrows, edges
+and nodes.
+
+\item {}
+Using output specific styles to customize the output.
+
+\end{itemize}
+
+
+%___________________________________________________________________________
+
+\hypertarget{dependencies}{}
+\pdfbookmark[0]{Dependencies}{dependencies}
+\section*{Dependencies}
+\label{dependencies}
+
+The following software and modules are required to run dot2tex:
+\begin{itemize}
+\item {}
+\href{http://www.python.org}{Python} 2.4+
+
+\item {}
+\href{http://pyparsing.wikispaces.com/}{pyparsing}. A recent version is required.
+
+\item {}
+\href{http://dkbza.org/pydot.html}{pydot}
+
+\item {}
+\href{http://www.graphviz.org/}{Graphviz}. A recent version is required.
+
+\item {}
+\href{http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html}{preview}. A LaTeX package for extracting parts of a document. A free-standing part of the \href{http://www.gnu.org/software/auctex/preview-latex.html}{preview-latex}/\href{http://www.gnu.org/software/auctex/}{AUCTeX} bundle.
+
+\end{itemize}
+
+Users have reported problems using dot2tex with old versions of pyparsing and Graphviz.
+
+Dot2tex was developed and tested using \href{http://www.python.org}{Python} 2.4. However, dot2tex will probably run fine using Python 2.3.
+
+
+%___________________________________________________________________________
+
+\hypertarget{installation}{}
+\pdfbookmark[0]{Installation}{installation}
+\section*{Installation}
+\label{installation}
+
+
+%___________________________________________________________________________
+
+\hypertarget{from-source}{}
+\pdfbookmark[1]{From source}{from-source}
+\subsection*{From source}
+\label{from-source}
+
+Download a zip or a tarball from the \href{http://www.fauskes.net/code/dot2tex/download/}{download} page. It is also available on \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/dot2tex.html}{CTAN}. Unpack the file to a directory and run \texttt{python} on the \texttt{setup.py} file:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~python~setup.py~install
+}\end{quote}
+
+This will create a dot2tex module in your Python module directory and a wrapper script in your \texttt{SCRIPTS} directory. Note that a few warnings will be displayed. You can safely ignore them. The warnings are shown because there is some extra information in the \texttt{setup.py} file that distutils does not understand.
+
+
+%___________________________________________________________________________
+
+\hypertarget{using-easy-install}{}
+\pdfbookmark[1]{Using easy{\_}install}{using-easy-install}
+\subsection*{Using easy{\_}install}
+\label{using-easy-install}
+
+The easiest way to install dot2tex is to use \href{http://peak.telecommunity.com/DevCenter/EasyInstall}{easy{\_}install}:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~easy{\_}install~dot2tex
+}\end{quote}
+
+The command will locate dot2tex and download it automatically. Note that documentation and examples are not installed by default. \href{http://peak.telecommunity.com/DevCenter/EasyInstall}{Easy{\_}install} will also create a wrapper script or EXE file for you and install dependencies if necessary.
+
+
+%___________________________________________________________________________
+
+\hypertarget{binary-packages}{}
+\pdfbookmark[1]{Binary packages}{binary-packages}
+\subsection*{Binary packages}
+\label{binary-packages}
+
+Binary packages are available for \href{http://packages.qa.debian.org/d/dot2tex.html}{Debian} and \href{http://download.opensuse.org/repositories/home:/jimfunk/}{OpenSUSE}.
+
+
+%___________________________________________________________________________
+
+\hypertarget{development-version}{}
+\pdfbookmark[1]{Development version}{development-version}
+\subsection*{Development version}
+\label{development-version}
+
+The development version of \texttt{dot2tex} is available from a \href{http://code.google.com/p/dot2tex/source}{Subversion repository} hosted at Google code. To get the code you can use the following command:
+\begin{quote}{\ttfamily \raggedright \noindent
+svn~checkout~http://dot2tex.googlecode.com/svn/trunk/~dot2tex
+}\end{quote}
+
+
+%___________________________________________________________________________
+
+\hypertarget{usage}{}
+\pdfbookmark[0]{Usage}{usage}
+\section*{Usage}
+\label{usage}
+
+Syntax:
+\begin{quote}{\ttfamily \raggedright \noindent
+dot2tex~{[}options{]}~{[}inputfile{]}
+}\end{quote}
+
+Input data is read from standard input if no input file is specified. Output is written to standard output unless a destination file is set with the \texttt{-o} option.
+
+Dot2tex relies on the \href{http://www.graphviz.org/doc/info/output.html\#d:xdot}{xdot format} generated by Graphviz. Dot2tex will automatically run \texttt{dot} on the input data if it is in the plain dot format. If you want to use other layout tools like \texttt{neato} and \texttt{circo}, use the \texttt{-{}-prog} option.
+
+A few examples on how to invoke dot2tex:
+
+Read a file from standard input and write the result to the file \texttt{test.tex}:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot~-Txdot~test.dot~|~dot2tex~>~test.tex~\\
+{\$}~neato~-Txdot~-Gstart=rand~test.dot~|~dot2tex~>~test.tex
+}\end{quote}
+
+Load \texttt{test.dot}, convert it to xdot format and output the resulting graph using the \texttt{tikz} output format to \texttt{testpgf.tex}:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-ftikz~test.dot~>~testtikz.tex
+}\end{quote}
+
+The same as above, but use neato for graph layout:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-prog=neato~-ftikz~test.dot~>~testtikz.tex
+}\end{quote}
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\vspace{2mm}
+\textbf{\large Invoking dot2tex}
+\smallskip
+
+Windows users you have to type \texttt{python dot2tex} to invoke the program.
+If you find this annoying, try the \href{http://effbot.org/zone/exemaker.htm}{ExeMaker} tool from \href{http://effbot.org}{effbot.org}, or better, use \href{http://peak.telecommunity.com/DevCenter/EasyInstall}{easy{\_}install} to install dot2tex.
+}}
+\end{sffamily}
+\end{center}
+
+
+%___________________________________________________________________________
+
+\hypertarget{options}{}
+\pdfbookmark[1]{Options}{options}
+\subsection*{Options}
+\label{options}
+
+The following options are available:
+\begin{optionlist}{3cm}
+\item [-h, -{}-help]
+Display help message.
+\item [-f fmt, -{}-format fmt]
+Set output format. The following values of \titlereference{fmt} are supported:
+\begin{description}
+\item[{\texttt{pgf}}] \leavevmode
+PGF/TikZ. Default.
+
+\item[{\texttt{pstricks} or \texttt{pst}}] \leavevmode
+Use PSTricks.
+
+\item[{\texttt{tikz}}] \leavevmode
+TikZ format.
+
+\end{description}
+\item [-t mode, -{}-texmode mode]
+Text mode. Specify how text is converted.
+\begin{description}
+\item[{\texttt{verbatim}}] \leavevmode
+Text is displayed with all special TeX chars escaped (default).
+
+\item[{\texttt{math}}] \leavevmode
+Output all text in math mode {\$}{\$}.
+
+\item[{\texttt{raw}}] \leavevmode
+Output text without any processing.
+
+\end{description}
+
+Note that you can locally override the text mode by assigning a special \texttt{texlbl} attribute to a graph element, or by using the \texttt{texmode} attribute.
+\item [-s, -{}-straightedges]
+Draw edges using straight lines. Graphviz uses bezier curves to draw straight edges. Use this option to force the use of line to operations instead of curves. Does not work in \texttt{duplicate} mode.
+\item [-o filename, -{}-output filename]
+Write output to file.
+\item [-d, -{}-duplicate]
+Duplicate the xdot output. Uses the drawing information embedded in the xdot output to draw nodes and edges.
+\item [-{}-template filename]
+Use template from file. See the \href{\#templates}{templates} section for more details.
+\item [-V, -{}-version]
+Print version information and exit.
+\item [-w, -{}-switchdraworder]
+Switch drawing order of nodes and edges. By default edges are drawn before nodes.
+\item [-c, -{}-crop]
+Use \texttt{preview.sty} to crop the graph. Currently only implemented for the \texttt{pgf} and \texttt{tikz} output format.
+\item [-{}-figonly]
+Output the graph without a document preamble. Useful if the graph is to be included in a master document.
+\item [-{}-codeonly]
+Output only the drawing commands, without wrapping it in a \texttt{tikzpicture} or \texttt{pspicture} environment. Useful when used with the dot2texi package.
+\item [-{}-preproc]
+Preprocess the graph through LaTeX using the \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html}{preview} package. Will generate a new dot file where the height and widths of nodes and edge labels are set based on the results from \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html}{preview}.
+\item [-{}-autosize]
+Preprocess the graph and run Graphviz on the output. Equivalent to:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-preproc~ex1.dot~|~dot2tex
+}\end{quote}
+\item [-{}-prog program]
+Set graph layout program to use when the input is in plain dot format. Allowed values:
+\begin{itemize}
+\item {}
+\texttt{dot} (default)
+
+\item {}
+\texttt{neato}
+
+\item {}
+\texttt{circo}
+
+\item {}
+\texttt{fdp}
+
+\item {}
+\texttt{twopi}
+
+\end{itemize}
+\item [-{}-usepdflatex]
+Use pdflatex instead of latex for preprocessing the graph.
+\item [-{}-nominsize]
+Ignore minimum node sizes during preprocessing.
+\item [-{}-valignmode mode]
+Vertical alignment of node labels, where \texttt{mode} can have the values:
+\begin{description}
+\item[{\texttt{center}}] \leavevmode
+Labels are placed in the middle of the node (default).
+
+\item[{\texttt{dot}}] \leavevmode
+Use the coordinate given by the xdot output from Graphviz.
+
+\end{description}
+
+(\texttt{pgf} and \texttt{pstricks} only)
+\item [-{}-alignstr]
+Used to pass a default alignment string to the PSTricks \texttt{{\textbackslash}rput} command:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}rput{[}alignstr{]}~...
+}\end{quote}
+
+Only works for the PSTricks format. PGF/TikZ users can instead pass an \texttt{anchor=...} style using the \texttt{graphstyle} option.
+\item [-{}-tikzedgelabels]
+Bypass Graphviz' edge label placement and use PGF/TikZ instead (\texttt{tikz} and \texttt{pgf} formats only).
+\item [-{}-styleonly]
+Use TikZ only styles when drawing nodes. No \texttt{draw} or \texttt{shape} option is added (\texttt{tikz} format only).
+\item [-{}-nodeoptions tikzoptions]
+Wrap node code in a \texttt{scope} environment with \texttt{tikzoptions} as parameter (\texttt{tikz} format only).
+\item [-{}-edgeoptions tikzoptions]
+Wrap edge code in a \texttt{scope} environment with \texttt{tikzoptions} as parameter (\texttt{tikz} format only).
+\item [-{}-debug]
+Write detailed debug information to the file dot2tex.log in the current directory.
+\end{optionlist}
+
+The following options are used by the output \href{\#templates}{templates}.
+\begin{optionlist}{3cm}
+\item [-e encoding, -{}-encoding encoding]
+Set text encoding. Supported encodings are:
+\begin{itemize}
+\item {}
+\texttt{utf8}
+
+\item {}
+\texttt{latin1}
+
+\end{itemize}
+\item [-{}-docpreamble TeXcode]
+Insert TeX code in the document preamble.
+\item [-{}-figpreamble TeXcode]
+Insert TeX code in the figure preamble.
+\item [-{}-figpostamble TeXcode]
+Insert TeX code in the figure postamble.
+\item [-{}-graphstyle style]
+Sets the \texttt{<{}<graphstyle>{}>} tag.
+\item [-{}-margin margin]
+Set margin around the graph when using \texttt{preview.sty}. \texttt{margin} must be a valid TeX unit. By default \texttt{margin} is set to \texttt{0pt}.
+\end{optionlist}
+
+
+%___________________________________________________________________________
+
+\hypertarget{output-formats}{}
+\pdfbookmark[0]{Output formats}{output-formats}
+\section*{Output formats}
+\label{output-formats}
+
+The output format is specified with the \texttt{-f fmt} or \texttt{-{}-format fmt} command line option.
+
+
+%___________________________________________________________________________
+
+\hypertarget{pgf}{}
+\pdfbookmark[1]{PGF}{pgf}
+\subsection*{PGF}
+\label{pgf}
+
+This is the default output format. Generates code for the \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html}{Portable Graphics Format} (PGF) package . Mixes both PGF and TikZ commands.
+
+
+%___________________________________________________________________________
+
+\hypertarget{id2}{}
+\pdfbookmark[1]{PSTricks}{id2}
+\subsection*{PSTricks}
+\label{id2}
+
+Generates code for the \href{http://tug.org/PSTricks/main.cgi/}{PSTricks} package.
+
+
+%___________________________________________________________________________
+
+\hypertarget{tikz}{}
+\pdfbookmark[1]{TikZ}{tikz}
+\subsection*{TikZ}
+\label{tikz}
+
+The \texttt{tikz} output format also uses the PGF and TikZ package. However, it relies on TikZ node and edge mechanisms to draw nodes and edges, instead of using the drawing information provided by Graphviz. This allows much tighter integration with TikZ and in some cases prettier results.
+
+Advantages of the \texttt{tikz} format:
+\begin{itemize}
+\item {}
+The generated code is very compact and clean.
+
+\item {}
+Easy to modify the output.
+
+\item {}
+Labels will fit inside nodes without preprocessing.
+
+\item {}
+Full access to the power of PGF and TikZ.
+
+\end{itemize}
+
+You can find more details in the section: \href{\#use-the-tikz-output-format-for-maximum-flexibility}{Use the tikz output format for maximum flexibility}.
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+The \texttt{tikz} output format requires detailed knowledge of the PGF and TikZ package. Some of Graphviz' features will not work with this output format.
+}}
+\end{sffamily}
+\end{center}
+
+
+%___________________________________________________________________________
+
+\hypertarget{labels}{}
+\pdfbookmark[0]{Labels}{labels}
+\section*{Labels}
+\label{labels}
+
+The main purpose of dot2tex is to allow text and labels to be typeset by LaTeX. Labels are treated differently according to the current TeX mode:
+\begin{description}
+\item[{\texttt{verbatim}}] \leavevmode
+Text is displayed with all special TeX chars escaped (default).
+
+\item[{\texttt{math}}] \leavevmode
+Output all text in math mode {\$}{\$}.
+
+\item[{\texttt{raw}}] \leavevmode
+Output text without any processing.
+
+\end{description}
+
+The TeX mode can be set on the command line using the \texttt{-t} option. It can also be set locally in a graph by using the special \texttt{texmode} attribute.
+
+You can also use the special \texttt{texlbl} attribute on a graph element, which is interpreted as \texttt{raw} TeX string. If a \texttt{texlbl} attribute is found, it will be used regardless of the current TeX mode. It also has precedence over the \texttt{label} attribute.
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+The \texttt{{\textbackslash}} character needs to be escaped with \texttt{{\textbackslash}{\textbackslash}} if used in the \texttt{label} attribute.
+}}
+\end{sffamily}
+\end{center}
+
+Note that only position and alignment information is converted. Any font information is lost. This may result in some odd behavior. Some tweaking may be necessary to get it right.
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+If you use \texttt{texlbl} for edges, you have to provide a dummy \texttt{label} attribute. Otherwise Graphviz will not generate the necessary code for placing edge labels.
+}}
+\end{sffamily}
+\end{center}
+
+
+%___________________________________________________________________________
+
+\hypertarget{label-examples}{}
+\pdfbookmark[1]{Label examples}{label-examples}
+\subsection*{Label examples}
+\label{label-examples}
+
+Consider the following graph:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~a{\_}1->~a{\_}2~->~a{\_}3~->~a{\_}1;~\\
+{\}}
+}\end{quote}
+
+Converting the graph using:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~ex1.dot~>~ex1.tex
+}\end{quote}
+
+gives the result shown in the left hand side of the figure below. The default rendering is shown to the right. Using the \texttt{raw} mode will result in a compilation error because of the underscore character.
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/ex1comb}
+\end{figure}
+
+Example of using \texttt{texlbl}:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~a{\_}1~{[}texlbl="{\$}{\textbackslash}frac{\{}{\textbackslash}gamma{\}}{\{}x{\textasciicircum}2{\}}{\$}"{]};~\\
+~~~~a{\_}1->~a{\_}2~->~a{\_}3~->~a{\_}1;~\\
+{\}}
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/ex2}
+\end{figure}
+
+Example of using the \texttt{texmode} attribute:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~a{\_}1~{[}texlbl="{\$}{\textbackslash}frac{\{}{\textbackslash}gamma{\}}{\{}2x{\textasciicircum}2+y{\textasciicircum}3{\}}{\$}"{]};~\\
+~~~~a{\_}1~->~a{\_}2~->~a{\_}3~->~a{\_}1~\\
+~~~~node~{[}texmode="math"{]};~\\
+~~~~a{\_}1~->~b{\_}1~->~b{\_}2~->~a{\_}3;~\\
+~~~~b{\_}1~{[}label="{\textbackslash}{\textbackslash}frac{\{}{\textbackslash}{\textbackslash}gamma{\}}{\{}x{\textasciicircum}2{\}}"{]};~\\
+~~~~node~{[}texmode="verbatim"{]}~\\
+~~~~b{\_}4~{[}label="{\textbackslash}{\textbackslash}beta"{]}~\\
+~~~~a{\_}3~->~b{\_}4~->~a{\_}1;~\\
+{\}}
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/texmode}
+\end{figure}
+
+The above example shows two important things:
+\begin{itemize}
+\item {}
+The backslash \texttt{{\textbackslash}} character needs to be written as \texttt{{\textbackslash}{\textbackslash}} in the \texttt{label} attribute.
+
+\item {}
+Using LaTeX markup in the \texttt{label} attribute gives oversized nodes. A workaround is to use the \texttt{texlbl} attribute, and manually pad the \texttt{label} attribute to an appropriate length. A much better solution is to use the \texttt{-{}-preproc} option.
+
+\end{itemize}
+
+Preprocessing the above graph with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-preproc~ex4.dot~|~dot2tex~>~ex4.tex
+}\end{quote}
+
+gives correctly sized nodes:
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/texmodeb}
+\end{figure}
+
+Read more about preprocessing in the \href{\#preprocessing-graphs}{Preprocessing graphs} section.
+
+
+%___________________________________________________________________________
+
+\hypertarget{vertical-label-alignment}{}
+\pdfbookmark[1]{Vertical label alignment}{vertical-label-alignment}
+\subsection*{Vertical label alignment}
+\label{vertical-label-alignment}
+
+Dot2tex relies on the xdot format for drawing nodes and placing node labels. The fonts that Graphviz and LaTeX use are different, so using the label coordinates from Graphviz does not always give good results. Dot2tex's default behavior is to place node labels in the middle of the node. However, you can change this behavior by setting the \texttt{valignmode} option to \texttt{dot}. Labels will then be placed using the coordinates supplied by Graphviz.
+
+Here is an example graph where it is necessary to use the \texttt{valignmode} option:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~node0~{[}label="{\{}left|right{\}}",~shape=record{]};~\\
+~~~~node1~{[}shape=rectangle,~label="node~1"{]};~\\
+~~~~node0~->~node1;~\\
+~~~~rankdir=LR;~\\
+{\}}
+}\end{quote}
+
+For record nodes dot2tex has to use Graphviz coordinates. This is shown in the following figure rendered with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~valign.dot
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/valignmode0}
+\end{figure}
+
+To get the same vertical alignment for both nodes, you can use:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-valignmode=dot~valign.dot
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/valignmode1}
+\end{figure}
+
+Now the labels are aligned, but the labels are still placed too low. The reason for this is that both PSTricks and PGF by default centers text vertically on the current coordinate. The alignment point should in this case be set to the baseline. For PGF/TikZ you can use the \texttt{-{}-graphstyle} option like this:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-valignmode=dot~-{}-graphstyle="anchor=base"~valign.dot
+}\end{quote}
+
+PSTricks users have to use the \texttt{-{}-alingstr} option:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-valignmode=dot~-{}-alignstr=B~valign.dot
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/valignmode2}
+\end{figure}
+
+The result is better, but to get even better alignment you have to change the node font size. Graphviz' default font size is 14pt, which is larger than the typical 10pt or 11pt used in LaTeX documents. By changing the node font size to 10pt we can trick Graphviz to give us a better alignment:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~node~{[}fontsize=10{]};~\\
+~~~~node0~{[}label="{\{}left|right{\}}",~shape=record{]};~\\
+~~~~node1~{[}shape=rectangle,~label="node~1"{]};~\\
+~~~~node0~->~node1;~\\
+~~~~rankdir=LR;~\\
+{\}}
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/valignmode3}
+\end{figure}
+
+
+%___________________________________________________________________________
+
+\hypertarget{preprocessing-graphs}{}
+\pdfbookmark[0]{Preprocessing graphs}{preprocessing-graphs}
+\section*{Preprocessing graphs}
+\label{preprocessing-graphs}
+
+A problem with using LaTeX for typesetting node and edge labels, is that Graphviz does not know the sizes of the resulting labels. To circumvent this problem, you can use the \texttt{-{}-preproc} or \texttt{-{}-autosize} option. The following will then happen:
+\newcounter{listcnt0}
+\begin{list}{\arabic{listcnt0}.}
+{
+\usecounter{listcnt0}
+\setlength{\rightmargin}{\leftmargin}
+}
+\item {}
+Node and edge labels are extracted and the corresponding LaTeX markup is saved to a temporary file.
+
+\item {}
+The file is typeset with LaTeX and information about sizes is extracted using the \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html}{preview} package.
+
+\item {}
+A new dot file is created where node and edge label sizes are set using the dot language's \texttt{width} and \texttt{height} attributes.
+
+\item {}
+The generated graph can now be processed using Graphviz and dot2tex. Label sizes will now correspond with the output from LaTeX.
+
+\end{list}
+
+Widths and heights of nodes are handled the in same way as Graphviz does it. The \texttt{width} and \texttt{height} attributes set the minimum size of the node. If label size + margins is larger that the minimum size, the node size will grow accordingly. Default values are width=0.75in and height=0.5in.
+
+Node margins are set using the \href{http://graphviz.org/doc/info/attrs.html\#d:margin}{margin} attribute. This also works for edge labels. \texttt{margin==value} sets both the horizontal and vertical margin to \texttt{value}, \texttt{margin=="hvalue,vvalue"} sets the horizontal and vertical margins respectively.
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+All sizes are given in inches.
+}}
+\end{sffamily}
+\end{center}
+
+If you do not want a minimum node size, you can use the '-{}-nominsize' option. Dot2tex will then use size of label + margins as node size.
+
+Nodes with \texttt{fixedsize=True} attributes are not processed.
+
+Limitations:
+\begin{itemize}
+\item {}
+Does not work for HTML-labels
+
+\item {}
+Does not work for record-based nodes
+
+\end{itemize}
+
+
+%___________________________________________________________________________
+
+\hypertarget{examples}{}
+\pdfbookmark[1]{Examples}{examples}
+\subsection*{Examples}
+\label{examples}
+
+Consider the following graph:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~node~{[}shape=circle{]};~\\
+~~~~a{\_}1~{[}texlbl="{\$}x{\textasciicircum}2+{\textbackslash}frac{\{}{\textbackslash}sin~y{\}}{\{}y{\textasciicircum}2+{\textbackslash}cos~{\textbackslash}beta{\}}+{\textbackslash}gamma{\_}3{\$}"{]};~\\
+~~~~a{\_}1~->~a{\_}2~{[}label="~",~texlbl="{\$}x{\_}1+x{\_}3{\textasciicircum}2+z+c+v{\textasciitilde}{\textasciitilde}{\$}"{]};~\\
+~~~~a{\_}2~->~a{\_}1;~\\
+{\}}
+}\end{quote}
+
+Rendered with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~example.dot~>~example.tex
+}\end{quote}
+
+the graph will look like this:
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/preproc1a}
+\end{figure}
+
+You could improve the result by adding a longer \texttt{label} attribute or setting a fixed width. A better solution is to preprocess the graph like this:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~-{}-preproc~example.dot~>~exampletmp.dot~\\
+{\$}~dot2tex~exampletmp.dot~>~example.tex
+}\end{quote}
+
+You can also chain the commands:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~-{}-preproc~example.dot~|~dot2tex~>~example.tex
+}\end{quote}
+
+A shorter alternative is:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~-{}-autosize~example.dot~>~example.tex
+}\end{quote}
+
+The resulting graph now has correctly sized nodes and edge labels:
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/preproc1b}
+\end{figure}
+
+Modifying node sizes using the \texttt{widht/height} and \texttt{margin} attributes can be a bit counterintuitive. A few examples will hopefully make it clearer:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~node~{[}shape=rectangle{]};~\\
+~~~~a{\_}1~{[}margin="0"{]};~\\
+~~~~a{\_}2~{[}margin="0.7,0.4"{]};~\\
+~~~~a{\_}3~{[}width="2",height="1"{]};~\\
+~~~~a{\_}1->~a{\_}2~->~a{\_}3~->~a{\_}1;~\\
+{\}}
+}\end{quote}
+
+Processing the graph with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~-{}-preproc~example.dot~|~dot2tex~>~example.tex
+}\end{quote}
+
+gives
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/nodewidth1}
+\end{figure}
+
+Setting the margin of \texttt{a{\_}1} to 0 has no effect because of the minimum node width. Processing the graph with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~-{}-preproc~-{}-nominsize~example.dot~|~dot2tex~>~example.tex
+}\end{quote}
+
+gives a different graph, where only label widths and margins affect the node sizes:
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/nodewidth2}
+\end{figure}
+
+
+%___________________________________________________________________________
+
+\hypertarget{customizing-the-output}{}
+\pdfbookmark[0]{Customizing the output}{customizing-the-output}
+\section*{Customizing the output}
+\label{customizing-the-output}
+
+Dot2tex offers a few ways of modifying the generated output.
+
+
+%___________________________________________________________________________
+
+\hypertarget{using-styles}{}
+\pdfbookmark[1]{Using styles}{using-styles}
+\subsection*{Using styles}
+\label{using-styles}
+
+The dot language defines the \texttt{style} attribute that can be used to modify the appearance of graphs, nodes, and edges. The \texttt{style} attribute is passed to the rendering backend, and is a powerful and flexible way of customizing the look and feel of your graphs. Using styles requires detailed knowledge of the output format.
+
+The following example shows how interesting visual results can be achieved with the PGF/TikZ output format. The styles are PGF/TikZ specific. See the user guide for details:
+\begin{quote}{\ttfamily \raggedright \noindent
+graph~G~{\{}~\\
+~~~~node~{[}shape=circle,~fixedsize=True,~width="0.2",~\\
+~~~~~~~~~~style="ball~color~=green",~label="{}"{]};~\\
+~~~~edge~{[}style="snake=zigzag,~green"{]};~\\
+~~~~a{\_}1~-{}-~c~-{}-~a{\_}2;~\\
+~~~~c~{[}style="ball~color=black"{]};~\\
+~~~~edge~{[}style="snake=snake,~blue"{]};~\\
+~~~~node~{[}style="ball~color~=~red",~label="{}"{]};~\\
+~~~~a{\_}3~-{}-~c~-{}-~a{\_}4~-{}-a{\_}3;~\\
+{\}}
+}\end{quote}
+
+The \texttt{snake} styles only work on straight lines. We therefore have to use the \texttt{-s} option. \texttt{fdp} is used to lay out the graph:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~fdp~-TXdot~ball.dot~|~dot2tex~-fpgf~-s~>~balls.tex
+}\end{quote}
+
+The resulting graph is shown below.
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/balls}
+\end{figure}
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+Use the straight edge option \texttt{-s} to force the use of straight lines. Otherwise curves will be used to draw even straight lines.
+}}
+\end{sffamily}
+\end{center}
+
+
+%___________________________________________________________________________
+
+\hypertarget{changing-arrow-types}{}
+\pdfbookmark[2]{Changing arrow types}{changing-arrow-types}
+\subsubsection*{Changing arrow types}
+\label{changing-arrow-types}
+
+The style attribute can be used to change arrow types. A PGF/TikZ example:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~graph~{[}mindist=0.5{]};~\\
+~~~~node~{[}fixedsize=true,~shape=circle,~width=0.4,~style="fill=green!20"{]};~\\
+~~~~c~->~n{\_}1~{[}style="-stealth"{]};~\\
+~~~~c~->~n{\_}2~{[}style="-to"{]};~\\
+~~~~c~->~n{\_}3~{[}style="-latex"{]};~\\
+~~~~c~->~n{\_}4~{[}style="-diamond"{]};~\\
+~~~~c~->~n{\_}5~{[}style="-o"{]};~\\
+~~~~c~->~n{\_}6~{[}style="{\{}-{]}{\}}"{]};~\\
+~~~~c~->~n{\_}7~{[}style="-triangle~90"{]};~\\
+~~~~c~->~n{\_}8~{[}style="-hooks"{]};~\\
+~~~~c~->~n{\_}9~{[}style="->{}>"{]};~\\
+~~~~c~{[}style="fill=red!80"{]};~\\
+{\}}
+}\end{quote}
+
+Rendered with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~circo~-Txdot~pgfarrows.dot~|~dot2tex~-tmath~>~pgfarrows.tex
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/pgfarrows}
+\end{figure}
+
+You can also set the default arrow style by using the \texttt{-{}-graphstyle} option or \texttt{d2tgraphstyle} attribute:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~-{}-graphstyle=">=diamond"~ex1.dot~>~ex1gstyle.tex
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/ex1gstyle}
+\end{figure}
+
+A PSTricks example:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~d2tdocpreamble="{\textbackslash}usepackage{\{}pstricks-add{\}}";~\\
+~~~~graph~{[}mindist=0.5{]};~\\
+~~~~node~{[}texmode="math",~fixedsize=true,~shape=circle,~width=0.4{]};~\\
+~~~~c~->~n{\_}1~{[}style="arrows=->"{]};~\\
+~~~~c~->~n{\_}2~{[}style="arrows=->{}>"{]};~\\
+~~~~c~->~n{\_}3~{[}style="arrows=-<"{]};~\\
+~~~~c~->~n{\_}4~{[}style="arrows=-*"{]};~\\
+~~~~c~->~n{\_}5~{[}style="arrows=-{\{}{]}{\}}"{]};~\\
+~~~~c~->~n{\_}6~{[}style="arrows=-o"{]};~\\
+~~~~c~->~n{\_}7~{[}style="arrows=-H"{]};~\\
+{\}}
+}\end{quote}
+
+Rendered with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~circo~-Txdot~pstarrows.dot~|~dot2tex~-fpst~>~pstarrows.tex
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/pstarrows}
+\end{figure}
+
+The above example shows how the \texttt{d2tdocpreamble} attribute can be used to load additional LaTeX packages. You could also use the \texttt{`-{}-docpreamble} option:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~...~|~dot2tex~-fpst~-{}-docpreamble="{\textbackslash}usepackage{\{}pstricks-add{\}}"~...
+}\end{quote}
+
+
+%___________________________________________________________________________
+
+\hypertarget{label-styles}{}
+\pdfbookmark[2]{Label styles}{label-styles}
+\subsubsection*{Label styles}
+\label{label-styles}
+
+Node, edge and graph labels can be styled using the special \texttt{lblstyle} attribute. However, this only works for the \texttt{pgf} and \texttt{tikz} output formats.
+
+Labels are drawn using code like:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}draw~(157bp,52bp)~node~{\{}label{\}};
+}\end{quote}
+
+When you specify a \texttt{lblstyle} attribute, the style will be given as a parameter to the node like this:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}draw~(157bp,52bp)~node{[}lblstyle{]}~{\{}label{\}};
+}\end{quote}
+
+Example:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~node~{[}shape=circle{]};~\\
+~~~~a~->~b~{[}label="label",lblstyle="draw=red,cross~out"{]};~\\
+~~~~b~->~c~{[}label="test",lblstyle="below=0.5cm,rotate=20,fill=blue!20"{]};~\\
+~~~~a~{[}label="aa",lblstyle="blue"{]};~\\
+~~~~b~{[}lblstyle="font={\textbackslash}Huge"{]};~\\
+~~~~c~{[}label="ccc",~lblstyle="red,rotate=90"{]};~\\
+~~~~label="Graph~label";~\\
+~~~~lblstyle="draw,fill=red!20";~\\
+~~~~rankdir=LR;~\\
+{\}}
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/lblstyle}
+\end{figure}
+
+See the PGF and TikZ documentation for more information about styles.
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+You can use the \texttt{exstyle} attribute in addition to \texttt{lblstyle}. The difference is that \texttt{exstyle} is ignored in preprocessing mode. Useful when using TikZ' \texttt{pin} and \texttt{label} options and you do not want them to influence the graph layout.
+}}
+\end{sffamily}
+\end{center}
+
+
+%___________________________________________________________________________
+
+\hypertarget{node-and-edge-options}{}
+\pdfbookmark[2]{Node and edge options}{node-and-edge-options}
+\subsubsection*{Node and edge options}
+\label{node-and-edge-options}
+
+The \texttt{tikz} output format offers an additional way of customizing the output by using the \texttt{-{}-nodeoptions} and \texttt{-{}-edgeoptions} options, or the \texttt{d2tnodeoptions} and \texttt{d2tedgeoptions} graph attributes. The code for generating nodes and edges will then be wrapped in a \texttt{scope} environment like this:
+\begin{quote}{\ttfamily \raggedright \noindent
+...~\\
+{\textbackslash}begin{\{}scope{\}}{[}nodeoptions{]}~\\
+{\%}~code~for~drawing~nodes~\\
+{\textbackslash}end{\{}scope{\}}~\\
+{\textbackslash}begin{\{}scope{\}}{[}edgeoptions{]}~\\
+{\%}~code~for~drawing~edges~\\
+{\textbackslash}end{\{}scope{\}}~\\
+...
+}\end{quote}
+
+
+%___________________________________________________________________________
+
+\hypertarget{customizing-edges}{}
+\pdfbookmark[0]{Customizing edges}{customizing-edges}
+\section*{Customizing edges}
+\label{customizing-edges}
+
+The \texttt{tikz} and \texttt{pgf} output formats offers a few additional ways of customizing how edges are drawn and how edge edge labels are placed. These features are tightly integrated with TikZ and detailed knowledge of the output format is therefore necessary.
+
+
+%___________________________________________________________________________
+
+\hypertarget{tikz-edge-labels}{}
+\pdfbookmark[1]{TikZ edge labels}{tikz-edge-labels}
+\subsection*{TikZ edge labels}
+\label{tikz-edge-labels}
+
+With the \texttt{-{}-tikzedgelabel} option you can bypass the XDOT edge label placement and let PGF and TikZ do the job instead. This can be useful in some cases. However, this only works properly for straight edges and \texttt{to} paths.
+
+Example:
+\begin{quote}{\ttfamily \raggedright \noindent
+graph~G~{\{}~\\
+~~~~mindist~=~0.5;~\\
+~~~~node~{[}shape="circle"{]};~\\
+~~~~edge~{[}lblstyle="mystyle"{]};~\\
+~~~~a~-{}-~b~{[}label="ab"{]};~\\
+~~~~b~-{}-~c~{[}label="bc"{]};~\\
+~~~~c~-{}-~a~{[}label="ca"{]};~\\
+{\}}
+}\end{quote}
+
+Without the \texttt{-{}-tikzedgelabel} option the code for placing edges will look something like this:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\%}~Edge:~a~-{}-~b~\\
+{\textbackslash}draw~{[}{]}~(28bp,55bp)~-{}-~(28bp,75bp);~\\
+{\textbackslash}draw~(40bp,65bp)~node{[}mystyle{]}~{\{}ab{\}};~\\
+{\%}~Edge:~b~-{}-~c~\\
+{\textbackslash}draw~{[}{]}~(51bp,88bp)~-{}-~(68bp,78bp);~\\
+{\textbackslash}draw~(66bp,96bp)~node{[}mystyle{]}~{\{}bc{\}};~\\
+{\%}~Edge:~c~-{}-~a~\\
+{\textbackslash}draw~{[}{]}~(69bp,51bp)~-{}-~(52bp,41bp);~\\
+{\textbackslash}draw~(53bp,57bp)~node{[}mystyle{]}~{\{}ca{\}};
+}\end{quote}
+
+With the \texttt{tikzedgelabels} option the output is simply:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}draw~{[}{]}~(a)~-{}-~node{[}mystyle{]}~{\{}ab{\}}~(b);~\\
+{\textbackslash}draw~{[}{]}~(b)~-{}-~node{[}mystyle{]}~{\{}bc{\}}~(c);~\\
+{\textbackslash}draw~{[}{]}~(c)~-{}-~node{[}mystyle{]}~{\{}ca{\}}~(a);
+}\end{quote}
+
+The placement of the edge labels depends on the options passed to the edge label node (in this case \texttt{mystyle}), and the curve used to connect the nodes. Some examples of \texttt{mystyle} values are shown in the figure below. The leftmost graph is rendered without the \texttt{tikzedgelabels} option.
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/tikzedgelabels}
+\end{figure}
+
+Limitations:
+\begin{itemize}
+\item {}
+Works best with straight edges and \texttt{to} paths
+
+\item {}
+The \texttt{headlabel} and \texttt{taillabel} attributes are currently not affected by the \texttt{tikzedgelabels} option.
+
+\end{itemize}
+
+
+%___________________________________________________________________________
+
+\hypertarget{to-paths}{}
+\pdfbookmark[1]{To paths}{to-paths}
+\subsection*{To paths}
+\label{to-paths}
+
+The \texttt{topath} edge attribute offers a way to override the edges drawn by Graphviz. When a \texttt{topath} attribute is encountered, dot2tex inserts a so called \texttt{to} path operation to connect the nodes. A number of predefined to paths are defined by TikZ, and you can create your own.
+
+Example:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~mindist~=~0.5;~\\
+~~~~node~{[}shape="circle"{]};~\\
+~~~~a~->~b~{[}topath="bend~right"{]};~\\
+~~~~c~->~b~{[}topath="bend~left"{]};~\\
+~~~~c~->~a~{[}topath="out=10,in=-90"{]};~\\
+~~~~b~->~b~{[}topath="loop~above"{]};~\\
+{\}}
+}\end{quote}
+
+Generating the graph with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~circo~-Txdot~topaths1.dot~|~dot2tex~-ftikz~>~topaths1.tex
+}\end{quote}
+
+yields:
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/topaths1}
+\end{figure}
+
+The generated edge drawing code is:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}draw~{[}->{]}~(a)~to{[}bend~right{]}~(b);~\\
+{\textbackslash}draw~{[}->{]}~(c)~to{[}bend~left{]}~(b);~\\
+{\textbackslash}draw~{[}->{]}~(c)~to{[}out=10,in=-90{]}~(a);~\\
+{\textbackslash}draw~{[}->{]}~(b)~to{[}loop~above{]}~(b);
+}\end{quote}
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+To paths works best with layout tools that generate straight edges (neato, fdp, circo, twopi). The \texttt{topath} attribute overrides the edge routing done by Graphviz. You may therefore end up with overlapping edges.
+}}
+\end{sffamily}
+\end{center}
+
+Here is a larger example that uses the \texttt{automata} library:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~d2tdocpreamble~=~"{\textbackslash}usetikzlibrary{\{}automata{\}}";~\\
+~~~~d2tfigpreamble~=~"{\textbackslash}tikzstyle{\{}every~state{\}}=~{\textbackslash}~\\
+~~~~{[}draw=blue!50,very~thick,fill=blue!20{]}";~\\
+~~~~node~{[}style="state"{]};~\\
+~~~~edge~{[}lblstyle="auto",topath="bend~left"{]};~\\
+~~~~A~{[}style="state,~initial"{]};~\\
+~~~~A~->~B~{[}label=2{]};~\\
+~~~~A~->~D~{[}label=7{]};~\\
+~~~~B~->~A~{[}label=1{]};~\\
+~~~~B~->~B~{[}label=3,topath="loop~above"{]};~\\
+~~~~B~->~C~{[}label=4{]};~\\
+~~~~C~->~F~{[}label=5{]};~\\
+~~~~F~->~B~{[}label=8{]};~\\
+~~~~F~->~D~{[}label=7{]};~\\
+~~~~D~->~E~{[}label=2{]};~\\
+~~~~E~->~A~{[}label="1,6"{]};~\\
+~~~~F~{[}style="state,accepting"{]};~\\
+{\}}
+}\end{quote}
+
+Generated with:
+\begin{quote}{\ttfamily \raggedright \noindent
+neato~-Txdot~fsm1.dot~|~dot2tex~-ftikz~-{}-tikzedgelabels~-{}-styleonly
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/fsm1}
+\end{figure}
+
+
+%___________________________________________________________________________
+
+\hypertarget{color-support}{}
+\pdfbookmark[0]{Color support}{color-support}
+\section*{Color support}
+\label{color-support}
+
+All Graphviz \href{http://www.graphviz.org/doc/info/attrs.html\#k:color}{color formats} are supported, including the RGBA format. Transparency will however only work when using the PGF/TikZ output format.
+
+Named colors are supported, but you have to ensure that the colors are defined in the resulting LaTeX file. The default PSTricks and PGF/TikZ templates load the \texttt{X11names} color scheme defined in the \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/xcolor.html}{xcolor} package. Note that color names in the \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/xcolor.html}{xcolor} package are case sensitive. This is not the case with Graphviz's \href{http://www.graphviz.org/doc/info/colors.html}{color names}. Use \href{http://en.wikipedia.org/wiki/CamelCase}{CamelCase} names in your graphs to ensure compatibility with \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/xcolor.html}{xcolor}.
+
+For convenience, a color definition file \texttt{gcols.tex} is distributed with dot2tex. You can find it in the \texttt{examples} directory. This file defines most of Graphviz's named colors as lower case. Include this file in the preamble if you need it.
+
+
+%___________________________________________________________________________
+
+\hypertarget{templates}{}
+\pdfbookmark[0]{Templates}{templates}
+\section*{Templates}
+\label{templates}
+
+The output from dot2tex is a list of drawing commands. To render the graphics with LaTeX there's a need for some boiling plate code. This code can be customized using simple templates. If no template is specified with the \titlereference{-{}-template} option, a default template will be used.
+
+The following template tags are available:
+\begin{description}
+\item[{\texttt{<{}<drawcommands>{}>}}] \leavevmode
+The actual list of drawing commands.
+
+\item[{\texttt{<{}<figcode>{}>}}] \leavevmode
+Drawing commands wrapped in a figure environment. Note that several important style options are set in the figure environment.
+
+\item[{\texttt{<{}<bbox>{}>}}] \leavevmode
+Bounding box. Example: \texttt{(0bp,0bp)(100bp,100bp)}
+The individual parts of the bounding box are available with the tags:
+\begin{itemize}
+\item {}
+\texttt{<{}<bbox.x0>{}>}
+
+\item {}
+\texttt{<{}<bbox.y0>{}>}
+
+\item {}
+\texttt{<{}<bbox.x1>{}>}
+
+\item {}
+\texttt{<{}<bbox.y1>{}>}
+
+\end{itemize}
+
+Note that the bounding box parts are given without any units.
+
+\item[{\texttt{<{}<textencoding>{}>}}] \leavevmode
+The text encoding used for the output file. Current values are:
+- \texttt{utf8}
+- \texttt{latin1}
+
+\item[{\texttt{<{}<docpreamble>{}>}}] \leavevmode
+Document preamble. The content of this tag is set by the \texttt{-{}-docpreamble} option or \texttt{d2tdocpreamble} graph attribute. Useful for including packages and such.
+
+\item[{\texttt{<{}<figpreamble>{}>}}] \leavevmode
+Figure preamble. The content of this tag is set by the \texttt{-{}-figpreamble} option or \texttt{d2tfigpreamble} graph attribute. Useful for setting font sizes and such.
+
+\item[{\texttt{<{}<preproccode>{}>}}] \leavevmode
+Code generated for preprocessing labels.
+
+\end{description}
+
+Three different templates are used by dot2tex for the preprocessing mode, output mode and figure only mode respectively. The following template tags make it possible to use the same template file for all modes.
+\begin{description}
+\item[{\texttt{<{}<startoutputsection>{}>} and \texttt{<{}<endoutputsection>{}>}}] \leavevmode
+Code between these tags is ignored in preprocessing mode.
+
+\item[{\texttt{<{}<startpreprocsection>{}>} and \texttt{<{}<endpreprocsection>{}>}}] \leavevmode
+Code between these tags is ignored in output mode.
+
+\item[{\texttt{<{}<startfigonlysection>{}>} and \texttt{<{}<endfigonlysection>{}>}}] \leavevmode
+Code between these tags is used as a template when using the \texttt{-{}-figonly} option. Ignored in preprocessing and output mode.
+
+\end{description}
+\begin{center}\begin{sffamily}
+\fbox{\parbox{\admonitionwidth}{
+\textbf{\large Note}
+\vspace{2mm}
+
+Tags that have no value are replaced with an empty string. Insert a \texttt{{\%}} character after a template tag to avoid unwanted line breaks.
+}}
+\end{sffamily}
+\end{center}
+
+
+%___________________________________________________________________________
+
+\hypertarget{default-pgf-tikz-template}{}
+\pdfbookmark[1]{Default PGF/TikZ template}{default-pgf-tikz-template}
+\subsection*{Default PGF/TikZ template}
+\label{default-pgf-tikz-template}
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}documentclass{\{}article{\}}~\\
+{\textbackslash}usepackage{[}x11names,~rgb{]}{\{}xcolor{\}}~\\
+{\textbackslash}usepackage{[}<{}<textencoding>{}>{]}{\{}inputenc{\}}~\\
+{\textbackslash}usepackage{\{}tikz{\}}~\\
+{\textbackslash}usetikzlibrary{\{}snakes,arrows,shapes{\}}~\\
+{\textbackslash}usepackage{\{}amsmath{\}}~\\
+<{}<startpreprocsection>{}>{\%}~\\
+{\textbackslash}usepackage{[}active,auctex{]}{\{}preview{\}}~\\
+<{}<endpreprocsection>{}>{\%}~\\
+<{}<gvcols>{}>{\%}~\\
+<{}<cropcode>{}>{\%}~\\
+<{}<docpreamble>{}>{\%}~\\
+~\\
+{\textbackslash}begin{\{}document{\}}~\\
+{\textbackslash}pagestyle{\{}empty{\}}~\\
+{\%}~\\
+<{}<startpreprocsection>{}>{\%}~\\
+<{}<preproccode>{}>~\\
+<{}<endpreprocsection>{}>{\%}~\\
+{\%}~\\
+<{}<startoutputsection>{}>~\\
+{\textbackslash}enlargethispage{\{}100cm{\}}~\\
+{\%}~Start~of~code~\\
+{\%}~{\textbackslash}begin{\{}tikzpicture{\}}{[}anchor=mid,>=latex',join=bevel,<{}<graphstyle>{}>{]}~\\
+{\textbackslash}begin{\{}tikzpicture{\}}{[}>=latex',join=bevel,<{}<graphstyle>{}>{]}~\\
+{\textbackslash}pgfsetlinewidth{\{}1bp{\}}~\\
+<{}<figpreamble>{}>{\%}~\\
+<{}<drawcommands>{}>~\\
+<{}<figpostamble>{}>{\%}~\\
+{\textbackslash}end{\{}tikzpicture{\}}~\\
+{\%}~End~of~code~\\
+<{}<endoutputsection>{}>~\\
+{\%}~\\
+{\textbackslash}end{\{}document{\}}~\\
+{\%}~\\
+<{}<startfigonlysection>{}>~\\
+{\textbackslash}begin{\{}tikzpicture{\}}{[}>=latex,join=bevel,<{}<graphstyle>{}>{]}~\\
+{\textbackslash}pgfsetlinewidth{\{}1bp{\}}~\\
+<{}<figpreamble>{}>{\%}~\\
+<{}<drawcommands>{}>~\\
+<{}<figpostamble>{}>{\%}~\\
+{\textbackslash}end{\{}tikzpicture{\}}~\\
+<{}<endfigonlysection>{}>
+}\end{quote}
+
+The \texttt{<{}<cropcode>{}>} template tag is available when the \texttt{-{}-preview} option is used. The contents will then be:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}usepackage{[}active,tightpage{]}{\{}preview{\}}~\\
+{\textbackslash}PreviewEnvironment{\{}tikzpicture{\}}~\\
+{\textbackslash}setlength{\textbackslash}PreviewBorder{\{}<{}<margin>{}>{\}}
+}\end{quote}
+
+
+%___________________________________________________________________________
+
+\hypertarget{default-pstricks-template}{}
+\pdfbookmark[1]{Default pstricks template}{default-pstricks-template}
+\subsection*{Default pstricks template}
+\label{default-pstricks-template}
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}documentclass{\{}article{\}}~\\
+{\%}~<{}<bbox>{}>~\\
+{\textbackslash}usepackage{[}x11names{]}{\{}xcolor{\}}~\\
+{\textbackslash}usepackage{[}<{}<textencoding>{}>{]}{\{}inputenc{\}}~\\
+{\textbackslash}usepackage{\{}graphicx{\}}~\\
+{\textbackslash}usepackage{\{}pstricks{\}}~\\
+{\textbackslash}usepackage{\{}amsmath{\}}~\\
+<{}<startpreprocsection>{}>{\%}~\\
+{\textbackslash}usepackage{[}active,auctex{]}{\{}preview{\}}~\\
+<{}<endpreprocsection>{}>{\%}~\\
+<{}<gvcols>{}>{\%}~\\
+<{}<docpreamble>{}>{\%}~\\
+~\\
+~\\
+{\textbackslash}begin{\{}document{\}}~\\
+{\textbackslash}pagestyle{\{}empty{\}}~\\
+<{}<startpreprocsection>{}>{\%}~\\
+<{}<preproccode>{}>{\%}~\\
+<{}<endpreprocsection>{}>{\%}~\\
+<{}<startoutputsection>{}>{\%}~\\
+{\textbackslash}enlargethispage{\{}100cm{\}}~\\
+~\\
+{\%}~Start~of~code~\\
+{\textbackslash}begin{\{}pspicture{\}}{[}linewidth=1bp<{}<graphstyle>{}>{]}<{}<bbox>{}>~\\
+{\textbackslash}pstVerb{\{}2~setlinejoin{\}}~{\%}~set~line~join~style~to~'mitre'~\\
+<{}<figpreamble>{}>{\%}~\\
+<{}<drawcommands>{}>~\\
+<{}<figpostamble>{}>{\%}~\\
+{\textbackslash}end{\{}pspicture{\}}~\\
+{\%}~End~of~code~\\
+<{}<endoutputsection>{}>{\%}~\\
+{\textbackslash}end{\{}document{\}}~\\
+{\%}~\\
+<{}<startfigonlysection>{}>~\\
+{\textbackslash}begin{\{}pspicture{\}}{[}linewidth=1bp<{}<graphstyle>{}>{]}<{}<bbox>{}>~\\
+{\textbackslash}pstVerb{\{}2~setlinejoin{\}}~{\%}~set~line~join~style~to~'mitre'~\\
+<{}<figpreamble>{}>{\%}~\\
+<{}<drawcommands>{}>~\\
+<{}<figpostamble>{}>{\%}~\\
+{\textbackslash}end{\{}pspicture{\}}~\\
+<{}<endfigonlysection>{}>
+}\end{quote}
+
+
+%___________________________________________________________________________
+
+\hypertarget{special-attributes}{}
+\pdfbookmark[0]{Special attributes}{special-attributes}
+\section*{Special attributes}
+\label{special-attributes}
+
+Dot2tex defines several special graph, node and edge attributes. Most of them are not part of the DOT language.
+\begin{description}
+\item[{\texttt{texmode}}] \leavevmode
+Changes locally how \href{\#labels}{labels} are interpreted.
+
+\item[{\texttt{texlbl}}] \leavevmode
+Overrides the current node or edge label.
+
+\item[{\texttt{d2tdocpreamble}}] \leavevmode
+Sets the \texttt{<{}<docpreamble>{}>} tag.
+
+\item[{\texttt{d2tfigpreamble}}] \leavevmode
+Sets the \texttt{<{}<figpreamble>{}>} tag.
+
+\item[{\texttt{d2tfigpostamble}}] \leavevmode
+Sets the \texttt{<{}<figpostable>{}>} tag.
+
+\item[{\texttt{d2tgraphstyle}}] \leavevmode
+Sets the \texttt{<{}<graphstyle>{}>} tag.
+
+\item[{\texttt{d2ttikzedgelabels}}] \leavevmode
+Sets the \texttt{-{}-tikzedgelabels} option.
+
+\item[{\texttt{d2tnodeoptions}}] \leavevmode
+Sets the \texttt{-{}-nodeoptions} option.
+
+\item[{\texttt{d2tedgeoptions}}] \leavevmode
+Sets the \texttt{-{}-edgeoptions} option.
+
+\item[{\texttt{style}}] \leavevmode
+Used to pass styles to the backend. Styles are output format specific, with the exception of the styles defined by the DOT language.
+
+\item[{\texttt{lblstyle}}] \leavevmode
+Used to set styles for drawing graph, node and edge labels. Only works for the \texttt{pgf} and \texttt{tikz} output formats.
+
+\item[{\texttt{exstyle}}] \leavevmode
+The same as \texttt{lblstyle}, except that \texttt{exstyle} is ignored in preprocessing mode.
+
+\item[{\texttt{topath}}] \leavevmode
+Used to set a \texttt{to} path operation for connecting nodes. Only works for the \texttt{tikz} output format.
+
+\item[{\texttt{d2talignstr}}] \leavevmode
+Used to pass a default alignment string to the PSTricks \texttt{{\textbackslash}rput} command:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}rput{[}d2talignstr{]}~...
+}\end{quote}
+
+\item[{\texttt{d2toptions}}] \leavevmode
+Allows you to pass options to dot2tex in the same format as from the command line. The \texttt{d2toptions} value is parsed in the same way as ordinary command line options.
+
+\end{description}
+
+
+%___________________________________________________________________________
+
+\hypertarget{issues-and-limitations}{}
+\pdfbookmark[0]{Issues and limitations}{issues-and-limitations}
+\section*{Issues and limitations}
+\label{issues-and-limitations}
+
+The purpose of dot2tex is to give graphs a more LaTeX friendly look, not to create exact duplicates. However, the program does a descent duplication job when it comes to drawing nodes and edges, but it does not try to duplicate label and annotation formatting.
+
+A list of known limitations:
+\begin{itemize}
+\item {}
+Parallel edges are only supported in the \texttt{duplicate} mode.
+
+\item {}
+Background color of page is currently not set.
+
+\item {}
+The \texttt{fontcolor} attribute is not supported yet.
+
+\item {}
+The \texttt{setlinewidth(.)} attribute is not supported yet.
+
+\item {}
+Pydot/Pyparsing have some problems with the HTML syntax.
+
+\item {}
+Pydot/Pyparsing sometimes choke on valid dot files. If this happen you could try to feed xdot data directly to dot2tex like this:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot~-Txdot~example.dot~|~dot2tex~-o~example.tex
+}\end{quote}
+
+\end{itemize}
+
+
+%___________________________________________________________________________
+
+\hypertarget{text-encoding}{}
+\pdfbookmark[1]{Text encoding}{text-encoding}
+\subsection*{Text encoding}
+\label{text-encoding}
+
+Graphviz's default text encoding is \texttt{utf8}. The \texttt{latin1} encoding can also be used. Utf8 is an unicode encoding and can in theory handle any international characters. However, LaTeX's unicode support is somewhat limited.
+
+
+%___________________________________________________________________________
+
+\hypertarget{tips-and-tricks}{}
+\pdfbookmark[0]{Tips and tricks}{tips-and-tricks}
+\section*{Tips and tricks}
+\label{tips-and-tricks}
+
+
+%___________________________________________________________________________
+
+\hypertarget{fonts}{}
+\pdfbookmark[1]{Fonts}{fonts}
+\subsection*{Fonts}
+\label{fonts}
+
+No font information in the DOT file is preserved by dot2tex. However, there are several ways of modifying the generated LaTeX code to achieve some control of fonts and font sizes.
+\begin{itemize}
+\item {}
+Modifying the templates.
+
+\item {}
+Using the \texttt{d2tdocpreamble} and \texttt{d2tfigpreamble} attributes or command line options.
+
+\item {}
+Using the \texttt{lblstyle} attribute.
+
+\end{itemize}
+
+To increase the font size you can for instance insert a \texttt{{\textbackslash}Huge} command in the figure preamble:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tmath~-{}-figpreamble="{\textbackslash}Huge"~ex1.dot~>~ex1huge.tex
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/ex1huge}
+\end{figure}
+
+
+%___________________________________________________________________________
+
+\hypertarget{debugging}{}
+\pdfbookmark[1]{Debugging}{debugging}
+\subsection*{Debugging}
+\label{debugging}
+
+When making your own templates it is easy to make mistakes, and LaTeX markup in graphs may fail to compile. To make it easier to find errors, invoke dot2tex with the \texttt{-{}-debug} option:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-preproc~-{}-debug~test.dot
+}\end{quote}
+
+A dot2tex.log file will then be generated with detailed information. In the log file you will find the generated LaTeX code, as well as well as the compilation log.
+
+
+%___________________________________________________________________________
+
+\hypertarget{be-consistent}{}
+\pdfbookmark[1]{Be consistent}{be-consistent}
+\subsection*{Be consistent}
+\label{be-consistent}
+
+Be aware of differences between the template you use for preprocessing and code used to generate final output. This is especially important if you use the \texttt{-{}-figonly} option and include the code in a master document. If a 10pt font is used during preprocessing, the result may not be optimal if a 12pt font is used in the final output.
+
+Example. A graph is generated with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-preproc~-tmath~-{}-nominsize~ex1.dot~>~ex1tmp.dot
+}\end{quote}
+
+Running through dot2tex again with:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-{}-figpreamble="{\textbackslash}Huge"~ex1tmp.dot~>~ex1huge.tex
+}\end{quote}
+
+gives labels that do not fit properly inside the nodes.
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/consistent}
+\end{figure}
+
+
+%___________________________________________________________________________
+
+\hypertarget{postprocessing}{}
+\pdfbookmark[1]{Postprocessing}{postprocessing}
+\subsection*{Postprocessing}
+\label{postprocessing}
+
+The output from Graphviz and dot2tex is not perfect. Manual adjustments are sometimes necessary to get the right results for use in a publication. For final and cosmetic adjustments, it is often easier to edit the generated code than to hack the dot source. This is especially true when using the \texttt{tikz} output format.
+
+
+%___________________________________________________________________________
+
+\hypertarget{use-the-special-graph-attributes}{}
+\pdfbookmark[1]{Use the special graph attributes}{use-the-special-graph-attributes}
+\subsection*{Use the special graph attributes}
+\label{use-the-special-graph-attributes}
+
+Dot2tex has many options for customizing the output. Sometimes is is impractical or boring to type the various options at the command line each time you want to create the graph. To avoid this, you can use the special graph attributes. The \texttt{d2toptions} attribute is handy because it is interpreted as command line options.
+
+So instead of typing:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~dot2tex~-tikz~-tmath~-{}-tikzedgelabels~ex1.dot
+}\end{quote}
+
+each time, use \texttt{d2toptions} like this:
+\begin{quote}{\ttfamily \raggedright \noindent
+digraph~G~{\{}~\\
+~~~~d2toptions~="-tikz~-tmath~-{}-tikzedgelabels";~\\
+~~~~...~\\
+{\}}
+}\end{quote}
+
+
+%___________________________________________________________________________
+
+\hypertarget{use-the-tikz-output-format-for-maximum-flexibility}{}
+\pdfbookmark[1]{Use the tikz output format for maximum flexibility}{use-the-tikz-output-format-for-maximum-flexibility}
+\subsection*{Use the tikz output format for maximum flexibility}
+\label{use-the-tikz-output-format-for-maximum-flexibility}
+
+The difference between the \texttt{pgf} and \texttt{tikz} output formats is best shown with an example. Consider the following graph:
+\begin{quote}{\ttfamily \raggedright \noindent
+graph~G~{\{}~\\
+~~~~mindist~=~0.5;~\\
+~~~~node~{[}shape=circle{]};~\\
+~~~~a~-{}-~b~-{}-~c~-{}-~a;~\\
+{\}}
+}\end{quote}
+
+Rendering the graph using \texttt{circo} and the \texttt{pgf} and \texttt{tikz} output formats:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\$}~circo~-Txdot~simple.dot~|~dot2tex~-tmath~-fpgf~-s~\\
+{\$}~circo~-Txdot~simple.dot~|~dot2tex~-tmath~-ftikz~-s
+}\end{quote}
+
+gives visually different graphs:
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/pgftikzsimple}
+\end{figure}
+
+However, the main difference is in the generated code. Here is the \texttt{pgf} output:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\%}~Edge:~a~-{}-~b~\\
+{\textbackslash}draw~{[}{]}~(19bp,38bp)~-{}-~(19bp,60bp);~\\
+{\%}~Edge:~b~-{}-~c~\\
+{\textbackslash}draw~{[}{]}~(35bp,70bp)~-{}-~(55bp,58bp);~\\
+{\%}~Edge:~c~-{}-~a~\\
+{\textbackslash}draw~{[}{]}~(55bp,40bp)~-{}-~(35bp,28bp);~\\
+{\%}~Node:~a~\\
+{\textbackslash}begin{\{}scope{\}}~\\
+{\textbackslash}pgfsetstrokecolor{\{}black{\}}~\\
+{\textbackslash}draw~(19bp,19bp)~ellipse~(18bp~and~19bp);~\\
+{\textbackslash}draw~(19bp,19bp)~node~{\{}{\$}a{\$}{\}};~\\
+{\textbackslash}end{\{}scope{\}}~\\
+{\%}~Node:~b~\\
+{\textbackslash}begin{\{}scope{\}}~\\
+{\textbackslash}pgfsetstrokecolor{\{}black{\}}~\\
+{\textbackslash}draw~(19bp,79bp)~ellipse~(18bp~and~19bp);~\\
+{\textbackslash}draw~(19bp,79bp)~node~{\{}{\$}b{\$}{\}};~\\
+{\textbackslash}end{\{}scope{\}}~\\
+{\%}~Node:~c~\\
+{\textbackslash}begin{\{}scope{\}}~\\
+{\textbackslash}pgfsetstrokecolor{\{}black{\}}~\\
+{\textbackslash}draw~(71bp,49bp)~ellipse~(18bp~and~19bp);~\\
+{\textbackslash}draw~(71bp,49bp)~node~{\{}{\$}c{\$}{\}};~\\
+{\textbackslash}end{\{}scope{\}}
+}\end{quote}
+
+Compare the above code with the \texttt{tikz} output:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}node~(a)~at~(19bp,19bp)~{[}draw,circle,{]}~{\{}{\$}a{\$}{\}};~\\
+{\textbackslash}node~(b)~at~(19bp,79bp)~{[}draw,circle,{]}~{\{}{\$}b{\$}{\}};~\\
+{\textbackslash}node~(c)~at~(71bp,49bp)~{[}draw,circle,{]}~{\{}{\$}c{\$}{\}};~\\
+{\textbackslash}draw~{[}{]}~(a)~-{}-~(b);~\\
+{\textbackslash}draw~{[}{]}~(b)~-{}-~(c);~\\
+{\textbackslash}draw~{[}{]}~(c)~-{}-~(a);
+}\end{quote}
+
+The code is much more compact and it is quite easy to modify the graph.
+
+
+%___________________________________________________________________________
+
+\hypertarget{the-dot2texi-latex-package}{}
+\pdfbookmark[1]{The dot2texi LaTeX package}{the-dot2texi-latex-package}
+\subsection*{The dot2texi LaTeX package}
+\label{the-dot2texi-latex-package}
+
+The dot2texi package allows you to embed DOT graphs directly in you LaTeX document. The package will automatically run \texttt{dot2tex} for you and include the generated code. Example:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}documentclass{\{}article{\}}~\\
+{\textbackslash}usepackage{\{}dot2texi{\}}~\\
+~\\
+{\textbackslash}usepackage{\{}tikz{\}}~\\
+{\textbackslash}usetikzlibrary{\{}shapes,arrows{\}}~\\
+~\\
+{\textbackslash}begin{\{}document{\}}~\\
+{\textbackslash}begin{\{}dot2tex{\}}{[}neato,options=-tmath{]}~\\
+digraph~G~{\{}~\\
+~~~~node~{[}shape="circle"{]};~\\
+~~~~a{\_}1~->~a{\_}2~->~a{\_}3~->~a{\_}4~->~a{\_}1;~\\
+~~~~{\}}~\\
+{\textbackslash}end{\{}dot2tex{\}}~\\
+~\\
+{\textbackslash}end{\{}document{\}}
+}\end{quote}
+
+When the above code is run through LaTeX, the following will happen is shell escape is enabled:
+\begin{itemize}
+\item {}
+The graph is written to file.
+
+\item {}
+\texttt{dot2tex} is run on the DOT file.
+
+\item {}
+The generated code is included in the document.
+
+\end{itemize}
+
+The whole process is completely automated. The generated graph will look like this:
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/dot2texiex1}
+\end{figure}
+
+The \texttt{codeonly} option is useful in conjunction with \texttt{dot2texi}, especially when used with the \texttt{tikz} output format. Here is an example that shows how to annotate a graph:
+\begin{quote}{\ttfamily \raggedright \noindent
+{\textbackslash}documentclass{\{}article{\}}~\\
+{\textbackslash}usepackage{\{}tikz{\}}~\\
+{\textbackslash}usetikzlibrary{\{}arrows,shapes{\}}~\\
+{\textbackslash}usepackage{\{}dot2texi{\}}~\\
+{\textbackslash}begin{\{}document{\}}~\\
+{\%}~Define~layers~\\
+{\textbackslash}pgfdeclarelayer{\{}background{\}}~\\
+{\textbackslash}pgfdeclarelayer{\{}foreground{\}}~\\
+{\textbackslash}pgfsetlayers{\{}background,main,foreground{\}}~\\
+~\\
+{\%}~The~scale~option~is~useful~for~adjusting~spacing~between~nodes.~\\
+{\%}~Note~that~this~works~best~when~straight~lines~are~used~to~connect~\\
+{\%}~the~nodes.~\\
+{\textbackslash}begin{\{}tikzpicture{\}}{[}>=latex',scale=0.8{]}~\\
+~~~~{\%}~set~node~style~\\
+~~~~{\textbackslash}tikzstyle{\{}n{\}}~=~{[}draw,shape=circle,minimum~size=2em,~\\
+~~~~~~~~~~~~~~~~~~~~~~~~inner~sep=0pt,fill=red!20{]}~\\
+~~~~{\textbackslash}begin{\{}dot2tex{\}}{[}dot,tikz,codeonly,styleonly,options=-s~-tmath{]}~\\
+~~~~~~~~digraph~G~~{\{}~\\
+~~~~~~~~~~~~node~{[}style="n"{]};~\\
+~~~~~~~~~~~~A{\_}1~->~B{\_}1;~A{\_}1~->~B{\_}2;~A{\_}1~->~B{\_}3;~\\
+~~~~~~~~~~~~B{\_}1~->~C{\_}1;~B{\_}1~->~C{\_}2;~\\
+~~~~~~~~~~~~B{\_}2~->~C{\_}2;~B{\_}2~->~C{\_}3;~\\
+~~~~~~~~~~~~B{\_}3~->~C{\_}3;~B{\_}3~->~C{\_}4;~\\
+~~~~~~~~{\}}~\\
+~~~~{\textbackslash}end{\{}dot2tex{\}}~\\
+~~~~{\%}~annotations~\\
+~~~~{\textbackslash}node{[}left=1em{]}~at~(C{\_}1.west)~~(l3)~{\{}Level~3{\}};~\\
+~~~~{\textbackslash}node~at~(l3~|-~B{\_}1)~(l2){\{}Level~2{\}};~\\
+~~~~{\textbackslash}node~at~(l3~|-~A{\_}1)~(l1)~{\{}Level~1{\}};~\\
+~~~~{\%}~Draw~lines~to~separate~the~levels.~First~we~need~to~calculate~\\
+~~~~{\%}~where~the~middle~is.~\\
+~~~~{\textbackslash}path~(l3)~-{}-~coordinate~(l32)~(l2)~-{}-~coordinate~(l21)~(l1);~\\
+~~~~{\textbackslash}draw{[}dashed{]}~(C{\_}1~|-~l32)~-{}-~(l32~-|~C{\_}4);~\\
+~~~~{\textbackslash}draw{[}dashed{]}~(C{\_}1~|-~l21)~-{}-~(l21~-|~C{\_}4);~\\
+~~~~{\textbackslash}draw{[}<->,red{]}~(A{\_}1)~to{[}out=-120,in=90{]}~(C{\_}2);~\\
+~~~~{\%}~Highlight~the~A{\_}1~->~B{\_}1~->~C{\_}2~path.~Use~layers~to~draw~\\
+~~~~{\%}~behind~everything.~\\
+~~~~{\textbackslash}begin{\{}pgfonlayer{\}}{\{}background{\}}~\\
+~~~~~~~~{\textbackslash}draw{[}rounded~corners=2em,line~width=3em,blue!20,cap=round{]}~\\
+~~~~~~~~~~~~~~~~(A{\_}1.center)~-{}-~(B{\_}1.west)~-{}-~(C{\_}2.center);~\\
+~~~~{\textbackslash}end{\{}pgfonlayer{\}}~\\
+{\textbackslash}end{\{}tikzpicture{\}}~\\
+{\textbackslash}end{\{}document{\}}
+}\end{quote}
+\begin{figure}[H]
+\centering
+
+\includegraphics{pdf/dot2texiex2}
+\end{figure}
+
+\end{document}
diff --git a/graphics/dot2tex/doc/usage.txt b/graphics/dot2tex/doc/usage.txt
new file mode 100644
index 0000000000..a61f79e766
--- /dev/null
+++ b/graphics/dot2tex/doc/usage.txt
@@ -0,0 +1,1313 @@
+=======================================
+dot2tex - A Graphviz to LaTeX converter
+=======================================
+
+:Author: Kjell Magne Fauske
+
+:Version: 2.7.0
+:Licence: MIT
+
+Dot2tex is a tool for converting graphs generated by Graphviz_ to formats suitable for use with LaTeX. Currently dot2tex can generate code for use with PSTricks_ and `PGF/TikZ`_.
+
+.. _Graphviz: http://www.graphviz.org/
+.. _PSTricks: http://tug.org/PSTricks/main.cgi/
+.. _PGF/TikZ: http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html
+
+The purpose of dot2tex is to give graphs a more LaTeX look and feel. This is accomplished by:
+
+- Typesetting labels with LaTeX, allowing mathematical notation.
+- Using native PSTricks_ and `PGF/TikZ`_ commands for drawing arrows, edges
+ and nodes.
+- Using output specific styles to customize the output.
+
+
+Dependencies
+============
+
+The following software and modules are required to run dot2tex:
+
+- Python_ 2.4+
+- pyparsing_. A recent version is required.
+- pydot_
+- Graphviz_. A recent version is required.
+- preview_. A LaTeX package for extracting parts of a document. A free-standing part of the `preview-latex`_/`AUCTeX`_ bundle.
+
+Users have reported problems using dot2tex with old versions of pyparsing and Graphviz.
+
+Dot2tex was developed and tested using Python_ 2.4. However, dot2tex will probably run fine using Python 2.3.
+
+.. _Python: http://www.python.org
+.. _pyparsing: http://pyparsing.wikispaces.com/
+.. _pydot: http://dkbza.org/pydot.html
+.. _preview: http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html
+.. _preview-latex: http://www.gnu.org/software/auctex/preview-latex.html
+.. _AUCTeX: http://www.gnu.org/software/auctex/
+
+Installation
+============
+
+From source
+-----------
+
+Download a zip or a tarball from the download_ page. It is also available on CTAN_. Unpack the file to a directory and run ``python`` on the ``setup.py`` file::
+
+ $ python setup.py install
+
+This will create a dot2tex module in your Python module directory and a wrapper script in your ``SCRIPTS`` directory. Note that a few warnings will be displayed. You can safely ignore them. The warnings are shown because there is some extra information in the ``setup.py`` file that distutils does not understand.
+
+Using easy_install
+------------------
+
+The easiest way to install dot2tex is to use `easy_install`_::
+
+ $ easy_install dot2tex
+
+The command will locate dot2tex and download it automatically. Note that documentation and examples are not installed by default. `Easy_install`_ will also create a wrapper script or EXE file for you and install dependencies if necessary.
+
+
+.. _download: http://www.fauskes.net/code/dot2tex/download/
+.. _CTAN: http://www.ctan.org/tex-archive/help/Catalogue/entries/dot2tex.html
+.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
+
+Binary packages
+---------------
+
+Binary packages are available for Debian_ and OpenSUSE_.
+
+Development version
+-------------------
+
+The development version of ``dot2tex`` is available from a `Subversion repository`_ hosted at Google code. To get the code you can use the following command::
+
+ svn checkout http://dot2tex.googlecode.com/svn/trunk/ dot2tex
+
+
+.. _Debian: http://packages.qa.debian.org/d/dot2tex.html
+.. _OpenSUSE: http://download.opensuse.org/repositories/home:/jimfunk/
+.. _Subversion repository: http://code.google.com/p/dot2tex/source
+
+Usage
+=====
+
+Syntax::
+
+ dot2tex [options] [inputfile]
+
+
+Input data is read from standard input if no input file is specified. Output is written to standard output unless a destination file is set with the ``-o`` option.
+
+Dot2tex relies on the `xdot format`_ generated by Graphviz. Dot2tex will automatically run ``dot`` on the input data if it is in the plain dot format. If you want to use other layout tools like ``neato`` and ``circo``, use the ``--prog`` option.
+
+.. _xdot format: http://www.graphviz.org/doc/info/output.html#d:xdot
+
+A few examples on how to invoke dot2tex:
+
+Read a file from standard input and write the result to the file ``test.tex``::
+
+ $ dot -Txdot test.dot | dot2tex > test.tex
+ $ neato -Txdot -Gstart=rand test.dot | dot2tex > test.tex
+
+Load ``test.dot``, convert it to xdot format and output the resulting graph using the ``tikz`` output format to ``testpgf.tex``::
+
+ $ dot2tex -ftikz test.dot > testtikz.tex
+
+The same as above, but use neato for graph layout::
+
+ $ dot2tex --prog=neato -ftikz test.dot > testtikz.tex
+
+
+.. admonition:: Invoking dot2tex
+
+ Windows users you have to type ``python dot2tex`` to invoke the program.
+ If you find this annoying, try the `ExeMaker`_ tool from `effbot.org`_, or better, use `easy_install`_ to install dot2tex.
+
+
+
+ .. _ExeMaker: http://effbot.org/zone/exemaker.htm
+ .. _effbot.org: http://effbot.org
+ .. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
+
+
+Options
+-------
+
+The following options are available:
+
+-h, --help
+ Display help message.
+-f fmt, --format fmt
+ Set output format. The following values of `fmt` are supported:
+
+ ``pgf``
+ PGF/TikZ. Default.
+ ``pstricks`` or ``pst``
+ Use PSTricks.
+ ``tikz``
+ TikZ format.
+
+-t mode, --texmode mode
+ Text mode. Specify how text is converted.
+
+ ``verbatim``
+ Text is displayed with all special TeX chars escaped (default).
+ ``math``
+ Output all text in math mode $$.
+ ``raw``
+ Output text without any processing.
+
+ Note that you can locally override the text mode by assigning a special ``texlbl`` attribute to a graph element, or by using the ``texmode`` attribute.
+
+-s, --straightedges
+ Draw edges using straight lines. Graphviz uses bezier curves to draw straight edges. Use this option to force the use of line to operations instead of curves. Does not work in ``duplicate`` mode.
+
+-o filename, --output filename
+ Write output to file.
+
+-d, --duplicate
+ Duplicate the xdot output. Uses the drawing information embedded in the xdot output to draw nodes and edges.
+
+--template filename
+ Use template from file. See the `templates`_ section for more details.
+
+-V, --version
+ Print version information and exit.
+
+-w, --switchdraworder
+ Switch drawing order of nodes and edges. By default edges are drawn before nodes.
+
+-c, --crop
+ Use ``preview.sty`` to crop the graph. Currently only implemented for the ``pgf`` and ``tikz`` output format.
+
+--figonly
+ Output the graph without a document preamble. Useful if the graph is to be included in a master document.
+
+--codeonly
+ Output only the drawing commands, without wrapping it in a ``tikzpicture`` or ``pspicture`` environment. Useful when used with the dot2texi package.
+
+--preproc
+ Preprocess the graph through LaTeX using the preview_ package. Will generate a new dot file where the height and widths of nodes and edge labels are set based on the results from preview_.
+
+--autosize
+ Preprocess the graph and run Graphviz on the output. Equivalent to::
+
+ $ dot2tex --preproc ex1.dot | dot2tex
+
+--prog program
+ Set graph layout program to use when the input is in plain dot format. Allowed values:
+
+ - ``dot`` (default)
+ - ``neato``
+ - ``circo``
+ - ``fdp``
+ - ``twopi``
+
+
+--usepdflatex
+ Use pdflatex instead of latex for preprocessing the graph.
+
+--nominsize
+ Ignore minimum node sizes during preprocessing.
+
+--valignmode mode
+ Vertical alignment of node labels, where ``mode`` can have the values:
+
+ ``center``
+ Labels are placed in the middle of the node (default).
+ ``dot``
+ Use the coordinate given by the xdot output from Graphviz.
+
+ (``pgf`` and ``pstricks`` only)
+
+--alignstr
+ Used to pass a default alignment string to the PSTricks ``\rput`` command::
+
+ \rput[alignstr] ...
+
+ Only works for the PSTricks format. PGF/TikZ users can instead pass an ``anchor=...`` style using the ``graphstyle`` option.
+
+--tikzedgelabels
+ Bypass Graphviz' edge label placement and use PGF/TikZ instead (``tikz`` and ``pgf`` formats only).
+
+--styleonly
+ Use TikZ only styles when drawing nodes. No ``draw`` or ``shape`` option is added (``tikz`` format only).
+
+--nodeoptions tikzoptions
+ Wrap node code in a ``scope`` environment with ``tikzoptions`` as parameter (``tikz`` format only).
+
+--edgeoptions tikzoptions
+ Wrap edge code in a ``scope`` environment with ``tikzoptions`` as parameter (``tikz`` format only).
+
+--debug
+ Write detailed debug information to the file dot2tex.log in the current directory.
+
+The following options are used by the output templates_.
+
+-e encoding, --encoding encoding
+ Set text encoding. Supported encodings are:
+
+ - ``utf8``
+ - ``latin1``
+
+--docpreamble TeXcode
+ Insert TeX code in the document preamble.
+
+--figpreamble TeXcode
+ Insert TeX code in the figure preamble.
+
+--figpostamble TeXcode
+ Insert TeX code in the figure postamble.
+
+--graphstyle style
+ Sets the ``<<graphstyle>>`` tag.
+
+--margin margin
+ Set margin around the graph when using ``preview.sty``. ``margin`` must be a valid TeX unit. By default ``margin`` is set to ``0pt``.
+
+
+Output formats
+==============
+
+The output format is specified with the ``-f fmt`` or ``--format fmt`` command line option.
+
+PGF
+---
+
+This is the default output format. Generates code for the `Portable Graphics Format`_ (PGF) package . Mixes both PGF and TikZ commands.
+
+.. _Portable Graphics Format: http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html
+
+PSTricks
+--------
+
+Generates code for the PSTricks_ package.
+
+TikZ
+----
+
+The ``tikz`` output format also uses the PGF and TikZ package. However, it relies on TikZ node and edge mechanisms to draw nodes and edges, instead of using the drawing information provided by Graphviz. This allows much tighter integration with TikZ and in some cases prettier results.
+
+Advantages of the ``tikz`` format:
+
+- The generated code is very compact and clean.
+- Easy to modify the output.
+- Labels will fit inside nodes without preprocessing.
+- Full access to the power of PGF and TikZ.
+
+You can find more details in the section: `Use the tikz output format for maximum flexibility`_.
+
+.. note:: The ``tikz`` output format requires detailed knowledge of the PGF and TikZ package. Some of Graphviz' features will not work with this output format.
+
+
+Labels
+======
+
+The main purpose of dot2tex is to allow text and labels to be typeset by LaTeX. Labels are treated differently according to the current TeX mode:
+
+``verbatim``
+ Text is displayed with all special TeX chars escaped (default).
+``math``
+ Output all text in math mode $$.
+``raw``
+ Output text without any processing.
+
+The TeX mode can be set on the command line using the ``-t`` option. It can also be set locally in a graph by using the special ``texmode`` attribute.
+
+You can also use the special ``texlbl`` attribute on a graph element, which is interpreted as ``raw`` TeX string. If a ``texlbl`` attribute is found, it will be used regardless of the current TeX mode. It also has precedence over the ``label`` attribute.
+
+.. note:: The ``\`` character needs to be escaped with ``\\`` if used in the ``label`` attribute.
+
+Note that only position and alignment information is converted. Any font information is lost. This may result in some odd behavior. Some tweaking may be necessary to get it right.
+
+.. note:: If you use ``texlbl`` for edges, you have to provide a dummy ``label`` attribute. Otherwise Graphviz will not generate the necessary code for placing edge labels.
+
+Label examples
+--------------
+
+Consider the following graph:
+
+.. sourcecode:: dot
+
+ digraph G {
+ a_1-> a_2 -> a_3 -> a_1;
+ }
+
+Converting the graph using::
+
+ $ dot2tex -tmath ex1.dot > ex1.tex
+
+gives the result shown in the left hand side of the figure below. The default rendering is shown to the right. Using the ``raw`` mode will result in a compilation error because of the underscore character.
+
+.. figure:: img/ex1comb.png
+ :alt: Difference between math and verbatim mode
+
+Example of using ``texlbl``:
+
+.. sourcecode:: dot
+
+ digraph G {
+ a_1 [texlbl="$\frac{\gamma}{x^2}$"];
+ a_1-> a_2 -> a_3 -> a_1;
+ }
+
+.. figure:: img/ex2.png
+ :alt: Using the special texlbl attribute
+
+Example of using the ``texmode`` attribute:
+
+.. sourcecode:: dot
+
+ digraph G {
+ a_1 [texlbl="$\frac{\gamma}{2x^2+y^3}$"];
+ a_1 -> a_2 -> a_3 -> a_1
+ node [texmode="math"];
+ a_1 -> b_1 -> b_2 -> a_3;
+ b_1 [label="\\frac{\\gamma}{x^2}"];
+ node [texmode="verbatim"]
+ b_4 [label="\\beta"]
+ a_3 -> b_4 -> a_1;
+ }
+
+.. figure:: img/texmode.png
+ :alt: Using the special texmode attribute
+
+The above example shows two important things:
+
+- The backslash ``\`` character needs to be written as ``\\`` in the ``label`` attribute.
+- Using LaTeX markup in the ``label`` attribute gives oversized nodes. A workaround is to use the ``texlbl`` attribute, and manually pad the ``label`` attribute to an appropriate length. A much better solution is to use the ``--preproc`` option.
+
+Preprocessing the above graph with::
+
+ $ dot2tex --preproc ex4.dot | dot2tex > ex4.tex
+
+gives correctly sized nodes:
+
+.. figure:: img/texmodeb.png
+ :alt: Preprocessing the graph to get correct node sizes.
+
+Read more about preprocessing in the `Preprocessing graphs`_ section.
+
+
+Vertical label alignment
+------------------------
+
+Dot2tex relies on the xdot format for drawing nodes and placing node labels. The fonts that Graphviz and LaTeX use are different, so using the label coordinates from Graphviz does not always give good results. Dot2tex's default behavior is to place node labels in the middle of the node. However, you can change this behavior by setting the ``valignmode`` option to ``dot``. Labels will then be placed using the coordinates supplied by Graphviz.
+
+Here is an example graph where it is necessary to use the ``valignmode`` option:
+
+.. sourcecode:: dot
+
+ digraph G {
+ node0 [label="{left|right}", shape=record];
+ node1 [shape=rectangle, label="node 1"];
+ node0 -> node1;
+ rankdir=LR;
+ }
+
+For record nodes dot2tex has to use Graphviz coordinates. This is shown in the following figure rendered with::
+
+ $ dot2tex valign.dot
+
+.. figure:: img/valignmode0.png
+ :alt: Vertical alignment for record shapes
+
+To get the same vertical alignment for both nodes, you can use::
+
+ $ dot2tex --valignmode=dot valign.dot
+
+.. figure:: img/valignmode1.png
+ :alt: Vertical alignment with --valignmode=dot
+
+Now the labels are aligned, but the labels are still placed too low. The reason for this is that both PSTricks and PGF by default centers text vertically on the current coordinate. The alignment point should in this case be set to the baseline. For PGF/TikZ you can use the ``--graphstyle`` option like this::
+
+ $ dot2tex --valignmode=dot --graphstyle="anchor=base" valign.dot
+
+PSTricks users have to use the ``--alingstr`` option::
+
+ $ dot2tex --valignmode=dot --alignstr=B valign.dot
+
+.. figure:: img/valignmode2.png
+ :alt: blabla
+
+The result is better, but to get even better alignment you have to change the node font size. Graphviz' default font size is 14pt, which is larger than the typical 10pt or 11pt used in LaTeX documents. By changing the node font size to 10pt we can trick Graphviz to give us a better alignment:
+
+.. sourcecode:: dot
+
+ digraph G {
+ node [fontsize=10];
+ node0 [label="{left|right}", shape=record];
+ node1 [shape=rectangle, label="node 1"];
+ node0 -> node1;
+ rankdir=LR;
+ }
+
+.. figure:: img/valignmode3.png
+ :alt: blabla
+
+Preprocessing graphs
+====================
+
+A problem with using LaTeX for typesetting node and edge labels, is that Graphviz does not know the sizes of the resulting labels. To circumvent this problem, you can use the ``--preproc`` or ``--autosize`` option. The following will then happen:
+
+1. Node and edge labels are extracted and the corresponding LaTeX markup is saved to a temporary file.
+2. The file is typeset with LaTeX and information about sizes is extracted using the preview_ package.
+3. A new dot file is created where node and edge label sizes are set using the dot language's ``width`` and ``height`` attributes.
+4. The generated graph can now be processed using Graphviz and dot2tex. Label sizes will now correspond with the output from LaTeX.
+
+Widths and heights of nodes are handled the in same way as Graphviz does it. The ``width`` and ``height`` attributes set the minimum size of the node. If label size + margins is larger that the minimum size, the node size will grow accordingly. Default values are width=0.75in and height=0.5in.
+
+Node margins are set using the `margin`_ attribute. This also works for edge labels. ``margin==value`` sets both the horizontal and vertical margin to ``value``, ``margin=="hvalue,vvalue"`` sets the horizontal and vertical margins respectively.
+
+.. note:: All sizes are given in inches.
+
+If you do not want a minimum node size, you can use the '--nominsize' option. Dot2tex will then use size of label + margins as node size.
+
+Nodes with ``fixedsize=True`` attributes are not processed.
+
+Limitations:
+
+- Does not work for HTML-labels
+- Does not work for record-based nodes
+
+
+Examples
+--------
+
+Consider the following graph:
+
+.. sourcecode:: dot
+
+ digraph G {
+ node [shape=circle];
+ a_1 [texlbl="$x^2+\frac{\sin y}{y^2+\cos \beta}+\gamma_3$"];
+ a_1 -> a_2 [label=" ", texlbl="$x_1+x_3^2+z+c+v~~$"];
+ a_2 -> a_1;
+ }
+
+Rendered with::
+
+ $ dot2tex -tmath example.dot > example.tex
+
+the graph will look like this:
+
+.. figure:: img/preproc1a.png
+ :alt: Graph with oversized edge and node labels
+
+You could improve the result by adding a longer ``label`` attribute or setting a fixed width. A better solution is to preprocess the graph like this::
+
+ $ dot2tex -tmath --preproc example.dot > exampletmp.dot
+ $ dot2tex exampletmp.dot > example.tex
+
+You can also chain the commands::
+
+ $ dot2tex -tmath --preproc example.dot | dot2tex > example.tex
+
+A shorter alternative is::
+
+ $ dot2tex -tmath --autosize example.dot > example.tex
+
+The resulting graph now has correctly sized nodes and edge labels:
+
+.. figure:: img/preproc1b.png
+ :alt: Graph with preprocessed labels
+
+Modifying node sizes using the ``widht/height`` and ``margin`` attributes can be a bit counterintuitive. A few examples will hopefully make it clearer:
+
+.. sourcecode:: dot
+
+ digraph G {
+ node [shape=rectangle];
+ a_1 [margin="0"];
+ a_2 [margin="0.7,0.4"];
+ a_3 [width="2",height="1"];
+ a_1-> a_2 -> a_3 -> a_1;
+ }
+
+Processing the graph with::
+
+ $ dot2tex -tmath --preproc example.dot | dot2tex > example.tex
+
+gives
+
+.. figure:: img/nodewidth1.png
+ :alt: Graph with preprocessed labels
+
+Setting the margin of ``a_1`` to 0 has no effect because of the minimum node width. Processing the graph with::
+
+ $ dot2tex -tmath --preproc --nominsize example.dot | dot2tex > example.tex
+
+gives a different graph, where only label widths and margins affect the node sizes:
+
+.. figure:: img/nodewidth2.png
+ :alt: Graph with preprocessed labels
+
+
+.. _margin: http://graphviz.org/doc/info/attrs.html#d:margin
+
+
+
+
+Customizing the output
+======================
+
+Dot2tex offers a few ways of modifying the generated output.
+
+Using styles
+------------
+
+The dot language defines the ``style`` attribute that can be used to modify the appearance of graphs, nodes, and edges. The ``style`` attribute is passed to the rendering backend, and is a powerful and flexible way of customizing the look and feel of your graphs. Using styles requires detailed knowledge of the output format.
+
+The following example shows how interesting visual results can be achieved with the PGF/TikZ output format. The styles are PGF/TikZ specific. See the user guide for details:
+
+.. sourcecode:: dot
+
+ graph G {
+ node [shape=circle, fixedsize=True, width="0.2",
+ style="ball color =green", label=""];
+ edge [style="snake=zigzag, green"];
+ a_1 -- c -- a_2;
+ c [style="ball color=black"];
+ edge [style="snake=snake, blue"];
+ node [style="ball color = red", label=""];
+ a_3 -- c -- a_4 --a_3;
+ }
+
+The ``snake`` styles only work on straight lines. We therefore have to use the ``-s`` option. ``fdp`` is used to lay out the graph::
+
+ $ fdp -TXdot ball.dot | dot2tex -fpgf -s > balls.tex
+
+The resulting graph is shown below.
+
+.. figure:: img/balls.png
+ :alt: Using styles to style the PGF/TikZ output.
+
+.. note:: Use the straight edge option ``-s`` to force the use of straight lines. Otherwise curves will be used to draw even straight lines.
+
+
+Changing arrow types
+~~~~~~~~~~~~~~~~~~~~
+
+The style attribute can be used to change arrow types. A PGF/TikZ example:
+
+.. sourcecode:: dot
+
+ digraph G {
+ graph [mindist=0.5];
+ node [fixedsize=true, shape=circle, width=0.4, style="fill=green!20"];
+ c -> n_1 [style="-stealth"];
+ c -> n_2 [style="-to"];
+ c -> n_3 [style="-latex"];
+ c -> n_4 [style="-diamond"];
+ c -> n_5 [style="-o"];
+ c -> n_6 [style="{-]}"];
+ c -> n_7 [style="-triangle 90"];
+ c -> n_8 [style="-hooks"];
+ c -> n_9 [style="->>"];
+ c [style="fill=red!80"];
+ }
+
+Rendered with::
+
+ $ circo -Txdot pgfarrows.dot | dot2tex -tmath > pgfarrows.tex
+
+.. figure:: img/pgfarrows.png
+ :alt: PGF/TikZ style arrows.
+
+You can also set the default arrow style by using the ``--graphstyle`` option or ``d2tgraphstyle`` attribute::
+
+ $ dot2tex -tmath --graphstyle=">=diamond" ex1.dot > ex1gstyle.tex
+
+.. figure:: img/ex1gstyle.png
+ :alt: Setting default PGF/TikZ arrows.
+
+A PSTricks example:
+
+.. sourcecode:: dot
+
+ digraph G {
+ d2tdocpreamble="\usepackage{pstricks-add}";
+ graph [mindist=0.5];
+ node [texmode="math", fixedsize=true, shape=circle, width=0.4];
+ c -> n_1 [style="arrows=->"];
+ c -> n_2 [style="arrows=->>"];
+ c -> n_3 [style="arrows=-<"];
+ c -> n_4 [style="arrows=-*"];
+ c -> n_5 [style="arrows=-{]}"];
+ c -> n_6 [style="arrows=-o"];
+ c -> n_7 [style="arrows=-H"];
+ }
+
+Rendered with::
+
+ $ circo -Txdot pstarrows.dot | dot2tex -fpst > pstarrows.tex
+
+
+.. figure:: img/pstarrows.png
+ :alt: PSTricks style arrows
+
+The above example shows how the ``d2tdocpreamble`` attribute can be used to load additional LaTeX packages. You could also use the ```--docpreamble`` option::
+
+ $ ... | dot2tex -fpst --docpreamble="\usepackage{pstricks-add}" ...
+
+
+Label styles
+~~~~~~~~~~~~
+
+Node, edge and graph labels can be styled using the special ``lblstyle`` attribute. However, this only works for the ``pgf`` and ``tikz`` output formats.
+
+Labels are drawn using code like:
+
+.. sourcecode:: latex
+
+ \draw (157bp,52bp) node {label};
+
+When you specify a ``lblstyle`` attribute, the style will be given as a parameter to the node like this:
+
+.. sourcecode:: latex
+
+ \draw (157bp,52bp) node[lblstyle] {label};
+
+Example:
+
+.. sourcecode:: dot
+
+ digraph G {
+ node [shape=circle];
+ a -> b [label="label",lblstyle="draw=red,cross out"];
+ b -> c [label="test",lblstyle="below=0.5cm,rotate=20,fill=blue!20"];
+ a [label="aa",lblstyle="blue"];
+ b [lblstyle="font=\Huge"];
+ c [label="ccc", lblstyle="red,rotate=90"];
+ label="Graph label";
+ lblstyle="draw,fill=red!20";
+ rankdir=LR;
+ }
+
+
+.. figure:: img/lblstyle.png
+ :alt: Label styles
+
+See the PGF and TikZ documentation for more information about styles.
+
+.. note:: You can use the ``exstyle`` attribute in addition to ``lblstyle``. The difference is that ``exstyle`` is ignored in preprocessing mode. Useful when using TikZ' ``pin`` and ``label`` options and you do not want them to influence the graph layout.
+
+
+Node and edge options
+~~~~~~~~~~~~~~~~~~~~~
+
+The ``tikz`` output format offers an additional way of customizing the output by using the ``--nodeoptions`` and ``--edgeoptions`` options, or the ``d2tnodeoptions`` and ``d2tedgeoptions`` graph attributes. The code for generating nodes and edges will then be wrapped in a ``scope`` environment like this:
+
+.. sourcecode:: latex
+
+ ...
+ \begin{scope}[nodeoptions]
+ % code for drawing nodes
+ \end{scope}
+ \begin{scope}[edgeoptions]
+ % code for drawing edges
+ \end{scope}
+ ...
+
+
+Customizing edges
+=================
+
+The ``tikz`` and ``pgf`` output formats offers a few additional ways of customizing how edges are drawn and how edge edge labels are placed. These features are tightly integrated with TikZ and detailed knowledge of the output format is therefore necessary.
+
+TikZ edge labels
+----------------
+
+With the ``--tikzedgelabel`` option you can bypass the XDOT edge label placement and let PGF and TikZ do the job instead. This can be useful in some cases. However, this only works properly for straight edges and ``to`` paths.
+
+Example:
+
+.. sourcecode:: dot
+
+ graph G {
+ mindist = 0.5;
+ node [shape="circle"];
+ edge [lblstyle="mystyle"];
+ a -- b [label="ab"];
+ b -- c [label="bc"];
+ c -- a [label="ca"];
+ }
+
+Without the ``--tikzedgelabel`` option the code for placing edges will look something like this:
+
+.. sourcecode:: latex
+
+ % Edge: a -- b
+ \draw [] (28bp,55bp) -- (28bp,75bp);
+ \draw (40bp,65bp) node[mystyle] {ab};
+ % Edge: b -- c
+ \draw [] (51bp,88bp) -- (68bp,78bp);
+ \draw (66bp,96bp) node[mystyle] {bc};
+ % Edge: c -- a
+ \draw [] (69bp,51bp) -- (52bp,41bp);
+ \draw (53bp,57bp) node[mystyle] {ca};
+
+With the ``tikzedgelabels`` option the output is simply:
+
+.. sourcecode:: latex
+
+ \draw [] (a) -- node[mystyle] {ab} (b);
+ \draw [] (b) -- node[mystyle] {bc} (c);
+ \draw [] (c) -- node[mystyle] {ca} (a);
+
+The placement of the edge labels depends on the options passed to the edge label node (in this case ``mystyle``), and the curve used to connect the nodes. Some examples of ``mystyle`` values are shown in the figure below. The leftmost graph is rendered without the ``tikzedgelabels`` option.
+
+.. figure:: img/tikzedgelabels.png
+ :alt: blabla
+
+Limitations:
+
+- Works best with straight edges and ``to`` paths
+- The ``headlabel`` and ``taillabel`` attributes are currently not affected by the ``tikzedgelabels`` option.
+
+To paths
+--------
+
+The ``topath`` edge attribute offers a way to override the edges drawn by Graphviz. When a ``topath`` attribute is encountered, dot2tex inserts a so called ``to`` path operation to connect the nodes. A number of predefined to paths are defined by TikZ, and you can create your own.
+
+Example:
+
+.. sourcecode:: dot
+
+ digraph G {
+ mindist = 0.5;
+ node [shape="circle"];
+ a -> b [topath="bend right"];
+ c -> b [topath="bend left"];
+ c -> a [topath="out=10,in=-90"];
+ b -> b [topath="loop above"];
+ }
+
+Generating the graph with::
+
+ $ circo -Txdot topaths1.dot | dot2tex -ftikz > topaths1.tex
+
+yields:
+
+.. figure:: img/topaths1.png
+
+
+The generated edge drawing code is:
+
+.. sourcecode:: latex
+
+ \draw [->] (a) to[bend right] (b);
+ \draw [->] (c) to[bend left] (b);
+ \draw [->] (c) to[out=10,in=-90] (a);
+ \draw [->] (b) to[loop above] (b);
+
+.. note:: To paths works best with layout tools that generate straight edges (neato, fdp, circo, twopi). The ``topath`` attribute overrides the edge routing done by Graphviz. You may therefore end up with overlapping edges.
+
+Here is a larger example that uses the ``automata`` library:
+
+.. sourcecode:: dot
+
+ digraph G {
+ d2tdocpreamble = "\usetikzlibrary{automata}";
+ d2tfigpreamble = "\tikzstyle{every state}= \
+ [draw=blue!50,very thick,fill=blue!20]";
+ node [style="state"];
+ edge [lblstyle="auto",topath="bend left"];
+ A [style="state, initial"];
+ A -> B [label=2];
+ A -> D [label=7];
+ B -> A [label=1];
+ B -> B [label=3,topath="loop above"];
+ B -> C [label=4];
+ C -> F [label=5];
+ F -> B [label=8];
+ F -> D [label=7];
+ D -> E [label=2];
+ E -> A [label="1,6"];
+ F [style="state,accepting"];
+ }
+
+Generated with::
+
+ neato -Txdot fsm1.dot | dot2tex -ftikz --tikzedgelabels --styleonly
+
+.. figure:: img/fsm1.png
+ :alt: blabla
+
+
+
+Color support
+=============
+
+All Graphviz `color formats`_ are supported, including the RGBA format. Transparency will however only work when using the PGF/TikZ output format.
+
+.. _color formats: http://www.graphviz.org/doc/info/attrs.html#k:color
+
+Named colors are supported, but you have to ensure that the colors are defined in the resulting LaTeX file. The default PSTricks and PGF/TikZ templates load the ``X11names`` color scheme defined in the xcolor_ package. Note that color names in the xcolor_ package are case sensitive. This is not the case with Graphviz's `color names`_. Use CamelCase_ names in your graphs to ensure compatibility with xcolor_.
+
+.. _CamelCase: http://en.wikipedia.org/wiki/CamelCase
+.. _xcolor: http://www.ctan.org/tex-archive/help/Catalogue/entries/xcolor.html
+.. _color names: http://www.graphviz.org/doc/info/colors.html
+
+For convenience, a color definition file ``gcols.tex`` is distributed with dot2tex. You can find it in the ``examples`` directory. This file defines most of Graphviz's named colors as lower case. Include this file in the preamble if you need it.
+
+
+Templates
+=========
+
+The output from dot2tex is a list of drawing commands. To render the graphics with LaTeX there's a need for some boiling plate code. This code can be customized using simple templates. If no template is specified with the `--template` option, a default template will be used.
+
+The following template tags are available:
+
+``<<drawcommands>>``
+ The actual list of drawing commands.
+
+``<<figcode>>``
+ Drawing commands wrapped in a figure environment. Note that several important style options are set in the figure environment.
+
+``<<bbox>>``
+ Bounding box. Example: ``(0bp,0bp)(100bp,100bp)``
+ The individual parts of the bounding box are available with the tags:
+
+ - ``<<bbox.x0>>``
+ - ``<<bbox.y0>>``
+ - ``<<bbox.x1>>``
+ - ``<<bbox.y1>>``
+
+ Note that the bounding box parts are given without any units.
+
+``<<textencoding>>``
+ The text encoding used for the output file. Current values are:
+ - ``utf8``
+ - ``latin1``
+
+``<<docpreamble>>``
+ Document preamble. The content of this tag is set by the ``--docpreamble`` option or ``d2tdocpreamble`` graph attribute. Useful for including packages and such.
+
+``<<figpreamble>>``
+ Figure preamble. The content of this tag is set by the ``--figpreamble`` option or ``d2tfigpreamble`` graph attribute. Useful for setting font sizes and such.
+
+``<<preproccode>>``
+ Code generated for preprocessing labels.
+
+Three different templates are used by dot2tex for the preprocessing mode, output mode and figure only mode respectively. The following template tags make it possible to use the same template file for all modes.
+
+``<<startoutputsection>>`` and ``<<endoutputsection>>``
+ Code between these tags is ignored in preprocessing mode.
+
+
+``<<startpreprocsection>>`` and ``<<endpreprocsection>>``
+ Code between these tags is ignored in output mode.
+
+``<<startfigonlysection>>`` and ``<<endfigonlysection>>``
+ Code between these tags is used as a template when using the ``--figonly`` option. Ignored in preprocessing and output mode.
+
+
+.. note:: Tags that have no value are replaced with an empty string. Insert a ``%`` character after a template tag to avoid unwanted line breaks.
+
+Default PGF/TikZ template
+-------------------------
+
+.. sourcecode:: latex
+
+ \documentclass{article}
+ \usepackage[x11names, rgb]{xcolor}
+ \usepackage[<<textencoding>>]{inputenc}
+ \usepackage{tikz}
+ \usetikzlibrary{snakes,arrows,shapes}
+ \usepackage{amsmath}
+ <<startpreprocsection>>%
+ \usepackage[active,auctex]{preview}
+ <<endpreprocsection>>%
+ <<gvcols>>%
+ <<cropcode>>%
+ <<docpreamble>>%
+
+ \begin{document}
+ \pagestyle{empty}
+ %
+ <<startpreprocsection>>%
+ <<preproccode>>
+ <<endpreprocsection>>%
+ %
+ <<startoutputsection>>
+ \enlargethispage{100cm}
+ % Start of code
+ % \begin{tikzpicture}[anchor=mid,>=latex',join=bevel,<<graphstyle>>]
+ \begin{tikzpicture}[>=latex',join=bevel,<<graphstyle>>]
+ \pgfsetlinewidth{1bp}
+ <<figpreamble>>%
+ <<drawcommands>>
+ <<figpostamble>>%
+ \end{tikzpicture}
+ % End of code
+ <<endoutputsection>>
+ %
+ \end{document}
+ %
+ <<startfigonlysection>>
+ \begin{tikzpicture}[>=latex,join=bevel,<<graphstyle>>]
+ \pgfsetlinewidth{1bp}
+ <<figpreamble>>%
+ <<drawcommands>>
+ <<figpostamble>>%
+ \end{tikzpicture}
+ <<endfigonlysection>>
+
+
+The ``<<cropcode>>`` template tag is available when the ``--preview`` option is used. The contents will then be:
+
+.. sourcecode:: latex
+
+ \usepackage[active,tightpage]{preview}
+ \PreviewEnvironment{tikzpicture}
+ \setlength\PreviewBorder{<<margin>>}
+
+
+
+Default pstricks template
+-------------------------
+
+.. sourcecode:: latex
+
+ \documentclass{article}
+ % <<bbox>>
+ \usepackage[x11names]{xcolor}
+ \usepackage[<<textencoding>>]{inputenc}
+ \usepackage{graphicx}
+ \usepackage{pstricks}
+ \usepackage{amsmath}
+ <<startpreprocsection>>%
+ \usepackage[active,auctex]{preview}
+ <<endpreprocsection>>%
+ <<gvcols>>%
+ <<docpreamble>>%
+
+
+ \begin{document}
+ \pagestyle{empty}
+ <<startpreprocsection>>%
+ <<preproccode>>%
+ <<endpreprocsection>>%
+ <<startoutputsection>>%
+ \enlargethispage{100cm}
+
+ % Start of code
+ \begin{pspicture}[linewidth=1bp<<graphstyle>>]<<bbox>>
+ \pstVerb{2 setlinejoin} % set line join style to 'mitre'
+ <<figpreamble>>%
+ <<drawcommands>>
+ <<figpostamble>>%
+ \end{pspicture}
+ % End of code
+ <<endoutputsection>>%
+ \end{document}
+ %
+ <<startfigonlysection>>
+ \begin{pspicture}[linewidth=1bp<<graphstyle>>]<<bbox>>
+ \pstVerb{2 setlinejoin} % set line join style to 'mitre'
+ <<figpreamble>>%
+ <<drawcommands>>
+ <<figpostamble>>%
+ \end{pspicture}
+ <<endfigonlysection>>
+
+
+Special attributes
+==================
+
+Dot2tex defines several special graph, node and edge attributes. Most of them are not part of the DOT language.
+
+``texmode``
+ Changes locally how labels_ are interpreted.
+
+``texlbl``
+ Overrides the current node or edge label.
+
+``d2tdocpreamble``
+ Sets the ``<<docpreamble>>`` tag.
+
+``d2tfigpreamble``
+ Sets the ``<<figpreamble>>`` tag.
+
+``d2tfigpostamble``
+ Sets the ``<<figpostable>>`` tag.
+
+``d2tgraphstyle``
+ Sets the ``<<graphstyle>>`` tag.
+
+``d2ttikzedgelabels``
+ Sets the ``--tikzedgelabels`` option.
+
+``d2tnodeoptions``
+ Sets the ``--nodeoptions`` option.
+
+``d2tedgeoptions``
+ Sets the ``--edgeoptions`` option.
+
+``style``
+ Used to pass styles to the backend. Styles are output format specific, with the exception of the styles defined by the DOT language.
+
+``lblstyle``
+ Used to set styles for drawing graph, node and edge labels. Only works for the ``pgf`` and ``tikz`` output formats.
+
+``exstyle``
+ The same as ``lblstyle``, except that ``exstyle`` is ignored in preprocessing mode.
+
+``topath``
+ Used to set a ``to`` path operation for connecting nodes. Only works for the ``tikz`` output format.
+
+``d2talignstr``
+ Used to pass a default alignment string to the PSTricks ``\rput`` command::
+
+ \rput[d2talignstr] ...
+
+``d2toptions``
+ Allows you to pass options to dot2tex in the same format as from the command line. The ``d2toptions`` value is parsed in the same way as ordinary command line options.
+
+
+
+
+
+Issues and limitations
+======================
+
+The purpose of dot2tex is to give graphs a more LaTeX friendly look, not to create exact duplicates. However, the program does a descent duplication job when it comes to drawing nodes and edges, but it does not try to duplicate label and annotation formatting.
+
+A list of known limitations:
+
+- Parallel edges are only supported in the ``duplicate`` mode.
+- Background color of page is currently not set.
+- The ``fontcolor`` attribute is not supported yet.
+- The ``setlinewidth(.)`` attribute is not supported yet.
+- Pydot/Pyparsing have some problems with the HTML syntax.
+- Pydot/Pyparsing sometimes choke on valid dot files. If this happen you could try to feed xdot data directly to dot2tex like this::
+
+ $ dot -Txdot example.dot | dot2tex -o example.tex
+
+
+Text encoding
+-------------
+
+Graphviz's default text encoding is ``utf8``. The ``latin1`` encoding can also be used. Utf8 is an unicode encoding and can in theory handle any international characters. However, LaTeX's unicode support is somewhat limited.
+
+Tips and tricks
+===============
+
+Fonts
+-----
+
+No font information in the DOT file is preserved by dot2tex. However, there are several ways of modifying the generated LaTeX code to achieve some control of fonts and font sizes.
+
+- Modifying the templates.
+- Using the ``d2tdocpreamble`` and ``d2tfigpreamble`` attributes or command line options.
+- Using the ``lblstyle`` attribute.
+
+To increase the font size you can for instance insert a ``\Huge`` command in the figure preamble::
+
+ $ dot2tex -tmath --figpreamble="\Huge" ex1.dot > ex1huge.tex
+
+.. figure:: img/ex1huge.png
+ :alt: Setting label font size to \Huge
+
+Debugging
+---------
+
+When making your own templates it is easy to make mistakes, and LaTeX markup in graphs may fail to compile. To make it easier to find errors, invoke dot2tex with the ``--debug`` option::
+
+ $ dot2tex --preproc --debug test.dot
+
+A dot2tex.log file will then be generated with detailed information. In the log file you will find the generated LaTeX code, as well as well as the compilation log.
+
+Be consistent
+-------------
+
+Be aware of differences between the template you use for preprocessing and code used to generate final output. This is especially important if you use the ``--figonly`` option and include the code in a master document. If a 10pt font is used during preprocessing, the result may not be optimal if a 12pt font is used in the final output.
+
+Example. A graph is generated with::
+
+ $ dot2tex --preproc -tmath --nominsize ex1.dot > ex1tmp.dot
+
+Running through dot2tex again with::
+
+ $ dot2tex --figpreamble="\Huge" ex1tmp.dot > ex1huge.tex
+
+gives labels that do not fit properly inside the nodes.
+
+.. figure:: img/consistent.png
+ :alt: Inconsistence between preproc mode and output mode
+
+Postprocessing
+--------------
+
+The output from Graphviz and dot2tex is not perfect. Manual adjustments are sometimes necessary to get the right results for use in a publication. For final and cosmetic adjustments, it is often easier to edit the generated code than to hack the dot source. This is especially true when using the ``tikz`` output format.
+
+Use the special graph attributes
+--------------------------------
+
+Dot2tex has many options for customizing the output. Sometimes is is impractical or boring to type the various options at the command line each time you want to create the graph. To avoid this, you can use the special graph attributes. The ``d2toptions`` attribute is handy because it is interpreted as command line options.
+
+So instead of typing::
+
+ $ dot2tex -tikz -tmath --tikzedgelabels ex1.dot
+
+each time, use ``d2toptions`` like this:
+
+.. sourcecode:: dot
+
+ digraph G {
+ d2toptions ="-tikz -tmath --tikzedgelabels";
+ ...
+ }
+
+
+
+Use the tikz output format for maximum flexibility
+--------------------------------------------------
+
+The difference between the ``pgf`` and ``tikz`` output formats is best shown with an example. Consider the following graph:
+
+.. sourcecode:: dot
+
+ graph G {
+ mindist = 0.5;
+ node [shape=circle];
+ a -- b -- c -- a;
+ }
+
+Rendering the graph using ``circo`` and the ``pgf`` and ``tikz`` output formats::
+
+ $ circo -Txdot simple.dot | dot2tex -tmath -fpgf -s
+ $ circo -Txdot simple.dot | dot2tex -tmath -ftikz -s
+
+gives visually different graphs:
+
+.. figure:: img/pgftikzsimple.png
+ :alt: Difference between pgf and tikz output format
+
+However, the main difference is in the generated code. Here is the ``pgf`` output:
+
+.. sourcecode:: latex
+
+ % Edge: a -- b
+ \draw [] (19bp,38bp) -- (19bp,60bp);
+ % Edge: b -- c
+ \draw [] (35bp,70bp) -- (55bp,58bp);
+ % Edge: c -- a
+ \draw [] (55bp,40bp) -- (35bp,28bp);
+ % Node: a
+ \begin{scope}
+ \pgfsetstrokecolor{black}
+ \draw (19bp,19bp) ellipse (18bp and 19bp);
+ \draw (19bp,19bp) node {$a$};
+ \end{scope}
+ % Node: b
+ \begin{scope}
+ \pgfsetstrokecolor{black}
+ \draw (19bp,79bp) ellipse (18bp and 19bp);
+ \draw (19bp,79bp) node {$b$};
+ \end{scope}
+ % Node: c
+ \begin{scope}
+ \pgfsetstrokecolor{black}
+ \draw (71bp,49bp) ellipse (18bp and 19bp);
+ \draw (71bp,49bp) node {$c$};
+ \end{scope}
+
+Compare the above code with the ``tikz`` output:
+
+.. sourcecode:: latex
+
+ \node (a) at (19bp,19bp) [draw,circle,] {$a$};
+ \node (b) at (19bp,79bp) [draw,circle,] {$b$};
+ \node (c) at (71bp,49bp) [draw,circle,] {$c$};
+ \draw [] (a) -- (b);
+ \draw [] (b) -- (c);
+ \draw [] (c) -- (a);
+
+The code is much more compact and it is quite easy to modify the graph.
+
+The dot2texi LaTeX package
+--------------------------
+
+The dot2texi package allows you to embed DOT graphs directly in you LaTeX document. The package will automatically run ``dot2tex`` for you and include the generated code. Example:
+
+.. sourcecode:: latex
+
+ \documentclass{article}
+ \usepackage{dot2texi}
+
+ \usepackage{tikz}
+ \usetikzlibrary{shapes,arrows}
+
+ \begin{document}
+ \begin{dot2tex}[neato,options=-tmath]
+ digraph G {
+ node [shape="circle"];
+ a_1 -> a_2 -> a_3 -> a_4 -> a_1;
+ }
+ \end{dot2tex}
+
+ \end{document}
+
+When the above code is run through LaTeX, the following will happen is shell escape is enabled:
+
+- The graph is written to file.
+- ``dot2tex`` is run on the DOT file.
+- The generated code is included in the document.
+
+The whole process is completely automated. The generated graph will look like this:
+
+.. figure:: img/dot2texiex1.png
+ :alt: Graph generated with dot2texi
+
+The ``codeonly`` option is useful in conjunction with ``dot2texi``, especially when used with the ``tikz`` output format. Here is an example that shows how to annotate a graph:
+
+.. sourcecode:: latex
+
+ \documentclass{article}
+ \usepackage{tikz}
+ \usetikzlibrary{arrows,shapes}
+ \usepackage{dot2texi}
+ \begin{document}
+ % Define layers
+ \pgfdeclarelayer{background}
+ \pgfdeclarelayer{foreground}
+ \pgfsetlayers{background,main,foreground}
+
+ % The scale option is useful for adjusting spacing between nodes.
+ % Note that this works best when straight lines are used to connect
+ % the nodes.
+ \begin{tikzpicture}[>=latex',scale=0.8]
+ % set node style
+ \tikzstyle{n} = [draw,shape=circle,minimum size=2em,
+ inner sep=0pt,fill=red!20]
+ \begin{dot2tex}[dot,tikz,codeonly,styleonly,options=-s -tmath]
+ digraph G {
+ node [style="n"];
+ A_1 -> B_1; A_1 -> B_2; A_1 -> B_3;
+ B_1 -> C_1; B_1 -> C_2;
+ B_2 -> C_2; B_2 -> C_3;
+ B_3 -> C_3; B_3 -> C_4;
+ }
+ \end{dot2tex}
+ % annotations
+ \node[left=1em] at (C_1.west) (l3) {Level 3};
+ \node at (l3 |- B_1) (l2){Level 2};
+ \node at (l3 |- A_1) (l1) {Level 1};
+ % Draw lines to separate the levels. First we need to calculate
+ % where the middle is.
+ \path (l3) -- coordinate (l32) (l2) -- coordinate (l21) (l1);
+ \draw[dashed] (C_1 |- l32) -- (l32 -| C_4);
+ \draw[dashed] (C_1 |- l21) -- (l21 -| C_4);
+ \draw[<->,red] (A_1) to[out=-120,in=90] (C_2);
+ % Highlight the A_1 -> B_1 -> C_2 path. Use layers to draw
+ % behind everything.
+ \begin{pgfonlayer}{background}
+ \draw[rounded corners=2em,line width=3em,blue!20,cap=round]
+ (A_1.center) -- (B_1.west) -- (C_2.center);
+ \end{pgfonlayer}
+ \end{tikzpicture}
+ \end{document}
+
+.. figure:: img/dot2texiex2.png
+ :alt: Annotated graph
+
diff --git a/graphics/dot2tex/dot2tex.pdf b/graphics/dot2tex/dot2tex.pdf
new file mode 100644
index 0000000000..49175e800a
--- /dev/null
+++ b/graphics/dot2tex/dot2tex.pdf
Binary files differ
diff --git a/graphics/dot2tex/dot2tex/__init__.py b/graphics/dot2tex/dot2tex/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/graphics/dot2tex/dot2tex/__init__.py
diff --git a/graphics/dot2tex/dot2tex/dot2tex b/graphics/dot2tex/dot2tex/dot2tex
new file mode 100644
index 0000000000..0cff5adb6e
--- /dev/null
+++ b/graphics/dot2tex/dot2tex/dot2tex
@@ -0,0 +1,4 @@
+#!/usr/bin/python
+from dot2tex.dot2tex import main
+if __name__ == '__main__':
+ main() \ No newline at end of file
diff --git a/graphics/dot2tex/dot2tex/dot2tex.py b/graphics/dot2tex/dot2tex/dot2tex.py
new file mode 100644
index 0000000000..034b0718ee
--- /dev/null
+++ b/graphics/dot2tex/dot2tex/dot2tex.py
@@ -0,0 +1,2586 @@
+#!/usr/bin/python
+# -*- coding: Latin-1 -*-
+"""Convert graphviz graphs to LaTeX-friendly formats
+
+Various tools for converting graphs generated by the graphviz library
+to formats for use with LaTeX.
+
+Copyright (c) 2006-2007, Kjell Magne Fauske
+
+"""
+
+# Copyright (c) 2006-2007, Kjell Magne Fauske
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+__author__ = 'Kjell Magne Fauske'
+__version__ = '2.7.0'
+__license__ = 'MIT'
+
+
+from itertools import izip
+from optparse import OptionParser
+import optparse
+import sys, tempfile, os, string,re
+import logging
+import tempfile
+from StringIO import StringIO
+
+# intitalize logging module
+log = logging.getLogger("dot2tex")
+console = logging.StreamHandler()
+console.setLevel(logging.WARNING)
+# set a format which is simpler for console use
+formatter = logging.Formatter('%(levelname)-8s %(message)s')
+# tell the handler to use this format
+console.setFormatter(formatter)
+log.addHandler(console)
+
+
+try:
+ import pydot
+except:
+ log.error("Could not load the pydot module.")
+ sys.exit(1)
+
+DEFAULT_TEXTENCODING = 'utf8'
+DEFAULT_OUTPUT_FORMAT = 'pgf'
+
+# label margins in inches
+DEFAULT_LABEL_XMARGIN = 0.11
+DEFAULT_LABEL_YMARGIN = 0.055
+DEFAULT_EDGELABEL_XMARGIN = 0.01
+DEFAULT_EDGELABEL_YMARGIN = 0.01
+DEFAULT_GRAPHLABEL_XMARGIN = 0.01
+DEFAULT_GRAPHLABEL_YMARGIN = 0.01
+
+DEFAULT_NODE_WIDTH = 0.75
+DEFAULT_NODE_HEIGHT = 0.5
+
+
+# Todo: set papersize based on bb
+# Todo: Fontcolor
+
+# Todo: Support linewidth in draw string
+# Todo: Support linestyle in draw string
+# Todo: Need to reconsider edge draw order.
+# See for instance html2.xdot
+
+
+# Inch to bp conversion factor
+in2bp = 72.0
+
+# Examples of draw strings
+# c 5 -black F 14.000000 11 -Times-Roman T 99 159 0 44 8 -a_1 test
+
+
+special_chars = ['$','\\','%','_','#','{',r'}','^','&']
+special_chars_escape = [r'\$', r'$\backslash$',r'\%',r'\_',r'\#',
+ r'\{',r'\}',r'\^{}',r'\&']
+charmap = dict(zip(special_chars,special_chars_escape))
+
+# Pydot has hardcoded Graphviz' graph, node and edge attributes.
+# Dot2tex extends the DOT language with several new attributes. Fortunately
+# it is possible to modify pydot at runtime to accept the new attributes.
+special_graph_attrs = [
+ 'd2tdocpreamble',
+ 'd2tfigpreamble',
+ 'd2tfigpostamble',
+ 'd2tgraphstyle',
+ 'd2talignstr',
+ 'd2tvalignmode',
+ 'd2tnominsize',
+ 'texlbl',
+ 'd2ttikzedgelabels',
+ 'd2toutputformat',
+ 'd2tstyleonly',
+ 'd2tnodeoptions',
+ 'd2tedgeoptions',
+ 'd2toptions',
+]
+
+special_nodeandedge_attrs = [
+ 'texmode',
+ 'texlbl',
+ 'lblstyle',
+ 'topath',
+ 'exstyle',
+]
+
+# Modify pydot to understand dot2tex's extensions to the DOT language
+pydot.Graph.attributes.extend(special_graph_attrs)
+pydot.Edge.attributes.extend(special_nodeandedge_attrs)
+pydot.Node.attributes.extend(special_nodeandedge_attrs)
+
+helpmsg = """\
+Failed to parse the input data. Is it a valid dot file?
+Try to input xdot data directly. Example:
+ dot -Txdot file.dot | dot2tex > file.tex
+
+If this does not work, check that you have an updated version of PyParsing and
+Graphviz. Users have reported problems with old versions. You can also run
+dot2tex in debug mode using the --debug option:
+ dot2tex --debug file.dot
+A file dot2tex.log will be written to the current directory with detailed
+information useful for debugging."""
+
+def mreplace(s, chararray, newchararray):
+ for a, b in zip(chararray, newchararray):
+ s = s.replace(a, b)
+ return s
+
+def escapeTeXChars(string):
+ r"""Escape the special LaTeX-chars %{}_^
+
+ Examples:
+
+ >>> escapeTeXChars('10%')
+ '10\\%'
+ >>> escapeTeXChars('%{}_^\\$')
+ '\\%\\{\\}\\_\\^{}$\\backslash$\\$'
+ """
+ return "".join([charmap.get(c,c) for c in string])
+
+
+def nsplit(seq, n=2):
+ """Split a sequence into pieces of length n
+
+ If the lengt of the sequence isn't a multiple of n, the rest is discareded.
+ Note that nsplit will strings into individual characters.
+
+ Examples:
+ >>> nsplit('aabbcc')
+ [('a', 'a'), ('b', 'b'), ('c', 'c')]
+ >>> nsplit('aabbcc',n=3)
+ [('a', 'a', 'b'), ('b', 'c', 'c')]
+
+ # Note that cc is discarded
+ >>> nsplit('aabbcc',n=4)
+ [('a', 'a', 'b', 'b')]
+ """
+ return [xy for xy in izip(*[iter(seq)]*n)]
+
+def chunks(s, cl):
+ """Split a string or sequence into pieces of length cl and return an iterator
+ """
+ for i in xrange(0, len(s), cl):
+ yield s[i:i+cl]
+
+def replaceTags(template, tags, tagsreplace):
+ """Replace occurences of tags with tagreplace
+
+ Example:
+ >>> replaceTags('a b c d',('b','d'),{'b':'bbb','d':'ddd'})
+ 'a bbb c ddd'
+ """
+ s = template
+ for tag in tags:
+ replacestr = tagsreplace.get(tag, '')
+ if not replacestr:
+ replacestr = ''
+ s = s.replace(tag, replacestr)
+ return s
+
+def getboolattr(item, key, default):
+ if str(getattr(item,key,'')).lower() == 'true':
+ return True
+ else:
+ return False
+
+def createXdot(dotdata,prog='dot'):
+ # The following code is from the pydot module written by Ero Carrera
+ progs = pydot.find_graphviz()
+
+ #prog = 'dot'
+ if progs is None:
+ return None
+ if not progs.has_key(prog):
+ log.warning('Invalid prog=%s',prog)
+ # Program not found ?!?!
+ return None
+
+ tmp_fd, tmp_name = tempfile.mkstemp()
+ os.close(tmp_fd)
+ f = open(tmp_name,'w')
+ f.write(dotdata)
+ f.close()
+ format = 'xdot'
+ cmd = progs[prog]+' -T'+format+' '+tmp_name
+ log.debug('Creating xdot data with: %s',cmd)
+ stdin, stdout, stderr = os.popen3(cmd,'t')
+ stdin.close()
+ stderr.close()
+
+ # I'm not quite sure why this is necessary, but some files
+ # produces data with line endings that confuses pydot/pyparser.
+ data = stdout.readlines()
+ lines = [line for line in data if line.strip()]
+ data = "".join(lines)
+
+ stdout.close()
+ os.unlink(tmp_name)
+
+ return data
+
+def parseDotData(dotdata):
+ """Wrapper for pydot.graph_from_dot_data
+
+ Redirects error messages to the log.
+ """
+ saveout = sys.stdout
+ fsock = StringIO()
+ sys.stdout = fsock
+ graph = pydot.graph_from_dot_data(dotdata)
+ log.debug('Output from pydot:\n'+fsock.getvalue())
+ fsock.close()
+ sys.stdout = sys.__stdout__
+ return graph
+
+def parseDrawString(drawstring):
+ """Parse drawstring and returns a list of draw operations"""
+ # The draw string parser is a bit clumsy and slow
+ def doeE(c,s):
+ # E x0 y0 w h Filled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1
+ # e x0 y0 w h Unfilled ellipse ((x-x0)/w)^2 + ((y-y0)/h)^2 = 1
+ tokens = s.split()[0:4]
+ if not tokens: return None
+ points = map(int,tokens)
+ didx = sum(map(len,tokens))+len(points)+1
+ return didx, (c , points[0], points[1], points[2], points[3])
+
+ def doPLB(c, s):
+ # P n x1 y1 ... xn yn Filled polygon using the given n points
+ # p n x1 y1 ... xn yn Unfilled polygon using the given n points
+ # L n x1 y1 ... xn yn Polyline using the given n points
+ # B n x1 y1 ... xn yn B-spline using the given n control points
+ # b n x1 y1 ... xn yn Filled B-spline using the given n control points
+ tokens = s.split()
+ n = int(tokens[0])
+ points = map(int,tokens[1:n*2+1])
+ didx = sum(map(len,tokens[1:n*2+1]))+n*2+2
+ npoints = nsplit(points, 2)
+ return didx, (c, npoints)
+
+ def doCS(c,s):
+ # C n -c1c2...cn Set fill color.
+ # c n -c1c2...cn Set pen color.
+ # Graphviz uses the following color formats:
+ # "#%2x%2x%2x" Red-Green-Blue (RGB)
+ # "#%2x%2x%2x%2x" Red-Green-Blue-Alpha (RGBA)
+ # H[, ]+S[, ]+V Hue-Saturation-Value (HSV) 0.0 <= H,S,V <= 1.0
+ # string color name
+ tokens = s.split()
+ n = int(tokens[0])
+ tmp = len(tokens[0])+3
+ d = s[tmp:tmp+n]
+ didx = len(d)+tmp+1
+ return didx, (c, d)
+
+ def doFont(c,s):
+ # F s n -c1c2...cn
+ # Set font. The font size is s points. The font name consists of
+ # the n characters following '-'.
+ tokens = s.split()
+ size = tokens[0]
+ n = int(tokens[1])
+ tmp = len(size)+len(tokens[1])+4
+ d = s[tmp:tmp+n]
+ didx = len(d)+tmp
+ return didx, (c, size, d)
+
+ def doText(c,s):
+ # T x y j w n -c1c2...cn
+ # Text drawn using the baseline point (x,y). The text consists of the
+ # n characters following '-'. The text should be left-aligned
+ #(centered, right-aligned) on the point if j is -1 (0, 1), respectively.
+ # The value w gives the width of the text as computed by the library.
+ tokens = s.split()
+ x, y, j, w = tokens[0:4]
+ n = int(tokens[4])
+ tmp = sum(map(len,tokens[0:5]))+7
+ text = s[tmp:tmp+n]
+ didx = len(text)+tmp
+ return didx, [c, x, y, j, w, text]
+
+ cmdlist = []
+ stat = {}
+ idx = 0
+ s = drawstring.strip()
+ while idx < len(s)-1:
+ didx = 1
+ c = s[idx]
+ stat[c] = stat.get(c,0)+1
+ try:
+ if c in ('e','E'):
+ didx, cmd = doeE(c,s[idx+1:])
+ cmdlist.append(cmd)
+ elif c in ('p','P','L','b','B'):
+ didx, cmd = doPLB(c, s[idx+1:])
+ cmdlist.append(cmd)
+ elif c in ('c','C','S'):
+ didx, cmd = doCS(c, s[idx+1:])
+ cmdlist.append(cmd)
+ elif c == 'F':
+ didx, cmd = doFont(c, s[idx+1:])
+ cmdlist.append(cmd)
+ elif c == 'T':
+ didx, cmd = doText(c, s[idx+1:])
+ cmdlist.append(cmd)
+
+ except:
+ pass
+
+ idx += didx
+ return cmdlist,stat
+
+
+
+def getGraphList(gg, l = []):
+ """Traverse a graph with subgraphs and return them as a list"""
+ if not l:
+ outer = True
+ else:
+ outer = False
+ l.append(gg)
+ if gg.subgraph_list:
+ for g in gg.subgraph_list:
+ getGraphList(g,l)
+ if outer: return l
+
+class EndOfGraphElement:
+ def __init__(self):
+ pass
+
+def getAllGraphElements(graph, l=[]):
+ """Return all nodes and edges, including elements in subgraphs"""
+ if not l:
+ outer = True
+ l.append(graph)
+ else:
+ outer = False
+ for element in graph.sorted_graph_elements:
+ if isinstance(element, pydot.Node):
+ l.append(element)
+ elif isinstance(element,pydot.Edge):
+ l.append(element)
+ elif isinstance(element, pydot.Graph):
+ l.append(element)
+ getAllGraphElements(element,l)
+ else:
+ log.warning('Unknown graph element')
+
+ if outer:
+ return l
+ else:
+ l.append(EndOfGraphElement())
+
+
+class DotConvBase:
+ """Dot2TeX converter base"""
+ def __init__(self, options = {}):
+ self.color = ""
+ self.template = options.get('template','')
+ self.textencoding = options.get('encoding',DEFAULT_TEXTENCODING)
+ self.templatevars = {}
+ self.body = ""
+ if options.get('templatefile',''):
+ self.loadTemplate(options['templatefile'])
+
+ self.options = options
+ if options.get('texpreproc',False) or options.get('autosize',False):
+ self.dopreproc = True
+ else:
+ self.dopreproc = False
+
+ def loadTemplate(self, templatefile):
+ try:
+ self.template = open(templatefile).read()
+ except:
+ pass
+
+ def convertFile(self, filename):
+ """Load dot file and convert"""
+ pass
+
+ def startFig(self):
+ return ""
+
+ def endFig(self):
+ return ""
+
+ def drawEllipse(self, drawop, style = None):
+ return ""
+
+ def drawBezier(self, drawop, style = None):
+ return ""
+
+ def drawPolygon(self, drawop, style = None):
+ return ""
+
+ def drawPolyLine(self, drawop, style = None):
+ return ""
+
+ def drawText(self, drawop, style = None):
+ return ""
+
+ def outputNodeComment(self, node):
+ return " %% Node: %s\n" % node.name
+
+ def outputEdgeComment(self, edge):
+ src = edge.get_source()
+ dst = edge.get_destination()
+ if self.directedgraph:
+ edge = '->'
+ else:
+ edge = '--'
+ return " %% Edge: %s %s %s\n" % (src, edge, dst)
+
+ def setColor(self, node):
+ return ""
+
+ def setStyle(self, node):
+ return ""
+
+ def drawEdge(self, edge):
+ return ""
+
+ def startNode(self, node):
+ return ""
+ def endNode(self,node):
+ return ""
+ def startGraph(self, graph):
+ return ""
+ def endGraph(self,graph):
+ return ""
+
+ def startEdge(self):
+ return ""
+
+ def endEdge(self):
+ return ""
+
+ def filterStyles(self, style):
+ return style
+
+ def convertColor(self, drawopcolor,pgf=False):
+ """Convert color to a format usable by LaTeX and XColor"""
+ # Graphviz uses the following color formats:
+ # "#%2x%2x%2x" Red-Green-Blue (RGB)
+ # "#%2x%2x%2x%2x" Red-Green-Blue-Alpha (RGBA)
+ # H[, ]+S[, ]+V Hue-Saturation-Value (HSV) 0.0 <= H,S,V <= 1.0
+ # string color name
+
+ # Is the format RBG(A)?
+ if drawopcolor.startswith('#'):
+ t = list(chunks(drawopcolor[1:],2))
+ # parallell lines not yet supported
+ if len(t) > 6:
+ t = t[0:3]
+ rgb = [(round((int(n,16)/255.0),2)) for n in t]
+ if pgf:
+ colstr = "{rgb}{%s,%s,%s}" % tuple(rgb[0:3])
+ opacity = "1"
+ if len(rgb)==4:
+ opacity = rgb[3]
+ return (colstr, opacity)
+ else:
+ return "[rgb]{%s,%s,%s}" % tuple(rgb[0:3])
+
+ elif (len(drawopcolor.split(' '))==3) or (len(drawopcolor.split(','))==3):
+ # are the values space or comma separated?
+ hsb = drawopcolor.split(',')
+ if not len(hsb) == 3:
+ hsb = drawopcolor.split(' ')
+ if pgf:
+ return "{hsb}{%s,%s,%s}" % tuple(hsb)
+ else:
+ return "[hsb]{%s,%s,%s}" % tuple(hsb)
+ else:
+ drawopcolor = drawopcolor.replace('grey','gray')
+ drawopcolor = drawopcolor.replace('_','')
+ drawopcolor = drawopcolor.replace(' ','')
+ return drawopcolor
+
+
+
+ def doDrawString(self, drawstring, drawobj):
+ """Parse and draw drawsting
+
+ Just a wrapper around doDrawOp.
+ """
+ drawoperations,stat = parseDrawString(drawstring)
+ return self.doDrawOp(drawoperations, drawobj,stat)
+
+ def doDrawOp(self, drawoperations, drawobj,stat):
+ """Excecute the operations in drawoperations"""
+ s = ""
+ for drawop in drawoperations:
+ op = drawop[0]
+ style = getattr(drawobj, 'style',None)
+ # styles are not passed to the draw operations in the
+ # duplicate mode
+ if style and not self.options.get('duplicate', False):
+ # map Graphviz styles to backend styles
+ style = self.filterStyles(style)
+ styles = [self.styles.get(key.strip(),key.strip()) \
+ for key in style.split(',') if key]
+ style = ','.join(styles)
+ else:
+ style = None
+
+ if op in ['e','E']:
+ s += self.drawEllipse(drawop, style)
+ elif op in ['p','P']:
+ s += self.drawPolygon(drawop, style)
+ elif op == 'L':
+ s += self.drawPolyLine(drawop, style)
+ elif op in ['C','c']:
+ s += self.setColor(drawop)
+ elif op == 'S':
+ s += self.setStyle(drawop)
+ elif op in ['B']:
+ s += self.drawBezier(drawop, style)
+ elif op in ['T']:
+ # Need to decide what to do with the text
+ # Note that graphviz removes the \ character from the draw
+ # string. Use \\ instead
+ # Todo: Use text from node|edge.label or name
+ # Todo: What about multiline labels?
+ text = drawop[5]
+## label = getattr(drawobj,'label','\N')
+## multiline = False
+## if label:
+## if label.find(r'\n') >= 0:
+## multiline = True
+## #print label
+## else:
+## label = "\N"
+## if not multiline and label <> '\N':
+## text = drawobj.label
+ texmode = self.options.get('texmode','verbatim')
+ if getattr(drawobj,'texmode', ''):
+ texmode = drawobj.texmode
+ if getattr(drawobj,'texlbl', ''):
+ # the texlbl overrides everything
+ text = drawobj.texlbl
+ elif texmode == 'verbatim':
+ # verbatim mode
+ text = escapeTeXChars(text)
+ pass
+ elif texmode == 'math':
+ # math mode
+ text = "$%s$" % text
+
+ drawop[5] = text
+ if self.options.get('alignstr',''):
+ drawop.append(self.options.get('alignstr'))
+ if stat['T'] == 1 and \
+ self.options.get('valignmode','center')=='center':
+ # do this for single line only
+ # Todo: Make this optional
+ pos = getattr(drawobj,'lp',None) or \
+ getattr(drawobj,'pos',None)
+ if pos:
+ coord = pos.split(',')
+ if len(coord)==2:
+ drawop[1] = coord[0]
+ drawop[2] = coord[1]
+ pass
+ lblstyle = getattr(drawobj,'lblstyle',None)
+ exstyle = getattr(drawobj,'exstyle','')
+ if exstyle:
+ if lblstyle:
+ lblstyle += ',' +exstyle
+ else:
+ lblstyle = exstyle
+ s += self.drawText(drawop,lblstyle)
+ return s
+
+ def doNodes(self):
+ s = ""
+ for node in self.nodes:
+ self.currentnode = node
+ dstring = getattr(node,'_draw_',"")
+ lstring = getattr(node,'_ldraw_',"")
+
+
+ drawstring = dstring+" "+lstring
+
+ if not drawstring.strip(): continue
+ # detect node type
+ shape = node.shape
+ if not shape:
+ shape = 'ellipse' # default
+ # extract size information
+ x,y = node.pos.split(',')
+
+ # width and height are in inches. Convert to bp units
+ w = float(node.width)*in2bp
+ h = float(node.height)*in2bp
+
+ s += self.outputNodeComment(node)
+ s += self.startNode(node)
+ #drawoperations = parseDrawString(drawstring)
+ s += self.doDrawString(drawstring, node)
+ s += self.endNode(node)
+ self.body += s
+
+ def getEdgePoints(self, edge):
+ points = edge.pos.split(' ')
+ # check direction
+ arrowstyle = '--'
+ i = 0
+ if points[i].startswith('s'):
+ p = points[0].split(',')
+ tmp = "%s,%s" % (p[1],p[2])
+ if points[1].startswith('e'):
+ points[2] =tmp
+ else:
+ points[1] = tmp
+ del points[0]
+ arrowstyle = '<-'
+ i += 1
+ if points[0].startswith('e'):
+ p = points[0].split(',')
+ points.pop()
+ points.append("%s,%s" % (p[1],p[2]))
+ del points[0]
+ arrowstyle = '->'
+ i += 1
+ if i>1: arrowstyle = '<->'
+ return arrowstyle, points
+
+ def doEdges(self):
+ s = ""
+ s += self.setColor(('cC',"black"))
+ for edge in self.edges:
+ dstring = getattr(edge,'_draw_',"")
+ lstring = getattr(edge,'_ldraw_',"")
+ hstring = getattr(edge,'_hdraw_',"")
+ tstring = getattr(edge,'_tdraw_',"")
+ tlstring = getattr(edge,'_tldraw_',"")
+ hlstring = getattr(edge,'_hldraw_',"")
+
+ # Note that the order of the draw strings should be the same
+ # as in the xdot output.
+ drawstring = dstring + " " + hstring + " " + tstring \
+ + " " + lstring + " " + tlstring + " " + hlstring
+ drawop,stat = parseDrawString(drawstring);
+ if not drawstring.strip():
+ continue
+ s += self.outputEdgeComment(edge)
+ if self.options.get('duplicate', False):
+ s += self.startEdge()
+ s += self.doDrawOp(drawop, edge,stat)
+ s += self.endEdge()
+ else:
+ s += self.drawEdge(edge)
+ s += self.doDrawString(lstring+" "+tlstring+" "+hlstring, edge)
+ self.body += s
+
+ def doGraph(self):
+ dstring = getattr(self.graph,'_draw_',"")
+ lstring = getattr(self.graph,'_ldraw_',"")
+ # print lstring
+ # Avoid filling background of graphs with white
+ if dstring.startswith('c 5 -white C 5 -white') \
+ and not getattr(self.graph,'style'):
+ dstring = ''
+ if getattr(self.graph,'_draw_',None):
+ # bug
+ dstring = "c 5 -black " + dstring #self.graph._draw_
+ pass
+ drawstring = dstring+" "+lstring
+ if drawstring.strip():
+ s = self.startGraph(self.graph)
+ g = self.doDrawString(drawstring, self.graph)
+ e = self.endGraph(self.graph)
+ if g.strip():
+ self.body += s +g + e
+
+ def setOptions(self):
+ # process options
+ # Warning! If graph attribute is true and command line option is false,
+ # the graph attribute will be used. Command line option should have
+ # precedence.
+ self.options['alignstr'] = self.options.get('alignstr','') \
+ or getattr(self.maingraph,'d2talignstr','')
+
+ # Todo: bad!
+ self.options['valignmode'] = getattr(self.maingraph,'d2tvalignmode','')\
+ or self.options.get('valignmode','center')
+
+
+ def convert(self, dotdata):
+ # parse data processed by dot.
+ log.debug('Start conversion')
+ try:
+ try:
+ maingraph = parseDotData(dotdata)
+ except:
+ log.info('Failed first attempt to parse graph')
+ if not self.dopreproc:
+ log.info('Could not parse input dotdata directly. '
+ 'Trying to create xdot data.')
+ try:
+ tmpdata = createXdot(dotdata,self.options.get('prog','dot'))
+ log.debug('xdotdata:\n'+tmpdata)
+ maingraph = parseDotData(tmpdata)
+ except:
+ raise
+
+ if not self.dopreproc and not hasattr(maingraph,'xdotversion'):
+ # Older versions of Graphviz does not include the xdotversion
+ # attribute
+ if not (dotdata.find('_draw_') > 0 or dotdata.find('_ldraw_') > 0):
+ # need to convert to xdot format
+ # Warning. Pydot will not include custom attributes
+ log.debug('Trying to create xdotdata')
+
+ tmpdata = createXdot(dotdata,self.options.get('prog','dot'))
+ log.debug('xdotdata:\n'+tmpdata)
+ if tmpdata == None or not tmpdata.strip():
+ log.error('Failed to create xdotdata. Is Graphviz installed?')
+ sys.exit(1)
+ maingraph = parseDotData(tmpdata)
+ else:
+ # old version
+ pass
+
+ self.maingraph = maingraph
+ self.pencolor = ""
+ self.fillcolor = ""
+ self.linewidth = 1
+ # Detect graph type
+ if maingraph.graph_type == 'digraph':
+ self.directedgraph = True
+ else:
+ self.directedgraph = False
+ except:
+ log.error(helpmsg)
+ sys.exit(1)
+ raise
+ if self.dopreproc:
+ return self.doPreviewPreproc()
+
+ # Romove annoying square
+ # Todo: Remove squares from subgraphs. See pgram.dot
+ dstring = getattr(self.maingraph,'_draw_',"")
+ if dstring:
+ self.maingraph._draw_ = ""
+
+ setDotAttr(self.maingraph)
+ self.setOptions()
+
+ # A graph can consists of nested graph. Extract all graphs
+ graphlist = getGraphList(self.maingraph, [])
+
+ self.body += self.startFig()
+
+ # To get correct drawing order we need to iterate over the graphs
+ # multiple times. First we draw the graph graphics, then nodes and
+ # finally the edges.
+
+ # todo: support the outputorder attribute
+ for graph in graphlist:
+ self.graph = graph
+ self.doGraph()
+
+ if not self.options.get('flattengraph',False):
+ for graph in graphlist:
+ self.graph = graph
+ self.nodes = cleanDotNodes(graph)
+ self.edges = graph.edge_list
+ if not self.options.get('switchdraworder',False):
+ self.doEdges() # tmp
+ self.doNodes()
+ else:
+ self.doNodes()
+ self.doEdges()
+ else:
+ nodelist = []
+ edgelist = []
+ for graph in graphlist:
+ self.graph = graph
+ nodelist.extend(cleanDotNodes(graph))
+ edgelist.extend(graph.edge_list)
+ self.nodes = nodelist
+ self.edges = edgelist
+ if not self.options.get('switchdraworder',False):
+ self.doEdges() # tmp
+ self.doNodes()
+ else:
+ self.doNodes()
+ self.doEdges()
+
+ self.body += self.endFig()
+ return self.output()
+
+ def cleanTemplate(self, template):
+ """Remove preprocsection or outputsection"""
+ if not self.dopreproc and self.options.get('codeonly',False):
+ r = re.compile('<<startcodeonlysection>>(.*?)<<endcodeonlysection>>',
+ re.DOTALL | re.MULTILINE)
+ m = r.search(template)
+ if m:
+ return m.group(1).strip()
+ if not self.dopreproc and self.options.get('figonly',False):
+ r = re.compile('<<startfigonlysection>>(.*?)<<endfigonlysection>>',
+ re.DOTALL | re.MULTILINE)
+ m = r.search(template)
+ if m:
+ return m.group(1)
+
+
+ if self.dopreproc:
+ r = re.compile('<<startoutputsection>>.*?<<endoutputsection>>',
+ re.DOTALL | re.MULTILINE)
+ else:
+ r = re.compile('<<startpreprocsection>>.*?<<endpreprocsection>>',
+ re.DOTALL | re.MULTILINE)
+ # remove codeonly and figonly section
+ r2 = re.compile('<<startfigonlysection>>.*?<<endfigonlysection>>',
+ re.DOTALL | re.MULTILINE)
+ tmp = r2.sub('',template)
+ r2 = re.compile('<<startcodeonlysection>>.*?<<endcodeonlysection>>',
+ re.DOTALL | re.MULTILINE)
+ tmp = r2.sub('',tmp)
+ return r.sub('',tmp)
+
+ def initTemplateVars(self):
+ vars = {}
+ # get bounding box
+ bbstr = self.maingraph.bb
+ if bbstr:
+ bb = bbstr.split(',')
+ vars['<<bbox>>'] = "(%sbp,%sbp)(%sbp,%sbp)\n" % (bb[0],bb[1],bb[2],bb[3])
+ vars['<<bbox.x0>>'] = bb[0]
+ vars['<<bbox.y0>>'] = bb[1]
+ vars['<<bbox.x1>>'] = bb[2]
+ vars['<<bbox.y1>>'] = bb[3]
+ vars['<<figcode>>'] = self.body.strip()
+ vars['<<drawcommands>>'] = self.body.strip()
+ vars['<<textencoding>>'] = self.textencoding
+ docpreamble = self.options.get('docpreamble','') \
+ or getattr(self.maingraph, 'd2tdocpreamble','')
+## if docpreamble:
+## docpreamble = docpreamble.replace('\\n','\n')
+ vars['<<docpreamble>>'] = docpreamble
+ vars['<<figpreamble>>'] = self.options.get('figpreamble','') \
+ or getattr(self.maingraph, 'd2tfigpreamble','%')
+ vars['<<figpostamble>>'] = self.options.get('figpostamble','') \
+ or getattr(self.maingraph, 'd2tfigpostamble','')
+ vars['<<graphstyle>>'] = self.options.get('graphstyle','') \
+ or getattr(self.maingraph, 'd2tgraphstyle','')
+ vars['<<margin>>'] = self.options.get('margin','0pt')
+ vars['<<startpreprocsection>>'] = vars['<<endpreprocsection>>'] = ''
+ vars['<<startoutputsection>>'] = vars['<<endoutputsection>>'] = ''
+ if self.options.get('gvcols',False):
+ vars['<<gvcols>>'] = "\input{gvcols.tex}"
+ else:
+ vars['<<gvcols>>'] = ""
+ self.templatevars = vars
+
+ def output(self):
+ self.initTemplateVars()
+ template = self.cleanTemplate(self.template)
+ code = replaceTags(template ,self.templatevars.keys(),
+ self.templatevars)
+ #code = self.template.replace('<<figcode>>', self.body)
+ return code
+
+ def getLabel(self, drawobj):
+ text = ""
+ texmode = self.options.get('texmode','verbatim')
+ if getattr(drawobj,'texmode', ''):
+ texmode = drawobj.texmode
+ text = getattr(drawobj,'label',None)
+
+ #log.warning('text %s %s',text,drawobj.to_string())
+
+ if text == None or text.strip() == '\N':
+
+ if not isinstance(drawobj, pydot.Edge):
+ text = getattr(drawobj,'name',None) or \
+ getattr(drawobj,'graph_name','')
+ else:
+ text = ''
+ elif text.strip() == '\N':
+ text = ''
+ else:
+ text = text.replace("\\\\","\\")
+
+ if getattr(drawobj,'texlbl', ''):
+ # the texlbl overrides everything
+ text = drawobj.texlbl
+ elif texmode == 'verbatim':
+ # verbatim mode
+ text = escapeTeXChars(text)
+ pass
+ elif texmode == 'math':
+ # math mode
+ text = "$%s$" % text
+
+ return text
+
+ # temp
+ def getLabeld(self, drawobj):
+ text = ""
+ texmode = self.options.get('texmode','verbatim')
+ if drawobj.get('texmode', ''):
+ texmode = drawobj["texmode"]
+ text = drawobj.get('label',None)
+ if text == None or text.strip() == '\N':
+ text = drawobj.get('name',None) or \
+ drawobj.get('graph_name','')
+ else:
+ text = text.replace("\\\\","\\")
+
+ if drawobj.get('texlbl', ''):
+ # the texlbl overrides everything
+ text = drawobj["texlbl"]
+ elif texmode == 'verbatim':
+ # verbatim mode
+ text = escapeTeXChars(text)
+ pass
+ elif texmode == 'math':
+ # math mode
+ text = "$%s$" % text
+ return text
+
+ def getNodePreprocCode(self, node):
+ return node['texlbl']
+
+ def getEdgePreprocCode(self,edge):
+ return edge.texlbl
+
+ def getGraphPreprocCode(self,graph):
+ return graph.texlbl
+
+
+ def getMargins(self, element):
+ """Return element margins"""
+ margins = element.__dict__.get('margin',None)
+ #print margins
+ #print type(margins)
+ if margins:
+ margins = margins.split(',')
+ if len(margins) == 1:
+ xmargin = ymargin = float(margins[0])
+ else:
+ xmargin = float(margins[0])
+ ymargin = float(margins[1])
+ else:
+ # use default values
+ if isinstance(element,pydot.Edge):
+ xmargin = DEFAULT_EDGELABEL_XMARGIN
+ ymargin = DEFAULT_EDGELABEL_YMARGIN
+ else:
+ xmargin = DEFAULT_LABEL_XMARGIN
+ ymargin = DEFAULT_LABEL_YMARGIN
+ return (xmargin, ymargin)
+
+ # Todo: Add support for head and tail labels!
+ # Todo: Support rect nodes if possible.
+ def doPreviewPreproc(self):
+ setDotAttr(self.maingraph)
+ self.initTemplateVars()
+ template = self.cleanTemplate(self.template)
+ template = replaceTags(template ,self.templatevars.keys(),
+ self.templatevars)
+ pp = TeXDimProc(template, self.options)
+ processednodes = {}
+ processededges = {}
+ processedgraphs = {}
+
+ usednodes = {}
+ usededges = {}
+ usedgraphs = {}
+ # iterate over every element in the graph
+ counter = 0
+ for element in getAllGraphElements(self.maingraph,[]):
+ if isinstance(element, pydot.Node):
+ # is it a node statement?
+ node = element
+ if node.name.startswith('"'):
+ node_stmt = True
+ else:
+ # node defined in a edge statement (edge_stmt)
+ node_stmt = False
+ name = node.name.replace('"','')
+ if node_stmt:
+ node.name=name
+ #print node.texmode
+ if name=='node' or name=='edge' or name=='graph': continue
+
+ label = self.getLabel(node)
+ tmpnode = processednodes.get(name,None)
+
+
+ # has the node been defined before?
+ if tmpnode:
+ pass
+## # is it a new label?
+## if node.label or node.texlbl:
+## #if tmpnode['texlbl'] <> label and node_stmt:
+## tmpnode['texlbl'] = label
+ else:
+ tmpnode = dict(texlbl=None, width=None, height=None,
+ margin=None, style=None, fixedsize=None,
+ shape=None, texmode=None,label=None,
+ lblstyle=None)
+ processednodes[name]= tmpnode
+ if node.width:
+ tmpnode['width'] = node.width
+ if node.height:
+ tmpnode['height'] = node.height
+ if node.margin:
+ tmpnode['margin'] = node.margin
+ if node.style:
+ tmpnode['style'] = node.style
+ if node.texmode:
+ tmpnode['texmode'] = node.texmode
+ if node.label or node.label=='':
+ tmpnode['label'] = node.label
+ if node.texlbl:
+ tmpnode['texlbl'] = node.texlbl
+ if node.lblstyle:
+ tmpnode['lblstyle'] = node.lblstyle
+ if node.shape:
+ tmpnode['shape'] = node.shape
+ if node.fixedsize:
+ tmpnode['fixedsize'] = node.fixedsize.lower()
+ #log.debug('nodeinfo %s %s',name, node.fixedsize)
+ if node.shape:
+ tmpnode['shape'] = node.shape
+ elif isinstance(element, pydot.Edge):
+ if not element.label: continue
+ # Ensure that the edge name is unique.
+ name = element.src + element.dst +str(counter)
+ label = self.getLabel(element)
+ element.texlbl = label
+ processededges[name]=element
+ elif isinstance(element, pydot.Graph):
+ if not getattr(element,'label',None) and \
+ not getattr(element,'texlbl',None): continue
+ name = element.graph_name
+ label = self.getLabel(element)
+ element.texlbl = label
+ processedgraphs[name]=element
+
+ else:
+ pass
+ counter += 1
+
+ for name, item in processednodes.items():
+ if item['fixedsize'] == 'true' or item['style'] == 'invis':
+ continue
+ if item['shape'] == 'record':
+ log.warning('Record nodes not supported in preprocessing mode: %s',name)
+ continue
+ item['name'] = name
+ texlbl = self.getLabeld(item)
+ if texlbl:
+ item['texlbl'] = texlbl
+ code = self.getNodePreprocCode(item)
+ pp.addSnippet(name,code)
+ #log.warning(item['texlbl'])
+ usednodes[name] = item
+ for name, item in processededges.items():
+ code = self.getEdgePreprocCode(item)
+ pp.addSnippet(name,code)
+ usededges[name] = item
+ for name, item in processedgraphs.items():
+ code = self.getGraphPreprocCode(item)
+ pp.addSnippet(name,code)
+ usedgraphs[name] = item
+
+
+ ok = pp.process()
+
+ if not ok:
+ errormsg = """\
+Failed to preprocess the graph.
+Is the preview LaTeX package installed? ((Debian package preview-latex-style)
+To see what happened, run dot2tex with the --debug option.
+"""
+ log.error(errormsg)
+ sys.exit(1)
+
+ for name,item in usednodes.items():
+ if not item['texlbl']:continue
+ node = pydot.Node('"'+name+'"',texlbl=item['texlbl'],margin=item['margin'])
+ hp,dp,wt = pp.texdims[name]
+ if self.options.get('rawdim',False):
+ # use dimesions from preview.sty directly
+ node.width = wt
+ node.height = hp+dp
+ node.label=" "
+ node.fixedsize='true'
+ self.maingraph.add_node(node)
+ continue
+ xmargin, ymargin = self.getMargins(node)
+ #print xmargin, ymargin
+ ht = hp+dp
+ minwidth = float(item['width'] or DEFAULT_NODE_WIDTH)
+ minheight = float(item['height'] or DEFAULT_NODE_HEIGHT)
+ if self.options.get('nominsize',False):
+ width = wt+2*xmargin
+ height = ht+2*ymargin
+ else:
+
+ if (wt+2*xmargin) < minwidth:
+ width = minwidth
+ #log.warning("%s %s %s %s %s",minwidth,wt,width,name,tmp)
+ pass
+ else:
+ width = wt+2*xmargin
+ height = ht
+ if ((hp+dp)+2*ymargin) < minheight:
+ height = minheight
+ else:
+ height = ht+ 2*ymargin
+ # Treat shapes with equal widht and height differently
+ # Warning! Rectangles will not alway fit inside a circle
+ # Should use the diagonal.
+ if item['shape'] in ['circle','Msquare','doublecircle','Mcircle']:
+ #log.warning('%s %s', name, item['shape'])
+ if wt< height and width < height:
+ width = height
+ else:
+ height=width
+ pass
+
+ node.width = width
+ node.height = height
+ node.label=" "
+
+ node.fixedsize='true'
+ self.maingraph.add_node(node)
+ for name,item in usededges.items():
+
+ edge = item
+ hp,dp,wt = pp.texdims[name]
+ xmargin, ymargin = self.getMargins(edge)
+ labelcode = '<<<table border="0" cellborder="0" cellpadding="0">'\
+ '<tr><td fixedsize="true" width="%s" height="%s">a</td>'\
+ '</tr></table>>>'
+ edge.label=labelcode % ((wt + 2*xmargin)*72, (hp+dp+2*ymargin)*72)
+ for name,item in usedgraphs.items():
+ graph = item
+ hp,dp,wt = pp.texdims[name]
+ xmargin, ymargin = self.getMargins(graph)
+ labelcode = '<<<table border="0" cellborder="0" cellpadding="0">'\
+ '<tr><td fixedsize="true" width="%s" height="%s">a</td>'\
+ '</tr></table>>>'
+ graph.label=labelcode % ((wt + 2*xmargin)*72, (hp+dp+2*ymargin)*72)
+
+ self.maingraph.d2toutputformat = self.options.get('format',
+ DEFAULT_OUTPUT_FORMAT)
+ graphcode = self.maingraph.to_string()
+ graphcode = graphcode.replace('"<<<','<<')
+ graphcode = graphcode.replace('>>>"','>>')
+ return graphcode
+
+
+
+
+PSTRICKS_TEMPLATE = r"""\documentclass{article}
+% <<bbox>>
+\usepackage[x11names]{xcolor}
+\usepackage[<<textencoding>>]{inputenc}
+\usepackage{graphicx}
+\usepackage{pstricks}
+\usepackage{amsmath}
+<<startpreprocsection>>%
+\usepackage[active,auctex]{preview}
+<<endpreprocsection>>%
+<<gvcols>>%
+<<docpreamble>>%
+
+
+\begin{document}
+\pagestyle{empty}
+<<startpreprocsection>>%
+<<preproccode>>%
+<<endpreprocsection>>%
+<<startoutputsection>>%
+\enlargethispage{100cm}
+
+% Start of code
+\begin{pspicture}[linewidth=1bp<<graphstyle>>]<<bbox>>
+ \pstVerb{2 setlinejoin} % set line join style to 'mitre'
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+\end{pspicture}
+% End of code
+<<endoutputsection>>%
+\end{document}
+%
+<<startfigonlysection>>
+\begin{pspicture}[linewidth=1bp<<graphstyle>>]<<bbox>>
+ \pstVerb{2 setlinejoin} % set line join style to 'mitre'
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+\end{pspicture}
+<<endfigonlysection>>
+%
+<<startcodeonlysection>>
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+<<endcodeonlysection>>
+"""
+
+class Dot2PSTricksConv(DotConvBase):
+ """PSTricks converter backend"""
+ def __init__(self, options = {}):
+ DotConvBase.__init__(self, options)
+ if not self.template:
+ self.template = PSTRICKS_TEMPLATE
+ self.styles = dict(
+ dotted = "linestyle=dotted",
+ dashed = "linestyle=dashed",
+ bold = "linewidth=2pt",
+ solid = "",
+ filled = "",
+ )
+
+ def doGraphtmp(self):
+ self.pencolor = "";
+ self.fillcolor = ""
+ self.color = ""
+ self.body += '{\n'
+ DotConvBase.doGraph(self)
+ self.body += '}\n'
+
+ def startFig(self):
+ # get bounding box
+ bbstr = self.maingraph.bb
+ if bbstr:
+ bb = bbstr.split(',')
+ #fillcolor=black,
+ s = "\\begin{pspicture}[linewidth=1bp](%sbp,%sbp)(%sbp,%sbp)\n" % \
+ (bb[0],bb[1],bb[2],bb[3])
+ # Set line style to mitre
+ s += " \pstVerb{2 setlinejoin} % set line join style to 'mitre'\n"
+ #return s
+ return ""
+
+ def endFig(self):
+ #return '\end{pspicture}\n'
+ return ""
+
+ def drawEllipse(self, drawop, style = None):
+ op, x,y,w,h = drawop
+ s = ""
+ #s = " %% Node: %s\n" % node.name
+ if op == 'E':
+ if style:
+ style = style.replace('filled','')
+ stylestr = 'fillstyle=solid'
+ else:
+ stylestr = ""
+
+ if style:
+ if stylestr:
+ stylestr += ','+ style
+ else:
+ stylestr = style
+
+ s += " \psellipse[%s](%sbp,%sbp)(%sbp,%sbp)\n" % (stylestr,x,y, \
+ # w+self.linewidth,h+self.linewidth)
+ w,h)
+
+
+ return s
+
+ def drawPolygon(self, drawop, style = None):
+ op, points = drawop
+ pp = ['(%sbp,%sbp)' % (p[0],p[1]) for p in points]
+ stylestr = ""
+ if op == 'P':
+ if style:
+ style = style.replace('filled','')
+ stylestr = "fillstyle=solid"
+ if style:
+ if stylestr:
+ stylestr += ','+ style
+ else:
+ stylestr = style
+
+ s = " \pspolygon[%s]%s\n" % (stylestr, "".join(pp))
+ return s
+
+ def drawPolyLine(self, drawop, style = None):
+ op, points = drawop
+ pp = ['(%sbp,%sbp)' % (p[0],p[1]) for p in points]
+ s = " \psline%s\n" % "".join(pp)
+ return s
+
+ def drawBezier(self, drawop, style = None):
+ op, points = drawop
+ pp= []
+ for point in points:
+ pp.append("(%sbp,%sbp)" % (point[0],point[1]))
+
+ #points = ['(%sbp, %sbp)' % (p[0],p[1]) for p in points]
+ arrowstyle = ""
+ return " \psbezier{%s}%s\n" % (arrowstyle, "".join(pp))
+
+
+
+ def drawText(self, drawop, style=None):
+
+ if len(drawop)==7:
+ c, x, y, align, w, text, valign = drawop
+ else:
+ c, x, y, align, w, text = drawop
+ valign=""
+ if align == "-1" :
+ alignstr = 'l' # left aligned
+ elif align == "1":
+ alignstr = 'r' # right aligned
+ else:
+ alignstr = "" # centered (default)
+ if alignstr or valign:
+ alignstr = '['+alignstr+valign+']'
+ s = " \\rput%s(%sbp,%sbp){%s}\n" % (alignstr, x,y,text)
+ return s
+
+ def setColor(self, drawop):
+ c, color = drawop
+ #color = color.replace('grey','gray')
+ #self.pencolor = "";
+ #self.fillcolor = ""
+ #self.color = ""
+ color = self.convertColor(color)
+ s = ""
+ if c == 'c':
+ # set pen color
+ if self.pencolor <> color:
+ self.pencolor = color
+ s = " \psset{linecolor=%s}\n" % color
+ else: return ""
+ elif c == 'C':
+ # set fill color
+ if self.fillcolor <> color:
+ self.fillcolor = color
+ s = " \psset{fillcolor=%s}\n" % color
+ else: return ""
+ return s
+
+ def setStyle(self, drawop):
+ c, style = drawop
+ psstyle = self.styles.get(style,"")
+ if psstyle:
+ return " \psset{%s}\n" % psstyle
+ else:
+ return ""
+
+ def filterStyles(self, style):
+ fstyles = []
+ for item in style.split(','):
+ keyval = item.strip()
+ if keyval.find('setlinewidth') < 0:
+ fstyles.append(keyval)
+ return ', '.join(fstyles)
+
+ def startNode(self, node):
+ self.pencolor = "";
+ self.fillcolor = ""
+ self.color = ""
+ return "{%\n"
+
+ def endNode(self,node):
+ return "}%\n"
+
+ def startEdge(self):
+ self.pencolor = "";
+ self.fillcolor = ""
+ return "{%\n"
+
+ def endEdge(self):
+ return "}%\n"
+
+ def startGraph(self, graph):
+ self.pencolor = "";
+ self.fillcolor = ""
+ self.color = ""
+ return "{\n"
+
+ def endGraph(self,node):
+ return "}\n"
+
+
+ def drawEllipseNode(self, x,y,w,h,node):
+ s = " %% Node: %s\n" % node.name
+ s += " \psellipse(%sbp,%sbp)(%sbp,%sbp)\n" % (x,y, \
+ w/2+self.linewidth,h/2+self.linewidth)
+ # label
+ if node.label:
+ label = node.label
+ else:
+ label = node.name
+ s += " \\rput(%sbp,%sbp){$%s$}\n" % (x,y,label)
+
+ return s
+
+
+
+ def drawEdge(self, edge):
+ s = ""
+ if edge.style == 'invis':
+ return ""
+ arrowstyle, points = self.getEdgePoints(edge)
+ if arrowstyle == '--': arrowstyle=''
+ color = getattr(edge,'color','')
+ if self.color <> color:
+ if color:
+ s += self.setColor(('c',color))
+ else:
+ # reset to default color
+ s += self.setColor(('c','black'))
+ pp= []
+ for point in points:
+ p = point.split(',')
+ pp.append("(%sbp,%sbp)" % (p[0],p[1]))
+
+ edgestyle = edge.style
+ styles = []
+ if arrowstyle:
+ styles.append('arrows=%s' % arrowstyle)
+ if edgestyle:
+ edgestyles = [self.styles.get(key.strip(),key.strip()) for key in edgestyle.split(',') if key]
+ styles.extend(edgestyles)
+ if styles:
+ stylestr = ",".join(styles)
+ else:
+ stylestr = ""
+ if not self.options.get('straightedges',False):
+ s += " \psbezier[%s]%s\n" % (stylestr,"".join(pp))
+ else:
+ s += " \psline[%s]%s%s\n" % (stylestr, pp[0], pp[-1])
+ #s += " \psbezier[%s]{%s}%s\n" % (stylestr, arrowstyle,"".join(pp))
+## if edge.label:
+## x,y = edge.lp.split(',')
+## #s += "\\rput(%s,%s){%s}\n" % (x,y,edge.label)
+ return s
+
+ def initTemplateVars(self):
+ DotConvBase.initTemplateVars(self)
+ # Put a ',' before <<graphstyle>>
+ graphstyle = self.templatevars.get('<<graphstyle>>','')
+ if graphstyle:
+ graphstyle = graphstyle.strip()
+ if not graphstyle.startswith(','):
+ graphstyle = ','+graphstyle
+ self.templatevars['<<graphstyle>>'] = graphstyle
+
+
+PGF_TEMPLATE = r"""\documentclass{article}
+\usepackage[x11names, rgb]{xcolor}
+\usepackage[<<textencoding>>]{inputenc}
+\usepackage{tikz}
+\usetikzlibrary{snakes,arrows,shapes}
+\usepackage{amsmath}
+<<startpreprocsection>>%
+\usepackage[active,auctex]{preview}
+<<endpreprocsection>>%
+<<gvcols>>%
+<<cropcode>>%
+<<docpreamble>>%
+
+\begin{document}
+\pagestyle{empty}
+%
+<<startpreprocsection>>%
+<<preproccode>>
+<<endpreprocsection>>%
+%
+<<startoutputsection>>
+\enlargethispage{100cm}
+% Start of code
+% \begin{tikzpicture}[anchor=mid,>=latex',join=bevel,<<graphstyle>>]
+\begin{tikzpicture}[>=latex',join=bevel,<<graphstyle>>]
+ \pgfsetlinewidth{1bp}
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+\end{tikzpicture}
+% End of code
+<<endoutputsection>>
+%
+\end{document}
+%
+<<startfigonlysection>>
+\begin{tikzpicture}[>=latex,join=bevel,<<graphstyle>>]
+ \pgfsetlinewidth{1bp}
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+\end{tikzpicture}
+<<endfigonlysection>>
+<<startcodeonlysection>>
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+<<endcodeonlysection>>
+"""
+
+class Dot2PGFConv(DotConvBase):
+ """PGF/TikZ converter backend"""
+ def __init__(self, options={}):
+ DotConvBase.__init__(self, options)
+ if not self.template:
+ self.template = PGF_TEMPLATE
+ self.styles = dict(dashed='dashed', dotted='dotted',
+ bold='very thick', filled='fill', invis="",
+ rounded='rounded corners', )
+ self.dashstyles = dict(
+ dashed = '\pgfsetdash{{3pt}{3pt}}{0pt}',
+ dotted='\pgfsetdash{{\pgflinewidth}{2pt}}{0pt}',
+ bold = '\pgfsetlinewidth{1.2pt}')
+
+ def startFig(self):
+ # get bounding box
+ # get bounding box
+ s = ""
+## bbstr = self.maingraph.bb
+## if bbstr:
+## bb = bbstr.split(',')
+## s += "%%(%sbp,%sbp)(%sbp,%sbp)\n" % \
+## (bb[0],bb[1],bb[2],bb[3])
+
+ return s
+
+ def endFig(self):
+ #return '\end{tikzpicture}'
+ return ""
+
+ def startNode(self, node):
+ # Todo: Should find a more elgant solution
+ self.pencolor = "";
+ self.fillcolor = ""
+ self.color = ""
+ return "\\begin{scope}\n"
+
+ def endNode(self,node):
+ return "\\end{scope}\n"
+
+ def startEdge(self):
+ # Todo: Should find a more elgant solution
+ #self.pencolor = "";
+ #self.fillcolor = ""
+ #self.color = ""
+ return "\\begin{scope}\n"
+
+ def endEdge(self):
+ return "\\end{scope}\n"
+
+ def startGraph(self, graph):
+ # Todo: Should find a more elgant solution
+ self.pencolor = "";
+ self.fillcolor = ""
+ self.color = ""
+ return "\\begin{scope}\n"
+
+ def endGraph(self,graph):
+ return "\\end{scope}\n"
+ #return "\\end{scope}"
+
+ def setColor(self, drawop):
+ c, color = drawop
+ # Todo: Should find a more elgant solution
+ #self.pencolor = "";
+ #self.fillcolor = ""
+ #self.color = ""
+ res = self.convertColor(color, True)
+ opacity = None
+ if len(res)==2:
+ ccolor, opacity = res
+ else:
+ ccolor = res
+ s = ""
+ if c == 'cC':
+ #self.pencolor = color
+ #self.fillcolor = color
+ if self.color <> color:
+ self.color = color
+ self.pencolor=color
+ self.fillcolor=color
+ if ccolor.startswith('{'):
+ # rgb or hsb
+ s += " \definecolor{newcol}%s;\n" % ccolor
+ ccolor = 'newcol'
+ s += " \pgfsetcolor{%s}\n" % ccolor
+ #s += " \pgfsetfillcolor{%s}\n" % ccolor
+ elif c == 'c':
+ # set pen color
+ if self.pencolor <> color:
+ self.pencolor = color
+ self.color = ''
+ if ccolor.startswith('{'):
+ # rgb or hsb
+ s += " \definecolor{strokecol}%s;\n" % ccolor
+ ccolor = 'strokecol'
+ s += " \pgfsetstrokecolor{%s}\n" % ccolor
+ else: return ""
+ elif c == 'C':
+ # set fill color
+ if self.fillcolor <> color:
+ self.fillcolor = color
+ self.color = ''
+ if ccolor.startswith('{'):
+ # rgb
+ s += " \definecolor{fillcol}%s;\n" % ccolor
+ ccolor = 'fillcol'
+ s += " \pgfsetfillcolor{%s}\n" % ccolor
+ if not opacity == None:
+ self.opacity = opacity
+ # Todo: The opacity should probably be set directly when drawing
+ # The \pgfsetfillcopacity cmd affects text as well
+ #s += " \pgfsetfillopacity{%s};\n" % opacity
+ else:
+ self.opacity = None
+ else: return ""
+ return s
+
+ def setStyle(self, drawop):
+ c, style = drawop
+ pgfstyle = self.dashstyles.get(style,"")
+ if pgfstyle:
+ return " %s\n" % pgfstyle
+ else:
+ return ""
+
+ def filterStyles(self, style):
+ fstyles = []
+ for item in style.split(','):
+ keyval = item.strip()
+ if keyval.find('setlinewidth') < 0 and not keyval=='filled':
+ fstyles.append(keyval)
+ return ', '.join(fstyles)
+
+
+ def drawEllipse(self, drawop, style = None):
+ op, x,y,w,h = drawop
+ s = ""
+ #s = " %% Node: %s\n" % node.name
+ if op == 'E':
+ if self.opacity <> None:
+ # Todo: Need to know the state of the current node
+ cmd = 'filldraw [opacity=%s]' % self.opacity
+ else:
+ cmd = 'filldraw'
+ else:
+ cmd = "draw"
+
+ if style:
+ stylestr = " [%s]" % style
+ else:
+ stylestr = ''
+ s += " \%s%s (%sbp,%sbp) ellipse (%sbp and %sbp);\n" % (cmd, stylestr, x,y, \
+ # w+self.linewidth,h+self.linewidth)
+ w,h)
+ return s
+
+ def drawPolygon(self, drawop, style = None):
+ op, points = drawop
+ pp = ['(%sbp,%sbp)' % (p[0],p[1]) for p in points]
+ cmd = "draw"
+ if op == 'P':
+ cmd = "filldraw"
+
+ if style:
+ stylestr = " [%s]" % style
+ else:
+ stylestr = ''
+ s = " \%s%s %s -- cycle;\n" % (cmd, stylestr, " -- ".join(pp))
+ return s
+
+ def drawPolyLine(self, drawop, style = None):
+ op, points = drawop
+ pp = ['(%sbp,%sbp)' % (p[0],p[1]) for p in points]
+ ##if style:
+## stylestr = " [%s]" % style
+## else:
+## stylestr = ''
+ stylestr = ''
+ return " \draw%s %s;\n" %(stylestr, " -- ".join(pp))
+
+
+ def drawText(self, drawop, style = None):
+ # The coordinates given by drawop are not the same as the node
+ # coordinates! This may give som odd results if graphviz' and
+ # LaTeX' fonts are very different.
+ if len(drawop)==7:
+ c, x, y, align, w, text, valign = drawop
+ else:
+ c, x, y, align, w, text = drawop
+ valign=""
+ styles = []
+ if align == "-1" :
+ alignstr = 'right' # left aligned
+ elif align == "1":
+ alignstr = 'left' # right aligned
+ else:
+ alignstr = "" # centered (default)
+ styles.append(alignstr)
+ styles.append(style)
+## if alignstr:
+## alignstr = "[" + alignstr+", anchor=mid" + "]"
+## else:
+## alignstr = "[anchor=mid]"
+ lblstyle = ",".join([i for i in styles if i])
+ if lblstyle:
+ lblstyle = '['+lblstyle+']'
+ s = " \draw (%sbp,%sbp) node%s {%s};\n" % (x,y,lblstyle,text)
+ return s
+
+ def drawBezier(self, drawop, style = None):
+ s = ""
+ c, points = drawop
+ arrowstyle = '--'
+
+ pp= []
+ for point in points:
+ pp.append("(%sbp,%sbp)" % (point[0],point[1]))
+
+ #points = ['(%sbp, %sbp)' % (p[0],p[1]) for p in points]
+ #quadp = nsplit(pp, 4)
+ pstrs = ["%s .. controls %s and %s " % p for p in nsplit(pp, 3)]
+ ##if style:
+## stylestr = " [%s]" % style
+## else:
+## stylestr = ''
+ stylestr = ''
+## if arrowstyle == '--':
+## style = ''
+## else:
+## style = '[%s]' % arrowstyle
+
+ s += " \draw%s %s .. %s;\n" % (stylestr, " .. ".join(pstrs), pp[-1])
+
+ return s
+
+
+ def doEdges(self):
+ s = ""
+ s += self.setColor(('cC',"black"))
+ for edge in self.edges:
+ dstring = getattr(edge,'_draw_',"")
+ lstring = getattr(edge,'_ldraw_',"")
+ hstring = getattr(edge,'_hdraw_',"")
+ tstring = getattr(edge,'_tdraw_',"")
+ tlstring = getattr(edge,'_tldraw_',"")
+ hlstring = getattr(edge,'_hldraw_',"")
+
+ # Note that the order of the draw strings should be the same
+ # as in the xdot output.
+ drawstring = dstring + " " + hstring + " " + tstring \
+ + " " + lstring + " " + tlstring + " " + hlstring
+ drawop,stat = parseDrawString(drawstring);
+ if not drawstring.strip():
+ continue
+ s += self.outputEdgeComment(edge)
+ if self.options.get('duplicate', False):
+ s += self.startEdge()
+ s += self.doDrawOp(drawop, edge,stat)
+ s += self.endEdge()
+ else:
+ topath = getattr(edge,'topath',None)
+ s += self.drawEdge(edge)
+ if not self.options.get('tikzedgelabels',False) and not topath:
+ s += self.doDrawString(lstring+" "+tlstring+" "+hlstring, edge)
+ else:
+ s += self.doDrawString(tlstring+" "+hlstring, edge)
+ #s += self.drawEdge(edge)
+ #s += self.doDrawString(lstring+" "+tlstring+" "+hlstring, edge)
+ self.body += s
+
+
+ def drawEdge(self, edge):
+ s = ""
+ if edge.style == 'invis':
+ return ""
+ arrowstyle, points = self.getEdgePoints(edge)
+ # PGF uses the fill style when drawing some arrowheads. We have to
+ # ensure that the fill color is the same as the pen color.
+ color = getattr(edge,'color','')
+
+ if self.color <> color:
+ if color:
+ s += self.setColor(('cC',color))
+ else:
+ # reset to default color
+ s += self.setColor(('cC','black'))
+
+ pp= []
+ for point in points:
+ p = point.split(',')
+ pp.append("(%sbp,%sbp)" % (p[0],p[1]))
+
+ edgestyle = edge.style
+
+ styles = []
+ if arrowstyle <> '--':
+ #styles.append(arrowstyle)
+ styles = [arrowstyle]
+
+ if edgestyle:
+ edgestyles = [self.styles.get(key.strip(),key.strip()) for key in edgestyle.split(',') if key]
+ styles.extend(edgestyles)
+
+ stylestr = ",".join(styles)
+ topath = getattr(edge,'topath',None)
+
+ pstrs = ["%s .. controls %s and %s " % p for p in nsplit(pp, 3)]
+ extra = ""
+ if self.options.get('tikzedgelabels',False) or topath:
+ edgelabel = self.getLabel(edge)
+ #log.warning('label: %s', edgelabel)
+ lblstyle = getattr(edge,'lblstyle','')
+ if lblstyle:
+ lblstyle = '['+lblstyle+']'
+ else:
+ lblstyle = ''
+ if edgelabel:
+ extra = " node%s {%s}" % (lblstyle,edgelabel)
+ src = pp[0]
+ dst = pp[-1]
+ if topath:
+ s += " \draw [%s] %s to[%s]%s %s;\n" % (stylestr, src,
+ topath, extra,dst)
+ elif not self.options.get('straightedges',False):
+ #s += " \draw [%s] %s .. %s;\n" % (stylestr, " .. ".join(pstrs), pp[-1])
+ s += " \draw [%s] %s ..%s %s;\n" % (stylestr, " .. ".join(pstrs), extra,pp[-1])
+ else:
+ s += " \draw [%s] %s --%s %s;\n" % (stylestr, pp[0],extra, pp[-1])
+
+ return s
+
+ def initTemplateVars(self):
+ DotConvBase.initTemplateVars(self)
+ if self.options.get('crop',False):
+ cropcode = "\usepackage[active,tightpage]{preview}\n" + \
+ "\PreviewEnvironment{tikzpicture}\n" + \
+ "\setlength\PreviewBorder{%s}" % self.options.get('margin','0pt')
+ else:
+ cropcode = ""
+ vars = {}
+ vars['<<cropcode>>'] = cropcode
+ self.templatevars.update(vars)
+
+ def getNodePreprocCode(self,node):
+ lblstyle = node.get('lblstyle','')
+ text = node.get('texlbl','')
+ if lblstyle:
+ return " \\tikz \\node[%s] {%s};\n" % (lblstyle, text)
+ else:
+ return r"\tikz \node {" + text +"};"
+
+ def getEdgePreprocCode(self,edge):
+ lblstyle = getattr(edge,'lblstyle','')
+ if lblstyle:
+ return " \\tikz \\node[%s] {%s};\n" % (lblstyle, edge.texlbl)
+ else:
+ return r"\tikz \node " + "{"+edge.texlbl +"};"
+
+ def getGraphPreprocCode(self,graph):
+ lblstyle = getattr(graph,'lblstyle','')
+ if lblstyle:
+ return " \\tikz \\node[%s] {%s};\n" % (lblstyle, graph.texlbl)
+ else:
+ return r"\tikz \node " + graph.texlbl +"};"
+
+
+
+
+
+
+TIKZ_TEMPLATE = r"""\documentclass{article}
+\usepackage[x11names, rgb]{xcolor}
+\usepackage[<<textencoding>>]{inputenc}
+\usepackage{tikz}
+\usetikzlibrary{snakes,arrows,shapes}
+\usepackage{amsmath}
+<<startpreprocsection>>%
+\usepackage[active,auctex]{preview}
+<<endpreprocsection>>%
+<<gvcols>>%
+<<cropcode>>%
+<<docpreamble>>%
+
+\begin{document}
+\pagestyle{empty}
+%
+<<startpreprocsection>>%
+<<preproccode>>
+<<endpreprocsection>>%
+%
+<<startoutputsection>>
+\enlargethispage{100cm}
+% Start of code
+\begin{tikzpicture}[>=latex',join=bevel,<<graphstyle>>]
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+\end{tikzpicture}
+% End of code
+<<endoutputsection>>
+%
+\end{document}
+%
+<<startfigonlysection>>
+\begin{tikzpicture}[>=latex,join=bevel,<<graphstyle>>]
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+\end{tikzpicture}
+<<endfigonlysection>>
+<<startcodeonlysection>>
+<<figpreamble>>%
+<<drawcommands>>
+<<figpostamble>>%
+<<endcodeonlysection>>
+"""
+
+class Dot2TikZConv(Dot2PGFConv):
+ """A backend that utilizes the node and edge mechanism of PGF/TikZ"""
+ shapemap = {'doublecircle' : 'circle, double',
+ 'box' : 'rectangle',
+ 'rect' : 'rectangle',
+ 'none' :'draw=none',
+ 'plaintext' : 'draw=none',
+ 'polygon' : 'regular polygon, regular polygon sides=7',
+ 'triangle' : 'regular polygon, regular polygon sides=3',
+ 'pentagon' : 'regular polygon, regular polygon sides=5',
+ 'hexagon' : 'regular polygon, regular polygon sides=5',
+ 'septagon' : 'regular polygon, regular polygon sides=7',
+ 'octagon' : 'regular polygon, regular polygon sides=8',
+ }
+
+ def __init__(self, options={}):
+ # to connect nodes they have to defined. Therefore we have to ensure
+ # that code for generating nodes is outputted first.
+ options['switchdraworder'] = True
+ options['flattengraph'] = True
+ options['rawdim'] = True
+ DotConvBase.__init__(self, options)
+ if not self.template:
+ self.template = TIKZ_TEMPLATE
+
+ self.styles = dict(dashed='dashed', dotted='dotted',
+ bold='very thick', filled='fill', invis="",
+ rounded='rounded corners', )
+ self.dashstyles = dict(
+ dashed = '\pgfsetdash{{3pt}{3pt}}{0pt}',
+ dotted='\pgfsetdash{{\pgflinewidth}{2pt}}{0pt}',
+ bold = '\pgfsetlinewidth{1.2pt}')
+
+ def setOptions(self):
+ Dot2PGFConv.setOptions(self)
+ self.options['tikzedgelabels'] = self.options.get('tikzedgelabels','') \
+ or getboolattr(self.maingraph,'d2ttikzedgelabels','')
+ self.options['styleonly'] = self.options.get('styleonly','') \
+ or getboolattr(self.maingraph,'d2tstyleonly','')
+ self.options['nodeoptions'] = self.options.get('nodeoptions','') \
+ or getattr(self.maingraph,'d2tnodeoptions','')
+ self.options['edgeoptions'] = self.options.get('edgeoptions','') \
+ or getattr(self.maingraph,'d2tedgeoptions','')
+
+ def outputNodeComment(self, node):
+ # With the node syntax comments are unnecessary
+ return ""
+
+ def getNodePreprocCode(self,node):
+ lblstyle = node.get('lblstyle','')
+
+ shape = node.get('shape','ellipse')
+ shape = self.shapemap.get(shape, shape)
+ #s += "%% %s\n" % (shape)
+ label = node.get('texlbl','')
+ style = node.get('style'," ") or " ";
+ if lblstyle:
+ if style.strip():
+ style += ','+lblstyle
+ else:
+ style = lblstyle
+
+ sn = ""
+ if self.options.get('styleonly'):
+ sn += "\\tikz \\node (%s) [%s] {%s};\n" % \
+ (style, label)
+ else:
+ sn += "\\tikz \\node [draw,%s,%s] {%s};\n" % \
+ (shape, style, label)
+ return sn
+
+ def doNodes(self):
+ s = ""
+ nodeoptions= self.options.get('nodeoptions',None)
+ if nodeoptions:
+ s += "\\begin{scope}[%s]\n" % nodeoptions
+ for node in self.nodes:
+ self.currentnode = node
+ # detect node type
+ shape = getattr(node,'shape','ellipse')
+ shape = self.shapemap.get(shape, shape)
+ if shape == None:
+ shape='ellipse'
+
+ pos = getattr(node,'pos',None)
+ if not pos:
+ continue
+ x,y = pos.split(',')
+ label = self.getLabel(node)
+
+ pos = "%sbp,%sbp" % (x,y)
+ style = node.style or "";
+ if node.lblstyle:
+ if style:
+ style += ','+node.lblstyle
+ else:
+ style = node.lblstyle
+ if node.exstyle:
+ if style:
+ style += ','+node.exstyle
+ else:
+ style = node.exstyle
+ sn = ""
+ sn += self.outputNodeComment(node)
+ sn += self.startNode(node)
+ if self.options.get('styleonly'):
+ sn += " \\node (%s) at (%s) [%s] {%s};\n" % \
+ (node.name, pos, style, label)
+ else:
+ color = getattr(node,'color','')
+ drawstr = 'draw'
+ if style.strip() == 'filled':
+ drawstr='fill,draw'
+ style = ''
+ if color:
+ drawstr += ','+color
+ elif color:
+ drawstr += '='+color
+
+ if style.strip():
+ sn += " \\node (%s) at (%s) [%s,%s,%s] {%s};\n" % \
+ (node.name, pos, drawstr, shape, style, label)
+ else:
+ sn += " \\node (%s) at (%s) [%s,%s] {%s};\n" % \
+ (node.name, pos, drawstr, shape, label)
+ sn += self.endNode(node)
+
+
+ s += sn
+ if nodeoptions:
+ s += "\\end{scope}\n"
+ self.body += s
+
+ def doEdges(self):
+ s = ""
+ edgeoptions = self.options.get('edgeoptions',None)
+ if edgeoptions:
+ s += "\\begin{scope}[%s]\n" % edgeoptions
+ for edge in self.edges:
+ dstring = getattr(edge,'_draw_',"")
+ lstring = getattr(edge,'_ldraw_',"")
+ hstring = getattr(edge,'_hdraw_',"")
+ tstring = getattr(edge,'_tdraw_',"")
+ tlstring = getattr(edge,'_tldraw_',"")
+ hlstring = getattr(edge,'_hldraw_',"")
+ topath = getattr(edge,'topath',None)
+ s += self.drawEdge(edge)
+ if not self.options.get('tikzedgelabels',False) and not topath:
+ s += self.doDrawString(lstring+" "+tlstring+" "+hlstring, edge)
+ else:
+ s += self.doDrawString(tlstring+" "+hlstring, edge)
+
+ if edgeoptions:
+ s += "\\end{scope}\n"
+ self.body += s
+
+ def drawEdge(self, edge):
+ s = ""
+ if edge.style == 'invis':
+ return ""
+ arrowstyle, points = self.getEdgePoints(edge)
+ # PGF uses the fill style when drawing some arrowheads. We have to
+ # ensure that the fill color is the same as the pen color.
+ color = getattr(edge,'color','')
+ pp= []
+ for point in points:
+ p = point.split(',')
+ pp.append("(%sbp,%sbp)" % (p[0],p[1]))
+
+ edgestyle = edge.style
+ #print edgestyle
+
+ styles = []
+ if arrowstyle <> '--':
+ #styles.append(arrowstyle)
+ styles = [arrowstyle]
+
+ if edgestyle:
+ edgestyles = [self.styles.get(key.strip(),key.strip()) for key in edgestyle.split(',') if key]
+ styles.extend(edgestyles)
+
+ stylestr = ",".join(styles)
+ if color:
+ stylestr = color+','+stylestr
+ src = edge.get_source()
+ dst = edge.get_destination()
+ topath = getattr(edge,'topath',None)
+
+ pstrs = ["%s .. controls %s and %s " % p for p in nsplit(pp, 3)]
+ pstrs[0] = "(%s) ..controls %s and %s " % (src, pp[1], pp[2])
+ extra = ""
+ if self.options.get('tikzedgelabels',False) or topath:
+ edgelabel = self.getLabel(edge)
+ #log.warning('label: %s', edgelabel)
+ lblstyle = getattr(edge,'lblstyle','')
+ exstyle = getattr(edge,'exstyle','')
+ if exstyle:
+ if lblstyle:
+ lblstyle += ',' +exstyle
+ else:
+ lblstyle = exstyle
+ if lblstyle:
+ lblstyle = '['+lblstyle+']'
+ else:
+ lblstyle = ''
+ if edgelabel:
+ extra = " node%s {%s}" % (lblstyle,edgelabel)
+
+ if topath:
+ s += " \draw [%s] (%s) to[%s]%s (%s);\n" % (stylestr, src,
+ topath, extra,dst)
+ elif not self.options.get('straightedges',False):
+ s += " \draw [%s] %s ..%s (%s);\n" % (stylestr,
+ " .. ".join(pstrs), extra,dst)
+ else:
+ s += " \draw [%s] (%s) --%s (%s);\n" % (stylestr, src, extra,dst)
+
+ return s
+
+ def startNode(self, node):
+ return ""
+
+ def endNode(self,node):
+ return ""
+
+dimext = r"""
+^\!\s Preview:\s Snippet\s
+(?P<number>\d*)\s ended.
+\((?P<ht>\d*)\+(?P<dp>\d*)x(?P<wd>\d*)\)"""
+
+class TeXDimProc:
+ """Helper class for for finding the size of TeX snippets
+
+ Uses preview.sty
+ """
+ # Produce document
+ # Create a temporary directory
+ # Compile file with latex
+ # Parse log file
+ # Update graph with with and height parameters
+ # Clean up
+ def __init__(self,template,options):
+ self.template = template
+ self.snippets_code=[]
+ self.snippets_id=[]
+ self.options = options
+ self.dimext_re = re.compile(dimext,re.MULTILINE|re.VERBOSE)
+ pass
+ def addSnippet(self,id, code):
+ """A a snippet of code to be processed"""
+ self.snippets_id.append(id)
+ self.snippets_code.append(code)
+
+ def process(self):
+ """Process all snippets of code with TeX and preview.sty
+
+ Results are stored in the texdimlist and texdims class attributes.
+ Returns False if preprocessing fails
+ """
+ import shutil
+ if len(self.snippets_code) == 0:
+ log.warning('No labels to preprocess')
+ return True
+ self.tempdir = tempfile.mkdtemp(prefix='dot2tex')
+ log.debug('Creating temporary directroy %s' % self.tempdir)
+ self.tempfilename = os.path.join(self.tempdir,'dot2tex.tex')
+ log.debug('Creating temporary file %s' % self.tempfilename)
+ f = open(self.tempfilename,'w')
+ s = ""
+ for n in self.snippets_code:
+ s += "\\begin{preview}%\n"
+ s += n.strip()+"%\n"
+ s += "\end{preview}%\n"
+
+ f.write(self.template.replace('<<preproccode>>',s))
+ #f.flush()
+ f.close()
+ s = open(self.tempfilename,'r').read()
+ log.debug('Code written to %s\n' % self.tempfilename + s)
+ self.parseLogFile()
+ shutil.rmtree(self.tempdir)
+ log.debug('Temporary directory and files deleted')
+ if self.texdims:
+ return True
+ else:
+ return False
+ # cleanup
+
+ def parseLogFile(self):
+ logfilename = os.path.splitext(self.tempfilename)[0]+'.log'
+ tmpdir = os.getcwd()
+ os.chdir(os.path.split(logfilename)[0])
+ if self.options.get('usepdflatex',False):
+ command = 'pdflatex -interaction=nonstopmode %s' % self.tempfilename
+ else:
+ command = 'latex -interaction=nonstopmode %s' % self.tempfilename
+ log.debug('Running command: %s' % command)
+ sres = os.popen(command)
+ resdata = sres.read()
+ #log.debug('resdata: %s' % resdata)
+ errcode = sres.close()
+ log.debug('errcode: %s' % errcode)
+ f = open(logfilename,'r')
+ logdata = f.read()
+ log.debug('Logfile from LaTeX run: \n'+logdata)
+ f.close()
+ os.chdir(tmpdir)
+
+ texdimdata = self.dimext_re.findall(logdata)
+ log.debug('Texdimdata: '+ str(texdimdata))
+ if len(texdimdata)== 0:
+ log.error('No dimension data could be extracted from dot2tex.tex.')
+ self.texdims = None
+ return
+
+ c = 1/(100.0*7227)
+ c = 1.0/4736286
+ self.texdims = {}
+ self.texdimlist = [(float(i[1])*c,float(i[2])*c,float(i[3])*c) for i in texdimdata]
+ #for i in range(len(self.snippets_id)):
+ # self.texdims[self.snippets_id[i]] = self.texdimlist[i]
+ self.texdims = dict(zip(self.snippets_id,self.texdimlist))
+
+
+def cleanDotNodes(graph):
+ """Remove unnecessary data from node list"""
+ nodes = graph.get_node_list()
+ tmp = [node for node in nodes if node.name.startswith('"')]
+ for node in nodes:
+ node.name = node.name.replace('"','')
+ # There are some strange issues with what nodes are returned
+ # across different operating systems and versions of pydot, pyparsing,
+ # and Graphviz. This is just a quick fix. Need to investigate this further
+ if tmp:
+ return tmp
+ else:
+ return nodes
+
+
+# todo: Should also support graph attributes
+def setDotAttr(graph):
+ """Distribute default attributes to nodes and edges"""
+ elements = getAllGraphElements(graph,[])
+ stack = []
+ definednodes = {}
+ defattrs = {}
+ defedgeattrs = {}
+ for element in elements:
+ if isinstance(element,pydot.Node):
+ node = element
+ nodeattrs = node.__dict__
+ # is it an attribute statement? (attr_stmt)
+ if node.name == 'node':
+ # The node attributes are stored in node.__dict__. Extract all
+ # items that are not None or functions
+ defattrs.update([a for a in nodeattrs.items()
+ if (a[1] or a[1]=='') and not callable(a[1])])
+ elif node.name == 'edge':
+ defedgeattrs.update([a for a in nodeattrs.items()
+ if a[1] and not callable(a[1])])
+ continue
+ elif node.name == 'graph':
+ continue
+ else:
+ name = node.name.replace('"','')
+ if definednodes.get(name,False):
+ continue
+ #pass
+ else:
+ definednodes[name] = True
+ for key,value in defattrs.items():
+ if value=='\N':continue
+ if not node.__dict__.get(key):
+ node.__dict__[key]=value
+ elif isinstance(element,pydot.Edge):
+ edge = element
+ for key,value in defedgeattrs.items():
+ if not edge.__dict__.get(key):
+ edge.__dict__[key]=value
+ elif isinstance(element,pydot.Graph):
+ # push current set of attributes on the stack
+ stack.append((defattrs,defedgeattrs))
+ defattrs = defattrs.copy()
+ defedgeattrs = defedgeattrs.copy()
+ elif isinstance(element,EndOfGraphElement):
+ defattrs,defedgeattrs = stack.pop()
+
+
+def convertDot(data, backend='pstricks', options = {}):
+ """Convert xdot data to a backend compatible format
+
+ Input:
+ data - dot
+ backend - pstricks, pgf, eepic
+
+ """
+ graph = pydot.graph_from_dot_data(data)
+ nodes = cleanDotNodes(graph)
+ edges = graph.edge_list
+ # Detect graph type
+ if graph.graph_type == 'digraph':
+ directedgraph = True
+ else:
+ directedgraph = False
+ # process edges and nodes
+ for node in nodes:
+ pass
+
+
+def debug(filename = 'd:/pycode/algs/t.dot'):
+ dotdata = open(filename).read()
+ r = convertDot(dotdata)
+ print r
+
+
+def processCmdLine():
+ """Set up and parse command line options"""
+ usage = "Usage: %prog [options] <files>"
+ parser = OptionParser(usage)
+ parser.add_option("-f", "--format",
+ action="store", dest="format",
+ choices = ('pstricks','pgf','pst','tikz'),
+ help="Set output format to 'v' (pstrics, pgf) ", metavar="v")
+ parser.add_option('-t','--texmode', dest='texmode', default = 'verbatim',
+ choices = ('math','verbatim', 'raw'),
+ help = "Set text mode (verbatim, math, raw).")
+ parser.add_option('-d', '--duplicate', dest = 'duplicate', action='store_true',
+ default=False, help='Try to duplicate Graphviz graphics')
+ parser.add_option('-s', '--straightedges', dest = 'straightedges', action='store_true',
+ default=False, help='Force straight edges')
+ parser.add_option('--template', dest = 'templatefile', action = 'store',
+ metavar = "FILE")
+ parser.add_option('-o','--output', dest = 'outputfile', action = 'store',
+ metavar = "FILE", default='',help="Write output to FILE")
+ parser.add_option('-e','--encoding', dest = 'encoding', action = 'store',
+ choices = ('utf8','latin1'), default=DEFAULT_TEXTENCODING,
+ help="Set text encoding to utf8 or latin1")
+ parser.add_option('-V','--version', dest = 'printversion', action='store_true',
+ help="Print version information and exit", default=False),
+ parser.add_option('-w','--switchdraworder', dest = 'switchdraworder',
+ action="store_true", help = "Switch draw order", default=False),
+ parser.add_option('-p','-c','--preview', '--crop', dest = 'crop', action = 'store_true',
+ help="Use preview.sty to crop graph", default=False),
+ parser.add_option('--margin', dest = 'margin', action = 'store',
+ help="Set preview margin", default="0pt"),
+ parser.add_option('--docpreamble', dest = 'docpreamble', action = 'store',
+ help="Insert TeX code in document preamble", metavar="TEXCODE"),
+ parser.add_option('--figpreamble', dest = 'figpreamble', action = 'store',
+ help="Insert TeX code in figure preamble", metavar="TEXCODE"),
+ parser.add_option('--figpostamble', dest = 'figpostamble', action = 'store',
+ help="Insert TeX code in figure postamble", metavar="TEXCODE"),
+ parser.add_option('--graphstyle', dest = 'graphstyle', action = 'store',
+ help="Insert graph style", metavar="STYLE"),
+ parser.add_option('--gvcols', dest='gvcols', action ="store_true",
+ default=False, help="Include gvcols.tex"),
+ parser.add_option('--figonly', dest='figonly', action ="store_true",
+ help="Output graph with no preamble", default=False)
+ parser.add_option('--codeonly', dest='codeonly', action ="store_true",
+ help="Output only drawing commands", default=False)
+ parser.add_option('--styleonly', dest='styleonly', action ="store_true",
+ help="Use style parameter only", default=False)
+ parser.add_option('--debug',dest='debug', action="store_true",
+ help="Show additional debugging information", default=False)
+ parser.add_option('--preproc', dest='texpreproc', action="store_true",
+ help = 'Preprocess graph through TeX', default=False)
+ parser.add_option('--alignstr',dest='alignstr',action='store')
+ parser.add_option('--valignmode', dest='valignmode', default = 'center',
+ choices = ('center','dot'),
+ help = "Set vertical alginment mode (center, dot).")
+ parser.add_option('--nominsize', dest='nominsize', action ="store_true",
+ help="No minimum node sizes", default=False)
+ parser.add_option('--usepdflatex', dest='usepdflatex', action ="store_true",
+ help="Use PDFLaTeX for preprocessing", default=False)
+ parser.add_option('--tikzedgelabels', dest='tikzedgelabels', action ="store_true",
+ help="Let TikZ place edge labels", default=False)
+ parser.add_option('--nodeoptions', dest = 'nodeoptions', action = 'store',
+ help="Set options for nodes", metavar="OPTIONS"),
+ parser.add_option('--edgeoptions', dest = 'edgeoptions', action = 'store',
+ help="Set options for edges", metavar="OPTIONS"),
+ parser.add_option('--runtests',dest='runtests',
+ help="Run testes", action="store_true",default=False)
+
+ parser.add_option("--prog", action="store", dest="prog", default='dot',
+ choices = ('dot','neato','circo','fdp','twopi'),
+ help="Use v to process the graph", metavar="v"),
+ parser.add_option('--autosize',dest='autosize',
+ help="Preprocess graph and then run Graphviz", action="store_true",default=False)
+
+ #parser.add_option("--var", action="append", dest="uservars")
+
+ (options, args) = parser.parse_args()
+
+ return options,args,parser
+
+def _runtests():
+ import doctest
+ doctest.testmod()
+
+
+def printVersionInfo():
+ print "Dot2tex version % s" % __version__
+
+def main():
+ import platform
+ options, args,parser = processCmdLine()
+ if options.runtests:
+ log.warning('running tests')
+ _runtests()
+ sys.exit(0)
+
+ if options.debug:
+ # initalize log handler
+ hdlr = logging.FileHandler('dot2tex.log')
+ log.addHandler(hdlr)
+ formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
+ hdlr.setFormatter(formatter)
+ log.setLevel(logging.DEBUG)
+ nodebug = False
+ else:
+ nodebug = True
+
+ log.info('------- Start of run -------')
+ log.info("Dot2tex version % s" % __version__)
+ log.info("System information:\n"
+ " Python: %s \n"
+ " Platform: %s\n"
+ " Pydot: %s\n"
+ " Pyparsing: %s",
+ sys.version_info, platform.platform(),
+ pydot.__version__,pydot.dot_parser.pyparsing_version)
+ log.info('dot2tex called with: %s' % sys.argv)
+ log.info('Program started in %s' % os.getcwd())
+
+ if options.printversion:
+ #print options.hest
+ printVersionInfo()
+ sys.exit(0)
+ if len(args) == 0:
+ log.info('Data read from standard input')
+ dotdata = sys.stdin.readlines()
+ elif len(args) == 1:
+ try:
+ dotdata = open(args[0], 'rU').readlines()
+ except:
+ log.error("Could not open input file %s" % args[0])
+ sys.exit(1)
+ log.info('Data read from %s' % args[0])
+
+ # I'm not quite sure why this is necessary, but some files
+ # produces data with line endings that confuses pydot/pyparser.
+ # Note: Whitespace at end of line is sometimes significant
+ log.debug('Input data:\n'+"".join(dotdata))
+ lines = [line for line in dotdata if line.strip()]
+ dotdata = "".join(lines)
+ #dotdata = convert_line_endings(dotdata,0)
+ #optparse.check_choice()
+
+ # check for output format attribute
+ fmtattr = re.findall(r'd2toutputformat=(.*?);',dotdata)
+ extraoptions = re.findall(r'd2toptions\s*=\s*"(.*?)"\s*;?',dotdata)
+ if fmtattr:
+ log.info('Found outputformat attribute: %s',fmtattr[0])
+ gfmt = fmtattr[0]
+ else:
+ gfmt = None
+ if extraoptions:
+ #log.warning('Found d2toptions attribute in graph: %s',extraoptions[0])
+ (options, args) = parser.parse_args(extraoptions[0].split(),options)
+ if options.debug and nodebug:
+ # initalize log handler
+ hdlr = logging.FileHandler('dot2tex.log')
+ log.addHandler(hdlr)
+ formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
+ hdlr.setFormatter(formatter)
+ log.setLevel(logging.DEBUG)
+ nodebug = False
+
+
+ output_format = options.format or gfmt or DEFAULT_OUTPUT_FORMAT
+ options.format = output_format
+
+ if output_format in ('pstricks', 'pst'):
+ conv = Dot2PSTricksConv(options.__dict__)
+ elif output_format == 'pgf':
+ conv = Dot2PGFConv(options.__dict__)
+ elif output_format == 'tikz':
+ conv = Dot2TikZConv(options.__dict__)
+ else:
+ log.error("Unknown output format %s" % options.format)
+ sys.exit(1)
+ try:
+ s = conv.convert(dotdata)
+ log.debug('Output:\n'+s)
+ if options.autosize:
+ conv.dopreproc = False
+ s = conv.convert(s)
+ log.debug('Output:\n'+s)
+ if options.outputfile:
+ f = open(options.outputfile, 'w')
+ f.write(s)
+ f.close()
+ else:
+ print s
+ #if options.texpreproc:
+ # print conv.preproc.writeTempFile()
+ except SystemExit:
+ pass
+ except Exception:
+ #log.error("Could not convert the xdot input.")
+ log.exception('Failed to process input')
+
+ log.info('------- End of run -------')
+
+
+
+if __name__ == '__main__':
+ main()
+
+
+
diff --git a/graphics/dot2tex/examples/automata.dot b/graphics/dot2tex/examples/automata.dot
new file mode 100644
index 0000000000..01304574da
--- /dev/null
+++ b/graphics/dot2tex/examples/automata.dot
@@ -0,0 +1,32 @@
+/*
+
+:Title: State machine
+:Tags: PGF, Preproc
+
+This state machine is `based on an example`_ from the PGF and TikZ manual.
+The original looks much better. For small graphs you usually
+get better looking results by drawing them manually.
+
+.. _based on an example: http://www.fauskes.net/pgftikzexamples/state-machine/
+
+Generated with::
+
+ $ dot2tex.py -tmath --preproc automata.dot |dot2tex.py --crop > automata.tex
+
+
+*/
+digraph automata {
+ rankdir=LR;
+ node [shape=circle];
+ edge [style=">=stealth',shorten >=1pt"];
+ q_a [shape=doublecircle];
+ q_a -> q_b [label="0,1,L"];
+ q_b -> q_b [label="1,1,L"];
+ q_b -> q_c [label="0,1,L"];
+ q_c -> q_e [label="1,0,R"];
+ q_e -> q_a [label="1,0,R"];
+ q_a -> q_c [label="1,1,R"];
+ q_c -> q_d [label="0,1,L"];
+ q_d -> q_d [label="1,1,R"];
+ q_d -> q_a [label="0,1,R"];
+}
diff --git a/graphics/dot2tex/examples/balls.dot b/graphics/dot2tex/examples/balls.dot
new file mode 100644
index 0000000000..59dc6f165e
--- /dev/null
+++ b/graphics/dot2tex/examples/balls.dot
@@ -0,0 +1,24 @@
+/*
+
+:Title: Snaked edges
+:Tags: PGF
+
+This graph uses special `PGF/TikZ`_ styles to create some interesting
+visual effects. To get the snaked edges run dot2tex with the ``-s`` option
+to force straight edges.
+
+Generated with::
+
+ $ fdp -Txdot balls.dot | dot2tex.py -s -fpgf > balls.tex
+
+.. _PGF/TikZ: http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html
+*/
+graph G {
+ node [shape=circle, fixedsize=True, width="0.2", style="ball color = green", label=""];
+ edge [style="snake=zigzag, green"];
+ a_1 -- c -- a_2;
+ c [style="ball color=black"];
+ edge [style="snake=snake, blue", color=red];
+ node [style="ball color = red", label=""];
+ a_3 -- c -- a_4 --a_3;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/distances.dot b/graphics/dot2tex/examples/distances.dot
new file mode 100644
index 0000000000..b9cc1f30e1
--- /dev/null
+++ b/graphics/dot2tex/examples/distances.dot
@@ -0,0 +1,25 @@
+/*
+:Title: Distances
+:Tags: TikZ, tikzedgelabels
+
+Generated with::
+
+ $ circo -Txdot distances.dot | dot2tex.py --crop --tikzedgelabels -ftikz -tmath -s > distances.tex
+
+*/
+graph G {
+ node [shape=circle,fixedsize = true,width=0.1,style="fill=blue!20"];
+ edge [lblstyle="fill=black!10,inner sep=1pt,sloped"];
+ K -- F [label="120"];
+ H -- S [label="650"];
+ H -- M [label="780"];
+ D -- B [label="490"];
+ D -- M [label="600"];
+ B -- M [label="580"];
+ H -- N [label="600"];
+ F -- H [label="490"];
+ S -- B [label="630"];
+ S -- N [label="210"];
+ S -- M [label="230"];
+ F --M [label="100"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/ex1.dot b/graphics/dot2tex/examples/ex1.dot
new file mode 100644
index 0000000000..5ae471d14f
--- /dev/null
+++ b/graphics/dot2tex/examples/ex1.dot
@@ -0,0 +1,14 @@
+/*
+:Title: Basic example
+:Tags: PGF
+
+A basic example.
+
+Generated with::
+
+ $ dot2tex.py --preproc -tmath ex1.dot | dot2tex.py > ex1.tex
+
+*/
+digraph G {
+ a_1-> a_2 -> a_3 -> a_1;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/graphanndtti.tex b/graphics/dot2tex/examples/graphanndtti.tex
new file mode 100644
index 0000000000..2d8f12835c
--- /dev/null
+++ b/graphics/dot2tex/examples/graphanndtti.tex
@@ -0,0 +1,44 @@
+\documentclass{article}
+\usepackage{tikz}
+\usetikzlibrary{arrows,shapes}
+\usepackage{dot2texi}
+\begin{document}
+% Define layers
+\pgfdeclarelayer{background}
+\pgfdeclarelayer{foreground}
+\pgfsetlayers{background,main,foreground}
+
+% The scale option is useful for adjusting spacing between nodes.
+% Note that this works best when straight lines are used to connect
+% the nodes.
+\begin{tikzpicture}[>=latex',scale=0.8]
+ % set node style
+ \tikzstyle{n} = [draw,shape=circle,minimum size=2em,
+ inner sep=0pt,fill=red!20]
+ \begin{dot2tex}[dot,tikz,codeonly,styleonly,options=-s -tmath]
+ digraph G {
+ node [style="n"];
+ A_1 -> B_1; A_1 -> B_2; A_1 -> B_3;
+ B_1 -> C_1; B_1 -> C_2;
+ B_2 -> C_2; B_2 -> C_3;
+ B_3 -> C_3; B_3 -> C_4;
+ }
+ \end{dot2tex}
+ % annotations
+ \node[left=1em] at (C_1.west) (l3) {Level 3};
+ \node at (l3 |- B_1) (l2){Level 2};
+ \node at (l3 |- A_1) (l1) {Level 1};
+ % Draw lines to separate the levels. First we need to calculate
+ % where the middle is.
+ \path (l3) -- coordinate (l32) (l2) -- coordinate (l21) (l1);
+ \draw[dashed] (C_1 |- l32) -- (l32 -| C_4);
+ \draw[dashed] (C_1 |- l21) -- (l21 -| C_4);
+ \draw[<->,red] (A_1) to[out=-120,in=90] (C_2);
+ % Highlight the A_1 -> B_1 -> C_2 path. Use layers to draw
+ % behind everything.
+ \begin{pgfonlayer}{background}
+ \draw[rounded corners=2em,line width=3em,blue!20,cap=round]
+ (A_1.center) -- (B_1.west) -- (C_2.center);
+ \end{pgfonlayer}
+\end{tikzpicture}
+\end{document} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/graphofgraphs.dot b/graphics/dot2tex/examples/graphofgraphs.dot
new file mode 100644
index 0000000000..6d234710e1
--- /dev/null
+++ b/graphics/dot2tex/examples/graphofgraphs.dot
@@ -0,0 +1,26 @@
+/*
+
+:Title: Graph of graphs
+:Tags: PGF
+
+This example shows that node content is not limited to text and math.
+You can for instance insert graphics and create this weird graph of graphs.
+Download the PDF and zoom in to see the details.
+
+Generated with::
+
+ $ neato -Txdot graphofgraphs.dot | dot2tex.py --crop -fpgf > graphofgraphs.tex
+
+*/
+digraph G {
+ graph [mindist=0.5];
+ node [shape=plaintext, height=0.5];
+ edge [style="black!50, thin,-to"];
+ a_1 [texlbl="\raisebox{-.4\height}{\includegraphics[height=30bp]{balls.pdf}}"];
+ a_2 [texlbl="\raisebox{-.4\height}{\includegraphics[height=30bp]{pgfsnakes.pdf}}"];
+ a_3 [texlbl="\raisebox{-.4\height}{\includegraphics[height=30bp]{pgfarrows.pdf}}"];
+ a_4 [texlbl="\raisebox{-.4\height}{\includegraphics[height=30bp]{poltab.pdf}}"];
+ a_5 [texlbl="\raisebox{-.4\height}{\includegraphics[height=30bp]{subgraphs.pdf}}"];
+ a_1-> a_2 -> a_3 -> a_4 -> a_5 -> a_1;
+ a_2 -> a_5;
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/gvcols.tex b/graphics/dot2tex/examples/gvcols.tex
new file mode 100644
index 0000000000..395cc992b0
--- /dev/null
+++ b/graphics/dot2tex/examples/gvcols.tex
@@ -0,0 +1,655 @@
+\def\rangeHSB{255}
+\preparecolorset{HSB}{}{}{%
+aliceblue,147,15,255;%
+antiquewhite,24,35,250;%
+antiquewhite1,23,36,255;%
+antiquewhite2,23,36,238;%
+antiquewhite3,23,36,205;%
+antiquewhite4,24,34,139;%
+aquamarine,113,128,255;%
+aquamarine1,113,128,255;%
+aquamarine2,113,128,238;%
+aquamarine3,113,128,205;%
+aquamarine4,113,128,139;%
+azure,127,15,255;%
+azure1,127,15,255;%
+azure2,127,15,238;%
+azure3,127,14,205;%
+azure4,127,14,139;%
+beige,42,26,245;%
+bisque,23,58,255;%
+bisque1,23,58,255;%
+bisque2,23,58,238;%
+bisque3,22,58,205;%
+bisque4,23,58,139;%
+black,0,0,0;%
+blanchedalmond,25,49,255;%
+blue,170,255,255;%
+blue1,170,255,255;%
+blue2,170,255,238;%
+blue3,170,255,205;%
+blue4,170,255,139;%
+blueviolet,192,206,226;%
+brown,0,190,165;%
+brown1,0,191,255;%
+brown2,0,191,238;%
+brown3,0,191,205;%
+brown4,0,190,139;%
+burlywood,23,99,222;%
+burlywood1,23,100,255;%
+burlywood2,23,99,238;%
+burlywood3,23,99,205;%
+burlywood4,23,99,139;%
+cadetblue,128,103,160;%
+cadetblue1,131,103,255;%
+cadetblue2,131,102,238;%
+cadetblue3,131,103,205;%
+cadetblue4,131,102,139;%
+chartreuse,63,255,255;%
+chartreuse1,63,255,255;%
+chartreuse2,63,255,238;%
+chartreuse3,63,255,205;%
+chartreuse4,63,255,139;%
+chocolate,17,218,210;%
+chocolate1,17,219,255;%
+chocolate2,17,219,238;%
+chocolate3,17,218,205;%
+chocolate4,17,220,139;%
+coral,11,175,255;%
+coral1,7,169,255;%
+coral2,6,169,238;%
+coral3,6,169,205;%
+coral4,6,168,139;%
+cornflowerblue,154,147,237;%
+cornsilk,33,34,255;%
+cornsilk1,33,34,255;%
+cornsilk2,34,35,238;%
+cornsilk3,34,34,205;%
+cornsilk4,35,34,139;%
+crimson,246,231,220;%
+cyan,127,255,255;%
+cyan1,127,255,255;%
+cyan2,127,255,238;%
+cyan3,127,255,205;%
+cyan4,127,255,139;%
+darkgoldenrod,30,239,184;%
+darkgoldenrod1,30,240,255;%
+darkgoldenrod2,30,240,238;%
+darkgoldenrod3,30,240,205;%
+darkgoldenrod4,30,240,139;%
+darkgreen,85,255,100;%
+darkkhaki,39,110,189;%
+darkolivegreen,58,142,107;%
+darkolivegreen1,58,143,255;%
+darkolivegreen2,58,143,238;%
+darkolivegreen3,58,143,205;%
+darkolivegreen4,58,143,139;%
+darkorange,23,255,255;%
+darkorange1,21,255,255;%
+darkorange2,21,255,238;%
+darkorange3,21,255,205;%
+darkorange4,21,255,139;%
+darkorchid,198,192,204;%
+darkorchid1,198,193,255;%
+darkorchid2,198,192,238;%
+darkorchid3,198,192,205;%
+darkorchid4,198,192,139;%
+darksalmon,10,121,233;%
+darkseagreen,85,61,188;%
+darkseagreen1,85,62,255;%
+darkseagreen2,85,62,238;%
+darkseagreen3,85,62,205;%
+darkseagreen4,85,62,139;%
+darkslateblue,175,143,139;%
+darkslategray,127,103,79;%
+darkslategray1,127,104,255;%
+darkslategray2,127,103,238;%
+darkslategray3,127,104,205;%
+darkslategray4,127,104,139;%
+darkslategrey,127,103,79;%
+darkturquoise,128,255,209;%
+darkviolet,199,255,211;%
+deeppink,232,235,255;%
+deeppink1,232,235,255;%
+deeppink2,232,235,238;%
+deeppink3,232,235,205;%
+deeppink4,231,236,139;%
+deepskyblue,138,255,255;%
+deepskyblue1,138,255,255;%
+deepskyblue2,138,255,238;%
+deepskyblue3,138,255,205;%
+deepskyblue4,138,255,139;%
+dimgray,0,0,105;%
+dimgrey,0,0,105;%
+dodgerblue,148,225,255;%
+dodgerblue1,148,225,255;%
+dodgerblue2,148,225,238;%
+dodgerblue3,148,225,205;%
+dodgerblue4,148,225,139;%
+firebrick,0,206,178;%
+firebrick1,0,207,255;%
+firebrick2,0,207,238;%
+firebrick3,0,207,205;%
+firebrick4,0,207,139;%
+floralwhite,28,15,255;%
+forestgreen,85,192,139;%
+gainsboro,0,0,220;%
+ghostwhite,170,7,255;%
+gold,35,255,255;%
+gold1,35,255,255;%
+gold2,35,255,238;%
+gold3,35,255,205;%
+gold4,35,255,139;%
+goldenrod,30,217,218;%
+goldenrod1,30,218,255;%
+goldenrod2,30,218,238;%
+goldenrod3,30,218,205;%
+goldenrod4,30,218,139;%
+gray,0,0,192;%
+gray0,0,0,0;%
+gray1,0,0,3;%
+gray10,0,0,26;%
+gray100,0,0,255;%
+gray11,0,0,28;%
+gray12,0,0,31;%
+gray13,0,0,33;%
+gray14,0,0,36;%
+gray15,0,0,38;%
+gray16,0,0,41;%
+gray17,0,0,43;%
+gray18,0,0,46;%
+gray19,0,0,48;%
+gray2,0,0,5;%
+gray20,0,0,51;%
+gray21,0,0,54;%
+gray22,0,0,56;%
+gray23,0,0,59;%
+gray24,0,0,61;%
+gray25,0,0,64;%
+gray26,0,0,66;%
+gray27,0,0,69;%
+gray28,0,0,71;%
+gray29,0,0,74;%
+gray3,0,0,8;%
+gray30,0,0,77;%
+gray31,0,0,79;%
+gray32,0,0,82;%
+gray33,0,0,84;%
+gray34,0,0,87;%
+gray35,0,0,89;%
+gray36,0,0,92;%
+gray37,0,0,94;%
+gray38,0,0,97;%
+gray39,0,0,99;%
+gray4,0,0,10;%
+gray40,0,0,102;%
+gray41,0,0,105;%
+gray42,0,0,107;%
+gray43,0,0,110;%
+gray44,0,0,112;%
+gray45,0,0,115;%
+gray46,0,0,117;%
+gray47,0,0,120;%
+gray48,0,0,122;%
+gray49,0,0,125;%
+gray5,0,0,13;%
+gray50,0,0,127;%
+gray51,0,0,130;%
+gray52,0,0,133;%
+gray53,0,0,135;%
+gray54,0,0,138;%
+gray55,0,0,140;%
+gray56,0,0,143;%
+gray57,0,0,145;%
+gray58,0,0,148;%
+gray59,0,0,150;%
+gray6,0,0,15;%
+gray60,0,0,153;%
+gray61,0,0,156;%
+gray62,0,0,158;%
+gray63,0,0,161;%
+gray64,0,0,163;%
+gray65,0,0,166;%
+gray66,0,0,168;%
+gray67,0,0,171;%
+gray68,0,0,173;%
+gray69,0,0,176;%
+gray7,0,0,18;%
+gray70,0,0,179;%
+gray71,0,0,181;%
+gray72,0,0,184;%
+gray73,0,0,186;%
+gray74,0,0,189;%
+gray75,0,0,191;%
+gray76,0,0,194;%
+gray77,0,0,196;%
+gray78,0,0,199;%
+gray79,0,0,201;%
+gray8,0,0,20;%
+gray80,0,0,204;%
+gray81,0,0,207;%
+gray82,0,0,209;%
+gray83,0,0,212;%
+gray84,0,0,214;%
+gray85,0,0,217;%
+gray86,0,0,219;%
+gray87,0,0,222;%
+gray88,0,0,224;%
+gray89,0,0,227;%
+gray9,0,0,23;%
+gray90,0,0,229;%
+gray91,0,0,232;%
+gray92,0,0,235;%
+gray93,0,0,237;%
+gray94,0,0,240;%
+gray95,0,0,242;%
+gray96,0,0,245;%
+gray97,0,0,247;%
+gray98,0,0,250;%
+gray99,0,0,252;%
+green,85,255,255;%
+green1,85,255,255;%
+green2,85,255,238;%
+green3,85,255,205;%
+green4,85,255,139;%
+greenyellow,59,208,255;%
+grey,0,0,192;%
+grey0,0,0,0;%
+grey1,0,0,3;%
+grey10,0,0,26;%
+grey100,0,0,255;%
+grey11,0,0,28;%
+grey12,0,0,31;%
+grey13,0,0,33;%
+grey14,0,0,36;%
+grey15,0,0,38;%
+grey16,0,0,41;%
+grey17,0,0,43;%
+grey18,0,0,46;%
+grey19,0,0,48;%
+grey2,0,0,5;%
+grey20,0,0,51;%
+grey21,0,0,54;%
+grey22,0,0,56;%
+grey23,0,0,59;%
+grey24,0,0,61;%
+grey25,0,0,64;%
+grey26,0,0,66;%
+grey27,0,0,69;%
+grey28,0,0,71;%
+grey29,0,0,74;%
+grey3,0,0,8;%
+grey30,0,0,77;%
+grey31,0,0,79;%
+grey32,0,0,82;%
+grey33,0,0,84;%
+grey34,0,0,87;%
+grey35,0,0,89;%
+grey36,0,0,92;%
+grey37,0,0,94;%
+grey38,0,0,97;%
+grey39,0,0,99;%
+grey4,0,0,10;%
+grey40,0,0,102;%
+grey41,0,0,105;%
+grey42,0,0,107;%
+grey43,0,0,110;%
+grey44,0,0,112;%
+grey45,0,0,115;%
+grey46,0,0,117;%
+grey47,0,0,120;%
+grey48,0,0,122;%
+grey49,0,0,125;%
+grey5,0,0,13;%
+grey50,0,0,127;%
+grey51,0,0,130;%
+grey52,0,0,133;%
+grey53,0,0,135;%
+grey54,0,0,138;%
+grey55,0,0,140;%
+grey56,0,0,143;%
+grey57,0,0,145;%
+grey58,0,0,148;%
+grey59,0,0,150;%
+grey6,0,0,15;%
+grey60,0,0,153;%
+grey61,0,0,156;%
+grey62,0,0,158;%
+grey63,0,0,161;%
+grey64,0,0,163;%
+grey65,0,0,166;%
+grey66,0,0,168;%
+grey67,0,0,171;%
+grey68,0,0,173;%
+grey69,0,0,176;%
+grey7,0,0,18;%
+grey70,0,0,179;%
+grey71,0,0,181;%
+grey72,0,0,184;%
+grey73,0,0,186;%
+grey74,0,0,189;%
+grey75,0,0,191;%
+grey76,0,0,194;%
+grey77,0,0,196;%
+grey78,0,0,199;%
+grey79,0,0,201;%
+grey8,0,0,20;%
+grey80,0,0,204;%
+grey81,0,0,207;%
+grey82,0,0,209;%
+grey83,0,0,212;%
+grey84,0,0,214;%
+grey85,0,0,217;%
+grey86,0,0,219;%
+grey87,0,0,222;%
+grey88,0,0,224;%
+grey89,0,0,227;%
+grey9,0,0,23;%
+grey90,0,0,229;%
+grey91,0,0,232;%
+grey92,0,0,235;%
+grey93,0,0,237;%
+grey94,0,0,240;%
+grey95,0,0,242;%
+grey96,0,0,245;%
+grey97,0,0,247;%
+grey98,0,0,250;%
+grey99,0,0,252;%
+honeydew,85,15,255;%
+honeydew1,85,15,255;%
+honeydew2,85,15,238;%
+honeydew3,85,14,205;%
+honeydew4,85,14,139;%
+hotpink,233,150,255;%
+hotpink1,234,145,255;%
+hotpink2,235,141,238;%
+hotpink3,236,135,205;%
+hotpink4,234,148,139;%
+indianred,0,140,205;%
+indianred1,0,148,255;%
+indianred2,0,148,238;%
+indianred3,0,149,205;%
+indianred4,0,148,139;%
+indigo,194,255,130;%
+ivory,42,15,255;%
+ivory1,42,15,255;%
+ivory2,42,15,238;%
+ivory3,42,14,205;%
+ivory4,42,14,139;%
+khaki,38,106,240;%
+khaki1,39,112,255;%
+khaki2,39,112,238;%
+khaki3,39,111,205;%
+khaki4,39,111,139;%
+lavender,170,20,250;%
+lavenderblush,240,15,255;%
+lavenderblush1,240,15,255;%
+lavenderblush2,239,15,238;%
+lavenderblush3,240,14,205;%
+lavenderblush4,239,14,139;%
+lawngreen,64,255,252;%
+lemonchiffon,38,49,255;%
+lemonchiffon1,38,49,255;%
+lemonchiffon2,37,50,238;%
+lemonchiffon3,38,49,205;%
+lemonchiffon4,39,49,139;%
+lightblue,137,63,230;%
+lightblue1,138,64,255;%
+lightblue2,138,64,238;%
+lightblue3,138,63,205;%
+lightblue4,137,64,139;%
+lightcoral,0,119,240;%
+lightcyan,127,31,255;%
+lightcyan1,127,31,255;%
+lightcyan2,127,31,238;%
+lightcyan3,127,31,205;%
+lightcyan4,127,31,139;%
+lightgoldenrod,35,115,238;%
+lightgoldenrod1,35,116,255;%
+lightgoldenrod2,35,115,238;%
+lightgoldenrod3,35,115,205;%
+lightgoldenrod4,35,115,139;%
+lightgoldenrodyellow,42,40,250;%
+lightgray,0,0,211;%
+lightgrey,0,0,211;%
+lightpink,248,73,255;%
+lightpink1,249,81,255;%
+lightpink2,248,81,238;%
+lightpink3,249,80,205;%
+lightpink4,249,80,139;%
+lightsalmon,12,132,255;%
+lightsalmon1,12,132,255;%
+lightsalmon2,11,132,238;%
+lightsalmon3,12,133,205;%
+lightsalmon4,12,133,139;%
+lightseagreen,125,209,178;%
+lightskyblue,143,117,250;%
+lightskyblue1,143,79,255;%
+lightskyblue2,143,79,238;%
+lightskyblue3,142,79,205;%
+lightskyblue4,143,78,139;%
+lightslateblue,175,143,255;%
+lightslategray,148,56,153;%
+lightslategrey,148,56,153;%
+lightsteelblue,151,52,222;%
+lightsteelblue1,151,53,255;%
+lightsteelblue2,151,53,238;%
+lightsteelblue3,151,53,205;%
+lightsteelblue4,150,53,139;%
+lightyellow,42,31,255;%
+lightyellow1,42,31,255;%
+lightyellow2,42,31,238;%
+lightyellow3,42,31,205;%
+lightyellow4,42,31,139;%
+limegreen,85,192,205;%
+linen,21,20,250;%
+magenta,212,255,255;%
+magenta1,212,255,255;%
+magenta2,212,255,238;%
+magenta3,212,255,205;%
+magenta4,212,255,139;%
+maroon,239,185,176;%
+maroon1,228,203,255;%
+maroon2,228,203,238;%
+maroon3,228,204,205;%
+maroon4,228,203,139;%
+mediumaquamarine,113,128,205;%
+mediumblue,170,255,205;%
+mediumorchid,204,152,211;%
+mediumorchid1,203,153,255;%
+mediumorchid2,203,153,238;%
+mediumorchid3,203,153,205;%
+mediumorchid4,203,154,139;%
+mediumpurple,183,124,219;%
+mediumpurple1,183,125,255;%
+mediumpurple2,183,125,238;%
+mediumpurple3,183,125,205;%
+mediumpurple4,183,124,139;%
+mediumseagreen,103,169,179;%
+mediumslateblue,176,143,238;%
+mediumspringgreen,111,255,250;%
+mediumturquoise,125,167,209;%
+mediumvioletred,228,228,199;%
+midnightblue,170,198,112;%
+mintcream,106,9,255;%
+mistyrose,4,30,255;%
+mistyrose1,4,30,255;%
+mistyrose2,4,30,238;%
+mistyrose3,3,29,205;%
+mistyrose4,5,29,139;%
+moccasin,26,73,255;%
+navajowhite,25,81,255;%
+navajowhite1,25,81,255;%
+navajowhite2,25,82,238;%
+navajowhite3,25,82,205;%
+navajowhite4,25,82,139;%
+navy,170,255,128;%
+navyblue,170,255,128;%
+oldlace,27,23,253;%
+olivedrab,56,192,142;%
+olivedrab1,56,193,255;%
+olivedrab2,56,192,238;%
+olivedrab3,56,192,205;%
+olivedrab4,56,192,139;%
+orange,27,255,255;%
+orange1,27,255,255;%
+orange2,27,255,238;%
+orange3,27,255,205;%
+orange4,27,255,139;%
+orangered,11,255,255;%
+orangered1,11,255,255;%
+orangered2,11,255,238;%
+orangered3,11,255,205;%
+orangered4,11,255,139;%
+orchid,214,123,218;%
+orchid1,214,124,255;%
+orchid2,214,124,238;%
+orchid3,214,124,205;%
+orchid4,213,124,139;%
+palegoldenrod,38,72,238;%
+palegreen,85,100,251;%
+palegreen1,85,101,255;%
+palegreen2,85,100,238;%
+palegreen3,85,100,205;%
+palegreen4,85,100,139;%
+paleturquoise,127,67,238;%
+paleturquoise1,127,68,255;%
+paleturquoise2,127,68,238;%
+paleturquoise3,127,68,205;%
+paleturquoise4,127,67,139;%
+palevioletred,241,124,219;%
+palevioletred1,241,125,255;%
+palevioletred2,241,125,238;%
+palevioletred3,241,125,205;%
+palevioletred4,241,124,139;%
+papayawhip,26,41,255;%
+peachpuff,20,70,255;%
+peachpuff1,20,70,255;%
+peachpuff2,19,69,238;%
+peachpuff3,19,69,205;%
+peachpuff4,20,69,139;%
+peru,20,176,205;%
+pink,247,63,255;%
+pink1,245,73,255;%
+pink2,245,73,238;%
+pink3,245,74,205;%
+pink4,245,73,139;%
+plum,212,70,221;%
+plum1,212,68,255;%
+plum2,212,68,238;%
+plum3,212,68,205;%
+plum4,212,67,139;%
+powderblue,132,59,230;%
+purple,196,221,240;%
+purple1,191,207,255;%
+purple2,192,207,238;%
+purple3,192,207,205;%
+purple4,192,207,139;%
+red,0,255,255;%
+red1,0,255,255;%
+red2,0,255,238;%
+red3,0,255,205;%
+red4,0,255,139;%
+rosybrown,0,61,188;%
+rosybrown1,0,62,255;%
+rosybrown2,0,62,238;%
+rosybrown3,0,62,205;%
+rosybrown4,0,62,139;%
+royalblue,159,181,225;%
+royalblue1,159,183,255;%
+royalblue2,159,183,238;%
+royalblue3,159,182,205;%
+royalblue4,159,183,139;%
+saddlebrown,17,220,139;%
+salmon,4,138,250;%
+salmon1,9,150,255;%
+salmon2,9,150,238;%
+salmon3,9,150,205;%
+salmon4,9,150,139;%
+sandybrown,19,154,244;%
+seagreen,103,170,139;%
+seagreen1,103,171,255;%
+seagreen2,103,171,238;%
+seagreen3,103,171,205;%
+seagreen4,103,170,139;%
+seashell,17,16,255;%
+seashell1,17,16,255;%
+seashell2,18,17,238;%
+seashell3,18,17,205;%
+seashell4,18,16,139;%
+sienna,13,183,160;%
+sienna1,13,184,255;%
+sienna2,13,184,238;%
+sienna3,13,184,205;%
+sienna4,13,185,139;%
+skyblue,139,108,235;%
+skyblue1,144,120,255;%
+skyblue2,144,120,238;%
+skyblue3,144,120,205;%
+skyblue4,145,119,139;%
+slateblue,175,143,205;%
+slateblue1,175,144,255;%
+slateblue2,175,144,238;%
+slateblue3,175,144,205;%
+slateblue4,175,144,139;%
+slategray,148,56,144;%
+slategray1,149,56,255;%
+slategray2,149,56,238;%
+slategray3,148,57,205;%
+slategray4,149,56,139;%
+slategrey,148,56,144;%
+snow,0,5,255;%
+snow1,0,5,255;%
+snow2,0,5,238;%
+snow3,0,4,205;%
+snow4,0,3,139;%
+springgreen,106,255,255;%
+springgreen1,106,255,255;%
+springgreen2,106,255,238;%
+springgreen3,106,255,205;%
+springgreen4,106,255,139;%
+steelblue,146,155,180;%
+steelblue1,146,156,255;%
+steelblue2,146,156,238;%
+steelblue3,146,156,205;%
+steelblue4,147,155,139;%
+tan,24,84,210;%
+tan1,20,176,255;%
+tan2,20,176,238;%
+tan3,20,176,205;%
+tan4,20,176,139;%
+thistle,212,29,216;%
+thistle1,212,30,255;%
+thistle2,212,30,238;%
+thistle3,212,29,205;%
+thistle4,212,29,139;%
+tomato,6,184,255;%
+tomato1,6,184,255;%
+tomato2,6,184,238;%
+tomato3,6,184,205;%
+tomato4,6,185,139;%
+transparent,42,0,255;%
+turquoise,123,182,224;%
+turquoise1,129,255,255;%
+turquoise2,129,255,238;%
+turquoise3,129,255,205;%
+turquoise4,129,255,139;%
+violet,212,115,238;%
+violetred,227,215,208;%
+violetred1,235,193,255;%
+violetred2,235,192,238;%
+violetred3,235,192,205;%
+violetred4,235,192,139;%
+wheat,27,68,245;%
+wheat1,27,69,255;%
+wheat2,27,68,238;%
+wheat3,27,68,205;%
+wheat4,27,67,139;%
+white,0,0,255;%
+whitesmoke,0,0,245;%
+yellow,42,255,255;%
+yellow1,42,255,255;%
+yellow2,42,255,238;%
+yellow3,42,255,205;%
+yellow4,42,255,139;%
+yellowgreen,56,192,205} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/latexmarkup.dot b/graphics/dot2tex/examples/latexmarkup.dot
new file mode 100644
index 0000000000..af48930fda
--- /dev/null
+++ b/graphics/dot2tex/examples/latexmarkup.dot
@@ -0,0 +1,32 @@
+/*
+
+:Title: LaTeX markup
+:Tags: PGF
+
+*/
+digraph G {
+ node [fontcolor=red];
+ subgraph cluster0 {
+ node [style=filled,color=white, texmode=math];
+ style=filled;
+ color=lightgrey;
+ a_0 -> a_1 -> a_2 -> a_3;
+ label="latex";
+ texlbl="\LaTeX";
+ }
+ subgraph cluster1 {
+ node [style=filled, texmode=math, fontcolor=red];
+ b_0 -> b_1 -> b_2 -> b_3;
+ label = "process #2";
+ color=blue
+ }
+ start -> a_0;
+ start -> b_0;
+ a_1 -> b_3;
+ b_2 -> a_3;
+ a_3 -> a_0;
+ a_3 -> end;
+ b_3 -> end;
+ start [shape=diamond, texlbl="${\frac{\sqrt{\gamma+\beta}}{x^2+y^2}}$"];
+ end [shape=Msquare];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/pgfarrows.dot b/graphics/dot2tex/examples/pgfarrows.dot
new file mode 100644
index 0000000000..0a4e98d088
--- /dev/null
+++ b/graphics/dot2tex/examples/pgfarrows.dot
@@ -0,0 +1,27 @@
+/*
+
+:Title: PGF and TikZ arrows
+:Tags: PGF
+
+Examples of PGF/TikZ style arrows. See chapter 14.1 in the PGF/TikZ manual
+for all availale arrow styles.
+
+Generated with::
+
+ $ circo -Txdot pgfarrows.dot | dot2tex.py > pgfarrows.tex
+
+*/
+digraph G {
+ graph [mindist=0.5];
+ node [texmode="math", fixedsize=true, shape=circle, width=0.4, style="fill=green!20"];
+ c -> n_1 [style="-stealth", label="stealth"];
+ c -> n_2 [style="-to", label="to"];
+ c -> n_3 [style="-latex", label="latex"];
+ c -> n_4 [style="-diamond", label="diamond"];
+ c -> n_5 [style="-o", label="o"];
+ c -> n_6 [style="{-]}", label="]"];
+ c -> n_7 [style="-triangle 90", label="triangle 90"];
+ c -> n_8 [style="-hooks", label="hooks"];
+ c -> n_9 [style="->>", texmode="math", label=">>"];
+ c [style="fill=red!80"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/pgfsnakes.dot b/graphics/dot2tex/examples/pgfsnakes.dot
new file mode 100644
index 0000000000..9e2cd27f72
--- /dev/null
+++ b/graphics/dot2tex/examples/pgfsnakes.dot
@@ -0,0 +1,26 @@
+/*
+
+:Title: PGF snakes
+:Tags: PGF
+
+Examples of PGF/TikZ snake line styles. See chapter 14.2 in the PGF/TikZ
+manual for all availale snake styles. Note that the snake styles requires
+line operations, so you have to use the ``-s`` option.
+
+Generated with::
+
+ $ circo -Txdot pgfsnakes.dot | dot2tex.py -fpgf -s > pgfsnakes.tex
+
+*/
+graph G {
+ graph [mindist=0.5];
+ node [texmode="math", fixedsize=true, shape=circle, width=0.4, style="fill=green!20"];
+ c -- n_1 [style="snake=zigzag"];
+ c -- n_2 [style="snake=saw"];
+ c -- n_3 [style="snake=expanding waves, segment angle=10"];
+ c -- n_4 [style="snake=snake"];
+ c -- n_5 [style="snake=coil, segment amplitude=6pt"];
+ c -- n_6 [style="snake=brace"];
+ c -- n_7 [style="snake=triangles"];
+ c [style="fill=red!80"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/poltab.dot b/graphics/dot2tex/examples/poltab.dot
new file mode 100644
index 0000000000..e84a4a625e
--- /dev/null
+++ b/graphics/dot2tex/examples/poltab.dot
@@ -0,0 +1,33 @@
+/*
+
+:Tags: PGF, Preproc
+
+This example graph was contributed by Teresa Gomez-Diaz, and shows
+that the ``texlbl`` attriute can contain arbitrary LaTeX markup.
+
+Generated with::
+
+ $ dot2tex.py -tmath --preproc poltab.dot |dot2tex.py > poltab.tex
+
+
+*/
+digraph G {
+ rankdir=LR;
+ node [shape=plaintext];
+ a_1 [texlbl="$\begin{array}{l} \fbox{1}\fbox{1} \end{array}$"];
+ a_2 [texlbl="$\frac{1}{q} \begin{array}{l} \fbox{2}\fbox{1} \end{array} + \begin{array}{l} \fbox{1}\fbox{2} \end{array}$"];
+ a_3 [texlbl="$(q+\frac{1}{q}) \begin{array}{l} \fbox{2}\fbox{2} \end{array}$"];
+
+ a_4 [texlbl="$\frac{1}{q} \frac{1}{z_1} \begin{array}{l} \fbox{1}\fbox{2} \end{array} + \frac{1}{z_2}\begin{array}{l} \fbox{2}\fbox{1} \end{array}$"];
+
+ { rank=same; a_1; a_2; a_3;}
+ { nodesep =1; a_2; a_4;}
+
+ a_1 -> a_2 [label="f_1" ];
+ a_2 -> a_3 [label="f_1" ];
+ a_1 -> a_4 [label="f_0" dir=back];
+ a_3 -> a_4 [label="f_0" ];
+
+}
+
+
diff --git a/graphics/dot2tex/examples/pstarrows.dot b/graphics/dot2tex/examples/pstarrows.dot
new file mode 100644
index 0000000000..f3ede31de5
--- /dev/null
+++ b/graphics/dot2tex/examples/pstarrows.dot
@@ -0,0 +1,25 @@
+/*
+:Title: PSTricks arrows
+:Tags: PSTricks
+
+Examples of Pstricks style arrows.
+To generate this graph you can write::
+
+ $ circo -Txdot pstarrows.dot | dot2tex.py -fpst > pstarrows.tex
+
+*/
+digraph G {
+ d2tdocpreamble="\usepackage{pstricks-add}";
+ graph [mindist=0.5];
+ node [texmode="math", fixedsize=true, shape=circle, width=0.4, style="linecolor=red, fillcolor=white"];
+ edge [color="blue"];
+ c -> n_1 [style="arrows=->", texmode="math", label=">"];
+ c -> n_2 [style="arrows=->>", texmode="math", label=">>"];
+ c -> n_3 [style="arrows=-<", texmode="math", label="<"];
+ c -> n_4 [style="arrows=-*", texmode="math", label="*"];
+ c -> n_5 [style="arrows=-{]}", texmode="math", label="]"];
+ edge [color="red"];
+ c -> n_6 [style="arrows=-o", texmode="math", label="o"];
+ c -> n_7 [style="arrows=-H", texmode="math", label="H"];
+ c -> n_8 [style="arrows=->, nArrowsA=5", texmode="math"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/showpoints.dot b/graphics/dot2tex/examples/showpoints.dot
new file mode 100644
index 0000000000..a84d24d05b
--- /dev/null
+++ b/graphics/dot2tex/examples/showpoints.dot
@@ -0,0 +1,89 @@
+/*
+:Title: Control points
+:Tags: PSTricks
+
+This example uses the ``showpoints`` PSTricks style to show the
+control points of the edge curves.
+
+Generated with::
+
+ $ dot2tex.py -fpst showpoints.dot > showpoints.tex
+
+
+*/
+digraph G {
+ size = "8,8";
+ {rank=min S8 S24 S1 S35 S30}
+ {rank=max T8 T24 T1 T35 T30}
+ edge [style="showpoints=true, linecolor=red"];
+ node [style="fillstyle=solid"];
+ S8 -> 9;
+ S24 -> 27;
+ S24 -> 25;
+ S1 -> 10;
+ S1 -> 2;
+ S35 -> 36;
+ S35 -> 43;
+ S30 -> 31;
+ S30 -> 33;
+ 9 -> 42;
+ 9 -> T1;
+ 25 -> T1;
+ 25 -> 26;
+ 27 -> T24;
+ 2 -> 3;
+ 2 -> 16;
+ 2 -> 17;
+ 2 -> T1;
+ 2 -> 18;
+ 10 -> 11;
+ 10 -> 14;
+ 10 -> T1;
+ 10 -> 13;
+ 10 -> 12;
+ 31 -> T1;
+ 31 -> 32;
+ 33 -> T30;
+ 33 -> 34;
+ 42 -> 4;
+ 26 -> 4;
+ 3 -> 4;
+ 16 -> 15;
+ 17 -> 19;
+ 18 -> 29;
+ 11 -> 4;
+ 14 -> 15;
+ 37 -> 39;
+ 37 -> 41;
+ 37 -> 38;
+ 37 -> 40;
+ 13 -> 19;
+ 12 -> 29;
+ 43 -> 38;
+ 43 -> 40;
+ 36 -> 19;
+ 32 -> 23;
+ 34 -> 29;
+ 39 -> 15;
+ 41 -> 29;
+ 38 -> 4;
+ 40 -> 19;
+ 4 -> 5;
+ 19 -> 21;
+ 19 -> 20;
+ 19 -> 28;
+ 5 -> 6;
+ 5 -> T35;
+ 5 -> 23;
+ 21 -> 22;
+ 20 -> 15;
+ 28 -> 29;
+ 6 -> 7;
+ 15 -> T1;
+ 22 -> 23;
+ 22 -> T35;
+ 29 -> T30;
+ 7 -> T8;
+ 23 -> T24;
+ 23 -> T1;
+}
diff --git a/graphics/dot2tex/examples/subgraphs.dot b/graphics/dot2tex/examples/subgraphs.dot
new file mode 100644
index 0000000000..4d9f1b023c
--- /dev/null
+++ b/graphics/dot2tex/examples/subgraphs.dot
@@ -0,0 +1,47 @@
+/*
+:Title: Styled subgraphs
+:Tags: PGF, Preproc
+
+This example shows how subgraphs can be styled using PGF/TikZ styles.
+Note that version 1.09 or higher of PGF/TikZ is required.
+
+Generated with::
+
+ $ dot2tex.py -tmath --preproc subgraphs.dot | dot2tex.py --crop > subgraphs.tex
+
+*/
+digraph G {
+ d2tdocpreamble="\usetikzlibrary{patterns}";
+ size="6,6";
+ node [style="fill=blue!40"];
+ node [shape=circle, width=0.4];
+ a -> b -> c;
+ graph [style="rounded corners, shade"];
+
+ subgraph cluster0 {
+ graph [style="pattern color=red, pattern=bricks, rounded corners"];
+ node [style = "fill=blue, semitransparent"];
+ x_0 -> y_0;
+ x_0 -> z_0;
+ }
+
+ subgraph cluster1 {
+ graph [style="snake=snake, fill=green!20"];
+ node [style = "fill=red!20"];
+ edge [style="->>"];
+ x_1 -> y_1;
+ x_1 -> z_1;
+ }
+
+ subgraph cluster2 {
+ node [style=" "];
+ x_2 -> y_2;
+ x_2 -> z_2;
+ }
+
+ a -> x_0;
+ b -> x_1;
+ b -> x_2;
+ a -> z_2;
+ c -> z_1;
+}
diff --git a/graphics/dot2tex/examples/tank.dot b/graphics/dot2tex/examples/tank.dot
new file mode 100644
index 0000000000..059b663523
--- /dev/null
+++ b/graphics/dot2tex/examples/tank.dot
@@ -0,0 +1,47 @@
+/*
+
+:Title: Two tank system
+:Tags: PGF
+
+This graph shows the structural model of a two tank system.
+
+Generated with::
+
+ $ dot2tex.py -fpgf tank.dot > tank.tex
+
+*/
+graph G {
+ node[shape=doublecircle, fixedsize=true, width=0.4];
+ graph [style="rounded corners"];
+ subgraph cluster0 {
+ style = "red, fill=blue!20,rounded corners";
+ label = "Tank 1";
+ node [texmode="math"]
+ c_1--q_L; c_1--h_1;
+ c_2--q_P; c_2--h_1;
+ c_3--q_L; c_3--q_P; c_3--dh_1;
+ d_4--dh_1;d_4--h_1;
+ dh_1 [label="\\dot{h}_1"];
+ }
+
+ subgraph cluster1{
+ label = "Pipe";
+ node [texmode="math"]
+ c_5--h_1; c_5--q_12;
+ q_12 [label="q_{12}"];
+ }
+
+ c_5--h_2;
+ c_3--q_12;
+ c_6--q_12;
+
+ subgraph cluster2{
+ label = "Tank 2";
+ node [texmode="math"]
+ c_6--dh_2;c_6--q_2;
+ d_7--dh_2; d_7--h_2;
+ c_8--h_2;c_8--q_2;
+ c_m--q_2;
+ dh_2 [label="\\dot{h}_2"];
+ }
+}
diff --git a/graphics/dot2tex/examples/tikzautomata.dot b/graphics/dot2tex/examples/tikzautomata.dot
new file mode 100644
index 0000000000..1e0937ff45
--- /dev/null
+++ b/graphics/dot2tex/examples/tikzautomata.dot
@@ -0,0 +1,34 @@
+/*
+
+:Title: Automata
+:Tags: TikZ, topath, tikzedgelabels
+
+An example of how to use TikZ' automata libray and to paths to
+create a pretty state machine.
+
+Generated with::
+
+ $ neato -Txdot tikzautomata.dot | dot2tex.py -ftikz > tikzautomata.tex
+
+*/
+digraph G {
+ d2ttikzedgelabels = true;
+ d2tstyleonly = true;
+ d2tdocpreamble = "\usetikzlibrary{automata}";
+ d2tfigpreamble = "\tikzstyle{every state}= \
+ [draw=blue!50,very thick,fill=blue!20]";
+ node [style="state"];
+ edge [lblstyle="auto",topath="bend left"];
+ A [style="state, initial"];
+ A -> B [label=2];
+ A -> D [label=7];
+ B -> A [label=1];
+ B -> B [label=3,topath="loop above"];
+ B -> C [label=4];
+ C -> F [label=5];
+ F -> B [label=8];
+ F -> D [label=7];
+ D -> E [label=2];
+ E -> A [label="1,6"];
+ F [style="state,accepting"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/tikzshapes.dot b/graphics/dot2tex/examples/tikzshapes.dot
new file mode 100644
index 0000000000..0211539b9d
--- /dev/null
+++ b/graphics/dot2tex/examples/tikzshapes.dot
@@ -0,0 +1,38 @@
+/*
+
+:Title: TikZ node shapes
+:Tags: TikZ, tikzedgelabels
+
+This example shows some of special `TikZ node shapes`_ that are available when using
+the ``tikz`` output format.
+
+Generated with::
+
+ $ circo -Txdot tikzshapes.dot | dot2tex.py -ftikz -s > tikzshapes.tex
+
+
+.. _TikZ node shapes: http://www.fauskes.net/pgftikzexamples/node-shapes/
+
+*/
+graph G {
+ graph [mindist=0.5];
+ node [style="fill=green!20",texmode=math];
+ edge [lblstyle="above,sloped"];
+ d2ttikzedgelabels=true;
+ c [shape=circle];
+ n_1 [shape=diamond];
+ n_2 [shape=star];
+ n_3 [shape="forbidden sign"];
+ n_4 [shape="circle split", texlbl="$n$ \nodepart{lower} $4$"];
+ n_5 [shape="cross out"];
+ n_6 [shape="strike out"];
+ n_7 [shape="regular polygon,regular polygon sides=7"];
+ c -- n_1 [label="diamond"];
+ c -- n_2 [label="star"];
+ c -- n_3 [label="forbidden sign"];
+ c -- n_4 [label="circle split"];
+ c -- n_5 [label="cross out"];
+ c -- n_6 [label="strike out"];
+ c -- n_7 [label="regular polygon"];
+ c [style="fill=red!80"];
+} \ No newline at end of file
diff --git a/graphics/dot2tex/examples/transp.dot b/graphics/dot2tex/examples/transp.dot
new file mode 100644
index 0000000000..8b39ea2bd5
--- /dev/null
+++ b/graphics/dot2tex/examples/transp.dot
@@ -0,0 +1,118 @@
+/*
+
+:Title: Node transparency
+:Tags: PGF
+
+Example of node transparency.
+Based on the graph on http://www.graphviz.org/Gallery/undirected/transparency.html
+
+The overlapping nodes are achieved with::
+
+ $ neato -Txdot transp.dot | dot2tex.py -fpgf > transp.tex
+
+*/
+graph G {
+ node [style=filled, fillcolor="#00ff005f"]
+ 1 -- 30 [f=1];
+ 1 -- 40 [f=14];
+ 8 -- 46 [f=1];
+ 8 -- 16 [f=18];
+ 10 -- 25 [f=1];
+ 10 -- 19 [f=5];
+ 10 -- 33 [f=1];
+ 12 -- 8 [f=1];
+ 12 -- 36 [f=5];
+ 12 -- 17 [f=16];
+ 13 -- 38 [f=1];
+ 13 -- 24 [f=19];
+ 24 -- 49 [f=1];
+ 24 -- 13 [f=1];
+ 24 -- 47 [f=12];
+ 24 -- 12 [f=19];
+ 25 -- 27 [f=1];
+ 25 -- 12 [f=1];
+ 27 -- 12 [f=1];
+ 27 -- 14 [f=8];
+ 29 -- 10 [f=1];
+ 29 -- 8 [f=17];
+ 30 -- 24 [f=1];
+ 30 -- 44 [f=15];
+ 38 -- 29 [f=1];
+ 38 -- 35 [f=15];
+ 2 -- 42 [f=2];
+ 2 -- 35 [f=3];
+ 2 -- 11 [f=19];
+ 14 -- 18 [f=2];
+ 14 -- 24 [f=15];
+ 14 -- 38 [f=18];
+ 18 -- 49 [f=2];
+ 18 -- 47 [f=20];
+ 26 -- 41 [f=2];
+ node [style=filled fillcolor="#ff00005f"]
+ 26 -- 42 [f=15];
+ 31 -- 39 [f=2];
+ 31 -- 47 [f=17];
+ 31 -- 25 [f=14];
+ 37 -- 26 [f=2];
+ 37 -- 16 [f=14];
+ 39 -- 50 [f=2];
+ 39 -- 14 [f=2];
+ 39 -- 18 [f=17];
+ 39 -- 47 [f=10];
+ 41 -- 31 [f=2];
+ 41 -- 8 [f=16];
+ 42 -- 44 [f=2];
+ 42 -- 29 [f=12];
+ 44 -- 37 [f=2];
+ 44 -- 32 [f=15];
+ 3 -- 20 [f=2];
+ 3 -- 28 [f=19];
+ 6 -- 45 [f=2];
+ 6 -- 28 [f=10];
+ 9 -- 6 [f=2];
+ 9 -- 16 [f=1];
+ node [style=filled fillcolor="#0000ff5f"]
+ 15 -- 16 [f=2];
+ 15 -- 48 [f=2];
+ 16 -- 50 [f=2];
+ 16 -- 32 [f=14];
+ 16 -- 39 [f=8];
+ 20 -- 33 [f=2];
+ 33 -- 9 [f=2];
+ 33 -- 46 [f=3];
+ 33 -- 48 [f=17];
+ 45 -- 15 [f=2];
+ 4 -- 17 [f=4];
+ 4 -- 15 [f=6];
+ 4 -- 12 [f=16];
+ 17 -- 21 [f=4];
+ 19 -- 35 [f=4];
+ 19 -- 15 [f=9];
+ 19 -- 43 [f=4];
+ 21 -- 19 [f=4];
+ 21 -- 50 [f=4];
+ 23 -- 36 [f=4];
+ 34 -- 23 [f=4];
+ 34 -- 24 [f=11];
+ 35 -- 34 [f=4];
+ 35 -- 16 [f=6];
+ 35 -- 18 [f=16];
+ 36 -- 46 [f=4];
+ 5 -- 7 [f=1];
+ 5 -- 36 [f=6];
+ 7 -- 32 [f=1];
+ 7 -- 11 [f=2];
+ 7 -- 14 [f=17];
+ 11 -- 40 [f=1];
+ 11 -- 50 [f=1];
+ 22 -- 46 [f=1];
+ 28 -- 43 [f=1];
+ 28 -- 8 [f=18];
+ 32 -- 28 [f=1];
+ 32 -- 39 [f=13];
+ 32 -- 42 [f=15];
+ 40 -- 22 [f=1];
+ 40 -- 47 [f=1];
+ 43 -- 11 [f=1];
+ 43 -- 17 [f=19];
+}
diff --git a/graphics/dot2tex/setup.py b/graphics/dot2tex/setup.py
new file mode 100644
index 0000000000..56c048ffc4
--- /dev/null
+++ b/graphics/dot2tex/setup.py
@@ -0,0 +1,50 @@
+from distutils.core import setup
+
+setup(name='dot2tex',
+ version='2.7.0',
+ description = 'A Graphviz to LaTeX converter',
+ long_description="""\
+The purpose of dot2tex is to give graphs generated by the graph layout tool
+Graphviz_, a more LaTeX friendly look and feel. This is accomplished by:
+
+- Using native PSTricks_ and `PGF/TikZ`_ commands for drawing arrows,
+ edges and nodes.
+- Typesetting labels with LaTeX, allowing mathematical notation.
+- Using backend specific styles to customize the output.
+
+.. _Graphviz: http://www.graphviz.org/
+.. _PSTricks: http://tug.org/PSTricks/main.cgi/
+.. _PGF/TikZ: http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html
+""",
+ author = 'Kjell Magne Fauske',
+ author_email = 'kjellmf@gmail.com',
+ url = "http://www.fauskes.net/code/dot2tex/",
+ download_url = "http://www.fauskes.net/code/dot2tex/download/",
+ py_modules = ['dot2tex.dot2tex'],
+ scripts=['dot2tex/dot2tex'],
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Console',
+ 'Intended Audience :: Science/Research',
+ 'License :: OSI Approved :: MIT License',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Scientific/Engineering :: Visualization',
+ 'Topic :: Text Processing :: Markup :: LaTeX',
+ 'Topic :: Utilities',
+ ],
+ install_requires = ['pyparsing','pydot'],
+ # easy_install does not manage to install pyparsing from pypi,
+ # so we have to provide the correct download link.
+ dependency_links = [
+ "http://sourceforge.net/project/showfiles.php?group_id=97203",
+ "http://code.google.com/p/pydot/downloads/list"
+ ],
+ entry_points = {
+ 'console_scripts': [
+ 'dot2tex = dot2tex.dot2tex:main',
+ ]
+
+ }
+) \ No newline at end of file