| 1 |
% mathematical symbols by Anthony Phan. |
| 2 |
% file: mathbase.mf (base file) |
| 3 |
% last modification: May 16, 2005. |
| 4 |
|
| 5 |
mathbase := 1; % when |mathbase| is known, this file has been input |
| 6 |
|
| 7 |
newinternal slant, currentbreadth, math_spread, superness, stress; |
| 8 |
slant := 0; superness := 1/sqrt 2; stress := 0.5; |
| 9 |
|
| 10 |
string main_name_string, tmp_string, |
| 11 |
extra_beginchar_save, extra_endchar_save; |
| 12 |
|
| 13 |
picture tmp_picture; |
| 14 |
path tmp_path, tmpp_path; |
| 15 |
|
| 16 |
boolean true_size, tmp_boolean, dagesh; |
| 17 |
true_size := false;% see mathhbrw.mf |
| 18 |
|
| 19 |
pair both; both = (1, 1); |
| 20 |
|
| 21 |
def autorounded = interim autorounding := 2 enddef; |
| 22 |
|
| 23 |
def localtransform = save currenttransform; |
| 24 |
transform currenttransform; currenttransform |
| 25 |
enddef; |
| 26 |
|
| 27 |
numeric currentlocation_; |
| 28 |
|
| 29 |
vardef currentlocation = |
| 30 |
currentlocation_ := currentlocation_+1; |
| 31 |
currentlocation_-1 |
| 32 |
enddef; |
| 33 |
|
| 34 |
def main_name_with(suffix $) = |
| 35 |
scantokens(main_name_string & str$) |
| 36 |
enddef; |
| 37 |
|
| 38 |
def math_setup = |
| 39 |
autorounding := 0; smoothing := 0; |
| 40 |
appr# := u#+letter_fit#; Appr# := 1.5u#+letter_fit#; |
| 41 |
numeric paren_depth#, asc_depth#, body_depth#; |
| 42 |
0.5[body_height#, -paren_depth#] = math_axis#; |
| 43 |
0.5[asc_height#, -asc_depth#] = math_axis#; |
| 44 |
body_depth# := desc_depth#+body_height#-asc_height#; |
| 45 |
% |
| 46 |
define_pixels(u, dh, dish, stem_corr, vair_corr); |
| 47 |
define_whole_blacker_pixels(hair, stem, curve, |
| 48 |
cap_hair, cap_stem, cap_curve, dtsz, ast_curve, ast_stem); |
| 49 |
define_whole_vertical_blacker_pixels(vair, slab);% cap_bar... |
| 50 |
define_whole_vertical_pixels(body_height, asc_height, |
| 51 |
cap_height, fig_height, x_height, desc_depth, |
| 52 |
asc_depth, body_depth, paren_depth); |
| 53 |
define_whole_pixels(letter_fit, appr, Appr, |
| 54 |
crisp, tiny, fine, ast_size); |
| 55 |
define_corrected_pixels(o); |
| 56 |
define_horizontal_corrected_pixels(ho); |
| 57 |
lowres_fix(stem, curve) 1.2; |
| 58 |
lowres_fix(cap_stem, cap_curve) 1.2; |
| 59 |
lowres_fix(hair, cap_hair) 1.2; |
| 60 |
oo := vround(0.5o#*hppp*o_correction)+eps; |
| 61 |
dw := (curve#-stem#)*hppp; bold := curve#*hppp+blacker; |
| 62 |
vair' := vround(vair+vair_corr); |
| 63 |
% |
| 64 |
% usual pens. |
| 65 |
% |
| 66 |
clear_pen_memory; |
| 67 |
if fine = 0: fine := 1; fi |
| 68 |
null := 0; |
| 69 |
forsuffixes $ = null, crisp, tiny, fine: |
| 70 |
$.breadth := $; |
| 71 |
pickup if $ = 0: nullpen else: pencircle scaled $ fi; |
| 72 |
$ := $-eps; $.nib := savepen; breadth_[$.nib] := $; |
| 73 |
endfor |
| 74 |
$ := 0; |
| 75 |
forever: |
| 76 |
exitif unknown rth[$].#; |
| 77 |
rth[$] := ceiling(rth[$].#*hppp); |
| 78 |
pickup pencircle scaled rth[$]; |
| 79 |
rule.nib[$] := savepen; |
| 80 |
$ := $+1; |
| 81 |
endfor |
| 82 |
% |
| 83 |
% spreads |
| 84 |
% |
| 85 |
for $ = 0 upto 10: |
| 86 |
if known spread[$].#: |
| 87 |
spread[$] := 2ceiling(0.5spread[$].#*hppp); |
| 88 |
fi |
| 89 |
endfor |
| 90 |
% |
| 91 |
% current transform (slant is not taken into account) |
| 92 |
% |
| 93 |
currenttransform = identity |
| 94 |
yscaled aspect_ratio scaled granularity; |
| 95 |
% |
| 96 |
% proofing |
| 97 |
% |
| 98 |
standard_proofing; |
| 99 |
use_rule1; |
| 100 |
enddef; |
| 101 |
|
| 102 |
% The following environment enables people to draw a picture |
| 103 |
% almost like drawing a character. The resulting picture is |
| 104 |
% stored in $_picture and then it can be used in at any |
| 105 |
% place later. |
| 106 |
|
| 107 |
def beginpicture(suffix $)(expr w_sharp, h_sharp, d_sharp) = |
| 108 |
begingroup |
| 109 |
save picturename; |
| 110 |
w := hround(w_sharp*hppp); h := vround(h_sharp*hppp); |
| 111 |
d := vround(d_sharp*hppp); clearxy; clearit; clearpen; |
| 112 |
string picturename; picturename = str $ &"_picture"; |
| 113 |
enddef; |
| 114 |
|
| 115 |
def endpicture = |
| 116 |
expandafter picture scantokens picturename; |
| 117 |
scantokens picturename = currentpicture; |
| 118 |
endgroup |
| 119 |
enddef; |
| 120 |
|
| 121 |
vardef use_rule@# = |
| 122 |
rth := rth@#; rth# := rth@#.#; |
| 123 |
rule.nib := rule.nib@#; |
| 124 |
math_axis := vround(math_axis#*hppp-0.5rth)+0.5rth; |
| 125 |
enddef; |
| 126 |
|
| 127 |
def numeric_pickup_ primary q = |
| 128 |
currentpen := pen_[q]; |
| 129 |
pen_lft := pen_lft_[q]; pen_rt := pen_rt_[q]; |
| 130 |
pen_top := pen_top_[q]; pen_bot := pen_bot_[q]; |
| 131 |
currentpen_path := pen_path_[q]; |
| 132 |
if known breadth_[q]: currentbreadth := breadth_[q]; fi |
| 133 |
enddef; |
| 134 |
|
| 135 |
%def compute_spread(expr normal_spread, big_spread) = |
| 136 |
% spread# := math_spread[normal_spread, big_spread]; |
| 137 |
% spread := 2ceiling((spread#)*hppp/2) |
| 138 |
%enddef; |
| 139 |
|
| 140 |
def v_center(expr h_sharp) = |
| 141 |
.5h_sharp+math_axis#, .5h_sharp-math_axis# |
| 142 |
enddef; |
| 143 |
|
| 144 |
def ensure_centering_of(expr stem) = |
| 145 |
if hround 0.5(w-hround stem)+0.5hround stem<> 0.5w: |
| 146 |
change_width; fi |
| 147 |
enddef; |
| 148 |
|
| 149 |
vardef v_adjust(suffix $, $$)(expr middle, height) = |
| 150 |
top y$-middle = middle-bot y$$ = vround 0.5(height-rth)+0.5rth |
| 151 |
enddef; |
| 152 |
|
| 153 |
def arithmetic_bounds = |
| 154 |
12u#+2appr#, math_axis#+6u#, 6u#-math_axis# |
| 155 |
enddef; |
| 156 |
|
| 157 |
def padded expr del_sharp = |
| 158 |
charht := charht+del_sharp; chardp := chardp+del_sharp |
| 159 |
enddef; |
| 160 |
|
| 161 |
%vardef pos@#(expr b, d) = |
| 162 |
% if known b: if b <= currentbreadth: errmessage "bad pos"; fi fi |
| 163 |
% save d_; pair d_; d_ = dir d; |
| 164 |
% z@#r-z@#l+penoffset d_ of currentpen+penoffset -d_ of currentpen = b*d_; |
| 165 |
% x@# = .5(x@#l+x@#r); y@# = .5(y@#l+y@#r) enddef; |
| 166 |
|
| 167 |
vardef pos@#(expr b, d) = |
| 168 |
if known b: if b <= currentbreadth: errmessage "bad pos"; fi fi |
| 169 |
(x@#r-x@#l, y@#r-y@#l) = (b-currentbreadth, 0) rotated d; |
| 170 |
x@# = .5(x@#l+x@#r); y@# = .5(y@#l+y@#r) enddef; |
| 171 |
|
| 172 |
vardef stroke text t = |
| 173 |
forsuffixes e = l, r: path_.e := t;endfor |
| 174 |
if cycle path_.l: |
| 175 |
errmessage "Beware: `stroke' doesn't work with cycles"; |
| 176 |
fi |
| 177 |
path_.l -- reverse path_.r -- cycle |
| 178 |
enddef; |
| 179 |
|
| 180 |
% DIAGONALS |
| 181 |
|
| 182 |
def diag_width(expr $, $$) = |
| 183 |
$/abs sind angle $$ |
| 184 |
enddef; |
| 185 |
|
| 186 |
%vardef diag_height(expr $, $$) = |
| 187 |
% $/abs cosd angle $$ |
| 188 |
%enddef; |
| 189 |
|
| 190 |
% $ <---> $$$; $$ <---> $$$$. sign = +1 for \, -1 for /. |
| 191 |
|
| 192 |
vardef adjust_slanted_bar(suffix $, $$, $$$, $$$$)(expr thickness, sign) = |
| 193 |
save a, b; |
| 194 |
if abs(y$$-y$) = thickness: |
| 195 |
(a1, a2) = (z$$-z$); |
| 196 |
if a1 = 0: b = 0;% b should then be infinite. |
| 197 |
else: b = if sign<0: - fi (a1++a2)*((a1++a2)/2a1); |
| 198 |
fi |
| 199 |
else: |
| 200 |
a = angle(z$$-z$); |
| 201 |
b = (cosd(a)/sind(a) if sign<0: - else: + fi |
| 202 |
(((y$$-y$)/(thickness)/sind(a))+-+1)) |
| 203 |
/(((y$$-y$)/(thickness))**2-1)*(y$$-y$); |
| 204 |
fi |
| 205 |
z$$$ = (x$-b, y$); z$$$$ = (x$$+b, y$$) |
| 206 |
enddef; |
| 207 |
|
| 208 |
% supplementary points for diagonal strokes |
| 209 |
% as in cm's \#. (see MetaFontbook, p. 200--201) |
| 210 |
% Well, ... |
| 211 |
|
| 212 |
vardef diag_stroke.@#(suffix $, $$, s)(text y_list) = |
| 213 |
z$.@#--for y_ = y_list: |
| 214 |
(good.x(((x$.s-x$$.s)/(y$.s-y$$.s))*(y_-y$$r)+x$$.s), y_) |
| 215 |
+z$.@#-z$.s |
| 216 |
--endfor z$$.@# |
| 217 |
enddef; |
| 218 |
|
| 219 |
% CIRCLES, ELLIPSES AND RELATED THINGS |
| 220 |
|
| 221 |
primarydef w up_to_right z = |
| 222 |
w{0, ypart(z-w)} |
| 223 |
...(superness[xpart z, xpart w], |
| 224 |
superness[ypart w, ypart z]){z-w} |
| 225 |
...{xpart(z-w), 0}z |
| 226 |
enddef; |
| 227 |
|
| 228 |
let up_to_left = up_to_right; |
| 229 |
let down_to_right = up_to_right; |
| 230 |
let down_to_left = up_to_right; |
| 231 |
|
| 232 |
primarydef w right_to_up z = |
| 233 |
w{xpart(z-w), 0} |
| 234 |
...(superness[xpart w, xpart z], |
| 235 |
superness[ypart z, ypart w]){z-w} |
| 236 |
...{0, ypart(z-w)}z |
| 237 |
enddef; |
| 238 |
|
| 239 |
let right_to_down = right_to_up; |
| 240 |
let left_to_up = right_to_up; |
| 241 |
let left_to_down = right_to_up; |
| 242 |
|
| 243 |
def ellipse_set(suffix $, @, @@, $$) = |
| 244 |
alpha_ := slope*(x@-x$); beta_ := y$$-y$-slope*(x$$-x$); |
| 245 |
gamma_ := alpha_/beta_; |
| 246 |
y@-y$ = .5(beta_-alpha_*gamma_); |
| 247 |
x@@-x$ = -2gamma_*(x@-x$)/(1+gamma_*gamma_); |
| 248 |
y@@-y$$ = slope*(x@@-x$$) |
| 249 |
enddef; |
| 250 |
|
| 251 |
def hellipse_set(suffix $, @, @@, $$) = |
| 252 |
alpha_ := (y@-y$)/slope; beta_ := x$$-x$-(y$$-y$)/slope; |
| 253 |
gamma_ := alpha_/beta_; |
| 254 |
x@-x$ = .5(beta_-alpha_*gamma_); |
| 255 |
y@@-y$ = -2gamma_*(y@-y$)/(1+gamma_*gamma_); |
| 256 |
x@@-x$$ = (y@@-y$$)/slope |
| 257 |
enddef; |
| 258 |
|
| 259 |
vardef adjust_elliptic_arc(suffix $, $$, $$$) = |
| 260 |
save a, b; |
| 261 |
if known (y$$$-y$): a = (1+-+((y$$$-y$)/(y$$-y$))); |
| 262 |
x$$-x$ = (x$$$-x$)/(1+a); b = (1+-+((x$$$-x$$)/(x$$-x$))); |
| 263 |
else: b = (1+-+((x$$$-x$$)/(x$$-x$))); |
| 264 |
y$$$-y$ = (y$$-y$)*b; a = (1+-+((y$$$-y$)/(y$$-y$))); |
| 265 |
fi |
| 266 |
y$$$' = y$$; x$$$' = (((1-b)/a)*(b/a))[x$$$, x$$]; |
| 267 |
enddef; |
| 268 |
|
| 269 |
def flatcup(expr zi, zii, ziii) = |
| 270 |
zi..controls (xpart zi, flatness[ypart zi, ypart zii]) |
| 271 |
and (xpart zi, ypart zii) |
| 272 |
..zii..controls (xpart ziii, ypart zii) |
| 273 |
and (xpart ziii, flatness[ypart ziii, ypart zii])..ziii |
| 274 |
enddef; |
| 275 |
|
| 276 |
% DOTS |
| 277 |
|
| 278 |
boolean full_dot; full_dot := true; |
| 279 |
|
| 280 |
def dot(suffix $, $$) = |
| 281 |
autorounded; |
| 282 |
if full_dot: filldraw else: draw fi |
| 283 |
dot_path($, $$); full_dot := true; |
| 284 |
enddef; |
| 285 |
|
| 286 |
def dot_path(suffix $, $$) = |
| 287 |
(x$, 0.5[y$, y$$]) down_to_right (0.5[x$, x$$], y$) right_to_up |
| 288 |
(x$$, 0.5[y$, y$$]) up_to_left (0.5[x$, x$$], y$$) left_to_down |
| 289 |
(x$, 0.5[y$, y$$])...cycle |
| 290 |
enddef; |
| 291 |
|
| 292 |
vardef adjust_dot@#(expr center, diameter, h_fit, v_fit) = |
| 293 |
if v_fit: save y_min, y_max; |
| 294 |
bot y_min = vround(ypart center-0.5diameter)-eps; |
| 295 |
top y_max = vround(ypart center+0.5diameter)+eps; |
| 296 |
y@#'-ypart center = ypart center-y@# |
| 297 |
= max(y_max-ypart center, ypart center-y_min); |
| 298 |
else: |
| 299 |
bot y@# = vround(ypart center-0.5diameter)-eps; |
| 300 |
top y@#'-bot y@# = vround diameter+2eps; fi |
| 301 |
if h_fit: save x_min, x_max; |
| 302 |
lft x_min = hround(xpart center-0.5diameter)-eps; |
| 303 |
rt x_max = hround(xpart center+0.5diameter)+eps; |
| 304 |
x@#'-xpart center = xpart center-x@# |
| 305 |
= max(x_max-xpart center, xpart center-x_min); |
| 306 |
else: |
| 307 |
lft x@# = vround(xpart center-0.5diameter)-eps; |
| 308 |
rt x@#'-lft x@# = hround(diameter)+2eps; fi |
| 309 |
labels(@#, @#'); |
| 310 |
enddef; |
| 311 |
|
| 312 |
% VERY DESIGN DEPENDENT MACROS |
| 313 |
|
| 314 |
% DAGGERS AND ASTERISKS |
| 315 |
|
| 316 |
vardef dagger_stroke@#(expr height, curve, stem, u_) = |
| 317 |
save alpha, a, b, c, R; |
| 318 |
alpha = angle u_-90; R = 0.5(curve-currentbreadth); |
| 319 |
a = stress*(height-curve+0.5currentbreadth)+R; |
| 320 |
b = 0.5(stem-currentbreadth); |
| 321 |
c = (a*R-b*sqrt(a**2+b**2-R**2))/(a**2+b**2); |
| 322 |
z@#c-z@# = (height-0.5currentbreadth)*u_; |
| 323 |
z@#c-z@#b = R*u_; z@#d-z@#b = -a*u_; z@#a = (c*(R/a))[z@#b, z@#d]; |
| 324 |
penpos@#(2b, alpha); penpos@#d(2b, alpha); |
| 325 |
penpos@#a(2R*(1+-+c), alpha); penpos@#b(2R, alpha); |
| 326 |
penlabels(@#a, @#b, @#c, @#d, @#); |
| 327 |
z@#r{u_}...z@#a.r{z@#a.r-z@#d.r}...z@#b.r{u_}... |
| 328 |
(superness[z@#b, z@#b.r]+superness[z@#b, z@#c]-z@#b){z@#c-z@#b.r} |
| 329 |
...z@#c{z@#b.l-z@#b.r}... |
| 330 |
(superness[z@#b, z@#b.l]+superness[z@#b, z@#c]-z@#b){z@#b.l-z@#c} |
| 331 |
...z@#b.l{-u_}...z@#a.l{z@#d.l-z@#a.l}...{-u_}z@#l |
| 332 |
enddef; |
| 333 |
|
| 334 |
% ARROWS |
| 335 |
|
| 336 |
numeric arrow_height, arrow_width, arrow_breadth, arrow_stress, |
| 337 |
arrow_tense[], arrow_time, double_arrow_height, double_arrow_width, |
| 338 |
double_arrow_tense, double_arrow_flatness; |
| 339 |
|
| 340 |
boolean arrow_head_fitting; |
| 341 |
arrow_head_fitting := false; |
| 342 |
|
| 343 |
vardef arrow_head@#(expr p, side) = |
| 344 |
save a, t; numeric a[]; |
| 345 |
a1 = angle direction infinity of p; pos@#a(rth, a1-90); |
| 346 |
z@#a = point infinity of p |
| 347 |
if arrow_head_fitting: -0.5currentbreadth*dir a1 fi; |
| 348 |
t := xpart(p intersectiontimes (halfcircle rotated(a1+90) |
| 349 |
scaled (2arrow_stress*arrow_height-currentbreadth) |
| 350 |
shifted z@#a)); |
| 351 |
a2 := angle direction t of p; arrow_time := t; |
| 352 |
z@# = point t of p; pos@#(rth, a2-90); |
| 353 |
z@#-z@#c = (1-arrow_stress)*arrow_height*dir a2; |
| 354 |
z@#c.r-z@#c = z@#c-z@#c.l = 0.5(arrow_width-currentbreadth)*dir(a2-90); |
| 355 |
z@#b.r-z@#c.r = z@#b.l-z@#c.l = max(arrow_breadth-currentbreadth, 0)*dir a2; |
| 356 |
z@#b = p intersectionpoint (z@#b.r..z@#b.l); |
| 357 |
t := xpart(p intersectiontimes (halfcircle rotated(a1+90) |
| 358 |
scaled (2arrow_tense2[1, arrow_stress]*arrow_height-currentbreadth) |
| 359 |
shifted z@#a)); |
| 360 |
a3 = angle direction t of p; z@#' = point t of p; pos@#'(rth, a3-90); |
| 361 |
z@#a' = if arrow_tense1<1: |
| 362 |
p intersectionpoint (halfcircle rotated(a1+90) |
| 363 |
scaled(arrow_tense1[length(z@#b-z@#a), 0]*2) shifted z@#a); |
| 364 |
else: z@#a; fi |
| 365 |
filldraw |
| 366 |
if side = right: z@#a.l{-dir a1}...{-dir a2}z@#l |
| 367 |
else: z@#a...{z@#b.l-z@#a'}z@#b.l--z@#c.l{z@#'l-z@#c.l}...z@#l |
| 368 |
fi -- |
| 369 |
if side = left: z@#r{dir a2}...z@#a.r{dir a1} |
| 370 |
else: z@#r...{z@#c.r-z@#'r}z@#c.r--z@#b.r{z@#a'-z@#b.r}...z@#a |
| 371 |
fi -- cycle; |
| 372 |
labels(@#a'); penlabels(@#', @#a, @#b, @#c); |
| 373 |
arrow_head_fitting := false; |
| 374 |
enddef; |
| 375 |
|
| 376 |
vardef double_arrow_head@#(expr head, vect) = |
| 377 |
save a, b, u_, v_; pair u_, v_; |
| 378 |
u_ = unitvector vect; v_ = u_ rotated 90; |
| 379 |
z@# = z@#' = head; |
| 380 |
z@#-z@#m = double_arrow_height*u_; |
| 381 |
pos@#'(rth, angle u_-90); |
| 382 |
pos@#m(rth, angle u_-90); |
| 383 |
z@#-z@#b.r = z@#m-z@#m.b = 0.5rth*double_arrow_flatness*v_; |
| 384 |
a = angle(-double_arrow_height, 0.5double_arrow_width); |
| 385 |
b = (cosd(a)/sind(a)+ |
| 386 |
((0.5double_arrow_width/rth/sind(a))+-+1)) |
| 387 |
/((0.5double_arrow_width/rth)**2-1) |
| 388 |
*0.5double_arrow_width; |
| 389 |
z@#c.l = double_arrow_tense[z@#m.b, z@#b.r-b*u_]; |
| 390 |
z@#m-z@#a.l = 0.5double_arrow_width*v_; |
| 391 |
b := rth/abs sind(angle(z@#a.l-z@#c.l)-angle(-u_)); |
| 392 |
z@#a.r-z@#a.l = z@#c.r-z@#c.l = b*u_; |
| 393 |
z@#ab = 0.5[z@#a.r, z@#c.r]; |
| 394 |
penpos@#b(rth, angle(z@#b.r-z@#ab)-90); |
| 395 |
% |
| 396 |
save p, t; path p[]; numeric t[]; |
| 397 |
z@#a = 0.5[z@#a.r, z@#a.l]; |
| 398 |
p1 = z@#a{z@#ab-z@#a.r}...{z@#b.r-z@#ab}z@#b; |
| 399 |
p3 = z@#a.r{z@#ab-z@#a.r}...{z@#b.r-z@#ab}z@#b.r; |
| 400 |
p5 = if (z@#b.l-z@#) dotprod v_<0: |
| 401 |
z@#'l+(u_ dotprod (z@#b.l-z@#))*u_-- fi |
| 402 |
z@#b.l{z@#ab-z@#b.r}...{z@#a.r-z@#ab}z@#a.l; |
| 403 |
p2 = reverse p1 reflectedabout (z@#, z@#m); |
| 404 |
p4 = reverse p3 reflectedabout (z@#, z@#m); |
| 405 |
p6 = reverse p5 reflectedabout (z@#, z@#m); |
| 406 |
t5 = xpart(p5 intersectiontimes (z@#+eps*v_ .. z@#m+eps*v_)); |
| 407 |
t6 = xpart(p6 intersectiontimes (z@#-eps*v_ .. z@#m-eps*v_)); |
| 408 |
fill p3--z@#+eps*v_--subpath (t5, length p5) of p5--cycle; |
| 409 |
fill z@#-eps*v_--p4--subpath (0, t6) of p6--cycle; |
| 410 |
forsuffixes $ = l, , r: |
| 411 |
z@#r$ = p1 intersectionpoint |
| 412 |
((z@#'$..z@#m$) shifted (-0.5spread1*v_)); |
| 413 |
z@#l$ = p2 intersectionpoint |
| 414 |
((z@#'$..z@#m$) shifted (0.5spread1*v_)); |
| 415 |
endfor |
| 416 |
penlabels(@#, @#', @#a, @#b, @#c, @#r, @#l, @#m); labels(@#ab, @#m.b); |
| 417 |
enddef; |
| 418 |
|
| 419 |
% ARM, BEAK and SERIFS (personal taste) |
| 420 |
|
| 421 |
% vardef arm@#(expr beak, beak_jut, breadth, darkness, orientation, x_limit) = |
| 422 |
% save a; a = 90; |
| 423 |
% if orientation = up: y@#a = min(y@#l, y@#r); y@#d = max(y@#l, y@#r); |
| 424 |
% y@#b-y@#d = vround beak; a := -a; |
| 425 |
% else: y@#a = max(y@#l, y@#r); y@#d = min(y@#l, y@#r); |
| 426 |
% y@#b-y@#d = -vround beak; fi |
| 427 |
% if x_limit>x@#: rt x@#b = hround x_limit; x@#b-x@#a = hround beak_jut; |
| 428 |
% else: lft x@#b = hround x_limit; x@#b-x@#a = -hround beak_jut; a := -a; fi |
| 429 |
% z@#c-z@#b = max(0, breadth-currentbreadth) |
| 430 |
% *unitvector(z@#a-z@#b)rotated a; |
| 431 |
% z@#d-z@#c = whatever*(z@#a-z@#b); |
| 432 |
% filldraw z@#c{z@#d-z@#c}... |
| 433 |
% if y@#l = y@#.d: darkness[z@#d, 0.5[z@#c, z@#l]]{z@#l-z@#c} |
| 434 |
% ...z@#l{z@#l-z@#d}--z@#r |
| 435 |
% else: darkness[z@#d, 0.5[z@#c, z@#r]]{z@#r-z@#c} |
| 436 |
% ...z@#r{z@#r-z@#d}--z@#l fi |
| 437 |
% --z@#a--z@#b--cycle; |
| 438 |
% labels(@#a, @#b, @#c, @#d); |
| 439 |
% enddef; |
| 440 |
|
| 441 |
vardef arm@#(expr beak, beak_jut, hair, darkness, direction, limit) = |
| 442 |
y@#d = y@#r; y@#a = y@#b = y@#r if ypart direction > 0: + else: - fi vround beak; |
| 443 |
y@#c = y@#l; |
| 444 |
rt x@#b = hround limit; lft x@#a = hround(limit-hair); |
| 445 |
x@#b-x@#c = hround beak_jut; z@#d-z@#a = whatever*(z@#c-z@#b); |
| 446 |
filldraw z@#r{z@#d-z@#r}...darkness[z@#d, 0.5[z@#r, z@#a]]... |
| 447 |
z@#a{z@#a-z@#d}--z@#b--z@#c--z@#l--cycle; |
| 448 |
labels(@#a, @#b, @#c, @#d); |
| 449 |
enddef; |
| 450 |
|
| 451 |
vardef serif(suffix $, $$) |
| 452 |
(expr bracket, left_jut, left_slab, dished_left, left_dish, |
| 453 |
right_jut, right_slab, dished_right, right_dish) = |
| 454 |
save a, b; b = cosd angle(z$$-z$); |
| 455 |
a = max(0.5left_jut, 0.5right_jut, bracket); |
| 456 |
if y$<y$$: top y$b = bot y$+vround left_slab; |
| 457 |
top y$g = bot y$+vround right_slab; |
| 458 |
y$a-y$b = y$h-y$g = bracket; |
| 459 |
top y$c-bot y$d = left_slab+left_dish; |
| 460 |
top y$f-bot y$e = right_slab+right_dish; |
| 461 |
else: bot y$b = top y$-vround left_slab; |
| 462 |
bot y$g = top y$-vround right_slab; |
| 463 |
y$a-y$b = y$h-y$g = -bracket; |
| 464 |
bot y$c-top y$d = -left_slab-left_dish; |
| 465 |
bot y$f-top y$e = -right_slab-right_dish; |
| 466 |
fi |
| 467 |
if dished_left: y$c = y$b; else: y$d = y$; fi |
| 468 |
if dished_right: y$f = y$g; else: y$e = y$; fi |
| 469 |
if x$l<x$r: z$a = whatever[z$l, z$$l]; |
| 470 |
z$h = whatever[z$r, z$$r]; |
| 471 |
x$c = x$d = x$l-hround(left_jut-b*abs(y$b-y$)); |
| 472 |
x$e = x$f = x$r+hround(right_jut+b*abs(y$g-y$)); |
| 473 |
x$l-x$b = min(left_jut, a); |
| 474 |
x$g-x$r = min(right_jut, a); |
| 475 |
else: z$a = whatever[z$r, z$$r]; |
| 476 |
z$h = whatever[z$l, z$$l]; |
| 477 |
x$c = x$d = x$r-hround(left_jut-b*abs(y$b-y$)); |
| 478 |
x$e = x$f = x$l+hround(right_jut+b*abs(y$g-y$)); |
| 479 |
x$r-x$b = min(left_jut, a); |
| 480 |
x$g-x$l = min(right_jut, a); |
| 481 |
fi |
| 482 |
filldraw z$a{z$-z$$}...z$b{left}...z$c--z$d...z${right} |
| 483 |
...z$e--z$f...z$g{left}...{z$$-z$}z$h--cycle; |
| 484 |
labels($a, $b, $c, $d, $e, $f, $g, $h); |
| 485 |
enddef; |
| 486 |
|
| 487 |
% SIM: drawn once, used many times |
| 488 |
|
| 489 |
def make_sim_picture = |
| 490 |
if unknown sim_picture: |
| 491 |
beginpicture(sim, 12u#+2appr#, v_center(spread1#+rth#)); |
| 492 |
pickup tiny.nib; |
| 493 |
save a, b; |
| 494 |
a = angle(1, 1.25(h+d)/u); |
| 495 |
b = angle(1, -(h+d)/4.5u); |
| 496 |
pos1(hair, a+90); pos9(hair, a+90); pos5(stem, b+90); |
| 497 |
bot y7l = -d-eps; top y3r = h+eps; |
| 498 |
y1l = good.y 0.225[y7l, y3r]; y3r-y9r = y1l-y7l; |
| 499 |
top y3r-bot y3l = top y7r-bot y7l = vround 0.5[hair, stem]; |
| 500 |
lft x1r = Appr-eps; rt x9l = w-Appr+eps; |
| 501 |
z5 = 0.5[z1, z9]; |
| 502 |
forsuffixes $ = r, l: y2$ = y3$ = y4$; y6$ = y7$ = y8$; |
| 503 |
z2$-z1$ = whatever*dir a; z8$-z9$ = whatever*dir a; |
| 504 |
z4$-z5$ = whatever*dir b; z6$-z5$ = whatever*dir b; |
| 505 |
x3$ = 0.6525[x2$, x4$]; x7$ = 0.6525[x8$, x6$]; |
| 506 |
endfor |
| 507 |
filldraw stroke z1e..controls 0.66[z1e, z2e] and 0.66[z3e, z2e] |
| 508 |
..z3e..controls 0.4[z3e, z4e] and 1[z5e, z4e]% 1 for inflexion point |
| 509 |
..z5e..controls 1[z5e, z6e] and 0.4[z7e, z6e] |
| 510 |
..z7e..controls 0.66[z7e, z8e] and 0.66[z9e, z8e]..z9e; |
| 511 |
%penlabels(1, 2, 3, 4, 5, 6, 7, 8, 9); |
| 512 |
endpicture; |
| 513 |
fi |
| 514 |
enddef; |
| 515 |
|
| 516 |
% TRIANGLES |
| 517 |
|
| 518 |
% makes an equilateral triangle optionally fully centered. |
| 519 |
|
| 520 |
numeric triangle_foot; |
| 521 |
|
| 522 |
vardef set_triangle@#(expr orientation, a, rth, centered, fit_bounds) = |
| 523 |
if orientation = left: |
| 524 |
rt x1@#r = rt x3@#r = if centered: |
| 525 |
hround(0.5w+0.5a/sqrt3); |
| 526 |
else: hround triangle_foot; fi |
| 527 |
x1@#r-x2@#r = hround(0.5a*sqrt(3)-currentbreadth)+eps; |
| 528 |
y2@#r = good.y 0.5[-d, h]; |
| 529 |
y3@#r-y2@#r = y2@#r-y1@#r = vround(0.5(a-currentbreadth))+eps; |
| 530 |
elseif orientation = right: |
| 531 |
lft x1@#r = lft x3@#r = if centered: |
| 532 |
hround(0.5w-0.5a/sqrt3); |
| 533 |
else: hround triangle_foot; fi |
| 534 |
x2@#r-x1@#r = hround(0.5a*sqrt(3)-currentbreadth)+eps; |
| 535 |
y2@#r = good.y 0.5[-d, h]; |
| 536 |
y2@#r-y3@#r = y1@#r-y2@#r = vround(0.5(a-currentbreadth))+eps; |
| 537 |
elseif orientation = down: |
| 538 |
top y1@#r = top y3@#r = if centered: |
| 539 |
vround(math_axis+0.5a/sqrt3); |
| 540 |
else: vround triangle_foot; fi |
| 541 |
y1@#r-y2@#r = hround(0.5a*sqrt(3)-currentbreadth)+eps; |
| 542 |
x2@#r = good.x 0.5w; |
| 543 |
x1@#r-x2@#r = x2@#r-x3@#r |
| 544 |
= hround 0.5min(a-currentbreadth, w-2appr-currentbreadth+2ho)+eps; |
| 545 |
else: |
| 546 |
bot y1@#r = bot y3@#r = if centered: |
| 547 |
vround(math_axis-0.5a/sqrt3); |
| 548 |
else: vround triangle_foot; fi |
| 549 |
y2@#r-y1@#r = hround(0.5a*sqrt(3)-currentbreadth)+eps; |
| 550 |
x2@#r = good.x 0.5w; |
| 551 |
x3@#r-x2@#r = x2@#r-x1@#r |
| 552 |
= hround 0.5min(a-currentbreadth, w-2appr-currentbreadth+2ho)+eps; |
| 553 |
fi |
| 554 |
z1@#l-z1@#r = (rth-currentbreadth)/sind(60) |
| 555 |
*(unitvector(z3@#r-z1@#r)+unitvector(z2@#r-z1@#r)); |
| 556 |
z2@#l-z2@#r = (rth-currentbreadth)/sind(60) |
| 557 |
*(unitvector(z3@#r-z2@#r)+unitvector(z1@#r-z2@#r)); |
| 558 |
z3@#l-z3@#r = (rth-currentbreadth)/sind(60) |
| 559 |
*(unitvector(z1@#r-z3@#r)+unitvector(z2@#r-z3@#r)); |
| 560 |
penlabels(1@#, 2@#, 3@#); |
| 561 |
enddef; |
| 562 |
|
| 563 |
% It's buggy |
| 564 |
vardef draw_star@#(expr center, n_edges, radius, tense, angle_init, void) = |
| 565 |
save a, b, theta; theta = 360/n_edges; |
| 566 |
x@# = good.x xpart center; y@# = good.y ypart center; |
| 567 |
% external points |
| 568 |
a = radius-0.5currentbreadth; |
| 569 |
b = (1-tense)*a*cosd theta/cosd(theta/2); |
| 570 |
for $ = 1 upto n_edges: |
| 571 |
z@#[2$-1]l = z@#+round(a*dir(($-1)*theta+angle_init)); |
| 572 |
z@#[2$]l = z@#+round(b*dir(($-0.5)*theta+angle_init)); |
| 573 |
labels(@#[2$-1]l, @#[2$]l); |
| 574 |
endfor |
| 575 |
if void: |
| 576 |
% internal points |
| 577 |
a := (rth-currentbreadth)/ |
| 578 |
abs sind(angle(z@#[1]l-z@#[2]l)-angle(z@#[1]l-z@#)); |
| 579 |
b := (rth-currentbreadth)/ |
| 580 |
abs sind(angle(z@#[2]l-z@#[1]l)-angle(z@#[2]l-z@#)); |
| 581 |
for $ = 1 upto n_edges: |
| 582 |
z@#[2$-1]l-z@#[2$-1]r = a*dir(($-1)*theta+angle_init); |
| 583 |
z@#[2$]l-z@#[2$]r = b*dir(($-0.5)*theta+angle_init); |
| 584 |
labels(@#[2$-1]r, @#[2$]r); |
| 585 |
endfor |
| 586 |
filldraw stroke for $ = 1 upto 2n_edges: z@#[$]e--endfor z@#[1]e; |
| 587 |
else: |
| 588 |
filldraw for $ = 1 upto 2n_edges: z@#[$]l--endfor cycle; |
| 589 |
fi |
| 590 |
enddef; |
| 591 |
|
| 592 |
% ADMINISTRATION |
| 593 |
|
| 594 |
% PROOFING |
| 595 |
|
| 596 |
def horizontal_rules_list = |
| 597 |
-body_depth, -desc_depth, x_height, cap_height, asc_height, body_height |
| 598 |
enddef; |
| 599 |
|
| 600 |
def makebox(text rule) = |
| 601 |
for y = -d.o_, 0, h.o_: |
| 602 |
rule((-xoffset, y), (w-xoffset, y)); endfor |
| 603 |
for y = horizontal_rules_list: |
| 604 |
rule((appr-xoffset, y), (w-appr-xoffset, y)); |
| 605 |
endfor |
| 606 |
for x = -xoffset, appr-xoffset, w-appr-xoffset, w-xoffset: |
| 607 |
rule((x, -d.o_), (x, h.o_)); endfor |
| 608 |
for x = appr+u-xoffset step u until w-appr-1.5-xoffset: |
| 609 |
rule((x, -d.o_), (x, h.o_)); endfor |
| 610 |
if charic<>0: |
| 611 |
rule((w-xoffset+charic*hppp, h.o_), |
| 612 |
(w-xoffset+charic*hppp, .5[h, -d].o_)); fi |
| 613 |
enddef; |
| 614 |
|
| 615 |
def accents_proofing = |
| 616 |
for $ = 0 upto 19: |
| 617 |
makelabel("", (0.5w-xoffset, 0.5x_height) |
| 618 |
+(4u*cosd($*360/20), 0.5x_height*sind($*360/20))); |
| 619 |
endfor |
| 620 |
enddef; |
| 621 |
|
| 622 |
def diacritics_proofing = |
| 623 |
if proofing>0: extra_endchar := extra_endchar&"accents_proofing;"; fi |
| 624 |
enddef; |
| 625 |
|
| 626 |
def standard_proofing = |
| 627 |
if proofing>0: extra_endchar := "additions_to_proof;"; fi |
| 628 |
enddef; |
| 629 |
|
| 630 |
def additions_to_proof = |
| 631 |
makelabel.lft("baseline", (-xoffset, 0)); |
| 632 |
if h>math_axis: makelabel.lft("math axis", (-xoffset, math_axis)); fi |
| 633 |
enddef; |
| 634 |
|
| 635 |
% `iff' CONSTRUCTION |
| 636 |
|
| 637 |
let semi_ = ;; let colon_ = :; let endchar_ = endchar; |
| 638 |
def iff expr b = if b:let next_ = use_it else:let next_ = lose_it fi; next_ enddef; |
| 639 |
def use_it = let : = restore_colon; enddef; |
| 640 |
def restore_colon = let : = colon_; enddef; |
| 641 |
def lose_it = let endchar = fi; |
| 642 |
let ; = fix_ semi_ if false enddef; |
| 643 |
def fix_ = let ; = semi_; let endchar = endchar_; |
| 644 |
enddef; |
| 645 |
def always_iff = let : = endgroup; killboolean enddef; |
| 646 |
def killboolean text t = use_it enddef; |
| 647 |
|
| 648 |
% Not the fastest solution |
| 649 |
def beginchar(expr c, w_sharp, h_sharp, d_sharp) = |
| 650 |
iff known c: |
| 651 |
begingroup |
| 652 |
charcode := byte c; |
| 653 |
charwd := w_sharp; |
| 654 |
charht := h_sharp; |
| 655 |
chardp := d_sharp; |
| 656 |
w := hround(charwd*hppp); |
| 657 |
h := vround(charht*hppp); |
| 658 |
d := vround(chardp*hppp); |
| 659 |
charic := 0; clearxy; clearit; |
| 660 |
clearpen; |
| 661 |
scantokens extra_beginchar; |
| 662 |
enddef; |
| 663 |
|
| 664 |
endinput; |