1

I was following a tutorial to try adding a dot graph to latex. I don't understand the dot code in-depth, I just copy pasted it, but I think it is not displaying as intended in the final pdf.

Dot Code

digraph simpleFA
{
    rankdir=LR;
    node [shape="point"] start;
    node [shape="circle"] p0;
    node [shape="circle"] p1;
    node [shape="doublecircle"] p2;
 
    start -> p0;
 
    p0 -> p0 [label="0"];
    p0 -> p1 [label="1"];
 
    p1 -> p2 [label="0"];
    p1 -> p1 [label="1"];
 
    p2 -> p2 [label="0,1"];
}

I'm working with cygwin and MikTex on Windows. Ran a pip install dot2tex in cygwin. I then executed dot2tex -o temp.tex --prog dot temp.dot (any options other than dot gave only worse results).

Resulting LaTex Code

\documentclass{article}
\usepackage[x11names, rgb]{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{snakes,arrows,shapes}
\usepackage{amsmath}
%
%

%

%

\begin{document}
\pagestyle{empty}
%
%
%

\enlargethispage{100cm}
% Start of code
% \begin{tikzpicture}[anchor=mid,>=latex',line join=bevel,]
\begin{tikzpicture}[>=latex',line join=bevel,]
  \pgfsetlinewidth{1bp}
%%
\pgfsetcolor{black}
  % Edge: p2 -> p2
  \draw [->] (223.22bp,47.126bp) .. controls (222.45bp,57.406bp) and (225.15bp,66.296bp)  .. (231.34bp,66.296bp) .. controls (235.3bp,66.296bp) and (237.84bp,62.648bp)  .. (239.46bp,47.126bp);
  \definecolor{strokecol}{rgb}{0.0,0.0,0.0};
  \pgfsetstrokecolor{strokecol}
  \draw (231.34bp,73.796bp) node {0,1};
  % Edge: p1 -> p1
  \draw [->] (136.85bp,42.991bp) .. controls (135.63bp,53.093bp) and (138.03bp,62.296bp)  .. (144.04bp,62.296bp) .. controls (147.9bp,62.296bp) and (150.27bp,58.519bp)  .. (151.24bp,42.991bp);
  \draw (144.04bp,69.796bp) node {1};
  % Edge: p1 -> p2
  \draw [->] (164.29bp,24.148bp) .. controls (173.99bp,24.148bp) and (185.87bp,24.148bp)  .. (207.17bp,24.148bp);
  \draw (185.69bp,31.648bp) node {0};
  % Edge: start -> p0
  \draw [->] (3.7613bp,24.148bp) .. controls (8.1357bp,24.148bp) and (19.192bp,24.148bp)  .. (40.58bp,24.148bp);
  % Edge: p0 -> p1
  \draw [->] (80.912bp,24.148bp) .. controls (90.763bp,24.148bp) and (102.82bp,24.148bp)  .. (123.78bp,24.148bp);
  \draw (102.4bp,31.648bp) node {1};
  % Edge: p0 -> p0
  \draw [->] (53.874bp,43.384bp) .. controls (52.816bp,53.331bp) and (55.108bp,62.296bp)  .. (60.748bp,62.296bp) .. controls (64.274bp,62.296bp) and (66.491bp,58.794bp)  .. (67.623bp,43.384bp);
  \draw (60.748bp,69.796bp) node {0};
  % Node: p2
\begin{scope}
  \definecolor{strokecol}{rgb}{0.0,0.0,0.0};
  \pgfsetstrokecolor{strokecol}
  \draw (231.34bp,24.148bp) node {p2};
\end{scope}
  % Node: start
\begin{scope}
  \definecolor{strokecol}{rgb}{0.0,0.0,0.0};
  \pgfsetstrokecolor{strokecol}
  \definecolor{fillcol}{rgb}{0.0,0.0,0.0};
  \pgfsetfillcolor{fillcol}
\end{scope}
  % Node: p0
\begin{scope}
  \definecolor{strokecol}{rgb}{0.0,0.0,0.0};
  \pgfsetstrokecolor{strokecol}
  \draw (60.748bp,24.148bp) node {p0};
\end{scope}
  % Node: p1
\begin{scope}
  \definecolor{strokecol}{rgb}{0.0,0.0,0.0};
  \pgfsetstrokecolor{strokecol}
  \draw (144.04bp,24.148bp) node {p1};
\end{scope}
%
\end{tikzpicture}
% End of code

%
\end{document}
%

It seems to me that the shapes for the nodes didn't make it into the LaTex code because I cannot find anything that looks like code for a circle to me.
Compiling this code with TexWorks (pdftex+MakeIndex+BibTex, the default option) results in this graph:
graph

I would have expected some circles and doublecircles around the nodes. How can I fix this?

I have tried:

  • A clean install of MikTex
  • A different computer, but also with Cygwin, Windows 10, MikTex
  • Using the --figonly flag
  • Using different --prog options

I believe I have all relevant packages installed. These I had to install are:

  • xcolor
  • pgf
  • pgftools

Possible Solution / Workaround
Running dot -Tps temp.dot -o temp.ps and opening the ps file in Adobe Acrobat Distiller produces the graph as expected.graph as expected

Or, better: dot -Tpng temp.dot -o temp.png to get the graphic directly.

That doesn't feel like a real solution though - I don't understand quite enough what's going on, but I assume dot2tex is supposed to work.

I am looking for a fix, rather than a different way of doing that, though I'm sure alternative ways will also be useful for future visitors.

6
  • 1
    this simple graph is far more simple draw direct in tikz. and it will work as expected.
    – Zarko
    Jan 13, 2018 at 7:50
  • 1
    Confirm the code produces the expected result in graphviz, and dot2tex is also unsuccessful on my Linux machine. Either you do it in tikz or, since you have the dot code already, integrate the graphics into your LaTeX document.
    – vaettchen
    Jan 13, 2018 at 8:01
  • a guess: remove " " from your shape specifications.
    – Ross
    Jan 13, 2018 at 9:11
  • @Ross Good Idea! Just tried it. The changed version still works with dot and still gives the same unexpected result with dot2tex though
    – lucidbrot
    Jan 13, 2018 at 9:35
  • 1
    Looks like it is a known bug: github.com/kjellmf/dot2tex/issues/44.
    – Ross
    Jan 13, 2018 at 16:02

3 Answers 3

4

It is very simple to do with pstricks:

\documentclass[svgnames, border =30pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{pst-node}
%\usepackage{auto-pst-pdf} % to compile with pdflatex --enable-write 18 (MiKTeX)) or pdflatex --shell-escape (TeX Live, Mac TeX)

\begin{document}

\small
\psset{arrowinset=0, linejoin=1,shortput=nab,linejoin = 1}
\def\pscolhookii{\hspace{-0.2cm}}%
\def\pscolhookiv{\psset{doubleline, doublesep = 2pt}}
$ \begin{psmatrix}[mnode =circle, colsep = 0.8cm, emnode = dot]
 & [name = p0] p_0 & [name = p1] p_1 & [name = p2] p_2
\psset{arrows = ->, doubleline = false}
\foreach \s/\t in {{1,1}/p0, p0/p1, p1/p2}{\ncline{\s}{\t}}
\psset{angleA = 65, angleB = 115, ncurv = 5, arrows = <-}
\foreach \p/\label in {p0/0,p1/1,p2/0.1}{\nccurve{\p}{\p}\nbput{\label}}
    \end{psmatrix} $

\end{document} 

enter image description here

2

Looks like it is a known bug: https://github.com/kjellmf/dot2tex/issues/44
- Ross

And in that link:

expbbc commented on 29 Dec 2016

This was fixed in 2014 here: 914f805
Kjellmf has never bothered to push an updated version to pip.

Turns out the latest version available on Github is up-to-date (currently version 2.10.dev) while the version on pip is still at version 2.9.0 from 2014.

So, for anyone else with the same problem...

The Fix

Firstly, uninstall the old version that you got from pip.

pip uninstall dot2tex

Then, navigate to some directory where you want to download the new version to and fetch the files. This will create a new directory dot2tex

git clone https://github.com/kjellmf/dot2tex.git

Now install it again.

cd dot2tex
python setup.py install

In my case, it added dot2tex automatically to the path environment variable, so it works now.

dot2tex --prog dot -o temp.tex temp.dot

And the output now contains lines like \draw (60.75bp,24.15bp) ellipse (20.3bp and 20.3bp);. The compiled Latex pdf matches the output of dot.

1

with tikz is also very simple:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{automata, chains, quotes}

\begin{document}
    \begin{tikzpicture}[
      node distance = 12mm,
        start chain = going right,
state/.append style = {on chain, join=by -latex},
               auto = left
                    ]
\coordinate[on chain] (in);
\node (p0) [state] {$p_0$};
\node (p1) [state] {$p_1$};
\node (p2) [state,double] {$p_2$};
\fill (in) circle (1pt);
\draw[->]   (p0) edge [loop above,"0" ] ()
            (p1) edge [loop above,"2"]  ()
            (p2) edge [loop above,"0.1"] ();
    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.