forked from jemmybutton/byrne-euclid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preamble.tex
321 lines (283 loc) · 12.9 KB
/
preamble.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
\newdimen\topmargin
\topmargin=\topspace
\advance \topmargin by \headerdistance
\newcount\mpInst
\mpInst = 0
% Every time new proposition is introduced, we define new picture
% with all its colors and styles, preceded with inclusion of byrne.mp library.
% It is done with \startMPinclusions in ConTeXt.
% Note that every time new MPinstance is defined .
% Before doing so we clear everything after previous definitions (explained below)
% In case the picture extends the previous picture, CreateNewInstanceForPicturefalse
% can be set temporarily
\def\mpPre{}
\def\mpPost{}
\newif\ifCreateNewInstanceForPicture
\CreateNewInstanceForPicturetrue
\def\defineNewPicture{\dodoubleempty\definenewpicture}
\def\definenewpicture[#1][#2]#3{\ignorespaces
\iffirstargument\ignorespaces
\global\def\sfA{#1}\ignorespaces
\else\ignorespaces
\global\def\sfA{1/3}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\global\def\sfB{#2}\ignorespaces
\else\ignorespaces
\global\def\sfB{defaultScaleFactor}\ignorespaces
\fi\ignorespaces
\undefineList\ignorespaces
\def\undefineList{}\ignorespaces
\ifCreateNewInstanceForPicture\ignorespaces
\global\advance \mpInst by 1\ignorespaces
\global\def\currentInstance{\the\mpInst}\ignorespaces
\defineMPinstance[\currentInstance]\ignorespaces
\fi\ignorespaces
\startreusableMPgraphic{\currentInstance::currentPicture}
\ifCreateNewInstanceForPicture input byrne; \fi
\mpPre
startMainPictureMode;
projectionAngle := (0, 0, 0);
linecap := butt;
scaleFactor := \sfB;
#3
scaleFactor := \sfA;
generateAngleSynonyms;
generateLineSynonyms;
stopMainPictureMode;
\mpPost
\stopreusableMPgraphic\ignorespaces\setbox0\vbox{\reuseMPgraphic{\currentInstance::currentPicture}}\global\addToUndefineList{#2}\ignorespaces}
\def\defineNewPictureBasedOnOld{\dodoubleempty\definenewpicturebasedonold}
\def\definenewpicturebasedonold[#1][#2]#3{\ignorespaces
\CreateNewInstanceForPicturefalse
\ifsecondargument\ignorespaces
\defineNewPicture[#1][#2]{#3}\ignorespaces
\else\ignorespaces
\iffirstargument\ignorespaces
\defineNewPicture[#1]{#3}\ignorespaces
\else\ignorespaces
\defineNewPicture{#3}
\fi\ignorespaces
\fi\ignorespaces
\CreateNewInstanceForPicturetrue
}
% Every time some simple picture is drawn, new macro is defined
% with \markPictAsReady. If macro is defined, predefined picture is used.
% Every time new picture is added, instructions to undefine it are added with
% \addToUndefineList. \undefineList is thus generated command, that, once executed,
% undefines everything that was appended to it with \addToUndefineList.
\def\unmarkPictAsReady#1{\expandafter\let\csname #1\endcsname\relax}
\def\addToUndefineList#1{\expandafter\def\expandafter\undefineList\expandafter{\undefineList \unmarkPictAsReady{#1}}}
\def\undefineList{}
\addToUndefineList{lastPicture}
% When larger picture is defined, we can visualize its parts with \drawFromCurrentPicture
% First (optional) argument is for picture's vertical alignment relative to the string
% Currently only `middle' and anything other (for `top') is working
% Second (optional) argument is for picture's name for future reuse
% If picture with the same name exists, it's not defined again.
% Third argument is MP code for picture itself.
% To actually define an inline picture \defineFromCurrentPicture is called.
% The latter can also be called separately, which can be convenient
% if one wants to define multiple inline pictures in one place.
% Whenever everything is defined, \drawDefinedPicture macro is called for
\def\drawFromCurrentPicture{\dodoubleempty\drawfromcurrentpicture}
\def\drawfromcurrentpicture[#1][#2]#3{{\ignorespaces
\iffirstargument\ignorespaces
\global\def\dfcpl{#1}\ignorespaces
\else\ignorespaces
\global\def\dfcpl{middle}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\expandafter\ifx\csname #2\endcsname\relax\ignorespaces
\defineFromCurrentPicture{\dfcpl}{#2}{#3}\ignorespaces
\global\addToUndefineList{#2}\ignorespaces
\else\ignorespaces
\global\def\lastPict{#2}\ignorespaces
\fi\ignorespaces
\else\ignorespaces
\defineFromCurrentPicture{\dfcpl}{lastPicture}{#3}\ignorespaces
\fi\ignorespaces
\csname\lastPict\endcsname}}
\def\defineFromCurrentPicture#1#2#3{\ignorespaces
\startreusableMPgraphic{\currentInstance::#2}
startOffspringPictureMode;
linecap := butt;
#3
stopOffspringPictureMode;
\stopreusableMPgraphic\ignorespaces
\global\def\lastPict{#2}\ignorespaces
\global\expandafter\edef\csname\lastPict\endcsname{{\noexpand\drawDefinedPicture{\expandafter\lastPict}{\expandafter#1}}}}
% \drawDefinedPicture draws defined and named picture, aligned as needed and,
% possibly, with margins modified with \offsetPicture (i. e., if we want picture to act as if it's less tall that it actually is,
% we put some value as its first argument, if we want picture to be less deep, we use second argument, and place picture
% itself as third).
\newdimen\pictOffsetTop
\newdimen\pictOffsetBottom
\pictOffsetTop=0pt
\pictOffsetBottom=0pt
\def\offsetPicture#1#2#3{{\pictOffsetTop=#1\pictOffsetBottom=#2#3\pictOffsetTop=0pt\pictOffsetBottom=0pt}}
\newdimen\midht
\newdimen\middp
\def\drawDefinedPicture#1#2{{\ignorespaces
\setbox0\vbox{\reuseMPgraphic{\currentInstance::#1}}\ignorespaces
\ifdim\ht0<\baselineskip\advance\pictOffsetTop by 1pt\advance\pictOffsetBottom by 1pt\fi\ignorespaces
\setbox0\vbox{\vskip2pt\vskip-\pictOffsetTop\box0\vskip2pt\vskip-\pictOffsetBottom}\ignorespaces
\def\tmpmiddle{middle}\ignorespaces
\def\tmpalignment{#2}\ignorespaces
\ifx\tmpalignment\tmpmiddle\ignorespaces
\middp=0.5\ht0
\midht=0.5\ht0
\advance\middp by -3pt
\advance\midht by 3pt
\else\ignorespaces
\middp=0pt
\midht=\ht0
\advance\middp by 3pt
\advance\midht by -3pt
\fi\ignorespaces
\advance\middp by 0.5\pictOffsetTop
\advance\midht by -0.5\pictOffsetTop
\advance\middp by -0.5\pictOffsetBottom
\advance\midht by 0.5\pictOffsetBottom
\dp0=\middp
\ht0=\midht
\nobreak\hskip0pt\nobreak\,\nobreak\box0\,\ignorespaces
}}
% Some convenient shorthand macros for commonly used derivations of definition picture are defined below
\def\drawCurrentPicture{\reuseMPgraphic{\currentInstance::currentPicture}}
\def\drawUnitLine{\dosingleempty\drawunitline}
\def\drawunitline[#1]#2{{\ignorespaces
\iffirstargument\ignorespaces
\drawFromCurrentPicture[middle][uline#2#1]{startAutoLabeling;draw byNamedCompoundLine(#1, 0)(#2);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[middle][uline#2]{startAutoLabeling;draw byNamedCompoundLine(1cm, 0)(#2);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawProportionalLine#1{\drawFromCurrentPicture[middle][lineprop#1]{startAutoLabeling;draw byNamedCompoundLine(1cm, 1)(#1);stopAutoLabeling;}}
\def\drawSizedLine{\dosingleempty\drawsizedline}
\def\drawsizedline[#1]#2{{\ignorespaces
\iffirstargument\ignorespaces
\drawFromCurrentPicture[middle][linesized#2#1]{startAutoLabeling;draw byNamedCompoundLine(#1, 2)(#2);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[middle][linesized#2]{startAutoLabeling;draw byNamedCompoundLine(2cm, 2)(#2);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawUnitRay{\dosingleempty\drawunitray}
\def\drawunitray[#1]#2{{\ignorespaces
\iffirstargument\ignorespaces
\drawFromCurrentPicture[middle][uray#2#1]{startAutoLabeling;draw byNamedCompoundRay(#1, 0)(#2);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[middle][uray#2]{startAutoLabeling;draw byNamedCompoundRay(1cm, 0)(#2);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawProportionalRay#1{\drawFromCurrentPicture[middle][rayprop#1]{startAutoLabeling;draw byNamedCompoundRay(1cm, 1)(#1);stopAutoLabeling;}}
\def\drawSizedRay{\dosingleempty\drawsizedray}
\def\drawsizedray[#1]#2{{\ignorespaces
\iffirstargument\ignorespaces
\drawFromCurrentPicture[middle][raysized#2#1]{startAutoLabeling;draw byNamedCompoundRay(#1, 2)(#2);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[middle][raysized#2]{startAutoLabeling;draw byNamedCompoundRay(2cm, 2)(#2);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawUnitIndLine{\dosingleempty\drawunitindline}
\def\drawunitindline[#1]#2{{\ignorespaces
\iffirstargument\ignorespaces
\drawFromCurrentPicture[middle][uindline#2#1]{startAutoLabeling;draw byNamedCompoundIndLine(#1, 0)(#2);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[middle][uindline#2]{startAutoLabeling;draw byNamedCompoundIndLine(1cm, 0)(#2);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawProportionalIndLine#1{\drawFromCurrentPicture[middle][lineindprop#1]{startAutoLabeling;draw byNamedCompoundIndLine(1cm, 1)(#1);stopAutoLabeling;}}
\def\drawSizedIndLine{\dosingleempty\drawsizedindline}
\def\drawsizedindline[#1]#2{{\ignorespaces
\iffirstargument\ignorespaces
\drawFromCurrentPicture[middle][lineindsized#2#1]{startAutoLabeling;draw byNamedCompoundIndLine(#1, 2)(#2);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[middle][lineindsized#2]{startAutoLabeling;draw byNamedCompoundIndLine(2cm, 2)(#2);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawTwoRightAngles{\ignorespaces
\drawFromCurrentPicture[middle][tworightangles]{draw twoRightAngles;}}
\def\drawRightAngle{\ignorespaces
\drawFromCurrentPicture[middle][onerightangle]{draw rightAngle;}}
\def\drawAngle#1{\drawFromCurrentPicture[middle][angle#1]{startAutoLabeling;draw byNamedAngleWithDummySides(#1);stopAutoLabeling;}}
\def\drawAngleWithSides#1{\drawFromCurrentPicture[middle][anglewithsides#1]{startAutoLabeling;draw byNamedAngleSides(#1)();stopAutoLabeling;}}
\def\drawPolygon{\dodoubleempty\drawpolygon}
\def\drawpolygon[#1][#2]#3{{\ignorespaces
\iffirstargument\ignorespaces
\global\def\plal{#1}\ignorespaces
\else\ignorespaces
\global\def\plal{middle}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\drawFromCurrentPicture[\plal][#2]{startAutoLabeling;draw byNamedPolygon(#3);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[\plal][polygon#3]{startAutoLabeling;draw byNamedPolygon(#3);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawCircle{\dodoubleempty\drawcircle}
\def\drawcircle[#1][#2]#3{{\ignorespaces
\iffirstargument\ignorespaces
\global\def\plal{#1}\ignorespaces
\else\ignorespaces
\global\def\plal{middle}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\drawFromCurrentPicture[\plal][circle#3]{
startAutoLabeling;
startTempScale(#2);
draw byNamedCircle(#3);
stopTempScale;
stopAutoLabeling;
}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[\plal][circle#3]{startAutoLabeling;draw byNamedCircle(#3);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawArc{\dodoubleempty\drawarc}
\def\drawarc[#1][#2]#3{{\ignorespaces
\iffirstargument\ignorespaces
\global\def\plal{#1}\ignorespaces
\else\ignorespaces
\global\def\plal{middle}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\drawFromCurrentPicture[\plal][arc#3]{
startAutoLabeling;
startTempScale(#2);
draw byNamedArc(#3);
stopTempScale;
stopAutoLabeling;
}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[\plal][arc#3]{startAutoLabeling;draw byNamedArc(#3);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawLine{\dodoubleempty\drawline}
\def\drawline[#1][#2]#3{{\ignorespaces
\iffirstargument\ignorespaces
\global\def\plal{#1}\ignorespaces
\else\ignorespaces
\global\def\plal{middle}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\drawFromCurrentPicture[\plal][#2]{startAutoLabeling;draw byNamedLineSeq(0)(#3);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[\plal][line#3]{startAutoLabeling;draw byNamedLineSeq(0)(#3);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawPointM#1{\drawFromCurrentPicture[middle][pointm#1]{startAutoLabeling; draw byNamedPointMark(#1); stopAutoLabeling;}}
\def\drawPointL{\dodoubleempty\drawpointl}
\def\drawpointl[#1][#2]#3{{\ignorespaces
\iffirstargument\ignorespaces
\global\def\plal{#1}\ignorespaces
\else\ignorespaces
\global\def\plal{middle}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\drawFromCurrentPicture[\plal][pointl#3-#2]{startAutoLabeling; draw byNamedPointLines(#3,"#2"); stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[\plal][pointl#3]{startAutoLabeling; draw byNamedPointLines(#3,""); stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}
\def\drawMagnitude{\dodoubleempty\drawmagnitude}
\def\drawmagnitude[#1][#2]#3{{\ignorespaces
\iffirstargument\ignorespaces
\global\def\plal{#1}\ignorespaces
\else\ignorespaces
\global\def\plal{middle}\ignorespaces
\fi\ignorespaces
\ifsecondargument\ignorespaces
\drawFromCurrentPicture[\plal][magnitude#2#3]{startAutoLabeling;draw byNamedMagnitude(#2)(#3);stopAutoLabeling;}\ignorespaces
\else\ignorespaces
\drawFromCurrentPicture[\plal][magnitude#3]{startAutoLabeling;draw byNamedMagnitude(0)(#3);stopAutoLabeling;}\ignorespaces
\fi\ignorespaces}}