syst-ini.mkiv /size: 47 Kb    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=syst-ini,
3%D        version=2008.11.04, % 2001.11.16, % 1999.03.17,  % an oldie: 1995.10.10
4%D          title=\CONTEXT\ System Macros,
5%D       subtitle=Bootstrapping \TEX,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D We used to load plain \TEX\ in a special way, but redefining a couple of
15%D primitives so that for instance font loading was ignored. For those interested,
16%D this loader is found in \type {syst-tex.tex}. Some of the comment's are Don
17%D Knuths and more of it can be found in the plain \TEX\ format.
18%D
19%D Characters can have special states, that can be triggered by setting their
20%D category coded. Some are preset, others are to be set as soon as possible,
21%D otherwise we cannot define any useful macros.
22%D
23%D First we define a bunch of constants. Normally we would \type {\setconstant}
24%D but we're prestine and have no macros defined yet. Abstraction also makes it
25%D possible to avoid the \type {^^} in the input.
26
27\chardef\escapecatcode             0
28\chardef\begingroupcatcode         1
29\chardef\endgroupcatcode           2
30\chardef\mathshiftcatcode          3
31\chardef\alignmentcatcode          4
32\chardef\endoflinecatcode          5
33\chardef\parametercatcode          6
34\chardef\superscriptcatcode        7
35\chardef\subscriptcatcode          8
36\chardef\ignorecatcode             9
37\chardef\spacecatcode             10
38\chardef\lettercatcode            11
39\chardef\othercatcode             12  % finally obsolete: \let\other \othercatcode
40\chardef\activecatcode            13  % finally obsolete: \let\active\activecatcode
41\chardef\commentcatcode           14
42\chardef\invalidcatcode           15
43
44%chardef\zeroasciicode             0
45\chardef\tabasciicode              9
46\chardef\newlineasciicode         10  % don't confuse this one with \endoflineasciicode
47\chardef\formfeedasciicode        12
48\chardef\endoflineasciicode       13  % somewhat messy but this can be the active \par
49\chardef\endoffileasciicode       26
50\chardef\spaceasciicode           32
51\chardef\exclamationmarkasciicode 33 % ! used in namespace protection
52\chardef\doublequoteasciicode     34 % "
53\chardef\hashasciicode            35
54\chardef\dollarasciicode          36
55\chardef\commentasciicode         37
56\chardef\ampersandasciicode       38
57\chardef\singlequoteasciicode     39 % '
58\chardef\primeasciicode           39 % '
59\chardef\leftparentasciicode      40
60\chardef\rightparentasciicode     41
61\chardef\commaasciicode           44
62\chardef\hyphenasciicode          45
63\chardef\periodasciicode          46
64\chardef\forwardslashasciicode    47 % /
65\chardef\colonasciicode           58
66\chardef\lessthanasciicode        60 % < used as alternative verbatim {
67\chardef\morethanasciicode        62 % > used as alternative verbatim }
68\chardef\questionmarkasciicode    63 % ? used in namespace protection
69\chardef\atsignasciicode          64 % @ used in namespace protection
70\chardef\backslashasciicode       92 % `\\
71\chardef\circumflexasciicode      94
72\chardef\underscoreasciicode      95
73\chardef\leftbraceasciicode      123 % `\{
74\chardef\barasciicode            124 % `\|
75\chardef\rightbraceasciicode     125 % `\}
76\chardef\tildeasciicode          126 % `\~
77\chardef\delasciicode            127
78
79%catcode\zeroasciicode           \ignorecatcode      % `\^^@   ascii null is ignored
80\catcode\tabasciicode            \spacecatcode       % `\^^I   ascii tab is a blank space
81\catcode\formfeedasciicode       \activecatcode      % `\^^L   ascii form-feed (active, set later)
82%catcode\endoflineasciicode      \endoflinecatcode   % `\^^M   ascii return is end-line
83\catcode\endoffileasciicode      \ignorecatcode      % `\^^Z   endoffile (ignored in ConTeXt)
84%catcode\spaceasciicode          \spacecatcode       % `\      ascii space is blank space
85\catcode\hashasciicode           \parametercatcode   % `\#     hash mark is macro parameter character
86\catcode\dollarasciicode         \mathshiftcatcode   % `\$     dollar sign is math shift
87%catcode\commentasciicode        \commentcatcode     % `\%     percent sign is comment character
88\catcode\ampersandasciicode      \alignmentcatcode   % `\&     ampersand is alignment tab
89%catcode\backslashasciicode      \escapecatcode      % `\\     backslash is TeX escape character
90\catcode\circumflexasciicode     \superscriptcatcode % `\^     circumflex and uparrow are for superscripts
91\catcode\underscoreasciicode     \subscriptcatcode   % `\_     underline and downarrow are for subscripts
92\catcode\leftbraceasciicode      \begingroupcatcode  % `\{     left brace is begin-group character
93\catcode\rightbraceasciicode     \endgroupcatcode    % `\}     right brace is end-group character
94\catcode\tildeasciicode          \activecatcode      % `\~     tilde is active
95%catcode\delasciicode            \invalidcatcode     % `\^^?   ascii delete is invalid
96
97\chardef\statuswrite   128
98
99%D Initialization of primitives.
100
101\directlua {
102    local primitives = tex.extraprimitives("core","tex","etex","luatex")
103
104  % table.sort(primitives)
105
106    tex.enableprimitives("",      primitives)
107    tex.enableprimitives("normal",primitives)
108
109    function tex.enableprimitives() end
110}
111
112\def\space{ }
113\def\empty{}
114
115\letcharcode \formfeedasciicode \par    % \def ^^L{\par}  formfeed
116\letcharcode \tildeasciicode    \       %                 tilde
117\letcharcode \spaceasciicode    \space  %                 space
118
119\expandafter\def\csname\Uchar\tabasciicode      \endcsname {\ }   % \def\^^I{\ }    tab
120\expandafter\def\csname\Uchar\formfeedasciicode \endcsname {\par} % \def\^^L{\par}  formfeed
121\expandafter\def\csname\Uchar\endoflineasciicode\endcsname {\ }   % \def\^^M{\ }    return
122
123%D For now:
124
125\def\gobbleoneargument#1{} % will be defined later on anyway
126
127%D First we define a simplified version of the \CONTEXT\ protection mechanism.
128%D Later we will implement a better variant.
129
130\def\unprotect
131  {\edef\protect
132     {\catcode\atsignasciicode         \the\catcode\atsignasciicode         \relax
133      \catcode\exclamationmarkasciicode\the\catcode\exclamationmarkasciicode\relax
134      \catcode\questionmarkasciicode   \the\catcode\questionmarkasciicode   \relax
135      \catcode\underscoreasciicode     \the\catcode\underscoreasciicode     \relax
136      \let\protect\relax}%
137   \catcode\atsignasciicode         \lettercatcode
138   \catcode\exclamationmarkasciicode\lettercatcode
139   \catcode\questionmarkasciicode   \lettercatcode
140   \catcode\underscoreasciicode     \lettercatcode}
141
142\let\protect\relax
143
144\unprotect
145
146%D Some pretty important definitions:
147
148\let\bgroup={
149\let\egroup=}
150
151%D \macros
152%D   {normalbgroup,normalgroup}
153%D
154%D No comment.
155
156%D Allocation of registers is done slightly different than in plain \TEX. First of
157%D all we use different reserved counters. We also don't implement a family handler
158%D because users are not supposed to implement their own math. We reserve the lowest
159%D 31 registers for scratch purposes. Keep in mind that in the core engine some
160%D registers are reserved: counters 0 upto 9, and counter 255.
161%D
162%D As with plain \TEX\ we recommend that macro designers always use \type {\global}
163%D assignments with respect to registers numbered 1, 3, 5 \unknown\ 31, and always
164%D non||\type {\global} assignments with respect to registers 0, 2, 4, \unknown\ 30.
165%D This will prevent \quote {save stack buildup} that might otherwise occur.
166%D
167%D We reserve some registers for special (management) purposes:
168
169%   0 -  20 : scratch
170%  21 - 127 : internal
171% 128 - 254 : inserts
172% 255       : page
173% 256 -     : user
174
175\countdef   \c_syst_min_allocated_register   =    52 \c_syst_min_allocated_register   =   256 % can change
176\countdef   \c_syst_max_allocated_register   =    53 \c_syst_max_allocated_register   = 32767
177\countdef   \c_syst_min_allocated_read       =    54 \c_syst_min_allocated_read       =    -1
178\countdef   \c_syst_max_allocated_read       =    55 \c_syst_max_allocated_read       =    16
179\countdef   \c_syst_min_allocated_language   =    56 \c_syst_min_allocated_language   =     0
180\countdef   \c_syst_max_allocated_language   =    57 \c_syst_max_allocated_language   =   255
181\countdef   \c_syst_min_allocated_insert     =    58 \c_syst_min_allocated_insert     =   128
182\countdef   \c_syst_max_allocated_insert     =    59 \c_syst_max_allocated_insert     =   254
183\countdef   \c_syst_min_allocated_family     =    60 \c_syst_min_allocated_family     =   128
184\countdef   \c_syst_max_allocated_family     =    61 \c_syst_max_allocated_family     =   255
185\countdef   \c_syst_min_allocated_attribute  =    62 \c_syst_min_allocated_attribute  =  1024 % 0-1023 : private
186\countdef   \c_syst_min_allocated_write      =    63 \c_syst_min_allocated_write      =     0
187\countdef   \c_syst_max_allocated_write      =    64 \c_syst_max_allocated_write      =   127
188
189\countdef   \c_syst_last_allocated_count     =    32 \c_syst_last_allocated_count     = \c_syst_min_allocated_register
190\countdef   \c_syst_last_allocated_dimen     =    33 \c_syst_last_allocated_dimen     = \c_syst_min_allocated_register
191\countdef   \c_syst_last_allocated_skip      =    34 \c_syst_last_allocated_skip      = \c_syst_min_allocated_register
192\countdef   \c_syst_last_allocated_muskip    =    35 \c_syst_last_allocated_muskip    = \c_syst_min_allocated_register
193\countdef   \c_syst_last_allocated_box       =    36 \c_syst_last_allocated_box       = \c_syst_min_allocated_register
194\countdef   \c_syst_last_allocated_toks      =    37 \c_syst_last_allocated_toks      = \c_syst_min_allocated_register
195\countdef   \c_syst_last_allocated_read      =    38 \c_syst_last_allocated_read      = \c_syst_min_allocated_read
196\countdef   \c_syst_last_allocated_write     =    39 \c_syst_last_allocated_write     = \c_syst_min_allocated_write
197\countdef   \c_syst_last_allocated_marks     =    40 \c_syst_last_allocated_marks     = \c_syst_min_allocated_register
198\countdef   \c_syst_last_allocated_language  =    41 \c_syst_last_allocated_language  = \c_syst_min_allocated_language    % not used in context
199\countdef   \c_syst_last_allocated_insertion =    42 \c_syst_last_allocated_insertion = \c_syst_min_allocated_insert
200\countdef   \c_syst_last_allocated_family    =    43 \c_syst_last_allocated_family    = \c_syst_min_allocated_family      % not used in context
201\countdef   \c_syst_last_allocated_attribute =    44 \c_syst_last_allocated_attribute = \c_syst_min_allocated_attribute   % not used in context
202
203\countdef   \c_syst_min_counter_value =   125 \c_syst_min_counter_value = -"7FFFFFFF % beware, we use index 125 at the lua end
204\countdef   \c_syst_max_counter_value =   126 \c_syst_max_counter_value =  "7FFFFFFF % beware, we use index 126 at the lua end
205
206\countdef   \zerocount                =   120 \zerocount                =  0
207\countdef   \plusone                  =   121 \plusone                  =  1
208\countdef   \minusone                 =   122 \minusone                 = -1
209
210\countdef   \normalpagebox            =   127 \normalpagebox            = 255  % hardcoded in pdftex/xetex
211
212% Only to be used by developers in very special cases!
213
214% \def\lastallocatedcount    {\the\c_syst_last_allocated_count}
215% \def\lastallocateddimen    {\the\c_syst_last_allocated_dimen}
216% \def\lastallocatedskip     {\the\c_syst_last_allocated_skip}
217% \def\lastallocatedmuskip   {\the\c_syst_last_allocated_muskip}
218% \def\lastallocatedbox      {\the\c_syst_last_allocated_dimen}
219% \def\lastallocatedtoks     {\the\c_syst_last_allocated_toks}
220% \def\lastallocatedattribute{\the\c_syst_last_allocated_attribute}
221
222% A few traditional allocations (these might go):
223
224\countdef \count@   255 % hm, used in \newif .. todo: replace it there
225\dimendef \dimen@     0
226\dimendef \dimen@i    1 % global only
227\dimendef \dimen@ii   2
228
229%D So, effectively we start allocating from 256 and upwards. The inserts sit in the
230%D range 128 upto 254. Page numbers use the counters 0 upto 9 and the pagebox is
231%D 255. Users can use the scratch registers upto 31 without problem but all others
232%D are reserved.
233
234\let\wlog\gobbleoneargument % Let's get rid of this one.
235
236%D The allocators share a common helper macro.
237
238\protected\def\newcount   {\syst_basics_allocate\c_syst_last_allocated_count    \count   \countdef   \c_syst_max_allocated_register}
239\protected\def\newdimen   {\syst_basics_allocate\c_syst_last_allocated_dimen    \dimen   \dimendef   \c_syst_max_allocated_register}
240\protected\def\newskip    {\syst_basics_allocate\c_syst_last_allocated_skip     \skip    \skipdef    \c_syst_max_allocated_register}
241\protected\def\newmuskip  {\syst_basics_allocate\c_syst_last_allocated_muskip   \muskip  \muskipdef  \c_syst_max_allocated_register}
242\protected\def\newbox     {\syst_basics_allocate\c_syst_last_allocated_box      \box     \mathchardef\c_syst_max_allocated_register}
243\protected\def\newtoks    {\syst_basics_allocate\c_syst_last_allocated_toks     \toks    \toksdef    \c_syst_max_allocated_register}
244\protected\def\newread    {\syst_basics_allocate\c_syst_last_allocated_read     \read    \chardef    \c_syst_max_allocated_read}
245\protected\def\newwrite   {\syst_basics_allocate\c_syst_last_allocated_write    \write   \chardef    \c_syst_max_allocated_write}
246\protected\def\newmarks   {\syst_basics_allocate\c_syst_last_allocated_marks    \marks   \mathchardef\c_syst_max_allocated_register}
247\protected\def\newinsert  {\syst_basics_allocate\c_syst_last_allocated_insertion\insert  \chardef    \c_syst_max_allocated_insert}
248
249%D We don't need these in \CONTEXT:
250
251\protected\def\newlanguage{\syst_basics_allocate\c_syst_last_allocated_language \language\chardef    \c_syst_max_allocated_language}
252\protected\def\newfamily  {\syst_basics_allocate\c_syst_last_allocated_family   \fam     \chardef    \c_syst_max_allocated_family}
253
254\let\newfam\newfamily
255
256\let\newinteger  \newcount % just in case
257\let\newdimension\newdimen % just in case
258
259\firstvalidlanguage\plusone
260
261% Watch out, for the moment we disable the check for already being defined
262% later we will revert this but first all chardefs must be replaced.
263
264\protected\def\newconstant       #1{\ifdefined#1\let#1\undefined\fi\newcount#1}
265\protected\def\setnewconstant    #1{\ifdefined#1\let#1\undefined\fi\newcount#1#1} % just a number
266\protected\def\setconstant         {}                                             % dummy, no checking, so it warns
267\protected\def\setconstantvalue#1#2{\csname#1\endcsname\numexpr#2\relax}
268
269% maybe setconstant with check
270
271% %D The next definitions are really needed (in \CONTEXT):
272
273\newlinechar\newlineasciicode  \edef\outputnewlinechar{\Uchar\newlineasciicode} % {^^J}
274
275%D One reason to start high with allocation is that it permits us to allocate
276%D consecutive ranges more easily, for instance if for \MPLIB\ we want to allocate a
277%D continuous range of boxes. It also permits us to do a proper upward allocation
278%D for inserts. The current code evolved from code that dealt with older engines but
279%D as all engines now provide many registers we removed all traces.
280
281\ifdefined\writestatus \else
282   %\protected\def\writestatus#1#2{\immediate\write\statuswrite{#1: #2}}
283    \protected\def\writestatus#1#2{\message{#1: #2}}
284\fi
285
286\def\syst_basics_allocate_yes#1#2#3#4#5% last class method max name
287  {\ifnum#1<#4\relax
288     \global\advance#1\plusone
289     \global#3#5=#1\relax
290   \else
291     \writestatus{warning}{no room for \string#2\space \string#5\space (max: \number#4)}%
292   \fi}
293
294\def\syst_basics_allocate_nop#1#2#3#4#5% last class method max name
295  {\writestatus{warning}{\string#2 \string#5 is already defined (\string\relax\space it first)}}
296
297\def\syst_basics_allocate#1#2#3#4#5% last class method max name
298  {\ifx#5\undefined
299     \expandafter\syst_basics_allocate_yes
300   \else\ifx#5\relax
301     \expandafter\expandafter\expandafter\syst_basics_allocate_yes
302   \else
303     \expandafter\expandafter\expandafter\syst_basics_allocate_nop
304   \fi\fi
305   #1#2#3#4#5}
306
307%D Since the number of chars exceed 256 now, we can use \type {\chardef} instead of
308%D the more limited \type {\mathchardef}.
309
310\protected\def\newbox  {\syst_basics_allocate\c_syst_last_allocated_box  \box  \chardef\c_syst_max_allocated_register}
311\protected\def\newmarks{\syst_basics_allocate\c_syst_last_allocated_marks\marks\chardef\c_syst_max_allocated_register}
312
313%D Attributes are something very \LUATEX. In \CONTEXT\ you are not supposed to use
314%D the attributes directly but always allocate then first. For instance attribute~0
315%D is reserved for special purposes (this might change). Attributes in the range
316%D 128-1023 are private and should not be touched.
317
318\let\attributeunsetvalue\c_syst_min_counter_value % used to be \minusone
319
320\protected\def\newattribute{\syst_basics_allocate\c_syst_last_allocated_attribute\attribute\attributedef\c_syst_max_allocated_register}
321
322%D Not used by \CONTEXT\ but for instance \PICTEX\ needs it. It's a trick to force
323%D strings instead of tokens that take more memory. It's a trick to trick to force
324%D strings. This macro is never used in \CONTEXT.
325
326%protected\def\newhelp#1#2{\newtoks#1#1\expandafter{\csname#2\endcsname}}
327\protected\def\newhelp#1#2{\newtoks#1#1\expandafter{\detokenize{#2}}}
328
329%D \macros
330%D   {scratchcounter,
331%D    scratchdimen,scratchskip,scratchmuskip,
332%D    scratchbox,
333%D    scratchtoks}
334%D
335%D We now define a few scratch registers, so that successive loads at least have
336%D some available. The private ones are used in cases where we don't want to
337%D intrude on normal scratch ones.
338
339\newcount \scratchcounter  \newcount \globalscratchcounter  \newcount \privatescratchcounter
340\newdimen \scratchdimen    \newdimen \globalscratchdimen    \newdimen \privatescratchdimen
341\newskip  \scratchskip     \newskip  \globalscratchskip     \newskip  \privatescratchskip
342\newmuskip\scratchmuskip   \newmuskip\globalscratchmuskip   \newmuskip\privatescratchmuskip
343\newtoks  \scratchtoks     \newtoks  \globalscratchtoks     \newtoks  \privatescratchtoks
344\newbox   \scratchbox      \newbox   \globalscratchbox      \newbox   \privatescratchbox
345
346\newcount\scratchcounterone  \newcount\scratchcountertwo  \newcount\scratchcounterthree
347\newdimen  \scratchdimenone  \newdimen  \scratchdimentwo  \newdimen  \scratchdimenthree
348\newskip    \scratchskipone  \newskip    \scratchskiptwo  \newskip    \scratchskipthree
349\newmuskip\scratchmuskipone  \newmuskip\scratchmuskiptwo  \newmuskip\scratchmuskipthree
350\newtoks    \scratchtoksone  \newtoks    \scratchtokstwo  \newtoks    \scratchtoksthree
351\newbox      \scratchboxone  \newbox      \scratchboxtwo  \newbox      \scratchboxthree
352
353\newcount\scratchcounterfour \newcount\scratchcounterfive \newcount\scratchcountersix
354\newdimen  \scratchdimenfour \newdimen  \scratchdimenfive \newdimen  \scratchdimensix
355\newskip    \scratchskipfour \newskip    \scratchskipfive \newskip    \scratchskipsix
356\newmuskip\scratchmuskipfour \newmuskip\scratchmuskipfive \newmuskip\scratchmuskipsix
357\newtoks    \scratchtoksfour \newtoks    \scratchtoksfive \newtoks    \scratchtokssix
358\newbox      \scratchboxfour \newbox      \scratchboxfive \newbox      \scratchboxsix
359
360\newcount\globalscratchcounterone
361\newcount\globalscratchcountertwo
362\newcount\globalscratchcounterthree
363
364%D \macros
365%D   {tempstring}
366
367\let\tempstring\empty
368
369%D \macros
370%D   {scratchwidth, scratchheight, scratchdepth, scratchoffset, scratchdistance}
371%D
372%D A few more scratch dimensions:
373
374\newdimen\scratchwidth
375\newdimen\scratchheight
376\newdimen\scratchdepth
377\newdimen\scratchtotal
378
379\newdimen\scratchoffset
380\newdimen\scratchleftoffset
381\newdimen\scratchrightoffset
382\newdimen\scratchtopoffset
383\newdimen\scratchbottomoffset
384
385\newdimen\scratchdistance
386
387\newdimen\scratchhsize
388\newdimen\scratchvsize
389
390\newdimen\scratchxoffset
391\newdimen\scratchyoffset
392\newdimen\scratchhoffset
393\newdimen\scratchvoffset
394
395\newdimen\scratchxposition
396\newdimen\scratchyposition
397
398\newcount\scratchnx
399\newcount\scratchny
400
401\newcount\scratchmx
402\newcount\scratchmy
403
404\newcount\scratchmin
405\newcount\scratchmax
406
407\newcount\scratchunicode
408
409\newdimen\scratchleftskip
410\newdimen\scratchrightskip
411\newdimen\scratchtopskip
412\newdimen\scratchbottomskip
413
414%D More allocations:
415
416\newskip  \zeroskip      \zeroskip      0pt plus 0pt minus 0pt
417\newdimen \zeropoint     \zeropoint     0pt
418\newdimen \onepoint      \onepoint      1pt
419\newdimen \halfapoint    \halfapoint    0.5pt
420\newdimen \maxdimen      \maxdimen      16383.99999pt % 1073741823sp
421\newcount \maxcount      \maxcount      2147483647
422\newdimen \onebasepoint  \onebasepoint  1bp
423\newdimen \scaledpoint   \scaledpoint   1sp
424\newdimen \thousandpoint \thousandpoint 1000pt
425\newmuskip\zeromuskip    \zeromuskip    0mu
426\newmuskip\onemuskip     \onemuskip     1mu
427
428\newmuskip\muquad        \muquad        18mu
429
430\let\points   \onepoint
431\let\halfpoint\halfapoint
432
433\newtoks \emptytoks
434
435%D And even more: (todo: countdefs 60+)
436
437%newcount\minusone \minusone    -1
438\newcount\minustwo \minustwo    -2
439%chardef \zerocount              0
440%chardef \plusone                1
441\chardef \plustwo                2
442\chardef \plusthree              3
443\chardef \plusfour               4
444\chardef \plusfive               5
445\chardef \plussix                6
446\chardef \plusseven              7
447\chardef \pluseight              8
448\chardef \plusnine               9
449\chardef \plusten               10
450\chardef \pluseleven            11
451\chardef \plustwelve            12
452\chardef \plussixteen           16
453\chardef \plusfifty             50
454\chardef \plushundred          100
455\chardef \plusonehundred       100
456\chardef \plustwohundred       200
457\chardef \plusfivehundred      500
458\chardef \pluscxxvii           127
459\chardef \pluscxxviii          128
460\chardef \pluscclv             255
461\chardef \pluscclvi            256
462\chardef \plusthousand        1000
463\chardef \plustenthousand    10000
464\chardef \plustwentythousand 20000
465\chardef \medcard            32768
466\chardef \maxcard            65536 % pdftex has less mathchars
467\chardef \maxcardminusone    65535
468
469%D \macros
470%D   {doubleexpandafter,tripleexpandafter,expanded,startexpanded}
471%D
472%D A few handy shortcuts
473
474\let\singleexpandafter \expandafter
475\def\doubleexpandafter{\expandafter\expandafter\expandafter}
476\def\tripleexpandafter{\expandafter\doubleexpandafter\expandafter}
477
478%D We prefer the more readable variant than in plain \TEX. User should only
479%D use \type {\emptybox}:
480
481\newbox\voidbox  % public
482
483\let\normalhbox\hbox
484\let\normalvbox\vbox
485
486\def\unvoidbox{\unhbox\voidbox}
487\def\emptybox {\box   \voidbox}  % used in initializations so no attributes
488\def\emptyvbox{\normalvpack{}}   % no copy as we need to set attributes
489\def\emptyhbox{\normalhpack{}}   % no copy as we need to set attributes
490
491\let\leavevmode\unvoidbox % we prefer to use \dontleavehmode
492
493%D \macros
494%D   {dontcomplain}
495%D
496%D We need this one soon:
497
498\protected\def\dontcomplain
499  {\hbadness\plustenthousand
500   \vbadness\plustenthousand
501   \hfuzz   \maxdimen
502   \vfuzz   \maxdimen}
503
504%D Some expected plain variants follow. We don't reuse registers because we
505%D don't want clashes.
506
507\let     \p@             \onepoint
508\let     \m@ne           \minusone
509\let     \z@             \zeropoint
510\let     \@ne            \plusone
511\let     \tw@            \plustwo
512\let     \thr@@          \plusthree
513\let     \sixt@@n        \plussixteen
514\let     \@cclv          \pluscclv
515\let     \@cclvi         \pluscclvi
516\let     \voidb@x        \voidbox
517\newtoks \toks@        % \scratchtoks
518
519%D We define \type {\newif} a la plain \TEX, but will redefine it later. As
520%D Knuth says:
521%D
522%D \startnarrower
523%D And here's a different sort of allocation: for example,
524%D
525%D \starttyping
526%D \newif\iffoo
527%D \stoptyping
528%D
529%D creates \type {\footrue}, \type {\foofalse} to go with \type {\iffoo}.
530%D \stopnarrower
531
532% \protected\def\newif#1%
533%   {\count@\escapechar
534%    \escapechar\minusone
535%    \expandafter\expandafter\expandafter\def\new_if #1{true}{\let#1\iftrue }%
536%    \expandafter\expandafter\expandafter\def\new_if#1{false}{\let#1\iffalse}%
537%    \new_if#1{false}% the condition starts out false
538%    \escapechar\count@}
539%
540% \def\new_if#1#2%
541%   {\csname\expandafter\if@\string#1#2\endcsname}
542%
543% \bgroup % `if' is required
544%   \uccode`1=`i \uccode`2=`f \uppercase{\gdef\if@12{}}
545% \egroup
546
547% We use \csstring so there is no need to push/pop escapechar.
548% We use different names so that we get a better error message.
549%
550% \protected\def\newif#1%
551%   {\let\new_if_saved\newif
552%    \let\newif\new_if_check
553%    \expandafter\expandafter\expandafter\def\new_if_cs #1{true}{\let#1\iftrue }%
554%    \expandafter\expandafter\expandafter\def\new_if_cs#1{false}{\let#1\iffalse}%
555%    \new_if_cs#1{false}%
556%    \let\newif\new_if_saved}
557%
558% \protected\def\new_if_cs#1#2%
559%   {\csname\expandafter\newif\csstring#1#2\endcsname}
560%
561% We wrap all into one macro:
562
563\protected\def\newif#1%
564  {\let\new_if_saved\newif
565   \let\newif\new_if_check
566   \expandafter\def\csname\expandafter\newif\csstring#1true\endcsname {\let#1\iftrue }%
567   \expandafter\def\csname\expandafter\newif\csstring#1false\endcsname{\let#1\iffalse}%
568   \csname\expandafter\newif\csstring#1false\endcsname
569   \let\newif\new_if_saved}
570
571\bgroup
572   \normalexpanded{\gdef\noexpand\new_if_check\string i\string f{}}
573\egroup
574
575%D Let's test this one:
576
577\newif\ifdone
578\newif\iffound
579
580\def\htdp#1{\dimexpr\ht#1+\dp#1\relax}
581
582%D A few shortcuts:
583
584\protected\def\udef {\protected\def }
585\protected\def\ugdef{\protected\gdef}
586\protected\def\uedef{\protected\edef}
587\protected\def\uxdef{\protected\xdef}
588
589% For now:
590
591\protected\def\defUmathtopaccent  #1#2#3#4{\global\instance\protected\def#1{\Umathaccent     "#2 "#3 "#4 }}
592\protected\def\defUmathbotaccent  #1#2#3#4{\global\instance\protected\def#1{\Umathbotaccent  "#2 "#3 "#4 }}
593\protected\def\defUdelimiterover  #1#2#3#4{\global\instance\protected\def#1{\Udelimiterover  "#2 "#3     }}
594\protected\def\defUdelimiterunder #1#2#3#4{\global\instance\protected\def#1{\Udelimiterunder "#2 "#3     }}
595\protected\def\defUdelimiter      #1#2#3#4{\global\instance\protected\def#1{\Udelimiter      "#2 "#3 "#4 }}
596\protected\def\defUradical          #1#2#3{\global\instance\protected\def#1{\Uradical        "#2 "#3     }}
597\protected\def\defUroot             #1#2#3{\global\instance\protected\def#1{\Uroot           "#2 "#3     }}
598\protected\def\defUmathchar       #1#2#3#4{\global\instance\Umathchardef #1                  "#2 "#3 "#4 }
599
600%D For a while we keep the following, as systems like tikz need it. Best
601%D not use that one \CONTEXT.
602
603\let\active\activecatcode
604
605%D Constants to be used with \type {\currentgrouptype}.
606
607\chardef\bottomlevelgroupcode   =  0
608\chardef\simplegroupcode        =  1
609\chardef\hboxgroupcode          =  2
610\chardef\adjustedhboxgroupcode  =  3
611\chardef\vboxgroupcode          =  4
612\chardef\vtopgroupcode          =  5
613\chardef\aligngroupcode         =  6
614\chardef\noaligngroupcode       =  7
615\chardef\outputgroupcode        =  8
616\chardef\mathgroupcode          =  9
617\chardef\discretionarygroupcode = 10
618\chardef\insertgroupcode        = 11
619\chardef\vcentergroupcode       = 12
620\chardef\mathchoicegroupcode    = 13
621\chardef\semisimplegroupcode    = 14
622\chardef\mathshiftgroupcode     = 15
623\chardef\mathleftgroupcode      = 16
624\chardef\vadjustgroupcode       = \insertgroupcode
625
626%D Constants to be used with \type {\interactionmode}.
627
628\chardef\batchmodecode     = 0
629\chardef\nonstopmodecode   = 1
630\chardef\scrollmodecode    = 2
631\chardef\errorstopmodecode = 3
632
633%D Constants to be used with \type {\lastnodetype}. The \type {\lastnodetype}
634%D primitive is \ETEX\ compliant. The valid range is still -1 .. 15 and glyph nodes
635%D have number 0 (used to be char node) and ligature nodes are mapped to 7. That way
636%D macro packages can use the same symbolic names as in traditional \ETEX. Keep in
637%D mind that the internal node numbers are different and that there are more node
638%D types that 15. The mode parameter forces \LUAMETATEX\ to use the real node
639%D numbers.
640
641\ifdefined\internalcodesmode
642
643    \internalcodesmode\plusone
644
645  % \chardef\gluenodecode          = 12
646  % \chardef\kernnodecode          = 13
647  % \chardef\penaltynodecode       = 14
648
649\else
650
651  % \chardef\charnodecode          =  0
652  % \chardef\hlistnodecode         =  1
653  % \chardef\vlistnodecode         =  2
654  % \chardef\rulenodecode          =  3
655  % \chardef\insertnodecode        =  4
656  % \chardef\marknodecode          =  5
657  % \chardef\adjustnodecode        =  6
658  % \chardef\ligaturenodecode      =  7
659  % \chardef\discretionarynodecode =  8
660  % \chardef\whatsitnodecode       =  9
661  % \chardef\mathnodecode          = 10
662    \chardef\gluenodecode          = 11
663    \chardef\kernnodecode          = 12
664    \chardef\penaltynodecode       = 13
665  % \chardef\unsetnodecode         = 14
666  % \chardef\mathsnodecode         = 15
667
668\fi
669
670%D Constants to be used with \type {\currentiftype}. I wonder if we will ever
671%D use these in \CONTEXT. We have a few more anyway and in \LUAMETATEX\ we
672%D have different numbers. So for now let's just not define them. The
673%D previously mentioned mode parameters enables the real numbers (we have
674%D some more and they are therefore ordered differently).
675
676% \chardef\charifcode     =  1
677% \chardef\catifcode      =  2
678% \chardef\numifcode      =  3
679% \chardef\dimifcode      =  4
680% \chardef\oddifcode      =  5
681% \chardef\vmodeifcode    =  6
682% \chardef\hmodeifcode    =  7
683% \chardef\mmodeifcode    =  8
684% \chardef\innerifcode    =  9
685% \chardef\voidifcode     = 10
686% \chardef\hboxifcode     = 11
687% \chardef\vboxifcode     = 12
688% \chardef\xifcode        = 13
689% \chardef\eofifcode      = 14
690% \chardef\trueifcode     = 15
691% \chardef\falseifcode    = 16
692% \chardef\caseifcode     = 17
693% \chardef\definedifcode  = 18
694% \chardef\csnameifcode   = 19
695% \chardef\fontcharifcode = 20
696
697%D Of course we want even bigger log files, so we copied this from the \ETEX\
698%D source files.
699%D
700%D When watching such logs, beware of nasty side effects of \type {\scantokens},
701%D as in:
702%D
703%D \starttyping
704%D \bgroup
705%D   \lccode`a=12\lowercase{\xdef\whatever{a}}\egroup
706%D   \def\whatever{test \whatever test}
707%D   \scantokens\expandafter{\whatever}
708%D \egroup
709%D \stoptyping
710%D
711%D In \LUATEX\ we have ways around this.
712
713% no longer \errorstopmode cf. plain tex 3.141592653
714
715\protected\def\tracingall
716  {\tracingonline    \plusone
717   \tracingcommands  \plusthree
718   \tracingstats     \plustwo
719   \tracingpages     \plusone
720   \tracingoutput    \plusone
721   \tracinglostchars \plustwo
722   \tracingmacros    \plustwo
723   \tracingparagraphs\plusone
724   \tracingrestores  \plusone
725   \showboxbreadth   \maxdimen
726   \showboxdepth     \maxdimen
727   \tracinggroups    \plusone
728   \tracingifs       \plusone
729   \tracingscantokens\plusone
730   \tracingnesting   \plustwo
731   \tracingassigns   \plustwo}
732
733\protected\def\loggingall
734  {\tracingall
735   \tracingonline    \zerocount}
736
737\protected\def\tracingnone
738  {\tracingassigns   \zerocount
739   \tracingnesting   \zerocount
740   \tracingscantokens\zerocount
741   \tracingifs       \zerocount
742   \tracinggroups    \zerocount
743   \showboxdepth     \plusthree
744   \showboxbreadth   \plusfive
745   \tracingrestores  \zerocount
746   \tracingparagraphs\zerocount
747   \tracingmacros    \zerocount
748   \tracinglostchars \plusone
749   \tracingoutput    \zerocount
750   \tracingpages     \zerocount
751   \tracingstats     \zerocount
752   \tracingcommands  \zerocount
753   \tracingonline    \zerocount}
754
755%D When we want to see a box we can as well show all of it.
756
757\showboxdepth  \maxdimen
758\showboxbreadth\maxdimen
759
760%D Just for tracing purposes we set:
761
762\tracingstats\plusone
763
764%D Here we also save \type {\input}, more will be saved later.
765
766\ifdefined\normalinput \else \let\normalinput\input \fi
767
768%D We don't like outer commands, and we always want access to the original
769%D \type {\input} primitive.
770
771\let\normalouter\outer  \def\outer{} % no longer \relax
772
773%D To circumvent dependencies, we can postpone certain initializations to
774%D dumping time, by appending them to the \type {\everydump} token register.
775
776\ifdefined\normaldump \else \let\normaldump\dump \fi
777
778\newtoks\everydump
779
780\def\dump{\the\everydump\global\everydump\emptytoks\glet\dump\relax\normaldump}
781
782%D The same applies for the startup actions.
783
784\ifdefined\normaleveryjob \else \let\normaleveryjob\everyjob \fi
785
786\let\everyjob\relax \newtoks\everyjob
787
788\normaleveryjob{\the\everyjob}
789
790%D \macros
791%D   {newconditional,
792%D    settrue, setfalse,
793%D    ifconditional,then}
794%D
795%D \TEX's lacks boolean variables, although the \PLAIN\ format implements \type
796%D {\newif}. The main disadvantage of this scheme is that it takes three hash table
797%D entries. A more memory saving alternative is presented here. A conditional is
798%D defined by:
799%D
800%D \starttyping
801%D \newconditional\doublesided
802%D \setfalse
803%D \stoptyping
804%D Setting a conditional is done by \type{\settrue} and
805%D \type{\setfalse}:
806%D
807%D \starttyping
808%D \settrue\doublesided
809%D \setfalse
810%D \stoptyping
811%D while testing is accomplished by:
812%D
813%D \starttyping
814%D \ifconditional\doublesided  ... \else ... \fi
815%D \setfalse
816%D \stoptyping
817%D We cannot use the simple scheme:
818%D
819%D \starttyping
820%D \def\settrue #1{\let#1=\iftrue}
821%D \def\setfalse#1{\let#1=\iffalse}
822%D \stoptyping
823%D
824%D Such an implementation gives problems with nested conditionals. The next
825%D implementation is about as fast and just as straightforward:
826
827\let\conditionalfalse\plusone    % maybe we will have a dedicated count/chardef
828\let\conditionaltrue \zerocount  % maybe we will have a dedicated count/chardef
829
830\protected\def\settrue #1{\let#1\conditionaltrue }
831\protected\def\setfalse#1{\let#1\conditionalfalse}
832
833\protected\def\settruevalue #1{\expandafter\let\csname#1\endcsname\conditionaltrue }
834\protected\def\setfalsevalue#1{\expandafter\let\csname#1\endcsname\conditionalfalse}
835
836\let\newconditional\setfalse
837\let\ifconditional \ifcase
838
839\let\then\relax % so that we can say: \ifnum1>2\then -)
840
841\def\truecondition {\iftrue}
842\def\falsecondition{\iffalse}
843
844%D \macros
845%D   {newmacro,setnewmacro,newfraction}
846%D
847%D Let's be complete and also introduce some definers. These are not mandate
848%D but handy for grepping.
849
850\protected\def\newmacro   #1{\let#1\empty}
851\protected\def\setnewmacro#1{\let#1}
852
853\def\!!zerocount{0}
854\def\!!plusone  {1}
855
856\protected\def\newfraction#1{\let#1\!!plusone}
857
858%D It would be handy to have a primitive \type {\unless\ifcase} because then we
859%D could use nicer values. Anyhow, this conditional code used to be in the \type
860%D {syst-aux} module but is now promoted to here.
861
862%D \macros
863%D   {ifzeropt}
864%D
865%D The next macro is both cosmetic and byte saving. It is pretty \type
866%D {\if}||safe too. It can be used in cases like:
867%D
868%D \starttyping
869%D \ifzeropt \somedimen ... \else ... \fi
870%D \stoptyping
871
872\let\ifzeropt\ifcase
873
874% these token list helpers might move to syst-aux.mkiv
875%
876% we assume a \cs. not toks0 or so
877%
878% \protected\def\appendtotoks #1#{\def\temp{#1}\afterassignment\doappendtotoks \scratchtoks=}
879% \protected\def\prependtotoks#1#{\def\temp{#1}\afterassignment\doprependtotoks\scratchtoks=}
880
881\newtoks\t_syst_toks_temp \let\m_syst_toks_temp\t_syst_toks_temp
882
883\protected\def\appendtotoks #1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_append_l \t_syst_toks_temp=}
884\protected\def\prependtotoks#1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_prepend_l\t_syst_toks_temp=}
885
886% \def\syst_toks_append {\m_syst_toks_temp\expandafter\expandafter\expandafter{\expandafter\the\expandafter\m_syst_toks_temp\the\t_syst_toks_temp}}}
887% \def\syst_toks_prepend{\m_syst_toks_temp\expandafter\expandafter\expandafter{\expandafter\the\expandafter\t_syst_toks_temp\the\m_syst_toks_temp}}}
888
889\protected\def\globalappendtotoks #1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_append_g \t_syst_toks_temp=}
890\protected\def\globalprependtotoks#1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_prepend_g\t_syst_toks_temp=}
891
892\def\syst_toks_append_l {\normalexpanded{\m_syst_toks_temp{\the\m_syst_toks_temp\the\t_syst_toks_temp}}}
893\def\syst_toks_prepend_l{\normalexpanded{\m_syst_toks_temp{\the\t_syst_toks_temp\the\m_syst_toks_temp}}}
894
895\def\syst_toks_append_g {\global\syst_toks_append_l }
896\def\syst_toks_prepend_g{\global\syst_toks_prepend_l}
897
898\protected\def\addtotoks      #1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_add_l\let\next}
899\protected\def\globaladdtotoks#1{\let\m_syst_toks_temp#1\afterassignment\syst_toks_add_g\let\next}
900
901\def\syst_toks_add_l{\m_syst_toks_temp\expandafter\bgroup\the\m_syst_toks_temp}
902\def\syst_toks_add_g{\global\syst_toks_add_l}
903
904\protected\def\addtotokscs      #1#2{#1{\the#1#2}}        % saves a few bytes
905\protected\def\globaladdtotokscs#1#2{\global#1{\the#1#2}} % saves a few bytes
906
907%D \macros
908%D   {begcsname}
909%D
910%D Handy for \ETEX-only usage (avoids making \type {\relax}'s:
911
912% \def\begcsname#1\endcsname{\ifcsname#1\endcsname\csname#1\endcsname\fi}
913
914\let\begcsname\begincsname
915
916%D Now come a few macros that might be needed in successive loading. We redefine the
917%D \type {\par} primitive pretty soon so that we get the equivalents right.
918
919% too tricky: \par is use more often than a par starts so we have too much change
920% that we get assymetrical behaviour
921%
922% \newtoks\everyendpar
923%
924% \protected\def\endpar{\the\everyendpar\normalpar}
925% \protected\def\par   {\endpar}
926%
927% \protected\def\reseteverypar
928%   {\everypar   \emptytoks
929%    \everyendpar\emptytoks}
930
931\protected\def\reseteverypar
932  {\everypar\emptytoks}
933
934\let\endgraf\par
935\let\endline\cr
936
937\protected\def\null{\hpack{}}
938
939%D The following two might be overloaded later on but some modules need then
940%D earlier. These functionality is reflected in the name and will not change.
941
942% \bgroup
943%     \catcode`\^^M=\activecatcode%
944%     \gdef\obeylines{\catcode`\^^M\activecatcode \let^^M\par}%
945%     \glet^^M\par%
946% \egroup
947%
948% \bgroup
949%     \gdef\obeyspaces{\catcode`\ \activecatcode}%
950%     \obeyspaces\glet =\space%
951% \egroup
952
953\def\obeylines {\catcode\endoflineasciicode\activecatcode\letcharcode\endoflineasciicode\par}
954\def\obeyspaces{\catcode\spaceasciicode    \activecatcode\letcharcode\spaceasciicode    \space}
955
956% %D A constant:
957%
958% \let\endoflinetoken=^^M
959
960%D Also needed might be a simple loop structure and we borrow plain \TEX's one
961%D as it is often expected to be present and it is about the fastest you can
962%D get. Beware: this macro does not support nested loops. We use a namespace
963%D prefix \type {@@pln}.
964
965\def\loop#1\repeat{\def\@@plnbody{#1}\@@plniterate} % might go
966
967%D The following makes \type {\loop} \unknown\ \type {\if} \unknown\ \type
968%D {\repeat} skippable (clever trick):
969
970\let\repeat\fi % so both \loop and \repeat are reserved words!
971
972%D The original (no \type {@@pln} there):
973%D
974%D \starttyping
975%D \def\@@plniterate{\@@plnbody\let\next\@@plniterate\else\let\next\relax\fi\next}
976%D \stoptyping
977%D
978%D A more efficient alternative:
979%D
980%D \starttyping
981%D \def\@@plniterate{\@@plnbody\expandafter\@@plniterate\else\expandafter\relax\fi}
982%D \stoptyping
983%D
984%D An even more efficient one:
985
986\def\@@plniterate{\@@plnbody\expandafter\@@plniterate\else\fi}
987
988%D We don't define a real output routine yet but at least get rid of pages:
989
990\output{\shipout\box\normalpagebox}
991
992%D Although we don't add pagenumbers yet we alias the default register used
993%D for counting pages:
994
995\countdef\pageno\zerocount \pageno\plusone % first page is number 1
996
997%D Beside the raw counter \type {\pageno} the \type {\folio} macro provides
998%D the value.
999
1000\def\folio{\the\pageno} % kind of expected and therefore reserved
1001
1002%D The following registers are kind of standard and (for the moment) we define
1003%D them here. This might change.
1004
1005\newskip \bigskipamount    \bigskipamount   = 12pt plus 4pt minus 4pt
1006\newskip \medskipamount    \medskipamount   =  6pt plus 2pt minus 2pt
1007\newskip \smallskipamount  \smallskipamount =  3pt plus 1pt minus 1pt
1008
1009\baselineskip  = 12pt
1010\lineskip      =  1pt
1011\lineskiplimit =  0pt
1012
1013%D Sometimes kerns make more sense than glue but we need to be in the
1014%D right mode:
1015
1016\protected\def\vkern   {\ifhmode\par           \fi\kern}
1017\protected\def\hkern   {\ifvmode\dontleavehmode\fi\kern}
1018
1019\protected\def\vpenalty{\ifhmode\par           \fi\penalty}
1020\protected\def\hpenalty{\ifvmode\dontleavehmode\fi\penalty}
1021
1022%D Again a few kind-of-extensions the core. These come from plain \TEX\ but
1023%D are probably not used in \CONTEXT.
1024
1025\newskip \hideskip   \hideskip  = -1000pt plus 1fill
1026\newskip \centering  \centering = 0pt plus 1000pt minus 1000pt
1027
1028\def\hidewidth % for alignment entries that can stick out
1029  {\hskip\hideskip}
1030
1031\def\ialign % initialized \halign
1032  {\everycr\emptytoks
1033   \tabskip\zeroskip
1034   \halign}
1035
1036\newcount \mscount
1037
1038\def\spanomit{\span\omit} % bypass error message
1039
1040\def\multispan#1%
1041  {\omit
1042   \mscount#1\relax
1043   \loop
1044     \ifnum\mscount>\plusone
1045       \spanomit \advance\mscount\minusone
1046   \repeat}
1047
1048%D For the \LUATEX\ backend (overloaded anyway):
1049
1050\ifdefined\pdfvariable
1051
1052    \pdfvariable compresslevel       \plusthree
1053    \pdfvariable objcompresslevel    \plusone
1054  % \pdfvariable recompress          \zerocount
1055    \pdfvariable decimaldigits       \plussix
1056    \pdfvariable gamma               \plusthousand
1057    \pdfvariable imageresolution     300
1058    \pdfvariable imageapplygamma     \zerocount
1059    \pdfvariable imagegamma          2200
1060    \pdfvariable imagehicolor        \plusone
1061    \pdfvariable imageaddfilename    \plusone
1062    \pdfvariable pkresolution        1200
1063    \pdfvariable inclusioncopyfonts  \plusone
1064    \pdfvariable inclusionerrorlevel \zerocount
1065    \pdfvariable gentounicode        \plusone
1066    \pdfvariable omitcidset          \plusone
1067    \pdfvariable omitcharset         \plusone
1068    \pdfvariable pagebox             \zerocount
1069  % \pdfvariable majorversion      % \plusone
1070    \pdfvariable minorversion        \plusseven
1071    \pdfvariable uniqueresname       \zerocount
1072    \pdfvariable horigin             1in
1073    \pdfvariable vorigin             1in
1074  % \pdfvariable linkmargin          \zeropoint
1075  % \pdfvariable destmargin          \zeropoint
1076  % \pdfvariable threadmargin        \zeropoint
1077  % \pdfvariable xformmargin         \zeropoint
1078    \pdfvariable pkfixeddpi          \plusone
1079    \pdfvariable ignoreunknownimages \zerocount
1080
1081\fi
1082
1083\let\nopdfcompression        \relax
1084\let\onlypdfobjectcompression\relax
1085\let\maximumpdfcompression   \relax
1086\let\normalpdfcompression    \relax
1087
1088\ifdefined\outputmode
1089    \outputmode \zerocount % we generate the format in this mode
1090\fi
1091
1092%D Basic status stuff.
1093
1094\newif\ifproductionrun
1095
1096%D For those who expect this \unknown
1097
1098\ifx\fmtname   \undefined \def\fmtname   {ConTeXt Initial TeX} \fi
1099\ifx\fmtversion\undefined \def\fmtversion{3.1415926}           \fi
1100
1101%D A few bonus macros:
1102
1103\def\modulonumber#1#2{\the\numexpr#2-((((#2+(#1/2))/#1)-1)*#1)\relax}
1104\def\dividenumber#1#2{\the\numexpr(#2-(#1/2))/#1\relax}
1105
1106\ifdefined\texenginename \else
1107    \edef\texenginename{\directlua{tex.print(LUATEXENGINE)}}
1108\fi
1109
1110\ifdefined\texengineversion \else
1111    \edef\texengineversion{\directlua{tex.print(LUATEXVERSION)}}
1112\fi
1113
1114\ifdefined\texenginefunctionality \else
1115    \edef\texenginefunctionality{\directlua{tex.print(LUATEXFUNCTIONALITY)}}
1116\fi
1117
1118%D We have no reason not to enable this:
1119
1120\savingvdiscards\plusone
1121
1122%D We only can set this one via directives (system.synctex) and we only support
1123%D the context variant. This will go away completely.
1124
1125\let\synctex\undefined \newcount\synctex \let\normalsynctex\synctex
1126
1127%D We get rid of the funny \TEX\ offset defaults of one inch by setting them to zero.
1128
1129\voffset\zeropoint \let\voffset\relax \newdimen\voffset \let\normalvoffset\voffset
1130\hoffset\zeropoint \let\hoffset\relax \newdimen\hoffset \let\normalhoffset\hoffset
1131
1132\ifdefined\pageleftoffset
1133    \let\pageleftoffset  \hoffset \let\normalpageleftoffset  \hoffset
1134    \let\pagerightoffset \hoffset \let\normalpagerightoffset \hoffset
1135    \let\pagetopoffset   \voffset \let\normalpagetopoffset   \voffset
1136    \let\pagebottomoffset\voffset \let\normalpagebottomoffset\voffset
1137\fi
1138
1139%D Handy (this will change, again).
1140
1141\ifdefined\suppresslongerror        \suppresslongerror        \plusone  \fi
1142\ifdefined\suppressoutererror       \suppressoutererror       \plusone  \fi
1143\ifdefined\suppressmathparerror     \suppressmathparerror     \plusone  \fi
1144\ifdefined\suppressifcsnameerror    \suppressifcsnameerror    \plusone  \fi
1145\ifdefined\suppressfontnotfounderror\suppressfontnotfounderror\zerocount\fi
1146
1147\let     \suppresslongerror        \relax
1148\newcount\suppresslongerror                           \let\normalsuppresslongerror        \suppresslongerror
1149\let     \suppressoutererror       \suppresslongerror \let\normalsuppressoutererror       \suppresslongerror
1150\let     \suppressmathparerror     \suppresslongerror \let\normalsuppressmathparerror     \suppresslongerror
1151\let     \suppressifcsnameerror    \suppresslongerror \let\normalsuppressifcsnameerror    \suppresslongerror
1152\let     \suppressfontnotfounderror\suppresslongerror \let\normalsuppressfontnotfounderror\suppresslongerror
1153
1154\matheqnogapstep\zerocount % for now
1155
1156%D For as long as we share code between \MKIV\ and \LMTX\ we need these:
1157
1158\ifdefined\overloadmode \else
1159    \newcount\overloadmode
1160    %
1161    \let\frozen    \empty
1162    \let\tolerant  \empty
1163    \let\overloaded\empty
1164    \let\aliased   \empty
1165    \let\permanent \empty
1166    \let\immutable \empty
1167    \let\mutable   \empty
1168    \let\instance  \empty
1169    \let\noaligned \empty
1170    \let\enforced  \empty
1171    %
1172    \let\unletfrozen\gobbleoneargument
1173    \let\letfrozen  \gobbleoneargument
1174    \def\letcsname  {\expandafter\let \csname}
1175    \def\defcsname  {\expandafter\def \csname}
1176    \def\edefcsname {\expandafter\edef\csname}
1177    %
1178    \let\pushoverloadmode\relax
1179    \let\popoverloadmode\relax
1180
1181    \let\pushrunstate\relax
1182    \let\poprunstate \relax
1183\fi
1184
1185%D Now we define a few helpers that we need in a very early stage. We have no
1186%D message system yet but redundant definitions are fatal anyway.
1187
1188\newcount\c_syst_helpers_n_of_namespaces \c_syst_helpers_n_of_namespaces\pluseight % 1-8 reserved for catcodes
1189
1190\def\v_interfaces_prefix_template_system{\number    \c_syst_helpers_n_of_namespaces>>}
1191%def\v_interfaces_prefix_template_system{\characters\c_syst_helpers_n_of_namespaces>>} % no \characters yet
1192
1193\protected\def\installsystemnamespace#1%
1194  {\ifcsname ??#1\endcsname
1195     \immediate\write\statuswrite{fatal error: duplicate system namespace '#1'}%
1196     \expandafter\normalend
1197   \else
1198     \global\advance\c_syst_helpers_n_of_namespaces\plusone
1199     \expandafter\edef\csname ??#1\endcsname{\v_interfaces_prefix_template_system}%
1200   \fi}
1201
1202%D It makes more sense to have these here:
1203
1204\let\normalsuperscript  \Usuperscript
1205\let\normalsubscript    \Usubscript
1206\let\normalnosuperscript\Unosuperscript
1207\let\normalnosubscript  \Unosubscript
1208\let\normalstartimath   \Ustartmath
1209\let\normalstopimath    \Ustopmath
1210\let\normalstartdmath   \Ustartdisplaymath
1211\let\normalstopdmath    \Ustopdisplaymath
1212
1213%D Also better here:
1214
1215\def\wildcardsymbol{*}
1216
1217%D Get rid of this, we don't need it. If we ever need to check the order we will
1218%D use proper symbolic constants.
1219
1220\let\eTeXglueshrinkorder \undefined
1221\let\eTeXgluestretchorder\undefined
1222
1223%D Experiment:
1224
1225\ifdefined\glyphdimensionsmode \else \newcount\glyphdimensionsmode \fi
1226
1227\glyphdimensionsmode\plusone
1228
1229%D For completeness (tokenizer commands have complements), so this one complements
1230%D \type {\detokenize}, like \type {\expanded} and \type {\unexpanded}. Not that we
1231%D ever needed this one:
1232
1233\ifdefined \tokenized \else
1234    \def\tokenized#1{\scantextokens\expandafter{\normalexpanded{#1}}}
1235\fi
1236
1237\ifdefined \unhpack \else
1238    \let\unhpack\unhbox
1239    \let\unvpack\unvbox
1240\fi
1241
1242%D Needed:
1243
1244\let\nexttoken\relax
1245
1246%D We need to disable this feature (comes from pdftex) because it not only messes up
1247%D the nested content and wrappers (like in the page builder) but also is rather
1248%D confusing wrt grouping. In \CONTEXT\ we don't redefine \type {\par} anyway, so
1249%D best not expose this feature.
1250
1251\ifdefined\partokenname
1252    \let\partokencontext\relax
1253    \newcount\partokencontext
1254    \let\partokenname\gobbleoneargument
1255\fi
1256
1257%D In case we load \LMTX\ code.
1258
1259\ifdefined\autoparagraphmode \else
1260    \newcount\autoparagraphmode
1261\fi
1262
1263\let\advanceby \advance
1264\let\multiplyby\multiply
1265\let\divideby  \divide
1266
1267\protect \endinput
1268