summaryrefslogtreecommitdiff
path: root/fonts/utilities/mathinst/mathinst.lib
blob: 83f7a74b46a957810798ae486c4b433a0320fca7 (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
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
#############################################################
##
## This is the file mathinst.lib, part of the MathInst package
## (version 1.0, August, 1998) for math font 
## generation.  (Author: Alan Hoenig, ajhjj@cunyvm.cuny.edu)
##
#############################################################

#!/usr/local/bin/perl
## This is a common file containing variables and common routines
## used by all Perl modules in the MathInst package.

## Begin by setting lots of environment-like variables.
## NONE of these should end with a backslash.

$mathinstver_   = 1.0;

## Some misc constants and constructs ...

$false = 0;  # these are valid for numeric tests only.
$true  = 1;

## Now for some common routines.

## Let's get the date and time.

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$curmonth = 
  (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)[$mon];
$curday = (Sun, Mon, Tues, Wednes, Thurs, Fri, Satur)[$wday];
$mday = "0$mday" if $mday < 10;
$curdate = "$mday $curmonth $year";
$today = $curdate;
$hour = "0$hour" if $hour < 10;
$min  = "0$min" if $min < 10;
$sec = "0$sec" if $sec < 10;
$now = "$hour:$min:$sec";

## Math font parameters...

@mathinstmanifest = (
		     "mathinst",
		     "mathinst.tex",
		     "mathinst.lib",
		     "map.a2d",
		     "map.sup",
		     "mt_ihax.mtx",
		     "eu_ihax.mtx",
		     "lu_ihax.mtx",
		     "mt_iskew.mtx",
		     "eu_iskew.mtx",
		     "lu_iskew.mtx",
	             "rhax.mtx",
		     );

%mathid_ = (
  mt => "m",
  eu => "e",
  cm => "c",
  lu => "l",
  ma => "a",
);

%mathname_ = (
  mt => "MathTime",
  eu => "Euler",
  cm => "Computer Modern",
  lu => "Lucida New Math",
  ma => "Mathematica",
);

%mathxheights_ = (
  mt => 464,
  eu => 459,
  cm => 431,
  lu => 530,
  ma => 452,
);

%nfssencoding = (
        t1   => "8t",
        ot1  => "7t",
        t1x  => "9e",
        ti9  => "9d",
        ot1x => "9t",
        ot19 => "9o",
		 );
  
%bold2nfss = (
        b => "b",
        s => "sb",
        d => "db",
	      );

%reg2nfss = (
        r => "m",
        k => "bk",
        l => "l",
        m => "md",
	     );

%ital2nfss = (
        o => "sl",
        i => "it",
	      );

##############################################################################
##
## MATHTIME
##
##############################################################################

@mt_manifest = (
	  "MTSY.etx",
	  "MTMI.etx",
	  "OMLmt.etx",
	  "OMLmts.etx",
	  "OMLmtss.etx",
	  "OMSmt.etx",
	  "OMSmts.etx",
	  "OMSmtss.etx",
	  "OMXmt.etx",
	  "OT1s.etx",
	  "OT1ss.etx",
	  "accsoff.mtx",
	  "alphoff.mtx",
	  "newmtsy.mtx",
	  "newrmtmi.mtx",
	  "newmtex.mtx",
	  "noslash.mtx",
	  "numoff.mtx",
	  "regreek.mtx",
	  "unfake.mtx",
	  "xdotless.mtx",
);

## In all arrays storing font name info for math font families, 
## the first two elements contain supplier and typeface info for
## use by TDS (ignored totally by traditional systems).  The remaining
## elements contain raw font names.

@mt_fonts = (
 $masup_, $matyp_,	# math fonts---supplier and typeface
 "RMTMI", # the math italic
 "MTSY",  # the math symbols
 "MTEX",  # math extension (large operator) font
	    );

if ($mathfam_ eq "mt") {
%comment = (
    accsoff  =>	"unsets accents, operators, and uppercase Greeks",
    alphoff  =>	"unsets alphabets (U&l/c) and some metric parameters",
    dotlessj => "constructs a virtual dotless j",
    newmtsy  =>	"renames some glyphs in conformance with 8r",
    newrmtmi =>	"renames some glyphs in conformance with 8r",
    newmtex  =>	"renames some glyphs in conformance with 8r",
    noslash  =>	"unsets glyphs `less', `equal', `slash'; get from MathTime",
    numoff   =>	"discards digits",
    regreek  =>	"constructs Greek uppercase letters",
    unfake   =>	"declares some math glyphs unfakable",
    xdotless =>	"discards dotless i and j", 
    mymathit => "MathTime math italic characters",
    mymathsy => "MathTime math symbols characters",
    mymathex => "MathTime math extension (large symbols) glyphs",
	    );
}


## Here is some special purpose stuff that needs to be added to
## the beginning of the installation file.
$mt_prelude_ = <<"End_mt_prelude";

\\declareencoding{MTEX}{OMX}
\\declareencoding{MTSY}{MTSY}
\\declareencoding{MTMI}{MTMI}

\\pltomtx{MTEX}{mymathex}
\\pltomtx{MTSY}{mymathsy}
\\pltomtx{RMTMI}{mymathit}
%% \\pltomtx{cmmi10}{cmmi10}
%% \\pltomtx{cmmi7}{cmmi7}
%% \\pltomtx{cmmi5}{cmmi5}
End_mt_prelude

##############################################################################
##
## EULER
##
##############################################################################

@eu_manifest = (
  "euex.etx",
  "eufm.etx",
  "eurm.etx",
  "OMSeu.etx",
  "OMSeus.etx",
  "OMSeuss.etx",
  "OT1eu.etx",
  "OT1eus.etx",
  "OT1euss.etx",
  "eusm.etx",
  "dotlessj.mtx",
  "notequal.mtx",
  "numoff.mtx",
  "ucgrkoff.mtx",
  "upsilon.mtx",
		);
@eu_fonts = (
	     $masup_, $matyp_,	# math fonts---supplier and typeface
	     "eurm",		# math `roman'
	     "eusm",		# math symbols
	     "euex",		# math large symbols
	     "eufm",		# fraktur
	     "eurb",		# `roman' bold
	     );

if ($mathfam_ eq "eu") {
%comment = (
    dotlessj => "creates a virtual dotless j",
    notequal => "discards equal, asterisk, and plus", 
    numoff   => "discards digits",
    ucgrkoff => "discards U/C Greek letters",
    upsilon  => "renames the upsilon letter properly", 
	    );
}


## Here is some special purpose stuff that needs to be added to
## the beginning of the installation file.

$eu_prelude_ = <<"End_eu_prelude";
\\declareencoding{TEX MATH ITALIC SUBSET}{eurm}
\\declareencoding{TEX MATH SYMBOLS SUBSET}{eusm}
\\declareencoding{TEX TEXT SUBSET}{eufm}
\\declareencoding{EULER SUBSTITUTIONS ONLY}{euex}

\\pltomtx{euex10}{euex10}
\\pltomtx{eurm10}{eurm10}
\\pltomtx{eurm7}{eurm7}
\\pltomtx{eurm5}{eurm5}
\\pltomtx{eufm10}{eufm10}
\\pltomtx{eufm7}{eufm7}
\\pltomtx{eufm5}{eufm5}
\\pltomtx{eusm10}{eusm10}
\\pltomtx{eusm7}{eusm7}
\\pltomtx{eusm5}{eusm5}

End_eu_prelude

##############################################################################
##
## LUCIDA
##
##############################################################################

@lu_manifest = (
        "lbmo.etx",
        "lbma.etx",
        "lbms.etx",
        "lbme.etx",
      	"OMXlu.etx",
      	"OMLluss.etx",
	"OMLlus.etx",
      	"OMSlu.etx",
      	"OMSlus.etx",
      	"OMSluss.etx",
      	"OT1lus.etx",
      	"OT1luss.etx",
      	"alphoff.mtx",
      	"newlbme.mtx",
      	"newlbmo.mtx",
      	"newlbms.mtx",
      	"notequa.mtx",
      	"numoff.mtx",
      	"ucgrkoff.mtx",
      	"upsilon.mtx",
		);

@lu_fonts = (
	   $masup_, $matyp_,	# math fonts---supplier and typeface
	    "lbmo",
	    "lbms",
	    "lbme",
	    );

if ($mathfam_ eq "lu") {
%comment = (
    lbme     => "Lucida New Math large symbols",
    lbms     => "Lucida New Math math symbols",
    lbmo     => "Lucida New Math italics",
    dotlessj => "virtually crafts the dotless j",
    newlbme  => "renames Lucida large symbols to OT1 standard",
    newlbms  => "renames Lucida symbols to OT1 standard",
    newlbmo  => "renames Lucida italic characters to OT1 standard",
    ucgrkoff => "unsets eppercase Greek letters",
    upsilon  => "renames the upsilon letter properly", 
    notequa  => "unsets equal and plus signs",
    alphoff  => "unsets alphabets (U&l/c) and some metric parameters",
	    );
}

$lu_prelude_ = <<"End_lu_prelude";
\\declareencoding{TEX MATH ITALIC}{lbmo}
\\declareencoding{TEX MATH SYMBOLS}{lbms}
\\declareencoding{LUCIDA MATH EXTENSION}{lbme}
\\declareencoding{LUCIDA MATH ARROWS}{lbma}

\\pltomtx{lbmo}{lbmo}
\\pltomtx{lbms}{lbms}
\\pltomtx{lbme}{lbme}

End_lu_prelude

##############################################################################
##
## MATHEMATICA
##
##############################################################################

@ma_manifest = (
    "dotlessj.mtx",
    "newxht.mtx",
    "nodotles.mtx",
    "notequal.mtx",
    "ucgrkoff.mtx",
    "unfake.mtx",
);

## In all arrays storing font name info for math font families, 
## the first two elements contain supplier and typeface info for
## use by TDS (ignored totally by traditional systems).  The remaining
## elements contain raw font names.

@ma_fonts = (
 $masup_, $matyp_,	# math fonts---supplier and typeface
 "mmami",  # the math italic
 "mmasy",  # the math symbols
 "mmaex",  # math extension (large operator) font
	    );

if ($mathfam_ eq "ma") {
%comment = (
    dotlessj => "constructs a virtual dotless j",
    mmaex    => "Mathematica math extension (large symbols) glyphs",
    mmami    => "Mathematica math italic characters",
    mmasy    => "Mathematica math symbols characters",
    newxht   => "restores proper x-height to math italic font",
    nodotles => "throws Mathematica's dotless i away!",
    notequal => "discards equal, asterisk, and plus", 
    ucgrkoff => "discards U/C Greek letters",
    unfake   =>	"declares some math glyphs unfakable",
	    );
}


## Here is some special purpose stuff that needs to be added to
## the beginning of the installation file.
$ma_prelude_ = <<"End_ma_prelude";

\\declareencoding{mmaex}{OMX}
\\declareencoding{mmasy}{OMS}
\\declareencoding{mmami}{OML}

\\pltomtx{mmaex}{mmaex}
\\pltomtx{mmasy}{mmasy}
\\pltomtx{mmami}{mmami}

End_ma_prelude

##############################################################################
##
## COMMON MATERIAL FOLLOWS NOW...
##
##############################################################################

## VARIOUS COMMON SUBROUTINES

sub pv{# print variable name and value; eg &pv(font);
    local($tmp) = $_[0];
    local($var) = $$tmp;
    print "\[\$$tmp = $var\] ";
}

sub mpv{ # print multiple variable values
	    foreach $var (@_) {
		&pv($var);
	    }
	    print "\n";
	}

sub scale{# divides two numbers, multiplies by 1000, and int's it.
  local($temp) = 1000 * $_[0]/$_[1] + 0.5;
  int($temp);
}

sub smul{# scaled multiplication
  local($temp) = $_[0]/1000 * $_[1];
  int($temp);
}

sub isTDS{
  defined($texmf_);
}

sub isfile{
  -e $_[0];
}

sub isfileorlink{
  -e $_[0] or -l $_[0];
}

sub isdir{
  -d $_[0];
}

sub isvariable{
  defined($_[0]);
}

sub iscmfont{# is a fontname a Computer Modern font?
  $_[0] =~ /^cm/i;
}

sub wlog{# write to a log file only
  print LOG "$_[0]\n";
}
sub display{# print to console only
  print "$_[0]\n";
}
sub dwlog{# display on console and write to log file
  &wlog($_[0]);
  &display($_[0]);
}

sub openlog{# 
  open (LOG, ">$mathpkg_.mlg");
  &dwlog
   ("This is MathInst$mathinstver_ + Perl$], ${curday}day, $curdate $now.");
  &dwlog("Called with options $mathfam_ and $fontfam_.");
  &dwlog("This is log file $mathpkg_.mlg.");
}
sub closelog{
  close LOG;
} 

sub copy{
  die "`copy' can't find file $_[0]" unless -e $_[0];
  open(IN, $_[0]); # the source
  open(OUT, ">$_[1]"); # the target
  while (<IN>) {print OUT $_;}
  close OUT;
}

sub safecopy{# copy source to target ONLY if target doesn't exist
    if ((not -e $_[1]) and (not -e "..$sep$_[1]")) { # target doesn't exist
	&copy(@_);
    } else {
	&display("Copy operation skipped; file $_[1] already exists.");
    }
}

## Lines in map.sup look like this:
##     a autologi Autologic
##     b bitstrea Bitstream

sub getTDSsupplier{
    open (SUP, "..${sep}map.sup") or
	die "Where is supplier file map.sup?";
    while (<SUP>) {
	next if /^\#/;		# ignore comments
	last if /^$s/;		# 
    }
    ($s, $supplier, $suppliername) = split(/\s+/, $_, 3);
    $supplier;
}

## Lines in map.a2d look like
##     ac acaslon
##     ad agaramon
## We don't load in the whole file as a hash in case this unduly
## overloads certain systems.

sub getTDStypeface{
    open(ATOD, "..${sep}map.a2d") or
	die "Cannot open map.a2d";
    $directory = "unknown";
    $upperbound = $typefam; $upperbound++;
    $lowerbound = $typefam;
    while (<ATOD>) {
	next if /^\#/;		# ignore comments
	chomp $_;
	last if $_ gt $upperbound;
	next if $_ lt $lowerbound;
	($abb, $dir) = split(/ /, $_, 2);
	last if $abb eq $typefam;
    }
    close ATOD;
    $directory = $dir if $abb eq $typefam;
    if ($directory eq "unknown") {
	print "I couldn't figure out the directory for $fontfam_.\n";
	print "Help me out by typing a directory name.>> ";
	$directory = <STDIN>; chomp $directory;
	while ($directory eq "" or length $directory > 8) {
	    print "$tmp is either too long or too short.";
	    print "Enter another name please.>> ";
	    $directory = <STDIN> ; chomp $directory;
	}
    }
    $directory;
}

## This rtn takes the @missingdirlist and suggests a script for creating
## the missing directories, which are stored in @neededdirs.
$mkdir="mkdir";  # system dependent
open(SCRIPT, ">mkdirs.bat");
sub makemkdirs{
  foreach $miss (@missingdirlist) { # check each missing path
  	 $misss = "$miss$sep";
  	 $Sep = $sep;
  	 $Sep = "\\\\" if $sep eq "\\"; # special case for DOS
  	 while ($misss =~ m/$Sep/g) {
  	     if (($know_about{$`} == $false) and (not -d $`)) {
  		 print SCRIPT "$mkdir $`\n" unless $` eq "";
  		 $know_about{$`} = $true;
  	     }
  	 }
  }
  undef %know_about; # preserve resources
}

sub verifydir{
  if (not &isdir($_[0])) {
    $missingdirs++;
    push(@missingdirlist,$_[0]);
  }
}
sub verifydirs{
  local($missingdirs)=0;
  foreach $directory (@_) {
    &verifydir($directory);
  }
  if ($missingdirs == 0) {
    &display("All directories in place.");
  } else { # something rotten...
    &dwlog("Pardon me.  Some directories are not present:");
    foreach $directory (@missingdirlist) {
	&dwlog("  $directory");
    }
    &dwlog("Use `mkdirs' to create them, and rerun your installation.");
    &makemkdirs; # here's a script for missing directories
    &dwlog("Use the `mkdirs' script to create them.");
  }
}
sub checkinstallation{# checks that a file list exists in PARENT dir
  local($missing, @missinglist, @presentlist); $missing = $false;
  foreach $i (@_) {
    if (&isfile("..${sep}$i") == $false) {
	$missing = $true;
	push(@missinglist, $i);
    } else {
	push(@presentlist, $i);
    }
  }
  local($misslist) = join("\n",@missinglist);
  local($preslist) = join("\n  ",@presentlist);
  &wlog("The files ");
  &wlog("  $preslist");
  &wlog("properly located."); 
  &dwlog("Can't find \n  $misslist \nfiles...$!")
    if $missing; 
}

## Problem: bold face weights can be in any of several flavors---
## bold (b), semibold (s), or demibold (d)---and we don't which we have.  
## We have to test for all of them, stopping as soon as we find something.
## Similarly for roman-like fonts, which can actually be regular (r),
## book (k), medium (m), or light (l).  
## The following tiny routine helps make this testing faster.

sub testforfontflavor{
  local($b) = $_[0];
  $encvariant = "$lc_encoding_$famvariant";
  $nfssvar = $nfssencoding{$encvariant};
  $fullfontname = "$vf_${sep}$fontfam_$_[0]$nfssvar\.vf";
  $flavor = $b if -e $fullfontname;
  if ($flavor) { # test for matching italic...
      TYPE_SEARCH: foreach $italic_type ("i", "o") {
	  $rit = $italic_type 
	      if -e
		  "$vf_${sep}$fontfam_$flavor$italic_type$nfssvar\.vf";
	  last TYPE_SEARCH 
	      if -e "$vf_${sep}$fontfam_$flavor$italic_type$nfssvar\.vf";
      }
  }
}


sub letterheight{# gets the height of the argument
  local($ascii) = ord($_[0]); # the Ascii code of the glyph $_[0]
  ## assumes the AFM file has previously been opened
  while (<AFM>) {last if /C\s+$ascii\s;\s/;}# seeking the glyph
  $_ =~ 
    /[A-Za-z0-9\s]+;[A-Za-z0-9\s]+;[A-Za-z0-9\s]+;\sB\s[-0-9]+\s[-0-9]+\s[0-9]+\s([0-9]+)\s;/;
  $1;
}

## This next routines verifies that some text fonts exist (at least
## that their virtual fonts do) and extracts some metric info re the
## heights of letters.  (The scaling factors for later use by the
## math fonts is determined here.)

sub verifytextfont{  # eg., &verifytextfont("Roman", "r")
  $encvariant = "$lc_encoding_$famvariant";
  $nfssvar = $nfssencoding{$encvariant};
  $fullfontname = "$vf_${sep}$fontfam_$_[1]$nfssvar\.vf";
  if (&isfileorlink($fullfontname)) {
      &display("   Font $fullfontname: found.");
  } else {			# font is missing!
      &display("   Missing $_[0] $fullfontname ...$!");
      push (@missingfonts, $fullfontname);
  }
}

sub verifytextfonts{
  local($var) = "r i";# will ident the weights/shapes of fonts
  local($curfont, $fullfontname);
  ## $foundfile contains the full path and name of the fd file.  It was
  ## set by the calling routine &DoIt in file 'mathinst'.
  ## We read this file and examine the first \DeclareFontShape command
  ## in order to learn the default series.  This is usually 'm'
  ## (medium), but can be something else.  In ITC Garamond,eg, it is
  ## 'bk' (book).
  if ($foundfile) {
      open (TMP, $foundfile) || die "Where is $foundfile?"; 
      while ($_=<TMP>) {
	  next unless /\\DeclareFontShape/;
	  $_=~ /\\DeclareFontShape{.*T1}{[a-zA-Z0-9]+}{([a-z]+)}{([a-z]+)}/;
	  $thisseries=$1;
	  $thisshape=$2;
	  last;
      }
      close TMP;
  }
  &dwlog("\nNow verifying text fonts:");
  undef $flavor; # initialize variable
  foreach $variant ("r", "k", "m", "l") {
      &testforfontflavor($variant);
  	 last if $flavor;
  }
  # We also need the italic variant---italic (usually) or oblique.
  if ($flavor) {
         $rreg=$flavor;
	 &verifytextfont("Roman", "$flavor");
	 &verifytextfont("Italic", "${flavor}$rit");
  } else { # font is missing!
  	 &dwlog("    ROMAN-like fonts are all MISSING.  Find them!");
  	 push (@missingfonts, "Roman");
  }
  ## Now for bold fonts...
  undef $flavor;
  foreach $variant ("s", "b", "d") {
      &testforfontflavor($variant);
      last if $flavor;
  }
  if ($flavor) {
      $rbold=$flavor; # save this variant for later use...
      &verifytextfont("bold ($flavor)", $rbold);
      &verifytextfont("bold italic(${rbold}$rit)", "${rbold}$rit");
  } else { # font is missing...
      &display("    BOLD-like fonts are all MISSING.  Find them!");
      push (@missingfonts, "Bold");
  }
  if (defined @missingfonts) {
      &dwlog("\nThe following missing fonts NEED to be present:");
      $tmp = "  ".join("\n  ", @missingfonts);
      &dwlog("$tmp");
      &dwlog("You may wish to find them and run me again.\n");
  }
  $nfssbold = $bold2nfss{$rbold};
  &dwlog("Something wrong with the bold weight $rbold...")
      unless $nfssbold;
  &dwlog("My default NFSS weight for these fonts is $nfssbold.")
      if $flavor ne "b";
  ## Let's get some metric info we need from the roman .afm file.
  local($afmfile) = "$afm_${sep}${fontfam_}${rreg}8a.afm";
  if (&isfile($afmfile)) {# get some font info
    # we can't rely on the `xheight' info at the top of file, since
    # sometimes, as in the Bitstream fonts, these values are wrong.
    open(AFM, $afmfile) || die
	"Cannot open the file $afmfile.  Help...";
    $capheight = &letterheight("B");
    $xheight = &letterheight("x");
    close AFM;
    &dwlog("\nText font cap height: $capheight units.");
    &dwlog("Text font x-height:   $xheight units.");
    $textSF7 = &scale($ssize_,  7);
    $textSF5 = &scale($sssize_, 5);
    &dwlog("Text font scale factors:");
    &dwlog("   script:  $textSF7");
    &dwlog("   sscript: $textSF5");   
  } else {
      &dwlog("I can't find afm file $afmfile, and I desperately need help.");
  }
}

sub verifymathfonts{# verify that math fonts are in place
  local($mathname) = $mathname_{$mathfam_};
  $mathxheight = $mathxheights_{$mathfam_};
  local($fontlist) = "${mathfam_}fonts";
  &dwlog("\nNow verifying math fonts:");
  foreach $i (2.. $#$fontlist) {
      if (&isfileorlink("$tfm_${sep}$$fontlist[$i].tfm")) {
	  &dwlog("   Math font: $$fontlist[$i] found.");
      } else {			# font missing
	  &dwlog("   Math font $$fontlist[$i] MISSING!!");
	  &dwlog("   Please find and re-run me!!!");
      }
  }
  $mathSF_ = &scale($xheight, $mathxheight) unless &isvariable($mathSF_);
  $mathSF7 = &smul($textSF7, $mathSF_);
  $mathSF5 = &smul($textSF5, $mathSF_);
  &dwlog("Math font scale factors:");
  &dwlog("   text:    $mathSF_");
  &dwlog("   script:  $mathSF7");
  &dwlog("   sscript: $mathSF5");
}

## FOR SPECIAL FONTS: USERS ARE NOT ONLY RESPONSIBLE FOR PROPER NAMING
## THESE FONTS, BUT ALSO FOR PLACING THEM IN PROPER DIRECTORIES IN TDS 
## SYSTEMS.  THE SUPPLIER AND TYPEFACE DIRECTORIES SHOULD BE STORED, EG,
## IN VARIABLES LIKE $ttsup_ AND $tttyp_.

## The purpose of `verification' is basically to get the x-height of the  
## font from which to compute the scaling factor.  As a side purpose, 
## we need to make sure that the font is placed where it's supposed to 
## be.  If the font is a bitmap, we don't scale it at all.
## 
## If the font is an `8r' font (ie, it's name ends in 8r), we look to make
## sure the corresponding `8a' afm file exists, and then read it for the 
## x-heght.  If it's not 8r, we check that an afm with the identical 
## font name exists.  If it doesn't we assume it's a bitmap.
## 
## Routine `verifyspecialfont' tkes 5 parameters---a string designating
## the font type, the font name, a field to store the height of a given
## special character, the special character whose height we want (usually 
## an `x'), and the variable to hold the new scale factor.  The font types
## should be drawn from this list:
##     tt (typewriter)
##     ss (sans serif)
##     ca (calligraphy)
##     fr (fraktur)
##     bb (blackboard bold)
##     gb (Greek bold)

$specialfonttypes = "tt ss ca fr bb gb"; 
		     
## The special font is assumed installed according to 
## the Berry fontnaming scheme.
##    &verifyspecialfont("sans",$sansserif_, "x")
## IT'S THE USERS RESPONSIBILITY TO MAKE SURE NAMING, INSTALLATION,
## ETC. FOLLOW THE FONTNAME2.1 CONVENTIONS!!!!  Caveat user!

sub deduce_rawfont_from{
    local($rawfont) = $_[0];
    if ($rawfont =~ /(7t|8t|9e|9d|9t|9o)$/) {
	substr($rawfont,-2,2) = "8r";
    }
    $rawfont;
}

sub checkmapfileforafmentry{
    local($font) = $_[0];
    local($mapfilepluspath) = "$map_${sep}psfonts.map";
    open (MAP, $mapfilepluspath) or
	die "Where the heck is $mapfilepluspath?";
    while (<MAP>) {
	$font_is_scalable = $true;
	last if /$font\s+/;
	$font_is_scalable = $false;
    }
    close MAP;
}

## The routine makeafmtest checks to see that both an afm file exists
## for a special file _and_ that an entry exists for it in the map
## file.  If possible, it computes $specxheight as the height of $char.

sub makeafmtest{
    $rawfont = &deduce_rawfont_from($font);
    if ($typestyle eq "ss") { # special treatment for sans serif,
    ## since raw sans serif fonts may contain an `s' variant
	if (&isfile($pathplusafm)) { # don't make any revisions
	} else { # try these instead...
	    $pathplusafm =~ s/8a\.afm/s8a\.afm/;
	    $rawfont =~ s/r8r/rs8r/;
	}
    }
    if (&isfile($pathplusafm)) { # afm file exists
	&checkmapfileforafmentry($rawfont); # entry exist in psfonts.map?
	if ($font_is_scalable) {
	    $rawfont =~ s/8r/8a/; # points now to un-reencoded font
	    open(AFM, "$pathplusafm") or
		die "Can't open afm file $pathplusafm.";
	    $specxheight = &letterheight($char);
	    close AFM;
	}
    } else { # no afm file
	$specSF_ = 1000;
    }
}

sub deduce_afmname_from{
    local($font) = $_[0];	
    local($afm) = $font;	# default for bitmap and 8a fonts
    if ($afm =~ /8r/) {		# an 8r font
	$afm =~ s/8r/8a/;
    }
    if ($afm =~ /(7t|8t|9e|9d|9t|9o)$/) { # for fontname fonts
	$afm = substr($font,0,4) . "8a";
    }
    $afm;
}
	       
sub verifyspecialfont{
  $refheight = $xheight;
  local($typestyle, $font, $char) = @_;
  local($styleSFname) = "${typestyle}SF_";
  while (not $specialfonttypes =~ /$typestyle/) {
      print "The font type $typestyle must be one of: ";  
      print "$specialfonttypes\nPlease enter a font type>>> ";
      $typestyle = <STDIN>; chomp $typestyle;
  }
  local($myafm_, $mytfm_) = ($afm_, $tfm_);
  $font_is_scalable = $false; undef $specSF_; undef $specxheight;
  if (&isTDS) {
    local($supname, $typname) = ("${typestyle}sup_", "${typestyle}typ_");
     &dwlog(
     "WARNING ($supname): I need a TDS supplier directory for $typestyle.")
	unless $$supname;
    &dwlog(
     "WARNING ($typname): I need a TDS typeface directory for $typestyle.")
	unless $$typname;
    local($pathname) = "$$supname${sep}$$typname";
    local($postfix) = "$pathname"; 
    $myafm_ = "$texmf_${sep}fonts${sep}afm$sep$postfix";
    $mytfm_ = "$texmf_${sep}fonts${sep}tfm$sep$postfix";
  }
  ## Now to ascertain the nature of the font, and to verify the
  ## existence of the font for use by TeX.
  $afm = &deduce_afmname_from($font);
  if (not &isfile("$mytfm_$sep$font.tfm")) {# no tfm file---BAD NEWS
      &dwlog("Font $font NOT FOUND! Please install and run MathInst again.");
  } else { # font found---check for afm
      local($font_is_scalable) = $true;	# just a guess...
      local($pathplusafm) = "$myafm_$sep$afm.afm";
      &makeafmtest;
  }
  ## We need to save the tfm location for the calligraphic font.
  $ca_tfm_=$mytfm_ if $typestyle eq "ca";
  $specSF_ = 1000 if $specSF_ == 0;
  if ($specxheight) {
      $specSF_ = &scale($refheight, $specxheight);
      $$styleSFname = $specSF_ unless $$styleSFname;
      &dwlog("$typestyle font $font scale factor: $$styleSFname.");
  } else {# for non-scalable font
      &dwlog("$typestyle font $font takes natural size.");
      $$styleSFname = 1000;
  }
  $refheight = $xheight;	# reset the default
}

sub verifyspecialfonts{
    ## Verify tt font...
    &verifyspecialfont("tt", $tt_, "x") if $tt_;
    &dwlog("No tt font being installed today.") if not $tt_;
    ## Blackboard bold...
    if ($bbold_) {
	$refheight = $capheight;
	&verifyspecialfont("bb", $bbold_, "B");
    } else {	
	&dwlog("No bboard bold font being installed today.");
    }
    ## the fraktur
    &verifyspecialfont("fr", $fraktur_, "x") if $fraktur_;
    &dwlog("No fraktur font being installed today.") if not $fraktur_;
    ## the sans serif
    &verifyspecialfont("ss",$sansserif_,"x") if $sansserif_;
    &dwlog("No sans serif fonts being installed today.") if not $sansserif_;
    ## the calligraphic
    if ($cal_) {
      $refheight = $xheight;
      &verifyspecialfont("ca",$cal_,"B");
      ## Need to recompute SF because cal uses cap heights.
      $caSF7 = &smul($textSF7, $caSF_);  
      $caSF5 = &smul($textSF5, $caSF_);  
      &dwlog("Calligraphic font $cal_ scale factors:");
      &dwlog("   text:    $caSF_.");
      &dwlog("   script:  $caSF7.");
      &dwlog("   sscript: $caSF5.");
    } else {
      &dwlog("No calligraphic font being installed today.");
    }
    ## Finally, uppercase greek font (used for bold math)
    if (&isvariable($greekbold_)) {
      &verifyspecialfont("gb", $greekbold_, "x");
      $gbSF7 = &smul($textSF7, $gbSF_);# grb = Greek bold  
      $gbSF5 = &smul($textSF5, $gbSF_); 
      @gscale = (
       " scaled $gbSF_", 
       " scaled $gbSF7", 
       " scaled $gbSF5",
      );  
      &dwlog("Greek bold font $greekbold_ scale factors:");
      &dwlog("   text:    $gbSF_.");
      &dwlog("   script:  $gbSF7.");
      &dwlog("   sscript: $gbSF5.");
    } else {
      &dwlog("No Greek bold font being installed today.");
    }
}


$FH_ = "STDOUT";			# default value
sub out{# same as Out, but no automatic \n
    foreach $str (@_){
	print $FH_ $str;
    }
}
sub Out{
    &out(@_, "\n");
}

open(MAKEPL, ">makepl.bat");
print MAKEPL "echo \" \" >makepl.mlg\n"; # start things off

## makepl now needs two arguments---the source of the tfm file is the first,
## and the string giving the font name is the second.

sub makepl{# some existing tfm fonts need a pl file
  #eg., &makepl($tfm_, "mbvr7t")
  print MAKEPL "echo \"$_[1]\" >> makepl.mlg\n";
  print MAKEPL "tftopl $_[0]${sep}$_[1].tfm $_[1].pl >> makepl.mlg\n";
}

$linelength = 75; # max chars on a line
sub fancyout{
  local($tmp) = "%" x $linelength;
  &Out($tmp);
  &Out("%%");
  &Out("%%  $_[0]");
  &Out("%%");
  &Out($tmp);
}

## The format for each list of mtx files can have
## ``arguments''. A number $n$ surrounded by colons
## (eg, "this :1: is it") will have the colon'ed unit
## replaced by the appropirate argument in the called
## routine.  (Note, though, the zeroth argument is
## the format string.)  Names surrounded by angle
## brackets name the array that whose element is used
## at each font size.  For ex, if 
##   $test = "This is <a> test:1:", 
## and we call 
##   &makemtxlist($test,$wt), 
## then the text font file list becomes 
##   "This is $a[0] test$wt" 
## while the script file list
## becomes 
##   "This is $a[1] test$wt" 
## and so on.

## The addcomments routine is used by makemtxlist.  It takes a key and a
## a line.  If a hash yields a comments for the key, it is added to 
## the line, padded to the right to make a line of length $linelength
## characters.

sub addcomments{
    local($key, $line) = @_;
    chomp $line;		# get rid of newlines if any
    if ($comment{$key}) {
	local($comm) = $comment{$key};
	local($lcomm, $lline) = (length($comm), length($line));
	local($room) = $linelength - $lline;
	if ($lcomm > $room) {	# no room on line for full comment!
	    $comm = substr($comm, 0, $room);
	    $lcomm = $room;
	}
	$line = $line . " " x ($room-$lcomm) . "$comm";
    }
    $line .= "\n";
    $_[1]  = $line;
}

sub makemtxlist{
  ## Some additional comments for makemath.tex...
  $comment{"${fontfam_}${rreg}$enc"} = "the Roman glyphs";
  $comment{"${fontfam_}${rreg}$rit$enc"} = "the italic glyphs";
  $comment{"${fontfam_}$rbold$enc"} = "the boldface glyphs";
  $comment{"${fontfam_}rhax"} = "adjustments to the roman math fonts";
  $comment{"${fontfam_}ihax"} = "adjustments to the italic math glyphs";
  $comment{"${fontfam_}iskew"} = "adjustments to accents for math italics";
  $comment{"${fontfam_}${rreg}8r"} ="reencoded font supplies some characters";
  $comment{"$times_"} = "a raw Times Roman font" if $times_;
  $comment{"$greekbold_"} = "Greek boldface letters" if $greekbold_;
  $comment{"$cal_"} = "the calligraphic font" if $cal_;
  $comment{"${fontfam_}${rreg}8x"} = "the expert font contains oldstyle figs"
      if $expert;
  local($temp, $tmp);
  foreach $i (0 .. 2) {
    $mtxlist[$i] = $_[0];
    foreach $j (1 .. $#_) {# deal with all fixed arguments
	   $mtxlist[$i] =~ s/:$j:/$_[$j]/g;
    }
    $temp = $mtxlist[$i];
    while ( $temp =~ /(<([A-Za-z0-9]+)>)/ ) {# are there angle-bracketed args?
	$tmp = eval "\$$2\[$i\]";
	$temp =~ s/$1/$tmp/;
    }
    $temp =~ s/,/,\%\n    /g;	# make the list multiline
    $temp = "\%\n    $temp\%\n  ";# add initial and final newlines
    local(@pieces) = split(/\n/, $temp);
    $temp = "";			# initialize
    foreach $piece (@pieces) {
	$piece =~ /\s+([A-Za-z0-9]+)[ ,\%]+/;
	&addcomments($1, $piece);
	$temp .= "$piece";
    }
    chomp $temp;
    $mtxlist[$i] = $temp;
  }
}

## The fontinst install commands need encoding files.  Sometimes, we'll
## use the defaults, but other times, we'll need special variations on 
## the default.  As an example, consider OML.  If OML*.etx are not 
## part of the manifest, we can assume the default is sufficient.  On
## the other hand, if there are 2 members, say OMLs.etx and OMLss.etx, 
## it is clear that we use OML for text, OMLs for script, and OMLss for 
## scriptscript.  If there are 3 members, OMLmt, OMLmts, and OMLmtss, 
## then these 3 get applied to the text, script, and scriptscript
## fonts.  We use the routine getetx to do the decision work for us.
## The results are stored in the array @etx_ (that is, $etx_[0], etc).  
## Ex:  &getetx("OML",*EUmanifest);

sub getetx{
  @etx_ = ($_[0], $_[0], $_[0]); # default values
  local(*tmp) = $_[1];
  local(@temp);
  foreach $i (0 .. $#tmp)  {
     if ($tmp[$i] =~ /$_[0]/) {
	 $tmp[$i] =~ s/(.+)\.etx$/$1/; # strip off file extension
	 push(@temp, $tmp[$i]);
     }
  }
  @temp = sort @temp;
  if ($#temp == 0) {# the case @temp has a single element
    @etx_ = ($temp[0], $temp[0], $temp[0]);
  }
  if ($#temp == 1) {# the case @temp has 2 members
    @etx_ = ($_[0],$temp[0], $temp[1]);
  }
  if ($#temp == 2) {# the case @temp has 3 members
    @etx_ = @temp;
  }
}

## The get_special_tfm routine takes a short string like "ma", "tt", etc
## and determines the source.  Use it as a function: 
##     $math_tfm_ = &get_special_tfm("ma");

sub get_special_tfm{
    local($spec_sup_, $spec_typ_);
    local($spec_tfm_)=$tfm_;	# default; non-TDS system
    if (&isTDS) {
	($spec_sup_, $spec_typ_)=("$_[0]sup_", "$_[0]typ_");
	$spec_tfm_=
          "$texmf_${sep}fonts${sep}tfm$sep$$spec_sup_$sep$$spec_typ_";
    }
    $spec_tfm_;
}

sub make_mt_math{# make the MathTime install file
  ## Set up convenient variables...
  $tmp = "${mathfam_}_fonts";
  ($mathital, $mathsym, $mathext) = @$tmp[2,3,4];
  $reencodedfont = $fontfam_ . "${rreg}8r";
  $rawfont       = $fontfam_ . "${rreg}8a";
  #$rreg = "r"; 
  $wt = $rreg; # the font's weight
  $comment{"RMTMI"} = "MathTime raw math italic font"; 
  $comment{"MTMI"} = "MathTime math italic font"; 
  $comment{"MTSY"} = "MathTime math symbols font";
  $comment{"MTEX"} = "MathTime math extension font"; 
  $comment{"cmmi10"} = $comment{"cmmi7"} = $comment{"cmmi5"} = 
      "Computer Modern math italic (for O/S figs)";
  local(@myexp);
  # is an expert font available for oldstyle digits?
  $expert = $false;
  $expfont = "${fontfam_}r8x";
  $pathplusexpfont = "$afm_${sep}$expfont.afm";
  $expert = $true if &isfile($pathplusexpfont);
  $myexp[0] = $myexp[1] = $myexp[2] = ""; 
  @myexp = ("$expfont","$expfont scaled $textSF7","$expfont scaled $textSF5") 
      if $expert;
  $math_tfm_=&get_special_tfm("ma");
  $gb_tfm_=&get_special_tfm("gb");
  $ca_tfm_=&get_special_tfm("ca");
  $expert_font=$false; # no expert Roman font (default value)
  $expert_font=$true if &isfile("$afm_${sep}${fontfam_}r8x.afm");
  print MAKEPL "$cp $afm_${sep}${fontfam_}${rreg}8a.afm .\n"; # local copy
  print MAKEPL "$cp $afm_${sep}${fontfam_}${rreg}8x.afm .\n" # expert font 
      if $expert_font; # if it exists...
  &makepl($math_tfm_, "$mathital");
  &makepl($math_tfm_, "$mathsym");
  &makepl($math_tfm_, "$mathext");
  &makepl($tfm_, "${fontfam_}$wt${enc}");
  &makepl($tfm_, "${fontfam_}${wt}$rit${enc}");
  if ($expert) {
      ## &makepl($tfm_, "${fontfam_}${wt}8x");
  } else { 
      $cmtfmplace = $tfm_; # for traditional systems
      if (&isTDS) {
	  $cmtfmplace = "$texmf_${sep}fonts${sep}tfm${sep}public${sep}cm";
      }
      &makepl($cmtfmplace, "cmmi10");
      &makepl($cmtfmplace, "cmmi7");
      &makepl($cmtfmplace, "cmmi5");
  }  
  if (&isvariable($greekbold_)) {
      &makepl($gb_tfm_, "$greekbold_"); # pl for greek font
      &makepl($tfm_, "${fontfam_}$rbold${enc}"); # pl for matching bold
  }
  #&makepl($gb_tfm_, "${fontfam_}$rbold${enc}") if &isvariable($greekbold_);
  &makepl($ca_tfm_, $cal_) if $cal_; 
  local(@mtxlist,$romanmtx,$boldmtx,$italicmtx,$symbolmtx); # the mtx lists
  @msize = (10,7,5); 
  @mscale = (# math scale factors
    " scaled $mathSF_",
    " scaled $mathSF7",
    " scaled $mathSF5",
  );
  @tscale = (# text scale factors
    "",
    " scaled $textSF7",
    " scaled $textSF5",
  );
  @calscale = (# Calligraphic scaling info
    " scaled $caSF_",
    " scaled $caSF7",
    " scaled $caSF5",
  );
## MATH EXTENSION
  $exmtx = "mymathex<mscale>,newmtex";
## MATH ROMAN
  $romanmtx = "${fontfam_}:1:${enc}<tscale>,accsoff,mymathit<mscale>,";
  $romanmtx .= "mymathsy<mscale>,${fontfam_}rhax,regreek,";
  $romanmtx .= "numoff,$times_<mscale>," if &isvariable($times_);
  $romanmtx .= "unfake";
## MATH BOLD (only if a greek bold font exists)
  $boldmtx = "${fontfam_}:1:${enc}<tscale>,accsoff,$greekbold_<tscale>,";
  $boldmtx .= "mymathit<mscale>,mymathsy<mscale>,";
  $boldmtx .= "${fontfam_}rhax,unfake";
## MATH ITALIC
  $italicmtx = "${fontfam_}iskew,mymathit<mscale>,newrmtmi,alphoff,";
  $italicmtx .= "${fontfam_}:1:$rit${enc}<tscale>,";
  #$italicmtx .= "<myexp>," if $expert;
  if ($expert) { # use expert fonts for oldstyle figs (preferable)
      $italicmtx .= "<myexp>,";
  } else { # no choice---get OSF from cmmi<nn>
      $italicmtx .= "cmmi<msize><mscale>,";
  }
  $italicmtx .= "mymathsy<mscale>,dotlessj,${fontfam_}ihax";
## MATH SYMBOL
  $symbolmtx = "mymathsy<mscale>,newmtsy,${fontfam_}:1:8r<tscale>,";
  $symbolmtx = "${symbolmtx}alphoff,$cal_<calscale>";
  &makemakemath;
}

sub make_eu_math{
  $tmp = "${mathfam_}_fonts";
  ($mathital, $mathsym, $mathext, $mathfrak, $mathitalb) = @$tmp[2,3,4,5,6];
  $comment{"euex10"} = "Euler large operators";
  $comment{"cmex10"} = "Computer Modern large operators";
  $comment{"eurm10"} = $comment{"eurm7"} = $comment{"eurm5"} = 
      "Euler math `italic'";
  $comment{"eusm10"} = $comment{"eusm7"} = $comment{"eusm5"} = 
      "Euler math symbols";
  $comment{"eufm10"} = $comment{"eufm7"} = $comment{"eufm5"} = 
      "Euler math fraktur";
  $comment{"eurb10"} = $comment{"eurb7"} = $comment{"eurb5"} = 
      "Euler bold math `italic'";
  $comment{"cmmi10"} = $comment{"cmmi7"} = $comment{"cmmi5"} = 
      "Computer Modern math italic";
  $comment{"cmsy10"} = $comment{"cmsy7"} = $comment{"cmsy5"} = 
      "Computer Modern math symbols";
  $comment{"cmr10"} = $comment{"cmr7"} = $comment{"cmr5"} = 
      "Computer Modern Roman font";
  $comment{"harpoons"}="renames harpoon characters";
  $comment{"euexs"}="renames some ext glyphs to agree with OMX encoding";
  $comment{"eusyms"}="renames some symbol glyphs to agree with OMS encoding";
  $reencodedfont = $fontfam_ . "${rreg}8r";
  $rawfont       = $fontfam_ . "${rreg}8a";
  $wt = $rreg; # the font's weight
  local(@myexp);
  # is an expert font available for oldstyle digits?
  $expert = $false;
  $expfont = $fontfam_ . "r8x";
  $fullexpfont = "$afm_${sep}$expfont.afm";
  $expert = $true if &isfile($fullexpfont);
  $myexp[0] = ""; $myexp[1] = ""; $myexp[2] = ""; 
  $myexp[0] = "$expfont" if $expert == $true;
  $myexp[1] = "$expfont scaled $textSF7" if $expert == $true;
  $myexp[2] = "$expfont scaled $textSF5" if $expert == $true;
  &makepl($tfm_, "${fontfam_}$wt${enc}");
  &makepl($tfm_, "${fontfam_}${wt}$rit${enc}");
  ## we use $italb for Greek bold, no matter what was set in eu.par...
  $greekbold_ = $italb;
  &makepl($tfm_, "${fontfam_}$rbold${enc}") if $greekbold_;
  $cmtfmplace = $eutfmplace = $tfm_; # for traditional systems
  if (&isTDS) {
      $cmtfmplace = "$texmf_${sep}fonts${sep}tfm${sep}public${sep}cm";
      $eutfmplace = "$texmf_${sep}fonts${sep}tfm${sep}ams${sep}euler";
  }
  $savetfm_ = $tfm_;
  foreach $i ("10", "7", "5") {
    $tfm_ = $cmtfmplace;
    &makepl($tfm_, "cmr$i");
    &makepl($tfm_, "cmmi$i");
    &makepl($tfm_, "cmsy$i");
    $tfm_=$eutfmplace;
    &makepl($tfm_, "eurm$i");
    &makepl($tfm_, "eurb$i");
    &makepl($tfm_, "eufm$i");
    &makepl($tfm_, "eusm$i");
  }
  $tfm_=$eutfmplace;
  &makepl($tfm_, "euex10");
  $tfm_=$cmtfmplace;
  &makepl($tfm_, "cmex10");
  $ca_tfm_=&get_special_tfm("ca");
  &makepl($ca_tfm_, $cal_) if $cal_;
  $tfm_ = $savetfm_;		# restore default (if any)
  local(@mtxlist,$romanmtx,$boldmtx,$italicmtx,$symbolmtx); # the mtx lists
  local(@msize) = (10,7,5); 
  @mscale = (# math scale factors
    " scaled $mathSF_",
    " scaled $mathSF7",
    " scaled $mathSF5",
  );
  @tscale = (# text scale factors
    "",
    " scaled $textSF7",
    " scaled $textSF5",
  );
  @calscale = (# Calligraphic scaling info
    " scaled $calSF_",
    " scaled $calSF7",
    " scaled $calSF5",
  );
  $exmtx = "$mathext<msize><mscale>,cmex<msize><mscale>,euexs";
## MATH ROMAN
  $romanmtx = "${fontfam_}:1:${enc}<tscale>,dotlessj,notequal,ucgrkoff,";
  $romanmtx = "${romanmtx}numoff,$mathital<msize><mscale>,upsilon,";
  $romanmtx = "${romanmtx}cmr<msize><mscale>,${fontfam_}rhax";
## MATH BOLD (only if a greek bold font exists)
  $boldmtx = "${fontfam_}:1:${enc}<tscale>,dotlessj,notequal,ucgrkoff,";
  $boldmtx = "${boldmtx}numoff,$mathitalb<msize><mscale>,upsilon,";
  $boldmtx = "${boldmtx}cmr<msize><mscale>,${fontfam_}rhax";
## MATH ITALIC
  $italicmtx = "${fontfam_}iskew,$mathital<msize><mscale>,upsilon,";
  $italicmtx = "${italicmtx}$mathfrak<msize><mscale>,cmmi<msize><mscale>,";
  $italicmtx = "${italicmtx}harpoons,${fontfam_}ihax";
## MATH SYMBOL
  $symbolmtx = "$mathsym<msize><mscale>,cmsy<msize><mscale>,eusyms";
  &makemakemath;
}

sub make_lu_math{
  ## Set up convenient variables...
  $tmp = "${mathfam_}_fonts";
  ($mathital, $mathsym, $mathext) = @$tmp[2,3,4];
  $reencodedfont = $fontfam_ . "${rreg}8r";
  $rawfont       = $fontfam_ . "${rreg}8a";
  #$rreg = "r"; 
  $wt = $rreg; # the font's weight
  local(@myexp);
  # is an expert font available for oldstyle digits?
  $expert = $false;
  $expfont = "${fontfam_}r8x";
  $fullexpfont = "$afm_${sep}$expfont.afm";
  $expert = $true if &isfile($fullexpfont);
  $myexp[0] = $myexp[1] = $myexp[2] = ""; 
  @myexp = ("$expfont", "$expfont scaled $textSF7", "$expfont scaled $textSF5")
      if $expert;
  $math_tfm_=&get_special_tfm("ma");	
  $gb_tfm_=&get_special_tfm("gb");
  &makepl($math_tfm_, "$mathext");
  &makepl($math_tfm_, "$mathsym");
  &makepl($math_tfm_, "$mathital");
  &makepl($tfm_, "${fontfam_}$wt${enc}");
  &makepl($tfm_, "${fontfam_}${wt}$rit${enc}");
  &makepl($gb_tfm_, "${fontfam_}$rbold${enc}") if &isvariable($greekbold_);
  local(@mtxlist,$exmtx,$romanmtx,$boldmtx,$italicmtx,$symbolmtx); 
    # the mtx lists
  local(@msize) = (10,7,5); 
  @mscale = (# math scale factors
    " scaled $mathSF_",
    " scaled $mathSF7",
    " scaled $mathSF5",
  );
  @tscale = (# text scale factors
    "",
    " scaled $textSF7",
    " scaled $textSF5",
  );
  @calscale = (# Calligraphic scaling info
    " scaled $calSF_",
    " scaled $calSF7",
    " scaled $calSF5",
	       );
## MATH EXTENSION
  $exmtx = "$mathext<mscale>,newlbme";
## MATH ROMAN
  $romanmtx = 
      "${fontfam_}:1:${enc}<tscale>,dotlessj,ucgrkoff,$mathext<mscale>,";
  $romanmtx .= "upsilon,notequa,$mathsym<mscale>,newlbms,${fontfam_}rhax";
## No Math Bold in Lucida...
  undef $greekbold_;		# just in case...
## MATH ITALIC
  $italicmtx = "${fontfam_}iskew,$mathital<mscale>,newlbmo,upsilon,alphoff,";
  $italicmtx .= "${fontfam_}:1:$rit${enc}<tscale>,dotlessj,${fontfam_}ihax";
## MATH SYMBOL
  $symbolmtx = "$mathsym<mscale>,newlbms";
  &makemakemath;
}

sub make_ma_math{# make the Mathematica install file
  ## Set up convenient variables...
  $tmp = "${mathfam_}_fonts";
  ($mathital, $mathsym, $mathext) = @$tmp[2,3,4];
  $reencodedfont = $fontfam_ . "${rreg}8r";
  $rawfont       = $fontfam_ . "${rreg}8a";
  #$rreg = "r"; 
  $wt = $rreg; # the font's weight
  local(@myexp);
  # is an expert font available for oldstyle digits?
  $expert = $false;
  $expfont = "${fontfam_}r8x";
  $pathplusexpfont = "$afm_${sep}$expfont.afm";
  $expert = $true if &isfile($pathplusexpfont);
  $myexp[0] = $myexp[1] = $myexp[2] = ""; 
  @myexp = ("$expfont", "$expfont scaled $textSF7", "$expfont scaled $textSF5")
      if $expert;	
  $math_tfm_=&get_special_tfm("ma");
  $gb_tfm_=&get_special_tfm("gb");
  $ca_tfm_=&get_special_tfm("ca");
  $cm_tfm_=$tfm_;
  $cm_tfm_="$texmf_${sep}fonts${sep}tfm${sep}public${sep}cm" if &isTDS;
  &makepl($math_tfm_, "$mathital");
  &makepl($math_tfm_, "$mathsym");
  &makepl($math_tfm_, "$mathext");
  &makepl($math_tfm_, "mmamio");
  &makepl($cm_tfm_, "cmex10");
  &makepl($tfm_, "${fontfam_}$wt${enc}");
  &makepl($tfm_, "${fontfam_}${wt}$rit${enc}");
  &makepl($tfm_, "${fontfam_}${wt}8x") if $expert;
  if (not $expert) { # if non-experts, pluck OSF from these fonts...
      &makepl($cm_tfm_, "cmmi10");
      &makepl($cm_tfm_, "cmmi7");
      &makepl($cm_tfm_, "cmmi5");
  }
  if (&isvariable($greekbold_)) {
      &makepl($tfm_, "${fontfam_}$rbold${enc}");
      &makepl($gb_tfm_, $greekbold_); 
      &makepl($math_tfm_, "mmamib");
  }
  &makepl($ca_tfm_, $cal_) if $cal_;
  local(@mtxlist,$romanmtx,$boldmtx,$italicmtx,$symbolmtx); # the mtx lists
  @msize = (10,7,5); # canonical math sizes
  @mscale = ( # math scale factors
    " scaled $mathSF_",
    " scaled $mathSF7",
    " scaled $mathSF5",
  );
  @tscale = ( # text scale factors
    "",
    " scaled $textSF7",
    " scaled $textSF5",
  );
  @calscale = ( # Calligraphic scaling info
    " scaled $caSF_",
    " scaled $caSF7",
    " scaled $caSF5",
  );
  $comment{"mmamio"} = "obliqued math italic for UC Greek letters";
  $comment{"cmex10"} = "get some symbols from CM large symbols font";
  $comment{"cmmi10"} = $comment{"cmmi7"} = $comment{"cmmi5"} = 
      "Computer Modern math italic (for O/S figs)";
  $comment{"mma1"}   = "need a few symbols from the raw Mathematica font";
  $comment{"mmagrb"} = "Mathematica's bold greek letters";
  $comment{"mmamib"} = "Mathematica's bold math italic";
## MATH EXTENSION
  $exmtx = "mmaex<mscale>,cmex10";
## MATH ROMAN
  $romanmtx = "${fontfam_}:1:${enc}<tscale>,ucgrkoff,notequal,";
  $romanmtx .= "mma1<mscale>,mmami<mscale>,${fontfam_}rhax,";
  $romanmtx .= "numoff,$times_<mscale>," if &isvariable($times_);
  $romanmtx .= "dotlessj,unfake";
## MATH BOLD (only if a greek bold font exists)
  $boldmtx = "${fontfam_}:1:${enc}<tscale>,$greekbold_<tscale>,";
  $boldmtx .= "mmamib<mscale>,";
  $boldmtx .= "${fontfam_}rhax,unfake";
## MATH ITALIC
  $italicmtx = "${fontfam_}iskew,mmami<mscale>,nodotles,";
  $italicmtx .= "${fontfam_}:1:$rit${enc}<tscale>,ucgrkoff,mmamio,";
  $italicmtx .= "<myexp>," if $expert;
  $italicmtx .= "cmmi<msize><mscale>," unless $expert;
  $italicmtx .= "newxht,dotlessj,${fontfam_}ihax";
## MATH SYMBOL
  $symbolmtx = "mmasy<mscale>,$cal_<calscale>";
  &makemakemath;
}

## We include the possibility of 3 hooks.  Anything to be added
## at the begining of the makemath file (after \input fontinst.sty
## but before the \installfonts command) should be stored in 
## a variable called $prelude_.  Anything to be included at the end
## of the file, after \endinstallfonts but before \bye, should
## be in a variable called $postlude_.  If the extension font needs to 
## be generated, create the variable $EX_ with the proper commands.
## If these variables don't exist, nothing will be done.

sub makemakemath{
  $FH_ = "MAKEMATH";
  ## Prelims...
  &Out("%\&plain\n");
  &fancyout("This is the file makemath.tex.");
  &Out(" ");
  &Out("% Created by MathInst$mathinstver_ on ${curday}day, $today, at $now.");
  &Out("THIS FILE MAY BE DELETED.");
  &Out("\n\\input fontinst.sty\n");
  local($tmp, $curprelude); $tmp = "${mathfam_}_prelude_"; 
  $curprelude = $$tmp;
  &Out($curprelude) if $curprelude;
  $tmp = "${mathfam_}_postlude_"; 
  local($curpostlude) = $$tmp;
  ## We need a raw font for some operators, etc...
  &out("\\transformfont{$reencodedfont}{\\reencodefont{8r}");
    &Out("{\\fromafm{$rawfont}}}");
  if ($expert) {
      &Out("\\afmtomtx{${fontfam_}r8x}{${fontfam_}r8x}\n");
  }
  &Out("\\installfonts");
## MATH EXTENSION
  &fancyout("MATH EXTENSION");
  &makemtxlist($exmtx);
  &getetx("OMX", *thismanifest);
  &Out("  \\installfamily{OMX}{$shortmathpkg_}{}");
  &Out("  \\installfont{${fontfam_}$wt${mathid}7v}",
    "{$mtxlist[0]}{$etx_[0]}{OMX}{$shortmathpkg_}{m}{n}{}");
## MATH ROMAN
  &makemtxlist($romanmtx,"$rreg");
  &fancyout("MATH ROMAN");
  &Out("  \\installfamily{$mathencoding_}{$shortmathpkg_}{}");
## Math Roman 10pt (text size)
  &getetx($mathencoding_, *thismanifest);
  &Out("  \\installfont{${fontfam_}$wt${mathid}7t}",
    "{$mtxlist[0]}{$etx_[0]}",
    "{$mathencoding_}{$shortmathpkg_}{m}{n}{<8->}");
## Math Roman 7pt (script size)
  &Out("  \\installfont{${fontfam_}$wt${mathid}7t7}",
    "{$mtxlist[1]}{$etx_[1]}",
    "{$mathencoding_}{$shortmathpkg_}{m}{n}{<6-8>}");
## Math Roman 5pt (scriptscript size)
  &Out("  \\installfont{${fontfam_}$wt${mathid}7t5}",
    "{$mtxlist[2]}{$etx_[2]}",
    "{$mathencoding_}{$shortmathpkg_}{m}{n}{<-6>}");  
  ## MATH BOLD?  Only if a greek uppercase font exists...
  if ($greekbold_) {
    &makemtxlist($boldmtx,$rbold);
    ## Math bold10pt (text size)
    &fancyout("MATH BOLD");
    &Out("  \\installfont{${fontfam_}${rbold}${mathid}7t}",
    "{$mtxlist[0]}{$etx_[0]}{$mathencoding_}",
    "{$shortmathpkg_}{${nfssbold}}{n}{<8->}");
    ## Math bold 7pt (script size)
    &Out("  \\installfont{${fontfam_}${rbold}${mathid}7t7}",
    "{$mtxlist[1]}",
    "{$etx_[1]}{$mathencoding_}{$shortmathpkg_}",
    "{${nfssbold}}{n}{<6-8>}");
    ## Math bold 5pt (scriptscript size)
    &Out("  \\installfont{${fontfam_}${rbold}${mathid}7t5}",
    "{$mtxlist[2]}{$etx_[2]}",
    "{$mathencoding_}{$shortmathpkg_}{${nfssbold}}{n}{<-6>}");
  }
## MATH ITALIC
  &makemtxlist($italicmtx,$rreg);
  &getetx("OML", *thismanifest);
  &fancyout("MATH ITALIC");
  &Out("\\installfamily{OML}{$shortmathpkg_}{\\skewchar\\font=127}");
## Math Italic 10pt
  &Out("  \\installfont{${fontfam_}$wt${mathid}7m}{$mtxlist[0]}",
  "{$etx_[0]}{OML}{$shortmathpkg_}",
  "{m}{it}{<8->}");
## Math Italic 7pt
  &Out("  \\installfont{${fontfam_}$wt${mathid}7m7}",
  "{$mtxlist[1]}",
  "{$etx_[1]}{OML}{$shortmathpkg_}",
  "{m}{it}{<6-8>}");
## Math Italic 5pt
  &Out("  \\installfont{${fontfam_}$wt${mathid}7m5}",
  "{$mtxlist[2]}",
  "{$etx_[2]}{OML}{$shortmathpkg_}",
  "{m}{it}{<-6>}");
## MATH SYMBOL
  &fancyout("MATH SYMBOLS");
  &makemtxlist($symbolmtx,$rreg);
  &getetx("OMS", *thismanifest);
  &Out("\\installfamily{OMS}{$shortmathpkg_}{\\skewchar\\font=48}");
## Mathsymbol 10pt
  &Out("  \\installfont{${fontfam_}$wt${mathid}7y}",
  "{$mtxlist[0]}{$etx_[0]}{OMS}{$shortmathpkg_}{m}{n}{<8->}");
## Mathsymbol 7pt
  &Out("  \\installfont{${fontfam_}$wt${mathid}7y7}",
  "{$mtxlist[1]}{$etx_[1]}{OMS}{$shortmathpkg_}{m}{n}{<6-8>}");
## Mathsymbol 5pt
  &Out("  \\installfont{${fontfam_}$wt${mathid}7y5}",
  "{$mtxlist[2]}{$etx_[2]}{OMS}{$shortmathpkg_}{m}{n}{<-6>}\n",
  "\\endinstallfonts\n");
## Winding down...
  &Out($curpostlude) if $curpostlude;
  &Out("\\bye");  
}

sub makevf{
  $FH_ = "GETVF";
  local($prefix) = "${fontfam_}${rreg}${mathid}7";
  local($mlg) = " > makevf.mlg";
  &Out("echo \"${prefix}\"v$mlg"); 
  local($mlg) = " >> makevf.mlg";
  &Out("vptovf ${prefix}v.vpl ${prefix}v.vf ${prefix}v.tfm$mlg\n");
  foreach $i ("t", "m", "y") {# text, italic, symbols
    foreach $j ("", "7", "5") {
        &Out("echo \"$prefix$i$j\" $mlg");
	&Out("vptovf $prefix$i$j.vpl $prefix$i$j.vf $prefix$i$j.tfm$mlg");
    }
    &Out("");
  }
  if ($greekbold_) {# greek bold math font?
    local($font_) = "${fontfam_}${rbold}${mathid}7t";
    &Out("echo \"${font_}\"$mlg");
    &Out("vptovf $font_.vpl $font_.vf $font_.tfm$mlg");
    &Out("echo \"${font_}7\"$mlg");
    &Out("vptovf ${font_}7.vpl ${font_}7.vf ${font_}7.tfm$mlg");
    &Out("echo \"${font_}5\"$mlg");
    &Out("vptovf ${font_}5.vpl ${font_}5.vf ${font_}5.tfm$mlg");
  }
}

## This routine reads an fd file and discards comments, the `\endinput' 
## statement, and the `\ProvidesPackage' statement.  It adds font scaling
## info specified as an argument to the routine into all 
## `\DeclareFontShape' statements.  One catch: scaling info may have
## been placed in the fd file by fontinst, so we want to catch this and
## replace it by our current scaling factor.

sub get_fd_info_and_scale_it{
    local($fdfile, $mysize) = @_;
    local($pathandfdfile) = "$inputs_${sep}$fdfile.fd";
    open(FD, $pathandfdfile) or die "Can't find $pathandfdfile.  Help";
    while (<FD>) {		# skips comments and ProvidesPackage
	last if /\\DeclareFontFamily/;
    }
    &Out("\n%% Extracting font info from file $fdfile.fd...");
    FDLINE: for (;;) {
	if ( $_ =~ /\[\d*\.\d+\]/ ) { # scaling factor found!
	    $_ =~ s/\[\d*\.\d+\]/\[$mysize\]/g;
	} else {		# no s.f. found
	    s/(>\s*)([^<\s])/\1\[$mysize\] \2/g; # AH 21 Mar 97
	}
	&out("$_") unless /^%/;	# ignore comments
	last FDLINE if eof(FD);
	$_ = <FD>;
	last FDLINE if /\\endinput/;
    }
    &Out("%% End of file $fdfile.fd.\n");
    close FD;
}

## Sometimes, we have a font name from which we want to deduce the
## fd file which describes it.  This next routine helps.

sub deduce_fdfile_from{
    local($fam) = substr($_[0],0,3);
    local($fdname) = "${encoding_}$fam";
    $fdname;
}

## We often need the NFSS family from a font name.  If it ends in 7t, 8t, 
## 9e,9d, 9t, 90, then the first 3 chars are the family.  Otherwise,
## replace all digits by nulls  (cmtt10 --> cmtt)

sub deduce_fontfam_from{
    local($spfont) = $_[0]; local($fontfam);
    if ($spfont =~ /(7t|8t|9e|9d|9t|9o)$/) { # a fontname font
	$fontfam = substr($spfont,0,3);
    } else {			# a bitmap font
	$fontfam = $spfont;
	$fontfam =~ s/\d+//;	# eliminate all digits
    }
    $fontfam;
}

## The plain macros use the next routine to get the four members
## (up, up italic, bold, bold italic) of the sansserif.

sub deduce_family_members_from_font{
    local($spfont) = $_[0]; local($r,$ri,$b,$bi,$fam,$end);
    local($tfmplace) = $tfm_;
    if ( $spfont =~ /(8a|8r|7t|8t|9e|9d|9t|9o)$/ ) { # a fontname font
	$fam = $`; chop $fam;
	$end = $&;
	$tfmplace = "$texmf_${sep}fonts${sep}tfm$sep$sssup_$sep$sstyp_" 
	    if &isTDS;
	$r = $spfont;
        $ri = "${fam}ro$&"; # default is oblique
	$ri = "${fam}ri$&" if -e "$tfmplace${sep}${fam}ri$&\.tfm";
        $b = $r; $bi = $ri; # defaults: bold are same as regular
	$b = "${fam}b$&" if -e "$tfmplace${sep}${fam}b$&\.tfm";
	$bi  = "${fam}bi$&" if -e "$tfmplace${sep}${fam}bi$&\.tfm";
    } else {			# cm, bitmap font
	$fam = $spfont;
	$fam =~ s/(\d+)$//;
	$r = "$spfont";
	$ri = "${fam}i$&";
	$b = "${fam}b$&";
	$bi = "${fam}bi$&";
    }
    ($r, $ri, $b, $bi);
}

sub makelatexstyle{
  $fontfamx_ = $fontfam_; 
  $fontfamx_ = "${fontfam_}x" 
    if &isfile("$inputs_/$mathencoding_${fontfam_}x.fd");# expert fonts?
  $stylefile = "z$_[0]$fontfam_.sty";
  open(LTXSTY, ">$stylefile");
  $FH_ = "LTXSTY";
  &Out("%% Created by MathInst$mathinstver_ on $curday, $today at $now.");
  &Out("%% This is a LaTeX style file for MathTime + $fontfam_ fonts.\n");
  &Out("\\ProvidesPackage{z$_[0]$fontfam_}\n");
  &Out("\n%% The gory details...");
  &out("\\SetSymbolFont{operators}{normal}{$mathencoding_}");
    &Out("{$shortmathpkg_}{$reg2nfss{$rreg}}{n}");
  &out("\\SetSymbolFont{letters}{normal}{OML}");
    &Out("{$shortmathpkg_}{m}{it}");
  &out("\\SetSymbolFont{symbols}{normal}{OMS}");
    &Out("{$shortmathpkg_}{m}{n}");
  &Out("\\SetSymbolFont{largesymbols}{normal}{OMX}{$shortmathpkg_}{m}{n}\n");
  &out("\n\\SetMathAlphabet{\\mathit}{normal}{$mathencoding_}");
    &Out("{$fontfamx_}{$reg2nfss{$rreg}}{$ital2nfss{$rit}}");
  &out("\\SetMathAlphabet{\\mathbf}{normal}{$mathencoding_}");
  if (&isvariable($greekbold_)) {# real math bold font exists!
    &Out("{$shortmathpkg_}{$nfssbold}{n}");
  } else {#                        use standard text bold
    &Out("{${fontfamx_}}{$nfssbold}{n}");
  }
  &out("\\SetSymbolFont{operators}{bold}{$mathencoding_}");
    &Out("{$shortmathpkg_}{$nfssbold}{n}");  
  &out("\\SetSymbolFont{letters}{bold}{OML}");
    &Out("{$shortmathpkg_}{$nfssbold}{it}");
  &out("\n\\SetMathAlphabet{\\mathit}{bold}{$mathencoding_}");
    &Out("{$fontfam_}{$nfssbold}{it}");
  if (&isvariable($greekbold_)) {# greek bold => special math bold
    &out("\\SetMathAlphabet{\\mathbf}{bold}{$mathencoding_}");
	&Out("{$shortmathpkg_}{$nfssbold}{n}");
  } else {
    &out("\\SetMathAlphabet{\\mathbf}{bold}{$mathencoding_}");
	&Out("{$fontfam_}{$nfssbold}{n}");
  }
  &Out("\n\\renewcommand{\\rmdefault}{$fontfamx_}");
  &Out("\\renewcommand{\\encodingdefault}{$mathencoding_}");
  &Out("\\renewcommand{\\seriesdefault}{$thisseries}")
      unless $thisseries eq "m";
  &Out("\\renewcommand{\\shapedefault}{$thisshape}")
      unless $thisshape eq "n";
  $nfssbold=$bold2nfss{$rbold};
  &Out("\\renewcommand{\\bfdefault}{$nfssbold}");
  # Now, the tt font.
  if ($tt_) {
      &Out("\n%% Typewriter fonts.");
      local($ttsize) = sprintf("%5.3f", $ttSF_ / 1000);
      local($ttfam) = &deduce_fontfam_from($tt_);
      if (-e "$inputs_$sep${encoding_}$ttfam.fd") {
          &get_fd_info_and_scale_it("${encoding_}$ttfam", $ttsize);
      } else { # no fd file for tt...
	  &out("\\DeclareFontFamily\{$encoding_\}\{$ttfam\}");
	  &Out("\{\\hyphenchar \\font\\m\@ne\}");
          &out("  \\DeclareFontShape{$encoding_}");
          &Out("{$ttfam}{m}{n}{<-> [$ttsize] $tt_}{}\n");
      }
      &Out("\\renewcommand{\\ttdefault}{$ttfam}"); 
      &out("\\SetMathAlphabet{\\mathtt}{normal}{$encoding_}");
      &Out("{\\ttdefault}{m}{n}"); 
  }
  # Now, the sans serif info.
  if ($sansserif_) {
      &Out("\n%% Sans serif fonts.");
      local($sssize) = sprintf("%5.3f", $ssSF_ / 1000);
      local($ssfam) = &deduce_fontfam_from($sansserif_);
      if (-e "$inputs_$sep${encoding_}$ssfam.fd") {
          &get_fd_info_and_scale_it("${encoding_}$ssfam", $sssize);
      } else { # no fd file for tt...
	  &Out("\\DeclareFontFamily\{$encoding_\}\{$ssfam\}\{\}");
          &out("  \\DeclareFontShape{$encoding_}");
          &Out("{$ssfam}{m}{n}{<-> [$sssize] $sansserif_}{}\n");
      }
      &Out("\\renewcommand{\\sfdefault}{$ssfam}"); 
      &out("\\SetMathAlphabet{\\mathsf}{normal}{$encoding_}");
      &Out("{\\sfdefault}{m}{n}"); 
  }
  if (&isvariable($cal_)) {
    local($calsize) = sprintf("%5.3f", $caSF_ / 1000);
    &Out("\n%% Math Calligraphic.");
    &Out("\\DeclareFontFamily{$mathencoding_}{cal}{}");
    &out("\\DeclareFontShape{$mathencoding_}");
	&Out("{cal}{m}{it}{<-> [$calsize] $cal_}{}");
    &Out("\\newcommand{\\caldefault}{cal}");
    &out("\\SetMathAlphabet{\\mathcal}{normal}{$mathencoding_}");
	&Out("{\\caldefault}{m}{it}");
  }
  if (&isvariable($fraktur_)) {
    local($fraksize) = sprintf("%5.3f", $frSF_ / 1000);
    &Out("\n%% Math Fraktur.");
    &Out("\\DeclareFontFamily{$mathencoding_}{frak}{}");
    &out("\\DeclareFontShape{$mathencoding_}");
	&Out("{frak}{m}{n}{<-> [$fraksize] $fraktur_}{}");
    &Out("\\newcommand{\\frakdefault}{frak}");
    &out("\\DeclareMathAlphabet{\\mathfr}{$mathencoding_}");
	&Out("{\\frakdefault}{m}{n}");
  }
  if (&isvariable($bbold_)) {
    local($bbsize) = sprintf("%5.3f", $bbSF_ / 1000);
    &Out("\n%% Math Blackboard Bold.");
    &Out("\\DeclareFontFamily{$mathencoding_}{bbold}{}");
    &out("\\DeclareFontShape{$mathencoding_}");
	&Out("{bbold}{m}{n}{<-> [$bbsize] $bbold_}{}");
    &Out("\\newcommand{\\bbdefault}{bbold}");
    &out("\\DeclareMathAlphabet{\\mathbb}{$mathencoding_}");
	&Out("{\\bbdefault}{m}{n}");
  }
  &out("\n\\renewcommand{\\l}{\\char170\\relax} "); # since lslashslash
  &Out("\\renewcommand{\\L}{\\char138\\relax} ");   # doesn't exist 
  &Out($mt_hax) if $_[0] eq "mt";
  &Out($lu_hax) if $_[0] eq "lu";
  &Out("\n\\endinput");  
  close LTXSTY;
}

$mt_hax = <<'EOMTHax';

%% Now for some hacks...

\mathchardef\varkappa="0180 
\mathchardef\comp="2181
\def\vec{\mathaccent"717E }
\mathchardef\Relbar="3280
\mathcode`\;="6281
EOMTHax

$lu_hax = <<'EOLUHax';

%% Now for some hacks...

\def\joinrel{\mathrel{\mkern-6mu}}
\mathchardef\Relbar="3280
\mathcode`\;="6281

\catcode`\@=11
\def\Lbrack{\delimiter"4382384 }
\def\Rbrack{\delimiter"5383385 }
\mathchardef\surfint="1390 \mathchardef\lsurfint="1394
\mathchardef\lointop="1393 \def\loint{\lointop\nolimits}
\mathchardef\lintop="1392  \def\lint{\lintop\nolimits}
\def\@intrad{\radical"352392 }%  ``radicalized'' integral sign
\def\@ointrad{\radical"348393 }% ``radicalized'' contour integral
\def\@sintrad{\radical"390394 }% ``radicalized'' surface integral
\newtoks\@subtoks \newtoks\@suptoks
\def\varint{\@int{\@intrad}}
\def\varoint{\@int{\@ointrad}}
\def\varsint{\@int{\@sintrad}}
\def\@int#1{\@subtoks={}\@suptoks={}\let\@limits=\nolimits
  \let\@thisint=#1
  \futurelet\@nextchar \@testnextchar}
\def\@testnextchar{\let\next=\@getintegrand
  \ifx\@nextchar_ \let\next=\@getsubscript\fi
  \ifx\@nextchar^ \let\next=\@getsuperscript\fi
  \next}
\def\@getsubscript_#1{\@subtoks=\expandafter{#1}%
  \futurelet\@nextchar \@testnextchar}
\def\@getsuperscript^#1{\@suptoks=\expandafter{#1}%
  \futurelet\@nextchar \@testnextchar}
\def\@getintegrand{\mathpalette\@integrand}
\def\@integrand#1#2{\setbox0=\hbox{$\m@th #1 #2$}\dimen@=\ht0
  \advance\dimen@ by\dp0 \mathop{\vcenter{\hbox{$\@thisint{%
  \vcenter to\dimen@{}}$}}}\@limits^{\the\@suptoks}_{\the\@subtoks}%
  \box0}
\def\setlimits{\global\let\@limits=\limits}
\def\setnolimits{\global\let\@limits=\nolimits}
\catcode`\@=12
EOLUHax

sub makeplainstyle{
  $stylefile = "z$_[0]$fontfam_.tex";
  local($mysize);
  open(PLNSTY, ">$stylefile");
  $FH_ = "PLNSTY";
  require("..${sep}plainsty.tpl")  or die "Where is the plain template?";
  close PLNSTY;  
}

sub makeLaTeXtestfile{
  $q = q!"!;
  $FH_ = "LTXTEST";
  open($FH_, ">testmath.tex");
  require("..${sep}testmath.tpl");
  &out($Caltest)   if $cal_;
  &out($Sanstest)  if $sansserif_;
  &out($Fraktest)  if $fraktur_;
  &out($BBoldtest) if $bbold_;
  &out($DD);
  close $FH_;
}

sub makeplaintestfile{
  $FH_ = "PLNTEST";
  open($FH_, ">testmatp.tex");
  require("..${sep}testmatp.tpl");
  &out($GreekBoldTest) if $greekbold_;
  &out($CalTest)       if $cal_;
  &out($SansTest)      if $sansserif_;
  &out($FrakTest)      if $fraktur_;
  &out($BBoldTest)     if $bbold_;
  &out($BBplain);
  close $FH_;
}

sub makecleanupfile{
  $FH_ = "PUTFONTS";
  open($FH_, ">putfonts.bat");
  if (&isTDS) {
    &Out(
    "$mv \*.vf    $texmf_${sep}fonts${sep}vf${sep}$installer_${sep}$mathpkg_");
    &Out(
    "$mv \*.tfm  $texmf_${sep}fonts${sep}tfm${sep}$installer_${sep}$mathpkg_");
    &Out("$mv z\*.tex  $texmf_${sep}tex${sep}plain${sep}mathinst");
    &Out("$mv z\*.sty  $texmf_${sep}tex${sep}latex${sep}mathinst");
  } else { # traditional systems
    &Out("$mv \*.vf   $vf_");    
    &Out("$mv \*.tfm  $tfm_");
    &Out("$mv z\*.\*   $inputs_");
  }
  ## Everyone...
  &Out("$mv \*.fd   $inputs_"); 
  close $FH_;
  ## Now to change executables to `execute' status for Unix systems...
  if ($sep eq "/") {
      chmod 0755, "mkdirs.bat" if -e "mkdirs.bat";
      local($cnt) = chmod 0755, "makepl.bat", "makevf.bat", "putfonts.bat";
      &Out("I couldn't make the .bat files executable.  Check permissions.")
	  if $cnt == 0;
  }
}