0

I would like to recreate diagrams of this form (from Iverson's A Programming Language book). The math inside the boxes is easy, but I'd like to be able to programmatically create those boxes and labeled arrows. Is there an easy way to do this?

enter image description here

I'd prefer to use plaintex but I'm willing to delve into the more complex world of LaTeX if it will make this work easier.

1
  • 2
    You can use TikZ also with plain TeX.
    – egreg
    Commented Feb 2, 2018 at 16:00

1 Answer 1

5

Just for fun:

\documentclass{article}

\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\begin{enumerate}[labelsep=10mm,label=\theenumi]
\item \tikzmark{a}$z \leftarrow c$
\item $p \leftarrow \in(v(z))$
\item \tikzmark{b}$v(f) : 2$
\item $i \leftarrow 1$
\item $x \leftarrow \in(0)$
\item \tikzmark{c}$j \leftarrow (\theta/f)_i$
\item $x \leftarrow x \oplus (((p \overset{\scriptscriptstyle +}{\times} a^{j-1}) \downarrow a^{p_j})/z)$ 
\item $i \leftarrow i + 1$
\item \tikzmark{d}$i : v(f)$
\item $z \leftarrow (\circ) \oplus x$
\item $p \leftarrow (\theta/f) \int p$
\item $p \leftarrow (1 + (p \overset{\scriptscriptstyle +}{\times} a^2 )) \oplus \overline{a}^2 / p$
\item $f \leftarrow (\theta/f) \int f$
\item \tikzmark{e}$f \leftarrow (+/a^2/f) \oplus \overline{a}^2 / f$
\end{enumerate}

\begin{tikzpicture}[remember picture,overlay]\footnotesize
 \draw ([xshift=-2mm,yshift=4mm]pic cs:a) rectangle ([xshift=50mm,yshift=-3mm]pic cs:e);
 \draw[->] ([xshift=-8mm,yshift=.5ex]pic cs:a) -- ([xshift=-2mm,yshift=.5ex]pic cs:a);
 \draw[->] ([xshift=-2mm,yshift=.5ex]pic cs:d) -- node [above] {$\leq$} ([xshift=-6mm,yshift=.5ex]pic cs:d) -- ([xshift=-6mm,yshift=.5ex]pic cs:c) -- ([xshift=-2mm,yshift=.5ex]pic cs:c);
 \draw[->] ([xshift=50mm,yshift=.5ex]pic cs:b) -- node [above] {$=$} ([xshift=56mm,yshift=.5ex]pic cs:b);
 \draw[->] ([xshift=-2mm,yshift=.5ex]pic cs:e) -- ([xshift=-8mm,yshift=.5ex]pic cs:e) -- ([xshift=-8mm,yshift=.5ex]pic cs:b) -- ([xshift=-2mm,yshift=.5ex]pic cs:b);
 \end{tikzpicture}

\end{document}

This yields:

enter image description here

1
  • Not the best solution, since the items are not equally distributed possibly due to the \overset macro Commented Feb 3, 2018 at 9:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .