Introducing dot2texi: Create graphs within LaTeX using dot2tex

  • Published 2007-11-12 (7 months, 3 weeks ago)

The dot2texi package is a LaTeX package for embedding graphs in the DOT graphs description language directly in your LaTeX file. Graphs are created within the special dot2tex environment. When compiling the document the following will happen:

  1. The content of the dot2tex environments are written to file.
  2. dot2tex is run on the saved files.
  3. The generated code is included in the document and rendered.

The above process is completely automated if write18 or shell escape is enabled when running TeX.

The main advantage of using dot2texi is that you can keep everything within your document. No need to keep graphs in separate files. It is also easy to keep a consistent look and feel.

Here is a simple example

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

To generate the graph you have to run LaTeX with shell escape enabled since dot2tex is called in the background:

$ pdflatex --shell-escape graphdemo.tex
""

The package is available on CTAN. See the documentation for more details.

Acknowledgements

The package is based on the dottex and gnuplottex packages wirtten by Lars Kotthoff. He has done most of the heavy lifting. I have just adapted the code for use with dot2tex.

Comments

  • #1 Jay A. Patel, November 13, 2007 at 6:04 a.m.

    Hi,

    I was intending to use your dot2tex.py script, when I ran into the doc2texi.sty package released today. Wow, talk about good timing.

    Anyway, I am a complete novice when it comes to LaTeX (well, I know how to use it to a very limited extent -- but nothing about writing my own .sty files). So, I am not able to do much more then report a "bug".

    I am using Ubuntu 7.04 w/ pdfeTeX 3.141592-1.21a-2.2 (Web2C 7.5.4):

    I get this problem when trying to compile docgraphs.tex in the examples/ directory:

    ---------------------
    ! Undefined control sequence.
    l.130 \define@choicekey
                           *{dtt}{prog}[\progval\nr]{dot,neato,circo,fdp,twopi}[...
    

    Any clue why LaTeX is choking on that particular line of the doc2texi.sty file? Is this something on my end only? If so, can you mention a quick fix?

    Thanks for all your contributions to the LaTeX universe.

    Cheers, Jay.

  • #2 Kjell Magne Fauske, November 13, 2007 at 8:49 a.m.

    @Jay Thank you for your interest in using dot2texi. From your error message it seems that your system chokes on a command from the xkeyval package. My first guess is that you may have an old version of xkeyval installed. Choicekeys were added in version 2.3. The current version is 2.5.f. You'll find this information in the log file.

    For debugging purposes I recommend trying the minimal example from the manual. The docgraphs example uses for instance the preview package. That may complicate things.

Post a comment

Markdown syntax enabled

(required)

(required, but will not be published)