% mathematical symbols by Anthony Phan.
% file: mathbigs.mf (large symbols)
% last modification: May 16, 2005.
% Only known charcodes will be generated.

def horizontal_rules_list = 
  0.5[-d, h]-math_axis, 0.5[-d, h]-math_axis+x_height, 
  0.25[-d, h], 0.5[-d, h], 0.75[-d, h] enddef;

% PARAMETERS

text_rth# := 0[0.95stem#, 0.95cap_stem#];
disp_rth# := 0.75[0.95stem#, 0.95cap_stem#];
disp_stem# := 1.25cap_stem#;
disp_hair# := max(rth1#, cap_hair#*(cap_curve#/cap_stem#));
define_whole_blacker_pixels(text_rth, disp_rth, disp_stem, disp_hair);

% SUMMATIONS

def tmp_program(expr lowerstem, sidestem, upperstem, beak, hair, beakjut, lo) =
  pickup crisp.nib;
  top y1 = top y2 = h; bot y5 = bot y6 = -d;
  bot y12 = h-vround upperstem; y12 = y13 = y13';
  bot y14 = bot y15 = h-vround(upperstem+beak);
  top y9 = -d+vround lowerstem; y9 = y9' = y10; 
  top y7 = top y8 = -d+vround(lowerstem+beak);
  y3 = y12; y0 = 0.5[y12, y9];
  rt x6 = w-appr; x6 = x7 = x15 = x1+hround beakjut;
  lft x2 = appr; x2 = x3; rt x5 = appr-hround lo;
  rt x7-lft x8 = rt x15- lft x14 = hround hair;
  x0 = floor(0.5[x2, x7])+0.5;
  x9 = x13 = 0.5[x0, x14]; x9' = x8; z13'-z14 = whatever*(z1-z15);
  adjust_slanted_bar(3, 0, 3', 0', max(.5(sidestem-crisp), 1), 1);
  z11-z0 = z0-z0'; z12 = whatever[z3+2(z3'-z3), z11];
  adjust_slanted_bar(5, 11, 5', 11', max(hair-crisp, 1), -1);
  z10 = whatever[z11, z5'];
  z4 = whatever[z5', z11']; z4 = whatever[z3, z0'];
  filldraw z1--z2--z3--z4--z5--z6--z7--z8{down}
  ...beak_darkness[z9', 0.5[z8, z9]]...z9{left}
  --z10--z11--z12--z13{right}
  ...beak_darkness[z13', 0.5[z13, z14]]...z14{z15-z1}
  --z15--cycle;
  labels(0, 0', 1, 2, 3, 3', 4, 5, 5', 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
enddef;

beginchar(small_summation_sign, 8u#+2appr#, 0.8asc_height#, 0);
  "Small summation sign";
  tmp_program(stem, stem, hair, 0.36h-stem, hair, 0.2u, 0.5u);
endchar;

beginchar(summation_sign, 14u#+2appr#, 0, 10/6dh#);
  "Textstyle summation sign";
  tmp_program(cap_stem, cap_stem, cap_hair, 0.333d-d/9,
    cap_hair, 0.4u, 5/7u);
endchar;

beginchar(Summation_sign, 18u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle summation sign";
  tmp_program(disp_stem, disp_stem, disp_hair, 0.333d-d/9,
    disp_hair, 0.75u, u);

endchar;

% PRODUCTS AND COPRODUCTS

def tmp_program(expr orientation, appr_corr, 
    stem, hair, jut, inner_jut, bracket, dish) = 
  if orientation = up: top y1 = top y3 = h; bot y2 = bot y4 = -d;
  else: top y2 = top y4 = h; bot y1 = bot y3 = -d; fi
  pos1(hround stem, 0); pos2(hround stem, 0);
  pos3(hround stem, 0); pos4(hround stem, 0);
  lft x1l = lft x2l = appr+hround(appr_corr+jut);
  rt x3r = rt x4r = w-appr-hround(appr_corr+jut);
  serif(1, 2, bracket, jut, hair, false, dish, 0, hair, true, 0);
  serif(2, 1, bracket, jut, hair, true, dish, inner_jut, hair, true, dish);
  serif(3, 4, bracket, 0, hair, false, 0, jut, hair, true, dish);
  serif(4, 3, bracket, inner_jut, hair, true, dish, jut, hair, true, dish);
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  filldraw z1f--z3c--z3d--z1e--cycle;
  penlabels(1, 2, 3, 4);
enddef;

beginchar(small_product_sign, 8u#+2appr#, 0.8asc_height#, 0);
  "Small product sign";
  pickup crisp.nib;
  tmp_program(up, -0.875u, stem, hair, u, u, 0.5u, dish);
endchar;

beginchar(product_sign, 16u#+2appr#, 0, 10/6dh#);
  "Textstyle product sign";
  pickup crisp.nib;
  tmp_program(up, 0, cap_stem, cap_hair, 1.8u, 1.8u, 0.9u, dish);
endchar;

beginchar(Product_sign, 21u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle product sign";
  pickup crisp.nib;
  tmp_program(up, 0, disp_stem, disp_hair, 2.4u, 2.4u, 1.2u, dish);
endchar;

beginchar(small_coproduct_sign, 8u#+2appr#, 0.8asc_height#, 0);
  "Small coproduct sign";
  pickup crisp.nib;
  tmp_program(down, -0.875u, stem, hair, u, u, 0.5u, dish);
endchar;

beginchar(coproduct_sign, 16u#+2appr#, 0, 10/6dh#);
  "Textstyle coproduct sign";
  pickup crisp.nib;
  tmp_program(down, 0, cap_stem, cap_hair, 1.8u, 1.8u, 0.9u, dish);
endchar;

beginchar(Coproduct_sign, 21u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle coproduct sign";
  pickup crisp.nib;
  tmp_program(down, 0, disp_stem, disp_hair, 2.4u, 2.4u, 1.2u, dish);
endchar;

% BIG PLUS, BIG TIMES

beginchar(bplus_sign, 10/6dh#+2appr#, 0, 10/6dh#);
  "Textstyle big plus sign";
  use_rule2;
  pickup rule.nib; y3 = y4 = good.y 0.5[-d, h];
  pickup tiny.nib;
  pos1(rth, 0); pos2(rth, 0); pos3(rth, 90); pos4(rth, 90);
  lft x1l = hround 0.5(w-rth); x2 = x1;
  lft x3 = Appr; x1-x3 = x4-x1 = y1-y3 = y3-y2;
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(Bplus_sign, 14/6dh#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle big plus sign";
  use_rule3;
  pickup rule.nib; y3 = y4 = good.y 0.5[-d, h];
  pickup tiny.nib;
  pos1(rth, 0); pos2(rth, 0); pos3(rth, 90); pos4(rth, 90);
  lft x1l = hround 0.5(w-rth); x2 = x1;
  lft x3 = Appr; x1-x3 = x4-x1 = y1-y3 = y3-y2;
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(btimes_sign, 10/6dh#+2appr#, 0, 10/6dh#);
  "Textstyle big times sign";
  use_rule2;
  pickup rule.nib; x0 = good.x 0.5w;
  y0 = y0' = good.y 0.5[-d, h];
  pickup tiny.nib; rt x0' = w-Appr;
  z1-z0 = z0-z2 = (z0'-z0) rotated 45; z3-z0 = z0-z4 = (z0'-z0) rotated -45;
  pos1(rth+2eps, -45); pos2(rth+2eps, -45);
  pos3(rth+2eps, 45); pos4(rth+2eps, 45);
  filldraw stroke z1e..z2e; filldraw stroke z4e..z3e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(Btimes_sign, 14/6dh#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle big times sign";
  use_rule3;
  pickup rule.nib; x0 = good.x 0.5w;
  y0 = y0' = good.y 0.5[-d, h];
  pickup tiny.nib; rt x0' = w-Appr;
  z1-z0 = z0-z2 = (z0'-z0) rotated 45; z3-z0 = z0-z4 = (z0'-z0) rotated -45;
  pos1(rth+2eps, -45); pos2(rth+2eps, -45);
  pos3(rth+2eps, 45); pos4(rth+2eps, 45);
  filldraw stroke z1e..z2e; filldraw stroke z4e..z3e;
  penlabels(1, 2, 3, 4);
endchar;

% COMPLEMENTS

beginchar(bcomplement, 7.5u#+2appr#, 0, 10/6dh#);
  "Textstyle complement";
  autorounded; pickup tiny.nib;
  pos1(text_rth, 0); pos2(text_rth, 0);
  pos7(text_rth, 0); pos8(text_rth, 0);
  h-bot y1 = top y8+d = vround 0.25(h+d);
  y3+0.5text_rth = h+vround(o*((h+d)/cap_height))+eps;
  y6-0.5text_rth = -d-vround(o*((h+d)/cap_height))-eps;
  rt x1r = w-appr; x1 = x2 = x7 = x8;
  x4 = x5 = appr+0.5text_rth; x3 = x6 = 0.5[x1, x4];
  y2 = y4 = max(y3-x1+x3, 1/6[y1, y3]);
  y5 = y7 = min(y6+x1-x3, 1/6[y8, y6]);
  filldraw stroke z1e..z2e; filldraw stroke z7e..z8e;
  pickup pencircle scaled text_rth;
  draw flatcup(z2, z3, z4)..flatcup(z5, z6, z7);
% z4..z5 down_to_right z6 right_to_up z7;
  penlabels(1, 2, 7, 8); labels(3, 4, 5, 6);
endchar;

beginchar(Bcomplement, 10u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "displaystyle complement";
  autorounded; pickup tiny.nib;
  pos1(disp_rth, 0); pos2(disp_rth, 0);
  pos7(disp_rth, 0); pos8(disp_rth, 0);
  h-bot y1 = top y8+d = vround 0.25(h+d);
  y3+0.5disp_rth = h+vround(o*((h+d)/cap_height))+eps;
  y6-0.5disp_rth = -d-vround(o*((h+d)/cap_height))-eps;
  rt x1r = w-appr; x1 = x2 = x7 = x8;
  x4 = x5 = appr+0.5disp_rth; x3 = x6 = 0.5[x1, x4];
  y2 = y4 = max(y3-x1+x3, 1/6[y1, y3]);
  y5 = y7 = min(y6+x1-x3, 1/6[y8, y6]);
  filldraw stroke z1e..z2e; filldraw stroke z7e..z8e;
  pickup pencircle scaled disp_rth;
  draw flatcup(z2, z3, z4)..flatcup(z5, z6, z7);
% z2 up_to_left z3 left_to_down
% z4..z5 down_to_right z6 right_to_up z7;
  penlabels(1, 2, 7, 8); labels(3, 4, 5, 6);
endchar;

%
% TRUCS
%

beginchar(btruc_sign, 10/6dh#+2appr#, 0, 10/6dh#);
  "Textstyle truc sign";
  pickup tiny.nib;
  pos1(rth2, 0); pos2(rth2, 0); pos3(rth2, 90); pos4(rth2, 90);
  top y1 = top y3r = top y4r = h; bot y2 = -d;
  lft x1l = hround 0.5(w-rth2); x2 = x1;
  lft x3 = Appr; x1-x3 = x4-x1; filldraw stroke z1e..z2e;
  filldraw stroke z3e..z4e; penlabels(1, 2, 3, 4);
endchar;

beginchar(Btruc_sign, 14/6dh#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle truc sign";
  pickup tiny.nib;
  pos1(rth3, 0); pos2(rth3, 0); pos3(rth3, 90); pos4(rth3, 90);
  top y1 = top y3r = top y4r = h; bot y2 = -d;
  lft x1l = hround 0.5(w-rth2); x2 = x1;
  lft x3 = Appr; x1-x3 = x4-x1; filldraw stroke z1e..z2e;
  filldraw stroke z3e..z4e; penlabels(1, 2, 3, 4);
endchar;

beginchar(bcurt_sign, 10/6dh#+2appr#, 0, 10/6dh#);
  "Textstyle curT sign";
  pickup tiny.nib;
  pos1(rth2, 0); pos2(rth2, 0); pos3(rth2, 90); pos4(rth2, 90);
  bot y1 = bot y3l = bot y4l = -d; top y2 = h;
  lft x1l = hround 0.5(w-rth); x2 = x1;
  lft x3 = appr; x1-x3 = x4-x1; filldraw stroke z2e..z1e;
  filldraw stroke z3e..z4e; penlabels(1, 2, 3, 4);
endchar;

beginchar(Bcurt_sign, 14/6dh#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle curT sign";
  pickup tiny.nib;
  pos1(rth3, 0); pos2(rth3, 0); pos3(rth3, 90); pos4(rth3, 90);
  bot y1 = bot y3l = bot y4l = -d; top y2 = h;
  lft x1l = hround 0.5(w-rth); x2 = x1;
  lft x3 = appr; x1-x3 = x4-x1; filldraw stroke z2e..z1e;
  filldraw stroke z3e..z4e; penlabels(1, 2, 3, 4);
endchar;

%
% CUPS AND CAPS : STEMS MATCH BRACKETS ONES
%

beginchar(bcap_sign, 14u#+2appr#, 0, 10/6dh#);
  "Textstyle cap sign";
  pickup tiny.nib;
  pos1(text_rth, 0); pos2(text_rth, 0); pos4(text_rth, 0); pos5(text_rth, 0);
  lft x1l = lft x2l = appr; rt x4r = rt x5r = w-appr; x3 = 0.5[x2, x4];
  bot y1 = bot y5 = -d; y3+0.5text_rth = h+vround(o*((h+d)/cap_height))+eps;
  y2 = y4 = max(y3-0.5(x4-x2), 0.5[y3, y1]);
  filldraw stroke z2e..z1e; filldraw stroke z4e..z5e;
  pickup pencircle scaled text_rth; autorounded; draw flatcup(z2, z3, z4);
  penlabels(1, 2, 3, 4, 5);
endchar;

beginchar(Bcap_sign, 18u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle cap sign";
  pickup tiny.nib;
  pos1(disp_rth, 0); pos2(disp_rth, 0); pos4(disp_rth, 0); pos5(disp_rth, 0);
  lft x1l = lft x2l = appr; rt x4r = rt x5r = w-appr; x3 = 0.5[x2, x4];
  bot y1 = bot y5 = -d; y3+0.5disp_rth = h+vround(o*((h+d)/cap_height))+eps;
  y2 = y4 = max(y3-0.5(x4-x2), 0.5[y3, y1]);
  filldraw stroke z2e..z1e; filldraw stroke z4e..z5e;
  pickup pencircle scaled disp_rth; autorounded; draw flatcup(z2, z3, z4);
  penlabels(1, 2, 3, 4, 5);
endchar;

beginchar(bcup_sign, 14u#+2appr#, 0, 10/6dh#);
  "Textstyle cup sign";
  pickup tiny.nib;
  pos1(text_rth, 0); pos2(text_rth, 0); pos4(text_rth, 0); pos5(text_rth, 0);
  lft x1l = lft x2l = appr; rt x4r = rt x5r = w-appr; x3 = 0.5[x2, x4];
  top y1 = top y5 = h; y3-0.5text_rth = -d-vround(o*((h+d)/cap_height))-eps;
  y2 = y4 = min(y3+0.5(x4-x2), 0.5[y3, y1]);
  filldraw stroke z2e..z1e; filldraw stroke z4e..z5e;
  pickup pencircle scaled text_rth; autorounded; draw flatcup(z2, z3, z4);
  penlabels(1, 2, 3, 4, 5);
endchar;

beginchar(Bcup_sign, 18u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle cup sign";
  pickup tiny.nib;
  pos1(disp_rth, 0); pos2(disp_rth, 0); pos4(disp_rth, 0); pos5(disp_rth, 0);
  lft x1l = lft x2l = appr; rt x4r = rt x5r = w-appr; x3 = 0.5[x2, x4];
  top y1 = top y5 = h; y3-0.5disp_rth = -d-vround(o*((h+d)/cap_height))-eps;
  y2 = y4 = min(y3+0.5(x4-x2), 0.5[y3, y1]);
  filldraw stroke z2e..z1e; filldraw stroke z4e..z5e;
  pickup pencircle scaled disp_rth; autorounded; draw flatcup(z2, z3, z4);
  penlabels(1, 2, 3, 4, 5);
endchar;

beginchar(bcup_plus, 14u#+2appr#, 0, 10/6dh#);
  "Textstyle cup-plus sign";
  ensure_centering_of(rth2);
 %
  pickup tiny.nib;
  pos1(text_rth, 0); pos2(text_rth, 0); pos4(text_rth, 0); pos5(text_rth, 0);
  lft x1l = lft x2l = appr; rt x4r = rt x5r = w-appr; x3 = 0.5[x2, x4];
  top y1 = top y5 = h; y3-0.5text_rth = -d-vround(o*((h+d)/cap_height))-eps;
  y2 = y4 = min(y3+0.5(x4-x2), 0.5[y3, y1]);
  filldraw stroke z2e..z1e; filldraw stroke z4e..z5e;
 %
  pos6(rth2, 0); pos7(rth2, 0); pos8(rth2, 90); pos9(rth2, 90);
  y8 = y9 = vround(0.5[-d, h]-0.5rth2)+0.5rth2;
  x6 = x7 = 0.5w;
  numeric a;
  a = 0.5(min(lft x5l-rt x1r-2.6u, h+d-text_rth-1.3u)-text_rth);
  y6-y8r = y8l-y7 = vround a; x6l-x8 = x9-x6r = hround a;
  filldraw stroke z6e..z7e; filldraw stroke z8e..z9e;
 %
  pickup pencircle scaled text_rth; autorounded; draw flatcup(z2, z3, z4);
  penlabels(1, 2, 3, 4, 5, 6, 7, 8, 9);
endchar;

beginchar(Bcup_plus, 18u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle cup-plus sign";
  ensure_centering_of(rth3);
 %
  pickup tiny.nib;
  pos1(disp_rth, 0); pos2(disp_rth, 0); pos4(disp_rth, 0); pos5(disp_rth, 0);
  lft x1l = lft x2l = appr; rt x4r = rt x5r = w-appr; x3 = 0.5[x2, x4];
  top y1 = top y5 = h; y3-0.5disp_rth = -d-vround(o*((h+d)/cap_height))-eps;
  y2 = y4 = min(y3+0.5(x4-x2), 0.5[y3, y1]);
  filldraw stroke z2e..z1e; filldraw stroke z4e..z5e;
 %
  pos6(rth3, 0); pos7(rth3, 0); pos8(rth3, 90); pos9(rth3, 90);
  y8 = y9 = vround(0.5[-d, h]-0.5rth3)+0.5rth3;
  x6 = x7 = 0.5w;
  numeric a;
  a = 0.5(min(lft x5l-rt x1r-2.9u, h+d-disp_rth-1.45u)-disp_rth);
  y6-y8r = y8l-y7 = vround a; x6l-x8 = x9-x6r = hround a;
  filldraw stroke z6e..z7e; filldraw stroke z8e..z9e;
 %
  pickup pencircle scaled disp_rth; autorounded; draw flatcup(z2, z3, z4);
  penlabels(1, 2, 3, 4, 5, 6, 7, 8, 9);
endchar;

beginchar(bsqcap_sign, 14u#+2appr#, 0, 10/6dh#);
  "Textstyle square cap sign";
  pickup tiny.nib;
  pos1(text_rth, 180); pos4(text_rth, 0);
  top y2r = top y3r = h; bot y1 = bot y4 = -d;
  top y2r-bot y2l = top y3r-bot y3l = text_rth;
  lft x1r = appr; rt x4r = w-appr;
  x2r = x1r; x3r = x4r; x2l = x1l; x3l = x4l;
  filldraw stroke z1e--z2e--z3e--z4e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(Bsqcap_sign, 18u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle square cap sign";
  pickup tiny.nib;
  pos1(disp_rth, 180); pos4(disp_rth, 0);
  top y2r = top y3r = h; bot y1 = bot y4 = -d;
  top y2r-bot y2l = top y3r-bot y3l = disp_rth;
  lft x1r = appr; rt x4r = w-appr;
  x2r = x1r; x3r = x4r; x2l = x1l; x3l = x4l;
  filldraw stroke z1e--z2e--z3e--z4e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(bsqcup_sign, 14u#+2appr#, 0, 10/6dh#);
  "Textstyle square cup sign";
  pickup tiny.nib;
  pos1(text_rth, 180); pos4(text_rth, 0);
  bot y2r = bot y3r = -d; top y1 = top y4 = h;
  top y2l-bot y2r = top y3l-bot y3r = text_rth;
  lft x1r = appr; rt x4r = w-appr;
  x2r = x1r; x3r = x4r; x2l = x1l; x3l = x4l;
  filldraw stroke z1e--z2e--z3e--z4e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(Bsqcup_sign, 18u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle square cup sign";
  pickup tiny.nib;
  pos1(disp_rth, 180); pos4(disp_rth, 0);
  bot y2r = bot y3r = -d; top y1 = top y4 = h;
  top y2l-bot y2r = top y3l-bot y3r = disp_rth;
  lft x1r = appr; rt x4r = w-appr;
  x2r = x1r; x3r = x4r; x2l = x1l; x3l = x4l;
  filldraw stroke z1e--z2e--z3e--z4e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(bsqcup_plus, 14u#+2appr#, 0, 10/6dh#);
  "Textstyle square cup-plus sign";
  ensure_centering_of(rth2);
 %
  pickup tiny.nib;
  pos1(text_rth, 180); pos4(text_rth, 0);
  bot y2r = bot y3r = -d; top y1 = top y4 = h;
  top y2l-bot y2r = top y3l-bot y3r = text_rth;
  lft x1r = appr; rt x4r = w-appr;
  x2r = x1r; x3r = x4r; x2l = x1l; x3l = x4l;
  filldraw stroke z1e--z2e--z3e--z4e;
 %
  pos6(rth2, 0); pos7(rth2, 0); pos8(rth2, 90); pos9(rth2, 90);
  y8 = y9 = vround(0.5[-d, h]-0.5rth2)+0.5rth2;
  x6 = x7 = 0.5w;
  numeric a;
  a = 0.5(min(lft x4l-rt x1l-2.6u, h+d-text_rth-1.3u)-text_rth);
  y6-y8r = y8l-y7 = vround a; x6l-x8 = x9-x6r = hround a;
  filldraw stroke z6e..z7e; filldraw stroke z8e..z9e;
  penlabels(1, 2, 3, 4, 6, 7, 8, 9);
endchar;

beginchar(Bsqcup_plus, 18u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle square cup-plus sign";
  ensure_centering_of(rth3);
 %
  pickup tiny.nib;
  pos1(disp_rth, 180); pos4(disp_rth, 0);
  bot y2r = bot y3r = -d; top y1 = top y4 = h;
  top y2l-bot y2r = top y3l-bot y3r = disp_rth;
  lft x1r = appr; rt x4r = w-appr;
  x2r = x1r; x3r = x4r; x2l = x1l; x3l = x4l;
  filldraw stroke z1e--z2e--z3e--z4e;
 %
  pos6(rth3, 0); pos7(rth3, 0); pos8(rth3, 90); pos9(rth3, 90);
  y8 = y9 = vround(0.5[-d, h]-0.5rth3)+0.5rth3;
  x6 = x7 = 0.5w;
  numeric a;
  a = 0.5(min(lft x4l-rt x1l-2.9u, h+d-disp_rth-1.45u)-disp_rth);
  y6-y8r = y8l-y7 = vround a; x6l-x8 = x9-x6r = hround a;
  filldraw stroke z6e..z7e; filldraw stroke z8e..z9e;
  penlabels(1, 2, 3, 4, 6, 7, 8, 9);
endchar;

%
% WEDGES AND VEES
%

beginchar(bwedge_sign, 16u#+2appr#, 0, 10/6dh#);
  "Textstyle wedge sign";
  pickup tiny.nib;
  lft x1 = appr; x2 = good.x 0.5w;
  x3-x2 = x2-x1; bot y1 = -d; y1 = y3 = y4 = y6;
  top y2 = h+vround(o*((h+d)/cap_height))+eps;
  x6-x1 = diag_width(text_rth-tiny, z2-z1);
  x3-x4 = diag_width(text_rth-tiny, z2-z3);
  z5-z4 = whatever*(z2-z3); z5-z6 = whatever*(z2-z1);
  filldraw z1--z2--z3--z4--z5--z6--cycle;
  labels(1, 2, 3, 4, 5, 6);
endchar;

beginchar(Bwedge_sign, 22.4u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle wedge sign";
  pickup tiny.nib;
  lft x1 = appr; x2 = good.x 0.5w;
  x3-x2 = x2-x1; bot y1 = -d; y1 = y3 = y4 = y6;
  top y2 = h+vround(o*((h+d)/cap_height))+eps;
  x6-x1 = diag_width(disp_rth-tiny, z2-z1);
  x3-x4 = diag_width(disp_rth-tiny, z2-z3);
  z5-z4 = whatever*(z2-z3); z5-z6 = whatever*(z2-z1);
  filldraw z1--z2--z3--z4--z5--z6--cycle;
  labels(1, 2, 3, 4, 5, 6);
endchar;

beginchar(bvee_sign, 16u#+2appr#, 0, 10/6dh#);
  "Textstyle vee sign";
  pickup tiny.nib;
  lft x1 = appr; x2 = good.x 0.5w;
  x3-x2 = x2-x1; top y1 = h; y1 = y3 = y4 = y6;
  bot y2 = -d-vround(o*((h+d)/cap_height))-eps;
  x6-x1 = diag_width(text_rth-tiny, z2-z1);
  x3-x4 = diag_width(text_rth-tiny, z2-z3);
  z5-z4 = whatever*(z2-z3); z5-z6 = whatever*(z2-z1);
  filldraw z1--z2--z3--z4--z5--z6--cycle;
  labels(1, 2, 3, 4, 5, 6);
endchar;

beginchar(Bvee_sign, 22.4u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle vee sign";
  pickup tiny.nib;
  lft x1 = appr; x2 = good.x 0.5w;
  x3-x2 = x2-x1; top y1 = h; y1 = y3 = y4 = y6;
  bot y2 = -d-vround(o*((h+d)/cap_height))-eps;
  x6-x1 = diag_width(disp_rth-tiny, z2-z1);
  x3-x4 = diag_width(disp_rth-tiny, z2-z3);
  z5-z4 = whatever*(z2-z3); z5-z6 = whatever*(z2-z1);
  filldraw z1--z2--z3--z4--z5--z6--cycle;
  labels(1, 2, 3, 4, 5, 6);
endchar;

beginchar(bwedge_curly, 16u#+2appr#, 0, 10/6dh#);
  "Textstyle curly wedge sign";
  pickup tiny.nib;
  x2 = hround 0.5(w-text_rth)+0.5text_rth;
  top y2 = h+vround(o*((h+d)/cap_height))+eps;
  pos2(text_rth, 0); bot y1r = bot y3l = -d;
  lft x1r = appr;
  x3l-x2r = x2l-x1r; x1l = x1r; x3l = x3r;
  x4 = x2; pos4(text_rth, 0); y4 = 0.625[y2, y1r];
  y1l-y1r = y3r-y3l = (text_rth-tiny)/cosd angle(z4r-z1r);
  filldraw stroke z2e{down}...z1e{z1r-z4r};
  filldraw stroke z2e{down}...z3e{z3l-z4l};
  penlabels(1, 2, 3, 4);
endchar;

beginchar(Bwedge_curly, 22.4u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle curly wedge sign";
  pickup tiny.nib;
  x2 = hround 0.5(w-disp_rth)+0.5disp_rth;
  top y2 = h+vround(o*((h+d)/cap_height))+eps;
  pos2(disp_rth, 0); bot y1r = bot y3l = -d;
  lft x1r = appr;
  x3l-x2r = x2l-x1r; x1l = x1r; x3l = x3r;
  x4 = x2; pos4(disp_rth, 0); y4 = 0.625[y2, y1r];
  y1l-y1r = y3r-y3l = (disp_rth-tiny)/cosd angle(z4r-z1r);
  filldraw stroke z2e{down}...z1e{z1r-z4r};
  filldraw stroke z2e{down}...z3e{z3l-z4l};
  penlabels(1, 2, 3, 4);
endchar;

beginchar(bvee_curly, 16u#+2appr#, 0, 10/6dh#);
  "Textstyle curly vee sign";
  pickup tiny.nib;
  x2 = hround 0.5(w-text_rth)+0.5text_rth;
  bot y2 = -d-vround(o*((h+d)/cap_height))-eps;
  pos2(text_rth, 0); top y1r = top y3l = h;
  lft x1r = appr;
  x1l = x1r; x3l = x3r; x3l-x2r = x2l-x1r;
  x4 = x2; pos4(text_rth, 0); y4 = 0.625[y2, y1r];
  y1r-y1l = y3l-y3r = (text_rth-tiny)/cosd angle(z4r-z1r);
  filldraw stroke z2e{up}...z1e{z1r-z4r};
  filldraw stroke z2e{up}...z3e{z3l-z4l};
  penlabels(1, 2, 3, 4);
endchar;

beginchar(Bvee_curly, 22.4u#+2appr#, 0, 14/6dh#);
  padded bigop_padding#;
  "Displaystyle curly vee sign";
  pickup tiny.nib;
  x2 = hround 0.5(w-disp_rth)+0.5disp_rth;
  bot y2 = -d-vround(o*((h+d)/cap_height))-eps;
  pos2(disp_rth, 0); top y1r = top y3l = h;
  lft x1r = appr;
  x1l = x1r; x3l = x3r; x3l-x2r = x2l-x1r;
  x4 = x2; pos4(disp_rth, 0); y4 = 0.625[y2, y1r];
  y1r-y1l = y3l-y3r = (disp_rth-tiny)/cosd angle(z4r-z1r);
  filldraw stroke z2e{up}...z1e{z1r-z4r};
  filldraw stroke z2e{up}...z3e{z3l-z4l};
  penlabels(1, 2, 3, 4);
endchar;

% UGLY

beginchar(btriangle_up, 16u#+2appr#, 0, 10/6dh#);
  "Big triangle up";
  pickup tiny.nib; lft x1r = appr;
  x2r = good.x 0.5w; x3r-x2r = x2r-x1r;
  bot y1r = -d; y1r = y3r = y1 = y3; top y2r = h+o;
  top y1l-bot y1r = top y3l-bot y3r = rth;
  x1-x1r = diag_width(rth-tiny, z2r-z1r);
  x3r-x3 = diag_width(rth-tiny, z2r-z3r);
  z2l-z1 = whatever*(z2r-z1r); z2l-z3 = whatever*(z2r-z3r);
  z1l = whatever[z1, z2l]; z3l = whatever[z3, z2l];
  filldraw stroke z1e--z2e--z3e--z1e; penlabels(1, 2, 3);
endchar;

beginchar(btriangle_down, 16u#+2appr#, 0, 10/6dh#);
  "Big triangle down";
  pickup tiny.nib; lft x1r = appr;
  x2r = good.x 0.5w; x3r-x2r = x2r-x1r;
  top y1r = h; y1r = y3r = y1 = y3; bot y2r = -d-o;
  top y1r-bot y1l = top y3r-bot y3l = rth;
  x1-x1r = diag_width(rth-tiny, z2r-z1r);
  x3r-x3 = diag_width(rth-tiny, z2r-z3r);
  z2l-z1 = whatever*(z2r-z1r); z2l-z3 = whatever*(z2r-z3r);
  z1l = whatever[z1, z2l]; z3l = whatever[z3, z2l];
  filldraw stroke z1e--z2e--z3e--z1e; penlabels(1, 2, 3);
endchar;

% INTEGRALS

beginchar(bintegral_sign,6u#+2appr#,0,100/54dh#);
  "Textstyle integral sign";
  z.c=(0.5w,0.5[-d,h]);
  y.t=y.tl=y.tr=h; y.b=y.bl=y.br=-d;
  x.c-x.t=x.b-x.c=2.3u;% slope
  x.tr-x.t=x.t-x.tl=x.br-x.b=x.b-x.bl=.5cap_stem/sind(angle(z.t-z.c));
  z1 = 0.52[z.bl,z.tl];
  z2 = (hround(appr+u), 0.82[-d, h]);
  z3 = (w-appr-2.3u, 1[-d, h]);
  z4 = (w-appr, 0.63[y3, y5]);
  z5 = (w-appr-0.7u, vround(h-0.2dh));
  z6 = (w-appr-2.5u, 1[-d, h]-cap_hair);
  z7 = 0.75[z.br,z.tr];
  x1.2=x2; z1.2-z1=whatever*(z.t-z.c);
  y6.7=y6; z6.7-z7=whatever*(z.t-z.c);
  path lastpath;
  lastpath := 
  z1..controls 0.6[z1,z1.2] and 0.5[z2,z1.2]..
  z2..controls(x2, 0.55[y2, y3]) and (0.65[x3, x2], y3)..
  z3..controls(0.79[x3, x4], y3) and (x4, 0.44[y4, y3])..
  z4..controls(x4, 0.6[y4, y5]) and (0.6[x5, x4], y5)..
  z5..controls(0.65[x5, x6], y5) and (0.6[x6, x5], y6)..
  z6..controls 0.6[z6, z6.7] and 0.65[z7, z6.7]..
  z7;
  lastpath := lastpath--lastpath rotated 180 shifted (w, -d)--cycle;
  fill lastpath;
  labels(1,2,3,4,5,6,7,1.2,6.7);
  charwd:=charwd-u#; italcorr 0.5u#; w:= round(charwd*hppp);
  tmp_picture := currentpicture;  
endchar;

beginchar(bintegral_double, 11.5u#+2appr#, 0, 100/54dh#);
  "Textstyle double integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture+(tmp_picture shifted (hround 6.5u, 0));
endchar;

beginchar(bintegral_triple, 
    18u#+2appr#, 0, 100/54dh#);
  "Textstyle triple integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture+(tmp_picture shifted (hround 6.5u, 0))
  +(tmp_picture shifted (2hround 6.5u, 0));
endchar;

beginchar(bintegral_contour, 5u#+2appr#, 0, 100/54dh#);
  "Textstyle contour integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture;
  pickup rule.nib0;
  rt x1 = w-appr+hround 1.5u+eps;
  lft x3 = appr-hround 0.5u-eps; x2=x4=0.5[x1,x3];
  top y2 = vround(0.5[-d, h]+3.5u)+eps;
  0.5[y2, y4] = 0.5[-d, h] = y1 = y3;
  draw z1 up_to_left z2 left_to_down z3
  down_to_right z4 right_to_up z1;
  labels(1,2,3,4);
endchar;

arrow_head_fitting:= true;
arrow_width  := 2ceiling 0.70spread1+rth;
arrow_height# := 4u#;
arrow_height := round 4u;
arrow_breadth := rth;
arrow_stress := 0.65;
arrow_tense1 := 0.75;
arrow_tense2 := 0.875;

beginchar(bintegral_contour_pos, 5u#+2appr#, 0, 100/54dh#);
  "Textstyle positive contour integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture;
  pickup rule.nib0;
  rt x1 = w-appr+hround 1.5u+eps;
  lft x3 = appr-hround 0.5u-eps; x2=x4=0.5[x1,x3];
  top y2 = vround(0.5[-d, h]+3.5u)+eps;
  0.5[y2, y4] = 0.5[-d, h] = y1 = y3;
  draw z1 up_to_left z2 left_to_down z3
  down_to_right z4 right_to_up z1;
  pickup tiny.nib;
  arrow_head5(subpath (0,3) of (z4 right_to_up z1 up_to_left z2), both);
  labels(1, 2, 3, 4, 5, 5l, 5r);
endchar;

beginchar(bintegral_contour_neg, 5u#+2appr#, 0, 100/54dh#);
  "Textstyle negative contour integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture;
  pickup rule.nib0;
  rt x1 = w-appr+hround 1.5u+eps;
  lft x3 = appr-hround 0.5u-eps; x2=x4=0.5[x1,x3];
  top y2 = vround(0.5[-d, h]+3.5u)+eps;
  0.5[y2, y4] = 0.5[-d, h] = y1 = y3;
  draw z1 up_to_left z2 left_to_down z3
  down_to_right z4 right_to_up z1;
  pickup tiny.nib;
  arrow_head5(subpath (0,3) of (z2 right_to_down z1 down_to_left z4), both);
  labels(1, 2, 3, 4, 5, 5l, 5r);
endchar;

beginchar(bintegral_square, 5u#+2appr#, 0, 100/54dh#);
  "Textstyle square integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture;
  pickup tiny.nib;
  top y1r = top y2r = vround(0.5[-d, h]+3.5u);
  rt x2r = rt x3r = w-appr+hround 1.5u;
  0.5[y1r, y3r] = 0.5[y2r, y4r] = 0.5[-d, h];
  lft x1r=lft x4r=appr-hround 0.5u; 
  rt x1l-lft x1r = rt x2r-lft x2l
  = rt x3r-lft x3l = rt x4l-lft x4r = rth0;
  top y1r-bot y1l = top y2r-bot y2l
  = top y3l-bot y3r = top y4l-bot y4r = rth0;
  filldraw stroke z1e--z2e--z3e--z4e--z1e;
  penlabels(1, 2, 3, 4);
endchar;

beginchar(bintegral_square_pos, 5u#+2appr#, 0, 100/54dh#);
  "Textstyle positive square integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture;
  pickup tiny.nib;
  top y1r = top y2r = vround(0.5[-d, h]+3.5u);
  rt x2r = rt x3r = w-appr+hround 1.5u;
  0.5[y1r, y3r] = 0.5[y2r, y4r] = 0.5[-d, h];
  lft x1r=lft x4r=appr-hround 0.5u; 
  rt x1l-lft x1r = rt x2r-lft x2l
  = rt x3r-lft x3l = rt x4l-lft x4r = rth0;
  top y1r-bot y1l = top y2r-bot y2l
  = top y3l-bot y3r = top y4l-bot y4r = rth0;
  filldraw stroke z1e--z2e--z3e--z4e--z1e;
  pickup tiny.nib; z2=0.5[z2l,z2r]; z3=0.5[z3l,z3r];
  arrow_head5(z3..0.75[z3,z2], both);
  penlabels(1, 2, 3, 4, 5);
endchar;

beginchar(bintegral_square_neg, 5u#+2appr#, 0, 100/54dh#);
  "Textstyle negative square integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture;
  pickup tiny.nib;
  top y1r = top y2r = vround(0.5[-d, h]+3.5u);
  rt x2r = rt x3r = w-appr+hround 1.5u;
  0.5[y1r, y3r] = 0.5[y2r, y4r] = 0.5[-d, h];
  lft x1r=lft x4r=appr-hround 0.5u; 
  rt x1l-lft x1r = rt x2r-lft x2l
  = rt x3r-lft x3l = rt x4l-lft x4r = rth0;
  top y1r-bot y1l = top y2r-bot y2l
  = top y3l-bot y3r = top y4l-bot y4r = rth0;
  filldraw stroke z1e--z2e--z3e--z4e--z1e;
  pickup tiny.nib; z2=0.5[z2l,z2r]; z3=0.5[z3l,z3r];
  arrow_head5(z2..0.75[z2,z3], both);
  penlabels(1, 2, 3, 4, 5);
endchar;

beginchar(bintegral_dblcont, 11u#+2appr#, 0, 100/54dh#);
  "Textstyle double contour integral sign";
  italcorr 0.5u#;
  currentpicture := tmp_picture+(tmp_picture shifted (hround 6u, 0));
  pickup rule.nib0;
  rt x1 = w-appr+hround 1.5u+eps; lft x3 = appr-hround 0.5u-eps;
  x2 = x4 = 0.5[x1,x3];
  top y2 = vround(0.5[-d, h]+3.5u)+eps;
  0.5[y2, y4] = 0.5[-d, h] = y1 = y3;
  draw z1 up_to_left z2 left_to_down z3
  down_to_right z4 right_to_up z1;
  labels(1, 2, 3, 4);
endchar;

beginchar(Bintegral_sign, 12u#+2appr#,0,200/54dh#);
%  save disp_stem; disp_stem=hround 2.2u;%46/36pt;
  z1 = (hround(0.5w-0.5disp_stem), 0.52[-d, h]);
  z2 = (w-appr-2.6u, 1[-d, h]);
  z3 = (w-appr, 0.63[y2, y4]);
  z4 = (w-appr-0.9u, vround(h-0.24dh));
  z5 = (w-appr-2.8u, 1[-d, h]-disp_hair);
  z6 = (x1+disp_stem, 0.75[-d, h]);
  path lastpath;
  lastpath :=
  z1..controls(x1, 0.6[y1, y2]) and (0.85[x2, x1], y2)..
  z2..controls(0.79[x2, x3], y2) and (x3, 0.44[y3, y2])..
  z3..controls(x3, 0.6[y3, y4]) and (0.6[x4, x3], y4)..
  z4..controls(0.65[x4, x5], y4) and (0.6[x5, x4], y5)..
  z5..controls(0.55[x5, x6], y5) and (x6, 0.8[y6, y5])..
  z6;
  lastpath := lastpath--lastpath shifted (-x1,0)
  rotated 180 shifted (x6, -d)--cycle;
  fill lastpath;
  labels(1,2,3,4,5,6);
  charwd:=charwd-5u#; italcorr 4.5u#; w:= round(charwd*hppp);
  tmp_picture := currentpicture;
  integral_x:=x1;
endchar;

beginchar(Bintegral_double, 16.5u#+2appr#, 0,200/54dh#);
  "Displaystyle double integral sign";
  italcorr 4.5u#;
  currentpicture := tmp_picture+(tmp_picture shifted (hround 9.5u, 0));
endchar;

beginchar(Bintegral_triple, 26u#+2appr#, 0,200/54dh#);
  "Displaystyle triple integral sign";
  italcorr 4.5u#;
  currentpicture := tmp_picture+(tmp_picture shifted (hround 9.5u, 0))
  +(tmp_picture shifted (2hround 9.5u, 0));
endchar;

beginchar(Bintegral_contour, 7u#+2appr#, 0,200/54dh#);
  "Displaystyle contour integral sign";
  italcorr 4.5u#;
  currentpicture := tmp_picture;
  pickup rule.nib0;
  lft x3 = appr+hround 0.75u-eps;
  x1 = 2integral_x-x3+disp_stem;
  x2=x4=0.5[x1,x3];
  top y2 = vround(0.5[-d, h]+5.25u)+eps;
  0.5[y2, y4] = 0.5[-d, h] = y1 = y3;
  draw z1 up_to_left z2 left_to_down z3
  down_to_right z4 right_to_up z1;
  labels(1,2,3,4);
endchar;

beginchar(Bintegral_dblcont, 16u#+2appr#, 0,200/54dh#);
  "Displaystyle double contour integral sign";
  italcorr 4.5u#;
  currentpicture := tmp_picture+(tmp_picture shifted (hround 9u, 0));
  pickup rule.nib0;
  lft x3 = appr-eps;
  x1 = 2integral_x-x3+disp_stem+hround 9u;
  x2=x4=0.5[x1,x3];
  top y2 = vround(0.5[-d, h]+6u)+eps;
  0.5[y2, y4] = 0.5[-d, h] = y1 = y3;
  draw z1 up_to_left z2 left_to_down z3
  down_to_right z4 right_to_up z1;
  labels(1,2,3,4);
endchar;

