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
|
%D \module
%D [ file=syst-ini,
%D version=2008.11.04, % 2001.11.16, % 1999.03.17, % an oldie: 1995.10.10
%D title=\CONTEXT\ System Macros,
%D subtitle=Bootstrapping \TEX,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
%D We used to load plain \TEX\ in a special way, but redefining a couple of
%D primitives so that for instance font loading was ignored. For those interested,
%D this loader is found in \type {syst-tex.tex}. Some of the comment's are Don
%D Knuths and more of it can be found in the plain \TEX\ format.
%D
%D Successive versions will be adapted to \LUAMETATEX. That also means that we
%D define things a bit differently than in \MKII\ and \MKIV. This is party due to
%D the fact that in this engine we removed some side effects or added features. The
%D original \TEX\ program is well defined and documented and is still the benchmark.
%D The \ETEX\ extensions originally were meant as systematic follow up but that
%D never went beyond a first upgrade. It had a dual mode: compatible or extensible.
%D We always used the second mode. The \LUATEX\ engines don't have that.
%D
%D There are some hard coded properties that relate to for instance node types but
%D we always used abstraction. There are also side effects that (probably) originate
%D in the fact that \ETEX\ had to stay compatible with the dominant set of macros
%D using the original \TEX\ ones (either or not wrapped). Even unwanted side effects
%D eventually become features. In\LUATEX\ and even more in \LUAMETATEX\ we get
%D around that by additional mode variables that you can find below.
%D
%D Side note: those who complain about \TEX\ as rather special language, \ETEX\
%D extensions that should have been or be different, should really look into how
%D \TEX\ and friends evolved, and not come to quick and wrong conclusions. There are
%D only a very few languages that evolve this way. As a comparison one can wonder
%D why \CCODE\ never had proper strings like \PASCAL\ bit it's just hindsight and
%D discussing it has no use. In a similar fashion one should keep in mind that what
%D you see here is just a logical follow up in \MKII\ where we had to bend the rules
%D and \MKIV\ where we had a bit more available. Not many who look at the latest
%D engines had to jump though all the hoops.
%D
%D This is for instance noticeable in the names of some primitvies: \CONTEXT\ has a
%D concept of protection before \type {\protected} showed up, and similarly had
%D expansion helpers. This is why in \MKII\ you find \type {\protected}, \type
%D {\expanded}, and \type {\unexpanded} commands with different meanings than the
%D later \ETEX\ primitives. In \MKIV\ we stuck to the \CONTEXT\ originals and use
%D \type {\normal...} ones when needed (so \type {\normal...} is there for a
%D reason!). In \LMTX\ we made the transition from \type {\unexpanded} to \type
%D {\protected} so again this file looks different than the \MKIV\ ancestor.
%D
%D When primitives get initialized they come from the \TEX\ namespace (the
%D originals), the \ETEX\ extensions (although we dropped some) and \LUATEX\ which
%D includes the \LUAMETATEX\ ones. The most noticeable \ETEX\ extensions we kept are
%D those that relate to expansion and the expression scanners. The last group has
%D always been somewhat special because (we were told) it was modelled after a macro
%D set so it had to be compatible. It is tempting to replace it (and eventually I
%D might do that) but for now we stick to them (although with an integer divide
%D extension (like the \LUA\ \type {//} and the source has commented binary
%D operators but I haven't yet decided on the symbols to use because we need to
%D avoid expansion issues). For the record: the more extensive, related to \ETEX\
%D follow up \NTS\ never took of, probably because of the implementation language
%D and because performance made it unuseable. This is also why \LUATEX\ took a
%D different route: extending by an extension language. Of course in the end some
%D core functionality got added too.
%D
%D The most noticeable \LUAMETATEX\ specific code here has to do with additional
%D data types (integer and dimension constants) and macro argument extensions. We
%D also set up some defaults in handling math, languages, etc. Elsewhere in the
%D \CONTEXT\ source the real configuration and usage happens so don't consider this
%D an tutorial (as the plain format is).
%D
%D Category codes are another areas where subtle changed happened. You might not
%D grasp it (maybe because \CONTEXT\ is alien to you) but whenever you see something
%D that looks weird keep in mind that there is a valid reason for it.
%D
%D In due time I will add some more comments here, also because some \CONTEXT\
%D users might be interested in the hostiry. Now to the code!
%D Characters can have special states, that can be triggered by setting their
%D category coded. Some are preset, others are to be set as soon as possible,
%D otherwise we cannot define any useful macros.
%D
%D First we define a bunch of constants. Normally we would \type {\setconstant}
%D but we're prestine and have no macros defined yet. Abstraction also makes it
%D possible to avoid the \type {^^} in the input. We no longer define the \ETEX\
%D nodes here (we have not only more, but also different numbers) so we do it
%D elsewhere.
% cheatsheet
%
% # : 0--9
% * : ignore spaces
% + : keep the braces
% - : discard and don't count the argument
% . : ignore pars and spaces
% , : push back space when no match
% / : remove leading and trailing spaces and pars
% : : pick up scanning here
% ; : quit scanning
% = : braces are mandate
% ^ : keep leading spaces
% _ : braces are mandate and kept
\immutable\integerdef\escapecatcode 0
\immutable\integerdef\begingroupcatcode 1
\immutable\integerdef\endgroupcatcode 2
\immutable\integerdef\mathshiftcatcode 3
\immutable\integerdef\alignmentcatcode 4
\immutable\integerdef\endoflinecatcode 5
\immutable\integerdef\parametercatcode 6
\immutable\integerdef\superscriptcatcode 7
\immutable\integerdef\subscriptcatcode 8
\immutable\integerdef\ignorecatcode 9
\immutable\integerdef\spacecatcode 10
\immutable\integerdef\lettercatcode 11
\immutable\integerdef\othercatcode 12 % finally obsolete: \let\other \othercatcode
\immutable\integerdef\activecatcode 13 % finally obsolete: \let\active\activecatcode
\immutable\integerdef\commentcatcode 14
\immutable\integerdef\invalidcatcode 15
%immutable\integerdef\zeroasciicode 0
\immutable\integerdef\tabasciicode 9
\immutable\integerdef\newlineasciicode 10 % don't confuse this one with \endoflineasciicode
\immutable\integerdef\formfeedasciicode 12
\immutable\integerdef\endoflineasciicode 13 % somewhat messy but this can be the active \par
\immutable\integerdef\endoffileasciicode 26
\immutable\integerdef\spaceasciicode 32
\immutable\integerdef\exclamationmarkasciicode 33 % ! used in namespace protection
\immutable\integerdef\doublequoteasciicode 34 % "
\immutable\integerdef\hashasciicode 35
\immutable\integerdef\dollarasciicode 36
\immutable\integerdef\commentasciicode 37
\immutable\integerdef\ampersandasciicode 38
\immutable\integerdef\singlequoteasciicode 39 % '
\immutable\integerdef\primeasciicode 39 % '
\immutable\integerdef\leftparentasciicode 40
\immutable\integerdef\rightparentasciicode 41
\immutable\integerdef\commaasciicode 44
\immutable\integerdef\hyphenasciicode 45
\immutable\integerdef\periodasciicode 46
\immutable\integerdef\forwardslashasciicode 47 % /
\immutable\integerdef\colonasciicode 58
\immutable\integerdef\lessthanasciicode 60 % < used as alternative verbatim {
\immutable\integerdef\morethanasciicode 62 % > used as alternative verbatim }
\immutable\integerdef\questionmarkasciicode 63 % ? used in namespace protection
\immutable\integerdef\atsignasciicode 64 % @ used in namespace protection
\immutable\integerdef\leftbracketasciicode 91
\immutable\integerdef\backslashasciicode 92 % `\\
\immutable\integerdef\rightbracketasciicode 93
\immutable\integerdef\circumflexasciicode 94
\immutable\integerdef\underscoreasciicode 95
\immutable\integerdef\leftbraceasciicode 123 % `\{
\immutable\integerdef\barasciicode 124 % `\|
\immutable\integerdef\rightbraceasciicode 125 % `\}
\immutable\integerdef\tildeasciicode 126 % `\~
\immutable\integerdef\delasciicode 127
\aliased\let\percentasciicode\commentasciicode
%catcode\zeroasciicode \ignorecatcode % `\^^@ ascii null is ignored
\catcode\tabasciicode \spacecatcode % `\^^I ascii tab is a blank space
\catcode\formfeedasciicode \activecatcode % `\^^L ascii form-feed (active, set later)
%catcode\endoflineasciicode \endoflinecatcode % `\^^M ascii return is end-line
\catcode\endoffileasciicode \ignorecatcode % `\^^Z endoffile (ignored in ConTeXt)
%catcode\spaceasciicode \spacecatcode % `\ ascii space is blank space
\catcode\hashasciicode \parametercatcode % `\# hash mark is macro parameter character
\catcode\dollarasciicode \mathshiftcatcode % `\$ dollar sign is math shift
%catcode\commentasciicode \commentcatcode % `\% percent sign is comment character
\catcode\ampersandasciicode \alignmentcatcode % `\& ampersand is alignment tab
%catcode\backslashasciicode \escapecatcode % `\\ backslash is TeX escape character
\catcode\circumflexasciicode \superscriptcatcode % `\^ circumflex and uparrow are for superscripts
\catcode\underscoreasciicode \subscriptcatcode % `\_ underline and downarrow are for subscripts
\catcode\leftbraceasciicode \begingroupcatcode % `\{ left brace is begin-group character
\catcode\rightbraceasciicode \endgroupcatcode % `\} right brace is end-group character
\catcode\tildeasciicode \activecatcode % `\~ tilde is active
%catcode\delasciicode \invalidcatcode % `\^^? ascii delete is invalid
%D First we need to initialization the primitives. Because \CONTEXT\ is already a
%D pretty old macro package, we have a couple of issues with respect to primitives.
%D The \ETEX\ engine added a few as did \PDFTEX. The \LUATEX\ engine added even
%D more. This means that there can be a potential clash between primitives and
%D existing macros. The most noticeable ones are:
%D
%D \starttyping
%D \protected
%D \expanded
%D \unexpanded
%D \stoptyping
%D
%D Because we had macros like that before the primitives showed up. The protection
%D related macros were there before we even knew about extensions to the engine.
%D When the expansion related ones were introduced, we originally came up with
%D different names but due to requests we used the current names, somethng that in
%D retrospect was a bad idea: they should have gotten different names in \LUATEX, if
%D only because at that time only \CONTEXT\ was using them in rolling releases.
%D Anyway, we're now stuck with this situation, and it means that one should use the
%D \type {\normal...} variants in low level code:
%D
%D \starttyping
%D \normalexpanded
%D \normalprotected
%D \normalunexpanded
%D \stoptyping
%D
%D In the end not using different names in \LUATEX\ for these kind of backfires. It
%D makes not much sense to fix this in \LUAMETATEX\ because we're now to long on the
%D road. It is actually the reason why we have the option in \LUATEX\ to alias all
%D primitives in one go using a prefix. Actually this trick could be used to recover
%D a primitive meaning: just enable it with some prefix and \type {\let} the
%D original to that. But \unknown\ we prevent that trick below.
%D
%D The code below differs from \LUATEX: in \LUAMETATEX\ all primitives are already
%D available; it cannot limit itself to being \TEX\ or \ETEX. It could not do that
%D anyway because there are differences (no backend, to mention one).
\directlua {
tex.enableprimitives("normal",true) % we default to everything
function tex.enableprimitives() end % so we kind of protect what's there
}
\untraced\permanent\let\undefined\undefined
\immutable\def\space{ }
\immutable\def\empty{}
\mutable \def\temp {}
\immutable\letcharcode \formfeedasciicode \par % \def ^^L{\par} formfeed
\immutable\letcharcode \tildeasciicode \ % tilde
\immutable\letcharcode \spaceasciicode \space % space
\immutable\defcsname\Uchar\tabasciicode \endcsname {\ } % \def\^^I{\ } tab
\immutable\defcsname\Uchar\formfeedasciicode \endcsname {\par} % \def\^^L{\par} formfeed
\immutable\defcsname\Uchar\endoflineasciicode\endcsname {\ } % \def\^^M{\ } return
%D For now:
\permanent\def\gobbleoneargument#-{} % will be defined later on anyway
%D First we define a simplified version of the \CONTEXT\ protection mechanism. Later
%D we will implement a better variant.
\def\unprotect
{\edef\protect
{\catcode\atsignasciicode \the\catcode\atsignasciicode \relax
\catcode\exclamationmarkasciicode\the\catcode\exclamationmarkasciicode\relax
\catcode\questionmarkasciicode \the\catcode\questionmarkasciicode \relax
\catcode\underscoreasciicode \the\catcode\underscoreasciicode \relax
\let\protect\relax}%
\catcode\atsignasciicode \lettercatcode
\catcode\exclamationmarkasciicode\lettercatcode
\catcode\questionmarkasciicode \lettercatcode
\catcode\underscoreasciicode \lettercatcode}
\let\protect\relax
\unprotect
%D Some pretty important definitions:
\immutable\let\bgroup={
\immutable\let\egroup=}
%D \macros
%D {normalbgroup,normalgroup}
%D
%D No comment.
%D Allocation of registers is done slightly different than in plain \TEX. First of
%D all we use different reserved counters. We also don't implement a family handler
%D because users are not supposed to implement their own math. We reserve the lowest
%D 31 registers for scratch purposes. Keep in mind that in the core engine some
%D registers are reserved: counters 0 upto 9, and counter 255.
%D
%D As with plain \TEX\ we recommend that macro designers always use \type {\global}
%D assignments with respect to registers numbered 1, 3, 5 \unknown\ 31, and always
%D non||\type {\global} assignments with respect to registers 0, 2, 4, \unknown\ 30.
%D This will prevent \quote {save stack buildup} that might otherwise occur.
%D
%D We reserve some registers for special (management) purposes. In the mkiv file you
%D can see how we also (even if we don't use it) deal with families and languages
%D and distinguish read and write ranges. There we also use a more traditional
%D insert allocator that operates in its own range. In \MKIV\ the ranges are:
% 0 - 20 : scratch
% 21 - 127 : internal
% 128 - 254 : inserts (no longer)
% 255 : page
% 256 - : user defined
%D However, in \LMTX\ we have:
% 0 - 199 : scratch
% 200 - 254 : internal
% 255 : page
% 256 - : user defined
%D Later on, the \type {\c_syst_max_allocated_register} variable will be halfed so
%D that while local allocators will use the 22* range. So we have plenty of room
%D reserved for more private ones.
\permanent\countdef\c_syst_min_allocated_register = 201 \c_syst_min_allocated_register = 256 % can change
\permanent\countdef\c_syst_max_allocated_register = 202 \c_syst_max_allocated_register = 65535 % is adapted later on
\permanent\countdef\c_syst_min_allocated_iohandle = 203 \c_syst_min_allocated_iohandle = 0
\permanent\countdef\c_syst_max_allocated_iohandle = 204 \c_syst_max_allocated_iohandle = 1023
\permanent\countdef\c_syst_min_allocated_attribute = 205 \c_syst_min_allocated_attribute = 1024 % 0-1023 : private
\permanent\countdef\c_syst_last_allocated_count = 211 \c_syst_last_allocated_count = \c_syst_min_allocated_register
\permanent\countdef\c_syst_last_allocated_dimen = 212 \c_syst_last_allocated_dimen = \c_syst_min_allocated_register
\permanent\countdef\c_syst_last_allocated_skip = 213 \c_syst_last_allocated_skip = \c_syst_min_allocated_register
\permanent\countdef\c_syst_last_allocated_muskip = 214 \c_syst_last_allocated_muskip = \c_syst_min_allocated_register
\permanent\countdef\c_syst_last_allocated_box = 215 \c_syst_last_allocated_box = \c_syst_min_allocated_register
\permanent\countdef\c_syst_last_allocated_toks = 216 \c_syst_last_allocated_toks = \c_syst_min_allocated_register
\permanent\countdef\c_syst_last_allocated_read = 217 \c_syst_last_allocated_read = \c_syst_min_allocated_iohandle
\permanent\countdef\c_syst_last_allocated_write = 218 \c_syst_last_allocated_write = \c_syst_min_allocated_iohandle
\permanent\countdef\c_syst_last_allocated_marks = 219 \c_syst_last_allocated_marks = \c_syst_min_allocated_register
\permanent\countdef\c_syst_min_counter_value = 253 \c_syst_min_counter_value = -"7FFFFFFF
\permanent\countdef\c_syst_max_counter_value = 254 \c_syst_max_counter_value = "7FFFFFFF
\immutable\integerdef\zerocount 0
\immutable\integerdef\plusone 1
\immutable\integerdef\minusone -1
\immutable\integerdef\normalpagebox 255 % hardcoded in pdftex/xetex
\immutable\integerdef\statuswrite \minusone
%D So, effectively we start allocating from 256 and upwards. The inserts sit in the
%D range 128 upto 254. Page numbers use the counters 0 upto 9 and the pagebox is
%D 255. Users can use the scratch registers upto 31 without problem but all others
%D are reserved.
\permanent\let\wlog\gobbleoneargument % Let's get rid of this one.
%D The allocators share a common helper macro.
\permanent\protected\def\newcount {\syst_basics_allocate\c_syst_last_allocated_count \count \countdef \c_syst_max_allocated_register}
\permanent\protected\def\newdimen {\syst_basics_allocate\c_syst_last_allocated_dimen \dimen \dimendef \c_syst_max_allocated_register}
\permanent\protected\def\newskip {\syst_basics_allocate\c_syst_last_allocated_skip \skip \skipdef \c_syst_max_allocated_register}
\permanent\protected\def\newmuskip{\syst_basics_allocate\c_syst_last_allocated_muskip\muskip\muskipdef \c_syst_max_allocated_register}
\permanent\protected\def\newbox {\syst_basics_allocate\c_syst_last_allocated_box \box \integerdef\c_syst_max_allocated_register}
\permanent\protected\def\newtoks {\syst_basics_allocate\c_syst_last_allocated_toks \toks \toksdef \c_syst_max_allocated_register}
\permanent\protected\def\newread {\syst_basics_allocate\c_syst_last_allocated_read \read \integerdef\c_syst_max_allocated_iohandle}
\permanent\protected\def\newwrite {\syst_basics_allocate\c_syst_last_allocated_write \write \integerdef\c_syst_max_allocated_iohandle}
\permanent\protected\def\newmarks {\syst_basics_allocate\c_syst_last_allocated_marks \marks \integerdef\c_syst_max_allocated_register}
\firstvalidlanguage \plusone % so zero is ignored in hyphenation, this might become the default
%D Watch out, for the moment we disable the check for already being defined later we
%D will revert this but first all chardefs must be replaced.
\permanent\protected\def\setconstant {}
\permanent\protected\def\setconstantvalue#1#2{\csname#1\endcsname\numexpr#2\relax}
\permanent\protected\def\newconstant#1%
{\ifrelax#1%
%\writestatus{!!!!!!!!!!}{\string #1 => RELAX}%
\unletfrozen#1%
\newcount#1%
\orelse\ifdefined#1%
%\writestatus{!!!!!!!!!!}{\string #1 => DEFINED}%
\else
\newcount#1%
\fi}
\permanent\protected\def\setnewconstant#1{\newconstant#1#1}
% %D The next definitions are really needed (in \CONTEXT):
\newlinechar\newlineasciicode \permanent\edef\outputnewlinechar{\Uchar\newlineasciicode} % {^^J}
%D One reason to start high with allocation is that it permits us to allocate
%D consecutive ranges more easily, for instance if for \MPLIB\ we want to allocate a
%D continuous range of boxes. It also permits us to do a proper upward allocation
%D for inserts. The current code evolved from code that dealt with older engines but
%D as all engines now provide many registers we removed all traces. If you ever run
%D into the \MKII\ \type {mptopdf} code, you'll notice that some register magic was
%D needed to fit into existing macro packages. The same is true for \PICTEX\ that we
%D used in (gheneric) \PPCHTEX.
\ifdefined\writestatus \else
%\protected\def\writestatus#1#2{\immediate\write\statuswrite{#1: #2}}
\frozen\protected\def\writestatus#1#2{\message{#1: #2}}
\fi
\def\syst_basics_allocate_yes#1#2#3#4#5% last class method max name
{\ifnum#1<#4\relax
\global\advance#1\plusone
\permanent\global#3#5=#1\relax
\else
\writestatus{warning}{no room for \string#2\space \string#5\space (max: \number#4)}%
\fi}
\def\syst_basics_allocate_nop#1#2#3#4#5% last class method max name
{\writestatus{warning}{\string#2 \string#5 is already defined (\string\relax\space it first)}}
\def\syst_basics_allocate#1#2#3#4#5% last class method max name
{\ifrelax#5%
\expandafter\syst_basics_allocate_yes
\orelse\ifdefined#5%
\expandafter\syst_basics_allocate_nop
\else
\expandafter\syst_basics_allocate_yes
\fi
#1#2#3#4#5}
%D Since the number of chars exceed 256 now, we can use \type {\chardef} instead of
%D the more limited \type {\mathchardef}.
% \protected\def\newbox {\syst_basics_allocate\c_syst_last_allocated_box \box \chardef\c_syst_max_allocated_register}
% \protected\def\newmarks{\syst_basics_allocate\c_syst_last_allocated_marks\marks\chardef\c_syst_max_allocated_register}
%D Attributes are something very \LUATEX. In \CONTEXT\ you are not supposed to use
%D the attributes directly but always allocate then first. For instance attribute~0
%D is reserved for special purposes (this might change). Attributes in the range
%D 128-1023 are private and should not be touched.
\immutable\integerdef\attributeunsetvalue\c_syst_min_counter_value % used to be \minusone
% \permanent\protected\def\newattribute{\syst_basics_allocate\c_syst_last_allocated_attribute\attribute\attributedef\c_syst_max_allocated_register}
% %D Not used by \CONTEXT\ but for instance \PICTEX\ needs it. It's a trick to force
% %D strings instead of tokens that take more memory.
%
% \permanent\protected\def\newhelp#1#2{\newtoks#1#1\expandafter{\detokenize{#2}}}
%D \macros
%D {scratchcounter,
%D scratchdimen,scratchskip,scratchmuskip,
%D scratchbox,
%D scratchtoks}
%D
%D We now define a few scratch registers, so that successive loads at least have
%D some available. The private ones are used in cases where we don't want to
%D intrude on normal scratch ones.
\newcount \scratchcounter \newcount \globalscratchcounter \newcount \privatescratchcounter
\newdimen \scratchdimen \newdimen \globalscratchdimen \newdimen \privatescratchdimen
\newskip \scratchskip \newskip \globalscratchskip \newskip \privatescratchskip
\newmuskip\scratchmuskip \newmuskip\globalscratchmuskip \newmuskip\privatescratchmuskip
\newtoks \scratchtoks \newtoks \globalscratchtoks \newtoks \privatescratchtoks
\newbox \scratchbox \newbox \globalscratchbox \newbox \privatescratchbox
\newcount \scratchcounterone \newcount \scratchcountertwo \newcount \scratchcounterthree
\newdimen \scratchdimenone \newdimen \scratchdimentwo \newdimen \scratchdimenthree
\newskip \scratchskipone \newskip \scratchskiptwo \newskip \scratchskipthree
\newmuskip \scratchmuskipone \newmuskip \scratchmuskiptwo \newmuskip \scratchmuskipthree
\newtoks \scratchtoksone \newtoks \scratchtokstwo \newtoks \scratchtoksthree
\newbox \scratchboxone \newbox \scratchboxtwo \newbox \scratchboxthree
\newcount \scratchcounterfour \newcount \scratchcounterfive \newcount \scratchcountersix
\newdimen \scratchdimenfour \newdimen \scratchdimenfive \newdimen \scratchdimensix
\newskip \scratchskipfour \newskip \scratchskipfive \newskip \scratchskipsix
\newmuskip \scratchmuskipfour \newmuskip \scratchmuskipfive \newmuskip \scratchmuskipsix
\newtoks \scratchtoksfour \newtoks \scratchtoksfive \newtoks \scratchtokssix
\newbox \scratchboxfour \newbox \scratchboxfive \newbox \scratchboxsix
\newcount\globalscratchcounterone
\newcount\globalscratchcountertwo
\newcount\globalscratchcounterthree
\mutable\let\scratchmacro \relax
\mutable\let\scratchmacroone\relax
\mutable\let\scratchmacrotwo\relax
%D \macros
%D {tempstring, scratchstring*}
\mutable\let\tempstring \empty
\mutable\let\scratchstring \empty
\mutable\let\scratchstringone\empty
\mutable\let\scratchstringtwo\empty
%D \macros
%D {scratchwidth, scratchheight, scratchdepth, scratchoffset, scratchdistance}
%D
%D A few more scratch dimensions:
\newdimen\scratchwidth
\newdimen\scratchheight
\newdimen\scratchdepth
\newdimen\scratchtotal
\newdimen\scratchoffset
\newdimen\scratchleftoffset
\newdimen\scratchrightoffset
\newdimen\scratchtopoffset
\newdimen\scratchbottomoffset
\newdimen\scratchdistance
\newdimen\scratchhsize
\newdimen\scratchvsize
\newdimen\scratchxoffset
\newdimen\scratchyoffset
\newdimen\scratchhoffset
\newdimen\scratchvoffset
\newdimen\scratchxposition
\newdimen\scratchyposition
\newcount\scratchnx
\newcount\scratchny
\newcount\scratchmx
\newcount\scratchmy
\newcount\scratchmin
\newcount\scratchmax
\newcount\scratchunicode
\newdimen\scratchleftskip
\newdimen\scratchrightskip
\newdimen\scratchtopskip
\newdimen\scratchbottomskip
%D More allocations:
% \newcount \maxcount \immutable\maxcount 2147483647
% \newdimen \zeropoint \immutable\zeropoint 0pt
% \newdimen \onepoint \immutable\onepoint 1pt
% \newdimen \halfapoint \immutable\halfapoint 0.5pt
% \newdimen \maxdimen \immutable\maxdimen 16383.99999pt % 1073741823sp
% \newdimen \onebasepoint \immutable\onebasepoint 1bp
% \newdimen \scaledpoint \immutable\scaledpoint 1sp
% \newdimen \thousandpoint \immutable\thousandpoint 1000pt
\immutable\integerdef \maxcount 2147483647
\immutable\dimensiondef \zeropoint 0pt
\immutable\dimensiondef \onepoint 1pt
\immutable\dimensiondef \halfapoint 0.5pt
\immutable\dimensiondef \maxdimen 16383.99999pt % 1073741823sp
\immutable\dimensiondef \onebasepoint 1bp
\immutable\dimensiondef \scaledpoint 1sp
\immutable\dimensiondef \thousandpoint 1000pt
\immutable\gluespecdef \zeroskip 0pt plus 0pt minus 0pt
\immutable\mugluespecdef \zeromuskip 0mu
\immutable\mugluespecdef \onemuskip 1mu
\immutable\mugluespecdef \muquad 18mu
\aliased\let\points \onepoint
\aliased\let\halfpoint\halfapoint
\newtoks \emptytoks
%D And even more: (todo: countdefs 60+). Watch out, we need a count for a negative constant
%D but can use chardefs for positive ones. Actually, because we have plenty of counters we
%D can also use counts for those.
%immutable\integerdef\minusone -1
\immutable\integerdef\minustwo -2
%immutable\integerdef\zerocount 0
%immutable\integerdef\plusone 1
\immutable\integerdef\plustwo 2
\immutable\integerdef\plusthree 3
\immutable\integerdef\plusfour 4
\immutable\integerdef\plusfive 5
\immutable\integerdef\plussix 6
\immutable\integerdef\plusseven 7
\immutable\integerdef\pluseight 8
\immutable\integerdef\plusnine 9
\immutable\integerdef\plusten 10
\immutable\integerdef\pluseleven 11
\immutable\integerdef\plustwelve 12
\immutable\integerdef\plussixteen 16
\immutable\integerdef\plusfifty 50
\immutable\integerdef\plushundred 100
\immutable\integerdef\plusonehundred 100
\immutable\integerdef\plustwohundred 200
\immutable\integerdef\plusfivehundred 500
\immutable\integerdef\pluscxxvii 127
\immutable\integerdef\pluscxxviii 128
\immutable\integerdef\pluscclv 255
\immutable\integerdef\pluscclvi 256
\immutable\integerdef\plusthousand 1000
\immutable\integerdef\plustenthousand 10000
\immutable\integerdef\plustwentythousand 20000
\immutable\integerdef\medcard 32768
\immutable\integerdef\maxcard 65536 % pdftex has less mathchars
\immutable\integerdef\maxcardminusone 65535
%D \macros
%D {doubleexpandafter,tripleexpandafter,expanded,startexpanded}
%D
%D A few handy shortcuts
\permanent\let\singleexpandafter \expandafter
\permanent\def\doubleexpandafter{\expandafter\expandafter\expandafter}
\permanent\def\tripleexpandafter{\expandafter\doubleexpandafter\expandafter}
%D We prefer the more readable variant than in plain \TEX. User should only
%D use \type {\emptybox}:
\newbox\voidbox % public
\permanent\def\unvoidbox{\unhbox\voidbox}
\permanent\def\emptybox {\box \voidbox} % used in initializations so no attributes
\permanent\def\emptyvbox{\normalvpack{}} % no copy as we need to set attributes
\permanent\def\emptyhbox{\normalhpack{}} % no copy as we need to set attributes
\aliased\let\leavevmode\unvoidbox % we prefer to use \dontleavehmode
%D \macros
%D {dontcomplain,lessboxtracing}
%D
%D We need this one soon. The second one shows less box details (because that actually
%D slows down noticeably due to the more extensive details in node content.
% With \showboxdepth\maxcount and \showboxbreadth\maxcount the second one is way slower:
%
% \testfeatureonce{10}{\setbox\scratchbox\vbox {\samplefile{tufte}}} \elapsedtime\par
% \testfeatureonce{10}{\setbox\scratchbox\vbox to 10cm{\samplefile{tufte}}} \elapsedtime\par
\permanent\protected\def\dontcomplain
{\hbadness\plustenthousand
\vbadness\plustenthousand
\hfuzz \maxdimen
\vfuzz \maxdimen}
\permanent\protected\def\lessboxtracing
{\showboxdepth \plusthree
\showboxbreadth\plusfive}
%D Some expected plain variants follow. We don't reuse registers because we don't
%D want clashes. These will go away and packages that need them have to define them.
\aliased\let\p@ \onepoint
\aliased\let\m@ne \minusone
\aliased\let\z@ \zeropoint
\aliased\let\@ne \plusone
\aliased\let\tw@ \plustwo
\aliased\let\thr@@ \plusthree
\aliased\let\sixt@@n\plussixteen
\aliased\let\@cclv \pluscclv
\aliased\let\@cclvi \pluscclvi
\aliased\let\voidb@x\voidbox
\newtoks \toks@ %scratchtoks
%D We define \type {\newif} a la plain \TEX, but will redefine it later. As Knuth
%D says:
%D
%D \startnarrower
%D And here's a different sort of allocation: for example,
%D
%D \starttyping
%D \newif\iffoo
%D \stoptyping
%D
%D creates \type {\footrue}, \type {\foofalse} to go with \type {\iffoo}.
%D \stopnarrower
% \protected\def\newif#1%
% {\count@\escapechar
% \escapechar\minusone
% \expandafter\expandafter\expandafter\def\new_if #1{true}{\let#1\iftrue }%
% \expandafter\expandafter\expandafter\def\new_if#1{false}{\let#1\iffalse}%
% \new_if#1{false}% the condition starts out false
% \escapechar\count@}
%
% \def\new_if#1#2%
% {\csname\expandafter\if@\string#1#2\endcsname}
%
% \bgroup % `if' is required
% \uccode`1=`i \uccode`2=`f \uppercase{\gdef\if@12{}}
% \egroup
% We use \csstring so there is no need to push/pop escapechar.
% We use different names so that we get a better error message.
%
% \protected\def\newif#1%
% {\let\new_if_saved\newif
% \let\newif\new_if_check
% \expandafter\expandafter\expandafter\def\new_if_cs #1{true}{\let#1\iftrue }%
% \expandafter\expandafter\expandafter\def\new_if_cs#1{false}{\let#1\iffalse}%
% \new_if_cs#1{false}%
% \let\newif\new_if_saved}
%
% \protected\def\new_if_cs#1#2%
% {\csname\expandafter\newif\csstring#1#2\endcsname}
%
% We wrap all into one macro (the frozen stuff adds 10% runtime):
\permanent\protected\def\newif#1%
{\permanent\protected\gdefcsname\expandafter\new_if_check\csstring#1true\endcsname {\overloaded\frozen\let#1\iftrue }%
\permanent\protected\gdefcsname\expandafter\new_if_check\csstring#1false\endcsname{\overloaded\frozen\let#1\iffalse}%
\csname\expandafter\new_if_check\csstring#1false\endcsname}
\normalexpanded{\gdef\noexpand\new_if_check\string i\string f{}}
%D Let's test this one:
\newif\ifdone
\newif\iffound
\newif\ifscratchcondition
\newif\ifscratchconditionone
\newif\ifscratchconditiontwo
%D This used to be a protected definition with a \type {dimexpr} but now we have
%D it natively (less tracking noise).
\aliased\let\htdp\boxtotal
%D A few shortcuts (gone by now):
% \permanent\protected\def\udef {\protected\def }
% \permanent\protected\def\ugdef{\protected\gdef}
% \permanent\protected\def\uedef{\protected\edef}
% \permanent\protected\def\uxdef{\protected\xdef}
% For now:
\permanent\protected\def\defUmathtopaccent #1#2#3#4{\global\immutable\protected\def#1{\Umathaccent "#2 "#3 "#4 }}
\permanent\protected\def\defUmathbotaccent #1#2#3#4{\global\immutable\protected\def#1{\Umathbotaccent "#2 "#3 "#4 }}
\permanent\protected\def\defUdelimiterover #1#2#3#4{\global\immutable\protected\def#1{\Udelimiterover "#2 "#3 }}
\permanent\protected\def\defUdelimiterunder #1#2#3#4{\global\immutable\protected\def#1{\Udelimiterunder "#2 "#3 }}
\permanent\protected\def\defUdelimiter #1#2#3#4{\global\immutable\protected\def#1{\Udelimiter "#2 "#3 "#4 }}
\permanent\protected\def\defUradical #1#2#3{\global\immutable\protected\def#1{\Uradical "#2 "#3 }}
\permanent\protected\def\defUroot #1#2#3{\global\immutable\protected\def#1{\Uroot "#2 "#3 }}
\permanent\protected\def\defUmathchar #1#2#3#4{\global\immutable\Umathchardef #1 "#2 "#3 "#4 }
%D For a while we keep the following, as systems like tikz need it. Best not use
%D that one \CONTEXT. It will probably move to the tikz loader.
\aliased\let\active\activecatcode
%D Constants to be used with \type {\interactionmode}.
\immutable\integerdef\batchmodecode \zerocount
\immutable\integerdef\nonstopmodecode \plusone
\immutable\integerdef\scrollmodecode \plustwo
\immutable\integerdef\errorstopmodecode \plusthree
%D Of course we want even bigger log files, so we copied this from the \ETEX\
%D source files.
%D
%D When watching such logs, beware of nasty side effects of \type {\scantokens},
%D as in:
%D
%D \starttyping
%D \bgroup
%D \lccode`a=12\lowercase{\xdef\whatever{a}}\egroup
%D \def\whatever{test \whatever test}
%D \scantokens\expandafter{\whatever}
%D \egroup
%D \stoptyping
%D
%D In \LUATEX\ we have ways around this.
% no longer \errorstopmode cf. plain tex 3.141592653
\permanent\protected\def\tracingall
{\tracingonline \plusone
\tracingcommands \plusfour % > 3: show mode change independent
\tracingmacros \plusthree % > 2: obey \untraced
\tracingoutput \plusone
\tracingpages \plusone
\tracingparagraphs\plustwo
\tracingrestores \plusone
\tracinggroups \plusone
\tracingifs \plusone
\tracingnesting \plusthree
\tracingassigns \plustwo
\tracingmath \plusone
\tracingalignments\plusone
\showboxbreadth \maxcount
\showboxdepth \maxcount}
\permanent\protected\def\loggingall
{\tracingall
\tracingonline \zerocount}
\permanent\protected\def\tracingnone
{\showboxdepth \maxcount % \plusthree
\showboxbreadth \plusten % \plusfive
\tracingalignments\zerocount
\tracingmath \zerocount
\tracingassigns \zerocount
\tracingnesting \zerocount
\tracingifs \zerocount
\tracinggroups \zerocount
\tracingrestores \zerocount
\tracingparagraphs\zerocount
\tracingpages \zerocount
\tracingoutput \zerocount
\tracingmacros \zerocount
\tracingcommands \zerocount
\tracingonline \zerocount}
%D When we want to see a box we can as well show all of it.
\showboxdepth \maxcount
\showboxbreadth\maxcount
%D Just for tracing purposes we set:
\tracingstats\plusone
%D This is only used when we load \CONTEXT. Nesting is not supported here.
\permanent\def\pushoverloadmode
{\enforced\permanent\protected\edef\popoverloadmode{\overloadmode\the\overloadmode\enforced\let\popoverloadmode\relax}%
\overloadmode\zerocount}
\aliased\let\popoverloadmode\relax
\let\pushrunstate\relax % will be defined later
\let\poprunstate \relax % will be defined later
\newtoks\everydump
\pushoverloadmode
\permanent\protected\def\dump
{\the\everydump
\global\everydump\emptytoks
\pushoverloadmode
\enforced\glet\dump\relax
\popoverloadmode
%let\pushoverloadmode\relax
%let\popoverloadmode\relax
% \tracingall
\normaldump}
\permanent\protected\def\input
{\normalinput}
\popoverloadmode
%D \macros
%D {newconditional,
%D settrue, setfalse,
%D ifconditional,then}
%D
%D \TEX's lacks boolean variables, although the \PLAIN\ format implements \type
%D {\newif}. The main disadvantage of this scheme is that it takes three hash table
%D entries. A more memory saving alternative is presented here. A conditional is
%D defined by:
%D
%D \starttyping
%D \newconditional\doublesided
%D \setfalse
%D \stoptyping
%D Setting a conditional is done by \type{\settrue} and
%D \type{\setfalse}:
%D
%D \starttyping
%D \settrue\doublesided
%D \setfalse
%D \stoptyping
%D while testing is accomplished by:
%D
%D \starttyping
%D \ifconditional\doublesided ... \else ... \fi
%D \setfalse
%D \stoptyping
%D We cannot use the simple scheme:
%D
%D \starttyping
%D \def\settrue #1{\let#1=\iftrue}
%D \def\setfalse#1{\let#1=\iffalse}
%D \stoptyping
%D
%D Such an implementation gives problems with nested conditionals. The next
%D implementation is about as fast and just as straightforward:
\aliased\let\conditionalfalse\plusone % maybe we will have a dedicated count/chardef
\aliased\let\conditionaltrue \zerocount % maybe we will have a dedicated count/chardef
% \permanent\protected\def\settrue #1{\integerdef#1\conditionaltrue }
% \permanent\protected\def\setfalse#1{\integerdef#1\conditionalfalse}
%
% \permanent\protected\def\settruevalue #1{\expandafter\integerdef\csname#1\endcsname\conditionaltrue }
% \permanent\protected\def\setfalsevalue#1{\expandafter\integerdef\csname#1\endcsname\conditionalfalse}
\permanent\protected\def\settrue #1{\enforced\let#1\conditionaltrue }
\permanent\protected\def\setfalse #1{\enforced\let#1\conditionalfalse}
\permanent\protected\def\setconditional#1{\enforced\let#1}
\permanent\protected\def\settruevalue #1{\enforced\letcsname#1\endcsname\conditionaltrue }
\permanent\protected\def\setfalsevalue#1{\enforced\letcsname#1\endcsname\conditionalfalse}
\aliased\let\newconditional\setfalse
\aliased\let\ifconditional \ifcase
\permanent\protected\lettonothing\then % so that we can say: \ifnum1>2\then -)
\permanent\def\truecondition {\iftrue}
\permanent\def\falsecondition{\iffalse}
% This one has to be unprotected otherwise we get a files-ends-to-soon but it's ok
% as conditions expand anyway.
\permanent\def\quitcondition{\orelse\iffalse}
%D \macros
%D {newmacro,setnewmacro,newfraction}
%D
%D Let's be complete and also introduce some definers. These are not mandate
%D but handy for grepping. We make these mutable because they are \type
%D {\let} (the only advantage is that we often give them names with some
%D prefix.
\permanent\protected\def\newmacro #1{\mutable\let#1\empty}
\permanent\protected\def\setnewmacro#1{\mutable\let#1}
\permanent\protected\def\newfraction#1{\mutable\let#1\!!plusone}
\def\!!zerocount{0} % later redefined
\def\!!plusone {1} % later redefined
%D It would be handy to have a primitive \type {\unless\ifcase} because then we
%D could use nicer values. Anyhow, this conditional code used to be in the \type
%D {syst-aux} module but is now promoted to here.
%D \macros
%D {ifzeropt}
%D
%D The next macro is both cosmetic and byte saving. It is pretty \type
%D {\if}||safe too. It can be used in cases like:
%D
%D \starttyping
%D \ifzeropt \somedimen ... \else ... \fi
%D \stoptyping
\aliased\let\ifzeropt\ifcase
% these token list helpers might move to syst-aux.mkiv
%
% we assume a \cs. not toks0 or so
%
% \protected\def\appendtotoks #1#{\def\temp{#1}\afterassignment\doappendtotoks \scratchtoks=}
% \protected\def\prependtotoks#1#{\def\temp{#1}\afterassignment\doprependtotoks\scratchtoks=}
\newtoks\t_syst_toks_temp \let\m_syst_toks_temp\t_syst_toks_temp
\permanent\protected\def\appendtotoks #1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_append_l \t_syst_toks_temp=}
\permanent\protected\def\prependtotoks#1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_prepend_l\t_syst_toks_temp=}
% \def\syst_toks_append {\m_syst_toks_temp\expandafter\expandafter\expandafter{\expandafter\the\expandafter\m_syst_toks_temp\the\t_syst_toks_temp}}}
% \def\syst_toks_prepend{\m_syst_toks_temp\expandafter\expandafter\expandafter{\expandafter\the\expandafter\t_syst_toks_temp\the\m_syst_toks_temp}}}
\permanent\protected\def\globalappendtotoks #1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_append_g \t_syst_toks_temp=}
\permanent\protected\def\globalprependtotoks#1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_prepend_g\t_syst_toks_temp=}
\def\syst_toks_append_l {\normalexpanded{\m_syst_toks_temp{\the\m_syst_toks_temp\the\t_syst_toks_temp}}}
\def\syst_toks_prepend_l{\normalexpanded{\m_syst_toks_temp{\the\t_syst_toks_temp\the\m_syst_toks_temp}}}
\def\syst_toks_append_g {\global\syst_toks_append_l }
\def\syst_toks_prepend_g{\global\syst_toks_prepend_l}
\permanent\protected\def\addtotoks #1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_add_l\let\next}
\permanent\protected\def\globaladdtotoks#1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_add_g\let\next}
\def\syst_toks_add_l{\m_syst_toks_temp\expandafter\bgroup\the\m_syst_toks_temp}
\def\syst_toks_add_g{\global\syst_toks_add_l}
\permanent\protected\def\addtotokscs #1#2{#1{\the#1#2}} % saves a few bytes
\permanent\protected\def\globaladdtotokscs#1#2{\global#1{\the#1#2}} % saves a few bytes
%D \macros
%D {begcsname}
%D
%D Handy for \ETEX-only usage (avoids making \type {\relax}'s:
% \def\begcsname#1\endcsname{\ifcsname#1\endcsname\csname#1\endcsname\fi}
\aliased\let\begcsname\begincsname
%D Now come a few macros that might be needed in successive loading. We redefine the
%D \type {\par} primitive pretty soon so that we get the equivalents right.
% too tricky: \par is use more often than a par starts so we have too much change
% that we get assymetrical behaviour
%
% \newtoks\everyendpar
%
% \protected\def\endpar{\the\everyendpar\normalpar}
% \protected\def\par {\endpar}
%
% \protected\def\reseteverypar
% {\everypar \emptytoks
% \everyendpar\emptytoks}
\permanent\protected\def\reseteverypar
{\everypar\emptytoks}
\aliased\let\endgraf\par % plain, a kind of funny name
%aliased\let\endline\cr % plain, not needed and probably also confusing
\permanent\protected\def\null{\hpack{}}
%D The following two might be overloaded later on but some modules need then
%D earlier. These functionality is reflected in the name and will not change.
% \bgroup
% \catcode`\^^M=\activecatcode%
% \gdef\obeylines{\catcode`\^^M\activecatcode \let^^M\par}%
% \glet^^M\par%
% \egroup
%
% \bgroup
% \gdef\obeyspaces{\catcode`\ \activecatcode}%
% \obeyspaces\glet =\space%
% \egroup
\def\obeylines {\catcode\endoflineasciicode\activecatcode\letcharcode\endoflineasciicode\par } % check if these can be \permanent
\def\obeyspaces{\catcode\spaceasciicode \activecatcode\letcharcode\spaceasciicode \space} % check if these can be \permanent
% %D A constant:
%
% \let\endoflinetoken=^^M
%D Also needed might be a simple loop structure and we borrow plain \TEX's one
%D as it is often expected to be present and it is about the fastest you can
%D get. Beware: this macro does not support nested loops. We use a namespace
%D prefix \type {@@pln}.
\let\syst_plain_body\relax
\permanent\def\loop#1\repeat{\def\syst_plain_body{#1}\syst_plain_iterate} % might go
%D The following makes \type {\loop} \unknown\ \type {\if} \unknown\ \type
%D {\repeat} skippable (clever trick):
\permanent\let\repeat\fi % so both \loop and \repeat are reserved words!
%D The original (no \type {syst_plain_} there):
%D
%D \starttyping
%D \def\syst_plain_iterate
%D {\syst_plain_body
%D \let\next\syst_plain_iterate
%D \else
%D \let\next\relax
%D \fi
%D \next}
%D \stoptyping
%D
%D A more efficient alternative:
%D
%D \starttyping
%D \def\syst_plain_iterate
%D {\syst_plain_body
%D \expandafter\syst_plain_iterate
%D \else\expandafter\relax\fi}
%D \stoptyping
%D
%D An even more efficient one:
\def\syst_plain_iterate
{\syst_plain_body
\expandafter\syst_plain_iterate\else\fi}
%D We don't define a real output routine yet but at least get rid of pages:
\output{\shipout\box\normalpagebox}
%D Although we don't add pagenumbers yet we alias the default register used
%D for counting pages:
\permanent\countdef\pageno\zerocount \pageno\plusone % first page is number 1
%D Beside the raw counter \type {\pageno} the \type {\folio} macro provides
%D the value.
\permanent\def\folio{\the\pageno} % kind of expected and therefore reserved
%D The following registers are kind of standard and (for the moment) we define
%D them here. This might change.
\newskip \bigskipamount \bigskipamount = 12pt plus 4pt minus 4pt
\newskip \medskipamount \medskipamount = 6pt plus 2pt minus 2pt
\newskip \smallskipamount \smallskipamount = 3pt plus 1pt minus 1pt
\baselineskip = 12pt
\lineskip = 1pt
\lineskiplimit = 0pt
%D Sometimes kerns make more sense than glue but we need to be in the right mode:
\permanent\protected\def\vkern {\ifhmode\par \fi\kern}
\permanent\protected\def\hkern {\ifvmode\dontleavehmode\fi\kern}
\permanent\protected\def\vpenalty{\ifhmode\par \fi\penalty}
\permanent\protected\def\hpenalty{\ifvmode\dontleavehmode\fi\penalty}
%D Again a few kind-of-extensions the core. These come from plain \TEX\ but are
%D probably not used in \CONTEXT.
\newskip \hideskip \hideskip = -1000pt plus 1fill
\newskip \centering \centering = 0pt plus 1000pt minus 1000pt
\permanent\def\hidewidth % for alignment entries that can stick out
{\hskip\hideskip}
\permanent\def\ialign % initialized \halign
{\everycr\emptytoks
\tabskip\zeroskip
\halign}
\newcount \mscount
\permanent\def\spanomit{\span\omit} % bypass error message
\permanent\def\multispan#1%
{\omit
\mscount#1\relax
\loop
\ifnum\mscount>\plusone
\spanomit \advance\mscount\minusone
\repeat}
\let\nopdfcompression \relax % later
\let\onlypdfobjectcompression\relax % later
\let\maximumpdfcompression \relax % later
\let\normalpdfcompression \relax % later
%D Basic status stuff.
% \newif\ifproductionrun % already defined
%D For those who expect this \unknown
\ifdefined\fmtname \else \immutable\def\fmtname {ConTeXt Initial TeX} \fi
\ifdefined\fmtversion \else \immutable\def\fmtversion{3.1415926} \fi
%D A few bonus macros:
%permanent\def\modulonumber#1#2{\the\numexpr#2-((((#2+(#1/2))/#1)-1)*#1)\relax}
\permanent\def\modulonumber#1#2{\the\numexpr#2-(#2:#1)*#1\relax}
\permanent\def\dividenumber#1#2{\the\numexpr(#2-(#1/2))/#1\relax}
%D These could be set at the \LUA\ end instead:
\immutable\edef\texenginename {\directlua{tex.print(LUATEXENGINE)}}
\immutable\edef\texengineversion {\directlua{tex.print(LUATEXVERSION)}}
\immutable\edef\texenginefunctionality{\directlua{tex.print(LUATEXFUNCTIONALITY)}}
%D We have no reason not to enable this:
\savingvdiscards\plusone
%D We only can set this one via directives (system.synctex) and we only support
%D the context variant. This will go away completely.
\newcount\synctex % \let\normalsynctex\synctex
%D We get rid of the funny \TEX\ offset defaults of one inch by setting them to zero.
% \voffset\zeropoint \overloaded\let\voffset\relax \newdimen\voffset \let\normalvoffset\voffset
% \hoffset\zeropoint \overloaded\let\hoffset\relax \newdimen\hoffset \let\normalhoffset\hoffset
\matheqnogapstep\zerocount % for now
%D Now we define a few helpers that we need in a very early stage. We have no
%D message system yet but redundant definitions are fatal anyway.
\newcount\c_syst_helpers_n_of_namespaces \c_syst_helpers_n_of_namespaces\pluseight % 1-8 reserved for catcodes
\def\v_interfaces_prefix_template_system{\number \c_syst_helpers_n_of_namespaces>>}
%def\v_interfaces_prefix_template_system{\characters\c_syst_helpers_n_of_namespaces>>} % no \characters yet
\protected\def\installsystemnamespace#1% will be redefined
{\ifcsname ??#1\endcsname
\immediate\write\statuswrite{fatal error: duplicate system namespace '#1'}%
\else
\global\advance\c_syst_helpers_n_of_namespaces\plusone
\immutable\edefcsname ??#1\endcsname{\v_interfaces_prefix_template_system}%
\fi}
%D It makes more sense to have these here:
\aliased\let\normalsuperscript \Usuperscript
\aliased\let\normalsubscript \Usubscript
\aliased\let\normalnosuperscript\Unosuperscript
\aliased\let\normalnosubscript \Unosubscript
\aliased\let\normalstartimath \Ustartmath
\aliased\let\normalstopimath \Ustopmath
\aliased\let\normalstartdmath \Ustartdisplaymath
\aliased\let\normalstopdmath \Ustopdisplaymath
%D Also better here:
\immutable\def\wildcardsymbol{*}
%D For a while we will keep these useless numbers as for instance tikz checks for them:
\immutable\integerdef\eTeXversion 2
\immutable\def \eTeXrevision {2}
%D Experiment:
\glyphoptions"80 % replaces \glyphdimensionsmode=1
%D Just in case users use this (or some styles still have it):
\aliased\let\immediateassignment\immediate
\aliased\let\immediateassigned \localcontrolled
%D Needed (maybe no longer the multiple next ones):
\mutable\let\nexttoken \relax
\mutable\let\next \relax
\mutable\let\nextnext \relax
\mutable\let\nextnextnext\relax
%D For now here: will get a proper solution
% \pushoverloadmode
% \mutable\let\par\par
% \popoverloadmode
%D Often used as cs key:
\mutable\let\on \empty
\mutable\let\of \empty
\mutable\let\and \empty
\mutable\let\with\empty
\mutable\let\nop \empty % used often
\mutable\let\yes \empty % used often
%D Another experiment:
\def\syst_suggested_alias#1#2% expandable
{\beginlocalcontrol
\writestatus{suggestion}{use \string#2 instead of \string#1}%
\enforced\glet#1#2%
\endlocalcontrol
#2}
\permanent\protected\def\suggestedalias#1#2%
{\ifflags#2\permanent\permanent\fi % the rest is taken with the copy
\def#1{\syst_suggested_alias#1#2}}
% A few traditional allocations (these might go too):
% \countdef \count@ 255 % hm, used in \newif .. todo: replace it there
% \dimendef \dimen@ 0
% \dimendef \dimen@i 1 % global only
% \dimendef \dimen@ii 2
\suggestedalias \count@ \scratchcounter
\suggestedalias \dimen@ \scratchdimen
\suggestedalias \dimen@i \scratchdimenone
\suggestedalias \dimen@ii \scratchdimentwo
%D The next feature is experimental and could go into another system module, but it
%D feels more natural to have it here.
%D
%D \starttyping
%D \begingroup
%D \newlocaldimen\mydimena % \mydimena1\onepoint
%D \newlocaldimen\mydimenb % \mydimenb2\onepoint
%D \begingroup
%D \newlocaldimen\mydimena % \mydimena3\onepoint
%D \newlocaldimen\mydimenb % \mydimenb4\onepoint
%D \newlocaldimen\mydimenc % \mydimenc5\onepoint
%D \endgroup
%D \endgroup
%D
%D \begingroup
%D \setlocaldimen\mydimena 1\onepoint
%D \setlocaldimen\mydimenb 2\onepoint
%D \begingrou
%D \setlocaldimen\mydimena 3\onepoint
%D \setlocaldimen\mydimenb 4\onepoint
%D \setlocaldimen\mydimenc 5\onepoint
%D \endgroup
%D \endgroup
%D \stoptyping
%D
%D There is a little extra overhead in the overload protection but not that much.
\permanent\countdef\c_syst_local_count = 221 \c_syst_local_count = \c_syst_max_allocated_register
\permanent\countdef\c_syst_local_dimen = 222 \c_syst_local_dimen = \c_syst_local_count
\permanent\countdef\c_syst_local_skip = 223 \c_syst_local_skip = \c_syst_local_count
\permanent\countdef\c_syst_local_muskip = 224 \c_syst_local_muskip = \c_syst_local_count
\permanent\countdef\c_syst_local_box = 225 \c_syst_local_box = \c_syst_local_count
\permanent\countdef\c_syst_local_toks = 226 \c_syst_local_toks = \c_syst_local_count
\permanent\countdef\c_syst_local_read = 227 \c_syst_local_read = \c_syst_local_count
\permanent\countdef\c_syst_local_write = 228 \c_syst_local_write = \c_syst_local_count
\c_syst_max_allocated_register \numexpr\c_syst_max_allocated_register:2\relax % floor
\permanent\protected\def\syst_local_overflow#1#2{\writestatus\m!system{no room for local #1 \string#2}\wait}
\permanent\protected\def\setnewlocaldimen#1%
{\ifnum\c_syst_local_dimen>\c_syst_max_allocated_register
\advance\c_syst_local_dimen\minusone\dimendef#1\c_syst_local_dimen
\else
\syst_local_overflow_dimen#1%
\fi
#1}
\permanent\protected\def\setnewlocalcount#1%
{\ifnum\c_syst_local_count>\c_syst_max_allocated_register
\advance\c_syst_local_count\minusone
\overloaded\frozen\countdef#1\c_syst_local_count
\else
\syst_local_overflow_count#1%
\fi
#1}
\permanent\protected\def\setnewlocalskip#1%
{\ifnum\c_syst_local_skip>\c_syst_max_allocated_register
\advance\c_syst_local_skip\minusone
\overloaded\frozen\skipdef#1\c_syst_local_skip
\else
\syst_local_overflow_skip#1%
\fi
#1}
\permanent\protected\def\setnewlocalmuskip#1%
{\ifnum\c_syst_local_muskip>\c_syst_max_allocated_register
\advance\c_syst_local_muskip\minusone
\overloaded\frozen\muskipdef#1\c_syst_local_muskip
\else
\syst_local_overflow_muskip#1%
\fi
#1}
\permanent\protected\def\setnewlocaltoks#1%
{\ifnum\c_syst_local_toks>\c_syst_max_allocated_register
\advance\c_syst_local_toks\minusone
\overloaded\frozen\toksdef#1\c_syst_local_toks
\else
\syst_local_overflow_toks#1%
\fi
#1}
\permanent\protected\def\setnewlocalbox#1%
{\ifnum\c_syst_local_box>\c_syst_max_allocated_register
\advance\c_syst_local_box\minusone
\overloaded\frozen\integerdef#1\c_syst_local_box
\else
\syst_local_overflow_box#1%
\fi
\setbox#1}
\permanent\protected\def\newlocalread#1% so no set
{\ifnum\c_syst_local_read>\c_syst_max_allocated_register
\advance\c_syst_local_read\minusone
\overloaded\frozen\integerdef#1\c_syst_local_read
\else
\syst_local_overflow_read#1%
\fi}
\permanent\protected\def\newlocalwrite#1% so no set
{\ifnum\c_syst_local_write>\c_syst_max_allocated_register
\advance\c_syst_local_write\minusone
\overloaded\frozen\integerdef#1\c_syst_local_write
\else
\syst_local_overflow_write#1%
\fi}
%D The error handlers:
\permanent\protected\def\syst_local_overflow_count {\syst_local_overflow {count}}
\permanent\protected\def\syst_local_overflow_dimen {\syst_local_overflow {dimen}}
\permanent\protected\def\syst_local_overflow_skip {\syst_local_overflow {skip}}
\permanent\protected\def\syst_local_overflow_muskip{\syst_local_overflow{muskip}}
\permanent\protected\def\syst_local_overflow_toks {\syst_local_overflow {toks}}
\permanent\protected\def\syst_local_overflow_box {\syst_local_overflow {box}}
\permanent\protected\def\syst_local_overflow_read {\syst_local_overflow {read}}
\permanent\protected\def\syst_local_overflow_write {\syst_local_overflow {write}}
%D We sacrifice a little performance but save some tokens by not defining these
%D completely:
\permanent\protected\def\newlocalcount #1{\setnewlocalcount #1\zerocount }
\permanent\protected\def\newlocaldimen #1{\setnewlocaldimen #1\zeropoint }
\permanent\protected\def\newlocalskip #1{\setnewlocalskip #1\zeroskip }
\permanent\protected\def\newlocalmuskip#1{\setnewlocalmuskip#1\zeromuskip}
\permanent\protected\def\newlocaltoks #1{\setnewlocaltoks #1\emptytoks }
\permanent\protected\def\newlocalbox #1{\setnewlocalbox #1\emptybox }
%D Let's be detailed: grouplevel:inputlevel:catcodetable (bits 1 2 4)
\tracinglevels\plusthree
\permanent\protected\def\tracingcatcodes{\tracinglevels\plusseven}
%D We just report duplicate patterns being ignored:
\tracinghyphenation\plusone
%D Sometimes nicer:
\let\ifexpression\ifnumexpression
%D This will be default:
\autoparagraphmode\plusone % we need at least 1 in order to be able to switch to 2
%autoparagraphmode\plustwo % because we define two \par delimited macros
\protect \endinput
|