%
% Copyright (c) 2011, 2012, Sebastian Schubert <schubert.seb@googlemail.com>
%
% This Font Software is licensed under the SIL Open Font License,
% Version 1.1. This license is in the accompanying file OFL.txt, and
% is also available with a FAQ at: http://scripts.sil.org/OFL
%

vardef ifneg(text values) =
  select(negated)(values)
enddef;

% equal signs

if negated < 2:
  beginorder(1, order_width#, ifneg(1,3) * equal_spread#); "equal";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);

    if negated = 1:
      stroke_through(centre, 3equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(4/2,7/2) * equal_spread#); "equiv";
    s := equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex, right_ex, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1/2,5/2) * equal_spread#); "sim";
      draw_sim(a, left_ex, right_ex, 1/4equal_spread, line_thickness);

      if negated = 1:
        stroke_through(centre, 5/2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(3/2,6/2) * equal_spread#); "approx";
    s := 1/2equal_spread;

    draw_sim(a, left_ex + s * up, right_ex + s * up, 1/4equal_spread, line_thickness);
    draw_sim(b, left_ex - s * up, right_ex - s * up, 1/4equal_spread,                                             line_thickness);

    if negated = 1:
      stroke_through(centre, 3equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(5/2,7/2) * equal_spread#); "triple sim";
    s := equal_spread;

    draw_sim(a, left_ex + s * up, right_ex + s * up, 1/4equal_spread, line_thickness);
    draw_sim(b, left_ex, right_ex, 1/4equal_spread, line_thickness);
    draw_sim(c, left_ex - s * up, right_ex - s * up, 1/4equal_spread, line_thickness);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(3/2,6/2) * equal_spread#); "sim equal";
      s := 1/2equal_spread;

      draw_sim(a, left_ex + s * up, right_ex + s * up, 1/4equal_spread, line_thickness);
      draw_line(left_ex - s * up, right_ex - s * up, false);

      if negated = 1:
        stroke_through(centre, 3equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(3/2,6/2) * equal_spread#); "equal sim";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_sim(a, left_ex - s * up, right_ex - s * up, 1/4equal_spread, line_thickness);

    if negated = 1:
      stroke_through(centre, 3equal_spread);
    fi;
  endchar;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(5/2,7/2,6/2) * equal_spread#); "cong";
      s := equal_spread;

      draw_sim(a, left_ex + s * up, right_ex + s * up, 1/4equal_spread, line_thickness);
      draw_line(left_ex, right_ex, false);
      draw_line(left_ex - s * up, right_ex - s * up, false);

      if negated = 1:
        stroke_through(centre, 7/2equal_spread);
      elseif negated = 2:
        if sign = 1:
          stroke_through(centre - 5/8s * up, 7/4equal_spread);
        else:
          stroke_through(centre - 1/2s * up, 2equal_spread);
        fi;
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(5/2,7/2) * equal_spread#); "approx equal";
    s := equal_spread;

    draw_sim(a, left_ex + s * up, right_ex + s * up, 1/4equal_spread, line_thickness);
    draw_sim(b, left_ex, right_ex, 1/4equal_spread, line_thickness);
    draw_line(left_ex - s * up, right_ex - s * up, false);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(1,3) * equal_spread# + ifneg(1,0) * 2/5order_width#); "bump equal";
    s := 1/2equal_spread;

    draw_bump(a, 1, left_ex + s * up, right_ex + s * up, order_width/5, line_thickness);
    draw_line(left_ex - s * up, right_ex - s * up, false);

    if negated = 1:
      stroke_through(centre, 3equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(4/2,7/2) * equal_spread# + ifneg(1,0) * 2/5order_width#); "bump over equal";
    s := equal_spread;

    draw_bump(a, 1, left_ex + s * up, right_ex + s * up, order_width/5, line_thickness);
    draw_line(left_ex, right_ex, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(2/2,7/2) * equal_spread# + ifneg(1,0) * 2/5order_width#); "double bump equal";
    s := 1/2equal_spread;

    draw_bump(a, 1, left_ex + s * up, right_ex + s * up, order_width/5, line_thickness);
    draw_bump(b, -1, left_ex - s * up, right_ex - s * up, order_width/5, line_thickness);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(6/2,7/2) * equal_spread# + ifneg(1,0) * 3/4dot_size#); "dot equal";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);
    fill dot(centre + 3s * up, 3/4dot_size);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(6/2,7/2) * equal_spread# + ifneg(1,0) * 3/4dot_size#); "equal dot";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);
    fill dot(centre - 3s * up, 3/4dot_size);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(6/2,7/2) * equal_spread# + ifneg(1,0) * 3/4dot_size#); "dot equal dot";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);
    fill dot(centre + 3s * up, 3/4dot_size);
    fill dot(centre - 3s * up, 3/4dot_size);

    if negated = 1:
      stroke_through(centre, 7/2equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(6/2,7/2) * equal_spread# + ifneg(1,0) * 3/4dot_size#); "falling dot equal";
      s := 1/2equal_spread;

      draw_line(left_ex + s * up, right_ex + s * up, false);
      draw_line(left_ex - s * up, right_ex - s * up, false);
      fill dot(left_ex + sign * 3/4dot_size * right + 3s * up, 3/4dot_size);
      fill dot(right_ex - sign * 3/4dot_size * right - 3s * up, 3/4dot_size);

      if negated = 1:
        stroke_through(centre, 7/2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 1:
  for sign = 1, -1:
    beginorder(sign, 4/3order_width# + 3/4dot_size#, equal_spread# + dot_size#); "colon equal";
      s := 1/2equal_spread;
      pair left_sep;
      left_sep := left_ex + sign * (3/4dot_size + 1/3order_width) * right;

      fill dot(left_ex + s * up + sign * 3/4dot_size * right, 3/4dot_size);
      fill dot(left_ex - s * up + sign * 3/4dot_size * right, 3/4dot_size);
      draw_line(left_sep + s * up, right_ex + s * up, false);
      draw_line(left_sep - s * up, right_ex - s * up, false);
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(1, order_width#, ifneg(1/2,5/2) * equal_spread#); "smile";
      draw_smile(a, sign, left_ex, right_ex, 1/2equal_spread, line_thickness, true);

      if negated = 1:
        stroke_through(centre, 5/2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(1, order_width#, ifneg(11/6,7/2) * equal_spread#); "smile frown";
      s := 2/3equal_spread;

      draw_smile(a, sign, left_ex + s * up, right_ex + s * up, 1/2equal_spread, line_thickness, true);
      draw_smile(b, -sign, left_ex - s * up, right_ex - s * up, 1/2equal_spread, line_thickness, true);

      if negated = 1:
        stroke_through(centre, 7/2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(1, order_width#, ifneg(5/2,7/2) * equal_spread#); "smile over equal";
      s := 1equal_spread;

      draw_smile(a, sign, left_ex + s * up, right_ex + s * up, 1/2equal_spread, line_thickness, true);
      draw_line(left_ex, right_ex, false);
      draw_line(left_ex - s * up, right_ex - s * up, false);

      if negated = 1:
        stroke_through(centre, 7/2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(1,3) * equal_spread#); "equal circ";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);
    draw_circle(centre, 5/6s, 3/4line_thickness);

    if negated = 1:
      stroke_through(centre, 3equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, ifneg(9/2,10/2) * equal_spread#); "circ equal";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);
    draw_circle(centre + 7/2s * up, 5/6s, 3/4line_thickness);

    if negated = 1:
      stroke_through(centre + s * up, 4equal_spread);
    fi;
  endchar;
fi;

for sign = 1, -1:
  if negated < 2:
    beginorder(1, order_width#, 5equal_spread#); "wedge equal";
      s := 1/2equal_spread;

      draw_line(left_ex + s * up, right_ex + s * up, false);
      draw_line(left_ex - s * up, right_ex - s * up, false);

      draw_less(a, centre + (7/2 + sign * 3/2) * s * up, centre + (7/2 - sign * 3/2) * s * up, 4s, line_thickness, false, true);
  
      if negated = 1:
        stroke_through(centre + s * up, 4equal_spread);
      fi;
    endchar;
  fi;
endfor;

if negated < 2:
  beginorder(1, order_width#, 5equal_spread#); "star equal";
    s := 1/2equal_spread;
    r := 5/4s + 3/4line_thickness;
    t := 1/11r;

    reg_poly_points(a)(5, centre + 7/2s * up, r, 90);
    reg_poly_points(b)(5, centre + 7/2s * up, .4r, 126);

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);
    %draw_triangle(a, centre + 7/2s * up, 3/2s, 90, 3/4line_thickness);
    
    fill z.a0 -- z.b0 -- z.a1 -- z.b1 -- z.a2 -- z.b2 -- z.a3 -- z.b3 -- z.a4 -- z.b4 -- cycle;

    if negated = 1:
      stroke_through(centre + s * up, 4equal_spread);
    fi;
  endchar;
fi;

if negated < 2:
  beginorder(1, order_width#, 5equal_spread#); "triangle equal";
    s := 1/2equal_spread;

    draw_line(left_ex + s * up, right_ex + s * up, false);
    draw_line(left_ex - s * up, right_ex - s * up, false);
    draw_triangle(a, centre + 7/2s * up, 3/2s, 90, 3/4line_thickness);

    if negated = 1:
      stroke_through(centre + s * up, 4equal_spread);
    fi;
  endchar;
fi;

% element signs

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,3/2) * equal_spread# + greater_spread#); "element";
      draw_subset(a, left_ex, right_ex, greater_spread, line_thickness);
      draw_line(z4a, 1/2[z0a,z1a], false);

      if negated = 1:
        stroke_through(centre, 3/2equal_spread + greater_spread);
      fi;
    endchar;
  endfor;
fi;

% orderings

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,1) * equal_spread# + greater_spread#); "less than";
      draw_less(a, left_ex, right_ex, greater_spread, line_thickness, false, true);

      if negated = 1:
        stroke_through(centre, equal_spread + greater_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2/3,6/3,5/3) * equal_spread# + 3/4greater_spread#); "less than or equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (2/3equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 1/3equal_spread * up;

      draw_less(a, z0, z1, s, line_thickness, false, true);
      draw_line(z2, z3, false);

      if negated = 1:
        stroke_through(centre, 6/3equal_spread + 3/4greater_spread);
      elseif negated = 2:
        stroke_through(1/2[z2,z3], equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,2) * equal_spread# + 3/4greater_spread#); "less than or slanted equal";
      s := 3/4greater_spread;
      t := 1/2equal_spread;

      draw_less(a, left_ex + t * up, right_ex + t * up, s, line_thickness, false, true);

      if sign = 1:
        z6 = z4a.l + 1/2line_thickness*up - 2t * up;
        z7 = z1a                          - 2t * up;
        draw_line_cut(6,7);
      else:
        z6 = z3a.l + 1/2line_thickness*up - 2t * up;
        z7 = z0a                          - 2t * up;
        draw_line_cut(6,7);
      fi;

      if negated = 1:
        stroke_through(centre, 2equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(5/3,8/3,8/3) * equal_spread# + 3/4greater_spread#); "less than or double equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (2/3equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 5/6equal_spread * up;
      z2 - z4 = z3 - z5 = equal_spread * up;

      draw_less(a, z0, z1, s, line_thickness, false, true);
      draw_line(z2, z3, false);
      draw_line(z4, z5, false);

      if negated = 1:
        stroke_through(centre, 8/3equal_spread + 3/4greater_spread);
      elseif negated = 2:
        stroke_through(1/2[1/2[z2,z3], 1/2[z4,z5]], 2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2/2,4/2,3/2) * equal_spread# + 3/4greater_spread#); "less sim";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (3/4equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 1/2equal_spread * up;

      draw_less(a, z0, z1, s, line_thickness, false, true);
      if sign > 0:
        draw_sim(b, z2, z3, 1/4equal_spread, line_thickness);
      else:
        draw_sim(b, z3, z2, 1/4equal_spread, line_thickness);
      fi

      if negated = 1:
        stroke_through(centre, 2equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[z2,z3], equal_spread);
      fi;
    endchar;
  endfor;
fi

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(4/2,5/2,5/2) * equal_spread# + 3/4greater_spread#); "less approx";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (3/4equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = equal_spread * up;
      z2 - z4 = z3 - z5 = equal_spread * up;

      draw_less(a, z0, z1, s, line_thickness, false, true);

      if sign > 0:
        draw_sim(b, z2, z3, 1/4equal_spread, line_thickness);
        draw_sim(c, z4, z5, 1/4equal_spread, line_thickness);
      else:
        draw_sim(b, z3, z2, 1/4equal_spread, line_thickness);
        draw_sim(c, z5, z4, 1/4equal_spread, line_thickness);
      fi

      if negated = 1:
        stroke_through(centre, 5/2equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[1/2[z2,z3], 1/2[z4,z5]], 2equal_spread);
      fi;
    endchar;
  endfor;
fi

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,if sign > 0: 2 else: 3/2 fi) * equal_spread# + 9/8greater_spread#); "less greater";
      s := 3/4greater_spread;
      t := 1/2equal_spread + 1/4s;

      draw_less(a, left_ex + t * up, right_ex + t * up, s, line_thickness, false, true);
      draw_less(b, right_ex - t * up, left_ex - t * up, s, line_thickness, false, true);

      if negated = 1:
        stroke_through(centre, if sign > 0: 2 else: 3/2 fi * equal_spread + 3/2s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(4/3,11/6 + 1/2sign) * equal_spread# + 3/2greater_spread#); "less equal greater";
      s := 3/4greater_spread;
      t := 2/3equal_spread + 1/2s;

      draw_less(a, left_ex + t * up, right_ex + t * up, s, line_thickness, false, true);
      draw_less(b, right_ex - t * up, left_ex - t * up, s, line_thickness, false, true);
      draw_line(left_ex, right_ex, false);
      
      if negated = 1:
        stroke_through(centre, (11/6 + 1/2sign) * equal_spread + 2s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(7/3,17/6 + 1/2sign, 7/3) * equal_spread# + 3/2greater_spread#); "less double equal greater";
      s := 3/4greater_spread;
      t := 7/6equal_spread + 1/2s;
      u := 1/2equal_spread;

      draw_less(a, left_ex + t * up, right_ex + t * up, s, line_thickness, false, true);
      draw_less(b, right_ex - t * up, left_ex - t * up, s, line_thickness, false, true);
      draw_line(left_ex + u * up, right_ex + u * up, false);
      draw_line(left_ex - u * up, right_ex - u * up, false);

      if negated = 1:
        stroke_through(centre, (17/6 + 1/2sign) * equal_spread + 2s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2,5/2 + 1/2sign) * equal_spread# + 9/8greater_spread#); "less slanted equal greater";
      s := 3/4greater_spread;
      t := equal_spread + 1/4s;

      draw_less(a, left_ex + t * up, right_ex + t * up, s, line_thickness, false, true);
      draw_less(b, right_ex - t * up, left_ex - t * up, s, line_thickness, false, true);

      if sign = 1:
        z6 = z4a.l + 1/2line_thickness*up - equal_spread * up;
        z7 = z1a                          - equal_spread * up;
        draw_line_cut(6,7);
      else:
        z6 = z3a.l + 1/2line_thickness*up - equal_spread * up;
        z7 = z0a                          - equal_spread * up;
        draw_line_cut(6,7);
      fi;
      
      if negated = 1:
        stroke_through(centre, (5/2 + 1/2sign) * equal_spread + 3/2s);
      fi;
    endchar;
  endfor;
fi;


if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width# + 2equal_spread# + line_thickness#, ifneg(0,1) * equal_spread# + greater_spread#); "less less";
      s := 2equal_spread;

      draw_less(a, left_ex, right_ex - sign * s * right, greater_spread, line_thickness, false, true);
      draw_less(b, left_ex + sign * s * right, right_ex, greater_spread, line_thickness, false, true);

      if negated = 1:
        stroke_through(centre, equal_spread + greater_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width# + 4equal_spread# + line_thickness#, ifneg(0,1) * equal_spread# + greater_spread#); "less less less";
      s := 2equal_spread;

      draw_less(a, left_ex, right_ex - sign * 2s * right, greater_spread, line_thickness, false, true);
      draw_less(b, left_ex + sign * s * right, right_ex - sign * s * right, greater_spread, line_thickness, false, true);
      draw_less(c, left_ex + sign * 2s * right, right_ex, greater_spread, line_thickness, false, true);

      if negated = 1:
        stroke_through_angle(centre, equal_spread + greater_spread, 50);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,1) * equal_spread# + greater_spread#); "closed less than";
      draw_less(a, left_ex, right_ex, greater_spread, line_thickness, true, true);

      if negated = 1:
        stroke_through(centre, equal_spread + greater_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2/3,6/3) * equal_spread# + 3/4greater_spread#); "closed less than or equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (2/3equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 1/3equal_spread * up;

      draw_less(a, z0, z1, s, line_thickness, true, true);
      draw_line(z2, z3, false);

      if negated = 1:
        stroke_through(centre, 6/3equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width# * sqrt(5/4), ifneg(0,1) * equal_spread# + greater_spread#); "round less than";
      path p;
      numeric r,s;
      thick := line_thickness;

      z0 = left_ex;
      z1 = z0 + order_width * dir angle(right_ex - left_ex);

      put_less(a, z0, z1, greater_spread, thick, false, false);

      z9 = whatever[z3a.l, z0a.l] = whatever[z4a.l,z1a.l];

      penpos1'(thick, 90 - sign*90);
    
      z1'r = z9 + sign*length(z0a.l - z9)*right;
      z4r  = z0a.l - line_thickness*(dir(angle(z0a.l-z9)));
      z5r  = z1a.l - line_thickness*(dir(angle(z1a.l-z9)));

      theta := angle(z0a.l - z9);
    
      p = (z4r{dir(theta -90)} .. z1'l .. {dir(-theta -90)}z5r);
      r = ypart ((z5a -- z0a.r) intersectiontimes p);
      s = ypart ((z5a -- z1a.r) intersectiontimes p);
    
      fill   z0a.l{dir(theta -90)} .. z1'.r .. {dir(-theta -90)}z1a.l -- z4a.l -- z3a.l -- cycle;
      unfill subpath (r,s) of p  -- z5a   -- cycle;
    
      if negated = 1:
        stroke_through(centre, equal_spread + greater_spread);
      fi;

      penlabels(1',4,5,9);
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width# * sqrt(7/6), ifneg(1,2) * equal_spread# + 3/4greater_spread#); "round less than or slanted equal";
      path p;
      numeric u,v;

      thick := line_thickness;
      s := 3/4greater_spread;
      t := 1/2equal_spread;

      z0 = left_ex + t * up;
      z1 = z0 + order_width * dir angle(right_ex - left_ex);

      put_less(a, z0, z1, s, thick, false, false);

      penpos1'(thick, 90 - sign*90);
    
      z9 = whatever[z3a.l, z0a.l] = whatever[z4a.l,z1a.l];

      z1'r = z9 + sign*length(z0a.l - z9)*right;
      z4r  = z0a.l - line_thickness*(dir(angle(z0a.l-z9)));
      z5r  = z1a.l - line_thickness*(dir(angle(z1a.l-z9)));

      theta := angle(z0a.l - z9);
    
      p = (z4r{dir(theta -90)} .. z1'l .. {dir(-theta -90)}z5r);
      u = ypart ((z5a -- z0a.r) intersectiontimes p);
      v = ypart ((z5a -- z1a.r) intersectiontimes p);

      fill   z0a.l{dir(theta -90)} .. z1'.r .. {dir(-theta -90)}z1a.l -- z4a.l -- z3a.l -- cycle;
      unfill subpath (u,v) of p  -- z5a   -- cycle;

      if sign = 1:
        draw_line(z1a - 2t * up, z4a - 2t * up, false);
      else:
        draw_line(z0a - 2t * up, z3a - 2t * up, false);
      fi;

      if negated = 1:
        stroke_through(centre, 2equal_spread + 3/4greater_spread);
      fi;
      
      penlabels(1',4,5,9);
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,3/2) * equal_spread# + greater_spread#); "square subset";
      s := greater_spread;

      draw_line(left_ex + s/2 * up, right_ex + s/2 * up, false);
      draw_line(left_ex - s/2 * up, right_ex - s/2 * up, false);
      draw_line(left_point + s/2 * up, left_point - s/2 * up, false);

      if negated = 1:
        stroke_through(centre, 3/2equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,5/2,2) * equal_spread# + 3/4greater_spread#); "square subset equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (equal_spread + s/2) * up;
      z0 - left_ex = z0' - left_point = z1 - right_ex = 1/2equal_spread * up;

      draw_line(z0 + s/2 * up, z1 + s/2 * up, false);
      draw_line(z0 - s/2 * up, z1 - s/2 * up, false);
      draw_line(z0' + s/2 * up, z0' - s/2 * up, false);
      draw_line(z2, z3, false);

      if negated = 1:
        stroke_through(centre, 5/2equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[z2,z3] + 1/2equal_spread * up, 2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2,3,3) * equal_spread# + 3/4greater_spread#); "square subset double equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (equal_spread + s/2) * up;
      z0 - left_ex = z0' - left_point = z1 - right_ex = equal_spread * up;
      z2 - z4 = z3 - z5 = equal_spread * up;

      draw_line(z0 + s/2 * up, z1 + s/2 * up, false);
      draw_line(z0 - s/2 * up, z1 - s/2 * up, false);
      draw_line(z0' + s/2 * up, z0' - s/2 * up, false);
      draw_line(z2, z3, false);
      draw_line(z4, z5, false);

      if negated = 1:
        stroke_through(centre, 3equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[1/2[z2,z3], 1/2[z4,z5]], 2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,3/2) * equal_spread# + greater_spread#); "double square subset";
      s := greater_spread;
      t := greater_spread - 3/2equal_spread;

      z0 - left_ex = z0' - left_point = 3/4equal_spread * dir (90 - sign * 90);

      draw_line(left_ex + s/2 * up, right_ex + s/2 * up, false);
      draw_line(left_ex - s/2 * up, right_ex - s/2 * up, false);
      draw_line(left_point + s/2 * up, left_point - s/2 * up, false);

      draw_line(z0 + t/2 * up, right_ex + t/2 * up, false);
      draw_line(z0 - t/2 * up, right_ex - t/2 * up, false);
      draw_line(z0' + t/2 * up, z0' - t/2 * up, false);

      if negated = 1:
        stroke_through(centre, 3/2equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,3/2) * equal_spread# + greater_spread#); "subset";
      draw_subset(a, left_ex, right_ex, greater_spread, line_thickness);

      if negated = 1:
        stroke_through(centre, 3/2equal_spread + greater_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,5/2,2) * equal_spread# + 3/4greater_spread#); "subset or equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (equal_spread + s/2) * up;
      z0 - left_ex = z0' - left_point = z1 - right_ex = 1/2equal_spread * up;

      draw_subset(a, z0, z1, s, line_thickness);
      draw_line(z2, z3, false);

      if negated = 1:
        stroke_through(centre, 5/2equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[z2,z3] + 1/2equal_spread * up, 2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2,3,3) * equal_spread# + 3/4greater_spread#); "subset or double equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (equal_spread + s/2) * up;
      z0 - left_ex = z0' - left_point = z1 - right_ex = equal_spread * up;
      z2 - z4 = z3 - z5 = equal_spread * up;

      draw_subset(a, z0, z1, s, line_thickness);
      draw_line(z2, z3, false);
      draw_line(z4, z5, false);

      if negated = 1:
        stroke_through(centre, 3equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[1/2[z2,z3], 1/2[z4,z5]], 2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,3/2) * equal_spread# + greater_spread#); "double subset";
      s := greater_spread;
      t := greater_spread - 3/2equal_spread;

      z0 - left_ex = 3/4equal_spread * dir (90 - sign * 90);

      draw_subset(a, left_ex, right_ex, s, line_thickness);
      draw_subset(b, z0, right_ex, t, line_thickness);

      if negated = 1:
        stroke_through(centre, 3/2equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,1) * equal_spread# + greater_spread#); "curly less than";
      draw_prec(a, left_ex, right_ex, greater_spread, line_thickness, false);

      if negated = 1:
        stroke_through(centre, equal_spread + greater_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2/3,6/3,5/3) * equal_spread# + 3/4greater_spread#); "curly less than or equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (2/3equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 1/3equal_spread * up;

      draw_prec(a, z0, z1, s, line_thickness, false);
      draw_line(z2, z3, false);

      if negated = 1:
        stroke_through(centre, 6/3equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[z2,z3], equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,2) * equal_spread# + 3/4greater_spread#); "curly less than or curly equal";
      s := 3/4greater_spread;

      z0 - z2 = equal_spread * up;
      z1 - z3 = (7/5equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 1/2equal_spread * up;
      z2' - z2 = line_thickness * dir (90 - sign * 90);

      draw_prec(a, z0, z1, s, line_thickness, false);

      if sign > 0:
        theta := angle (z1a.l - z1a);
      else:
        theta := angle (z0a.r - z0a);
      fi;

      penpos2(line_thickness, 90);
      penpos2'(line_thickness, 90);
      penpos3(line_thickness, theta);
      penpos5(line_thickness, theta);

      path p, q;

      p = z2.l -- z2'.l{dir (90 - sign * 90)} .. {dir (theta - sign * 90)}z3.l;
      q = z2.r -- z2'.r{dir (90 - sign * 90)} .. {dir (theta - sign * 90)}z3.r;

      z5.r = point 1.8 of q;
      t := xpart (p intersectiontimes (z5.l -- z5.r));

      fill (subpath (0,t) of p) -- (reverse (subpath (0,1.8) of q)) -- cycle;

      penlabels(2,5);

      if negated = 1:
        stroke_through(centre, 2equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(5/3,8/3,8/3) * equal_spread# + 3/4greater_spread#); "curly less than or double equal";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (2/3equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 5/6equal_spread * up;
      z2 - z4 = z3 - z5 = equal_spread * up;

      draw_prec(a, z0, z1, s, line_thickness, false);
      draw_line(z2, z3, false);
      draw_line(z4, z5, false);

      if negated = 1:
        stroke_through(centre, 8/3equal_spread + 3/4greater_spread);
      elseif negated = 2:
        stroke_through(1/2[1/2[z2,z3], 1/2[z4,z5]], 2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,4/2,3/2) * equal_spread# + 3/4greater_spread#); "curly less sim";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (3/4equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 1/2equal_spread * up;

      draw_prec(a, z0, z1, s, line_thickness, false);
      if sign > 0:
        draw_sim(b, z2, z3, 1/4equal_spread, line_thickness);
      else:
        draw_sim(b, z3, z2, 1/4equal_spread, line_thickness);
      fi

      if negated = 1:
        stroke_through(centre, 4/2equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[z2,z3], equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 3:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2,5/2,5/2) * equal_spread# + 3/4greater_spread#); "curly less approx";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (3/4equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = equal_spread * up;
      z2 - z4 = z3 - z5 = equal_spread * up;

      draw_prec(a, z0, z1, s, line_thickness, false);

      if sign > 0:
        draw_sim(b, z2, z3, 1/4equal_spread, line_thickness);
        draw_sim(c, z4, z5, 1/4equal_spread, line_thickness);
      else:
        draw_sim(b, z3, z2, 1/4equal_spread, line_thickness);
        draw_sim(c, z5, z4, 1/4equal_spread, line_thickness);
      fi

      if negated = 1:
        stroke_through(centre, 5/2equal_spread + s);
      elseif negated = 2:
        stroke_through(1/2[1/2[z2,z3], 1/2[z4,z5]], 2equal_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(0,1) * equal_spread# + greater_spread#); "less than dot";
      draw_less(a, left_ex, right_ex, greater_spread, line_thickness, false, true);
      fill dot(right_ex - sign * 3/4dot_size * right, 3/4dot_size);

      if negated = 1:
        stroke_through(centre, equal_spread + greater_spread);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(2/3,6/3) * equal_spread# + 3/4greater_spread#); "less than or equal dot";
      s := 3/4greater_spread;

      z0 - z2 = z1 - z3 = (2/3equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = 1/3equal_spread * up;

      draw_less(a, z0, z1, s, line_thickness, false, true);
      fill dot(z1 - sign * 3/4dot_size * right, 3/4dot_size);
      draw_line(z2, z3, false);

      if negated = 1:
        stroke_through(centre, 6/3equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,2) * equal_spread# + 3/4greater_spread#); "less than or slanted equal dot";
      s := 3/4greater_spread;
      t := 1/2equal_spread;

      draw_less(a, left_ex + t * up, right_ex + t * up, s, line_thickness, false, true);
      fill dot(right_ex + t * up - sign * 3/4dot_size * right, 3/4dot_size);

      if sign = 1:
        z6 = z4a.l + 1/2line_thickness*up - 2t * up;
        z7 = z1a                          - 2t * up;
        draw_line_cut(6,7);
      else:
        z6 = z3a.l + 1/2line_thickness*up - 2t * up;
        z7 = z0a                          - 2t * up;
        draw_line_cut(6,7);
      fi;

      if negated = 1:
        stroke_through(centre, 2equal_spread + s);
      fi;
    endchar;
  endfor;
fi;

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,2) * equal_spread# + 3/4greater_spread#); "slanted equal or less than";
      s := 3/4greater_spread;
      t := 1/2equal_spread;

      draw_less(a, left_ex - t * up, right_ex - t * up, s, line_thickness, false, true);

      if sign = 1:
        z6 = z3a.l - 1/2line_thickness*up + 2t * up;
        z7 = z0a                          + 2t * up;
        draw_line_cut(6,7);
      else:
        z6 = z4a.l - 1/2line_thickness*up + 2t * up;
        z7 = z1a                          + 2t * up;
        draw_line_cut(6,7);
      fi;

      if negated = 1:
        stroke_through(centre, 2equal_spread + s);
      fi;
    endchar;
  endfor;
fi

if negated < 2:
  for sign = 1, -1:
    beginorder(sign, order_width#, ifneg(1,2) * equal_spread# + 3/4greater_spread#); "curly equal or curly less than";
      s := 3/4greater_spread;

      z0 - z2 = -equal_spread * up;
      z1 - z3 = -(7/5equal_spread + s/2) * up;
      z0 - left_ex = z1 - right_ex = -1/2equal_spread * up;
      z2' - z2 = line_thickness * dir (90 - sign * 90);

      draw_prec(a, z0, z1, s, line_thickness, false);

      if sign > 0:
        theta := angle (z1a.l - z1a);
      else:
        theta := angle (z0a.r - z0a);
      fi;

      penpos2(line_thickness, -90);
      penpos2'(line_thickness, -90);
      penpos3(line_thickness, -theta);
      penpos5(line_thickness, -theta);

      path p, q;

      p = z2.l -- z2'.l{dir (90 - sign * 90)} .. {dir (sign * 90 - theta)}z3.l;
      q = z2.r -- z2'.r{dir (90 - sign * 90)} .. {dir (sign * 90 - theta)}z3.r;

      z5.r = point 1.8 of q;
      t := xpart (p intersectiontimes (z5.l -- z5.r));

      fill (subpath (0,t) of p) -- (reverse (subpath (0,1.8) of q)) -- cycle;

      penlabels(2,5);

      if negated = 1:
        stroke_through(centre, 2equal_spread + s);
      fi;
    endchar;
  endfor;
fi
