I am re-typesetting a picture (Figure 3.9) from "Structure and Interpretation of Computer Programs":
The result of my TikZ musings is the following:
Please, ignore the white-ish main colour, I want to make the picture usable with both dark and light backgrounds.
This is the code for the picture:
#+name: remark-environments-3-9
#+header: :imagemagick yes :iminoptions -density 300 :imoutoptions -geometry 800
#+header: :fit yes :headers '("\\usepackage{tikz} \\usetikzlibrary{positioning,fit,petri,arrows}")
#+header: :buffer on
#+begin_src latex :results raw file :exports both :file figure-3-9.png
\begin{tikzpicture}[inner sep=0mm,>=stealth',very thick,color=black!50]
\begin{scope} [node distance=4mm]
\node (make withdraw) {make-withdraw: ...};
\node (fake1) [right=of make withdraw,xshift=40mm] {};
\node (W1) [below=of make withdraw.west,anchor=west] {W1:};
\end{scope}
\node (g env) [draw,rectangle,inner sep=2mm, fit=(make withdraw) (W1) (fake1)]
{ };
\node (g env name) [left={of g env},text width=1cm]
{global env} edge[->,very thick] (g env);
\begin{scope}[node distance=0mm]
\node [draw,minimum size=5mm,circle,tokens=1,below=of W1.east, yshift=-20mm] (w1fun-left) {};
\node [draw,minimum size=5mm,circle,tokens=1,right=of w1fun-left, xshift=0mm]
(w1fun-right) {};
\node [rectangle, fit=(w1fun-left) (w1fun-right)] (w1fun)
{} edge [<-, to path={|- (\tikztotarget)}] (W1.east);
\end{scope}
\node [below=of w1fun-left, align=left] {parameters: amount \\ body:...}
edge [<-] (w1fun-left.center);
\node (E1-env) [below=of g env,yshift=5mm,draw,inner sep=2mm] {balance: amount}
edge [->] (g env);
\node [left=of E1-env,xshift=5mm] {E1} edge [->] (E1-env);
\path (w1fun-right.center) edge[->,to path={-| (\tikztotarget)}] (E1-env.south);
\end{tikzpicture}
#+end_src
This looks more or less matching the original, even looking better, but I wonder what are the most obvious (and less obvious) ways to make the code more idiomatic.
In particular I don't like:
- "two dot" scope
- "tokens" are still black and thus invisible
- manual xshifts and yshifts
- I'd like some macro, or something like that to define for later usage, if I want to make bigger environment diagrams, to make something like \environment or \closure.
- Any other ways to make this look better.