summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/math-vfu.lua
blob: fb5113be45bbf962fdb23ee70ac6006191dba4e1 (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
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
if not modules then modules = { } end modules ['math-vfu'] = {
    version   = 1.001,
    comment   = "companion to math-ini.tex",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- All these math vectors .. thanks to Aditya and Mojca they become
-- better and better.

local type, next = type, next

local trace_virtual = false trackers.register("math.virtual", function(v) trace_virtual = v end)
local trace_timings = false trackers.register("math.timings", function(v) trace_timings = v end)

fonts.enc.math = fonts.enc.math or { }

local shared = { }

fonts.vf.math          = fonts.vf.math or { }
fonts.vf.math.optional = false

local push, pop, back = { "push" }, { "pop" }, { "slot", 1, 0x2215 }

local function negate(main,unicode,basecode)
    local characters = main.characters
    if not characters[unicode] then
        local basechar = characters[basecode]
        if basechar then
            local ht, wd = basechar.height, basechar.width
            characters[unicode] = {
                width    = wd,
                height   = ht,
                depth    = basechar.depth,
                italic   = basechar.italic,
                kerns    = basechar.kerns,
                commands = {
                    { "slot", 1, basecode },
                    push,
                    { "down",    ht/5},
                    { "right", - wd/2},
                    back,
                    push,
                }
            }
        end
    end
end

--~ \Umathchardef\braceld="0 "1 "FF07A
--~ \Umathchardef\bracerd="0 "1 "FF07B
--~ \Umathchardef\bracelu="0 "1 "FF07C
--~ \Umathchardef\braceru="0 "1 "FF07D

local function brace(main,unicode,first,rule,left,right,rule,last)
    local characters = main.characters
    if not characters[unicode] then
        characters[unicode] = {
            horiz_variants = {
                { extender = 0, glyph = first },
                { extender = 1, glyph = rule  },
                { extender = 0, glyph = left  },
                { extender = 0, glyph = right },
                { extender = 1, glyph = rule  },
                { extender = 0, glyph = last  },
            }
        }
    end
end

local function arrow(main,unicode,arrow,minus,isleft)
    if isleft then
        t = {
            { extender = 0, glyph = arrow },
            { extender = 1, glyph = minus  },
        }
    else
        t = {
            { extender = 0, glyph = minus },
            { extender = 1, glyph = arrow },
        }
    end
--~     main.characters[unicode] = { horiz_variants = t }
    main.characters[unicode].horiz_variants = t
end

local function parent(main,unicode,first,rule,last)
    local characters = main.characters
    if not characters[unicode] then
        characters[unicode] = {
            horiz_variants = {
                { extender = 0, glyph = first },
                { extender = 1, glyph = rule  },
                { extender = 0, glyph = last  },
            }
        }
    end
end

local push, pop, step = { "push" }, { "pop" }, 0.2 -- 0.1 is nicer but gives larger files

local function make(main,id,size,n,m)
    local characters = main.characters
    local xu = main.parameters.x_height + 0.3*size
    local xd = 0.3*size
    local old, upslot, dnslot, uprule, dnrule = 0xFF000+n, 0xFF100+n, 0xFF200+n, 0xFF300+m, 0xFF400+m
    local c = characters[old]
    if c then
        local w, h, d = c.width, c.height, c.depth
        local thickness = h - d
        local rulewidth = step*size -- we could use an overlap
        local slot = { "slot", id, old }
        local rule = { "rule", thickness, rulewidth  }
        local up = { "down", -xu }
        local dn = { "down", xd }
        local ht, dp = xu + 3*thickness, 0
        if not characters[uprule] then
            characters[uprule] = { width = rulewidth, height = ht, depth = dp, commands = { push, up, rule, pop } }
        end
        characters[upslot] = { width = w, height = ht, depth = dp, commands = { push, up, slot, pop } }
        local ht, dp = 0, xd + 3*thickness
        if not characters[dnrule] then
            characters[dnrule] = { width = rulewidth, height = ht, depth = dp, commands = { push, dn, rule, pop } }
        end
        characters[dnslot] = { width = w, height = ht, depth = dp, commands = { push, dn, slot, pop } }
    end
end

local function minus(main,id,size,unicode)
    local characters = main.characters
    local mu = size/18
    local minus = characters[0x002D]
    local width = minus.width - 5*mu
    characters[unicode] = {
        width = width, height = minus.height, depth = minus.depth,
        commands = { push, { "right", -3*mu }, { "slot", id, 0x002D }, pop }
    }
end

local function dots(main,id,size,unicode)
    local characters = main.characters
    local c = characters[0x002E]
    local w, h, d = c.width, c.height, c.depth
    local mu = size/18
    local right3mu  = { "right", 3*mu }
    local right1mu  = { "right", 1*mu }
    local up1size   = { "down", -.1*size }
    local up4size   = { "down", -.4*size }
    local up7size   = { "down", -.7*size }
    local right2muw = { "right", 2*mu + w }
    local slot = { "slot", id, 0x002E }
    if unicode == 0x22EF then
        local c = characters[0x022C5]
        if c then
            local w, h, d = c.width, c.height, c.depth
            local slot = { "slot", id, 0x022C5 }
            characters[unicode] = {
                width = 3*w + 2*3*mu, height = h, depth = d,
                commands = { push, slot, right3mu, slot, right3mu, slot, pop }
            }
        end
    elseif unicode == 0x22EE then
        -- weird height !
        characters[unicode] = {
            width = w, height = h+(1.4)*size, depth = 0,
            commands = { push, push, slot, pop, up4size, push, slot, pop, up4size, slot, pop }
        }
    elseif unicode == 0x22F1 then
        characters[unicode] = {
            width = 3*w + 6*size/18, height = 1.5*size, depth = 0,
            commands = {
                push,
                    right1mu,
                    push, up7size, slot, pop,
                    right2muw,
                    push, up4size, slot, pop,
                    right2muw,
                    push, up1size, slot, pop,
                    right1mu,
                pop
            }
        }
    elseif unicode == 0x22F0 then
        characters[unicode] = {
            width = 3*w + 6*size/18, height = 1.5*size, depth = 0,
            commands = {
                push,
                    right1mu,
                    push, up1size, slot, pop,
                    right2muw,
                    push, up4size, slot, pop,
                    right2muw,
                    push, up7size, slot, pop,
                    right1mu,
                pop
            }
        }
    else
        characters[unicode] = {
            width = 3*w + 2*3*mu, height = h, depth = d,
            commands = { push, slot, right3mu, slot, right3mu, slot, pop }
        }
    end
end

function fonts.vf.math.alas(main,id,size)
    for i=0x7A,0x7D do
        make(main,id,size,i,1)
    end
    brace (main,0x23DE,0xFF17A,0xFF301,0xFF17D,0xFF17C,0xFF301,0xFF17B)
    brace (main,0x23DF,0xFF27C,0xFF401,0xFF27B,0xFF27A,0xFF401,0xFF27D)
    parent(main,0x23DC,0xFF17A,0xFF301,0xFF17B)
    parent(main,0x23DD,0xFF27C,0xFF401,0xFF27D)
    negate(main,0x2260,0x003D)
    dots(main,id,size,0x2026) -- ldots
    dots(main,id,size,0x22EE) -- vdots
    dots(main,id,size,0x22EF) -- cdots
    dots(main,id,size,0x22F1) -- ddots
    dots(main,id,size,0x22F0) -- udots
    minus(main,id,size,0xFF501)
    arrow(main,0x2190,0xFE190,0xFF501,true) -- left
    arrow(main,0x2192,0xFE192,0xFF501,false) -- right
end

local reverse -- index -> unicode

function fonts.basecopy(tfmtable)
    local t, c, p = { }, { }, { }
    for k, v in next, tfmtable do
        t[k] = v
    end
    for k, v in next, tfmtable.characters do
        c[k] = v
    end
    for k, v in next, tfmtable.parameters do
        p[k] = v
    end
    t.characters, t.parameters = c, p
    return t
end

local reported = { }

function fonts.vf.math.define(specification,set)
    if not reverse then
        reverse = { }
        for k, v in next, fonts.enc.math do
            local r = { }
            for u, i in next, v do
                r[i] = u
            end
            reverse[k] = r
        end
    end
    local name = specification.name -- symbolic name
    local size = specification.size -- given size
    local fnt, lst, main = { }, { }, nil
    local start = (trace_virtual or trace_timings) and os.clock()
--~ texio.write_nl("defining font " .. name .. " " .. size)
    local okset, n = { }, 0
    for s=1,#set do
        local ss = set[s]
        local ssname = ss.name
        if ss.optional and fonts.vf.math.optional then
            if trace_virtual then
                logs.report("math virtual","loading font %s subfont %s with name %s at %s is skipped",name,s,ssname,size)
            end
        else
            if ss.features then ssname = ssname .. "*" .. ss.features end
            if ss.main then main = s end
            local f, id = fonts.tfm.read_and_define(ssname,size)
            if not f then
                logs.report("math virtual","loading font %s subfont %s with name %s at %s is skipped, not found",name,s,ssname,size)
            else
                n = n + 1
                okset[n] = ss
                fnt[n] = f
                lst[n] = { id = id, size = size }
                if not shared[s] then shared[n] = { } end
                if trace_virtual then
                    logs.report("math virtual","loading font %s subfont %s with name %s at %s as id %s using encoding %s",name,s,ssname,size,id,ss.vector or "none")
                end
            end
        end
    end
    -- beware, fnt[1] is already passed to tex (we need to make a simple copy then .. todo)
    main = fonts.basecopy(fnt[1])
    main.name, main.fonts, main.virtualized, main.math_parameters = name, lst, true, { }
    local characters, descriptions = main.characters, main.descriptions
    main.parameters.x_height = main.parameters.x_height or 0
    for s=1,n do
        local ss, fs = okset[s], fnt[s]
        if not fs then
            -- skip, error
        elseif ss.optional and fonts.vf.math.optional then
            -- skip, redundant
        else
            local mm, fp = main.math_parameters, fs.parameters
            if ss.extension then
                mm.math_x_height          = fp.x_height or 0 -- math_x_height           height of x
                mm.default_rule_thickness = fp[ 8] or 0 -- default_rule_thickness  thickness of \over bars
                mm.big_op_spacing1        = fp[ 9] or 0 -- big_op_spacing1         minimum clearance above a displayed op
                mm.big_op_spacing2        = fp[10] or 0 -- big_op_spacing2         minimum clearance below a displayed op
                mm.big_op_spacing3        = fp[11] or 0 -- big_op_spacing3         minimum baselineskip above displayed op
                mm.big_op_spacing4        = fp[12] or 0 -- big_op_spacing4         minimum baselineskip below displayed op
                mm.big_op_spacing5        = fp[13] or 0 -- big_op_spacing5         padding above and below displayed limits
            --  logs.report("math virtual","loading and virtualizing font %s at size %s, setting ex parameters",name,size)
            elseif ss.parameters then
                main.parameters.x_height = fp.x_height or main.parameters.x_height
                mm.x_height      = mm.x_height or fp.x_height or 0 -- x_height                height of x
                mm.num1          = fp[ 8] or 0 -- num1                    numerator shift-up in display styles
                mm.num2          = fp[ 9] or 0 -- num2                    numerator shift-up in non-display, non-\atop
                mm.num3          = fp[10] or 0 -- num3                    numerator shift-up in non-display \atop
                mm.denom1        = fp[11] or 0 -- denom1                  denominator shift-down in display styles
                mm.denom2        = fp[12] or 0 -- denom2                  denominator shift-down in non-display styles
                mm.sup1          = fp[13] or 0 -- sup1                    superscript shift-up in uncramped display style
                mm.sup2          = fp[14] or 0 -- sup2                    superscript shift-up in uncramped non-display
                mm.sup3          = fp[15] or 0 -- sup3                    superscript shift-up in cramped styles
                mm.sub1          = fp[16] or 0 -- sub1                    subscript shift-down if superscript is absent
                mm.sub2          = fp[17] or 0 -- sub2                    subscript shift-down if superscript is present
                mm.sup_drop      = fp[18] or 0 -- sup_drop                superscript baseline below top of large box
                mm.sub_drop      = fp[19] or 0 -- sub_drop                subscript baseline below bottom of large box
                mm.delim1        = fp[20] or 0 -- delim1                  size of \atopwithdelims delimiters in display styles
                mm.delim2        = fp[21] or 0 -- delim2                  size of \atopwithdelims delimiters in non-displays
                mm.axis_height   = fp[22] or 0 -- axis_height             height of fraction lines above the baseline
            --  logs.report("math virtual","loading and virtualizing font %s at size %s, setting sy parameters",name,size)
            end
            local vectorname = ss.vector
            if vectorname then
                local offset = 0xFF000
                local vector = fonts.enc.math[vectorname]
                local rotcev = reverse[vectorname]
                if vector then
                    local fc, fd, si = fs.characters, fs.descriptions, shared[s]
                    local skewchar = ss.skewchar
                    for unicode, index in next, vector do
                        local fci = fc[index]
                        if not fci then
                            local fontname = fs.name
                            local rf = reported[fontname]
                            if not rf then rf = { } reported[fontname] = rf end
                            local rv = rf[vectorname]
                            if not rv then rv = { } rf[vectorname] = rv end
                            local ru = rv[unicode]
                            if not ru then
                                logs.report("math virtual", "unicode point U+%05X has no index %04X in vector %s for font %s",unicode,index,vectorname,fontname)
                                rv[unicode] = true
                            end
                        else
                            local ref = si[index]
                            if not ref then
                                ref = { { 'slot', s, index } }
                                si[index] = ref
                            end
                            local kerns = fci.kerns
                            if kerns then
                                local width = fci.width
                                local krn = { }
                                for k=1,#kerns do
                                    local rk = rotcev[k]
                                    if rk then
                                        krn[rk] = kerns[k]
                                    end
                                end
                                if not next(krn) then
                                    krn = nil
                                end
                                local t = {
                                    width    = width,
                                    height   = fci.height,
                                    depth    = fci.depth,
                                    italic   = fci.italic,
                                    kerns    = krn,
                                    commands = ref,
                                }
                                if skewchar and kerns then
                                    local k = kerns[skewchar]
                                    if k then
                                        t.top_accent = width/2 + k
                                    end
                                end
                                characters[unicode] = t
                            else
                                characters[unicode] = {
                                    width    = fci.width,
                                    height   = fci.height,
                                    depth    = fci.depth,
                                    italic   = fci.italic,
                                    commands = ref,
                                }
                            end
                        end
                    end
                    if ss.extension then
                        -- todo: if multiple ex, then 256 offsets per instance
                        local extension = fonts.enc.math["large-to-small"]
                        local variants_done = fs.variants_done
                        for index, fci in next, fc do -- the raw ex file
                            if type(index) == "number" then
                                local ref = si[index]
                                if not ref then
                                    ref = { { 'slot', s, index } }
                                    si[index] = ref
                                end
                                local t = {
                                    width    = fci.width,
                                    height   = fci.height,
                                    depth    = fci.depth,
                                    italic   = fci.italic,
                                    commands = ref,
                                }
                                local n = fci.next
                                if n then
                                    t.next = offset + n
                                elseif variants_done then
                                    local vv = fci.vert_variants
                                    if vv then
                                        t.vert_variants = vv
                                    end
                                    local hv = fci.horiz_variants
                                    if hv then
                                        t.horiz_variants = hv
                                    end
                                else
                                    local vv = fci.vert_variants
                                    if vv then
                                        for i=1,#vv do
                                            local vvi = vv[i]
                                            vvi.glyph = vvi.glyph + offset
                                        end
                                        t.vert_variants = vv
                                    end
                                    local hv = fci.horiz_variants
                                    if hv then
                                        for i=1,#hv do
                                            local hvi = hv[i]
                                            hvi.glyph = hvi.glyph + offset
                                        end
                                        t.horiz_variants = hv
                                    end
                                end
                                characters[offset + index] = t
                            end
                        end
                        fs.variants_done = true
                        for unicode, index in next, extension do
                            local cu = characters[unicode]
                            if cu then
                                cu.next = offset + index
                                --~ local n, c, d = unicode, cu, { }
                                --~ print("START", unicode)
                                --~ while n do
                                --~     n = c.next
                                --~     if n then
                                --~         print("NEXT", n)
                                --~         c = characters[n]
                                --~         if not c then
                                --~             print("EXIT")
                                --~         elseif d[n] then
                                --~             print("LOOP")
                                --~             break
                                --~         end
                                --~         d[n] = true
                                --~     end
                                --~ end
                            else
                                local fci = fc[index]
                                local ref = si[index]
                                if not ref then
                                    ref = { { 'slot', s, index } }
                                    si[index] = ref
                                end
                                local kerns = fci.kerns
                                if kerns then
                                    local krn = { }
                                    for k=1,#kerns do
                                        krn[offset + k] = kerns[k]
                                    end
                                    characters[unicode] = {
                                        width    = fci.width,
                                        height   = fci.height,
                                        depth    = fci.depth,
                                        italic   = fci.italic,
                                        commands = ref,
                                        kerns    = krn,
                                        next     = offset + index,
                                    }
                                else
                                    characters[unicode] = {
                                        width    = fci.width,
                                        height   = fci.height,
                                        depth    = fci.depth,
                                        italic   = fci.italic,
                                        commands = ref,
                                        next     = offset + index,
                                    }
                                end
                            end
                        end
                    end
                end
            end
            mathematics.extras.copy(main) --not needed here (yet)
        end
    end
    lst[#lst+1] = { id = font.nextid(), size = size }
    fonts.vf.math.alas(main,#lst,size)
    if trace_virtual or trace_timings then
        logs.report("math virtual","loading and virtualizing font %s at size %s took %0.3f seconds",name,size,os.clock()-start)
    end
    main.has_italic = true
    main.type = "virtual" -- not needed
    mathematics.scaleparameters(main,main,1)
main.nomath = false
    return main
end

function mathematics.make_font(name, set)
    fonts.define.methods[name] = function(specification)
        return fonts.vf.math.define(specification,set)
    end
end

-- varphi is part of the alphabet, contrary to the other var*s'

fonts.enc.math["large-to-small"] = {
    [0x00028] = 0x00, -- (
    [0x00029] = 0x01, -- )
    [0x0005B] = 0x02, -- [
    [0x0005D] = 0x03, -- ]
    [0x0230A] = 0x04, -- lfloor
    [0x0230B] = 0x05, -- rfloor
    [0x02308] = 0x06, -- lceil
    [0x02309] = 0x07, -- rceil
    [0x0007B] = 0x08, -- {
    [0x0007D] = 0x09, -- }
    [0x027E8] = 0x0A, -- <
    [0x027E9] = 0x0B, -- >
    [0x0007C] = 0x0C, -- |
--~ [0x0]     = 0x0D, -- lVert rVert Vert
--  [0x0002F] = 0x0E, -- /
    [0x0005C] = 0x0F, -- \
--~ [0x0]     = 0x3A, -- lgroup
--~ [0x0]     = 0x3B, -- rgroup
--~ [0x0]     = 0x3C, -- arrowvert
--~ [0x0]     = 0x3D, -- Arrowvert
    [0x02195] = 0x3F, -- updownarrow
--~ [0x0]     = 0x40, -- lmoustache
--~ [0x0]     = 0x41, -- rmoustache
    [0x0221A] = 0x70, -- sqrt
    [0x021D5] = 0x77, -- Updownarrow
    [0x02191] = 0x78, -- uparrow
    [0x02193] = 0x79, -- downarrow
    [0x021D1] = 0x7E, -- Uparrow
    [0x021D3] = 0x7F, -- Downarrow
    [0x0220F] = 0x59, -- prod
    [0x02210] = 0x61, -- coprod
    [0x02211] = 0x58, -- sum
    [0x0222B] = 0x5A, -- intop
    [0x0222E] = 0x49, -- ointop
    [0xFE302] = 0x62, -- widehat
    [0xFE303] = 0x65, -- widetilde
    [0x022C0] = 0x5E, -- bigwedge
    [0x022C1] = 0x5F, -- bigvee
    [0x022C2] = 0x5C, -- bigcap
    [0x022C3] = 0x5B, -- bigcup
    [0x02044] = 0x0E, -- /
}

fonts.enc.math["tex-ex"] = {
    [0x0220F] = 0x51, -- prod
    [0x0222B] = 0x52, -- intop
    [0x02210] = 0x60, -- coprod
    [0x02211] = 0x50, -- sum
    [0x022C0] = 0x56, -- bigwedge
    [0x022C1] = 0x57, -- bigvee
    [0x022C2] = 0x54, -- bigcap
    [0x022C3] = 0x53, -- bigcup
    [0x02A04] = 0x55, -- biguplus
    [0x02A02] = 0x4E, -- bigotimes
    [0x02A01] = 0x4C, -- bigoplus
    [0x02A03] = 0x4A, -- bigodot
    [0x0222E] = 0x48, -- ointop
    [0x02A06] = 0x46, -- bigsqcup
}

-- only math stuff is needed, since we always use an lm or gyre
-- font as main font

fonts.enc.math["tex-mr"] = {
    [0x00393] = 0x00, -- Gamma
    [0x00394] = 0x01, -- Delta
    [0x00398] = 0x02, -- Theta
    [0x0039B] = 0x03, -- Lambda
    [0x0039E] = 0x04, -- Xi
    [0x003A0] = 0x05, -- Pi
    [0x003A3] = 0x06, -- Sigma
    [0x003A5] = 0x07, -- Upsilon
    [0x003A6] = 0x08, -- Phi
    [0x003A8] = 0x09, -- Psi
    [0x003A9] = 0x0A, -- Omega
--  [0x00060] = 0x12, -- [math]grave
--  [0x000B4] = 0x13, -- [math]acute
--  [0x002C7] = 0x14, -- [math]check
--  [0x002D8] = 0x15, -- [math]breve
--  [0x000AF] = 0x16, -- [math]bar
--  [0x00021] = 0x21, -- !
--  [0x00028] = 0x28, -- (
--  [0x00029] = 0x29, -- )
--  [0x0002B] = 0x2B, -- +
--  [0x0002F] = 0x2F, -- /
--  [0x0003A] = 0x3A, -- :
--  [0x02236] = 0x3A, -- colon
--  [0x0003B] = 0x3B, -- ;
--  [0x0003C] = 0x3C, -- <
--  [0x0003D] = 0x3D, -- =
--  [0x0003E] = 0x3E, -- >
--  [0x0003F] = 0x3F, -- ?
    [0x00391] = 0x41, -- Alpha
    [0x00392] = 0x42, -- Beta
    [0x02145] = 0x44,
    [0x00395] = 0x45, -- Epsilon
    [0x00397] = 0x48, -- Eta
    [0x00399] = 0x49, -- Iota
    [0x0039A] = 0x4B, -- Kappa
    [0x0039C] = 0x4D, -- Mu
    [0x0039D] = 0x4E, -- Nu
    [0x0039F] = 0x4F, -- Omicron
    [0x003A1] = 0x52, -- Rho
    [0x003A4] = 0x54, -- Tau
    [0x003A7] = 0x58, -- Chi
    [0x00396] = 0x5A, -- Zeta
--  [0x0005B] = 0x5B, -- [
--  [0x0005D] = 0x5D, -- ]
--  [0x0005E] = 0x5E, -- [math]hat -- the text one
    [0x00302] = 0x5E, -- [math]hat -- the real math one
--  [0x002D9] = 0x5F, -- [math]dot
    [0x02146] = 0x64,
    [0x02147] = 0x65,
--  [0x002DC] = 0x7E, -- [math]tilde -- the text one
    [0x00303] = 0x7E, -- [math]tilde -- the real one
--  [0x000A8] = 0x7F, -- [math]ddot
}

fonts.enc.math["tex-mi"] = {
    [0x1D6E4] = 0x00, -- Gamma
    [0x1D6E5] = 0x01, -- Delta
    [0x1D6E9] = 0x02, -- Theta
    [0x1D6F3] = 0x02, -- varTheta (not present in TeX)
    [0x1D6EC] = 0x03, -- Lambda
    [0x1D6EF] = 0x04, -- Xi
    [0x1D6F1] = 0x05, -- Pi
    [0x1D6F4] = 0x06, -- Sigma
    [0x1D6F6] = 0x07, -- Upsilon
    [0x1D6F7] = 0x08, -- Phi
    [0x1D6F9] = 0x09, -- Psi
    [0x1D6FA] = 0x0A, -- Omega
    [0x1D6FC] = 0x0B, -- alpha
    [0x1D6FD] = 0x0C, -- beta
    [0x1D6FE] = 0x0D, -- gamma
    [0x1D6FF] = 0x0E, -- delta
    [0x1D716] = 0x0F, -- epsilon TODO: 1D716
    [0x1D701] = 0x10, -- zeta
    [0x1D702] = 0x11, -- eta
    [0x1D703] = 0x12, -- theta TODO: 1D703
    [0x1D704] = 0x13, -- iota
    [0x1D705] = 0x14, -- kappa
    [0x1D718] = 0x14, -- varkappa, not in tex fonts
    [0x1D706] = 0x15, -- lambda
    [0x1D707] = 0x16, -- mu
    [0x1D708] = 0x17, -- nu
    [0x1D709] = 0x18, -- xi
    [0x1D70B] = 0x19, -- pi
    [0x1D70C] = 0x1A, -- rho
    [0x1D70E] = 0x1B, -- sigma
    [0x1D70F] = 0x1C, -- tau
    [0x1D710] = 0x1D, -- upsilon
    [0x1D719] = 0x1E, -- phi
    [0x1D712] = 0x1F, -- chi
    [0x1D713] = 0x20, -- psi
    [0x1D714] = 0x21, -- omega
    [0x1D700] = 0x22, -- varepsilon (the other way around)
    [0x1D717] = 0x23, -- vartheta
    [0x1D71B] = 0x24, -- varpi
    [0x1D71A] = 0x25, -- varrho
    [0x1D70D] = 0x26, -- varsigma
    [0x1D711] = 0x27, -- varphi (the other way around)
    [0x021BC] = 0x28, -- leftharpoonup
    [0x021BD] = 0x29, -- leftharpoondown
    [0x021C0] = 0x2A, -- righttharpoonup
    [0x021C1] = 0x2B, -- rightharpoondown
    --          0x2C, -- lhook (hook for combining arrows)
    --          0x2D, -- rhook (hook for combining arrows)
    [0x022B3] = 0x2E, -- triangleright (TODO: which one is right?)
    [0x022B2] = 0x2F, -- triangleleft (TODO: which one is right?)
--  [0x00041] = 0x30, -- 0
--  [0x00041] = 0x31, -- 1
--  [0x00041] = 0x32, -- 2
--  [0x00041] = 0x33, -- 3
--  [0x00041] = 0x34, -- 4
--  [0x00041] = 0x35, -- 5
--  [0x00041] = 0x36, -- 6
--  [0x00041] = 0x37, -- 7
--  [0x00041] = 0x38, -- 8
--  [0x00041] = 0x39, -- 9
--~     [0x0002E] = 0x3A, -- .
    [0x0002C] = 0x3B, -- ,
    [0x0003C] = 0x3C, -- <
--  [0x0002F] = 0x3D, -- /, slash, solidus
    [0x02044] = 0x3D, -- / AM: Not sure
    [0x0003E] = 0x3E, -- >
    [0x022C6] = 0x3F, -- star
    [0x02202] = 0x40, -- partial
--  [0x00041] = 0x41, -- A
    [0x1D6E2] = 0x41, -- Alpha
--  [0x00042] = 0x42, -- B
    [0x1D6E3] = 0x42, -- Beta
--  [0x00043] = 0x43, -- C
--  [0x00044] = 0x44, -- D
--  [0x00045] = 0x45, -- E
    [0x1D6E6] = 0x45, -- Epsilon
--  [0x00046] = 0x46, -- F
--  [0x00047] = 0x47, -- G
--  [0x00048] = 0x48, -- H
    [0x1D6E8] = 0x48, -- Eta
--  [0x00049] = 0x49, -- I
    [0x1D6EA] = 0x49, -- Iota
--  [0x0004A] = 0x4A, -- J
--  [0x0004B] = 0x4B, -- K
    [0x1D6EB] = 0x4B, -- Kappa
--  [0x0004C] = 0x4C, -- L
--  [0x0004D] = 0x4D, -- M
    [0x1D6ED] = 0x4D, -- Mu
--  [0x0004E] = 0x4E, -- N
    [0x1D6EE] = 0x4E, -- Nu
--  [0x0004F] = 0x4F, -- O
    [0x1D6F0] = 0x4F, -- Omicron
--  [0x00050] = 0x50, -- P
    [0x1D6F2] = 0x50, -- Rho
--  [0x00051] = 0x51, -- Q
--  [0x00052] = 0x52, -- R
--  [0x00053] = 0x53, -- S
--  [0x00054] = 0x54, -- T
    [0x1D6F5] = 0x54, -- Tau
--  [0x00055] = 0x55, -- U
--  [0x00056] = 0x56, -- V
--  [0x00057] = 0x57, -- W
--  [0x00058] = 0x58, -- X
    [0x1D6F8] = 0x58, -- Chi
--  [0x00059] = 0x59, -- Y
--  [0x0005A] = 0x5A, -- Z
    [0x1D6E7] = 0x5A, -- Zeta
    [0x0266D] = 0x5B, -- flat
    [0x0266E] = 0x5C, -- natural
    [0x0266F] = 0x5D, -- sharp
    [0x02323] = 0x5E, -- smile
    [0x02322] = 0x5F, -- frown
    [0x02113] = 0x60, -- ell
--  [0x00061] = 0x61, -- a
--  [0x00062] = 0x62, -- b
--  [0x00063] = 0x63, -- c
--  [0x00064] = 0x64, -- d
--  [0x00065] = 0x65, -- e
--  [0x00066] = 0x66, -- f
--  [0x00067] = 0x67, -- g
--  [0x00068] = 0x68, -- h
    [0x0210E] = 0x68, -- plant constant
--  [0x00069] = 0x69, -- i
--  [0x0006A] = 0x6A, -- j
--  [0x0006B] = 0x6B, -- k
--  [0x0006C] = 0x6C, -- l
--  [0x0006D] = 0x6D, -- m
--  [0x0006E] = 0x6E, -- n
--  [0x0006F] = 0x6F, -- o
    [0x1D70A] = 0x6F, -- omicron
--  [0x00070] = 0x70, -- p
--  [0x00071] = 0x71, -- q
--  [0x00072] = 0x72, -- r
--  [0x00073] = 0x73, -- s
--  [0x00074] = 0x74, -- t
--  [0x00075] = 0x75, -- u
--  [0x00076] = 0x76, -- v
--  [0x00077] = 0x77, -- w
--  [0x00078] = 0x78, -- x
--  [0x00079] = 0x79, -- y
--  [0x0007A] = 0x7A, -- z
    [0x1D6A4] = 0x7B, -- imath (TODO: also 0131)
    [0x1D6A5] = 0x7C, -- jmath (TODO: also 0237)
    [0x02118] = 0x7D, -- wp
    [0x020D7] = 0x7E, -- vec (TODO: not sure)
--              0x7F, -- (no idea what that could be)
}

fonts.enc.math["tex-ss"]           = { }
fonts.enc.math["tex-tt"]           = { }
fonts.enc.math["tex-bf"]           = { }
fonts.enc.math["tex-bi"]           = { }
fonts.enc.math["tex-fraktur"]      = { }
fonts.enc.math["tex-fraktur-bold"] = { }

function fonts.vf.math.set_letters(font_encoding, name, uppercase, lowercase)
    local enc = font_encoding[name]
    for i = 0,25 do
        enc[uppercase+i] = i + 0x41
        enc[lowercase+i] = i + 0x61
    end
end

function fonts.vf.math.set_digits(font_encoding, name, digits)
    local enc = font_encoding[name]
    for i = 0,9 do
        enc[digits+i] = i + 0x30
    end
end

fonts.enc.math["tex-sy"] = {
    [0x0002D] = 0x00, -- -
    [0x02212] = 0x00, -- -
--  [0x02201] = 0x00, -- complement
--  [0x02206] = 0x00, -- increment
--  [0x02204] = 0x00, -- not exists
--~     [0x000B7] = 0x01, -- cdot
    [0x022C5] = 0x01, -- cdot
    [0x000D7] = 0x02, -- times
    [0x0002A] = 0x03, -- *
    [0x02217] = 0x03, -- *
    [0x000F7] = 0x04, -- div
    [0x022C4] = 0x05, -- diamond
    [0x000B1] = 0x06, -- pm
    [0x02213] = 0x07, -- mp
    [0x02295] = 0x08, -- oplus
    [0x02296] = 0x09, -- ominus
    [0x02297] = 0x0A, -- otimes
    [0x02298] = 0x0B, -- oslash
    [0x02299] = 0x0C, -- odot
    [0x025EF] = 0x0D, -- bigcirc, Orb (either 25EF or 25CB) -- todo
    [0x02218] = 0x0E, -- circ
    [0x02219] = 0x0F, -- bullet
    [0x02022] = 0x0F, -- bullet
    [0x0224D] = 0x10, -- asymp
    [0x02261] = 0x11, -- equiv
    [0x02286] = 0x12, -- subseteq
    [0x02287] = 0x13, -- supseteq
    [0x02264] = 0x14, -- leq
    [0x02265] = 0x15, -- geq
    [0x02AAF] = 0x16, -- preceq
--  [0x0227C] = 0x16, -- preceq, AM:No see 2AAF
    [0x02AB0] = 0x17, -- succeq
--  [0x0227D] = 0x17, -- succeq, AM:No see 2AB0
    [0x0223C] = 0x18, -- sim
    [0x02248] = 0x19, -- approx
    [0x02282] = 0x1A, -- subset
    [0x02283] = 0x1B, -- supset
    [0x0226A] = 0x1C, -- ll
    [0x0226B] = 0x1D, -- gg
    [0x0227A] = 0x1E, -- prec
    [0x0227B] = 0x1F, -- succ
    [0x02190] = 0x20, -- leftarrow
    [0x02192] = 0x21, -- rightarrow
--~ [0xFE190] = 0x20, -- leftarrow
--~ [0xFE192] = 0x21, -- rightarrow
    [0x02191] = 0x22, -- uparrow
    [0x02193] = 0x23, -- downarrow
    [0x02194] = 0x24, -- leftrightarrow
    [0x02197] = 0x25, -- nearrow
    [0x02198] = 0x26, -- searrow
    [0x02243] = 0x27, -- simeq
    [0x021D0] = 0x28, -- Leftarrow
    [0x021D2] = 0x29, -- Rightarrow
    [0x021D1] = 0x2A, -- Uparrow
    [0x021D3] = 0x2B, -- Downarrow
    [0x021D4] = 0x2C, -- Leftrightarrow
    [0x02196] = 0x2D, -- nwarrow
    [0x02199] = 0x2E, -- swarrow
    [0x0221D] = 0x2F, -- propto
    [0x02032] = 0x30, -- prime
    [0x0221E] = 0x31, -- infty
    [0x02208] = 0x32, -- in
    [0x0220B] = 0x33, -- ni
    [0x025B3] = 0x34, -- triangle, bigtriangleup
    [0x025BD] = 0x35, -- bigtriangledown
    [0x00338] = 0x36, -- not
--              0x37, -- (beginning of arrow)
    [0x02200] = 0x38, -- forall
    [0x02203] = 0x39, -- exists
    [0x000AC] = 0x3A, -- neg, lnot
    [0x02205] = 0x3B, -- empty set
    [0x0211C] = 0x3C, -- Re
    [0x02111] = 0x3D, -- Im
    [0x022A4] = 0x3E, -- top
    [0x022A5] = 0x3F, -- bot, perp
    [0x02135] = 0x40, -- aleph
    [0x1D49C] = 0x41, -- script A
    [0x0212C] = 0x42, -- script B
    [0x1D49E] = 0x43, -- script C
    [0x1D49F] = 0x44, -- script D
    [0x02130] = 0x45, -- script E
    [0x02131] = 0x46, -- script F
    [0x1D4A2] = 0x47, -- script G
    [0x0210B] = 0x48, -- script H
    [0x02110] = 0x49, -- script I
    [0x1D4A5] = 0x4A, -- script J
    [0x1D4A6] = 0x4B, -- script K
    [0x02112] = 0x4C, -- script L
    [0x02133] = 0x4D, -- script M
    [0x1D4A9] = 0x4E, -- script N
    [0x1D4AA] = 0x4F, -- script O
    [0x1D4AB] = 0x50, -- script P
    [0x1D4AC] = 0x51, -- script Q
    [0x0211B] = 0x52, -- script R
    [0x1D4AE] = 0x53, -- script S
    [0x1D4AF] = 0x54, -- script T
    [0x1D4B0] = 0x55, -- script U
    [0x1D4B1] = 0x56, -- script V
    [0x1D4B2] = 0x57, -- script W
    [0x1D4B3] = 0x58, -- script X
    [0x1D4B4] = 0x59, -- script Y
    [0x1D4B5] = 0x5A, -- script Z
    [0x0222A] = 0x5B, -- cup
    [0x02229] = 0x5C, -- cap
    [0x0228E] = 0x5D, -- uplus
    [0x02227] = 0x5E, -- wedge, land
    [0x02228] = 0x5F, -- vee, lor
    [0x022A2] = 0x60, -- vdash
    [0x022A3] = 0x61, -- dashv
    [0x0230A] = 0x62, -- lfloor
    [0x0230B] = 0x63, -- rfloor
    [0x02308] = 0x64, -- lceil
    [0x02309] = 0x65, -- rceil
    [0x0007B] = 0x66, -- {, lbrace
    [0x0007D] = 0x67, -- }, rbrace
    [0x027E8] = 0x68, -- <, langle
    [0x027E9] = 0x69, -- >, rangle
    [0x0007C] = 0x6A, -- |, mid, lvert, rvert
    [0x02225] = 0x6B, -- parallel, Vert, lVert, rVert, arrowvert
    [0x02195] = 0x6C, -- updownarrow
    [0x021D5] = 0x6D, -- Updownarrow
    [0x0005C] = 0x6E, -- \, backslash, setminus
    [0x02216] = 0x6E, -- setminus
    [0x02240] = 0x6F, -- wr
    [0x0221A] = 0x70, -- sqrt. AM: Check surd??
    [0x02A3F] = 0x71, -- amalg
    [0x1D6FB] = 0x72, -- nabla
--  [0x0222B] = 0x73, -- smallint (TODO: what about intop?)
    [0x02294] = 0x74, -- sqcup
    [0x02293] = 0x75, -- sqcap
    [0x02291] = 0x76, -- sqsubseteq
    [0x02292] = 0x77, -- sqsupseteq
    [0x000A7] = 0x78, -- S
    [0x02020] = 0x79, -- dagger, dag
    [0x02021] = 0x7A, -- ddagger, ddag
    [0x000B6] = 0x7B, -- P
    [0x02663] = 0x7C, -- clubsuit
    [0x02662] = 0x7D, -- diamondsuit
    [0x02661] = 0x7E, -- heartsuit
    [0x02660] = 0x7F, -- spadesuit
    [0xFE321] = 0x37, -- mapstochar
}

-- The names in masm10.enc can be trusted best and are shown in the first
-- column, while in the second column we show the tex/ams names. As usual
-- it costs hours to figure out such a table.

fonts.enc.math["tex-ma"] = {
    [0x022A1] = 0x00, -- squaredot             \boxdot
    [0x0229E] = 0x01, -- squareplus            \boxplus
    [0x022A0] = 0x02, -- squaremultiply        \boxtimes
    [0x025A1] = 0x03, -- square                \square \Box
    [0x025A0] = 0x04, -- squaresolid           \blacksquare
    [0x000B7] = 0x05, -- squaresmallsolid      \centerdot
    [0x022C4] = 0x06, -- diamond               \Diamond \lozenge
    [0x029EB] = 0x07, -- diamondsolid          \blacklozenge
    [0x021BA] = 0x08, -- clockwise             \circlearrowright
    [0x021BB] = 0x09, -- anticlockwise         \circlearrowleft
    [0x021CC] = 0x0A, -- harpoonleftright      \rightleftharpoons
    [0x021CB] = 0x0B, -- harpoonrightleft      \leftrightharpoons
    [0x0229F] = 0x0C, -- squareminus           \boxminus
    [0x022A9] = 0x0D, -- forces                \Vdash
    [0x022AA] = 0x0E, -- forcesbar             \Vvdash
    [0x022A8] = 0x0F, -- satisfies             \vDash
    [0x021A0] = 0x10, -- dblarrowheadright     \twoheadrightarrow
    [0x0219E] = 0x11, -- dblarrowheadleft      \twoheadleftarrow
    [0x021C7] = 0x12, -- dblarrowleft          \leftleftarrows
    [0x021C9] = 0x13, -- dblarrowright         \rightrightarrows
    [0x021C8] = 0x14, -- dblarrowup            \upuparrows
    [0x021CA] = 0x15, -- dblarrowdwn           \downdownarrows
    [0x021BE] = 0x16, -- harpoonupright        \upharpoonright \restriction
    [0x021C2] = 0x17, -- harpoondownright      \downharpoonright
    [0x021BF] = 0x18, -- harpoonupleft         \upharpoonleft
    [0x021C3] = 0x19, -- harpoondownleft       \downharpoonleft
    [0x021A3] = 0x1A, -- arrowtailright        \rightarrowtail
    [0x021A2] = 0x1B, -- arrowtailleft         \leftarrowtail
    [0x021C6] = 0x1C, -- arrowparrleftright    \leftrightarrows
--  [0x021C5] = 0x00, --                       \updownarrows (missing in lm)
    [0x021C4] = 0x1D, -- arrowparrrightleft    \rightleftarrows
    [0x021B0] = 0x1E, -- shiftleft             \Lsh
    [0x021B1] = 0x1F, -- shiftright            \Rsh
    [0x021DD] = 0x20, -- squiggleright         \leadsto \rightsquigarrow
    [0x021AD] = 0x21, -- squiggleleftright     \leftrightsquigarrow
    [0x021AB] = 0x22, -- curlyleft             \looparrowleft
    [0x021AC] = 0x23, -- curlyright            \looparrowright
    [0x02257] = 0x24, -- circleequal           \circeq
    [0x0227F] = 0x25, -- followsorequal        \succsim
    [0x02273] = 0x26, -- greaterorsimilar      \gtrsim
    [0x02A86] = 0x27, -- greaterorapproxeql    \gtrapprox
    [0x022B8] = 0x28, -- multimap              \multimap
    [0x02234] = 0x29, -- therefore             \therefore
    [0x02235] = 0x2A, -- because               \because
    [0x02251] = 0x2B, -- equalsdots            \Doteq \doteqdot
    [0x0225C] = 0x2C, -- defines               \triangleq
    [0x0227E] = 0x2D, -- precedesorequal       \precsim
    [0x02272] = 0x2E, -- lessorsimilar         \lesssim
    [0x02A85] = 0x2F, -- lessorapproxeql       \lessapprox
    [0x02A95] = 0x30, -- equalorless           \eqslantless
    [0x02A96] = 0x31, -- equalorgreater        \eqslantgtr
    [0x022DE] = 0x32, -- equalorprecedes       \curlyeqprec
    [0x022DF] = 0x33, -- equalorfollows        \curlyeqsucc
    [0x0227C] = 0x34, -- precedesorcurly       \preccurlyeq
    [0x02266] = 0x35, -- lessdblequal          \leqq
    [0x02A7D] = 0x36, -- lessorequalslant      \leqslant
    [0x02276] = 0x37, -- lessorgreater         \lessgtr
    [0x02035] = 0x38, -- primereverse          \backprime
    --  [0x0] = 0x39, -- axisshort             \dabar
    [0x02253] = 0x3A, -- equaldotrightleft     \risingdotseq
    [0x02252] = 0x3B, -- equaldotleftright     \fallingdotseq
    [0x0227D] = 0x3C, -- followsorcurly        \succcurlyeq
    [0x02267] = 0x3D, -- greaterdblequal       \geqq
    [0x02A7E] = 0x3E, -- greaterorequalslant   \geqslant
    [0x02277] = 0x3F, -- greaterorless         \gtrless
    [0x0228F] = 0x40, -- squareimage           \sqsubset
    [0x02290] = 0x41, -- squareoriginal        \sqsupset
    -- wrong:
    [0x022B3] = 0x42, -- triangleright         \rhd \vartriangleright
    [0x022B2] = 0x43, -- triangleleft          \lhd \vartriangleleft
    [0x022B5] = 0x44, -- trianglerightequal    \unrhd \trianglerighteq
    [0x022B4] = 0x45, -- triangleleftequal     \unlhd \trianglelefteq
    --
    [0x02605] = 0x46, -- star                  \bigstar
    [0x0226C] = 0x47, -- between               \between
    [0x025BC] = 0x48, -- triangledownsld       \blacktriangledown
    [0x025B6] = 0x49, -- trianglerightsld      \blacktriangleright
    [0x025C0] = 0x4A, -- triangleleftsld       \blacktriangleleft
    --  [0x0] = 0x4B, -- arrowaxisright
    --  [0x0] = 0x4C, -- arrowaxisleft
    [0x025B2] = 0x4D, -- triangle              \triangleup \vartriangle
    [0x025B2] = 0x4E, -- trianglesolid         \blacktriangle
    [0x025BC] = 0x4F, -- triangleinv           \triangledown
    [0x02256] = 0x50, -- ringinequal           \eqcirc
    [0x022DA] = 0x51, -- lessequalgreater      \lesseqgtr
    [0x022DB] = 0x52, -- greaterlessequal      \gtreqless
    [0x02A8B] = 0x53, -- lessdbleqlgreater     \lesseqqgtr
    [0x02A8C] = 0x54, -- greaterdbleqlless     \gtreqqless
    [0x000A5] = 0x55, -- Yen                   \yen
    [0x021DB] = 0x56, -- arrowtripleright      \Rrightarrow
    [0x021DA] = 0x57, -- arrowtripleleft       \Lleftarrow
    [0x02713] = 0x58, -- check                 \checkmark
    [0x022BB] = 0x59, -- orunderscore          \veebar
    [0x022BC] = 0x5A, -- nand                  \barwedge
    [0x02306] = 0x5B, -- perpcorrespond        \doublebarwedge
    [0x02220] = 0x5C, -- angle                 \angle
    [0x02221] = 0x5D, -- measuredangle         \measuredangle
    [0x02222] = 0x5E, -- sphericalangle        \sphericalangle
    --  [0x0] = 0x5F, -- proportional          \varpropto
    --  [0x0] = 0x60, -- smile                 \smallsmile
    --  [0x0] = 0x61, -- frown                 \smallfrown
    [0x022D0] = 0x62, -- subsetdbl             \Subset
    [0x022D1] = 0x63, -- supersetdbl           \Supset
    [0x022D3] = 0x64, -- uniondbl              \doublecup \Cup
    [0x00100] = 0x65, -- intersectiondbl       \doublecap \Cap
    [0x022CF] = 0x66, -- uprise                \curlywedge
    [0x022CE] = 0x67, -- downfall              \curlyvee
    [0x022CB] = 0x68, -- multiopenleft         \leftthreetimes
    [0x022CC] = 0x69, -- multiopenright        \rightthreetimes
    [0x02AC5] = 0x6A, -- subsetdblequal        \subseteqq
    [0x02AC6] = 0x6B, -- supersetdblequal      \supseteqq
    [0x0224F] = 0x6C, -- difference            \bumpeq
    [0x0224E] = 0x6D, -- geomequivalent        \Bumpeq
    [0x022D8] = 0x6E, -- muchless              \lll \llless
    [0x022D9] = 0x6F, -- muchgreater           \ggg \gggtr
    [0x0231C] = 0x70, -- rightanglenw          \ulcorner
    [0x0231D] = 0x71, -- rightanglene          \urcorner
    [0x024C7] = 0x72, -- circleR               \circledR
    [0x024C8] = 0x73, -- circleS               \circledS
    [0x022D4] = 0x74, -- fork                  \pitchfork
    [0x02245] = 0x75, -- dotplus               \dotplus
    [0x0223D] = 0x76, -- revsimilar            \backsim
    [0x022CD] = 0x77, -- revasymptequal        \backsimeq -- AM: Check this! I mapped it to simeq.
    [0x0231E] = 0x78, -- rightanglesw          \llcorner
    [0x0231F] = 0x79, -- rightanglese          \lrcorner
    [0x02720] = 0x7A, -- maltesecross          \maltese
    [0x02201] = 0x7B, -- complement            \complement
    [0x022BA] = 0x7C, -- intercal              \intercal
    [0x0229A] = 0x7D, -- circlering            \circledcirc
    [0x0229B] = 0x7E, -- circleasterisk        \circledast
    [0x0229D] = 0x7F, -- circleminus           \circleddash
}

fonts.enc.math["tex-mb"] = {
    --  [0x0] = 0x00, -- lessornotequal        \lvertneqq
    --  [0x0] = 0x01, -- greaterornotequal     \gvertneqq
    [0x02270] = 0x02, -- notlessequal          \nleq
    [0x02271] = 0x03, -- notgreaterequal       \ngeq
    [0x0226E] = 0x04, -- notless               \nless
    [0x0226F] = 0x05, -- notgreater            \ngtr
    [0x02280] = 0x06, -- notprecedes           \nprec
    [0x02281] = 0x07, -- notfollows            \nsucc
    [0x02268] = 0x08, -- lessornotdbleql       \lneqq
    [0x02269] = 0x09, -- greaterornotdbleql    \gneqq
    --  [0x0] = 0x0A, -- notlessorslnteql      \nleqslant
    --  [0x0] = 0x0B, -- notgreaterorslnteql   \ngeqslant
    [0x02A87] = 0x0C, -- lessnotequal          \lneq
    [0x02A88] = 0x0D, -- greaternotequal       \gneq
    --  [0x0] = 0x0E, -- notprecedesoreql      \npreceq
    --  [0x0] = 0x0F, -- notfollowsoreql       \nsucceq
    [0x022E8] = 0x10, -- precedeornoteqvlnt    \precnsim
    [0x022E9] = 0x11, -- followornoteqvlnt     \succnsim
    [0x022E6] = 0x12, -- lessornotsimilar      \lnsim
    [0x022E7] = 0x13, -- greaterornotsimilar   \gnsim
    --  [0x0] = 0x14, -- notlessdblequal       \nleqq
    --  [0x0] = 0x15, -- notgreaterdblequal    \ngeqq
    [0x02AB5] = 0x16, -- precedenotslnteql     \precneqq
    [0x02AB6] = 0x17, -- follownotslnteql      \succneqq
    [0x02AB9] = 0x18, -- precedenotdbleqv      \precnapprox
    [0x02ABA] = 0x19, -- follownotdbleqv       \succnapprox
    [0x02A89] = 0x1A, -- lessnotdblequal       \lnapprox
    [0x02A8A] = 0x1B, -- greaternotdblequal    \gnapprox
    [0x02241] = 0x1C, -- notsimilar            \nsim
    [0x02247] = 0x1D, -- notapproxequal        \ncong
    --  [0x0] = 0x1E, -- upslope               \diagup
    --  [0x0] = 0x1F, -- downslope             \diagdown
    --  [0x0] = 0x20, -- notsubsetoreql        \varsubsetneq
    --  [0x0] = 0x21, -- notsupersetoreql      \varsupsetneq
    --  [0x0] = 0x22, -- notsubsetordbleql     \nsubseteqq
    --  [0x0] = 0x23, -- notsupersetordbleql   \nsupseteqq
    [0x02ACB] = 0x24, -- subsetornotdbleql     \subsetneqq
    [0x02ACC] = 0x25, -- supersetornotdbleql   \supsetneqq
    --  [0x0] = 0x26, -- subsetornoteql        \varsubsetneqq
    --  [0x0] = 0x27, -- supersetornoteql      \varsupsetneqq
    [0x0228A] = 0x28, -- subsetnoteql          \subsetneq
    [0x0228B] = 0x29, -- supersetnoteql        \supsetneq
    [0x02288] = 0x2A, -- notsubseteql          \nsubseteq
    [0x02289] = 0x2B, -- notsuperseteql        \nsupseteq
    [0x02226] = 0x2C, -- notparallel           \nparallel
    [0x02224] = 0x2D, -- notbar                \nmid \ndivides
    --  [0x0] = 0x2E, -- notshortbar           \nshortmid
    --  [0x0] = 0x2F, -- notshortparallel      \nshortparallel
    [0x022AC] = 0x30, -- notturnstile          \nvdash
    [0x022AE] = 0x31, -- notforces             \nVdash
    [0x022AD] = 0x32, -- notsatisfies          \nvDash
    [0x022AF] = 0x33, -- notforcesextra        \nVDash
    [0x022ED] = 0x34, -- nottriangeqlright     \ntrianglerighteq
    [0x022EC] = 0x35, -- nottriangeqlleft      \ntrianglelefteq
    [0x022EA] = 0x36, -- nottriangleleft       \ntriangleleft
    [0x022EB] = 0x37, -- nottriangleright      \ntriangleright
    [0x0219A] = 0x38, -- notarrowleft          \nleftarrow
    [0x0219B] = 0x39, -- notarrowright         \nrightarrow
    [0x021CD] = 0x3A, -- notdblarrowleft       \nLeftarrow
    [0x021CF] = 0x3B, -- notdblarrowright      \nRightarrow
    [0x021CE] = 0x3C, -- notdblarrowboth       \nLeftrightarrow
    [0x021AE] = 0x3D, -- notarrowboth          \nleftrightarrow
    [0x022C7] = 0x3E, -- dividemultiply        \divideontimes
    [0x02300] = 0x3F, -- diametersign          \varnothing
    [0x02204] = 0x40, -- notexistential        \nexists
    [0x1D538] = 0x41, -- A                     (blackboard A)
    [0x1D539] = 0x42, -- B
    [0x02102] = 0x43, -- C
    [0x1D53B] = 0x44, -- D
    [0x1D53C] = 0x45, -- E
    [0x1D53D] = 0x46, -- F
    [0x1D53E] = 0x47, -- G
    [0x0210D] = 0x48, -- H
    [0x1D540] = 0x49, -- I
    [0x1D541] = 0x4A, -- J
    [0x1D542] = 0x4B, -- K
    [0x1D543] = 0x4C, -- L
    [0x1D544] = 0x4D, -- M
    [0x02115] = 0x4E, -- N
    [0x1D546] = 0x4F, -- O
    [0x02119] = 0x50, -- P
    [0x0211A] = 0x51, -- Q
    [0x0211D] = 0x52, -- R
    [0x1D54A] = 0x53, -- S
    [0x1D54B] = 0x54, -- T
    [0x1D54C] = 0x55, -- U
    [0x1D54D] = 0x56, -- V
    [0x1D54E] = 0x57, -- W
    [0x1D54F] = 0x58, -- X
    [0x1D550] = 0x59, -- Y
    [0x02124] = 0x5A, -- Z                     (blackboard Z)
    [0x02132] = 0x60, -- hatwide               \Finv
    [0x02141] = 0x61, -- hatwider              \Game
    --  [0x0] = 0x62,    tildewide
    --  [0x0] = 0x63,    tildewider
    --  [0x0] = 0x64,    Finv
    --  [0x0] = 0x65,    Gmir
    [0x02127] = 0x66, -- Omegainv              \mho
    [0x000F0] = 0x67, -- eth                   \eth
    [0x02242] = 0x68, -- equalorsimilar        \eqsim
    [0x02136] = 0x69, -- beth                  \beth
    [0x02137] = 0x6A, -- gimel                 \gimel
    [0x02138] = 0x6B, -- daleth                \daleth
    [0x022D6] = 0x6C, -- lessdot               \lessdot
    [0x022D7] = 0x6D, -- greaterdot            \gtrdot
    [0x022C9] = 0x6E, -- multicloseleft        \ltimes
    [0x022CA] = 0x6F, -- multicloseright       \rtimes
    --  [0x0] = 0x70, -- barshort              \shortmid
    --  [0x0] = 0x71, -- parallelshort         \shortparallel
    --  [0x02216] = 0x72, -- integerdivide         \smallsetminus (2216 already part of tex-sy
    --  [0x0] = 0x73, -- similar               \thicksim
    --  [0x0] = 0x74, -- approxequal           \thickapprox
    [0x0224A] = 0x75, -- approxorequal         \approxeq
    [0x02AB8] = 0x76, -- followsorequal        \succapprox
    [0x02AB7] = 0x77, -- precedesorequal       \precapprox
    [0x021B6] = 0x78, -- archleftdown          \curvearrowleft
    [0x021B7] = 0x79, -- archrightdown         \curvearrowright
    [0x003DC] = 0x7A, -- Digamma               \digamma
    [0x003F0] = 0x7B, -- kappa                 \varkappa
    [0x1D55C] = 0x7C, -- k                     \Bbbk (blackboard k)
    [0x0210F] = 0x7D, -- planckover2pi         \hslash
    [0x00127] = 0x7E, -- planckover2pi1        \hbar
    [0x003F6] = 0x7F, -- epsiloninv            \backepsilon
}

fonts.enc.math["tex-fraktur"] = {
--  [0x1D504] = 0x41, -- A                     (fraktur A)
--  [0x1D505] = 0x42, -- B
    [0x0212D] = 0x43, -- C
--  [0x1D507] = 0x44, -- D
--  [0x1D508] = 0x45, -- E
--  [0x1D509] = 0x46, -- F
--  [0x1D50A] = 0x47, -- G
    [0x0210C] = 0x48, -- H
    [0x02111] = 0x49, -- I
--  [0x1D50D] = 0x4A, -- J
--  [0x1D50E] = 0x4B, -- K
--  [0x1D50F] = 0x4C, -- L
--  [0x1D510] = 0x4D, -- M
--  [0x1D511] = 0x4E, -- N
--  [0x1D512] = 0x4F, -- O
--  [0x1D513] = 0x50, -- P
--  [0x1D514] = 0x51, -- Q
    [0x0211C] = 0x52, -- R
--  [0x1D516] = 0x53, -- S
--  [0x1D517] = 0x54, -- T
--  [0x1D518] = 0x55, -- U
--  [0x1D519] = 0x56, -- V
--  [0x1D51A] = 0x57, -- W
--  [0x1D51B] = 0x58, -- X
--  [0x1D51C] = 0x59, -- Y
    [0x02128] = 0x5A, -- Z                     (fraktur Z)
--  [0x1D51E] = 0x61, -- a                     (fraktur a)
--  [0x1D51F] = 0x62, -- b
--  [0x1D520] = 0x63, -- c
--  [0x1D521] = 0x64, -- d
--  [0x1D522] = 0x65, -- e
--  [0x1D523] = 0x66, -- f
--  [0x1D524] = 0x67, -- g
--  [0x1D525] = 0x68, -- h
--  [0x1D526] = 0x69, -- i
--  [0x1D527] = 0x6A, -- j
--  [0x1D528] = 0x6B, -- k
--  [0x1D529] = 0x6C, -- l
--  [0x1D52A] = 0x6D, -- m
--  [0x1D52B] = 0x6E, -- n
--  [0x1D52C] = 0x6F, -- o
--  [0x1D52D] = 0x70, -- p
--  [0x1D52E] = 0x71, -- q
--  [0x1D52F] = 0x72, -- r
--  [0x1D530] = 0x73, -- s
--  [0x1D531] = 0x74, -- t
--  [0x1D532] = 0x75, -- u
--  [0x1D533] = 0x76, -- v
--  [0x1D534] = 0x77, -- w
--  [0x1D535] = 0x78, -- x
--  [0x1D536] = 0x79, -- y
--  [0x1D537] = 0x7A, -- z
}

-- now that all other vectors are defined ...

fonts.vf.math.set_letters(fonts.enc.math, "tex-mi", 0x1D434, 0x1D44E)
fonts.vf.math.set_letters(fonts.enc.math, "tex-ss", 0x1D5A0, 0x1D5BA)
fonts.vf.math.set_letters(fonts.enc.math, "tex-tt", 0x1D670, 0x1D68A)
fonts.vf.math.set_letters(fonts.enc.math, "tex-bf", 0x1D400, 0x1D41A)
fonts.vf.math.set_letters(fonts.enc.math, "tex-bi", 0x1D468, 0x1D482)
fonts.vf.math.set_letters(fonts.enc.math, "tex-fraktur", 0x1D504, 0x1D51E)
fonts.vf.math.set_letters(fonts.enc.math, "tex-fraktur-bold", 0x1D56C, 0x1D586)

fonts.vf.math.set_digits (fonts.enc.math, "tex-ss", 0x1D7E2)
fonts.vf.math.set_digits (fonts.enc.math, "tex-tt", 0x1D7F6)
fonts.vf.math.set_digits (fonts.enc.math, "tex-bf", 0x1D7CE)

-- fonts.vf.math.set_digits (fonts.enc.math, "tex-bi", 0x1D7CE)

-- todo: add ss, tt, bf etc vectors
-- we can make ss tt etc an option

-- rm-lmr5  : LMMathRoman5-Regular
-- rm-lmbx5 : LMMathRoman5-Bold          ]
-- lmbsy5   : LMMathSymbols5-BoldItalic
-- lmsy5    : LMMathSymbols5-Italic
-- lmmi5    : LMMathItalic5-Italic
-- lmmib5   : LMMathItalic5-BoldItalic

mathematics.make_font ( "lmroman5-math", {
    { name = "lmroman5-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr5.tfm", vector = "tex-mr" } ,
    { name = "lmmi5.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy5.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam5.tfm", vector = "tex-ma" },
    { name = "msbm5.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx5.tfm", vector = "tex-bf" } ,
    { name = "lmroman5-bold", vector = "tex-bf" } ,
    { name = "lmmib5.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm5.tfm", vector = "tex-fraktur", optional=true },
} )

-- rm-lmr6  : LMMathRoman6-Regular
-- rm-lmbx6 : LMMathRoman6-Bold
-- lmsy6    : LMMathSymbols6-Italic
-- lmmi6    : LMMathItalic6-Italic

mathematics.make_font ( "lmroman6-math", {
    { name = "lmroman6-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr6.tfm", vector = "tex-mr" } ,
    { name = "lmmi6.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy6.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam5.tfm", vector = "tex-ma" },
    { name = "msbm5.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx6.tfm", vector = "tex-bf" } ,
    { name = "lmroman6-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib5.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm5.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb5.tfm", vector = "tex-fraktur-bold", optional=true },
} )

-- rm-lmr7  : LMMathRoman7-Regular
-- rm-lmbx7 : LMMathRoman7-Bold
-- lmbsy7   : LMMathSymbols7-BoldItalic
-- lmsy7    : LMMathSymbols7-Italic
-- lmmi7    : LMMathItalic7-Italic
-- lmmib7   : LMMathItalic7-BoldItalic

mathematics.make_font ( "lmroman7-math", {
    { name = "lmroman7-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr7.tfm", vector = "tex-mr" } ,
    { name = "lmmi7.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy7.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam7.tfm", vector = "tex-ma" },
    { name = "msbm7.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx7.tfm", vector = "tex-bf" } ,
    { name = "lmroman7-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib7.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm7.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb7.tfm", vector = "tex-fraktur-bold", optional=true },
} )

-- rm-lmr8  : LMMathRoman8-Regular
-- rm-lmbx8 : LMMathRoman8-Bold
-- lmsy8    : LMMathSymbols8-Italic
-- lmmi8    : LMMathItalic8-Italic

mathematics.make_font ( "lmroman8-math", {
    { name = "lmroman8-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr8.tfm", vector = "tex-mr" } ,
    { name = "lmmi8.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy8.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam7.tfm", vector = "tex-ma" },
    { name = "msbm7.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx8.tfm", vector = "tex-bf" } ,
    { name = "lmroman8-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib7.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans8-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono8-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm7.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb7.tfm", vector = "tex-fraktur-bold", optional=true },
} )

-- rm-lmr9  : LMMathRoman9-Regular
-- rm-lmbx9 : LMMathRoman9-Bold
-- lmsy9    : LMMathSymbols9-Italic
-- lmmi9    : LMMathItalic9-Italic

mathematics.make_font ( "lmroman9-math", {
    { name = "lmroman9-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr9.tfm", vector = "tex-mr" } ,
    { name = "lmmi9.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy9.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx9.tfm", vector = "tex-bf" } ,
    { name = "lmroman9-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans9-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono9-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
} )

-- rm-lmr10  : LMMathRoman10-Regular
-- rm-lmbx10 : LMMathRoman10-Bold
-- lmbsy10   : LMMathSymbols10-BoldItalic
-- lmsy10    : LMMathSymbols10-Italic
-- lmex10    : LMMathExtension10-Regular
-- lmmi10    : LMMathItalic10-Italic
-- lmmib10   : LMMathItalic10-BoldItalic

mathematics.make_font ( "lmroman10-math", {
    { name = "lmroman10-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr10.tfm", vector = "tex-mr" } ,
    { name = "lmmi10.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy10.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx10.tfm", vector = "tex-bf" } ,
    { name = "lmroman10-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans10-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono10-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
} )

mathematics.make_font ( "lmroman10-boldmath", {
    { name = "lmroman10-bold.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr10.tfm", vector = "tex-mr" } ,
    { name = "lmmib10.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmbsy10.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
-- copied from roman:
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx10.tfm", vector = "tex-bf" } ,
    { name = "lmroman10-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans10-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono10-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
} )

-- rm-lmr12  : LMMathRoman12-Regular
-- rm-lmbx12 : LMMathRoman12-Bold
-- lmmi12    : LMMathItalic12-Italic

mathematics.make_font ( "lmroman12-math", {
    { name = "lmroman12-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr12.tfm", vector = "tex-mr" } ,
    { name = "lmmi12.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy10.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx12.tfm", vector = "tex-bf" } ,
    { name = "lmroman12-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans12-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono12-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
} )

-- rm-lmr17 : LMMathRoman17-Regular

mathematics.make_font ( "lmroman17-math", {
    { name = "lmroman17-regular.otf", features = "virtualmath", main = true },
 -- { name = "rm-lmr12.tfm", vector = "tex-mr" } ,
    { name = "lmmi12.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "lmsy10.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "lmex10.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
 -- { name = "rm-lmbx12.tfm", vector = "tex-bf" } ,
    { name = "lmroman12-bold.otf", vector = "tex-bf" } ,
    { name = "lmmib10.tfm", vector = "tex-bi", skewchar=0x7F } ,
    { name = "lmsans17-regular.otf", vector = "tex-ss", optional=true },
    { name = "lmmono17-regular.otf", vector = "tex-tt", optional=true },
    { name = "eufm10.tfm", vector = "tex-fraktur", optional=true },
    { name = "eufb10.tfm", vector = "tex-fraktur-bold", optional=true },
} )

-- pxr/txr messes up the accents

mathematics.make_font ( "px-math", {
    { name = "texgyrepagella-regular.otf", features = "virtualmath", main = true },
    { name = "rpxr.tfm", vector = "tex-mr" } ,
    { name = "rpxmi.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "pxsy.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "pxex.tfm", vector = "tex-ex", extension = true } ,
    { name = "pxsya.tfm", vector = "tex-ma" },
    { name = "pxsyb.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "tx-math", {
    { name = "texgyretermes-regular.otf", features = "virtualmath", main = true },
    { name = "rtxr.tfm", vector = "tex-mr" } ,
    { name = "rtxmi.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "txsy.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "txex.tfm", vector = "tex-ex", extension = true } ,
    { name = "txsya.tfm", vector = "tex-ma" },
    { name = "txsyb.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "iwona-math", {
    { name = "file:Iwona-Regular", features = "virtualmath", main = true },
    { name = "mi-iwonari.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "sy-iwonarz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "ex-iwonar.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "iwona-light-math", {
    { name = "file:IwonaLight-Regular", features = "virtualmath", main = true },
    { name = "mi-iwonali.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "sy-iwonalz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "ex-iwonal.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "iwona-medium-math", {
    { name = "file:IwonaMedium-Regular", features = "virtualmath", main = true },
    { name = "mi-iwonami.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "sy-iwonamz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "ex-iwonam.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "iwona-heavy-math", {
    { name = "file:IwonaHeavy-Regular", features = "virtualmath", main = true },
    { name = "mi-iwonahi.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "sy-iwonahz.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
    { name = "ex-iwonah.tfm", vector = "tex-ex", extension = true } ,
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
} )

-- not ok, we need adapted vectors !

mathematics.make_font ( "mathtimes-math", {
    { name = "file:texgyretermes-regular.otf", features = "virtualmath", main = true },
    { name = "mtmiz.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "mtsyn.tfm", vector = "tex-sy", skewchar=0x30, parameters = true },
    { name = "mtex.tfm", vector = "tex-ex", extension = true },
    { name = "msam10.tfm", vector = "tex-ma" },
    { name = "msbm10.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "lucida-math", {
    { name = "lbr.afm", features = "virtualmath", main = true },
    { name = "hlcrim.tfm", vector = "tex-mi", skewchar=0x7F },
    { name = "hlcry.tfm", vector = "tex-sy", skewchar=0x30, parameters = true },
    { name = "hlcrv.tfm", vector = "tex-ex", extension = true },
    { name = "hlcra.tfm", vector = "tex-ma" },
    { name = "hlcrm.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "charter-math", {
   { name = "file:bchr8a", features = "virtualmath", main = true },
-- { name = "md-chr7m.tfm", vector = "tex-mr" },
   { name = "md-chri7m.tfm", vector = "tex-mi", skewchar=0x7F },
   { name = "md-chr7y.tfm", vector = "tex-sy", skewchar=0x30, parameters = true },
   { name = "md-chr7v.tfm", vector = "tex-ex", extension = true },
   { name = "msam10.tfm", vector = "tex-ma" },
   { name = "msbm10.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "garamond-math", {
   { name = "file:ugmr8y", features = "virtualmath", main = true },
-- { name = "md-gmr7m.tfm", vector = "tex-mr" },
   { name = "md-gmri7m.tfm", vector = "tex-mi", skewchar=0x7F },
   { name = "md-gmr7y.tfm", vector = "tex-sy", skewchar=0x30, parameters = true },
   { name = "md-gmr7v.tfm", vector = "tex-ex", extension = true },
   { name = "msam10.tfm", vector = "tex-ma" },
   { name = "msbm10.tfm", vector = "tex-mb" },
} )

mathematics.make_font ( "utopia-math", {
   { name = "file:putr8y", features = "virtualmath", main = true },
-- { name = "md-utr7m.tfm", vector = "tex-mr" },
   { name = "md-utri7m.tfm", vector = "tex-mi", skewchar=0x7F },
   { name = "md-utr7y.tfm", vector = "tex-sy", skewchar=0x30, parameters = true },
   { name = "md-utr7v.tfm", vector = "tex-ex", extension = true },
   { name = "msam10.tfm", vector = "tex-ma" },
   { name = "msbm10.tfm", vector = "tex-mb" },
} )