% mathematical symbols by Anthony Phan.
% file: mathsymb.mf (various 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,
  math_axis-0.5spread1,math_axis-0.5spread2,math_axis-0.5spread3,
  math_axis-0.5spread4,
  math_axis+0.5spread1,math_axis+0.5spread2,math_axis+0.5spread3,
  math_axis+0.5spread4,
enddef;

%%% !!! marked signs are to be revised

use_rule1;

% standard

beginchar(hex"20",6u#+2letter_fit#,0,0);
  "Normal space";
endchar;

% hex"00"

beginchar(currentlocation,arithmetic_bounds);
  "Top dot plus sign";
  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; y3=y4=math_axis;
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  pickup null.nib;
  adjust_dot5((x1,y3+6.5u+0.5dtsz),dtsz,true,false); dot(5,5');
  penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Top dot minus sign";
  pickup tiny.nib;
  lft x1=Appr; rt x2=w-Appr;
  y2=y1=math_axis; pos1(rth,90); pos2(rth,90);
  filldraw stroke z1e..z2e; penlabels(1,2);
  adjust_dot3((0.5[x1,x2],y1+math_spread[0.5x_height,0.6x_height]),
    dtsz,true,false); dot(3,3');
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Top dot times sign";
  pickup rule.nib; x0=good.x 0.5w;
  pickup tiny.nib; rt x0'=w-Appr; y0=y0'=math_axis;
  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;
  pickup null.nib;
  adjust_dot5((x0,y0+5.5u+0.5dtsz),dtsz,true,false); dot(5,5');
  penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Bot dot minus sign";
  pickup tiny.nib;
  lft x1=Appr; rt x2=w-Appr;
  y2=y1=math_axis; pos1(rth,90); pos2(rth,90);
  filldraw stroke z1e..z2e; penlabels(1,2);
  adjust_dot3((0.5[x1,x2],y1-math_spread[0.5x_height,0.6x_height]),
    dtsz,true,false); dot(3,3');
endchar;

beginchar(currentlocation,3u#+2appr#,cap_height#,0);
  "Cap centered dot";
  pickup null.nib;
  adjust_dot1((0.5w,0.5h),1.2dtsz,false,false);
  dot(1,1');
endchar;

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small box";
  pickup tiny.nib;
  a:=sqrt(3.14159)*0.5*max(7u,dtsz+rth0);
  top y1r=top y2r=vround(math_axis+0.5a);
  bot y3r=bot y4r=top y1r-vround a;
  lft x1r=lft x4r=hround 0.5(w-a);
  rt x2r=rt x3r=lft x1r+hround a;
  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(currentlocation,arithmetic_bounds);
  "Large asterisk";
  autorounded;
  interim stress:=0.5; pickup null.nib;
  numeric b,c,dag_curve,dag_stem; spread:=12u;
  b=2.6hair; c=0.625b; dag_curve=round 1.1cap_curve; dag_stem=hair;
  %
  x0=hround(0.5w-0.5dag_curve)+0.5dag_curve;
  y0=0.5[-d,h];
  for $=1 upto 6: z[$]=b*dir($*60+30)+z0;
    z[$]'=c*dir($*60+60)+z0; endfor
  filldraw for $=1 upto 6: dagger_stroke[$](round(0.5spread-b)+eps,
      dag_curve,dag_stem,dir($*60+30))...z[$]'...endfor cycle;
  labels(0,1',2',3',4',5',6');
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Large co-asterisk";
  autorounded;
  interim stress:=0.5;
  pickup null.nib;
  numeric b,c,dag_curve,dag_stem; spread:=12u;
  b=2.6hair; c=0.625b; dag_curve=round 1.1cap_curve; dag_stem=hair;
  %
  x0=hround(0.5w-0.5dag_curve)+0.5dag_curve;
  y0=0.5[-d,h];
  for $=1 upto 6: z[$]=b*dir($*60-60)+z0;
    z[$]'=c*dir($*60-30)+z0; endfor
  filldraw for $=1 upto 6: dagger_stroke[$](round(0.5spread-b)+eps,
      dag_curve,dag_stem,dir($*60-60))...z[$]'...endfor cycle;
  labels(0,1',2',3',4',5',6');
endchar;

% beginchar(currentlocation,arithmetic_bounds);
%   "Top dot truc sign";
%   pickup tiny.nib;
%   pos1(rth,0); pos2(rth,0); pos3(rth,90); pos4(rth,90);
%   top y1=top y3r=top y4r=h; bot y2=-d;
%   lft x1l=hround 0.5(w-rth); x2=x1;
%   lft x3=Appr; x1-x3=x4-x1; filldraw stroke z1e..z2e;
%   filldraw stroke z3e..z4e; pickup null.nib;
%   adjust_dot5((x1,h+u+0.5dtsz),dtsz,true,false); dot(5,5');
%   penlabels(1,2,3,4);
% endchar;

% beginchar(currentlocation,arithmetic_bounds);
%   "Top dot curT sign";
%   pickup tiny.nib;
%   pos1(rth,0); pos2(rth,0); pos3(rth,90); pos4(rth,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; pickup null.nib;
%   adjust_dot5((x1,h+u+0.5dtsz),dtsz,true,false); dot(5,5');
%   penlabels(1,2,3,4);
% endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Top circ plus sign";
  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; y3=y4=math_axis;
  filldraw stroke z1e..z2e; % stem
  filldraw stroke z3e..z4e; % crossbar
  pickup rule.nib0;
  adjust_dot5((x1,y3+6u+0.5rth0+1.5u),3u+rth0,true,false);
  full_dot:=false; dot(5,5');
  penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Plus circle sign";
  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; y3=y4=math_axis;
  filldraw stroke z1e..z2e; % stem
  filldraw stroke z3e..z4e; % crossbar
  pickup rule.nib; z0=(x1,y3);
  rt x5=ceiling rt 0.75[Appr,w-Appr]+eps; y5=y0;
  z5-z0=z0-z7; z6-z0=z0-z8=(z5-z0) rotated 90;
  draw superellipse(z5,z6,z7,z8,superness);
  penlabels(1,2,3,4); labels(5,6,7,8);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Convolution sign";
  numeric darkness; darkness=0.8;
  pickup rule.nib; x0=good.x 0.5w;
  pickup tiny.nib; rt x1=w-Appr; y0=y1=y1'=y1''=math_axis;
  x1'=min(x0+2.5rth,0.5[x0,x1]); x1''=min(x0+1.25rth,0.25[x0,x1]);
  forsuffixes $=,':
    z1$-z0=z0-z2$; z3$-z0=z0-z4$=(z1$-z0) rotated 45;
    z5$-z0=z0-z6$=(z1$-z0) rotated 90;
    z7$-z0=z0-z8$=(z1$-z0) rotated -45;
    pos1$(rth,90); pos2$(rth,90); pos3$(rth,135); pos4$(rth,135);
    pos5$(rth,0); pos6$(rth,0); pos7$(rth,45); pos8$(rth,45);
    penlabels(1$,2$,3$,4$,5$,6$,7$,8$);
  endfor
  z1''-z0=z0-z2''; z3''-z0=z0-z4''=(z1''-z0) rotated 45;
  z5''-z0=z0-z6''=(z1''-z0) rotated 90;
  z7''-z0=z0-z8''=(z1''-z0) rotated -45;
  pos1''(darkness*rth,90); pos2''(darkness*rth,90);
  pos3''(darkness*rth,135); pos4''(darkness*rth,135);
  pos5''(darkness*rth,0); pos6''(darkness*rth,0);
  pos7''(darkness*rth,45); pos8''(darkness*rth,45);
  penlabels(1'',2'',3'',4'',5'',6'',7'',8'');
  filldraw stroke z2e---z2'e...z2''e---z1''e...z1'e---z1e;
  filldraw stroke z4e---z4'e...z4''e---z3''e...z3'e---z3e;
  filldraw stroke z5e---z5'e...z5''e---z6''e...z6'e---z6e;
  filldraw stroke z8e---z8'e...z8''e---z7''e...z7'e---z7e;
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Divide on times sign";
  numeric darkness; darkness=0.8;
  pickup rule.nib; x0=good.x 0.5w;
  pickup tiny.nib; rt x1=w-Appr; y0=y1=y1'=y1''=math_axis;
  x1'=min(x0+2.5rth,0.5[x0,x1]); x1''=min(x0+1.25rth,0.25[x0,x1]);
  z1-z0=z0-z2; z1'-z0=z0-z2'; z1''-z0=z0-z2'';
  z3-z0=z0-z4=(z1-z0) rotated 45; z7-z0=z0-z8=(z1-z0) rotated 135;
  pos1(rth,90); pos2(rth,90); pos1'(rth,90); pos2'(rth,90);
  pos3(rth,135); pos4(rth,135); pos7(rth,225); pos8(rth,225);
  pos1''(darkness*rth,90); pos2''(darkness*rth,90);
  filldraw stroke z2e---z2'e...z2''e---z1''e...z1'e---z1e;
  filldraw stroke z4e..z3e; filldraw stroke z8e..z7e;
  pickup null.nib;
  adjust_dot5((x0,y0+5.5u-0.5dtsz),dtsz,true,false); dot(5,5');
  adjust_dot6((x0,y0-5.5u+0.5dtsz),dtsz,true,false); dot(6,6');
  penlabels(1,1',1'',2,2',2'',3,4,7,8);
endchar;

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small full diamond";
  pickup tiny.nib;
  a:=sqrt(3.14159)*0.5*max(7u,dtsz+rth0)-0.5rth0;
  y2=y4=good.y math_axis; x1=x3=good.x 0.5w;
  y1-y2=y2-y3=vround(0.5a*sqrt(2)-tiny)+eps;
  x2-x1=x1-x4=hround(0.5a*sqrt(2)-tiny)+eps;
  fill z1--z2--z3--z4--cycle;
  labels(1,2,3,4);
endchar;

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small full box";
  pickup tiny.nib;
  a:=sqrt(3.14159)*0.5*max(7u-rth0,dtsz);
  top y1=top y2=vround(math_axis+0.5a);
  bot y3=bot y4=top y1-vround a;
  lft x1=lft x4=hround 0.5(w-a);
  rt x2=rt x3=lft x1+hround a;
  filldraw z1--z4--z3--z2--cycle;
  labels(1,2,3,4);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Big five star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),5,6u+o,0.1,90,false);
  labels(a);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Big six star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),6,6u+o,0.3,90,false);
  labels(a);
endchar;

% hex"10"
