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