320
320
<p>Users have reported problems using dot2tex with old versions of pyparsing and Graphviz.</p>
321
321
<p>Dot2tex was developed and tested using <a class="reference external" href="http://www.python.org">Python</a> 2.4. However, dot2tex will probably run fine using Python 2.3.</p>
323
<div class="section" id="installation">
324
<h2>Installation</h2>
325
<div class="section" id="from-source">
327
<p>Download a zip or a tarball from the <a class="reference external" href="http://www.fauskes.net/code/dot2tex/download/">download</a> page. It is also available on <a class="reference external" href="http://www.ctan.org/tex-archive/help/Catalogue/entries/dot2tex.html">CTAN</a>. Unpack the file to a directory and run <tt class="docutils literal"><span class="pre">python</span></tt> on the <tt class="docutils literal"><span class="pre">setup.py</span></tt> file:</p>
328
<pre class="literal-block">
329
$ python setup.py install
331
<p>This will create a dot2tex module in your Python module directory and a wrapper script in your <tt class="docutils literal"><span class="pre">SCRIPTS</span></tt> 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 <tt class="docutils literal"><span class="pre">setup.py</span></tt> file that distutils does not understand.</p>
333
<div class="section" id="using-easy-install">
334
<h3>Using easy_install</h3>
335
<p>The easiest way to install dot2tex is to use <a class="reference external" href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a>:</p>
336
<pre class="literal-block">
337
$ easy_install dot2tex
339
<p>The command will locate dot2tex and download it automatically. Note that documentation and examples are not installed by default. <a class="reference external" href="http://peak.telecommunity.com/DevCenter/EasyInstall">Easy_install</a> will also create a wrapper script or EXE file for you and install dependencies if necessary.</p>
341
<div class="section" id="binary-packages">
342
<h3>Binary packages</h3>
343
<p>Binary packages are available for <a class="reference external" href="http://packages.qa.debian.org/d/dot2tex.html">Debian</a> and <a class="reference external" href="http://download.opensuse.org/repositories/home:/jimfunk/">OpenSUSE</a>.</p>
345
<div class="section" id="development-version">
346
<h3>Development version</h3>
347
<p>The development version of <tt class="docutils literal"><span class="pre">dot2tex</span></tt> is available from a <a class="reference external" href="http://code.google.com/p/dot2tex/source">Subversion repository</a> hosted at Google code. To get the code you can use the following command:</p>
348
<pre class="literal-block">
349
svn checkout http://dot2tex.googlecode.com/svn/trunk/ dot2tex
323
353
<div class="section" id="usage">
539
572
<li>Labels will fit inside nodes without preprocessing.</li>
540
573
<li>Full access to the power of PGF and TikZ.</li>
575
<p>You can find more details in the section: <a class="reference internal" href="#use-the-tikz-output-format-for-maximum-flexibility">Use the tikz output format for maximum flexibility</a>.</p>
542
576
<div class="note">
543
577
<p class="first admonition-title">Note</p>
544
578
<p class="last">The <tt class="docutils literal"><span class="pre">tikz</span></tt> output format requires detailed knowledge of the PGF and TikZ package. Some of Graphviz' features will not work with this output format.</p>
547
The difference between the ``pgf`` and ``tikz`` output formats is best shown with an example. Consider the following graph:
557
Rendering the graph using ``circo`` and the ``pgf`` and ``tikz`` output formats::
559
$ circo -Txdot simple.dot | dot2tex -tmath -fpgf -s
560
$ circo -Txdot simple.dot | dot2tex -tmath -ftikz -s
562
gives visually different graphs:
564
.. figure:: img/pgftikzsimple.png
565
:alt: Difference between pgf and tikz output format
567
However, the main difference is in the generated code. Here is the ``pgf`` output:
569
.. sourcecode:: latex
572
\draw [] (19bp,38bp) - - (19bp,60bp);
574
\draw [] (35bp,70bp) - - (55bp,58bp);
576
\draw [] (55bp,40bp) - - (35bp,28bp);
579
\pgfsetstrokecolor{black}
580
\draw (19bp,19bp) ellipse (18bp and 19bp);
581
\draw (19bp,19bp) node {$a$};
585
\pgfsetstrokecolor{black}
586
\draw (19bp,79bp) ellipse (18bp and 19bp);
587
\draw (19bp,79bp) node {$b$};
591
\pgfsetstrokecolor{black}
592
\draw (71bp,49bp) ellipse (18bp and 19bp);
593
\draw (71bp,49bp) node {$c$};
596
Compare the above code with the ``tikz`` output:
598
.. sourcecode:: latex
600
\node (a) at (19bp,19bp) [draw,circle,] {$a$};
601
\node (b) at (19bp,79bp) [draw,circle,] {$b$};
602
\node (c) at (71bp,49bp) [draw,circle,] {$c$};
603
\draw [] (a) - - (b);
604
\draw [] (b) - - (c);
605
\draw [] (c) - - (a);
607
The code is much more compact and it is quite easy to modify the graph. -->
610
582
<div class="section" id="labels">
1303
<div class="section" id="use-the-tikz-output-format-for-maximum-flexibility">
1304
<h3>Use the tikz output format for maximum flexibility</h3>
1305
<p>The difference between the <tt class="docutils literal"><span class="pre">pgf</span></tt> and <tt class="docutils literal"><span class="pre">tikz</span></tt> output formats is best shown with an example. Consider the following graph:</p>
1306
<div class="highlight"><pre>graph G {
1308
node [shape=circle];
1312
<p>Rendering the graph using <tt class="docutils literal"><span class="pre">circo</span></tt> and the <tt class="docutils literal"><span class="pre">pgf</span></tt> and <tt class="docutils literal"><span class="pre">tikz</span></tt> output formats:</p>
1313
<pre class="literal-block">
1314
$ circo -Txdot simple.dot | dot2tex -tmath -fpgf -s
1315
$ circo -Txdot simple.dot | dot2tex -tmath -ftikz -s
1317
<p>gives visually different graphs:</p>
1318
<div class="figure">
1319
<img alt="Difference between pgf and tikz output format" src="img/pgftikzsimple.png" />
1321
<p>However, the main difference is in the generated code. Here is the <tt class="docutils literal"><span class="pre">pgf</span></tt> output:</p>
1322
<div class="highlight"><pre><span class="c">% Edge: a -- b</span>
1323
<span class="k">\draw</span> [] (19bp,38bp) -- (19bp,60bp);
1324
<span class="c">% Edge: b -- c</span>
1325
<span class="k">\draw</span> [] (35bp,70bp) -- (55bp,58bp);
1326
<span class="c">% Edge: c -- a</span>
1327
<span class="k">\draw</span> [] (55bp,40bp) -- (35bp,28bp);
1328
<span class="c">% Node: a</span>
1329
<span class="k">\begin</span><span class="nb">{</span>scope<span class="nb">}</span>
1330
<span class="k">\pgfsetstrokecolor</span><span class="nb">{</span>black<span class="nb">}</span>
1331
<span class="k">\draw</span> (19bp,19bp) ellipse (18bp and 19bp);
1332
<span class="k">\draw</span> (19bp,19bp) node <span class="nb">{</span><span class="s">$</span><span class="nb">a</span><span class="s">$</span><span class="nb">}</span>;
1333
<span class="k">\end</span><span class="nb">{</span>scope<span class="nb">}</span>
1334
<span class="c">% Node: b</span>
1335
<span class="k">\begin</span><span class="nb">{</span>scope<span class="nb">}</span>
1336
<span class="k">\pgfsetstrokecolor</span><span class="nb">{</span>black<span class="nb">}</span>
1337
<span class="k">\draw</span> (19bp,79bp) ellipse (18bp and 19bp);
1338
<span class="k">\draw</span> (19bp,79bp) node <span class="nb">{</span><span class="s">$</span><span class="nb">b</span><span class="s">$</span><span class="nb">}</span>;
1339
<span class="k">\end</span><span class="nb">{</span>scope<span class="nb">}</span>
1340
<span class="c">% Node: c</span>
1341
<span class="k">\begin</span><span class="nb">{</span>scope<span class="nb">}</span>
1342
<span class="k">\pgfsetstrokecolor</span><span class="nb">{</span>black<span class="nb">}</span>
1343
<span class="k">\draw</span> (71bp,49bp) ellipse (18bp and 19bp);
1344
<span class="k">\draw</span> (71bp,49bp) node <span class="nb">{</span><span class="s">$</span><span class="nb">c</span><span class="s">$</span><span class="nb">}</span>;
1345
<span class="k">\end</span><span class="nb">{</span>scope<span class="nb">}</span>
1347
<p>Compare the above code with the <tt class="docutils literal"><span class="pre">tikz</span></tt> output:</p>
1348
<div class="highlight"><pre><span class="k">\node</span> (a) at (19bp,19bp) [draw,circle,] <span class="nb">{</span><span class="s">$</span><span class="nb">a</span><span class="s">$</span><span class="nb">}</span>;
1349
<span class="k">\node</span> (b) at (19bp,79bp) [draw,circle,] <span class="nb">{</span><span class="s">$</span><span class="nb">b</span><span class="s">$</span><span class="nb">}</span>;
1350
<span class="k">\node</span> (c) at (71bp,49bp) [draw,circle,] <span class="nb">{</span><span class="s">$</span><span class="nb">c</span><span class="s">$</span><span class="nb">}</span>;
1351
<span class="k">\draw</span> [] (a) -- (b);
1352
<span class="k">\draw</span> [] (b) -- (c);
1353
<span class="k">\draw</span> [] (c) -- (a);
1355
<p>The code is much more compact and it is quite easy to modify the graph.</p>
1357
<div class="section" id="the-dot2texi-latex-package">
1358
<h3>The dot2texi LaTeX package</h3>
1359
<p>The dot2texi package allows you to embed DOT graphs directly in you LaTeX document. The package will automatically run <tt class="docutils literal"><span class="pre">dot2tex</span></tt> for you and include the generated code. Example:</p>
1360
<div class="highlight"><pre><span class="k">\documentclass</span><span class="nb">{</span>article<span class="nb">}</span>
1361
<span class="k">\usepackage</span><span class="nb">{</span>dot2texi<span class="nb">}</span>
1363
<span class="k">\usepackage</span><span class="nb">{</span>tikz<span class="nb">}</span>
1364
<span class="k">\usetikzlibrary</span><span class="nb">{</span>shapes,arrows<span class="nb">}</span>
1366
<span class="k">\begin</span><span class="nb">{</span>document<span class="nb">}</span>
1367
<span class="k">\begin</span><span class="nb">{</span>dot2tex<span class="nb">}</span>[neato,options=-tmath]
1368
digraph G <span class="nb">{</span>
1369
node [shape="circle"];
1370
a<span class="nb">_</span>1 -> a<span class="nb">_</span>2 -> a<span class="nb">_</span>3 -> a<span class="nb">_</span>4 -> a<span class="nb">_</span>1;
1371
<span class="nb">}</span>
1372
<span class="k">\end</span><span class="nb">{</span>dot2tex<span class="nb">}</span>
1374
<span class="k">\end</span><span class="nb">{</span>document<span class="nb">}</span>
1376
<p>When the above code is run through LaTeX, the following will happen is shell escape is enabled:</p>
1378
<li>The graph is written to file.</li>
1379
<li><tt class="docutils literal"><span class="pre">dot2tex</span></tt> is run on the DOT file.</li>
1380
<li>The generated code is included in the document.</li>
1382
<p>The whole process is completely automated. The generated graph will look like this:</p>
1383
<div class="figure">
1384
<img alt="Graph generated with dot2texi" src="img/dot2texiex1.png" />
1386
<p>The <tt class="docutils literal"><span class="pre">codeonly</span></tt> option is useful in conjunction with <tt class="docutils literal"><span class="pre">dot2texi</span></tt>, especially when used with the <tt class="docutils literal"><span class="pre">tikz</span></tt> output format. Here is an example that shows how to annotate a graph:</p>
1387
<div class="highlight"><pre><span class="k">\documentclass</span><span class="nb">{</span>article<span class="nb">}</span>
1388
<span class="k">\usepackage</span><span class="nb">{</span>tikz<span class="nb">}</span>
1389
<span class="k">\usetikzlibrary</span><span class="nb">{</span>arrows,shapes<span class="nb">}</span>
1390
<span class="k">\usepackage</span><span class="nb">{</span>dot2texi<span class="nb">}</span>
1391
<span class="k">\begin</span><span class="nb">{</span>document<span class="nb">}</span>
1392
<span class="c">% Define layers</span>
1393
<span class="k">\pgfdeclarelayer</span><span class="nb">{</span>background<span class="nb">}</span>
1394
<span class="k">\pgfdeclarelayer</span><span class="nb">{</span>foreground<span class="nb">}</span>
1395
<span class="k">\pgfsetlayers</span><span class="nb">{</span>background,main,foreground<span class="nb">}</span>
1397
<span class="c">% The scale option is useful for adjusting spacing between nodes.</span>
1398
<span class="c">% Note that this works best when straight lines are used to connect</span>
1399
<span class="c">% the nodes.</span>
1400
<span class="k">\begin</span><span class="nb">{</span>tikzpicture<span class="nb">}</span>[>=latex',scale=0.8]
1401
<span class="c">% set node style</span>
1402
<span class="k">\tikzstyle</span><span class="nb">{</span>n<span class="nb">}</span> = [draw,shape=circle,minimum size=2em,
1403
inner sep=0pt,fill=red!20]
1404
<span class="k">\begin</span><span class="nb">{</span>dot2tex<span class="nb">}</span>[dot,tikz,codeonly,styleonly,options=-s -tmath]
1405
digraph G <span class="nb">{</span>
1406
node [style="n"];
1407
A<span class="nb">_</span>1 -> B<span class="nb">_</span>1; A<span class="nb">_</span>1 -> B<span class="nb">_</span>2; A<span class="nb">_</span>1 -> B<span class="nb">_</span>3;
1408
B<span class="nb">_</span>1 -> C<span class="nb">_</span>1; B<span class="nb">_</span>1 -> C<span class="nb">_</span>2;
1409
B<span class="nb">_</span>2 -> C<span class="nb">_</span>2; B<span class="nb">_</span>2 -> C<span class="nb">_</span>3;
1410
B<span class="nb">_</span>3 -> C<span class="nb">_</span>3; B<span class="nb">_</span>3 -> C<span class="nb">_</span>4;
1411
<span class="nb">}</span>
1412
<span class="k">\end</span><span class="nb">{</span>dot2tex<span class="nb">}</span>
1413
<span class="c">% annotations</span>
1414
<span class="k">\node</span><span class="na">[left=1em]</span> at (C<span class="nb">_</span>1.west) (l3) <span class="nb">{</span>Level 3<span class="nb">}</span>;
1415
<span class="k">\node</span> at (l3 |- B<span class="nb">_</span>1) (l2)<span class="nb">{</span>Level 2<span class="nb">}</span>;
1416
<span class="k">\node</span> at (l3 |- A<span class="nb">_</span>1) (l1) <span class="nb">{</span>Level 1<span class="nb">}</span>;
1417
<span class="c">% Draw lines to separate the levels. First we need to calculate</span>
1418
<span class="c">% where the middle is.</span>
1419
<span class="k">\path</span> (l3) -- coordinate (l32) (l2) -- coordinate (l21) (l1);
1420
<span class="k">\draw</span><span class="na">[dashed]</span> (C<span class="nb">_</span>1 |- l32) -- (l32 -| C<span class="nb">_</span>4);
1421
<span class="k">\draw</span><span class="na">[dashed]</span> (C<span class="nb">_</span>1 |- l21) -- (l21 -| C<span class="nb">_</span>4);
1422
<span class="k">\draw</span><span class="na">[<->,red]</span> (A<span class="nb">_</span>1) to[out=-120,in=90] (C<span class="nb">_</span>2);
1423
<span class="c">% Highlight the A_1 -> B_1 -> C_2 path. Use layers to draw</span>
1424
<span class="c">% behind everything.</span>
1425
<span class="k">\begin</span><span class="nb">{</span>pgfonlayer<span class="nb">}{</span>background<span class="nb">}</span>
1426
<span class="k">\draw</span><span class="na">[rounded corners=2em,line width=3em,blue!20,cap=round]</span>
1427
(A<span class="nb">_</span>1.center) -- (B<span class="nb">_</span>1.west) -- (C<span class="nb">_</span>2.center);
1428
<span class="k">\end</span><span class="nb">{</span>pgfonlayer<span class="nb">}</span>
1429
<span class="k">\end</span><span class="nb">{</span>tikzpicture<span class="nb">}</span>
1430
<span class="k">\end</span><span class="nb">{</span>document<span class="nb">}</span>
1432
<div class="figure">
1433
<img alt="Annotated graph" src="img/dot2texiex2.png" />