| 1 |
input automata; |
| 2 |
|
| 3 |
verbatimtex |
| 4 |
% generic layout |
| 5 |
\documentclass{article} |
| 6 |
\usepackage[english]{babel} |
| 7 |
\usepackage[latin1]{inputenc} |
| 8 |
\selectlanguage{english} |
| 9 |
% additional packages |
| 10 |
\usepackage{amsmath} |
| 11 |
\begin{document} |
| 12 |
etex |
| 13 |
|
| 14 |
|
| 15 |
% EXAMPLE FOR THE PACKAGE automata.mp |
| 16 |
|
| 17 |
beginfig(0); |
| 18 |
|
| 19 |
% Setting of some global parameters. |
| 20 |
|
| 21 |
size := 15; |
| 22 |
incominglength := 25; |
| 23 |
loopsize := 22; |
| 24 |
|
| 25 |
% The following command defines a grid of nodes with 7 rows and 10 columns. |
| 26 |
% Instead of using "spacing := (36,29)" and thus change the global parameter for the ditance |
| 27 |
% between nodes, one can use `with spacing((36,29))' to temporarily change the value of this |
| 28 |
% parameter. |
| 29 |
|
| 30 |
with spacing((36,29)) matrix.a(7,10); |
| 31 |
|
| 32 |
% Next, one declares the shape of the nodes and possibly their labels. One can use the directives |
| 33 |
% "btex" and "etex" to include LaTeX-compiled labels in nodes, or just "" to leave them unlabeled. |
| 34 |
% Moreover, one can use several shapes for the nodes. There are some predefined shorhands for |
| 35 |
% modified styles of nodes and arrows (e.g., "node_double" is equivalent to "with border(double) node") |
| 36 |
|
| 37 |
node.a[4][0](btex $s_0$ etex); |
| 38 |
with shape(boxed) node.a[4][2](btex $s_1$ etex); |
| 39 |
with shape(fixedbox) node.a[4][4](btex $s_2$ etex); |
| 40 |
with size(18) with shape(diamond) node.a[4][6](btex $s_3$ etex); |
| 41 |
with size(22) with shape(utriangle) node.a[4][8](btex $s_4$ etex); |
| 42 |
node.a[2][2](btex $s_5$ etex); |
| 43 |
node.a[2][5](btex $s_6$ etex); |
| 44 |
node.a[1][6](btex $s_7$ etex); |
| 45 |
node_double.a[1][8](btex $s_8$ etex); |
| 46 |
|
| 47 |
% One can define arrows of different forms. Each arrow follow a path from an initial node to a |
| 48 |
% final node and this path must be explicitly given as a MetaPost path expression (e.g., point..point--point). |
| 49 |
% Note that labels of nodes and arrows can be rotated using the MetaPost directive "rotated". |
| 50 |
|
| 51 |
incoming(0, "") (a[4][0]) 120; |
| 52 |
loop.bot(.65, btex \small $a$ etex) (a[4][0]) -165; |
| 53 |
arrow_dash.bot(.5, btex \small $b$ etex) (a[4][0],a[4][2]) a[4][0].c..a[4][2].c; |
| 54 |
arrow.bot(.5, btex \small $a$ etex) (a[4][2],a[4][4]) a[4][2].c..a[4][4].c; |
| 55 |
arrow.bot(.5, btex \small $a$ etex) (a[4][4],a[4][6]) a[4][4].c..a[4][6].c; |
| 56 |
arrow.bot(.5, btex \small $a$ etex) (a[4][6],a[4][8]) a[4][6].c..a[4][8].c; |
| 57 |
arrow.bot(.5, btex \small $c$ etex) (a[4][8],a[4][0]) a[4][8].c..a[5][7].c---a[5][1].c..a[4][0].c; |
| 58 |
arrow_dash.rt(.5, btex \small $a$ etex rotated 90) (a[4][2],a[2][2]) a[4][2].c..a[2][2].c; |
| 59 |
arrow.bot(.5, btex \small $c$ etex rotated 39) (a[2][2],a[4][0]) a[2][2].c..a[4][0].c; |
| 60 |
arrow_dash.bot(.5, btex \small $a$ etex) (a[2][2],a[2][5]) a[2][2].c{dir-30}..a[2][5].c; |
| 61 |
arrow_dash.rt(.5, btex \small $a$ etex rotated 90) (a[4][6],a[1][6]) a[4][6].c..a[1][6].c; |
| 62 |
arrow.top(.5, btex \small $a$ etex) (a[1][6],a[1][8]) a[1][6].c..a[1][8].c; |
| 63 |
arrow.bot(.38, btex \small $c$ etex) (a[2][5],a[4][0]) a[2][5].c..a[1][4].c---a[1][2].c shifted(-10,0)..a[2][1].c shifted (-10,0)---a[4][0].c; |
| 64 |
arrow_bold.bot(.5, btex \small $c$ etex) (a[1][8],a[4][0]) a[1][8].c..a[2][9].c---a[5][9].c..a[6][8].c---a[6][1].c..a[5][0].c---a[4][0].c; |
| 65 |
arrow_bold.top(.38, btex \small $c$ etex) (a[1][8],a[4][0]) a[1][8].c..a[0][7].c---a[0][1].c..a[1][0].c---a[4][0].c; |
| 66 |
|
| 67 |
% Finally, one may want to highligh a given set of nodes. This can done using the macro |
| 68 |
% "enclose"/"enclosure", which draws/returns a path that goes around the given sequence |
| 69 |
% of vertices (it is always a good idea if the sequence is given in clockwise order and |
| 70 |
% if it defines a convex region!). |
| 71 |
|
| 72 |
with enclosuremargin(20) draw enclosure(a[4][4].c--a[2][5].c--a[1][6].c--a[4][6].c--cycle) withcolor light.light.green withpen pencircle scaled 3; |
| 73 |
|
| 74 |
endfig; |
| 75 |
|
| 76 |
end. |