Put spaces in example and definition labels.
[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. Suppress page breaks directly before
63 % such a box (\page[no] only works directly after a paragraph break, so
64 % insert one).
65 \definetyping[lambda][option=LAM,style=sans,before={\par\page[no]\startboxed},after={\stopboxed},strip=auto]
66 % Define \startunboxedlambda \stopunboxedlambda
67 \definetyping[unboxedlambda][option=LAM,style=sans,strip=auto]
68
69 % Define \lam{} (since \lambda is taken)
70 \definetype[lam][option=LAM,style=sans]
71
72 % Install the transformation pretty-printer, as defined in pret-trans.lua.
73 \installprettytype [TRANS] [TRANS]
74 % Define \starttrans \stoptrans
75 \definetyping[trans][option=TRANS,style=normal,before={\par\page[no]\startboxed},after={\stopboxed},strip=auto]
76
77 % Install the haskell pretty-printer, as defined in pret-haskell.lua.
78 \installprettytype [HASKELL] [HASKELL]
79 % Define \starthaskell \stophaskell
80 \definetyping[haskell][option=HASKELL,before={\par\page[no]\startboxed},after={\stopboxed},strip=auto]
81 % Define \hs
82 \definetype[hs][option=HASKELL,style=mono]
83
84 % Define \startvhdl \stopvhdl
85 \definetyping[vhdl][numbering=line,before={\startboxed},after={\stopboxed}]
86
87 % Type the given buffer with the lambda typing style.
88 % e.g., \typebufferlam{buffname}
89 \define[1]\typebufferlam{
90   % We can't use \startlambda here defined by definetyping[lambda] above when
91   % typing buffers, so instead we'll redfine the options here.
92   \setuptyping[option=LAM,style=sans,before=,after=,strip=auto]
93   \startboxed
94   \typebuffer[#1]
95   \stopboxed
96   % Reset the typing options
97   \setuptyping[option=none,style=\tttf,strip=auto]
98 }
99
100 % Type the given buffer with the haskell typing style.
101 % e.g., \typebufferhs{buffname}
102 \define[1]\typebufferhs{
103   % We can't use \startlambda here defined by definetyping[lambda] above when
104   % typing buffers, so instead we'll redfine the options here.
105   \setuptyping[option=HASKELL,style=mono,strip=auto]
106   \startboxed
107   \typebuffer[#1]
108   \stopboxed
109   % Reset the typing options
110   \setuptyping[option=none,style=\tttf,strip=auto]
111 }
112
113 % Type the given buffer with the vhdl typing style.
114 % e.g., \typebuffervhdl{buffname}
115 \define[1]\typebuffervhdl{
116   % We can't use \startvhdl here defined by definetyping[vhdl] above when
117   % typing buffers, so instead we'll redefine the options here.
118   \setuptyping[style=mono,strip=auto,numbering=line]
119   \startboxed
120   \typebuffer[#1]
121   \stopboxed
122   % Reset the typing options
123   \setuptyping[option=none,style=\tttf,strip=auto]
124 }
125
126 % Display a useMPgraphic in a pretty box
127 \define[1]\boxedgraphic{
128   \startboxed
129   \useMPgraphic{#1}
130   \stopboxed
131 }
132
133 \setupcaption[figure][location=top] % Put captions on top
134 % Define an "example" float. Don't add box around it, since an example will
135 % commonly contain two boxed items (Before / after, code / picture).
136 % Make an example use the same numbering as a figure.
137 \definefloat[example][examples][figure]
138 \setupcaption[example][location=top] % Put captions on top
139 % Define a definition float that shares its numbering and setting with
140 % examples.
141 \definefloat[definition][definitions][figure]
142 \setupcaption[example][location=top] % Put captions on top
143 % Make sure the labels really say Definition and Example instead of
144 % Figure. This seems to be a bug in ConTeXt (\redodefinefloat in
145 % strc-flt.mkiv has \presetlabeltext[#1=\Word{#3}~]% which should
146 % reference #1 instead of #3).
147 \setuplabeltext[en][definition=Definition~]
148 \setuplabeltext[en][example=Example~]
149
150 % Margin magic taken from
151 % http://www.pragma-ade.com/general/manuals/details.pdf By setting negative
152 % margin distances, we put our float inside the outer margin. I think we set
153 % both left and right margin distance, because we don't know what will be the
154 % outer margin (and it will probably only use the distance of the margin it's
155 % actually aligning against).
156 % The default= option corresponds to the first option to \placefloat.
157 % outer puts it in the outer margin, none means no caption, high means
158 % no spacing at the top (placing it high wrt the text) and low means no
159 % spacing at the bottom.
160 \setupfloat[intermezzo][leftmargindistance=-\leftmarginwidth, rightmargindistance=-\rightmarginwidth, default={outer,none,low,high}]
161
162 % Let floats float next to titles, instead of inserting whitespace so a
163 % section head comes after a float.
164 \setupheads[aligntitle=float]
165
166 % A variant of \startquotation that puts a citation directly after the
167 % quote.
168 \long\def\startcitedquotation[#1]#2\stopcitedquotation
169     {\bgroup \par
170      \startnarrower
171        \symbol[leftquotation]%
172        #2\removeunwantedspaces
173        \symbol[rightquotation]%
174        \mbox{ }\cite[#1]
175      \stopnarrower
176      \par \egroup}
177
178 % vim: set sw=2 sts=2 expandtab: