[pgf-tikz] [Question] Automata why no graph

mail-login+tikz at protonmail.com mail-login+tikz at protonmail.com
Fri Oct 1 00:17:56 CEST 2021


On Saturday, June 5th, 2021 at 22:58, Henri Menke via pgf-tikz <pgf-tikz at tug.org> wrote:

> On 05/06/21, 19:02, l.mail.n--- via pgf-tikz wrote:
>
> > Hi,
> >
> > in all templates I found, drawing automatas is done by creating nodes and placing them to explicit positions (mostly relative to other nodes). The fact that one is forced to manually place the nodes is something that I'm wondering about. Is there a reason why automatas normally are not set as graphs (since in almost all points I currently can think about they are)? Is this because the tikz-automata layout suggests doing so? If yes, what was the reason for not using a graph?
>
> The reason is very simple: The automata library is much older than the
> graphdrawing mechanism. It hasn't been updated to use graphs mainly for
> compatibility reasons. Graphdrawing requires LuaTeX and old documents
> using automata might not work with LuaTeX.
>
> > The reason why this comes to me, is that for graphs as far as I skimmed the tikz code there are automatic layout methods implemented and in many occasions it would be great to use them to draw automatas (at least for a first suggestion how the graph can be laid out, on most occasions the end result will most probably still be manually laid out).
>
> We're open to PRs introducing a new layout engine for automata.

Well I've been experimenting a bit, but I'm not sure is there are any changes that should be made in the automata library. As far as I see this on [1] the automata library simply specifies some pfg-keys and sets some styles. What I'd do to make use of graphdrawing when drawing automata is the following:
```tex
\begin{tikzpicture}
   \graph[layered layout,nodes={state}] % or another layout option
    {
        % State declaration
        q0[initial];
        q1[accepting];
        %
        % Edge declaration
        q0 ->["a"] q1;
    }
\end{tikzpicture}
```
(Annotation: Of course one could merge the state declaration and the edge declaration but that's something I personally liked with the "old" approach)

Since there are simply no additional keys that would be necessary to be defined and this use of `\graph` isn't that big deal (after one knows about it...), I think there is no need in some sort of automata-gd library.
In my opinion, if one thinks this may be a help to many people (which I somehow doubt, since most people use (plain) latex instead of lualatex (that's at least how I perceive it)), maybe there should be a note in the manual. Or/And maybe reach out to the author of [2] for a note in the tutorial (this is a tutorial that is often used as far as I noticed it).
But as already written, I think the distribution of lualatex isn't that far to this point.

Regards
Lukas

[1]: https://github.com/pgf-tikz/pgf/blob/247f1f0445a9e996560c9f5a9b3fb03a4184e6ec/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryautomata.code.tex
[2]: https://hauke-stieler.de/public/tikz-for-state-machines_en.pdf

PS: A larger full example (as part of the mail since I'm not sure how suspicious attachments are on mailing lists)
Since I don't do that much with automata at the moment I didn't test the result of the graphdrawing lib that extensively.
One can already see that edges going from a to b and from b to a might get a problem in larger drawings.

```tex
\documentclass[border=1cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{graphs,automata,arrows,shapes.geometric,positioning,quotes}
\usetikzlibrary{graphdrawing}
\usegdlibrary{layered,force,circular}

\tikzset{
	automata/.style={
		->,>=stealth',shorten >=1pt,auto,
		node distance=2.8cm,semithick,
		font=\small,
		initial text=,
		every state/.style={
			draw=blue!50,very thick,fill=blue!20
		},
		every loop/.style={looseness=5},
		rounded corners,
	}
}

\begin{document}
\foreach \layout in {layered layout, spring layout, simple necklace layout}
{
	\begin{tikzpicture}[automata]
		\graph[
			\layout,
			level distance=4cm, sibling distance=4cm, % relevant for layered
			random seed=10, % relevant for spring layout
			nodes={state}, edges={sloped},
		]
		{
			% nudging ex: [nudge:(up:2mm)]
			% can "correct" node position after applying the graph drawing algorithm
			% use at node declaration
			%
			% NODES
			0[initial, fill=pink];
			1;
			2[fill=brown];
			3[fill=yellow];
			4[fill=pink];
			5[fill=brown,accepting];
			6[fill=gray];
			7[fill=gray];
			8[fill=yellow];
			9[fill=gray];
			%
			% EDGES
			0 ->["a"] 2;
			0 ->["b"] 7;
			2 ->["a",bend left] 4;
			2 ->["b"] 3;
			1 ->["b"] 3;
			1 ->["a"] 6;
			3 ->["a"] 6;
			3 ->["b"] 5;
			4 ->["a",bend left] 2;
			4 ->["b"] 7;
			5 ->["a"] 4;
			5 ->["b",bend left] 8;
			6 ->["a,b",bend left] 9;
			7 ->["a,b"] 7;
			8 ->["b",bend left] 5;
			8 ->["a"] 9;
			9 ->["a,b",bend left] 6;
		};
	\end{tikzpicture}
}
\end{document}
```
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 855 bytes
Desc: OpenPGP digital signature
URL: <https://tug.org/pipermail/pgf-tikz/attachments/20210930/f06be905/attachment.sig>


More information about the pgf-tikz mailing list.