\documentclass{article}
\usepackage{amssymb}            % AMS symbols
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{arrows.meta}

\usepackage{MnSymbol}   % Special symbols

\def\TMedgeInMath#1#2#3{#1{\filledtriangleright}#2{,}#3}
\def\TMedge#1#2#3{$\TMedgeInMath{#1}{#2}{#3}$}
\def\TMedgeTwo#1#2#3#4#5#6{$\textstyle \TMedgeInMath {#1}{#2}{#3} \atop {\textstyle \TMedgeInMath {#4}{#5}{#6}}$}
\def\TR{{\mathrm{R}}}   % "R" = "reversal" or "right"
\def\TL{{\mathrm{L}}}   % "L" = "left"

\def\Tacc{{\mathrm{acc}}}
\def\Trej{{\mathrm{rej}}}
\def\Tout{{\mathrm{out}}}
\def\Thalt{{\mathrm{halt}}}


\begin{document}

\noindent
Demos of state diagrams in LaTeX with TIKZ.\newline
For Math 160B \newline
S.\ Buss, February 2022.

\begin{center}
\begin{tikzpicture}[scale=1.5,
   >={Latex[length=4pt,width=4pt]},
   state/.style={minimum size=10pt,circle,draw},
   halting/.style={circle,minimum size=10pt,inner sep=1pt,draw,double}]
\node (q0) at (0,0) [state]{$q_0$};
\node (q1) at (2,0) [state] {$q_1$};
\node (qAcc) at (0,-1) [halting] {$q_\Tacc$};
\node (qRej) at (2,-1) [halting] {$q_\Trej$};
\draw [->] (-0.5,0) to (q0);
\draw [,->] (q0) to[bend left=20] node[above]{\TMedge 1 1 \TR} (q1);
\draw [->] (q1) to[bend left=20] node[below]{\TMedge 1 1 \TR} (q0);
\draw [->] (q0) to node[left]{\TMedge \# \# \TL} (qAcc);
\draw [->] (q1) to node[right]{\TMedge \# \# \TL}(qRej);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}[scale=1.2,
   >={Latex[length=4pt,width=4pt]},
   state/.style={minimum size=20pt,circle,draw},
   halting/.style={circle,minimum size=20pt,inner sep=1pt,draw,double}]
\node (q1) at (2,0) [state] {$q_0$};
\node (q2) at (4,0) [state] {$q_1$};
\node (q3) at (6,0) [state] {$q_2$};
\node (qOut) at (8,0) [halting] {$q_\Tout$};
\draw [->] (1.0,0) to (q1);
\draw [->] (q1) edge[loop above] node[above]{\TMedgeTwo 0 0 \TR  1 1 \TR} ();
\draw [->] (q1) to node[above]{\TMedge \# \# L} (q2);
\draw [->] (q2) edge[loop above] node[above]{\TMedge 1 0 \TL} ();
\draw [->] (q2) to node[above]{\TMedgeTwo \# 1 \TL  0 1 \TL} (q3);
\draw [->] (q3) edge[loop above] node[above]{\TMedgeTwo 0 0 \TL  1 1 \TL} ();
\draw [->] (q3) to node[above]{\TMedge \# \# R} (qOut);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}[scale=1.2,
   >={Latex[length=4pt,width=4pt]},
   state/.style={minimum size=20pt,inner sep=1pt,circle,draw},
   halting/.style={circle,minimum size=20pt,inner sep=1pt,draw,double}]
\node (q0) at (0,0) [state]{$q_0$};
\node (q01) at (2,0.5) [state] {$q_{0,1}$};
\node (q02) at (4,0.5) [state] {$q_{0,2}$};
\node (q11) at (2,-0.5) [state] {$q_{1,1}$};
\node (q12) at (4,-0.5) [state] {$q_{1,2}$};
\node (q3) at (6,0) [state] {$q_3$};
\node (q4) at (8,0) [state] {$q_4$};
\node (q5) at (8,-1.8) [state] {$q_5$};
\node (q6) at (0,-2) [halting] {$q_6$};
\draw [->] (-0.5,0) to (q0);
\draw [->] (q0) to node[left]{\TMedge \# \# \TL} (q6);
\draw [->] (q0) to node[above]{\TMedge 0 {0'} \TR} (q01);
\draw [->] (q0) to node[below]{\TMedge 1 {1'} \TR} (q11);
\draw [->] (q01) edge[out=130,in=100,loop] node[above]{\TMedgeTwo 0 0 \TR  1 1 \TR} (q01);
\draw [->] (q01) to node[below]{\TMedge \# \# \TR} (q02);
\draw [->] (q02) edge[loop above] node[above]{\TMedgeTwo 0 0 \TR  1 1 \TR} (q02);
\draw [->] (q02) to node[above]{\TMedge \# 0 \TL} (q3);
\draw [->] (q11) edge[out=-130,in=-100,loop] node[below]{\TMedgeTwo 0 0 \TR  1 1 \TR} (q11);
\draw [->] (q11) to node[above]{\TMedge \# \# \TR} (q12);
\draw [->] (q12) edge[loop below] node[below]{\TMedgeTwo 0 0 \TR  1 1 \TR} (q12);
\draw [->] (q12) to node[below]{\TMedge \# 0 \TL} (q3);
\draw [->] (q3) to node[above]{\TMedge {0'} 0 \TR} (q4);
\path (q3) to node[below]{\TMedge {1'} 1 \TR} (q4);
\draw [->] (q3) edge[loop below] node[below]{\TMedgeTwo 0 0 \TL  1 1 \TL} (q3);
\draw [->] (q4) to node[right]{\TMedge \# \# \TL} (q5);
\draw [->] (q4)
      .. controls (6,2) and (3,3) ..
      node[above,pos=0.35,yshift=2pt]{\TMedge 0 {0'} \TR}
      (q01);
\draw [->] (q4)
      .. controls (6,-2.25) and (3,-3) ..
      node[below,pos=0.35,yshift=-2pt]{\TMedge 1 {1'} \TR}
      (q11);
\draw [->] (q5) to[bend left,looseness=0.75] node[below]{\TMedge \# \# \TL} (q6);
\draw [->] (q5) edge[loop below] node[below]{\TMedgeTwo 0 0 \TL  1 1 \TL} (q5);
\end{tikzpicture}
\end{center}

\end{document}
