Add an intermezzo about substitution.
[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 / 50) ;
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{HDLine}
26 path a, b;
27 % Create a rectangle of the full size
28 a := origin -- (\MPvar{width}, 0mm);
29 % Randomize it a bit
30 b := a randomized (\overlaywidth / 100) ;
31 % And draw it
32 drawoptions (withpen pencircle scaled .75mm withcolor black dashed evenly) ;
33 draw b; 
34 \stopuseMPgraphic
35
36 % Draw a line with the given options. Accepts only the 'width' option. Be
37 % careful that these are metapost options, so use \the\textwidth instead of
38 % textwidth, and a metapost expression for arithmethic (e.g. 0.5 *
39 % \the\textwidth instead of 0.5\textwidth).
40 \def\HDLine[#1]%
41   {\setupMPvariables[HDLine][#1]%
42   \useMPgraphic{HDLine}}
43
44 \startuseMPgraphic{box}
45 path a, b;
46 % Create a rectangle of the full size
47 a := unitsquare xyscaled(\overlaywidth,\overlayheight);
48 % Randomize it a bit
49 b := a randomized (min(\overlayheight, \overlaywidth) / 25) ;
50 % And draw it
51 drawoptions (withpen pencircle scaled .75mm withcolor black) ;
52 draw b; 
53 \stopuseMPgraphic
54
55 \defineoverlay[box][\useMPgraphic{box}]
56
57 % Define \{start,stop}boxed with a nice metapost box around it.
58 \defineframedtext[boxed][width=fit,background=box,frame=off]
59
60 % Install the lambda calculus pretty-printer, as defined in pret-lam.lua.
61 \installprettytype [LAM] [LAM]
62 % Define \startlambda \stoplambda
63 \definetyping[lambda][option=LAM,style=sans,before=\startboxed,after=\stopboxed,strip=auto]
64 % Define \startunboxedlambda \stopunboxedlambda
65 \definetyping[unboxedlambda][option=LAM,style=sans,strip=auto]
66
67 % Define \lam{} (since \lambda is taken)
68 \definetype[lam][option=LAM,style=sans]
69
70 % Install the transformation pretty-printer, as defined in pret-trans.lua.
71 \installprettytype [TRANS] [TRANS]
72 % Define \starttrans \stoptrans
73 \definetyping[trans][option=TRANS,style=normal,before=\startboxed,after=\stopboxed,strip=auto]
74
75 % Install the haskell pretty-printer, as defined in pret-haskell.lua.
76 \installprettytype [HASKELL] [HASKELL]
77 % Define \starthaskell \stophaskell
78 \definetyping[haskell][option=HASKELL,before=\startboxed,after=\stopboxed,strip=auto]
79 % Define \hs
80 \definetype[hs][option=HASKELL,style=mono]
81
82 % Type the given buffer with the lambda typing style.
83 % e.g., \typebufferlam{buffname}
84 \define[1]\typebufferlam{
85   % We can't use \startlambda here defined by definetyping[lambda] above when
86   % typing buffers, so instead we'll redfine the options here.
87   \setuptyping[option=LAM,style=sans,before=,after=,strip=auto]
88   \startboxed
89   \typebuffer[#1]
90   \stopboxed
91   % Reset the typing options
92   \setuptyping[option=none,style=\tttf,strip=auto]
93 }
94
95 % Type the given buffer with the haskell typing style.
96 % e.g., \typebufferhs{buffname}
97 \define[1]\typebufferhs{
98   % We can't use \startlambda here defined by definetyping[lambda] above when
99   % typing buffers, so instead we'll redfine the options here.
100   \setuptyping[option=HASKELL,style=mono,strip=auto]
101   \startboxed
102   \typebuffer[#1]
103   \stopboxed
104   % Reset the typing options
105   \setuptyping[option=none,style=\tttf,strip=auto]
106 }
107
108 % Display a useMPgraphic in a pretty box
109 \define[1]\boxedgraphic{
110   \startboxed
111   \useMPgraphic{#1}
112   \stopboxed
113 }
114
115 % Define a "definition" float. We would like some more backgroundoffset, but
116 % this offset doesn't move the caption, causing the border to cross the
117 % caption... Also, centering the content didn't seem to work...
118 % TODO: Make more pretty.
119 \definefloat[definition][definitions]
120 \setupfloat[definition][background=box,backgroundoffset=1mm]
121
122 % Define an "example" float. Don't add box around it, since an example will
123 % commonly contain two boxed items (Before / after, code / picture).
124 \definefloat[example][examples]
125 \setupcaption[example][location=top] % Put captions on top
126
127 % Margin magic taken from
128 % http://www.pragma-ade.com/general/manuals/details.pdf By setting negative
129 % margin distances, we put our float inside the outer margin. I think we set
130 % both left and right margin distance, because we don't know what will be the
131 % outer margin (and it will probably only use the distance of the margin it's
132 % actually aligning against).
133 % We also set an offset, to prevent protruding text (overfull hboxes) from
134 % jamming into the intermezzo. Also, some extra space is easier on the eye
135 % (However, the intermezzo is moved to the right by this offset, instead of
136 % moving the text to left. We can't increase the offset by much...)
137 \setupfloat[intermezzo][offset=.3cm,leftmargindistance=-\leftmarginwidth, rightmargindistance=-\rightmarginwidth, default={outer}]
138 \setupcaption[intermezzo][location=top,number=no] % Put captions on top
139
140 \setupheads[aligntitle=float]
141 % vim: set sw=2 sts=2 expandtab: