input automata;

verbatimtex
% generic layout
\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\selectlanguage{english}
% additional packages
\usepackage{amsmath}
\begin{document}
etex


% SIMPLE EXAMPLE FOR THE PACKAGE automata.mp

beginfig(0);

  % settings for some global parameters
  size := 15;
  incominglength := 25;
  loopsize := 22;

  % instead of using `spacing := (36,29)'
  % one could use `with spacing((36,29))' to temporarily change the value of the parameter
  with spacing((36,29)) matrix.a(7,10);
  
  % one can use directives btex etex to include LaTeX-compiled labels
  node.a[4][0](btex $s_0$ etex);
  node.a[4][2](btex $s_1$ etex);
  node.a[4][4](btex $s_2$ etex);
  node.a[4][6](btex $s_3$ etex);
  node.a[4][8](btex $s_4$ etex);
  node.a[2][2](btex $s_5$ etex);
  node.a[2][5](btex $s_6$ etex);
  node.a[1][6](btex $s_7$ etex);
  % there are some predefined shorhands for modified styles of nodes and arrows
  % (e.g., `node_double ...' is equivalent to `with border(double) node ...')
  node_double.a[1][8](btex $s_8$ etex);
 
  incoming(0, "") (a[4][0]) 120;
  loop.bot(.65, btex \small $a$ etex) (a[4][0]) -165;
  % paths can be simple expressions (e.g., point..point) ...
  arrow_dash.bot(.5, btex \small $b$ etex) (a[4][0],a[4][2]) a[4][0].c..a[4][2].c;
  arrow.bot(.5, btex \small $a$ etex) (a[4][2],a[4][4]) a[4][2].c..a[4][4].c;
  arrow.bot(.5, btex \small $a$ etex) (a[4][4],a[4][6]) a[4][4].c..a[4][6].c;
  arrow.bot(.5, btex \small $a$ etex) (a[4][6],a[4][8]) a[4][6].c..a[4][8].c;
  % ...or more complex expressions (e.g., point..point---point...point)
  % (BUG: directive `{dir <angle>}' does not work with arrows, but `{up}' does)
  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;
  % one can rotate labels as usual in MetaPost
  arrow_dash.rt(.5, btex \small $a$ etex rotated 90) (a[4][2],a[2][2]) a[4][2].c..a[2][2].c;
  arrow.bot(.5, btex \small $c$ etex rotated 39) (a[2][2],a[4][0]) a[2][2].c..a[4][0].c;
  arrow_dash.bot(.5, btex \small $a$ etex) (a[2][2],a[2][5]) a[2][2].c..a[2][5].c;
  arrow_dash.rt(.5, btex \small $a$ etex rotated 90) (a[4][6],a[1][6]) a[4][6].c..a[1][6].c;
  arrow.top(.5, btex \small $a$ etex) (a[1][6],a[1][8]) a[1][6].c..a[1][8].c;
  % again some complex paths for arrows...
  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;
  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;
  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;
  
endfig;

end.