Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I took the following figure from JSON official site.

enter image description here

Is there a package to do it easily?

Anyway, what is the name of this diagram?

share|improve this question
2  
If it had arrows, I'd say it's a deterministic finite state automaton. –  TH. Mar 24 '11 at 3:09
    
@TH If I had to guess, I'd say that the arrows are implied and it is a DFA, albeit an "artistic" representation of one. –  Aaron Mar 24 '11 at 3:38
2  
TiKZ chains library. See the fourth tutorial in the TikZ manual. –  Caramdir Mar 24 '11 at 4:26
    
@Aaron: As per Herbert's answer, it appears that these syntax diagrams are supposed to be for CFGs, so I guess they aren't DFAs (although the language for this one is clearly regular). –  TH. Mar 24 '11 at 14:24

4 Answers 4

up vote 7 down vote accepted

that are so-called railroad diagrams for the syntax and can be set with simple nodes and loops:

\documentclass{article}
\usepackage{pst-node}
\def\CBox#1{\pscirclebox[fillcolor=green!20,fillstyle=solid]{\bfseries#1}}
\def\PBox#1{\psframebox[fillcolor=green!20,fillstyle=solid]{\bfseries\tabular{c}#1\endtabular}}
\begin{document}

\begin{pspicture}(0,-5)(13,1)
\psset{linewidth=1.5pt,linearc=0.3}\psline{|-|}(13,0)
\psforeach{\iA}{0,1,..,13}{\pnode(\iA,0){O\iA}}
\ncloop[angleB=180,loopsize=-1]{O0}{O2}\ncput{\CBox{--}}
\rput(3,0){\CBox{0}}
\ncloop[angleB=180,loopsize=-1.75]{O2}{O6}\ncput[npos=2.3]{\PBox{digit\\1-9}}
\rput(5.5,-2.5){\rnode{A}{\PBox{digit}}}\ncloop[angleB=180,loopsize=0.75]{A}{A}
\ncloop[angleB=180,loopsize=0.75]{O6}{O9}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer

I am sure you can find an example on www.texample.net

that you can modify to suit your needs. I am not aware of a package that does precesily the job.

share|improve this answer
    
Here it is: texample.net/tikz/examples/diagram-chains –  Roberto Bonvallet Mar 24 '11 at 14:29

No package but a tutorial: Diagrams as Simple Graphs in the pgfmanual page 60. You only need to change (modify) some styles

share|improve this answer

I believe these are called "syntax diagrams". I don't know about a package, but there is a tool called syngen on ctan that will generate those. It uses LaTeX picture environment, so the results are not as good looking as if you used tikz or pstricks, but maybe you could modify the code to produce some tikz code instead.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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