~ubuntu-branches/ubuntu/raring/dot2tex/raring

« back to all changes in this revision

Viewing changes to doc/usage.html

  • Committer: Bazaar Package Importer
  • Author(s): Peter Collingbourne
  • Date: 2008-01-16 01:31:30 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080116013130-z4dr2lw8mswabbso
Tags: 2.7.0-1
* New upstream release
* dot2tex/dot2tex.py: backed out all changes apart from shebang as
  taken upstream
* debian/dot2tex.1: documented new command line option --codeonly
* debian/rules: moved patching system to CDBS simple-patchsys
* debian/control: updated Standards-Version
* debian/control: added Uploaders, Vcs-Svn, Vcs-Browser fields for
  PAPT
* debian/copyright: changed year to 2008

Show diffs side-by-side

added added

removed removed

Lines of Context:
294
294
<tr><th class="docinfo-name">Author:</th>
295
295
<td>Kjell Magne Fauske</td></tr>
296
296
<tr><th class="docinfo-name">Version:</th>
297
 
<td>2.6.1</td></tr>
 
297
<td>2.7.0</td></tr>
298
298
<tr class="field"><th class="docinfo-name">Licence:</th><td class="field-body">MIT</td>
299
299
</tr>
300
300
</tbody>
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>
322
322
</div>
 
323
<div class="section" id="installation">
 
324
<h2>Installation</h2>
 
325
<div class="section" id="from-source">
 
326
<h3>From source</h3>
 
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
 
330
</pre>
 
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>
 
332
</div>
 
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
 
338
</pre>
 
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>
 
340
</div>
 
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>
 
344
</div>
 
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
 
350
</pre>
 
351
</div>
 
352
</div>
323
353
<div class="section" id="usage">
324
354
<h2>Usage</h2>
325
355
<p>Syntax:</p>
414
444
<kbd><span class="option">--figonly</span></kbd></td>
415
445
<td>Output the graph without a document preamble. Useful if the graph is to be included in a master document.</td></tr>
416
446
<tr><td class="option-group">
 
447
<kbd><span class="option">--codeonly</span></kbd></td>
 
448
<td>Output only the drawing commands, without wrapping it in a <tt class="docutils literal"><span class="pre">tikzpicture</span></tt> or <tt class="docutils literal"><span class="pre">pspicture</span></tt> environment. Useful when used with the dot2texi package.</td></tr>
 
449
<tr><td class="option-group">
417
450
<kbd><span class="option">--preproc</span></kbd></td>
418
451
<td>Preprocess the graph through LaTeX using the <a class="reference external" href="http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html">preview</a> package. Will generate a new dot file where the height and widths of nodes and edge labels are set based on the results from <a class="reference external" href="http://www.ctan.org/tex-archive/help/Catalogue/entries/preview.html">preview</a>.</td></tr>
419
452
<tr><td class="option-group">
525
558
<h3>PGF</h3>
526
559
<p>This is the default output format. Generates code for the <a class="reference external" href="http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html">Portable Graphics Format</a> (PGF) package . Mixes both PGF and TikZ commands.</p>
527
560
</div>
528
 
<div class="section" id="id1">
 
561
<div class="section" id="id2">
529
562
<h3>PSTricks</h3>
530
563
<p>Generates code for the <a class="reference external" href="http://tug.org/PSTricks/main.cgi/">PSTricks</a> package.</p>
531
564
</div>
539
572
<li>Labels will fit inside nodes without preprocessing.</li>
540
573
<li>Full access to the power of PGF and TikZ.</li>
541
574
</ul>
 
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>
545
579
</div>
546
 
<!-- sdfsdf
547
 
The difference between the ``pgf`` and ``tikz`` output formats is best shown with an example. Consider the following graph:
548
 
 
549
 
.. sourcecode:: dot
550
 
 
551
 
    graph G {
552
 
        mindist = 0.5;
553
 
        node [shape=circle];
554
 
        a - - b - - c - - a;
555
 
    }
556
 
 
557
 
Rendering the graph using ``circo`` and the ``pgf`` and ``tikz`` output formats::
558
 
 
559
 
    $ circo -Txdot simple.dot | dot2tex -tmath -fpgf -s
560
 
    $ circo -Txdot simple.dot | dot2tex -tmath -ftikz -s
