% 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,
enddef;

use_rule1;
make_sim_picture;

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

%
% Usual binary operators.
%

currentlocation_:=hex"00";

beginchar(currentlocation,arithmetic_bounds);
  "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;
  penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Minus sign";
  pickup tiny.nib; pos1(rth,90); pos2(rth,90);
  y1=y2=math_axis; lft x1=Appr; rt x2=w-Appr;
  filldraw stroke z1e..z2e; penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "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;
  penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Division 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;
  pickup null.nib;
  adjust_dot3((0.5[x1,x2],y1+math_spread[0.5x_height,0.6x_height]),
    dtsz,true,false); dot(3,3');
  adjust_dot4((0.5[x1,x2],y1-math_spread[0.5x_height,0.6x_height]),
    dtsz,true,false); dot(4,4');
  penlabels(1,2);
endchar;

beginchar(currentlocation,3u#+2appr#,v_center(7u#));
  "Centered dot";
  pickup null.nib;
  adjust_dot1((0.5w,math_axis),dtsz,false,false);
  dot(1,1');
endchar;

% known as \circ

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small circle";
  pickup rule.nib0;
  adjust_dot1((0.5w,math_axis),max(7u,dtsz+rth0),false,false);
  full_dot:=false; dot(1,1');
endchar;

beginchar(currentlocation,ast_size#+2appr#,v_center(ast_size#));
  "Small asterisk";
  autorounded;
  interim stress:=0.5;
  pickup null.nib;
  numeric b,c,dag_curve,dag_stem;
  dag_curve=ast_curve; dag_stem=ast_stem;
  b=1.8ast_stem; c=1.4ast_stem;
  %
  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.5ast_size-b)+eps,
      dag_curve,dag_stem,dir($*60+30))...z[$]'...endfor cycle;
endchar;

beginchar(currentlocation,ast_size#+2appr#,v_center(ast_size#));
  "Small co-asterisk";
  autorounded;
  interim stress:=0.5;
  pickup null.nib;
  numeric b,c,dag_curve,dag_stem;
  dag_curve=ast_curve; dag_stem=ast_stem;
  b=1.8ast_stem; c=1.4ast_stem;
  %
  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.5ast_size-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);
%   "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; penlabels(1,2,3,4);
% endchar;

% beginchar(currentlocation,arithmetic_bounds);
%   "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; penlabels(1,2,3,4);
% endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Plus-minus sign";
  numeric a; a=min(vround(rth+0.3u),0.5spread1);
  pickup tiny.nib; pos1(rth,0); pos2(rth,0);
  pos3(rth,90); pos4(rth,90); pos5(rth,90); pos6(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+0.5spread1;
  top y5r=top y6r=bot y2-a; x5=x3; x6=x4;
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  filldraw stroke z5e..z6e; penlabels(1,2,3,4,5,6);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Minus-plus sign";
  numeric a; a=min(vround(rth+0.3u),0.5spread1);
  pickup tiny.nib; pos1(rth,0); pos2(rth,0);
  pos3(rth,90); pos4(rth,90); pos5(rth,90); pos6(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-0.5spread1;
  bot y5l=bot y6l=top y1+a; x5=x3; x6=x4;
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  filldraw stroke z5e..z6e; penlabels(1,2,3,4,5,6);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Left times sign";
  pickup rule.nib; x0=good.x 0.5w;
  pickup tiny.nib; rt x0'=w-Appr; y0=y0'=math_axis;
  z1-z0=(z0'-z0) rotated 45; z3-z0=(z0'-z0) rotated -45;
  pos1(rth+2eps,-45); pos2(rth+2eps,-45);
  pos3(rth+2eps,45); pos4(rth+2eps,45);
  lft x2l=lft x4l=hround(2x0-rt x1r);
  z2=whatever[z0,z1]; z4=whatever[z0,z3];
  rt x2'-lft x2l=rt x4'-lft x4l=rth;
  z2'=whatever[z1l,z2l]; z4'=whatever[z3l,z4l];
  filldraw z1l--z2'--z4'--z3l--z3r--z4r
  --z4l--z2l--z2r--z1r--cycle;
  penlabels(1,2,3,4); labels(2',4');
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Right times sign";
  pickup rule.nib; x0=good.x 0.5w;
  pickup tiny.nib; lft x0'=Appr; y0=y0'=math_axis;
  z1-z0=(z0'-z0) rotated 45; z3-z0=(z0'-z0) rotated -45;
  pos1(rth+2eps,-45); pos2(rth+2eps,-45);
  pos3(rth+2eps,45); pos4(rth+2eps,45);
  rt x2l=rt x4l=hround(2x0-lft x1r);
  z2=whatever[z0,z1]; z4=whatever[z0,z3];
  lft x2'-rt x2r=lft x4'-rt x4r=-rth;
  z2'=whatever[z1r,z2r]; z4'=whatever[z3r,z4r];
  filldraw z1r--z2'--z4'--z3r--z3l--z4l
  --z4r--z2r--z2l--z1l--cycle;
  penlabels(1,2,3,4); labels(2',4');
endchar;

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small diamond";
  pickup tiny.nib;
  a:=sqrt(3.14159)*0.5*max(7u,dtsz+rth0);
  y2r=y4r=good.y math_axis; x1r=x3r=good.x 0.5w;
  y1r-y2r=y2r-y3r=vround(0.5a*sqrt(2)-tiny)+eps;
  x2r-x1r=x1r-x4r=hround(0.5a*sqrt(2)-tiny)+eps;
  z1l-z1r=z3r-z3l=(rth0-tiny)/sind(45)
  *(unitvector(z4r-z1r)+unitvector(z2r-z1r));
  z2l-z2r=z4r-z4l=(rth0-tiny)/sind(45)
  *(unitvector(z3r-z2r)+unitvector(z1r-z2r));
  filldraw stroke z1e--z2e--z3e--z4e--z1e;
  penlabels(1,2,3,4);
endchar;

% known as \bullet

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small full circle";
  pickup nullpen;
  adjust_dot1((0.5w,math_axis),max(7u-rth0,dtsz),false,false);
  dot(1,1');
endchar;

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small five star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),5,3.5u+o,0.2,90,false);
  labels(a);
endchar;

beginchar(currentlocation,7u#+2appr#,v_center(7u#));
  "Small six star";
  pickup tiny.nib;
  draw_star.a((0.5w,math_axis),6,3.5u+o,0.4,90,false);
  labels(a);
endchar;

% currentlocation_:=hex"10";

beginchar(currentlocation,12u#+2appr#,v_center(spread1#+rth#));
  "Equality sign";
  pickup tiny.nib;
  pos1(rth,90); pos2(rth,90); pos3(rth,90); pos4(rth,90);
  lft x1=lft x3=Appr; rt x2=rt x4=w-Appr;
  y1=y2; y3=y4; y1-y3=spread1; .5[y1,y3]=math_axis;
  filldraw stroke z1e..z2e; % upper bar
  filldraw stroke z3e..z4e; % lower bar
  penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,12u#+2appr#,v_center(2spread1#+rth#));
  "Identity sign";
  pickup tiny.nib; for i=1 upto 6: pos[i](rth,90); endfor
  lft x1=appr; x1=x3=x5; rt x2=w-appr; x2=x4=x6;
  y1=y2; y3=y4; y5=y6; y3=math_axis; y1-y3=y3-y5=spread1;
  filldraw stroke z1e..z2e; % upper bar
  filldraw stroke z3e..z4e; % middle bar
  filldraw stroke z5e..z6e; % lower bar
  penlabels(1,2,3,4,5,6);
endchar;

beginchar(currentlocation,12u#+2appr#,v_center(spread1#+rth#));
  "Similarity sign";
  currentpicture:=sim_picture;
endchar;

beginchar(currentlocation,12u#+2appr#,v_center(2spread1#+2rth#));
  "Similarity-similarity sign";
  currentpicture:=(sim_picture shifted(0,0.5(spread1+rth)))
  +(sim_picture shifted(0,-0.5(spread1+rth)));
endchar;

beginchar(currentlocation,12u#+2appr#,v_center(2spread1#+rth#));
  "Similarity-bar 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);
endchar;

beginchar(currentlocation,12u#+2appr#,v_center(3spread1#+rth#));
  "Similarity-equal sign";
  currentpicture:=sim_picture shifted(0,spread1);
  pickup tiny.nib;
  pos1(rth,90); pos2(rth,90); pos3(rth,90); pos4(rth,90);
  lft x1=lft x3=Appr; rt x2=rt x4=w-Appr;
  y3=y4=math_axis-1.5spread1; y1-y3=y2-y4=spread1;
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,12u#+2appr#,v_center(2spread1#+rth#));
  "Smile-frown sign";
  pickup tiny.nib;
  pos2(rth,90); pos5(rth,90);
  0.5[y2,y5]=math_axis; y2-y5=spread1;
  y1l=y3l=y2l+0.5spread1; y4r=y6r=y5r-0.5spread1;
  lft x1l=lft x4r=appr; rt x3l=rt x6r=w-appr; x2=x5=0.5[x1l,x3l];
  z1'-z1l=(z2l-z1l) xscaled 1/2; z4'-z4r=(z5r-z4r) xscaled 1/2;
  z3'-z3l=(z2l-z3l) xscaled 1/2; z6'-z6r=(z5r-z6r) xscaled 1/2;
  pos1(rth,angle(z1'-z1l)+90); pos4(rth,angle(z4'-z4r)+90);
  pos3(rth,angle(z3'-z3l)-90); pos6(rth,angle(z6'-z6r)-90);
  filldraw stroke z1e{z1'-z1l}...z2e{right}...z3e{z3l-z3'};
  filldraw stroke z4e{z4'-z4r}...z5e{right}...z6e{z6r-z6'};
  penlabels(1,2,3,4,5,6); labels(1',3',4',6');
endchar;

beginchar(currentlocation,7u#+2appr#,asc_height#,asc_depth#);
  "Divide sign";
  pickup tiny.nib; pos1(rth0,0); pos2(rth0,0);
  rt x1r=rt x2r=hround(0.5w+0.5rth0);
  top y1=h; bot y2=-d; filldraw stroke z1e..z2e;
  penlabels(1,2);
endchar;

% currentlocation_:=hex"18";

beginchar(currentlocation,arithmetic_bounds);
  "Not equal sign";
  pickup tiny.nib;
  pos1(rth,90); pos2(rth,90); pos3(rth,90); pos4(rth,90);
  lft x1=lft x3=Appr; rt x2=rt x4=w-Appr;
  y1=y2; y3=y4; y1-y3=spread1; .5[y1,y3]=math_axis;
  filldraw stroke z1e..z2e; % upper bar
  filldraw stroke z3e..z4e; % lower bar
  lft x6l=w-rt x5r=Appr+hround 1.75u;
  top y5r=h+eps; 0.5[bot y6l,top y5r]=math_axis;
  adjust_slanted_bar(6l,5r,6r,5l)(rth-tiny.breadth,-1);
  filldraw stroke z5e..z6e;
  penlabels(1,2,3,4,5,6);
endchar;

beginchar(currentlocation,12u#+2appr#,asc_height#,asc_depth#);
  "not identity sign";
  pickup tiny.nib; for i=1 upto 6: pos[i](rth,90); endfor
  lft x1=appr; x1=x3=x5; rt x2=w-appr; x2=x4=x6;
  y1=y2; y3=y4; y5=y6; y3=math_axis; y1-y3=y3-y5=spread1;
  filldraw stroke z1e..z2e; % upper bar
  filldraw stroke z3e..z4e; % middle bar
  filldraw stroke z5e..z6e; % lower bar
  lft x8l=w-rt x7r=appr+hround 1.75u;
  top y7r=h+eps; 0.5[bot y8l,top y7r]=math_axis;
  adjust_slanted_bar(8l,7r,8r,7l)(rth-tiny.breadth,-1);
  filldraw stroke z7e..z8e;
  penlabels(1,2,3,4,5,6,7,8);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Not similarity sign";
  currentpicture:=sim_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.breadth,-1);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Not similarity-similarity sign";
  currentpicture:=(sim_picture shifted(0,0.5(spread1+rth)))
  +(sim_picture shifted(0,-0.5(spread1+rth)));
  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.breadth,-1);
  filldraw stroke z1e..z2e; penlabels(1,2);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Not similarity-bar 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;
  lft x4l-Appr=w-Appr-rt x3r=hround 1.75u;
  top y3r=h+eps; 0.5[bot y4l,top y3r]=math_axis;
  adjust_slanted_bar(4l,3r,4r,3l)(rth-tiny.breadth,-1);
  filldraw stroke z3e..z4e; penlabels(1,2,3,4);
endchar;

beginchar(currentlocation,12u#+2appr#,asc_height#,asc_depth#);
  "Not similarity-equal sign";
  currentpicture:=sim_picture shifted(0,spread1);
  pickup tiny.nib;
  pos1(rth,90); pos2(rth,90); pos3(rth,90); pos4(rth,90);
  lft x1=lft x3=Appr; rt x2=rt x4=w-Appr;
  y3=y4=math_axis-1.5spread1; y1-y3=y2-y4=spread1;
  lft x6l-appr=w-appr-rt x5r=hround 1.75u;
  top y5r=h+eps; 0.5[bot y6l,top y5r]=math_axis;
  adjust_slanted_bar(6l,5r,6r,5l)(rth-tiny.breadth,-1);
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  filldraw stroke z6e..z5e; penlabels(1,2,3,4,5,6);
endchar;

beginchar(currentlocation,arithmetic_bounds);
  "Not smile-frown sign";
  pickup tiny.nib;
  pos2(rth,90); pos5(rth,90);
  0.5[y2,y5]=math_axis; y2-y5=spread1;
  y1l=y3l=y2l+0.5spread1; y4r=y6r=y5r-0.5spread1;
  lft x1l=lft x4r=appr; rt x3l=rt x6r=w-appr; x2=x5=0.5[x1l,x3l];
  z1'-z1l=(z2l-z1l) xscaled 1/2; z4'-z4r=(z5r-z4r) xscaled 1/2;
  z3'-z3l=(z2l-z3l) xscaled 1/2; z6'-z6r=(z5r-z6r) xscaled 1/2;
  pos1(rth,angle(z1'-z1l)+90); pos4(rth,angle(z4'-z4r)+90);
  pos3(rth,angle(z3'-z3l)-90); pos6(rth,angle(z6'-z6r)-90);
  filldraw stroke z1e{z1'-z1l}...z2e{right}...z3e{z3l-z3'};
  filldraw stroke z4e{z4'-z4r}...z5e{right}...z6e{z6r-z6'};
  lft x8l=w-rt x7r=Appr+hround 1.75u;
  top y7r=h+eps; 0.5[bot y8l,top y7r]=math_axis;
  adjust_slanted_bar(8l,7r,8r,7l)(rth-tiny.breadth,-1);
  filldraw stroke z7e..z8e;
  penlabels(1,2,3,4,5,6,7,8); labels(1',3',4',6');
endchar;

beginchar(currentlocation,7u#+2appr#,asc_height#,asc_depth#);
  "Not divide";
  pickup tiny.nib; pos1(rth0,0); pos2(rth0,0);
  rt x1r=rt x2r=hround(0.5w+0.5rth0);
  top y1=h; bot y2=-d;
  lft x3l=appr-eps; x1l-x3l=x4r-x1r; x3l=x3r; x4l=x4r;
  h-top y4r=bot y3l+d=hround 0.15(h+d)-eps;
  a:=rth0-tiny; b:=abs(z4r-z3l);
  y3r-y3l=y4r-y4l=a/(((x4r-x3l)/b)*((b+-+a)/b)+((y4r-y3l)/b)*(a/b));
  filldraw stroke z1e..z2e; filldraw stroke z3e..z4e;
  penlabels(1,2,3,4);
endchar;