% mathematical symbols by Anthony Phan.
% file: mathfine.mf (various fine 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;

%beginchar(Infinity,13.8u#+2appr#,v_center(0.2[x_height#,cap_height#]));
%  "Infinity";
%  numeric a,b; pickup fine.nib;
%  b=vround 0.3[fine,curve];
%  a=vround((h+d)/18); slope:=(h+d)/3u;
%  pos5(curve,angle(-1,-slope)-90);
%  pos11(b,-90); pos14(b,-90);
%  y1=y9=y5=(h-d)/2; top y7r=h+eps; bot y11r=-d-eps;
%  y7r-y14l=y3l-y11r=a; y3-y3l=y3r-y3=y7-y7l=y7r-y7=y11l-y11;
%  lft x1=appr; rt x9=w-appr; (x5-x1)/(y14-y3)=(x9-x5)/(y7-y11);
%  forsuffixes $=,r,l:
%    hellipse_set(1,3$,4$,5$); hellipse_set(9,7$,6$,5$);
%  endfor
%  slope:=-slope;
%  hellipse_set(1,14,13,5); hellipse_set(9,11,12,5);
%  y15=y13; x13-x14=x14-x15; x15=x2; y15-y1=y1-y2;
%  y10=y12; x10-x11=x11-x12; x8=x10; y10-y9=y9-y8;
%  filldraw stroke z1{down}...z2{1,slope}...z3e{right}...z4e---z6e
%  ...z7e{right}...z8{1,slope}...z9{down}...z10{-1,slope}...
%  z11e{left}...z12---z13...z14e{left}...z15{-1,slope}...z1{down};
%  penlabels(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
%  tmp_picture:=currentpicture;
%endchar;

beginchar(Infinity,13.8u#+2appr#,v_center(spread3#));
  "Infinity";
  numeric a,b; pickup fine.nib;
  a=vround((h+d+2o)/18); b=vround 0.3[fine,curve];
  slope:=(h+d+2o)/3.15u;
  pos5(0.3[stem,curve],angle(-1,-slope)-90);
  pos11(b,-90); pos14(b,-90);
  y1=y9=y5=(h-d)/2; top y7r=h+o; bot y11r=-d-o;
  y7r-y14l=y3l-y11r=a; y3-y3l=y3r-y3=y7-y7l=y7r-y7=y11l-y11;
  lft x1=appr; rt x9=w-appr; (x5-x1)/(y14-y3)=(x9-x5)/(y7-y11);
  forsuffixes $=,r,l:
    hellipse_set(1,3$,4$,5$); hellipse_set(9,7$,6$,5$);
  endfor
  slope:=-slope;
  hellipse_set(1,14,13,5); hellipse_set(9,11,12,5);
  y15=y13; x13-x14=x14-x15; x15=x2; y15-y1=y1-y2;
  y10=y12; x10-x11=x11-x12; x8=x10; y10-y9=y9-y8;
  filldraw stroke z1{down}...z2{1,slope}...z3e{right}...z4e---z6e
  ...z7e{right}...z8{1,slope}...z9{down}...z10{-1,slope}...
  z11e{left}...z12---z13...z14e{left}...z15{-1,slope}...z1{down};
  penlabels(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
  tmp_picture:=currentpicture;
endchar;

iff (known Infinity) and (known proportionnal_to):
beginchar(proportionnal_to,12u#+2appr#,v_center(spread3#));
  "Proportionnal to sign";
  currentpicture:=tmp_picture;
  cullit;
  unfill (w-appr,-d)--(w-appr+4u,-d)--
  (w-appr+4u,h)--(w-appr,h)--cycle;
endchar;

%
% a revoir
%
beginchar(partial,6.8u#+2appr#,asc_height#,0);
  "Partial derivative";
  italcorr x_height#*slant-0.5u#-0.8u#;
  localtransform = identity slanted slant
  yscaled aspect_ratio scaled granularity
  shifted (-hround 0.8u,0);
  pickup fine.nib; pos2(stem,90); pos5(curve,180);
  lft x1-hround 0.35u=lft x5r+eps=appr;
  rt x3=w-appr+eps; x2=0.4[x1,x3]; x4=0.5[x5r,x3];
  x6=0.5[x5,x3];
  top y2r=asc_height+o; bot y4=-o;
  top y6=max(x_height,0.5asc_height)+oo;
  y3=0.5[y4,y2r]; y5=0.5[y4,y6]; y1=good.y 0.84[y4,y2r];
  filldraw stroke z1 up_to_right z2e right_to_down z3;
  filldraw stroke z4 left_to_up z5e up_to_right z6;
  draw z3 down_to_left z4; draw z6{right}...z3;
  penlabels(1,2,3,4,5,6);
endchar;

beginchar(partial_slash,6.8u#+2appr#,asc_height#,asc_depth#);
  "Slashed partial derivative";
  italcorr x_height#*slant-0.5u#-0.8u#;
  localtransform=identity slanted slant
  yscaled aspect_ratio scaled granularity
  shifted (-hround 0.8u,0);
  pickup fine.nib; pos2(stem,90); pos5(curve,180);
  lft x1-hround 0.35u=lft x5r+eps=appr;
  rt x3=w-appr+eps; x2=0.4[x1,x3]; x4=0.5[x5r,x3];
  x6=0.5[x5,x3];
  top y2r=asc_height+o; bot y4=-o;
  top y6=max(x_height,0.5asc_height)+oo;
  y3=0.5[y4,y2r]; y5=0.5[y4,y6]; y1=good.y 0.84[y4,y2r];
  filldraw stroke z1 up_to_right z2e right_to_down z3;
  filldraw stroke z4 left_to_up z5e up_to_right z6;
  draw z3 down_to_left z4; draw z6{right}...z3;
  %
  bot y8=-d; y7-asc_height=-y8;
  z7=whatever[z4,z6]; z8=whatever[z4,z6];
  numeric a;
  a=diag_width(max((rth0-fine),0),(z7-z8) slanted slant);
  penpos7(a,0); penpos8(a,0); filldraw stroke z7e..z8e;
  penlabels(1,2,3,4,5,6,7,8);
endchar;

%
% daggers and asterisks
%

numeric dag_stem,dag_Stem;
dag_stem=hround 0.3[curve,cap_curve];
dag_Stem=hround 0.6[curve,cap_curve];

beginchar(dagger,6u#+2appr#,asc_height#,asc_depth#);
  "Dagger mark";
%  italcorr (0.75asc_height#-0.25asc_depth#)*slant-0.5u#;
  interim stress:=0.5;
  pickup fine.nib;
  x1=hround(0.5w-0.5dag_stem)+0.5dag_stem;
  y1=vround(0.25[h,-d]-0.5curve)+0.5curve;
  y4=good.y 0.4[h,-d]; z1=z2=z3;
  filldraw dagger_stroke1(h+oo-y1,dag_stem,hair,up)--cycle;
  x1=x4=x4a=x4b=x5; bot y5=-d-o;
  y4a=stress[y1,y4]; y4b=stress[y5,y4];
  pos4(dag_Stem,0); pos5(hair,0);
  filldraw stroke z1e{down}...{z4e-z4a}z4e{z4b-z4e}...z5e{down};
  interim stress:=0.4;
  filldraw dagger_stroke2(x1-appr+eps,curve,vair,left)--cycle;
  filldraw dagger_stroke3(x1-appr+eps,curve,vair,right)--cycle;
  labels(4,4a,4b,4r,4l,5,5r,5l);
endchar;

beginchar(double_dagger,6u#+2appr#,asc_height#,asc_depth#);
  "Double dagger mark";
%  italcorr (0.75asc_height#-0.25asc_depth#)*slant-0.5u#;
  interim stress:=0.5; pickup fine.nib;
  x1=hround(0.5w-0.5dag_stem)+0.5dag_stem;
  y1=vround(0.25[h,-d]-0.5curve)+0.5curve;
  x1=x2=x3=x4=x5=x6=x7=x8=x9=x10; y1=y2=y3; h-y1-d=y4=y5=y6;
  filldraw dagger_stroke1(h+oo-y1,dag_stem,hair,up)--cycle;
  filldraw dagger_stroke4(h+oo-y1,dag_stem,hair,down)--cycle;
  y7=good.y 0.35[h,-d]; z10l=z4r; z10r=z4l; y1-y7=y9-y4;
  y8=0.5[y7,y9]; pos7(dag_Stem,0);
  pos8(hair,0); pos9(dag_Stem,0);
  z7a=stress[z1,z7]; z7b=stress[z8,z7];
  z9a=stress[z4,z9]; z9b=stress[z8,z9];
  filldraw stroke z1e{down}...{z7e-z7a}z7e{z7b-z7e}...z8e{down}
  ...{z9e-z9b}z9e{z9a-z9e}...z10e{down};
  interim stress:=0.4;
  filldraw dagger_stroke2(x1-appr,curve,vair,left)--cycle;
  filldraw dagger_stroke3(x1-appr+eps,curve,vair,right)--cycle;
  filldraw dagger_stroke5(x1-appr+eps,curve,vair,left)--cycle;
  filldraw dagger_stroke6(x1-appr+eps,curve,vair,right)--cycle;
  labels(7a,7b,9a,9b); penlabels(7,8,9,10);
endchar;

if (known upper_asterisk)
  or (known lower_asterisk)
  or (known triple_asterisk):
  beginpicture(tmp,ast_size#+2appr#,ast_size#,0);
  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;
  endpicture;
fi

beginchar(upper_asterisk,ast_size#+2appr#,body_height#,0);
  "Upper asterisk";
%  italcorr body_height#*slant-0.5u#;
  currentpicture:=tmp_picture shifted(0,h-ast_size);
endchar;

beginchar(lower_asterisk,ast_size#+2appr#,
    ast_size#-body_depth#,body_depth#);
  "Lower asterisk";
%  italcorr charht*slant-0.5u;
  currentpicture:=tmp_picture shifted(0,-body_depth);
endchar;

beginchar(triple_asterisk,20u#+2appr#,body_height#,body_depth#);
  "Triple asterisks";
%  italcorr charht*slant-0.5u;
  currentpicture:=
  tmp_picture shifted(hround 6.5u,h-ast_size)+
  tmp_picture shifted(2hround 6.5u-hround 13u,-d)+
  tmp_picture shifted(hround 13u,-d);
endchar;

%
% Musical signs (supposed to be identical to cm's ones...)
%

beginchar(musical_flat_sign,5u#+2appr#,body_height#,0);
  "Musical flat sign";
  pickup crisp.nib;
  pos1(hair,0); pos2(hair,180); pos3(hair,0); x1=x2=x3;
  pos4(.25[hair,curve],60); pos5(curve,0);
  lft x1l=appr; x4=0.5w; rt x5r=w-appr;
  top y1=h; bot y3=-o; top y4=x_height+o;
  y2=y4-.2x_height; y5=3/4x_height;
  filldraw stroke z1e--z3e;  % stem
  filldraw stroke z2e{up}...z4e{right}...z5e{down}
  ...{2(x3-x5e),y3-y5e}z3e;  % bowl
  penlabels(1,2,3,4,5);
endchar;

beginchar(musical_natural_sign,5u#+2appr#,asc_height#,desc_depth#);
  "Musical natural sign";
  pickup crisp.nib;
  pos1(hair,0); pos2(curve,90); pos3(curve,90);
  pos4(curve,90); pos5(curve,90); pos6(hair,0);
  rt x1r=hround 7/8u+appr; x2=x4=x1l; x3=x5=x6r=w-x2;
  y1=h+o; top y2r=0; .5[y2,y3]=0; y4-y2=y5-y3=x_height; bot y6=-d-o;
  x2'=x1r; z2'=whatever[z2r,z3r]; x5'=x6l; z5'=whatever[z4l,z5l];
  (x1r,y)=z1l+whatever*(z5-z4); y6l:=y6l-(y-y1r); y1r:=y;
  filldraw z1l--z2l--z3l--z3r--z2'--z1r--cycle;  % left stem and lower bar
  filldraw z6r--z5r--z4r--z4l--z5'--z6l--cycle;  % right stem and upper bar
  penlabels(1,2,3,4,5,6);
endchar;

beginchar(musical_sharp_sign,5u#+2appr#,asc_height#,desc_depth#);
  "Musical sharp sign";
  pickup crisp.nib;
  pos1(curve,90); pos2(curve,90); pos3(curve,90); pos4(curve,90);
  lft x1=lft x3=appr; rt x2=rt x4=w-appr;
  top y3r=0; .5[y3,y4]=0; y1-y3=y2-y4=x_height;
  filldraw stroke z1e--z2e; filldraw stroke z3e--z4e;  % bars
  numeric theta,hstem; theta=angle(z2-z1);
  (hstem-crisp)*cosd theta=hair-crisp;
  pos5(hstem,theta); pos6(hstem,theta);
  pos7(hstem,theta); pos8(hstem,theta);
  lft x5l=lft x6l=hround(2u-.5hair); x7=x8=w-x6;
  top y7l=h+o; bot y6r=-d-o; z7-z5=z8-z6=(whatever,0) rotated theta;
  filldraw stroke z5e--z6e; filldraw stroke z7e--z8e;  % stems
  penlabels(1,2,3,4,5,6,7,8);
endchar;

beginchar(degree_sign,
    5u#+2appr#,0.8asc_height#,0);
  "Degree sign";
  b:=round min(6.5u,8/12h);
  pickup rule.nib0;
  adjust_dot1((0.5w,6.5/12h),b,true,true);
  full_dot:=false; dot(1,1');
endchar;

beginchar(prime_sign,
    u#+max(1.75u#,curve#+2(curve#-stem#))+2appr#,
    0.8asc_height#,0);
  "Prime sign";
  pickup fine.nib;
  a:=hround(bold+2dw); b:=hround 0.5[vair,stem];
  y1+0.5a=h; x1+0.5a=w-appr+hround 0.75u;
  y3=1/12asc_height; x3-0.5b=appr-hround 0.5u;
  save r,R,u_; pair u_; u_=unitvector(z1-z3);
  R=0.5(a-fine); x=R/(length(z1-z3)++0.5(b-fine));
  z1-z2=R*x*u_; z0-z1=R*u_; c:=angle(z1-z3)-90;
  penpos1(2R,c); penpos2(2R*(1+-+x),c); pos3(b,c);
  filldraw z3r---z2r...z1r{u_}...
  (superness[z1,z1.r]+superness[z1,z0]-z1){z0-z1.r}
  ...z0{z1.l-z1.r}...
  (superness[z1,z1.l]+superness[z1,z0]-z1){z1.l-z0}
  ...z1.l{-u_}...z2l---z3l--cycle;
  penlabels(0,1,2,3);
  tmp_picture:=currentpicture;
endchar;

beginchar(second_sign,
    u#+2.25u#+2letter_fit#+2max(1.75u#,curve#+2(curve#-stem#))+2appr#,
    0.8asc_height#,0);
  "Second sign";
  a:=hround(bold+2dw+2.25u+2letter_fit);
  currentpicture:=tmp_picture+(tmp_picture shifted (a,0));
endchar;

beginchar(third_sign,
    u#+2*2.00u#+4letter_fit#+3max(1.75u#,curve#+2(curve#-stem#))+2appr#,
    0.8asc_height#,0);
  "Third sign"; 
  a:=hround(bold+2dw+2.00u+2letter_fit);
  currentpicture:=tmp_picture+(tmp_picture shifted (a,0))
  +(tmp_picture shifted (2a,0));
endchar;

beginchar(fourth_sign,
    u#+3*1.75u#+6letter_fit#+4max(1.75u#,curve#+2(curve#-stem#))+2appr#,
    0.8asc_height#,0);
  "Fourth sign";
  a:=hround(bold+2dw+1.75u+2letter_fit);
  currentpicture:=tmp_picture+(tmp_picture shifted (a,0))
  +(tmp_picture shifted (2a,0))+(tmp_picture shifted (3a,0));
endchar;

beginchar(backprime_sign,
    u#+max(1.75u#,curve#+2(curve#-stem#))+2appr#,0.8asc_height#,0);
  "Backrime sign";
  pickup fine.nib;
  a:=hround(bold+2dw); b:=hround 0.5[vair,stem];
  y1+0.5a=h; x1-0.5a=appr-hround 0.75u;
  y3=1/12asc_height; x3+0.5b=w-appr+hround 0.5u;
  save r,R,u_; pair u_; u_=unitvector(z1-z3);
  R=0.5(a-fine); x=R/(length(z1-z3)++0.5(b-fine));
  z1-z2=R*x*u_; z0-z1=R*u_; c:=angle(z1-z3)-90;
  penpos1(2R,c); penpos2(2R*(1+-+x),c); pos3(b,c);
  filldraw z3r---z2r...z1r{u_}...
  (superness[z1,z1.r]+superness[z1,z0]-z1){z0-z1.r}
  ...z0{z1.l-z1.r}...
  (superness[z1,z1.l]+superness[z1,z0]-z1){z1.l-z0}
  ...z1.l{-u_}...z2l---z3l--cycle;
  penlabels(0,1,2,3);
endchar;

beginchar(accent_circ,
    5u#+2appr#,asc_height#,0);
  "Circ accent";
  b:=max(h+2o-1/3[x_height,h],4u);
  pickup pencircle scaled hair;
  adjust_dot1((0.5w,max(1/3[x_height,h]+0.5b-o,x_height+2o)),b,false,false);
  full_dot:=false; dot(1,1');
endchar;

beginchar(accent_dot,
    3u#+2appr#,
    min(7/10[x_height#,asc_height]+0.5max(dtsz#,cap_curve#),asc_height#),0);
  "Dot accent";
  b:=max(dtsz,cap_curve); ensure_centering_of(b);
  pickup null.nib;
  adjust_dot1((0.5w,h+1-0.5b),b,false,false); dot(1,1');
endchar;

beginchar(accent_ddot,7u#+2appr#,
    min(7/10[x_height#,asc_height]+0.5max(dtsz#,cap_curve#),asc_height#),0);
  "Ddot accent";
  b:=max(dtsz,cap_curve);% ensure_centering_of(b);
  pickup null.nib;
  adjust_dot1((0.5w-1.75u,h+1-0.5b),b,false,false); dot(1,1');
  adjust_dot2((0.5w+1.75u,h+1-0.5b),b,false,false); dot(2,2');
endchar;

beginchar(accent_dddot,8u#+2appr#,
    min(7/10[x_height#,asc_height]+0.5max(dtsz#,cap_curve#),asc_height#),0);
  "Dddot accent";
  a:=hround 3.25u; b:=max(dtsz,cap_curve); ensure_centering_of(b);
  pickup null.nib;
  adjust_dot1((0.5w-a,h+1-0.5b),b,false,false); dot(1,1');
  adjust_dot2((0.5w,h+1-0.5b),b,false,false); dot(2,2');
  adjust_dot3((0.5w+a,h+1-0.5b),b,false,false); dot(3,3');
endchar;

beginchar(accent_ddddot,9u#+2appr#,
    min(7/10[x_height#,asc_height]+0.5max(dtsz#,cap_curve#),asc_height#),0);
  "Ddddot accent";
  a:=hround 3u; b:=max(dtsz,cap_curve);% ensure_centering_of(b);
  pickup null.nib;
  adjust_dot1((0.5w-1.5a,h+1-0.5b),b,false,false); dot(1,1');
  adjust_dot2((0.5w-0.5a,h+1-0.5b),b,false,false); dot(2,2');
  adjust_dot3((0.5w+0.5a,h+1-0.5b),b,false,false); dot(3,3');
  adjust_dot4((0.5w+1.5a,h+1-0.5b),b,false,false); dot(4,4');
endchar;

