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

def horizontal_rules_list=math_axis,
  -body_depth,-desc_depth,x_height,cap_height,asc_height,body_height
enddef;

vardef draw_polygon@#(expr center,n_edges,angle_init,sqrt_area)=
  save a,b;
  x@#=good.x xpart center; y@#=good.y ypart center;
  a=sqrt_area/sqrt((n_edges*cosd(180/n_edges)*sind(180/n_edges)))
  -0.5currentbreadth;
  b=(rth-currentbreadth)/cosd(180/n_edges);
  for $=1 upto n_edges:
    z@#[$]r=z@#+round(a*dir(($-1)*360/n_edges+angle_init));
    z@#[$]r-z@#[$]l=b*dir(($-1)*360/n_edges+angle_init);
    penlabels(@#[$]);
  endfor
  filldraw stroke for $=1 upto n_edges: z@#[$]e--endfor z@#[1]e;
enddef;

use_rule1;

% The square root of the total area has been calculated
% so that circle would fit the bounding box.

beginchar(hex"B0",arithmetic_bounds);
  "Square a";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),4,45,6u*sqrt 3.14159);
  labels(a);
endchar;

beginchar(hex"B1",arithmetic_bounds);
  "Pentagon a";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),5,90,6u*sqrt 3.14159);
  labels(a);
endchar;

beginchar(hex"B2",arithmetic_bounds);
  "Hexagon a";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),6,90,6u*sqrt 3.14159);
  labels(a);
endchar;

beginchar(hex"B3",arithmetic_bounds);
  "Octogon a";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),8,22.5,6u*sqrt 3.14159);
  labels(a);
endchar;

beginchar(hex"B4",arithmetic_bounds);
  "Square b";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),4,0,6u*sqrt 3.14159);
  labels(a);
endchar;

beginchar(hex"B5",arithmetic_bounds);
  "Pentagon b";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),5,-90,6u*sqrt 3.14159);
  labels(a);
endchar;

beginchar(hex"B6",arithmetic_bounds);
  "Hexagon b";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),6,0,6u*sqrt 3.14159);
  labels(a);
endchar;

beginchar(hex"B7",arithmetic_bounds);
  "Octogon b";
  pickup tiny.nib;
  draw_polygon.a((0.5w,math_axis),8,0,6u*sqrt 3.14159);
  labels(a);
endchar;

use_rule0;

beginchar(hex"B8",arithmetic_bounds);
  "5-bright-star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),5,6u,0.05,90,true);
  labels(a);
endchar;

beginchar(hex"B9",arithmetic_bounds);
  "5-black-star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),5,6u,0.1,90,false);
  labels(a);
endchar;

beginchar(hex"BA",arithmetic_bounds);
  "6-bright-star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),6,6u,0.05,90,true);
  labels(a);
endchar;

beginchar(hex"BB",arithmetic_bounds);
  "6-black-star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),6,6u,0.2,90,false);
  labels(a);
endchar;

use_rule1;

% mathltlk.mf

%
% Q
%

