~ubuntu-branches/ubuntu/trusty/dot2tex/trusty-proposed

« back to all changes in this revision

Viewing changes to doc/usage.html

  • Committer: Bazaar Package Importer
  • Author(s): Peter Collingbourne
  • Date: 2008-09-29 00:58:56 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080929005856-jxgcw984cb0kyle2
Tags: 2.8.4-1
* New upstream release
* debian/dot2tex.1: documented --cache option
* debian/control: changed maintainer email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
294
294
<tbody valign="top">
295
295
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Kjell Magne Fauske</td>
296
296
</tr>
297
 
<tr class="field"><th class="field-name">Version:</th><td class="field-body">2.8.2</td>
 
297
<tr class="field"><th class="field-name">Version:</th><td class="field-body">2.8.4</td>
298
298
</tr>
299
299
<tr class="field"><th class="field-name">Licence:</th><td class="field-body"><a class="reference external" href="http://www.opensource.org/licenses/mit-license.php">MIT</a></td>
300
300
</tr>
605
605
<div class="section" id="label-examples">
606
606
<h3>Label examples</h3>
607
607
<p>Consider the following graph:</p>
608
 
<div class="highlight"><pre>digraph G {
 
608
<div class="highlight"><pre><span class="k">digraph</span> G {
609
609
    a_1-&gt; a_2 -&gt; a_3 -&gt; a_1;
610
610
}
611
611
</pre></div>
618
618
<img alt="Difference between math and verbatim mode" src="img/ex1comb.png" />
619
619
</div>
620
620
<p>Example of using <tt class="docutils literal"><span class="pre">texlbl</span></tt>:</p>
621
 
<div class="highlight"><pre>digraph G {
 
621
<div class="highlight"><pre><span class="k">digraph</span> G {
622
622
    a_1 [texlbl=&quot;$\frac{\gamma}{x^2}$&quot;];
623
623
    a_1-&gt; a_2 -&gt; a_3 -&gt; a_1;
624
624
}
627
627
<img alt="Using the special texlbl attribute" src="img/ex2.png" />
628
628
</div>
629
629
<p>Example of using the <tt class="docutils literal"><span class="pre">texmode</span></tt> attribute:</p>
630
 
<div class="highlight"><pre>digraph G {
 
630
<div class="highlight"><pre><span class="k">digraph</span> G {
631
631
    a_1 [texlbl=&quot;$\frac{\gamma}{2x^2+y^3}$&quot;];
632
632
    a_1 -&gt; a_2 -&gt; a_3 -&gt; a_1
633
 
    node [texmode=&quot;math&quot;];
 
633
    <span class="k">node</span> [texmode=&quot;math&quot;];
634
634
    a_1 -&gt; b_1 -&gt; b_2 -&gt; a_3;
635
635
    b_1 [label=&quot;\\frac{\\gamma}{x^2}&quot;];
636
 
    node [texmode=&quot;verbatim&quot;]
 
636
    <span class="k">node</span> [texmode=&quot;verbatim&quot;]
637
637
    b_4 [label=&quot;\\beta&quot;]
638
638
    a_3 -&gt; b_4 -&gt; a_1;
639
639
}
660
660
<h3>Vertical label alignment</h3>
661
661
<p>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 <tt class="docutils literal"><span class="pre">valignmode</span></tt> option to <tt class="docutils literal"><span class="pre">dot</span></tt>. Labels will then be placed using the coordinates supplied by Graphviz.</p>
662
662
<p>Here is an example graph where it is necessary to use the <tt class="docutils literal"><span class="pre">valignmode</span></tt> option:</p>
663
 
<div class="highlight"><pre>digraph G {
 
663
<div class="highlight"><pre><span class="k">digraph</span> G {
664
664
    node0 [label=&quot;{left|right}&quot;, shape=record];
665
665
    node1 [shape=rectangle, label=&quot;node 1&quot;];
666
666
    node0 -&gt; node1;
693
693
<img alt="blabla" src="img/valignmode2.png" />
694
694
</div>
695
695
<p>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:</p>
696
 
<div class="highlight"><pre>digraph G {
697
 
    node [fontsize=10];
 
696
<div class="highlight"><pre><span class="k">digraph</span> G {
 
697
    <span class="k">node</span> [fontsize=10];
698
698
    node0 [label=&quot;{left|right}&quot;, shape=record];
699
699
    node1 [shape=rectangle, label=&quot;node 1&quot;];
700
700
    node0 -&gt; node1;
731
731
<div class="section" id="examples">
732
732
<h3>Examples</h3>
733
733
<p>Consider the following graph:</p>
734
 
<div class="highlight"><pre>digraph G {
735
 
    node [shape=circle];
 
734
<div class="highlight"><pre><span class="k">digraph</span> G {
 
735
    <span class="k">node</span> [shape=circle];
736
736
    a_1 [texlbl=&quot;$x^2+\frac{\sin y}{y^2+\cos \beta}+\gamma_3$&quot;];
737
737
    a_1 -&gt; a_2 [label=&quot; &quot;, texlbl=&quot;$x_1+x_3^2+z+c+v~~$&quot;];
738
738
    a_2 -&gt; a_1;
764
764
<img alt="Graph with preprocessed labels" src="img/preproc1b.png" />
765
765
</div>
766
766
<p>Modifying node sizes using the <tt class="docutils literal"><span class="pre">widht/height</span></tt> and <tt class="docutils literal"><span class="pre">margin</span></tt> attributes can be a bit counterintuitive. A few examples will hopefully make it clearer:</p>
767
 
<div class="highlight"><pre>digraph G {
768
 
    node [shape=rectangle];
 
767
<div class="highlight"><pre><span class="k">digraph</span> G {
 
768
    <span class="k">node</span> [shape=rectangle];
769
769
    a_1 [margin=&quot;0&quot;];
770
770
    a_2 [margin=&quot;0.7,0.4&quot;];
771
771
    a_3 [width=&quot;2&quot;,height=&quot;1&quot;];
797
797
<h3>Using styles</h3>
798
798
<p>The dot language defines the <tt class="docutils literal"><span class="pre">style</span></tt> attribute that can be used to modify the appearance of graphs, nodes, and edges. The <tt class="docutils literal"><span class="pre">style</span></tt> 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.</p>
799
799
<p>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:</p>
800
 
<div class="highlight"><pre>graph G {
801
 
    node [shape=circle, fixedsize=True, width=&quot;0.2&quot;,
 
800
<div class="highlight"><pre><span class="k">graph</span> G {
 
801
    <span class="k">node</span> [shape=circle, fixedsize=True, width=&quot;0.2&quot;,
802
802
          style=&quot;ball color =green&quot;, label=&quot;&quot;];
803
 
    edge [style=&quot;snake=zigzag, green&quot;];
 
803
    <span class="k">edge</span> [style=&quot;snake=zigzag, green&quot;];
804
804
    a_1 -- c -- a_2;
805
805
    c [style=&quot;ball color=black&quot;];
806
 
    edge [style=&quot;snake=snake, blue&quot;];
807
 
    node [style=&quot;ball color = red&quot;, label=&quot;&quot;];
 
806
    <span class="k">edge</span> [style=&quot;snake=snake, blue&quot;];
 
807
    <span class="k">node</span> [style=&quot;ball color = red&quot;, label=&quot;&quot;];
808
808
    a_3 -- c -- a_4 --a_3;
809
809
}
810
810
</pre></div>
823
823
<div class="section" id="changing-arrow-types">
824
824
<h4>Changing arrow types</h4>
825
825
<p>The style attribute can be used to change arrow types. A PGF/TikZ example:</p>
826
 
<div class="highlight"><pre>digraph G {
827
 
    graph [mindist=0.5];
828
 
    node [fixedsize=true, shape=circle, width=0.4, style=&quot;fill=green!20&quot;];
 
826
<div class="highlight"><pre><span class="k">digraph</span> G {
 
827
    <span class="k">graph</span> [mindist=0.5];
 
828
    <span class="k">node</span> [fixedsize=true, shape=circle, width=0.4, style=&quot;fill=green!20&quot;];
829
829
    c -&gt; n_1 [style=&quot;-stealth&quot;];
830
830
    c -&gt; n_2 [style=&quot;-to&quot;];
831
831
    c -&gt; n_3 [style=&quot;-latex&quot;];
853
853
<img alt="Setting default PGF/TikZ arrows." src="img/ex1gstyle.png" />
854
854
</div>
855
855
<p>A PSTricks example:</p>
856
 
<div class="highlight"><pre>digraph G {
 
856
<div class="highlight"><pre><span class="k">digraph</span> G {
857
857
    d2tdocpreamble=&quot;\usepackage{pstricks-add}&quot;;
858
 
    graph [mindist=0.5];
859
 
    node [texmode=&quot;math&quot;, fixedsize=true, shape=circle, width=0.4];
 
858
    <span class="k">graph</span> [mindist=0.5];
 
859
    <span class="k">node</span> [texmode=&quot;math&quot;, fixedsize=true, shape=circle, width=0.4];
860
860
    c -&gt; n_1 [style=&quot;arrows=-&gt;&quot;];
861
861
    c -&gt; n_2 [style=&quot;arrows=-&gt;&gt;&quot;];
862
862
    c -&gt; n_3 [style=&quot;arrows=-&lt;&quot;];
888
888
<div class="highlight"><pre><span class="k">\draw</span> (157bp,52bp) node[lblstyle] <span class="nb">{</span>label<span class="nb">}</span>;
889
889
</pre></div>
890
890
<p>Example:</p>
891
 
<div class="highlight"><pre>digraph G {
892
 
    node [shape=circle];
 
891
<div class="highlight"><pre><span class="k">digraph</span> G {
 
892
    <span class="k">node</span> [shape=circle];
893
893
    a -&gt; b [label=&quot;label&quot;,lblstyle=&quot;draw=red,cross out&quot;];
894
894
    b -&gt; c [label=&quot;test&quot;,lblstyle=&quot;below=0.5cm,rotate=20,fill=blue!20&quot;];
895
895
    a [label=&quot;aa&quot;,lblstyle=&quot;blue&quot;];
931
931
<h3>TikZ edge labels</h3>
932
932
<p>With the <tt class="docutils literal"><span class="pre">--tikzedgelabel</span></tt> 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 <tt class="docutils literal"><span class="pre">to</span></tt> paths.</p>
933
933
<p>Example:</p>
934
 
<div class="highlight"><pre>graph G {
 
934
<div class="highlight"><pre><span class="k">graph</span> G {
935
935
    mindist = 0.5;
936
 
    node [shape=&quot;circle&quot;];
937
 
    edge [lblstyle=&quot;mystyle&quot;];
 
936
    <span class="k">node</span> [shape=&quot;circle&quot;];
 
937
    <span class="k">edge</span> [lblstyle=&quot;mystyle&quot;];
938
938
    a -- b [label=&quot;ab&quot;];
939
939
    b -- c [label=&quot;bc&quot;];
940
940
    c -- a [label=&quot;ca&quot;];
970
970
<h3>To paths</h3>
971
971
<p>The <tt class="docutils literal"><span class="pre">topath</span></tt> edge attribute offers a way to override the edges drawn by Graphviz. When a <tt class="docutils literal"><span class="pre">topath</span></tt> attribute is encountered, dot2tex inserts a so called <tt class="docutils literal"><span class="pre">to</span></tt> path operation to connect the nodes. A number of predefined to paths are defined by TikZ, and you can create your own.</p>
972
972
<p>Example:</p>
973
 
<div class="highlight"><pre>digraph G {
 
973
<div class="highlight"><pre><span class="k">digraph</span> G {
974
974
    mindist = 0.5;
975
 
    node [shape=&quot;circle&quot;];
 
975
    <span class="k">node</span> [shape=&quot;circle&quot;];
976
976
    a -&gt; b [topath=&quot;bend right&quot;];
977
977
    c -&gt; b [topath=&quot;bend left&quot;];
978
978
    c -&gt; a [topath=&quot;out=10,in=-90&quot;];
998
998
<p class="last">To paths works best with layout tools that generate straight edges (neato, fdp, circo, twopi). The <tt class="docutils literal"><span class="pre">topath</span></tt> attribute overrides the edge routing done by Graphviz. You may therefore end up with overlapping edges.</p>
999
999
</div>
1000
1000
<p>Here is a larger example that uses the <tt class="docutils literal"><span class="pre">automata</span></tt> library:</p>
1001
 
<div class="highlight"><pre>digraph G {
 
1001
<div class="highlight"><pre><span class="k">digraph</span> G {
1002
1002
    d2tdocpreamble = &quot;\usetikzlibrary{automata}&quot;;
1003
1003
    d2tfigpreamble = &quot;\tikzstyle{every state}= \
1004
1004
    [draw=blue!50,very thick,fill=blue!20]&quot;;
1005
 
    node [style=&quot;state&quot;];
1006
 
    edge [lblstyle=&quot;auto&quot;,topath=&quot;bend left&quot;];
 
1005
    <span class="k">node</span> [style=&quot;state&quot;];
 
1006
    <span class="k">edge</span> [lblstyle=&quot;auto&quot;,topath=&quot;bend left&quot;];
1007
1007
    A [style=&quot;state, initial&quot;];
1008
1008
    A -&gt; B [label=2];
1009
1009
    A -&gt; D [label=7];
1366
1366
$ dot2tex -tikz -tmath --tikzedgelabels ex1.dot
1367
1367
</pre>
1368
1368
<p>each time, use <tt class="docutils literal"><span class="pre">d2toptions</span></tt> like this:</p>
1369
 
<div class="highlight"><pre>digraph G {
 
1369
<div class="highlight"><pre><span class="k">digraph</span> G {
1370
1370
    d2toptions =&quot;-tikz -tmath --tikzedgelabels&quot;;
1371
1371
    ...
1372
1372
}
1375
1375
<div class="section" id="use-the-tikz-output-format-for-maximum-flexibility">
1376
1376
<h3>Use the tikz output format for maximum flexibility</h3>
1377
1377
<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>
1378
 
<div class="highlight"><pre>graph G {
 
1378
<div class="highlight"><pre><span class="k">graph</span> G {
1379
1379
    mindist = 0.5;
1380
 
    node [shape=circle];
 
1380
    <span class="k">node</span> [shape=circle];
1381
1381
    a -- b -- c -- a;
1382
1382
}
1383
1383
</pre></div>