summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/fonts/source/public/mnsymbol/Sym-Delim.mf
blob: cee9984a55289e58c18c1572dfc6dab51e3fdeb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
% brackets

def draw_bracket(expr sign, thick, draw_top, draw_mid, draw_bot, draw_double) =
  penpos0(thick, 90 - sign * 90);
  penpos1(thick, 90 - sign * 90);
  penpos2(3/2thick, 90);
  penpos3(1/2thick, 90);
  penpos4(3/2thick, 90);
  penpos5(1/2thick, 90);
  penpos6(1/2thick, 0);
  penpos7(1/2thick, 0);

  x3 - x2 = x5 - x4 = sign * (w - 2side_bearing); % - 2u + thick);

  1/2[x2,x3] = w/2 + sign * 1/2u;

  if draw_top:
    y1 = h;
  else:
    y1 = h + 1/3rule_thickness;
  fi;

  if draw_bot:
    y0 = -d;
  else:
    y0 = -d - 1/3rule_thickness;
  fi;

  x1 = x0;

  z6 = 1/3[z2l,z3l] + sign * thick * dir 0;
  z7 = 1/3[z4r,z5r] + sign * thick * dir 0;

  y2l = y3l;
  y4r = y5r;
  z2l = z0l;
  z4r = z1l;

  if draw_mid:
    fill stroke z0e -- z1e;
  else:
    if draw_bot: fill stroke z0e -- 1/4[z0e,z1e]; fi;
    if draw_top: fill stroke 3/4[z0e,z1e] -- z1e; fi;
  fi;
  if draw_top: fill stroke z4e .. {sign * dir 0}z5e; fi;
  if draw_bot: fill stroke z2e .. {sign * dir 0}z3e; fi;
  if draw_double: fill stroke z6e -- z7e; fi;
enddef;

lsquare_char = current_char + 1;
rsquare_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "square bracket";
      draw_bracket(sign, 5/4rule_thickness * sqrt (scale/2), true, true, true, false);
    endchar;
  endfor;
endfor;

lfloor_char = current_char + 1;
rfloor_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "floor";
      draw_bracket(sign, 5/4rule_thickness * sqrt (scale/2), false, true, true, false);
    endchar;
  endfor;
endfor;

lceil_char = current_char + 1;
rceil_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "ceiling";
      draw_bracket(sign, 5/4rule_thickness * sqrt (scale/2), true, true, false, false);
    endchar;
  endfor;
endfor;

ulcorner_char = current_char + 1;
urcorner_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "upper corner";
      draw_bracket(sign, 5/4rule_thickness * sqrt (scale/2), true, false, false, false);
    endchar;
  endfor;
endfor;

charlist urcorner_char: urcorner_char + 1: urcorner_char + 2: urcorner_char + 3: urcorner_char + 4;
charlist ulcorner_char: ulcorner_char + 1: ulcorner_char + 2: ulcorner_char + 3: ulcorner_char + 4;

llcorner_char = current_char + 1;
lrcorner_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "lower corner";
      draw_bracket(sign, 5/4rule_thickness * sqrt (scale/2), false, false, true, false);
    endchar;
  endfor;
endfor;

charlist lrcorner_char: lrcorner_char + 1: lrcorner_char + 2: lrcorner_char + 3: lrcorner_char + 4;
charlist llcorner_char: llcorner_char + 1: llcorner_char + 2: llcorner_char + 3: llcorner_char + 4;

ullcorner_char = current_char + 1;
ulrcorner_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "upper/lower corner";
      draw_bracket(sign, 5/4rule_thickness * sqrt (scale/2), true, false, true, false);
    endchar;
  endfor;
endfor;

charlist ulrcorner_char: ulrcorner_char + 1: ulrcorner_char + 2: ulrcorner_char + 3: ulrcorner_char + 4;
charlist ullcorner_char: ullcorner_char + 1: ullcorner_char + 2: ullcorner_char + 3: ullcorner_char + 4;

