=======================================
dot2tex - A Graphviz to LaTeX converter
=======================================

:Author: Kjell Magne Fauske
:Version: 2.0.3
: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/


Usage
=====

Syntax::

    dot2tex.py [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 try to convert an input file in the plain dot format to this format, but it is recommended to feed xdot data directly to dot2tex due to some limitations in the pydot_ module.

.. _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.py > test.tex
    $ neato -Txdot -Gstart=rand test.dot | dot2tex.py > test.tex

Load ``test.dot``, convert it to xdot format and output the resulting graph using PGF/TikZ to ``testpgf.tex``::

    $ dot2tex.py -fpgf test.dot > testpgf.tex

.. note:: Windows users you have to type ``python dot2tex.py`` to invoke the program.
   If you find this annoying, try the `ExeMaker`_ tool from `effbot.org`_.

   .. _ExeMaker: http://effbot.org/zone/exemaker.htm
   .. _effbot.org: http://effbot.org


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/TikZ output format.

--figonly
    Output the graph without a document preamble. Useful if the graph is to be included in a master document.

--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_.

--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.

--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.


--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 and TikZ
------------

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
----

**Not implemented yet**. This purpose of the TikZ output format is to use TikZ' node and edge commands, instead of relying on the xdot draw commands. This will allow tighter integration with PGF/TikZ and better visual results.

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. If a ``texlbl`` attribute is found, it will be used regardless of the current text mode.

.. 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.py -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;d
    }

.. 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.py --preproc ex4.dot | dot2tex.py > ex4.tex

gives correctly sized nodes:

.. figure:: img/texmodeb.png
   :alt: Preprocessing the graph to get correct node sizes.


Preprocessing the graph
-----------------------

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`` 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 that 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.py -tmath --preproc example.dot > exampletmp.dot
    $ dot2tex.py exampletmp.dot > example.tex

You can also chain the commands::

    $ dot2tex.py -tmath --preproc example.dot | dot2tex.py > 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.py -tmath --preproc example.dot | dot2tex.py > 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.py -tmath --preproc --nominwidth example.dot | dot2tex.py > 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


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.py valign.dot

.. figure:: img/valignmode0.png
   :alt: blabla

To get the same vertical alignment for both nodes, you can use::

    $ dot2tex.py --valignmode=dot valign.dot

.. figure:: img/valignmode1.png
   :alt: blabla

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.py --valignmode=dot --graphstyle="anchor=base" valign.dot

PSTricks users have to use the ``--alingstr`` option::

    $ dot2tex.py --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



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.


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.py -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.py -fpgf > 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.py -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"];
        c -> n_8 [style="arrows=->];
    }

Rendered with::

    $ circo -Txdot pstarrows.dot | dot2tex.py -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.py -fpst --docpreamble="\usepackage{pstricks-add}" ...




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 `-t` 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.

``style``
  Used to pass styles to the backend. Styles are output format specific, with the exception of the styles defined by the DOT language.

``d2talignstr``
  Used to pass a default alignment string to the PSTricks ``\rput`` command::

    \rput[d2talignstr] ...




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.py -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.

To increase the font size you can for instance insert a ``\Huge`` command in the figure preamble::

    $ dot2tex.py -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.py --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.py --preproc -tmath --nominsize ex1.dot > ex1tmp.dot

Running through dot2tex again with::

    $ dot2tex.py figpreamble="\Huge" ex1tmp.dot > ex1huge.tex

gives labels that do not fit inside the nodes.

.. figure:: img/consistent.png
   :alt: Inconsistence between preproc mode and output mode.




