LaTeX: Automata in LaTeX

Automata is one of the most important packages that are provided to you by LaTeX. They are extremely beneficial and they are not provided by word editors and it will neither be easy nor clean enough to draw such automata using these word editors. That is why another strong feature of LaTeX is introduced to you in this tutorial, which is the LaTeX Automata Package.

Since the automata package is new for you, you need first to use certain packages for the correct compilation of the LaTeX script that you are writing. These packages are: FinalStateVar.tex, multido.sty, multido.tex, vaucanson-g.sty, Vaucanson-G.tex and VCPref-main.tex.

After downloading these packages, you should place them in the directory where you are working (i.e. where you put your .tex file).

Now, you are ready to begin your first TeX Automata Script!

When you are starting to work with LaTeX automata, it is much easier and better to start with the simple details rather than starting with complicated figures and automata. However, as the diagram gets more complicated, the more complex the commands will get.

Starting with a simple example as follows and illustarting the commands in details:

\begin{VCPicture}{(0,-2)(6,2)} % states \State[p]{(0,0)}{A} \State{(3,0)}{B} \State[r]{(6,0)}{C} % initial--final \Initial{A} \Final{C} % transitions \EdgeL{A}{B}{a} \ArcL{B}{C}{b} \ArcL{C}{B}{b} \LoopN{A}{a} \LoopS{C}{d} \end{VCPicture}

If you take a look at the provided script, you will find it rather logical to identify from the commands names and the corrersponding figure how they relate to each other. But for preventing confusion, this is explained thoroughly here.

\begin{VCPicture}{(x,y)(x1,y1)} .... \end{VCPicture}

This command starts the automata's enviroment, preapring to get started with drawing your figure. The x, y coordinates of the figure are then defined.

The states in LaTeX automata are represented by circles, in which you can write the state label within. This state is also given a name which identifies it internally in the figure that it is drawn in to describe the transitions that start from it or end at it.

  • \State[Label]{(x,y)}{Name}: Here the label is an optional attribute, that means that you can choose to draw a state without any label.
  • \Initial[Direction]{Name}: This is the command that defines that the state is an initial state. The "Direction" is specified in order to identify the incoming arrow from this direction to state with the name "Name".
  • \Final[Direction]{Name}: This command defines the final state of our figure. This defines the state with "Name" as the final sate and draws an outgoing arrow in the direction "Direction" from the state "Name" .

The parameter Direction is also optional and has eight different values: n,s,e,w,ne,nw,se,sw.

% states \State[p]{(0,0)}{A} \State{(3,0)}{B} \State[r]{(6,0)}{C} % initial--final \Initial{A} \Final{C}

Some people prefer to identify a Final state with double lines rather than a single line.

\FinalState[r]{(6,-1)}{D} \Initial[n]{D} \Final[s]{D}

You can also play around a little bit, in order ro to do some enhancements to your states as follows:

\State[p]{(0,1)}{A} \State{(2,-1)}{B} \State[r]{(4,1)}{C} \Initial{A} \Final{A} \Initial[ne]{B} \Initial[nw]{B} \Initial[se]{B} \Initial[sw]{B} \Initial{C} \Final[w]{C}

The Edge commands are similarly as simple as the previous transition commands. They are oriented from an original state to a final state or an end state. There are eiher left or right orientations of a certain transition.

  • \EdgeL[Position]{Start}{End}{Label}
  • \EdgeR[Position]{Start}{End}{Label}

Here we are drawing a state transition from the Start state to the End state with the label Label on the left side for \EdgeL, on the right side for \EdgeR .

Here the parameter [Position] is optional. It is a value between 0 <= Position =< 1. It defines the position of out label on the specified edge. It has a default value of 0.45.

% states \State[A]{(0,0)}{A} \State[B]{(2,-2)}{B} \State[C]{(4,2)}{C} \State[D]{(6,0)}{D} % transitions \EdgeR{A}{B}{a} \EdgeL{A}{C}{b} \EdgeR{B}{D}{c} \EdgeL{C}{D}{d} \EdgeL{C}{B}{} \EdgeL[.3]{A}{D}{x}]

The Arc commands are similarly as the previous Edge commands. They are oriented from an original state to a final state or an end state. There are eiher left or right orientations of a certain transition.

  • \ArcL[Position]{Start}{End}{Label}
  • \ArcR[Position]{Start}{End}{Label}

The starting angle for ArcX is 15 degrees, However, the starting angle for LArcX is 30 degrees. The parameter [Position] as mentioned before is optional and has a default value of 0.4.

  • \LArcL[Position]{Start}{End}{Label}
  • \LArcR[Position]{Start}{End}{Label}

\State[A]{(0,0)}{A} \State[B]{(2,-2)}{B} \State[C]{(4,2)}{C} \State[D]{(6,0)}{D} %initial-final \Initial{A} \Final[s]{B} \Final[n]{C} % transitions \ArcR{A}{B}{a} \ArcL{A}{C}{b} \LArcR{B}{D}{c} \LArcL{C}{D}{d} \ArcL{A}{B}{a'} \EdgeR{A}{C}{b'} \EdgeL{B}{D}{c'} \ LArcR{C}{D}{d'}

Loops are transitions that connect a state to itself, a state which could be said to be the start and end of the same transition.

  • \LoopY[Pos]{Name}{Label}
  • \CLoopY[Pos]{Name}{Label}

Draw a loop around the state Name with the label Label. The direction of the loop is given by Y. The opening of the loop is 60 degrees for the LoopY commands and 44 degrees for the CLoopY commands. The parameter [Position] is optioal and has a default value of 0.25.

% states \State[A]{(0,0)}{A} \State[B]{(3,-2)}{B} \State[C]{(3,2)}{C} \State[D]{(6,0)}{D} % transitions \LoopE{A}{e} \LoopW{A}{w} \LoopS{A}{s} \LoopN[.5]{A}{n} \LoopSE[.5]{B}{se} \LoopSW[.5]{B}{sw} \CLoopNE[.6]{C}{ne} \CLoopNW[.6]{C}{nw} \CLoopE{D}{e} \CLoopW{D}{w} \CLoopS{D}{s} \CLoopN[.5]{D}{n}

% states \State[i]{(0,0)}{A} \State[q]{(3,0)}{B} \State[t]{(6,0)}{C} % initial-final \Initial{A} \Final{C} % transitions \EdgeR{A}{B}{2b} \EdgeR{B}{C}{2b} \LArcL{A}{C}{b} \LoopN{A}{a} \LoopS{A}{b} \LoopS[.5]{B}{2a+2b} \LoopN[.75]{C}{4a} \LoopS[.75]{C}{4b}

There are a lot of other enhacments that once can to do while drawing automata; for instance, you can have zigzag edges, edge borders, reaverse transitions and many more functionalities, but since this tutorial takes you through the important basics that gets you started, we will not dig deeply into more features. However, you are free to check the attached VCManual.pdf that includes a lot of commands and code samples that can help you with your further enhancements.

This is an example of a Reverse Transition:

% states \State[A]{(0,0)}{A} \State[B]{(2,-2)}{B} \State[C]{(4,2)}{C} \State[D]{(6,0)}{D} % transitions \Final[s]{B} \ArcR{A}{B}{a} \ArcL{A}{C}{b} \LArcR{B}{D}{c} \LArcL{C}{D}{d} \ReverseArrow \Initial{A} \Final[n]{C} \ArcL{A}{B}{a'} \EdgeR{A}{C}{b'} \EdgeL{B}{D}{c'} \LArcR{C}{D}{d'}

Hopefully, you are able now to start with your own automata script. If you are willing to dig a little bit deeper, it would be really helpful to check the provided reference.

An Important Note:

Note that when compiling your script, you will normally get a .dvi file. You must change this .dvi file into a .pdf file using the dvipdf command on Linux OS or the corrersponding command on Windows OS.

The LaTeX packages takes you from one tutorial to the other with pretty much astonishment, the strength and quality it provides makes you wonder, why am i still using word editors. Well, you are right to wonder, because it is a waste of time. So, instead of wasting your time using paint brushes to draw malformed circles, why not try LaTeX Automata package and Feel the difference yourself!

For your own convenience here is the automata.tex and automata.pdf

The next tutorial, will take you through the basics of Hardware and Logic gates, which is really a beneficial material especially for Electical and Computer Engineers. A lot of nice features will be discussed thoroughly in the next tutorial.