for sign = 1, -1:
  beginsymbol((6 + 6)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "square bracket -- top";
    draw_bracket(sign, 5/4rule_thickness * sqrt (6/2), true, true, false, false);
  endchar;
endfor;

for sign = 1, -1:
  beginsymbol((6 + 6)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "square bracket -- bot";
    draw_bracket(sign, 5/4rule_thickness * sqrt (6/2), false, true, true, false);
  endchar;
endfor;

for sign = 1, -1:
  beginsymbol((6 + 6)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "square bracket -- module";
    draw_bracket(sign, 5/4rule_thickness * sqrt (6/2), false, true, false, false);
  endchar;
endfor;

extensible current_char:     current_char - 4, 0, current_char - 2, current_char;     %right square bracket
extensible current_char - 1: current_char - 5, 0, current_char - 3, current_char - 1; %left square bracket
extensible current_char - 2: 0,                0, current_char - 2, current_char;     %right floor
extensible current_char - 3: 0,                0, current_char - 3, current_char - 1; %left floor
extensible current_char - 4: current_char - 4, 0, 0,                current_char;     %right ceiling
extensible current_char - 5: current_char - 5, 0, 0,                current_char - 1; %left ceiling

charlist rsquare_char: rsquare_char + 1: rsquare_char + 2: rsquare_char + 3: rsquare_char + 4: current_char;
charlist lsquare_char: lsquare_char + 1: lsquare_char + 2: lsquare_char + 3: lsquare_char + 4: current_char - 1;
charlist rfloor_char:  rfloor_char  + 1: rfloor_char  + 2: rfloor_char  + 3: rfloor_char  + 4: current_char - 2;
charlist lfloor_char:  lfloor_char  + 1: lfloor_char  + 2: lfloor_char  + 3: lfloor_char  + 4: current_char - 3;
charlist rceil_char:   rceil_char   + 1: rceil_char   + 2: rceil_char   + 3: rceil_char   + 4: current_char - 4;
charlist lceil_char:   lceil_char   + 1: lceil_char   + 2: lceil_char   + 3: lceil_char   + 4: current_char - 5;

% semantic brackets

lsem_char = current_char + 1;
rsem_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 8)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "semantic bracket";
      draw_bracket(sign, rule_thickness * sqrt (scale/2), true, true, true, true);
    endchar;
  endfor;
endfor;

for sign = 1, -1:
  beginsymbol((6 + 8)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "semantic bracket -- top";
    draw_bracket(sign, 5/4rule_thickness * sqrt (6/2), true, true, false, true);
  endchar;
endfor;

for sign = 1, -1:
  beginsymbol((6 + 8)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "semantic bracket -- bot";
    draw_bracket(sign, 5/4rule_thickness * sqrt (6/2), false, true, true, true);
  endchar;
endfor;

for sign = 1, -1:
  beginsymbol((6 + 8)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "semantic bracket -- module";
    draw_bracket(sign, 5/4rule_thickness * sqrt (6/2), false, true, false, true);
  endchar;
endfor;

extensible current_char:     current_char - 4, 0, current_char - 2, current_char;     %right semanic bracket
extensible current_char - 1: current_char - 5, 0, current_char - 3, current_char - 1; %left semanic bracket
extensible current_char - 2: 0,                0, current_char - 2, current_char;     %right semanic floor
extensible current_char - 3: 0,                0, current_char - 3, current_char - 1; %left semanic floor
extensible current_char - 4: current_char - 4, 0, 0,                current_char;     %right semanic ceiling
extensible current_char - 5: current_char - 5, 0, 0,                current_char - 1; %left semanic ceiling

charlist rsem_char: rsem_char + 1: rsem_char + 2: rsem_char + 3: rsem_char + 4: current_char;
charlist lsem_char: lsem_char + 1: lsem_char + 2: lsem_char + 3: lsem_char + 4: current_char - 1;

beginsymbol(6/2 * u# + 2side_bearing#, vcentre(1/2delim_height#)); "vertical bar -- module";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  pickup pencircle scaled 1/12thick;

  penpos2 (thick, 0);
  penpos3 (thick, 0);

  x2 = x3 = w/2;

  top y2 =  h + 1/3rule_thickness;
  bot y3 = -d - 1/3rule_thickness;

  filldraw stroke z2e -- z3e;
endchar;

extensible current_char: 0, 0, 0, current_char; % vertical bar

for scale = 2, 2.5, 3.3, 4.2, 5.1:
  beginsymbol(scale/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "vertical bar";
    thick := 5/8rule_thickness * sqrt scale;

    pickup pencircle scaled 1/12thick;

    penpos2 (thick, 0);
    penpos3 (thick, 0);

    x2 = x3 = w/2;

    top y2 =  h;
    bot y3 = -d;

    filldraw stroke z2e -- z3e;
  endchar;
endfor;

charlist current_char - 4: current_char - 3: current_char - 2: current_char - 1: current_char:
         current_char - 5;

beginsymbol((5.1 + 8)/2 * u# + 2side_bearing#, vcentre(1/2delim_height#));
  "double vertical bar -- module";

  thick := 3/8rule_thickness * sqrt 5.1;

  pickup pencircle scaled 1/12thick;

  penpos0 (thick, 0);
  penpos1 (thick, 0);
  penpos2 (thick, 0);
  penpos3 (thick, 0);

  x0 = x1;
  x2 = x3;
  1/2[x0,x2] = w/2;
  x2 - x0 = 4thick;

  top y0 = top y2 =  h + 1/3rule_thickness;
  bot y1 = bot y3 = -d - 1/3rule_thickness;

  filldraw stroke z0e -- z1e;
  filldraw stroke z2e -- z3e;
endchar;

extensible current_char: 0, 0, 0, current_char; % double vertical line

for scale = 2, 2.5, 3.3, 4.2, 5.1:
  beginsymbol((scale + 8)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "double vertical bar";
    thick := 4/8rule_thickness * sqrt scale;

    pickup pencircle scaled 1/12thick;

    penpos0 (thick, 0);
    penpos1 (thick, 0);
    penpos2 (thick, 0);
    penpos3 (thick, 0);

    x0 = x1;
    x2 = x3;
    1/2[x0,x2] = w/2;
    x2 - x0 = 4thick;

    top y0 = top y2 =  h;
    bot y1 = bot y3 = -d;

    filldraw stroke z0e -- z1e;
    filldraw stroke z2e -- z3e;
  endchar;
endfor;

charlist current_char - 4: current_char - 3: current_char - 2: current_char - 1: current_char:
         current_char - 5;

beginsymbol(5u# + 2side_bearing#, vcentre(delim_height#)); "wavy line";
  thick := rule_thickness;

  pickup pencircle scaled thick;

  x0 = x1 = x2 = x3 = w/2;
  1/2[y0,y1] = h;
  1/2[y2,y3] = -d;
  y2 - y1 = y1 - y0 = y3 - y2;

  draw (subpath (0.5,2.5) of
         (z0{dir (270-30)}
          .. {dir (270+30)}z1{dir (270+30)}
          .. {dir (270-30)}z2{dir (270-30)}
          .. {dir (270+30)}z3));
endchar;

extensible current_char: 0, 0, 0, current_char;

beginsymbol(8u# + 2side_bearing#, vcentre(delim_height#)); "double wavy line";
  thick := rule_thickness;

  pickup pencircle scaled thick;

  x0a = x1a = x2a = x3a = 1/3w;
  x0b = x1b = x2b = x3b = 2/3w;
  1/2[y0a,y1a] = 1/2[y0b,y1b] = h;
  1/2[y2a,y3a] = 1/2[y2b,y3b] = -d;

  y2a - y1a = y1a - y0a = y3a - y2a;
  y2b - y1b = y1b - y0b = y3b - y2b;

  draw (subpath (0.5,2.5) of
         (z0a{dir (270-30)}
          .. {dir (270+30)}z1a{dir (270+30)}
          .. {dir (270-30)}z2a{dir (270-30)}
          .. {dir (270+30)}z3a));
  draw (subpath (0.5,2.5) of
         (z0b{dir (270-30)}
          .. {dir (270+30)}z1b{dir (270+30)}
          .. {dir (270-30)}z2b{dir (270-30)}
          .. {dir (270+30)}z3b));
endchar;

extensible current_char: 0, 0, 0, current_char;

def draw_angle(suffix $)(expr shift, sign, thick) =
  pickup pencircle scaled (7/8thick);

  x0$ = x1$ = x2$ + sign * (w - 2side_bearing - 2abs shift - thick);

  x3$ = x2$ + sign * 3/8thick;

  top y1$ =  h;
  bot y0$ = -d;
  1/2[y0$,y1$] = y2$ = y3$;
  1/2[x0$,x2$] = w/2;

  draw (z0$ + shift * right) -- (z2$ + shift * right) -- (z1$ + shift * right) -- (z3$ + shift * right) -- cycle;
enddef;

for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "angle";
      draw_angle(a, 0, sign, 7/8rule_thickness * sqrt scale);
    endchar;
  endfor;
  charlist current_char - 4: current_char - 3: current_char - 2: current_char - 1: current_char;
endfor;

for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "angle bar";
      draw_angle(a, 0, sign, 7/8rule_thickness * sqrt scale);

      z3 = whatever[z0a,z2a];
      z4 = whatever[z1a,z2a];

      x3 = x4 = (1/(2*scale))[x0a,x2a];

      pickup pencircle scaled (11/25rule_thickness * sqrt scale);

      draw z3 -- z4;
    endchar;
  endfor;
  charlist current_char - 4: current_char - 3: current_char - 2: current_char - 1: current_char;
endfor;

for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 6)/2 * u# + 5/2rule_thickness# * sqrt scale + 2side_bearing#,
                vcentre(scale * delim_height#));
      "double angle";
      thick := 5/8rule_thickness * sqrt scale;
      draw_angle(a, -2thick, sign, thick);
      draw_angle(b,  2thick, sign, thick);
    endchar;
  endfor;
  charlist current_char - 4: current_char - 3: current_char - 2: current_char - 1: current_char;
endfor;

for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol(3scale * u# + side_bearing#, vcentre(scale * delim_height#)); "slash";
      thick := 5/4rule_thickness * sqrt (scale/2);

      pickup pencircle scaled thick;

      x1 - x0 = sign * (w - side_bearing - thick);

      top y1 =  h;
      bot y0 = -d;
      1/2[x0,x1] = w/2;

      draw z0 -- z1;
    endchar;
  endfor;
  charlist current_char - 4: current_char - 3: current_char - 2: current_char - 1: current_char;
endfor;

def draw_paren(expr sign, thick) =
  penpos0(1/2thick,  90 - sign * 40);
  penpos1(1/2thick, -90 + sign * 40);
  penpos2(4/3thick,  90 - sign * 90);

  x0 = x1 = x2 + sign * (w - 2side_bearing - thick);

  top y1l =  h;
  bot y0l = -d;
  1/2[y0,y1] = y2;
  1/2[x0l,x2l] = w/2;

  fill stroke z0e{3(x2e - x0e), y2e - y0e} .. z2e .. {3(x1e - x2e), y1e - y2e}z1e;

  penlabels(0,1,2);
enddef;

lparen_char = current_char + 1;
rparen_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol(2/3*(scale + 5.5) * u# + 2side_bearing#, vcentre(scale * delim_height#)); "parenthesis";
      draw_paren(sign, 9/20rule_thickness * sqrt (4*scale));
    endchar;
  endfor;
endfor;

% extensible parenthesis

for sign = 1, -1:
  beginsymbol(2/3*(6 + 5.5) * u# + 2side_bearing#, vcentre(6/2 * delim_height#)); "parenthesis -- top";
    thick := 9/20rule_thickness * sqrt 24;

    penpos1(1/2thick, -90 + sign * 40);
    penpos2(4/3thick, 90 - sign * 90);

    x1 = x2 + sign * (w - 2side_bearing - thick);

    top y1l = h + eps;
    y2 = -d - 1/2rule_thickness;
    1/2[x1l,x2l] = w/2;

    fill stroke z2e{up} .. {3(x1e - x2e), y1e - y2e}z1e;
  endchar;
endfor;

for sign = 1, -1:
  beginsymbol(2/3*(6 + 5.5) * u# + 2side_bearing#, vcentre(6/2 * delim_height#)); "parenthesis -- bot";
    thick := 9/20rule_thickness * sqrt 24;

    penpos0(1/2thick, 90 - sign * 40);
    penpos2(4/3thick, 90 - sign * 90);

    x0 = x2 + sign * (w - 2side_bearing - thick);

    y2 =  h + 1/2rule_thickness;
    bot y0l = -d - eps;
    1/2[x0l,x2l] = w/2;

    fill stroke z0e{3(x2e - x0e), y2e - y0e} .. {up}z2e;
  endchar;
endfor;

for sign = 1, -1:
  beginsymbol(2/3*(6 + 5.5) * u# + 2side_bearing#, vcentre(delim_height#)); "parenthesis -- module";
    thick := 9/20rule_thickness * sqrt 24;

    penpos1(1/2thick, 90 - sign * 40);
    penpos2(4/3thick, 90 - sign * 90);
    penpos3(4/3thick, 90 - sign * 90);

    x2 = x3 = x1 - sign * (w - 2side_bearing - thick);

    y2 =  h + 1/2rule_thickness;
    y3 = -d - 1/2rule_thickness;
    1/2[x1l,x2l] = w/2;

    fill stroke z2e -- z3e;
  endchar;
endfor;

extensible current_char:     current_char - 4, 0, current_char - 2, current_char;     %right parenthesis
extensible current_char - 1: current_char - 5, 0, current_char - 3, current_char - 1; %left parenthesis

charlist rparen_char: rparen_char + 1: rparen_char + 2: rparen_char + 3: rparen_char + 4: current_char;
charlist lparen_char: lparen_char + 1: lparen_char + 2: lparen_char + 3: lparen_char + 4: current_char - 1;

% curly braces

def draw_brace_tip(suffix $,@)(expr alpha,thick) =
  pickup pencircle scaled 1/12thick;

  penpos$ (1/2thick, alpha);
  penpos$'(1/2thick, alpha);
  penpos@ (thick, alpha);
  penpos@'(thick, alpha);

  beta := angle (5(x$l-x@l), y$-y@) - alpha;

  filldraw z$l{-dir (alpha + beta)} ... z@l --- z@'l -- z@'r
    --- z@r ... {dir (alpha + beta)}z$'r -- z$r -- cycle;
enddef;

def draw_brace(expr center, size, width, alpha, thick, top_size, mid_size, bot_size) =

  pickup pencircle scaled 1/12thick;

  penpos1 (1/2thick, alpha);
  penpos1'(1/2thick, alpha);
  penpos4 (1/2thick, alpha);
  penpos4'(1/2thick, alpha);
  penpos7 (1/2thick, alpha);
  penpos7'(1/2thick, alpha);
  penpos2 (thick, alpha);
  penpos2'(thick, alpha);
  penpos3 (thick, alpha);
  penpos3'(thick, alpha);
  penpos5 (thick, alpha);
  penpos5'(thick, alpha);
  penpos6 (thick, alpha);
  penpos6'(thick, alpha);

  z1 - z7 = (size - 1/6thick) * dir (alpha + 90);

  center - 1/2[z1l,z7l] = 1/2[z4r,z4'r] - center = width/2 * dir alpha;

  z2  = center + whatever * dir (alpha + 90);
  z3  = center + whatever * dir (alpha + 90);

  z3' = center + (mid_size/2 + 1/2rule_thickness) * dir (alpha + 90);
  z5' = center - (mid_size/2 + 1/2rule_thickness) * dir (alpha + 90);

  z2' = center + (size/2 - top_size - 1/2rule_thickness) * dir (alpha + 90);
  z6' = center - (size/2 - bot_size - 1/2rule_thickness) * dir (alpha + 90);

  1/2[z2,z6] = 1/2[z3,z5] = center;

  z2 - z3 = z5 - z6 = 5/24(size - 1/3thick) * dir (alpha + 90);

  z1 - z2 = z3 - z4;
  z7 - z6 = z5 - z4';

  z1 - z1' = z4 - z4' = z7' - z7 = 1/4thick * dir (alpha + 90);

  beta := angle (5 (z1l-z2l) dotprod dir alpha, (z1l-z2l) dotprod dir (alpha+90));

  if top_size > 0:
    filldraw z1r{-dir (alpha + beta)} ... z2r --- z2'r -- z2'l
      --- z2l ... {dir (alpha + beta)}z1'l -- z1l -- cycle;
    penlabels(1,2,2');
  elseif bot_size > 0:
    filldraw 
      z6'r --- z6r ... {dir (alpha - beta)}z7r
      -- z7l -- z7'l{-dir (alpha - beta)} ... z6l --- z6'l -- cycle;
    penlabels(6',6,7);
  elseif mid_size > 0:
    filldraw z3'r --- z3r{dir (alpha-90)} ... {dir alpha}z4r
      -- z4'r{-dir alpha} ... {dir (alpha-90)}z5r --- z5'r -- z5'l --- z5l{dir (alpha+90)}
      ... {dir alpha}1/2[z4l, z4'l]{-dir alpha}
      ... {dir (alpha+90)}z3l --- z3'l -- cycle;
    penlabels(3',3,4,5,5');
  else:
    filldraw z1r{-dir (alpha + beta)} ... z2r --- z3r{dir (alpha-90)} ... {dir alpha}z4r
      -- z4'r{-dir alpha} ... {dir (alpha-90)}z5r --- z6r ... {dir (alpha - beta)}z7r
      -- z7l -- z7'l{-dir (alpha - beta)} ... z6l --- z5l{dir (alpha+90)}
      ... {dir alpha}1/2[z4l, z4'l]{-dir alpha}
      ... {dir (alpha+90)}z3l --- z2l ... {dir (alpha + beta)}z1'l -- z1l -- cycle;
    penlabels(1,2,3,4,5,6,7);
  fi;

enddef;

lcurly_char = current_char + 1;
rcurly_char = current_char + 6;
for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol((scale + 10)/2 * u# + 2side_bearing#, vcentre(scale * delim_height#)); "curly brace";
      thick := 5/4rule_thickness * sqrt sqrt (scale/2);

      draw_brace((w/2, (h-d)/2), h+d, w - 2side_bearing, 90 + sign * 90, thick, 0, 0, 0)
    endchar;
  endfor;
endfor;

beginsymbol((6 + 10)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "curly brace -- top";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((w/2, h - 3delim_height), 6delim_height, w - 2side_bearing, 180, thick, 0, 0, h+d);
endchar;

beginsymbol((6 + 10)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "curly brace -- top";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((w/2, h - 3delim_height), 6delim_height, w - 2side_bearing,   0, thick, h+d, 0, 0);
endchar;

beginsymbol((6 + 10)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "curly brace -- bot";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((w/2, 3delim_height - d), 6delim_height, w - 2side_bearing, 180, thick, h+d, 0, 0)
endchar;

beginsymbol((6 + 10)/2 * u# + 2side_bearing#, vcentre(delim_height#)); "curly brace -- bot";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((w/2, 3delim_height - d), 6delim_height, w - 2side_bearing,   0, thick, 0, 0, h+d)
endchar;

for sign = 1, -1:
  beginsymbol((6 + 10)/2 * u# + 2side_bearing#, vcentre(2delim_height#)); "curly brace -- middle";
    thick := 5/4rule_thickness * sqrt sqrt (6/2);

    draw_brace((w/2, (h-d)/2), 6delim_height, w - 2side_bearing, 90 + sign * 90, thick, 0, h+d, 0);
  endchar;
endfor;

beginsymbol((6 + 10)/2 * u# + 2side_bearing#, vcentre(1/2delim_height#)); "curly brace -- module";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  pickup pencircle scaled 1/12thick;

  penpos2 (thick, 0);
  penpos3 (thick, 0);

  x2 = x3 = w/2;

  top y2 =  h + 1/2rule_thickness;
  bot y3 = -d - 1/2rule_thickness;

  filldraw stroke z2e -- z3e;
endchar;

extensible current_char - 6: current_char - 6, 0,                current_char - 4, current_char; %sharp left parenthesis
extensible current_char - 5: current_char - 5, 0,                current_char - 3, current_char; %sharp right parenthesis
extensible current_char - 4: current_char - 5, 0,                current_char - 4, current_char; %right moustache
extensible current_char - 3: current_char - 6, 0,                current_char - 3, current_char; %left moustache
extensible current_char - 2: current_char - 6, current_char - 2, current_char - 4, current_char; %left curly brace
extensible current_char - 1: current_char - 5, current_char - 1, current_char - 3, current_char; %right curly brace
extensible current_char:     0,                0,                0,                current_char; %vertical line

charlist rcurly_char: rcurly_char + 1: rcurly_char + 2: rcurly_char + 3: rcurly_char + 4: current_char - 1;
charlist lcurly_char: lcurly_char + 1: lcurly_char + 2: lcurly_char + 3: lcurly_char + 4: current_char - 2;

for sign = 1, -1:
  for scale = 2, 2.5, 3.3, 4.2, 5.1:
    beginsymbol(scale * delim_height#, vcentre((scale + 10)/2 * u# + 2side_bearing#));
      "horizontal curly brace";

      thick := 5/4rule_thickness * sqrt sqrt (scale/2);

      draw_brace((w/2, (h-d)/2), w, (h+d) - 2side_bearing, sign * 90, thick, 0, 0, 0)
    endchar;
  endfor;
endfor;

beginsymbol(delim_height#, vcentre((6 + 10)/2 * u# + 2side_bearing#)); "curly brace -- left";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((3delim_height, (h-d)/2), 6delim_height, (h+d) - 2side_bearing,  90, thick, w, 0, 0);
endchar;

beginsymbol(delim_height#, vcentre((6 + 10)/2 * u# + 2side_bearing#)); "curly brace -- left";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((3delim_height, (h-d)/2), 6delim_height, (h+d) - 2side_bearing, -90, thick, 0, 0, w);
endchar;

beginsymbol(delim_height#, vcentre((6 + 10)/2 * u# + 2side_bearing#)); "curly brace -- right";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((w - 3delim_height, (h-d)/2), 6delim_height, (h+d) - 2side_bearing,  90, thick, 0, 0, w);
endchar;

beginsymbol(delim_height#, vcentre((6 + 10)/2 * u# + 2side_bearing#)); "curly brace -- right";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  draw_brace((w - 3delim_height, (h-d)/2), 6delim_height, (h+d) - 2side_bearing, -90, thick, w, 0, 0);
endchar;

for sign = 1, -1:
  beginsymbol(2delim_height#, vcentre((6 + 10)/2 * u# + 2side_bearing#));
    "curly brace -- horizontal middle";

    thick := 5/4rule_thickness * sqrt sqrt (6/2);

    draw_brace((w/2, (h-d)/2), 6delim_height, (h+d) - 2side_bearing, sign * 90, thick, 0, w, 0);
  endchar;
endfor;

beginsymbol(u#, vcentre((6 + 10)/2 * u# + 2side_bearing#));
  "curly brace -- horizontal module";
  thick := 5/4rule_thickness * sqrt sqrt (6/2);

  pickup pencircle scaled 1/12thick;

  penpos1 (thick, 90);
  penpos2 (thick, 90);

  x1 = -u/2;
  x2 = w + u/2;
  y1 = y2 = (h-d)/2;

  filldraw stroke z1e -- z2e;
endchar;


% roots

def draw_root_top(expr scale, thick, vertical) =
  pickup pencircle scaled thick;

  top y0 = h;
  x0 = w;

  bot y1 = -d;

  if vertical:
    x1 = 6/9w;
    draw z0 -- (x1, y0) -- z1;
  else:
    x1 = 4/9w;
    draw z0 -- z1;
  fi;
enddef;

def draw_root_bot(expr scale, thick, vertical) =
  penpos2(3/2thick, 0);
  penpos3(thick, 0);

  x2l = 1/9w;
  y2  = 1/2[y0, y1];
  x3  = x1;
  bot y3 = -d;

  z4 = whatever[z0, z1] = z2r + whatever * (z2l - z3l);

  penpos5(1/2thick, angle (z3l - z2l));
  z5l = z2r + 5/2thick * dir (angle (z3l - z2l) - 90);

  z6 = whatever[z2l, z3l] = z5r + whatever * dir (angle (z3l - z2l) - 90);

  fill z5r -- z6 -- z3l -- z3 -- z4 -- z2r -- z5l -- cycle;
enddef;

root_char = current_char + 1;

for scale = 2, 2.5, 3.3, 4.2, 5.1:
  beginsymbol((2scale + 10) * u# + side_bearing#,
              sqrt (scale/2) * rule_thickness#,
              scale * delim_height# - sqrt (scale/2) * rule_thickness#);
    "root";

    draw_root_top(scale, sqrt (scale/2) * rule_thickness, false);
    draw_root_bot(scale, sqrt (scale/2) * rule_thickness, false);
    labels(0,1,2,3,4,5,6);

  endchar;
endfor;

beginsymbol((12 + 10) * u# + side_bearing#,
            sqrt (6/2) * rule_thickness#,
            delim_height# - sqrt (6/2) * rule_thickness#);
  "root -- top";

  thick := vround (sqrt (6/2) * rule_thickness# * hppp);

  draw_root_top(6, thick, true);
endchar;

beginsymbol((12 + 10) * u# + side_bearing#, 0, 3 * delim_height#);
  "root -- bottom";

  thick := vround (sqrt (6/2) * rule_thickness# * hppp);

  pickup pencircle scaled thick;

  x0 = x1 = 6/9w;
  bot y0 = d;
  bot y1 = -d;

  draw 1/2[z0, z1] -- z1;

  draw_root_bot(6, thick, true);
endchar;

beginsymbol((12 + 10) * u# + side_bearing#, vcentre(delim_height#));
  "root -- module";

  thick := vround (sqrt (6/2) * rule_thickness# * hppp);

  pickup pencircle scaled thick;

  x0 = x1 = 6/9w;
  y0 = h;
  y1 = -d;

  draw z0 -- z1;
endchar;

extensible current_char - 2: current_char - 2, 0, current_char - 1, current_char;

charlist root_char: root_char + 1: root_char + 2: root_char + 3: root_char + 4: current_char - 2;

% reserve space for accents
current_char := 212;

for arrow_dir = 90, 270:
  beginsymbol(8u# + 2side_bearing#, vcentre(delim_height#)); "arrow up/down";
    pickup rule_pen;

    pair foot, head;

    if arrow_dir = 90:
      head = (w/2, h);
      foot = (w/2, -d);
    else:
      head = (w/2, -d);
      foot = (w/2, h);
    fi;

    draw foot -- head;
    draw arrowhead(head, arrow_dir, arrow_spread);
  endchar;
endfor;

beginsymbol(8u# + 2side_bearing#, vcentre(delim_height#)); "arrow module";
  pickup rule_pen;

  z0 = (w/2,  h + 1/2rule_thickness);
  z1 = (w/2, -d - 1/2rule_thickness);

  draw z0 -- z1;
endchar;

extensible current_char-2: current_char-2, 0, current_char,   current_char;
extensible current_char-1: current_char,   0, current_char-1, current_char;
extensible current_char:   current_char-2, 0, current_char-1, current_char;

for arrow_dir = 90, 270:
  beginsymbol(8u# + 2side_bearing#, vcentre(delim_height#)); "double arrow up/down";
    pickup rule_pen;

    pair foot, head;

    if arrow_dir = 90:
      head = (w/2, h);
      foot = (w/2, -d);
    else:
      head = (w/2, -d);
      foot = (w/2, h);
    fi;

    z1 - z0 = z3 - z2 = equal_spread * dir (arrow_dir + 90);

    1/2[z0,z1] = foot - 1/2rule_thickness * dir arrow_dir;
    1/2[z2,z3] = head;

    draw z0 -- arrowhead_intersection(head, arrow_dir, 13/10arrow_spread, z0 -- z2);
    draw z1 -- arrowhead_intersection(head, arrow_dir, 13/10arrow_spread, z1 -- z3);

    draw arrowhead(head, arrow_dir, 13/10arrow_spread);
  endchar;
endfor;

beginsymbol(8u# + 2side_bearing#, vcentre(delim_height#)); "double arrow module";
  pickup rule_pen;

  z1 - z0 = z3 - z2 = equal_spread * right;

  1/2[z0,z1] = (w/2,  h + 1/2rule_thickness);
  1/2[z2,z3] = (w/2, -d - 1/2rule_thickness);

  draw z0 -- z2;
  draw z1 -- z3;
endchar;

extensible current_char-2: current_char-2, 0, current_char,   current_char;
extensible current_char-1: current_char,   0, current_char-1, current_char;
extensible current_char:   current_char-2, 0, current_char-1, current_char;