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
|
%D \module
%D [ file=syst-pln,
%D version=2001.11.16, % 1999.03.17, % an oldie: 1995.10.10
%D title=\CONTEXT\ System Macros,
%D subtitle=Efficient \PLAIN\ \TEX\ loading,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%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
%D a couple of primitives so that for instance font loading was
%D ignored. For those interested, this loader is found in
%D \type {syst-tex.tex}.
%D This is a stripped down version of plain \TEX. We need this
%D module to get started. Whole sections are missing here,
%D like font loading and math. Thise are taken care of in
%D dedicated modules. A few definitions are added (and
%D marked as such).
%D Characters can have special states, that can be triggered
%D by setting their category coded. Some are preset, others
%D are to be set as soon as possible, otherwise we cannot
%D define any useful macros.
%catcode`\^^@ = 9 % ascii null is ignored
%catcode`\\ = 0 % backslash is TeX escape character
\catcode`\{ = 1 % left brace is begin-group character
\catcode`\} = 2 % right brace is end-group character
\catcode`\$ = 3 % dollar sign is math shift
\catcode`\& = 4 % ampersand is alignment tab
\catcode`\# = 6 % hash mark is macro parameter character
\catcode`\^ = 7 % circumflex and uparrow are for superscripts
\catcode`\_ = 8 % underline and downarrow are for subscripts
\catcode`\^^I = 10 % ascii tab is a blank space
%catcode`\^^M = 5 % ascii return is end-line
%catcode`\% = 14 % percent sign is comment character
%catcode`\ = 10 % ascii space is blank space
%catcode`\^^? = 15 % ascii delete is invalid
\catcode`\~ = 13 % tilde is active
\catcode`\^^L = 13 % ascii form-feed
%catcode`\A = 11
%.......
%catcode`\Z = 11
%catcode`\a = 11
%.......
%catcode`\z = 11
\chardef\active = 13
\def ^^L{\par}
\def\^^M{\ } % control <return> = control <space>
\def\^^I{\ } % same for <tab>
%D In \CONTEXT, we simply ignore end||of||file tokens:
\catcode`\^^Z=9
%D First we define a simplified version of the \CONTEXT\
%D protection mechanism.
\def\unprotect{\catcode`@=11}
\def\protect {\catcode`@=12}
\unprotect
%D We do not set up mathcodes here, but postpone that to the
%D math modules.
\mathcode`\ = "8000 % \space
\mathcode`\' = "8000 % ^\prime
\mathcode`\_ = "8000 % \_
\mathcode`\^^? = "1273 % \smallint
\sfcode`\)=0
\sfcode`\'=0
\sfcode`\]=0
\chardef\@ne = 1
\chardef\tw@ = 2
\chardef\thr@@ = 3
\chardef\sixt@@n = 16
\chardef\@cclv = 255
\mathchardef\@cclvi = 256
\mathchardef\@m = 1000
\mathchardef\@M = 10000
\mathchardef\@MM = 20000
%D Pretty important definitions:
\let\bgroup={
\let\egroup=}
%D In plain \TEX\ the following explanation about the register
%D allocation mechanism is given:
%D
%D \startnarrower
%D The following counters are reserved:
%D
%D \starttabulate
%D \NC 0--9 \NC page numbering \NC \NR
%D \NC 10 \NC count allocation \NC \NR
%D \NC 11 \NC dimen allocation \NC \NR
%D \NC 12 \NC skip allocation \NC \NR
%D \NC 13 \NC muskip allocation \NC \NR
%D \NC 14 \NC box allocation \NC \NR
%D \NC 15 \NC toks allocation \NC \NR
%D \NC 16 \NC read file allocation \NC \NR
%D \NC 17 \NC write file allocation \NC \NR
%D \NC 18 \NC math family allocation \NC \NR
%D \NC 19 \NC language allocation \NC \NR
%D \NC 20 \NC insert allocation \NC \NR
%D \NC 21 \NC the most recently allocated number \NC \NR
%D \NC 22 \NC constant $-1$ \NC \NR
%D \stoptabulate
%D
%D New counters are allocated starting with 23, 24, etc. Other
%D registers are allocated starting with 10. This leaves 0
%D through 9 for the user to play with safely, except that
%D counts 0 to 9 are considered to be the page and subpage
%D numbers (since they are displayed during output). In this
%D scheme, \type {\count10} always contains the number of the
%D highest||numbered counter that has been allocated, \type
%D {\count14} the highest||numbered box, etc. Inserts are given
%D numbers 254, 253, etc., since they require a \type
%D {\count}, \type {\dimen}, \type {\skip}, and \type {\box}
%D all with the same number; \type {\count20} contains the
%D lowest-numbered insert that has been allocated. Of course,
%D \type {\box255} is reserved for \type {\output}; \type
%D {\count255}, \type {\dimen255}, and \type {\skip255} can be
%D used freely.
%D
%D It is recommended that macro designers always use \type
%D {\globa}l assignments with respect to registers numbered 1,
%D 3, 5, 7, 9, and always non||\type {\global} assignments
%D with respect to registers 0, 2, 4, 6, 8, 255. This will
%D prevent \quote {save stack buildup} that might otherwise
%D occur.
%D \stopnarrower
%D
%D We well overload some macros in \ETEX\ mode.
\count10 = 22 % allocates \count registers 23, 24, ...
\count11 = 9 % allocates \dimen registers 10, 11, ...
\count12 = 9 % allocates \skip registers 10, 11, ...
\count13 = 9 % allocates \muskip registers 10, 11, ...
\count14 = 9 % allocates \box registers 10, 11, ...
\count15 = 9 % allocates \toks registers 10, 11, ...
\count16 = -1 % allocates input streams 0, 1, ...
\count17 = -1 % allocates output streams 0, 1, ...
\count18 = 3 % allocates math families 4, 5, ...
\count19 = 0 % allocates \language codes 1, 2, ...
\count20 =255 % allocates insertion classes 254, 253, ...
\countdef\insc@unt = 20 % the insertion counter
\countdef\allocationnumber= 21 % the most recent allocation
\countdef\m@ne = 22 % a handy constant
\m@ne = -1
\def\wlog{\immediate\write\m@ne} % write on log file (only)
%D \startnarrower
%D Here are abbreviations for the names of scratch registers
%D that don't need to be allocated.
%D \stopnarrower
\countdef \count@ = 255
\dimendef \dimen@ = 0
\dimendef \dimen@i = 1 % global only
\dimendef \dimen@ii = 2
\skipdef \skip@ = 0
\toksdef \toks@ = 0
%D \startnarrower
%D Now, we define \type {\newcount}, \type {\newbox}, etc. so
%D that you can say \newcount\foo and \type {\foo} will be
%D defined (with \type {\countdef}) to be the next counter. To
%D find out which counter \type {\foo} is, you can look at
%D \type {\allocationnumber}. Since there's no \type {\boxdef}
%D command, \type {\chardef} is used to define a \type
%D {\newbox}, \type {\newinsert}, \type {\newfam}, and so on.
%D \stopnarrower
\def\newcount {\alloc@0\count \countdef \insc@unt}
\def\newdimen {\alloc@1\dimen \dimendef \insc@unt}
\def\newskip {\alloc@2\skip \skipdef \insc@unt}
\def\newmuskip {\alloc@3\muskip \muskipdef\@cclvi }
\def\newbox {\alloc@4\box \chardef \insc@unt}
\def\newtoks {\alloc@5\toks \toksdef \@cclvi }
\def\newread {\alloc@6\read \chardef \sixt@@n }
\def\newwrite {\alloc@7\write \chardef \sixt@@n }
\def\newfam {\alloc@8\fam \chardef \sixt@@n }
\def\newlanguage{\alloc@9\language\chardef \@cclvi }
\def\newhelp#1#2{\newtoks#1#1\expandafter{\csname#2\endcsname}}
\def\alloc@#1#2#3#4#5%
{\global\advance\count1#1by\@ne
\ch@ck#1#4#2% make sure there's still room
\allocationnumber=\count1#1%
\global#3#5=\allocationnumber
\wlog{\string#5=\string#2\the\allocationnumber}}
\def\newinsert#1%
{\global\advance\insc@unt by\m@ne
\ch@ck0\insc@unt\count
\ch@ck1\insc@unt\dimen
\ch@ck2\insc@unt\skip
\ch@ck4\insc@unt\box
\allocationnumber=\insc@unt
\global\chardef#1=\allocationnumber
\wlog{\string#1=\string\insert\the\allocationnumber}}
\def\ch@ck#1#2#3%
{\ifnum\count1#1<#2\else
\errmessage{No room for a new #3}
\fi}
\newdimen\maxdimen \maxdimen = 16383.99999pt
\newskip \hideskip \hideskip = -1000pt plus 1fill
\newskip \centering \centering = 0pt plus 1000pt minus 1000pt
\newdimen\p@ \p@ = 1pt
\newdimen\z@ \z@ = 0pt
\newskip \z@skip \z@skip = 0pt plus 0pt minus 0pt
\newbox \voidb@x % permanently void box register
%D We define \type {\newif} a la plain \TEX, but will
%D redefine it later. As Knuth 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
%D with \type {\iffoo}.
%D \stopnarrower
\def\newif#1%
{\count@\escapechar
\escapechar\m@ne
\expandafter\expandafter\expandafter\def\@if #1{true}{\let#1\iftrue }%
\expandafter\expandafter\expandafter\def\@if#1{false}{\let#1\iffalse}%
\@if#1{false}% the condition starts out false
\escapechar\count@}
\def\@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
%D Build||in numeric variables.
\adjdemerits = 10000
\binoppenalty = 700
\brokenpenalty = 100
\clubpenalty = 150
%day = 0
\defaulthyphenchar = `\-
\defaultskewchar = -1
\delimiterfactor = 901
\displaywidowpenalty = 50
\doublehyphendemerits = 10000
%endlinechar = `\^^M
\errorcontextlines = 5
%escapechar = `\\
\exhyphenpenalty = 50
%fam = 0
\finalhyphendemerits = 5000
%floatingpenalty = 0
%globaldefs = 0
%hangafter = 1
\hbadness = 1000
%holdinginserts = 0
\hyphenpenalty = 50
%interlinepenalty = 0
%language = 0
\lefthyphenmin = 2
\linepenalty = 10
%looseness = 0
%mag = 1000
%maxdeadcycles = 25
%month = 0
\newlinechar = -1
%outputpenalty = 0
%pausing = 0
%postdisplaypenalty = 0
\predisplaypenalty = 10000
\pretolerance = 100
\relpenalty = 500
\righthyphenmin = 3
\showboxbreadth = 5
\showboxdepth = 3
%time = 0
\tolerance = 200
%tracingcommands = 0
\tracinglostchars = 1
%tracingmacros = 0
%tracingonline = 0
%tracingoutput = 0
%tracingpages = 0
%tracingparagraphs = 0
%tracingrestores = 0
%tracingstats = 0
\uchyph = 1
\vbadness = 1000
\widowpenalty = 150
%year = 0
%D Extra numeric variables.
\newcount \interdisplaylinepenalty
\newcount \interfootnotelinepenalty
\interdisplaylinepenalty = 100
\interfootnotelinepenalty = 100
%D Build in dimension variables.
\abovedisplayshortskip = 0pt plus 3pt
\abovedisplayskip = 12pt plus 3pt minus 9pt
%baselineskip = 0pt
\belowdisplayshortskip = 7pt plus 3pt minus 4pt
\belowdisplayskip = 12pt plus 3pt minus 9pt
\boxmaxdepth = \maxdimen
\delimitershortfall = 5pt
%displayindent = 0pt
%displaywidth = 0pt
%hangindent = 0pt
\hfuzz = 0.1pt
%hoffset = 0pt
\hsize = 6.5in
%leftskip = 0pt
%lineskip = 0pt
%lineskiplimit = 0pt
%mathsurround = 0pt
\maxdepth = 4pt
\medmuskip = 4mu plus 2mu minus 4mu
\nulldelimiterspace = 1.2pt
\overfullrule = 5pt
\parfillskip = 0pt plus 1fil
\parindent = 20pt
\parskip = 0pt plus 1pt
%predisplaysize = 0pt
%rightskip = 0pt
\scriptspace = 0.5pt
%spaceskip = 0pt
\splitmaxdepth = \maxdimen
\splittopskip = 10pt
%tabskip = 0pt
\thickmuskip = 5mu plus 5mu
\thinmuskip = 3mu
\topskip = 10pt
\vfuzz = 0.1pt
%voffset = 0pt
\vsize = 8.9in
%xspaceskip = 0pt
%D Extra dimension parameters.
\newskip \bigskipamount
\newdimen \jot
\newskip \medskipamount
\newskip \normalbaselineskip
\newskip \normallineskip
\newdimen \normallineskiplimit
\newskip \smallskipamount
\bigskipamount = 12pt plus 4pt minus 4pt
\jot = 3pt
\medskipamount = 6pt plus 2pt minus 2pt
\normalbaselineskip = 12pt
\normallineskip = 1pt
\normallineskiplimit = 0pt
\smallskipamount = 3pt plus 1pt minus 1pt
%D The following shortcuts are rather standard:
\def\lq{`}
\def\rq{'}
\def\lbrack{[}
\def\rbrack{]}
\let\endgraf=\par
\let\endline=\cr
\def\space{ }
\def\empty{}
\def\null {\hbox{}}
%D The next loop construct is about the fastest you can get.
%D Beware: this macro does not support nested loops. We use
%D a namespace prefix \type {@@pln}.
\long\def\loop#1\repeat{\long\def\@@plnbody{#1}\@@plniterate}
%D The following makes \type {\loop} \unknown\ \type {\if}
%D \unknown\ \type {\repeat} skippable (clever trick):
\let\repeat=\fi
%D The original (no \type {@@pln} there):
\def\@@plniterate{\@@plnbody\let\next\@@plniterate\else\let\next\relax\fi\next}
%D A more efficient alternative:
\def\@@plniterate{\@@plnbody\expandafter\@@plniterate\else\expandafter\relax\fi}
%D An even more efficient one:
\def\@@plniterate{\@@plnbody\expandafter\@@plniterate\else\fi}
%D Counter 0 is normally used as page counter:
\countdef\pageno=0 \pageno=1 % first page is number 1
%D Beside the raw counter \type {\pageno} the \type {\folio}
%D macro provides the value.
\def\folio{\the\pageno}
%D Indeed, we don't define a real output routine yet:
\output{\box255}
%D We don't support \type {\magnification} and just consume
%D the value.
\let\magnification\count@
%D The following macro will be overloaded in \ETEX.
\def\tracingall
{\tracingonline \@ne
\tracingcommands \tw@
\tracingstats \tw@
\tracingpages \@ne
\tracingoutput \@ne
\tracinglostchars \@ne
\tracingmacros \tw@
\tracingparagraphs\@ne
\tracingrestores \@ne
\showboxbreadth \maxdimen
\showboxdepth \maxdimen
\errorstopmode}
%D Some users expect this macro to be present. This one
%D sends the hyphenated word to the terminal.
\def\showhyphens#1%
{\setbox0\vbox
{\parfillskip\z@skip
\hsize\maxdimen\tenrm
\pretolerance\m@ne
\tolerance\m@ne
\hbadness0
\showboxdepth0
\ #1}}
%D The following bunch of macros deals with basic alignment.
%D We just include them here so that they can be used if
%D needed. Normally, \CONTEXT\ users will fall back on one of
%D the three table environments.
\newcount \mscount
\newif \ifus@
\newif \if@cr
\newbox \tabs
\newbox \tabsyet
\newbox \tabsdone
\def\hidewidth % for alignment entries that can stick out
{\hskip\hideskip}
\def\ialign % initialized \halign
{\everycr{}
\tabskip\z@skip
\halign}
\def\multispan#1%
{\omit
\mscount#1\relax
\loop
\ifnum\mscount>\@ne \sp@n
\repeat}
\def\sp@n
{\span
\omit
\advance\mscount\m@ne}
\def\cleartabs
{\global\setbox\tabsyet\null
\setbox\tabs\null}
\def\settabs
{\setbox\tabs\null
\futurelet\next\sett@b}
\def\sett@b
{\ifx\next\+%
\def\nxt{\afterassignment\s@tt@b\let\nxt}%
\else
\let\nxt\s@tcols
\fi
\let\next\relax
\nxt}
\def\s@tt@b%
{\let\nxt\relax
\us@false\m@ketabbox}
\def\tabalign%
{\us@true\m@ketabbox}
\let\+\tabalign % no outer here
\def\s@tcols#1\columns%
{\count@#1%
\dimen@\hsize
\loop
\ifnum\count@>\z@ \@nother
\repeat}
\def\@nother%
{\dimen@ii\dimen@
\divide\dimen@ii\count@
\setbox\tabs\hbox{\hbox to\dimen@ii{}\unhbox\tabs}%
\advance\dimen@-\dimen@ii
\advance\count@\m@ne}
\def\m@ketabbox%
{\begingroup
\global\setbox\tabsyet\copy\tabs
\global\setbox\tabsdone\null
\def\cr
{\@crtrue\crcr\egroup\egroup
\ifus@\unvbox\z@\lastbox\fi\endgroup
\setbox\tabs\hbox{\unhbox\tabsyet\unhbox\tabsdone}}%
\setbox\z@\vbox\bgroup\@crfalse
\ialign\bgroup&\t@bbox##\t@bb@x\crcr}
\def\t@bbox
{\setbox\z@\hbox\bgroup}
\def\t@bb@x
{\if@cr
\egroup % now \box\z@ holds the column
\else
\hss\egroup
\global\setbox\tabsyet\hbox
{\unhbox\tabsyet\global\setbox\@ne\lastbox}% now \box\@ne holds its size
\ifvoid\@ne
\global\setbox\@ne\hbox to\wd\z@{}%
\else
\setbox\z@\hbox to\wd\@ne{\unhbox\z@}%
\fi
\global\setbox\tabsdone\hbox{\box\@ne\unhbox\tabsdone}%
\fi
\box\z@}
%D Users are advised not to use the following macros:
\def\hang
{\hangindent\parindent}
\def\textindent#1%
{\indent
\llap{#1\enspace}%
\ignorespaces}
\def\narrower%
{\advance\leftskip \parindent
\advance\rightskip\parindent}
%D Useful, used too, but sometimes dangerous:
\def\leavevmode{\unhbox\voidb@x}
%D We will overload these, but may need them beforehand:
\bgroup
\catcode`\^^M=\active%
\gdef\obeylines{\catcode`\^^M\active \let^^M\par}%
\global\let^^M\par%
\egroup
\def\obeyspaces{\catcode`\ \active}
{\obeyspaces\global\let =\space}
%D Useful and expected:
\def~{\penalty\@M \ } % tie
\chardef\%=`\%
\chardef\&=`\&
\chardef\#=`\#
\chardef\$=`\$
\def\_{\leavevmode \kern.06em \vbox{\hrule width.3em}}
%D Used at all?
\def\slash{/\penalty\exhyphenpenalty} % a `/' that acts like a `-'
%D Replaced later on:
\def\line {\hbox to\hsize}
\def\leftline #1{\line{#1\hss}}
\def\rightline #1{\line{\hss#1}}
\def\centerline#1{\line{\hss#1\hss}}
%D These are used by TaBlE:
\newif\ifh@
\newif\ifv@
%D Let's end in the plain way:
\def\fmtname {ConTeXt Minimized Plain TeX}
\def\fmtversion{3.1415926}
\protect \endinput
|