2
%% Copyright 2006 Tommy Ekola <tek@kth.se>
4
% This work may be distributed and/or modified under the conditions of
5
% the LaTeX Project Public License, either version 1.3 of this license
6
% or (at your option) any later version. The latest version of this
7
% license is in http://www.latex-project.org/lppl.txt
9
% This work has the LPPL maintenance status `maintained'. The Current
10
% Maintainer of this work is Tommy Ekola. The Base Interpreter is
13
vardef setup_extensiblebrace (expr source_file, cmdname) =
15
scantokens ("input tgbx0000");
17
scantokens ("input " & source_file);
19
expandafter def scantokens cmdname expr p =
20
scantokens (cmdname & "__tgbxww")(p)
23
expandafter vardef scantokens (cmdname & "__tgbxww " & "(expr apth) " &
26
"save u, designsize, curve, stem, hair, rule_thickness, eps, fine, " &
29
"u# := " & decimal u# & ";" &
30
"designsize := " & decimal designsize & ";" &
31
"curve# := " & decimal curve# & ";" &
32
"stem# := " & decimal stem# & ";" &
33
"hair# := " & decimal hair# & ";" &
34
"rule_thickness# := " & decimal rule_thickness# & ";" &
35
"eps := " & decimal eps & ";" &
36
"fine# := " & decimal fine# & ";" &
37
"fudge := " & decimal fudge & ";" &
39
% Time for middle piece
41
"save st; numeric st;" &
42
"if unknown " & cmdname & "_middle_time:" &
43
" st := arctime (arclength apth)/2 of apth;" &
44
"else: st:=" & cmdname & "_middle_time; fi")
49
save w; numeric w; w :=12u#;
50
save h; numeric h; h :=0;
51
save dh; numeric dh; dh:=0.6designsize;
52
save dw; numeric dw; dw:=curve#-stem#;
53
save d; numeric d; d :=1.5dh;
54
save min_breadth; numeric min_breadth#;
55
min_breadth#:=rule_thickness#+0.6dw;
56
save heavy_rule_thickness; numeric heavy_rule_thickness#;
57
heavy_rule_thickness#:=3rule_thickness#;
60
numeric x[],x[]',x[]l,x[]'l,x[]r,x[]'r,
61
y[],y[]',y[]l,y[]'l,y[]r,y[]'r;
66
pickup if fine#=0: nullpen else: pencircle scaled fine# fi;
68
penpos7(min_breadth#,0); penpos7'(min_breadth#,0);
69
penpos6(heavy_rule_thickness#,0);
70
rt x7r = rt x7'r = w-1.5u#+.5min_breadth#;
71
lft x6l = .5w-.5heavy_rule_thickness#;
72
bot y7 = -d; y6 = .5[h+eps,y7]; y7'-y7 = min_breadth#-fine#;
74
penpos1(min_breadth#,0); penpos1'(min_breadth#,0);
75
penpos2(heavy_rule_thickness#,0);
76
rt x1r = rt x1'r = w-1.5u#+.5min_breadth#;
78
top y1 = h; y2 = .5[y1,-d-eps]; y1-y1' = min_breadth#-fine#;
80
penpos4'(min_breadth#,0); penpos4(min_breadth#,0);
81
penpos5(heavy_rule_thickness#,0);
82
penpos3(heavy_rule_thickness#,0);
83
lft x4l=lft x4'l=1.5u#-.5min_breadth#;
84
lft x5l=.5w-.5heavy_rule_thickness#;
86
y4-y4'=min_breadth#-fine#; y4=0;
87
lft x3l = .5w-.5heavy_rule_thickness#;
88
y3-y4 = (h+2d+2eps)/4;
91
vardef mapto(text t) =
93
numeric x,x_[],y,y_[];
94
for z=t: z_[incr n]:=z; endfor;
96
z_2 = z_1 transformed T;
97
z_4 = z_3 transformed T;
98
z_6 = z_5 transformed T;)
102
% The bottom part of the brace
105
vardef bottom_part(expr T) =
106
filldraw (z6l{down}...{3(x7l-x6l),y7-y6}z7l
107
--z7r--z7'r{3(x6r-x7r),y6-y7'}...{up}z6r--z6l & cycle)
113
abs(point 0 of apth - (point s of apth + (.5w-1.5u#+.5min_breadth#)
114
*(unitvector (direction s of apth) rotated 90)))
115
< ((d/2) ++ (.5w-1.5u#+.5min_breadth#))
118
save tolerence; tolerence := epsilon;
121
save T; transform T; % transform for the bottom part
122
if arclength apth = 0:
123
T:=identity shifted (point (length apth) of apth - z7r);
124
elseif arclength apth < y1-y2+y3-y5+y6-y7:
126
.25[point 0 of apth, point (length apth) of apth]+
127
+abs(x7r-x6l)*(unitvector (point (length apth) of apth -
128
point 0 of apth) rotated 90),
130
.25[point 0 of apth, point (length apth) of apth]+
131
+abs(x7r-x6r)*(unitvector (point (length apth) of apth -
132
point 0 of apth) rotated 90),
136
s := solve f(0,length apth);
139
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#)
140
*(unitvector (direction s of apth) rotated 90),
143
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#)
144
*(unitvector (direction s of apth) rotated 90),
150
% The top part of the brace
153
vardef top_part(expr T) =
154
filldraw (z1l{3(x2l-x1l),y2-y1}...{down}z2l
155
--z2r{up}...{3(x1r-x2r),y1'-y2}z1'r--z1r--cycle)
161
abs(point (length apth) of apth
162
- (point t of apth + (.5w-1.5u#+.5min_breadth#)
163
*(unitvector (direction t of apth) rotated 90)))
164
< ((d/2) ++ (.5w-1.5u#+.5min_breadth#))
169
transform T; % transform the top part
170
if arclength apth = 0:
171
T:=identity shifted (point (length apth) of apth - z1r);
172
elseif arclength apth < y1-y2+y3-y5+y6-y7:
174
.75[point 0 of apth, point (length apth) of apth] +
175
abs(x1r-x2l)*(unitvector (point (length apth) of apth -
176
point 0 of apth) rotated 90),
178
.75[point 0 of apth, point (length apth) of apth] +
179
abs(x1r-x2r)*(unitvector (point (length apth) of apth -
180
point 0 of apth) rotated 90),
182
point (length apth) of apth);
184
t := solve g(length apth,0);
187
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#)
188
*(unitvector (direction t of apth) rotated 90),
191
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#)
192
*(unitvector (direction t of apth) rotated 90),
194
point (length apth) of apth);
198
% The lower part of the middle piece
200
save middle_part_bottom;
201
vardef middle_part_bottom(expr T) =
202
(.5[z4r,z4'r]{3(x5r-x4r),y5-.5[y4,y4']}...{down}z5r
203
--z5l{up}...{3(x4l-x5l),y4'-y5}z4'l) transformed T
209
+(w-3u#)*(unitvector (direction st of apth) rotated 90)
210
-(point ss of apth + (.5w-1.5u#+.5min_breadth#)
211
*(unitvector (direction ss of apth) rotated 90)))
212
> ((h+2d+2eps)/4+(min_breadth#-fine#)/2) ++ (.5w-1.5u#-.5min_breadth#)
217
if arclength apth = 0:
218
T:=identity shifted (point (length apth) of apth - z4'l);
219
elseif arclength apth < y1-y2+y3-y5+y6-y7:
220
T:=mapto(.5[z4r,z4'r],
221
.5[point 0 of apth, point (length apth) of apth]+
222
abs(x1r-.5[x4r,x4'r])
223
*(unitvector (point (length apth) of apth -
224
point 0 of apth) rotated 90),
226
.25[point 0 of apth, point (length apth) of apth]+
227
abs(x1r-x5l)*(unitvector (point (length apth) of apth -
228
point 0 of apth) rotated 90),
230
.25[point 0 of apth, point (length apth) of apth]+
231
abs(x1r-x5r)*(unitvector (point (length apth) of apth -
232
point 0 of apth) rotated 90));
234
ss := solve ff(0,st);
235
T:=mapto(.5[z4r,z4'r],
237
+(w-3u#)*(unitvector (direction st of apth) rotated 90),
240
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#)
241
*(unitvector (direction ss of apth) rotated 90),
244
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#)
245
*(unitvector (direction ss of apth) rotated 90));
249
pb:=middle_part_bottom(T);
251
% The upper part of the middle piece
253
save middle_part_top;
254
vardef middle_part_top(expr T) =
255
(z4l{3(x3l-x4l),y3-y4}...{up}z3l--z3r{down}
256
...{3(x4r-x3r),.5[y4,y4']-y3}.5[z4r,z4'r]) transformed T
262
+(w-3u#)*(unitvector (direction st of apth) rotated 90)
263
-(point tt of apth + (.5w-1.5u#+.5min_breadth#)
264
*(unitvector (direction tt of apth) rotated 90)))
265
> ((h+2d+2eps)/4+(min_breadth#-fine#)/2) ++ (.5w-1.5u#-.5min_breadth#)
270
if arclength apth = 0:
271
T:=identity shifted (point (length apth) of apth - z4l);
272
elseif arclength apth < y1-y2+y3-y5+y6-y7:
273
T:=mapto(.5[z4r,z4'r],
274
.5[point 0 of apth, point (length apth) of apth]+
275
abs(x1r-.5[x4r,x4'r])
276
*(unitvector (point (length apth) of apth -
277
point 0 of apth) rotated 90),
279
.75[point 0 of apth, point (length apth) of apth]+
280
abs(x1r-x3l)*(unitvector (point (length apth) of apth -
281
point 0 of apth) rotated 90),
283
.75[point 0 of apth, point (length apth) of apth]+
284
abs(x1r-x3r)*(unitvector (point (length apth) of apth -
285
point 0 of apth) rotated 90));
287
tt := solve gg(length apth, st);
288
T := mapto(.5[z4r,z4'r],
290
+(w-3u#)*(unitvector (direction st of apth) rotated 90),
293
+(.5w-1.5u#+.5min_breadth#+.5heavy_rule_thickness#)
294
*(unitvector (direction tt of apth) rotated 90),
297
+(.5w-1.5u#+.5min_breadth#-.5heavy_rule_thickness#)
298
*(unitvector (direction tt of apth) rotated 90));
302
ptt:=middle_part_top(T);
304
filldraw pb--ptt--cycle text_;
306
% The extension parts
309
vardef extension_part(expr ss,tt) =
310
numeric stp; stp:=(ss-tt) div 5pt;
314
pickup pencircle scaled (heavy_rule_thickness#+fine#);
317
draw for uu=ss step stp until tt-stp:
318
point uu of apth + (.5w-1.5u#+.5min_breadth#)
319
*(unitvector (direction uu of apth) rotated 90)
320
{direction uu of apth} ..
322
{direction tt of apth}
323
point tt of apth + (.5w-1.5u#+.5min_breadth#)
324
*(unitvector (direction tt of apth) rotated 90) text_;
328
if arclength apth > y1-y2+y3-y5+y6-y7:
329
extension_part(s,ss); extension_part(tt,t);