beginchar(Q_northwest,13u#+2appr#,cap_height#,0);
  "Q northwest";
  autorounded; pickup rule.nib;
  top y2=h+o; bot y4=-d-o; lft x3=appr; rt x1=w-appr;
  x2=x4=0.5[x1,x3]; y1=y3=0.5[y2,y4];
  tmp_path:=superellipse(z1,z2,z3,z4,1/sqrt 2);
  draw tmp_path; pickup tiny.nib; top y5=h; lft x5=appr;
  z5'=tmp_path intersectionpoint ((x2,y1)..z5);
  (sqrt 2)*(z5-z5')=z5'-z6; a:=angle(z5-z6)-90; pos5(rth,a); pos6(rth,a);
  filldraw stroke z5e..z6e;
  labels(1,2,3,4); penlabels(5,6);
endchar;

beginchar(Q_northeast,13u#+2appr#,cap_height#,0);
  "Q northeast";
  autorounded; pickup rule.nib;
  top y2=h+o; bot y4=-d-o; lft x3=appr; rt x1=w-appr;
  x2=x4=0.5[x1,x3]; y1=y3=0.5[y2,y4];
  tmp_path:=superellipse(z1,z2,z3,z4,1/sqrt 2);
  draw tmp_path; pickup tiny.nib; top y5=h; rt x5=w-appr;
  z5'=tmp_path intersectionpoint ((x2,y1)..z5);
  (sqrt 2)*(z5-z5')=z5'-z6; a:=angle(z5-z6)-90; pos5(rth,a); pos6(rth,a);
  filldraw stroke z5e..z6e;
  labels(1,2,3,4); penlabels(5,6);
endchar;

beginchar(Q_southwest,13u#+2appr#,cap_height#,0);
  "Q southwest";
  autorounded; pickup rule.nib;
  top y2=h+o; bot y4=-d-o; lft x3=appr; rt x1=w-appr;
  x2=x4=0.5[x1,x3]; y1=y3=0.5[y2,y4];
  tmp_path:=superellipse(z1,z2,z3,z4,1/sqrt 2);
  draw tmp_path; pickup tiny.nib; bot y5=-d; lft x5=appr;
  z5'=tmp_path intersectionpoint ((x2,y1)..z5);
  (sqrt 2)*(z5-z5')=z5'-z6; a:=angle(z5-z6)-90; pos5(rth,a); pos6(rth,a);
  filldraw stroke z5e..z6e;
  labels(1,2,3,4); penlabels(5,6);
endchar;

beginchar(Q_southeast,13u#+2appr#,cap_height#,0);
  "Q southeast";
  autorounded; pickup rule.nib;
  top y2=h+o; bot y4=-d-o; lft x3=appr; rt x1=w-appr;
  x2=x4=0.5[x1,x3]; y1=y3=0.5[y2,y4];
  tmp_path:=superellipse(z1,z2,z3,z4,1/sqrt 2);
  draw tmp_path; pickup tiny.nib; bot y5=-d; rt x5=w-appr;
  z5'=tmp_path intersectionpoint ((x2,y1)..z5);
  (sqrt 2)*(z5-z5')=z5'-z6; a:=angle(z5-z6)-90; pos5(rth,a); pos6(rth,a);
  filldraw stroke z5e..z6e;
  labels(1,2,3,4); penlabels(5,6);
endchar;

%
%  Z
%

vardef tmp_program(expr stem,radius,
    up_adjustment,bot_adjustment)=
  pickup tiny.nib; save R,a,c,s;
  pos1(stem,90); pos2(stem,90); pos3(stem,0);
  pos6(stem,0); pos7(stem,90); pos8(stem,90);
  bot y1l=bot y2l=y0-radius=y3-radius=-d;
  top y7r=top y8r=y0'+radius=y6+radius=h;
  rt x1+hround bot_adjustment=rt x6r=w-appr;
  x0'=x7=w-appr-radius;
  lft x3l=lft x8-hround up_adjustment=appr;
  x0=x2=appr+radius;
  a=0.5length(z0'-z0); R=radius-0.5stem;
  c=0.5((R/a)*(abs(x0'-x0)/a)-(abs(y0'-y0)/a)*((a+-+R)/a));
  s=1+-+c; z5-z0'=-R*(c,s); z4-z0=R*(c,s);
  pos4(stem,angle(-c,-s)); pos5(stem,angle(-c,-s));
  filldraw stroke z1e..z2e left_to_up z3e...z4e
  ---z5e...z6e up_to_left z7e..z8e;
  penlabels(1,2,3,4,5,6,7,8); labels(0,0');
enddef;

beginchar(Bourbaki_Z,12u#+2appr#,cap_height#,0);
  "Bourbaki's Z";
  tmp_program(cap_stem,1.6cap_stem,1.2*0.6u,1.2*0.3u);
endchar;

beginchar(bBourbaki_Z,16u#+2appr#,0,10/6dh#);
  "Bourbaki's Z";
  tmp_program(round 1.2cap_curve,1.6*1.2cap_curve,1.6*0.6u,1.6*0.3u);
endchar;

beginchar(BBourbaki_Z,22u#+2appr#,0,14/6dh#);
  "Bourbaki's Z";
  tmp_program(round 1.4cap_curve,1.6*1.4cap_curve,2.2*0.6u,2.2*0.3u);
endchar;

% mathsymb.mf

beginchar(nuclear_sign,arithmetic_bounds);
  "Nuclear sign";
  a:=0.13; t:=1.6;
  autorounded;
  pickup null.nib;
  adjust_dot1((0.5w,0.5[-d,h]),dtsz,true,true);
  dot(1,1');
  pickup rule.nib0;
  top y7=top y4=h; bot y2=bot y9=-d;
  lft x5=lft x8=appr; rt x6=rt x3=w-appr;
  y5=y6=a[y2,y4]; y3=y8=a[y4,y2];
  x2=x7=a[x5,x6]; x4=x9=a[x6,x5];
  draw z2{right}..tension atleast t..z3{up}...z4{left}
  ..tension atleast t..z5{down}...cycle;
  draw z6{up}..tension atleast t..z7{left}...z8{down}
  ..tension atleast t..z9{right}...cycle;
  labels(2,3,4,5,4,5,6,7,8,9);
endchar;

% SMILES AND FROWNS

use_rule1;

beginchar(smile_small,12u#+2appr#,v_center(spread1#+rth#));
  "Small smile sign";
  pickup tiny.nib;
  pos2(rth,90);
  y2=math_axis-0.5spread1; y1l=y3l=y2l+spread1;
  lft x1l=appr; rt x3l=w-appr; x2=0.5[x1l,x3l];
  z1'-z1l=(z2l-z1l) xscaled 1/3;
  z3'-z3l=(z2l-z3l) xscaled 1/3;
  pos1(rth,angle(z1'-z1l)+90);
  pos3(rth,angle(z3'-z3l)-90);
  filldraw stroke z1e{z1'-z1l}...z2e{right}...z3e{z3l-z3'};
  penlabels(1,2,3); labels(1',3');
endchar;

beginchar(frown_small,12u#+2appr#,v_center(spread1#+rth#));
  "Small frown sign";
  pickup tiny.nib;
  pos2(rth,90);
  y2=math_axis+0.5spread1; y1r=y3r=y2r-spread1;
  lft x1r=appr; rt x3r=w-appr; x2=0.5[x1r,x3r];
  z1'-z1r=(z2r-z1r) xscaled 1/3;
  z3'-z3r=(z2r-z3r) xscaled 1/3;
  pos1(rth,angle(z1'-z1r)+90);
  pos3(rth,angle(z3'-z3r)-90);
  filldraw stroke z1e{z1'-z1r}...z2e{right}...z3e{z3r-z3'};
  penlabels(1,2,3); labels(1',3');
endchar;

make_sim_picture;

beginchar(sim_sim_bar,12u#+2appr#,v_center(3spread1#+2rth#));
  "Similarity-similarity-bar sign";
  currentpicture:=(sim_picture shifted(0,spread1+rth))+
  sim_picture;% shifted(0,-0.5(spread1+rth));
  pickup tiny.nib;
  pos1(rth,90); pos2(rth,90);
  lft x1=Appr; rt x2=w-Appr; y1=y2=math_axis-1.5spread1;
  filldraw stroke z1e..z2e; penlabels(1,2);
  tmp_picture:=currentpicture;
endchar;

beginchar(sim_sim_not_bar,12u#+2appr#,asc_height#,asc_depth#);
  "Not similarity-similarity_bar sign";
  currentpicture:=tmp_picture;
  pickup tiny.nib;
  lft x2l-appr=w-appr-rt x1r=hround 1.75u;
  top y1r=h+eps; 0.5[bot y2l,top y1r]=math_axis;
  adjust_slanted_bar(2l,1r,2r,1l)(rth-tiny,-1);
  filldraw stroke z2e..z1e; penlabels(1,2);
endchar;

beginchar(bar_sim,12u#+2appr#,v_center(2spread1#+rth#));
  "Bar-similarity sign";
  currentpicture:=sim_picture shifted(0,-vround 0.5spread1);
  pickup tiny.nib;
  pos1(rth,90); pos2(rth,90);
  lft x1=Appr; rt x2=w-Appr; y1=y2=math_axis+spread1;
  filldraw stroke z1e..z2e; penlabels(1,2);
  tmp_picture:=currentpicture;
endchar;

beginchar(bar_sim_not,arithmetic_bounds);
  "Not bar-similarity sign";
  currentpicture:=tmp_picture;
  pickup tiny.nib;
  lft x2l-Appr=w-Appr-rt x1r=hround 1.75u;
  top y1r=h+eps; 0.5[bot y2l,top y1r]=math_axis;
  adjust_slanted_bar(2l,1r,2r,1l)(rth-tiny,-1);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(sim_vert,arithmetic_bounds);
  "Sim-vert sign";
  currentpicture:=sim_picture rotatedaround((0.5w,math_axis),90);
endchar;

beginchar(sim_reverse,12u#+2appr#,v_center(spread1#+rth#));
  "Sim-reverse sign";
  currentpicture:=sim_picture reflectedabout((0.5w,0),(0.5w,h));
endchar;

beginchar(sim_reverse_bar,12u#+2appr#,v_center(2spread1#+rth#));
  "Sim-reverse-bar sign";
  currentpicture:=sim_picture reflectedabout((0.5w,0),(0.5w,h))
  shifted(0,vround 0.5spread1);
  pickup tiny.nib;
  pos1(rth,90); pos2(rth,90);
  lft x1=Appr; rt x2=w-Appr; y1=y2=math_axis-spread1;
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(reverse_negation_sign,12u#+2appr#,v_center(spread1#+rth#));
  "Reverse negation sign";
  pickup tiny.nib;
  pos1(rth,-90); pos3(rth,0);
  y2r=y1r; y2l=y1l; x2l=x3l; x2r=x3r;
  y1=math_axis+0.5spread1; y1r-y3=spread1;
  rt x1=w-Appr; lft x3l=Appr;
  filldraw stroke z1e--z2e--z3e;
  penlabels(1,2,3);
endchar;

beginchar(smash_product_sign,arithmetic_bounds);
  "Smash product sign";
  pickup tiny.nib;
  top y1r=top y5l=h+eps; bot y4l=bot y8r=-d-eps;
  lft x3l=lft x6l=appr-eps; rt x2r=rt x7r=w-appr+eps;
  y1r-y3l=y5r-y7l=y6l-y8r=y2r-y4l=vround((spread1+rth-tiny)/sqrt 2);
  x1r-x3l=x7r-x5l=x8r-x6l=x2r-x4l=hround((spread1+rth-tiny)/sqrt 2);
  pos1(rth,45); pos2(rth,45); pos3(rth,45); pos4(rth,45);
  pos5(rth,-45); pos6(rth,-45); pos7(rth,-45); pos8(rth,-45);
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  filldraw stroke z5e..z6e; filldraw stroke z7e..z8e;
  penlabels(1,2,3,4,5,6,7,8);
endchar;

% The next design is taken from my favorite pen:
% a Omas' Paragon.

beginchar(greek_motive,24u#,body_height#,0);
  "Decorative greek motive";
  numeric a,b; a=2max(hround 0.5rth1,1);
  b=a*(1++slant);
  pickup pencircle scaled a;
  if 0.5w<>good.x 0.5w: change_width; fi
  x21=x22=good.x 0.5w;
  x1=x3=x5l=x6l=-1; x2=x4=x20l=x19l=w+1;
  x7=x8=good.x 0.75[x1,x21]; x17=x18=x21+(x21-x7);
  x9=x10=good.x 0.5[x1,x21]; x15=x16=x21+(x21-x9);
  x11=x12=good.x 0.25[x1,x21]; x13=x14=x21+(x21-x11);
  y1r=y2r=h; y3l=y4l=-d; penpos1(a,90);
  penpos2(a,90); penpos3(a,90); penpos4(a,90);
  penpos5(0.5b+1,0); penpos20(0.5b+1,180);
  penpos21(b,0); penpos22(b,0);
  y6=y7=y18=y19=good.y 0.2[y3,y1]; y22=bot y6;
  y12=y21=y13=good.y 0.8[y3,y1]; y5=y20=top y12;
  y10=y11=y14=y15=good.y 0.3[y6,y12];
  y8=y9=y16=y17=good.y 0.7[y6,y12];
  forsuffixes $=6,7,12,13,18,19:
    y$r-y$l=a; z$=0.5[z$r,z$l]; endfor
  forsuffixes $=8,9,10,11,14,15,16,17:
    y$l-y$r=a; z$=0.5[z$r,z$l]; endfor
  forsuffixes $=9,10,13,14,17,18:
    x$r-x$l=b; endfor
  x6r-x6l=x19l-x19r=0.5b+1;
  forsuffixes $=7,8,11,12,15,16:
    x$l-x$r=b; endfor
  penstroke z1e..z2e; penstroke z3e..z4e; penstroke z21e..z22e;
  penstroke z5e--z6e--z7e--z8e--z9e--z10e--z11e--
  z12e--z13e--z14e--z15e--z16e--z17e--z18e--z19e--z20e;
  penlabels(range 1 thru 22);
endchar;

% The next motive appears in ITC's Kokoa font.
% The designer (Jochen Schuss) has been inspired by
% a trip in Ghana. It is therefore possible that
% this design is not copyright since it may be
% a traditionnal one.

beginchar(ghanean_motive,14u#,body_height#,body_depth#);
  "Decorative ghanean motive";
  numeric a; a=2max(hround 0.5rth1,1);
  pickup pencircle scaled a;
  if 0.5w<>good.x 0.5w: change_width; fi
  numeric b; b=vround((h+d)/7);
  x2=x3=x8l=x15l=x21l=0.5w;
  x1r=x5r=x12r=x19l=x20l=0;
  x4r=x11r=x18r=x23l=x22l=w;
  y1r=y4r=h;
  y1r-y5r=y5r-y12r=y12r-y19l=b;
  y4r-y11r=y11r-y18r=y18r-y23l=b;
  y3-y8l=y8l-y15l=y15l-y21l=b;
  y1r-y2=y2-y3=y19l-y20l=y23l-y22l=2b;
  x6=x7=good.x 2/3[x1r,x2]; x9=x10=x2+(x2-x6); 
  x13=x14=good.x 1/3[x1r,x2]; x16=x17=x2+(x2-x13);
  forsuffixes $=2,3,6,7,13,14:
    x$r-x$l=a; x$=0.5[x$r,x$l];
  endfor
  forsuffixes $=10,9,17,16:
    x$r-x$l=-a; x$=0.5[x$r,x$l];
  endfor
  numeric b,c;
  b=a/abs cosd angle(z2-z1r);
  c=a/abs cosd angle(z2-z4r);
  penpos1(b,90); penpos5(b,90); penpos12(b,90);
  penpos4(c,90); penpos11(c,90); penpos18(c,90);
  x19r-x19l=x20r-x20l=x23l-x23r=x22l-x22r=0.5a;
% 
  z21r-(z21l+z1r-z1l)=whatever*(z2-z1r);
  z21r-(z21l+z4r-z4l)=whatever*(z2-z4r);
  z8r-z8l=z15r-z15l=z21r-z21l;
%
  z2l-z1l=whatever*(z2-z1r); z3-z3l=whatever*(z2-z1r);
  z6r-z5r=whatever*(z2-z1r); z6l-z5l=whatever*(z2-z1r);
  z8r-z7r=whatever*(z2-z1r); z8l-z7l=whatever*(z2-z1r);
  z13r-z12r=whatever*(z2-z1r); z13l-z12l=whatever*(z2-z1r);
  z15r-z14r=whatever*(z2-z1r); z15l-z14l=whatever*(z2-z1r);
  z19r-z19l=whatever*(z2-z1r);
  z21r-z20r=whatever*(z2-z1r);% z21l-z20l=whatever*(z2-z1r);
%
  z2r-z4l=whatever*(z2-z4r); z3-z3r=whatever*(z2-z4r);
  z10r-z11r=whatever*(z2-z4r); z10l-z11l=whatever*(z2-z4r);
  z8r-z9r=whatever*(z2-z4r); z8l-z9l=whatever*(z2-z4r);
  z17r-z18r=whatever*(z2-z4r); z17l-z18l=whatever*(z2-z4r);
  z15r-z16r=whatever*(z2-z4r); z15l-z16l=whatever*(z2-z4r);
  z23r-z23l=whatever*(z2-z4r);
  z21r-z22r=whatever*(z2-z4r);% z21l-z22l=whatever*(z2-z4r);
%
  fill z1r--z2--z4r--z4l--z2r--z3r--z3--z3l--z2l--z1l--cycle;
  penstroke z5e--z6e--z7e--z8e--z9e--z10e--z11e;
  penstroke z12e--z13e--z14e--z15e--z16e--z17e--z18e;
  penstroke z19e--z20e--z21e--z22e--z23e;
  penlabels(range 1 thru 23);
endchar;

%
% doted symbols
%

beginchar(cap_dot,12u#+2appr#,x_height#,0);
  "Small cap with dot sign";
  pickup tiny.nib;
  pos1(rth,180); pos2(rth,180);
  pos4(rth,0); pos5(rth,0);
  y3+0.5rth=h+o; bot y1r=bot y5r=-d; y2=y4=2/3[y3,y1r];
  lft x1r=w-rt x5r=appr+hround 0.8u;
  x1=x2; x4=x5; x3=0.5[x2,x4];
  filldraw stroke z1e..z2e; filldraw stroke z4e..z5e;
  pickup rule.nib; autorounded;
  draw z2 up_to_right z3 right_to_down z4;
  penlabels(1,2,3,4,5);
  adjust_dot6((0.5w,h-math_axis),dtsz,false,true);
  dot(6,6');
endchar;

beginchar(cup_dot,12u#+2appr#,x_height#,0);
  "Small cup with dot sign";
  pickup tiny.nib;
  pos1(rth,180); pos2(rth,180);
  pos4(rth,0); pos5(rth,0);
  y3-0.5rth=-d-o; top y1r=top y5r=h; y2=y4=2/3[y3,y1r];
  lft x1r=w-rt x5r=appr+hround 0.8u;
  x1=x2; x4=x5; x3=0.5[x2,x4];
  filldraw stroke z5e..z4e; filldraw stroke z2e..z1e;
  pickup rule.nib; autorounded;
  draw z2 down_to_right z3 right_to_up z4;
  penlabels(1,2,3,4,5);
  adjust_dot6((0.5w,math_axis),dtsz,false,true);
  dot(6,6');
endchar;

beginchar(sqcap_dot,12u#+2appr#,x_height#,0);
  "Small square cap with dot sign";
  pickup tiny.nib;
  pos1(rth,180); pos4(rth,0);
  top y2r=top y3r=h; bot y1=bot y4=-d;
  top y2r-bot y2l=top y3r-bot y3l=rth;
  lft x1r=w-rt x4r=appr+hround 0.95u;
  x2r=x1r; x3r=x4r; x2l=x1l; x3l=x4l;
  filldraw stroke z1e--z2e--z3e--z4e;
  penlabels(1,2,3,4);
  adjust_dot5((0.5w,h-math_axis),dtsz,false,true);
  dot(5,5');
endchar;

beginchar(sqcup_dot,12u#+2appr#,x_height#,0);
  "Small square cup with dot sign";
  pickup tiny.nib;
  pos1(rth,180); pos4(rth,0);
  bot y2r=bot y3r=-d; top y1=top y4=h;
  top y2l-bot y2r=top y3l-bot y3r=rth;
  lft x1r=w-rt x4r=appr+hround 0.95u;
  x2r=x1r; x3r=x4r; x2l=x1l; x3l=x4l;
  filldraw stroke z4e--z3e--z2e--z1e;
  penlabels(1,2,3,4);
  adjust_dot5((0.5w,math_axis),dtsz,false,true);
  dot(5,5');
endchar;
