| 1 |
|
| 2 |
% This is a stripped-down version of etex.src, meant as companion to |
| 3 |
% minim-plain.tex. |
| 4 |
% |
| 5 |
% It follows e-TeX V2.1;0-luatex2. |
| 6 |
% |
| 7 |
% The following has been removed: |
| 8 |
% - Module loading |
| 9 |
% - Version checks |
| 10 |
% |
| 11 |
% The following has been retained: |
| 12 |
% - Language handling (somewhat simplified) |
| 13 |
% - Tracing and logging extensions |
| 14 |
% - The \eTeX symbol |
| 15 |
% - Register allocation |
| 16 |
|
| 17 |
\catcode `\@=\catcode `\A |
| 18 |
|
| 19 |
% Define the language-handling commands |
| 20 |
|
| 21 |
\def \uselanguage #1% |
| 22 |
{\ifcsname lang@#1\endcsname |
| 23 |
\language=\csname lang@#1\endcsname |
| 24 |
\lefthyphenmin=\csname lhm@#1\endcsname |
| 25 |
\righthyphenmin=\csname rhm@#1\endcsname |
| 26 |
\ifcsname lu@texhyphen@loaded@\the\language\endcsname \else |
| 27 |
\global\expandafter\def\csname |
| 28 |
lu@texhyphen@loaded@\the\language\endcsname{}% |
| 29 |
\directlua{ |
| 30 |
if not status.ini_version then |
| 31 |
require("luatex-hyphen") |
| 32 |
luatexhyphen.loadlanguage("\luatexluaescapestring{#1}", |
| 33 |
\the\language) |
| 34 |
end}% |
| 35 |
\fi |
| 36 |
\ifdefined\uselanguage@hook \uselanguage@hook{#1}\fi |
| 37 |
\else |
| 38 |
\begingroup\errorcontextlines=0\relax |
| 39 |
\errhelp {You are trying to use a language which has not previously |
| 40 |
been defined; remember that any language you want to use |
| 41 |
will need to have been specified at the time the format |
| 42 |
was created.% |
| 43 |
}% |
| 44 |
\errmessage {Language #1 undefined.}\endgroup |
| 45 |
\fi} |
| 46 |
|
| 47 |
\def \addlanguage #1#2#3#4#5{% language patterns exceptions lhm rhm |
| 48 |
\expandafter\newlanguage \csname lang@#1\endcsname |
| 49 |
\expandafter\chardef \csname lhm@#1\endcsname=#4 |
| 50 |
\expandafter\chardef \csname rhm@#1\endcsname=#5 |
| 51 |
\csname if\directlua{% do we want to skip this language now? |
| 52 |
require("luatex-hyphen") |
| 53 |
if (luatexhyphen.lookupname("\luatexluaescapestring{#1}") == nil) |
| 54 |
or (\number\csname lang@#1\endcsname == 0) then |
| 55 |
tex.sprint("false") % no, load it (execute 'else' part) |
| 56 |
else |
| 57 |
tex.sprint("true") % yes, skip |
| 58 |
end}\endcsname |
| 59 |
\else |
| 60 |
\uselanguage {#1}% |
| 61 |
\input #2 |
| 62 |
\if *#3*\else \input #3 \fi |
| 63 |
\edef \fmtversion {\fmtversion/#1}% |
| 64 |
\fi |
| 65 |
\ifdefined\addlanguage@hook \addlanguage@hook{#1}\fi} |
| 66 |
|
| 67 |
% Decrement \count 19, because \newlanguage will increment it again |
| 68 |
|
| 69 |
\advance \count 19 by -1 |
| 70 |
|
| 71 |
% We are about to try to process a user/site-specific file "language.def", |
| 72 |
% which establishes a Babel-like language selection environment. |
| 73 |
|
| 74 |
\input language.def |
| 75 |
|
| 76 |
% All that was just to set up natural language handling... |
| 77 |
% The "real" work of "etex.src", however, is to augment the non-primitives |
| 78 |
% of Plain.TeX to incorporate e-TeX specific features, and to add new |
| 79 |
% non-primitives to simplify access to new e-TeX specific primitives. |
| 80 |
|
| 81 |
\message {Augmenting the Plain TeX definitions:} |
| 82 |
\message {\string \tracingall;} |
| 83 |
|
| 84 |
\def \tracingall |
| 85 |
{\tracingonline=\@ne |
| 86 |
\tracingcommands=\thr@@ % plain.tex has \tw@ |
| 87 |
\tracingstats=\tw@ |
| 88 |
\tracingpages=\@ne |
| 89 |
\tracingoutput=\@ne |
| 90 |
\tracinglostchars=\tw@ % plain.tex has \@ne |
| 91 |
\tracingmacros=\tw@ |
| 92 |
\tracingparagraphs=\@ne |
| 93 |
\tracingrestores=\@ne |
| 94 |
\showboxbreadth=\maxdimen |
| 95 |
\showboxdepth=\maxdimen |
| 96 |
\errorstopmode |
| 97 |
\tracinggroups=\@ne |
| 98 |
\tracingifs=\@ne |
| 99 |
\tracingscantokens=\@ne |
| 100 |
\tracingnesting=\@ne |
| 101 |
\tracingassigns=\tw@ |
| 102 |
} |
| 103 |
|
| 104 |
\message {Adding new e-TeX definitions:} |
| 105 |
|
| 106 |
\message {\string \eTeX,} |
| 107 |
\def \eTeX {$\varepsilon$-\TeX} %%% the simple version, not suitable for maths; |
| 108 |
|
| 109 |
\message {\string \loggingall,} |
| 110 |
\def \loggingall {\tracingall \tracingonline=\z@} |
| 111 |
|
| 112 |
\message {\string \tracingnone,} |
| 113 |
\def \tracingnone |
| 114 |
{\tracingassigns=\z@ |
| 115 |
\tracingnesting=\z@ |
| 116 |
\tracingscantokens=\z@ |
| 117 |
\tracingifs=\z@ |
| 118 |
\tracinggroups=\z@ |
| 119 |
\showboxdepth=\thr@@ |
| 120 |
\showboxbreadth=5 |
| 121 |
\tracingrestores=\z@ |
| 122 |
\tracingparagraphs=\z@ |
| 123 |
\tracingmacros=\z@ |
| 124 |
\tracinglostchars=\@ne |
| 125 |
\tracingoutput=\z@ |
| 126 |
\tracingpages=\z@ |
| 127 |
\tracingstats=\z@ |
| 128 |
\tracingcommands=\z@ |
| 129 |
\tracingonline=\z@ |
| 130 |
} |
| 131 |
|
| 132 |
\message {register allocation;} |
| 133 |
|
| 134 |
\newcount \et@xins % our insertion counter (\insc@unt is used differently) |
| 135 |
|
| 136 |
% We have to adjust the Plain TeX register allocation counts for our |
| 137 |
% slightly modified book-keeping: |
| 138 |
|
| 139 |
\advance \count 10 by 1 % \count 10=23 % allocates \count registers 23, 24, ... |
| 140 |
\advance \count 11 by 1 % \count 11=10 % allocates \dimen registers 10, 11, ... |
| 141 |
\advance \count 12 by 1 % \count 12=10 % allocates \skip registers 10, 11, ... |
| 142 |
\advance \count 13 by 1 % \count 13=10 % allocates \muskip registers 10, 11, ... |
| 143 |
\advance \count 14 by 1 % \count 14=10 % allocates \box registers 10, 11, ... |
| 144 |
\advance \count 15 by 1 % \count 15=10 % allocates \toks registers 10, 11, ... |
| 145 |
\advance \count 16 by 1 % \count 16=0 % allocates input streams 0, 1, ... |
| 146 |
\advance \count 17 by 1 % \count 17=0 % allocates output streams 0, 1, ... |
| 147 |
\advance \count 18 by 1 % \count 18=4 % allocates math families 4, 5, ... |
| 148 |
\advance \count 19 by 1 % \count 19=0 % allocates \language codes 0, 1, ... |
| 149 |
|
| 150 |
\et@xins=\insc@unt % \et@xins=255 % allocates insertions 254, 253, ... |
| 151 |
|
| 152 |
% We don't change the Plain TeX definitions of \newcount, etc., but the |
| 153 |
% \alloc@ macro doing the actual work is redefined. |
| 154 |
|
| 155 |
% When the normal register pool for \count, \dimen, \skip, \muskip, |
| 156 |
% \box, or \toks registers is exhausted, we switch to the extended pool. |
| 157 |
|
| 158 |
\def \alloc@ #1#2#3#4#5% |
| 159 |
{\ifnum \count 1#1 < #4% make sure there's still room |
| 160 |
\allocationnumber=\count 1#1 |
| 161 |
\global \advance \count 1#1 by \@ne |
| 162 |
\global #3#5=\allocationnumber |
| 163 |
\wlog {\string #5=\string #2\the \allocationnumber}% |
| 164 |
\else \ifnum #1 < 6 |
| 165 |
\begingroup \escapechar=\m@ne |
| 166 |
\expandafter \alloc@@ \expandafter {\string #2}#5% |
| 167 |
\else |
| 168 |
\errmessage {No room for a new #2}% |
| 169 |
\fi |
| 170 |
\fi |
| 171 |
} |
| 172 |
|
| 173 |
% The \expandafter construction used here allows the generation of |
| 174 |
% \newcount and \globcount from #1=count. Moreover (and more important) |
| 175 |
% this construction avoids the appearance of \outer macros inside |
| 176 |
% macro definitions or conditionals. |
| 177 |
|
| 178 |
\def \alloc@@ #1#2% |
| 179 |
{\endgroup % restore \escapechar |
| 180 |
\message {Normal \csname#1\endcsname register pool exhausted, |
| 181 |
switching to extended pool.}% |
| 182 |
\global \expandafter |
| 183 |
\let \csname new#1\expandafter \endcsname \csname glob#1\endcsname |
| 184 |
\csname new#1\endcsname#2% |
| 185 |
} |
| 186 |
|
| 187 |
% We do change the Plain TeX definition of \newinsert |
| 188 |
|
| 189 |
\outer \def \newinsert #1%make sure there's still room for ... |
| 190 |
{\ch@ck 0 \et@xins \count % ... a \count, ... |
| 191 |
{\ch@ck 1 \et@xins \dimen % ... \dimen, ... |
| 192 |
{\ch@ck 2 \et@xins \skip % ... \skip, ... |
| 193 |
{\ch@ck 4 \et@xins \box % ... and \box register |
| 194 |
{\global \advance \et@xins by \m@ne |
| 195 |
\unless |
| 196 |
\ifnum \insc@unt < \et@xins |
| 197 |
\global \insc@unt=\et@xins |
| 198 |
\fi |
| 199 |
\allocationnumber=\et@xins |
| 200 |
\global \chardef #1=\allocationnumber |
| 201 |
\wlog {\string #1=\string \insert \the \allocationnumber}% |
| 202 |
}% |
| 203 |
}% |
| 204 |
}% |
| 205 |
}% |
| 206 |
} |
| 207 |
|
| 208 |
\def \ch@ck #1#2#3#4% |
| 209 |
{\ifnum \count 1#1 < #2#4\else \errmessage {No room for a new #3}\fi} |
| 210 |
|
| 211 |
% And we define \reserveinserts, so that you can say \reserveinserts{17} |
| 212 |
% in order to reserve room for up to 17 additional insertion classes that will |
| 213 |
% not be taken away by \newcount, \newdimen, \newskip, or \newbox. |
| 214 |
|
| 215 |
\outer \def \reserveinserts#1% |
| 216 |
{\global \insc@unt=\numexpr \et@xins \ifnum #1 > \z@ -#1\fi \relax} |
| 217 |
|
| 218 |
\message {extended register allocation;} |
| 219 |
|
| 220 |
% Now, we define \globcount, \globbox, etc., so that you can say |
| 221 |
% \globcount\foo and \foo will be defined (with \countdef) to be the |
| 222 |
% next count register from the vastly larger but somewhat less efficient |
| 223 |
% extended register pool. We also define \loccount, etc., but these |
| 224 |
% register definitions are local to the current group. |
| 225 |
|
| 226 |
\count 260=277 % globally allocates \count registers 277, 278, ... |
| 227 |
\count 261=\@cclvi % globally allocates \dimen registers 256, 257, ... |
| 228 |
\count 262=\@cclvi % globally allocates \skip registers 256, 257, ... |
| 229 |
\count 263=\@cclvi % globally allocates \muskip registers 256, 257, ... |
| 230 |
\count 264=\@cclvi % globally allocates \box registers 256, 257, ... |
| 231 |
\count 265=\@cclvi % globally allocates \toks registers 256, 257, ... |
| 232 |
\count 266=\@ne % globally allocates \marks classes 1, 2, ... |
| 233 |
|
| 234 |
\def \et@xmaxregs {32768} |
| 235 |
|
| 236 |
\count 270=\et@xmaxregs % locally allocates \count registers 32767, 32766, ... |
| 237 |
\count 271=\et@xmaxregs % ditto for \dimen registers |
| 238 |
\count 272=\et@xmaxregs % ditto for \skip registers |
| 239 |
\count 273=\et@xmaxregs % ditto for \muskip registers |
| 240 |
\count 274=\et@xmaxregs % ditto for \box registers |
| 241 |
\count 275=\et@xmaxregs % ditto for \toks registers |
| 242 |
\count 276=\et@xmaxregs % ditto for \marks classes |
| 243 |
|
| 244 |
% \count registers 256-259 and 267-269 are not (yet) used |
| 245 |
|
| 246 |
\outer \def \globcount {\et@xglob 0 \count \countdef} |
| 247 |
\def \loccount {\et@xloc 0 \count \countdef} |
| 248 |
\outer \def \globdimen {\et@xglob 1 \dimen \dimendef} |
| 249 |
\def \locdimen {\et@xloc 1 \dimen \dimendef} |
| 250 |
\outer \def \globskip {\et@xglob 2 \skip \skipdef} |
| 251 |
\def \locskip {\et@xloc 2 \skip \skipdef} |
| 252 |
\outer \def \globmuskip {\et@xglob 3 \muskip \muskipdef} |
| 253 |
\def \locmuskip {\et@xloc 3 \muskip \muskipdef} |
| 254 |
\outer \def \globbox {\et@xglob 4 \box \mathchardef} |
| 255 |
\def \locbox {\et@xloc 4 \box \mathchardef} |
| 256 |
\outer \def \globtoks {\et@xglob 5 \toks \toksdef} |
| 257 |
\def \loctoks {\et@xloc 5 \toks \toksdef} |
| 258 |
\outer \def \globmarks {\et@xglob 6 \marks \mathchardef} |
| 259 |
\def \locmarks {\et@xloc 6 \marks \mathchardef} |
| 260 |
|
| 261 |
\let\newmark=\globmarks %%% 2.0;14 |
| 262 |
\let\newmarks=\globmarks |
| 263 |
|
| 264 |
\def \et@xglob #1#2#3#4% |
| 265 |
{\et@xchk #1#2% make sure there's still room |
| 266 |
{\allocationnumber=\count 26#1 |
| 267 |
\global \advance \count 26#1 by \@ne |
| 268 |
\global #3#4=\allocationnumber |
| 269 |
\wlog {\string #4=\string #2\the \allocationnumber}% |
| 270 |
}% |
| 271 |
} |
| 272 |
|
| 273 |
\def \et@xloc#1#2#3#4% |
| 274 |
{\et@xchk #1#2% make sure there's still room |
| 275 |
{\advance \count 27#1 by \m@ne |
| 276 |
\allocationnumber=\count 27#1 |
| 277 |
#3#4=\allocationnumber |
| 278 |
\wlog {\string #4=\string #2\the \allocationnumber \space (local)}% |
| 279 |
}% |
| 280 |
} |
| 281 |
|
| 282 |
\def \et@xchk #1#2#3% |
| 283 |
{\ifnum \count 26#1 < \count 27#1 |
| 284 |
#3% |
| 285 |
\else |
| 286 |
\errmessage {No room for a new #2}% |
| 287 |
\fi |
| 288 |
} |
| 289 |
|
| 290 |
% Next we define \globcountblk, \loccountblk, etc., so that one can |
| 291 |
% write \globcountblk\foo{17} and \foo will be defined (with \mathchardef) |
| 292 |
% as the first (the zeroth?) of a block of 17 consecutive registers. |
| 293 |
% Thus the user is intended to reference elements <\foo+0> to <\foo+n-1>, |
| 294 |
% where n is the length of the block allocated. |
| 295 |
|
| 296 |
\outer \def \globcountblk {\et@xgblk 0 \count} |
| 297 |
\def \loccountblk {\et@xlblk 0 \count} |
| 298 |
\outer \def \globdimenblk {\et@xgblk 1 \dimen} |
| 299 |
\def \locdimenblk {\et@xlblk 1 \dimen} |
| 300 |
\outer \def \globskipblk {\et@xgblk 2 \skip} |
| 301 |
\def \locskipblk {\et@xlblk 2 \skip} |
| 302 |
\outer \def \globmuskipblk {\et@xgblk 3 \muskip} |
| 303 |
\def \locmuskipblk {\et@xlblk 3 \muskip} |
| 304 |
\outer \def \globboxblk {\et@xgblk 4 \box} |
| 305 |
\def \locboxblk {\et@xlblk 4 \box} |
| 306 |
\outer \def \globtoksblk {\et@xgblk 5 \toks} |
| 307 |
\def \loctoksblk {\et@xlblk 5 \toks} |
| 308 |
\outer \def \globmarksblk {\et@xgblk 6 \marks} |
| 309 |
\def \locmarksblk {\et@xlblk 6 \marks} |
| 310 |
|
| 311 |
% And, both to provide a higher-level interface to the block allocation |
| 312 |
% scheme, and to demonstrate possible applications of the new \...expr |
| 313 |
% primitives, we also define \globcountvector and \loccountvector (etc) |
| 314 |
% which allow the user to access elements with embedded arithmetic, as in |
| 315 |
|
| 316 |
% \globcountvector \foo {12} |
| 317 |
% \foo {\count 0 + 3} = \foo {\count 1 * 2} |
| 318 |
|
| 319 |
\outer \def \globcountvector {\et@xgvec 0 \count} |
| 320 |
\def \loccountvector {\et@xlvec 0 \count} |
| 321 |
\outer \def \globdimenvector {\et@xgvec 1 \dimen} |
| 322 |
\def \locdimenvector {\et@xlvec 1 \dimen} |
| 323 |
\outer \def \globskipvector {\et@xgvec 2 \skip} |
| 324 |
\def \locskipvector {\et@xlvec 2 \skip} |
| 325 |
\outer \def \globmuskipvector {\et@xgvec 3 \muskip} |
| 326 |
\def \locmuskipvector {\et@xlvec 3 \muskip} |
| 327 |
\outer \def \globboxvector {\et@xgvec 4 \box} |
| 328 |
\def \locboxvector {\et@xlvec 4 \box} |
| 329 |
\outer \def \globtoksvector {\et@xgvec 5 \toks} |
| 330 |
\def \loctoksvector {\et@xlvec 5 \toks} |
| 331 |
\outer \def \globmarksvector {\et@xgvec 6 \marks} |
| 332 |
\def \locmarksvector {\et@xlvec 6 \marks} |
| 333 |
|
| 334 |
\def \et@xgblk #1#2#3#4% |
| 335 |
{\et@xchkblk #1#2{#4}% make sure there's still room |
| 336 |
{\allocationnumber=\count 26#1 |
| 337 |
\global \advance \count 26#1 by #4% |
| 338 |
\global \mathchardef #3=\allocationnumber |
| 339 |
\wlog {\string #3=\string #2blk{\number #4} at \the \allocationnumber}% |
| 340 |
}% |
| 341 |
} |
| 342 |
|
| 343 |
\def \et@xlblk #1#2#3#4% |
| 344 |
{\et@xchkblk #1#2{#4}% make sure there's still room |
| 345 |
{\advance \count 27#1 by -#4% |
| 346 |
\allocationnumber=\count 27#1 |
| 347 |
\mathchardef #3=\allocationnumber |
| 348 |
\wlog {\string #3=\string #2blk{\number #4} |
| 349 |
at \the \allocationnumber \space (local)% |
| 350 |
}% |
| 351 |
}% |
| 352 |
} |
| 353 |
|
| 354 |
\begingroup |
| 355 |
\catcode `\# = 12 |
| 356 |
\gdef \et@xhash {#} |
| 357 |
\endgroup |
| 358 |
|
| 359 |
\def \et@xgvec #1#2#3#4% |
| 360 |
{\et@xchkblk #1#2{#4}% make sure there's still room |
| 361 |
{\allocationnumber=\count 26#1 |
| 362 |
\global \advance \count 26#1 by #4% |
| 363 |
\ifx #2\box |
| 364 |
\def \2{}% |
| 365 |
\else \ifx #2\marks |
| 366 |
\def \2{}% |
| 367 |
\else |
| 368 |
\def \2{\string #2}% |
| 369 |
\fi |
| 370 |
\fi |
| 371 |
\xdef #3##1{\2 \noexpand \numexpr \the \allocationnumber+##1\relax}% |
| 372 |
\wlog {\string #3 {\et@xhash 1} = |
| 373 |
\2 {\the \allocationnumber+\et@xhash 1} (global #2 vector)% |
| 374 |
}% |
| 375 |
}% |
| 376 |
} |
| 377 |
|
| 378 |
\def \et@xlvec #1#2#3#4% |
| 379 |
{\et@xchkblk #1#2{#4}% make sure there's still room |
| 380 |
{\advance \count 27#1 by -#4% |
| 381 |
\allocationnumber=\count27#1 |
| 382 |
\mathchardef #3=\allocationnumber |
| 383 |
\ifx #2\box |
| 384 |
\def \2{}% |
| 385 |
\else \ifx #2\marks |
| 386 |
\def \2{}% |
| 387 |
\else |
| 388 |
\def \2{\string #2}% |
| 389 |
\fi |
| 390 |
\fi |
| 391 |
\edef #3##1{\2 \noexpand \numexpr \the \allocationnumber+##1\relax}% |
| 392 |
\wlog {\string #3 {\et@xhash 1} = |
| 393 |
\2 {\the \allocationnumber+\et@xhash 1} (local #2 vector)% |
| 394 |
}% |
| 395 |
}% |
| 396 |
} |
| 397 |
|
| 398 |
\def \et@xchkblk #1#2#3#4% |
| 399 |
{\ifnum #3 < \z@ |
| 400 |
\errmessage {Negative register block size \number #3}% |
| 401 |
\else \ifnum \numexpr \count 26#1+#3 > \count 27#1 |
| 402 |
\errmessage {No room for new #2block of size \number#3}% |
| 403 |
\else |
| 404 |
#4% |
| 405 |
\fi |
| 406 |
\fi |
| 407 |
} |
| 408 |
|
| 409 |
% And finally re-catcode commercial-at |
| 410 |
|
| 411 |
\catcode `\@=12 |
| 412 |
|
| 413 |
|