5efe1df0f0ad9aaeed8a510709e6ab490b212eeb
[matthijs/master-project/report.git] / Utils / Lambda.tex
1 %
2 % Some utilities for formatting (extended) lambda calculus and
3 % transformations.
4 %
5
6 \startuseMPgraphic{HLine}
7 path a, b;
8 % Create a rectangle of the full size
9 a := origin -- (\MPvar{width}, 0mm);
10 % Randomize it a bit
11 b := a randomized (\overlaywidth / 25) ;
12 % And draw it
13 drawoptions (withpen pencircle scaled .75mm withcolor black) ;
14 draw b; 
15 \stopuseMPgraphic
16
17 % Draw a line with the given options. Accepts only the 'width' option. Be
18 % careful that these are metapost options, so use \the\textwidth instead of
19 % textwidth, and a metapost expression for arithmethic (e.g. 0.5 *
20 % \the\textwidth instead of 0.5\textwidth).
21 \def\HLine[#1]%
22   {\setupMPvariables[HLine][#1]%
23   \useMPgraphic{HLine}}
24
25 \startuseMPgraphic{box}
26 path a, b;
27 % Create a rectangle of the full size
28 a := unitsquare xyscaled(\overlaywidth,\overlayheight);
29 % Randomize it a bit
30 b := a randomized (min(\overlayheight, \overlaywidth) / 25) ;
31 % And draw it
32 drawoptions (withpen pencircle scaled .75mm withcolor black) ;
33 draw b; 
34 \stopuseMPgraphic
35
36 \defineoverlay[box][\useMPgraphic{box}]
37
38 % Define \{start,stop}boxed with a nice metapost box around it.
39 \defineframedtext[boxed][width=fit,background=box,frame=off]
40
41 % Install the lambda calculus pretty-printer, as defined in pret-lam.lua.
42 \installprettytype [LAM] [LAM]
43 % Define \startlambda \stoplambda
44 \definetyping[lambda][option=LAM,style=sans,before=\startboxed,after=\stopboxed]
45
46 % Define \lam{} (since \lambda is taken)
47 \definetype[lam][option=LAM,style=sans]
48
49 % Install the transformation pretty-printer, as defined in pret-trans.lua.
50 \installprettytype [TRANS] [TRANS]
51 % Define \starttrans \stoptrans
52 \definetyping[trans][option=TRANS,style=normal,before=\startboxed,after=\stopboxed]
53
54 % Install the haskell pretty-printer, as defined in pret-haskell.lua.
55 \installprettytype [HASKELL] [HASKELL]
56 % Define \starthaskell \stophaskell
57 \definetyping[haskell][option=HASKELL,before=\startboxed,after=\stopboxed]
58 % Define \hs
59 \definetype[hs][option=HASKELL,style=mono]
60
61 % Type the given buffer with the lambda typing style.
62 % e.g., \typebufferlam{buffname}
63 \define[1]\typebufferlam{
64   % We can't use \startlambda here defined by definetyping[lambda] above when
65   % typing buffers, so instead we'll redfine the options here.
66   \setuptyping[option=LAM,style=sans,before=,after=]
67   \startboxed
68   \typebuffer[#1]
69   \stopboxed
70   % Reset the typing options
71   \setuptyping[option=none,style=\tttf]
72 }
73
74 % Display a useMPgraphic in a pretty box
75 \define[1]\boxedgraphic{
76   \startboxed
77   \useMPgraphic{#1}
78   \stopboxed
79 }