561
 
 
562
 
gives visually different graphs:
563
 
 
564
 
.. figure:: img/pgftikzsimple.png
565
 
:alt: Difference between pgf and tikz output format
566
 
 
567
 
However, the main difference is in the generated code. Here is the ``pgf`` output:
568
 
 
569
 
.. sourcecode:: latex
570
 
 
571
 
    % Edge: a - - b
572
 
    \draw [] (19bp,38bp) - - (19bp,60bp);
573
 
    % Edge: b - - c
574
 
    \draw [] (35bp,70bp) - - (55bp,58bp);
575
 
    % Edge: c - - a
576
 
    \draw [] (55bp,40bp) - - (35bp,28bp);
577
 
    % Node: a
578
 
    \begin{scope}
579
 
    \pgfsetstrokecolor{black}
580
 
    \draw (19bp,19bp) ellipse (18bp and 19bp);
581
 
    \draw (19bp,19bp) node {$a$};
582
 
    \end{scope}
583
 
    % Node: b
584
 
    \begin{scope}
585
 
    \pgfsetstrokecolor{black}
586
 
    \draw (19bp,79bp) ellipse (18bp and 19bp);
587
 
    \draw (19bp,79bp) node {$b$};
588
 
    \end{scope}
589
 
    % Node: c
590
 
    \begin{scope}
591
 
    \pgfsetstrokecolor{black}
592
 
    \draw (71bp,49bp) ellipse (18bp and 19bp);
593
 
    \draw (71bp,49bp) node {$c$};
594
 
    \end{scope}
595
 
 
596
 
Compare the above code with the ``tikz`` output:
597
 
 
598
 
.. sourcecode:: latex
599
 
 
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);
606
 
 
607
 
The code is much more compact and it is quite easy to modify the graph. -->
608
580
</div>
609
581
</div>
610
582
<div class="section" id="labels">
1328
1300
}
1329
1301
</pre></div>
1330
1302
</div>
 
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 {
 
1307
    mindist = 0.5;
 
1308
    node [shape=circle];
 
1309
    a -- b -- c -- a;
 
1310
}
 
1311
</pre></div>
 
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
 
1316
</pre>
 
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" />
 
1320
</div>
 
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>
 
1346
</pre></div>
 
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);
 
1354
</pre></div>
 
1355
<p>The code is much more compact and it is quite easy to modify the graph.</p>
 
1356
</div>
 
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>
 
1362
 
 
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>
 
1365
 
 
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=&quot;circle&quot;];
 
1370
    a<span class="nb">_</span>1 -&gt; a<span class="nb">_</span>2 -&gt; a<span class="nb">_</span>3 -&gt; a<span class="nb">_</span>4 -&gt; 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>
 
1373
 
 
1374
<span class="k">\end</span><span class="nb">{</span>document<span class="nb">}</span>
 
1375
</pre></div>
 
1376
<p>When the above code is run through LaTeX, the following will happen is shell escape is enabled:</p>
 
1377
<ul class="simple">
 
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>
 
1381
</ul>
 
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" />
 
1385
</div>
 
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>
 
1396
 
 
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>[&gt;=latex&#39;,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=&quot;n&quot;];
 
1407
            A<span class="nb">_</span>1 -&gt; B<span class="nb">_</span>1; A<span class="nb">_</span>1 -&gt; B<span class="nb">_</span>2; A<span class="nb">_</span>1 -&gt; B<span class="nb">_</span>3;
 
1408
            B<span class="nb">_</span>1 -&gt; C<span class="nb">_</span>1; B<span class="nb">_</span>1 -&gt; C<span class="nb">_</span>2;
 
1409
            B<span class="nb">_</span>2 -&gt; C<span class="nb">_</span>2; B<span class="nb">_</span>2 -&gt; C<span class="nb">_</span>3;
 
1410
            B<span class="nb">_</span>3 -&gt; C<span class="nb">_</span>3; B<span class="nb">_</span>3 -&gt; 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">[&lt;-&gt;,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 -&gt; B_1 -&gt; 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>
 
1431
</pre></div>
 
1432
<div class="figure">
 
1433
<img alt="Annotated graph" src="img/dot2texiex2.png" />
 
1434
</div>
 
1435
</div>
1331
1436
</div>
1332
1437
</div>
1333
1438
</body>