Debian Codegraph @

texmf-dist/tex/latex/etex-pkg/etex.sty

raw
1 % \iffalse meta-comment
2 %
3 % Copyright 1997, 1998, 2008 2015 2016 LaTeX Project and Peter Breitenlohner.
4 %
5 % This file (etex.sty) may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3 of
7 % this license or (at your option) any later version. The latest
8 % version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2003/12/01 or later.
12 %
13 % This work has the LPPL maintenance status "maintained".
14 %
15 % The Current Maintainer of this work is David Carlisle.
16 % https://github.com/davidcarlisle/dpctex/issues
17 % \fi
18
19 \NeedsTeXFormat{LaTeX2e}
20 \ProvidesPackage{etex}
21 % [1997/08/12 v0.1 eTeX basic definition package (DPC)]
22 % [1998/03/26 v2.0 eTeX basic definition package (PEB)]
23 % [2015/03/02 v2.1 eTeX basic definition package (PEB,DPC)]
24 % [2015/07/06 v2.2 eTeX basic definition package (PEB,DPC)]
25 % [2015/07/08 v2.3 eTeX basic definition package (PEB,DPC)]
26 % [2015/09/02 v2.4 eTeX basic definition package (PEB,DPC)]
27 % [2016/01/07 v2.5 eTeX basic definition package (PEB,DPC)]
28 % [2016/01/11 v2.6 eTeX basic definition package (PEB,DPC)]
29 [2016/08/01 v2.7 eTeX basic definition package (PEB,DPC)]
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
33 %% A basic interface to some etex primitives, closely modeled on
34 %% etex.src and etexdefs.lib provided by the core etex team.
35
36 %% The etex.src `module' system is not copied here, the standard
37 %% LaTeX package option mechanism is used instead,
38 %% however the package options match the module names.
39 %% (Currently grouptypes, interactionmodes, nodetypes, iftypes.)
40 %% The individual type names are different too: We use, e.g.,
41 %%
42 %% `\bottomleveltype' and `\simplegrouptype' instead of
43 %% `\grouptypes{bottomlevel}' and `\grouptypes{simple}'.
44
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
47 %% Other Comments...
48
49 %% The names of the `interactionmodes' are not too good.
50 %% In particular \scroll and \batch are likely to clash with existing
51 %% uses. These names have been changed into \batchinteractionmode,
52 %% \scrollinteractionmode etc.
53 %% Similarly, the names of the `groupetypes' have been changed, in
54 %% particular \mathgroup would conflict with the LaTeX kernel.
55
56 %% \etex logo could have the same trick as \LaTeXe to pick up a bold
57 %% epsilon when needed. (Not done here, I hate wasting tokens on logos.)
58 %% This version does have a \m@th not in the original.
59
60 %% The \globcountvector, \loccountvector, etc. allocation macros are
61 %% not (yet) implemented.
62
63 %% Currently if run on a standard TeX, the package generates an error.
64 %% Perhaps it should instead load some code to try to fake
65 %% the new etex primitives in that case???
66 %% Likewise, the package generates an error when used with e-TeX V 1
67
68 %% The etex.src language mechanism is not copied here. That facility
69 %% does not use any of the etex features. LaTeX should be customised
70 %% using the same hyphen.cfg mechanism as for a format built with a
71 %% standard TeX.
72
73 %% David Carlisle
74
75 %% Upgraded for e-TeX V 2.0
76 %% Peter Breitenlohner
77
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80
81
82 \ifx\eTeXversion\@undefined
83 \PackageError{etex}
84 {This package may only be run using an\MessageBreak
85 etex in extended mode}
86 {Perhaps you forgot the `*' when making the format with (e)initex.%
87 }
88 \fi
89
90 \ifnum\eTeXversion<2
91 \PackageError{etex}
92 {This package requires e-TeX V 2}
93 {You are probably using the obsolete e-TeX V 1.%
94 }
95 \fi
96
97 % 2.2
98 % Check if the new latex 2015/01/01 allocation is already using
99 % extended reisters. If so it is too late to change allocation scheme.
100 % Older versions of LaTeX would have given an error when the classic
101 % TeX registers were all allocated, but newer formats allocate from
102 % the extended range, so usually this package is not needed.
103 \@tempswafalse
104 \ifnum\count10>\@cclv\@tempswatrue\else
105 \ifnum\count11>\@cclv\@tempswatrue\else
106 \ifnum\count12>\@cclv\@tempswatrue\else
107 \ifnum\count13>\@cclv\@tempswatrue\else
108 \ifnum\count14>\@cclv\@tempswatrue\else
109 \ifnum\count15>\@cclv\@tempswatrue
110 \fi\fi\fi\fi\fi\fi
111
112 \if@tempswa
113 \PackageWarningNoLine{etex}{%
114 Extended allocation already in use.\MessageBreak
115 etex.sty code will not be used.\MessageBreak
116 To force etex package to load, add\MessageBreak
117 \string\RequirePackage{etex}\MessageBreak
118 at the start of the document}
119
120 % 2.5 define the global allocation to be the standard ones
121 % as extended allocation is already in use. Helps with
122 % compatibility with some packages that use these commands
123 % after loading etex.
124 % 2.6 avoid error from outer if used with (e)plain
125 \expandafter\let\csname globcount\expandafter\endcsname
126 \csname newcount\endcsname
127 \expandafter\let\csname globdimen\expandafter\endcsname
128 \csname newdimen\endcsname
129 \expandafter\let\csname globskip\expandafter\endcsname
130 \csname newskip\endcsname
131 \expandafter\let\csname globmuskip\expandafter\endcsname
132 \csname newmuskip\endcsname
133 \expandafter\let\csname globtoks\expandafter\endcsname
134 \csname newtoks\endcsname
135 \expandafter\let\csname globmarks\expandafter\endcsname
136 \csname newmarks\endcsname
137 % end of 2.5/2.6 change
138
139 \expandafter\endinput\fi
140
141 % End of 2.2 addition.
142
143 % 2.3 move option handling after the above error checks.
144 \DeclareOption{grouptypes}{\catcode`\G=9}
145 \DeclareOption{interactionmodes}{\catcode`\I=9}
146 \DeclareOption{nodetypes}{\catcode`\N=9}
147 \DeclareOption{iftypes}{\catcode`\C=9}
148 \DeclareOption{localalloclog}{\let\et@xwlog\wlog} % the default
149 \DeclareOption{localallocnolog}{\let\et@xwlog\@gobble} % be quiet
150 \DeclareOption{localallocshow}{\let\et@xwlog\typeout} % debugging
151 % End of 2.3 addition.
152
153 % v2.7
154 % \extrafloats does not work with this package
155 % but make it give a sensible error, not mis-parse \ifnum.
156 %
157 % Note that using \extrafloats earlier might not be safe as
158 % it could in principle clash with registers used for local allocation.
159 % However it probably works (as local allocation is used locally...).
160 % A better fix would be not to load this package with current LaTeX.
161 % This current etex package is just provided to force the old behaviour
162 % and such documents should not be using new features such as \extrafloats).
163 \ifdefined\extrafloats
164 \def\extrafloats#1{%
165 \PackageError{etex}{%
166 \noexpand\extrafloats is incompatible with etex.sty allocation.\MessageBreak
167 Try using \noexpand\extrafloats before loading etex}%
168 \@ehc}
169 \fi
170 % end of v2.7 change
171
172 \def\eTeX{%
173 $\m@th\varepsilon$-\TeX}
174
175 \def\tracingall{%
176 \tracingcommands\thr@@ % etex
177 \tracingstats\tw@
178 \tracingpages\@ne
179 \tracinglostchars\tw@ % etex
180 \tracingmacros\tw@
181 \tracingparagraphs\@ne
182 \tracingrestores\@ne
183 \tracinggroups\@ne % etex
184 \tracingifs\@ne % etex
185 \tracingscantokens\@ne % etex
186 \tracingnesting\@ne % etex
187 \tracingassigns\@ne % etex
188 \errorcontextlines\maxdimen
189 \showoutput}
190
191 \def\loggingall{%
192 \tracingall
193 \tracingonline\z@}
194
195 \def\tracingnone{%
196 \tracingonline\z@
197 \showboxdepth\m@ne
198 \showboxbreadth\m@ne
199 \tracingoutput\z@
200 \errorcontextlines\m@ne
201 \tracingassigns\z@
202 \tracingnesting\z@
203 \tracingscantokens\z@
204 \tracingifs\z@
205 \tracinggroups\z@
206 \tracingrestores\z@
207 \tracingparagraphs\z@
208 \tracingmacros\z@
209 \tracinglostchars\@ne
210 \tracingpages\z@
211 \tracingstats\z@
212 \tracingcommands\z@}
213
214 %% Register allocation
215 %% We have to adjust the Plain TeX / LaTeX register allocation counts
216 %% for our slightly modified book-keeping, but first we allocate our
217 %% insertion counter \et@xins, because \insc@ount of Plain TeX / LaTeX
218 %% will be used differently.
219
220 \newcount\et@xins
221
222 \advance\count10 by 1 % \count10=23 % allocates \count registers 23, 24, ...
223 \advance\count11 by 1 % \count11=10 % allocates \dimen registers 10, 11, ...
224 \advance\count12 by 1 % \count12=10 % allocates \skip registers 10, 11, ...
225 \advance\count13 by 1 % \count13=10 % allocates \muskip registers 10, 11, ...
226 \advance\count14 by 1 % \count14=10 % allocates \box registers 10, 11, ...
227 \advance\count15 by 1 % \count15=10 % allocates \toks registers 10, 11, ...
228 \advance\count16 by 1 % \count16=0 % allocates input streams 0, 1, ...
229 \advance\count17 by 1 % \count17=0 % allocates output streams 0, 1, ...
230 \advance\count18 by 1 % \count18=4 % allocates math families 4, 5, ...
231 \advance\count19 by 1 % \count19=0 % allocates \language codes 0, 1, ...
232
233 \et@xins=\insc@unt % \et@xins=255 % allocates insertions 254, 253, ...
234
235
236 %% To ensure working in LaTeX 2015 release do define \newcount etc
237 %% with their pre 2015 LaTeX definitions
238 \def\newcount{\alloc@0\count\countdef\insc@unt}
239 \def\newdimen{\alloc@1\dimen\dimendef\insc@unt}
240 \def\newskip{\alloc@2\skip\skipdef\insc@unt}
241 \def\newmuskip{\alloc@3\muskip\muskipdef\@cclvi}
242 \def\newbox{\alloc@4\box\chardef\insc@unt}
243 \def\newtoks{\alloc@5\toks\toksdef\@cclvi}
244 \def\newread{\alloc@6\read\chardef\sixt@@n}
245 \def\newwrite{\alloc@7\write\chardef\sixt@@n}
246 \def\new@mathgroup{\alloc@8\mathgroup\chardef\sixt@@n}
247 \let\newfam\new@mathgroup
248 \def\newlanguage{\alloc@9\language\chardef\@cclvi}
249
250 %% When the normal register pool for \count, \dimen, \skip, \muskip,
251 %% \box, or \toks registers is exhausted, we switch to the extended pool.
252
253 \def\alloc@#1#2#3#4#5%
254 {\ifnum\count1#1<#4% make sure there's still room
255 \allocationnumber\count1#1
256 \global\advance\count1#1\@ne
257 \global#3#5\allocationnumber
258 \wlog{\string#5=\string#2\the\allocationnumber}%
259 \else\ifnum#1<6
260 \begingroup \escapechar\m@ne
261 \expandafter\alloc@@\expandafter{\string#2}#5%
262 \else\errmessage{No room for a new #2}\fi\fi
263 }
264
265 %% The \expandafter construction used here allows the generation of
266 %% \newcount and \globcount from #1=count.
267
268 \def\alloc@@#1#2%
269 {\endgroup % restore \escapechar
270 \wlog{Normal \csname#1\endcsname register pool exhausted,
271 switching to extended pool.}%
272 \global\expandafter\let
273 \csname new#1\expandafter\endcsname
274 \csname glob#1\endcsname
275 \csname new#1\endcsname#2%
276 }
277
278 %% We do change the LaTeX definition of \newinsert
279
280 \def\newinsert#1{% make sure there's still room for ...
281 \ch@ck0\et@xins\count{% ... a \count, ...
282 \ch@ck1\et@xins\dimen{% ... \dimen, ...
283 \ch@ck2\et@xins\skip{% ... \skip, ...
284 \ch@ck4\et@xins\box{% ... and \box register
285 \global\advance\et@xins\m@ne
286 \unless\ifnum\insc@unt<\et@xins \global\insc@unt\et@xins \fi
287 \allocationnumber\et@xins
288 \global\chardef#1\allocationnumber
289 \wlog{\string#1=\string\insert\the\allocationnumber}}}}}}
290
291 \def\ch@ck#1#2#3#4%
292 {\ifnum\count1#1<#2#4\else\errmessage{No room for a new #3}\fi}
293
294 %% And we define \reserveinserts, so that you can say \reserveinserts{17}
295 %% in order to reserve room for up to 17 additional insertion classes, that
296 %% will not be taken away by \newcount, \newdimen, \newskip, or \newbox.
297
298 % 2.4 Remove \outer to match LaTeX allocations
299 % which are never \outer unlike plain TeX.
300
301 %\outer
302 \def\reserveinserts#1%
303 {\global\insc@unt\numexpr \et@xins \ifnum#1>\z@ -#1\fi \relax}
304
305 % Now, we define \globcount, \globbox, etc., so that you can say
306 % \globcount\foo and \foo will be defined (with \countdef) to be the
307 % next count register from the vastly larger but somewhat less efficient
308 % extended register pool. We also define \loccount, etc., but these
309 % register definitions are local to the current group.
310
311 \count260=277 % globally allocates \count registers 277, 278, ...
312 \count261=256 % globally allocates \dimen registers 256, 257, ...
313 \count262=256 % globally allocates \skip registers 256, 257, ...
314 \count263=256 % globally allocates \muskip registers 256, 257, ...
315 \count264=256 % globally allocates \box registers 256, 257, ...
316 \count265=256 % globally allocates \toks registers 256, 257, ...
317 \count266=1 % globally allocates \marks classes 1, 2, ...
318
319 \count270=32768 % locally allocates \count registers 32767, 32766, ...
320 \count271=32768 % ditto for \dimen registers
321 \count272=32768 % ditto for \skip registers
322 \count273=32768 % ditto for \muskip registers
323 \count274=32768 % ditto for \box registers
324 \count275=32768 % ditto for \toks registers
325 \count276=32768 % ditto for \marks classes
326
327 % \count registers 256-259 and 267-269 are not (yet) used
328
329 % \def \et@xglob #1#2#3#4% <offset>, <type>, <method>, <register>
330 % \def \et@xloc #1#2#3#4% <offset>, <type>, <method>, <register>
331
332 \def \globcount {\et@xglob 0\count \countdef}
333 \def \loccount {\et@xloc 0\count \countdef}
334 \def \globdimen {\et@xglob 1\dimen \dimendef}
335 \def \locdimen {\et@xloc 1\dimen \dimendef}
336 \def \globskip {\et@xglob 2\skip \skipdef}
337 \def \locskip {\et@xloc 2\skip \skipdef}
338 \def \globmuskip {\et@xglob 3\muskip \muskipdef}
339 \def \locmuskip {\et@xloc 3\muskip \muskipdef}
340 \def \globbox {\et@xglob 4\box \mathchardef}
341 \def \locbox {\et@xloc 4\box \mathchardef}
342 \def \globtoks {\et@xglob 5\toks \toksdef}
343 \def \loctoks {\et@xloc 5\toks \toksdef}
344 \def \globmarks {\et@xglob 6\marks \mathchardef}
345 \def \locmarks {\et@xloc 6\marks \mathchardef}
346
347 \let\newmarks=\globmarks %% this used to be \newmark for e-TeX V 1.1
348
349 \def\et@xglob#1#2#3#4%
350 {\et@xchk#1#2{% make sure there's still room
351 \allocationnumber=\count26#1%
352 \global\advance\count26#1\@ne
353 \global#3#4\allocationnumber
354 \wlog{\string#4=\string#2\the\allocationnumber}}%
355 }
356
357 \def\et@xloc#1#2#3#4%
358 {\et@xchk#1#2{% make sure there's still room
359 \advance\count27#1by\m@ne
360 \allocationnumber=\count27#1%
361 #3#4=\allocationnumber
362 \et@xwlog{\string#4=\string#2\the\allocationnumber\space(local)}}%
363 }
364
365 %% The allocation messages for local allocations use \et@xwlog, such that
366 %% these messages can easily be switched on/off
367
368 \let\et@xwlog=\wlog
369
370 \def\et@xchk#1#2#3%
371 {\ifnum\count26#1<\count27#1 #3\else\errmessage{No room for a new #2}\fi}
372
373 % Next we define \globcountblk, \loccountblk, etc., so that you can
374 % say \globcountblk\foo{17} and \foo will be defined (with \mathchardef)
375 % as the first (the zeroth?) of a block of 17 consecutive registers.
376 % Thus the user is intended to reference elements <\foo+0> to <\foo+n-1>,
377 % where n is the length of the block allocated.
378
379 % \def \et@xgblk #1#2#3#4% <offset>, <type>, <register>, <size>
380 % \def \et@xlblk #1#2#3#4% <offset>, <type>, <register>, <size>
381
382 \def\globcountblk {\et@xgblk 0\count }
383 \def\loccountblk {\et@xlblk 0\count }
384 \def\globdimenblk {\et@xgblk 1\dimen }
385 \def\locdimenblk {\et@xlblk 1\dimen }
386 \def\globskipblk {\et@xgblk 2\skip }
387 \def\locskipblk {\et@xlblk 2\skip }
388 \def\globmuskipblk {\et@xgblk 3\muskip }
389 \def\locmuskipblk {\et@xlblk 3\muskip }
390 \def\globboxblk {\et@xgblk 4\box }
391 \def\locboxblk {\et@xlblk 4\box }
392 \def\globtoksblk {\et@xgblk 5\toks }
393 \def\loctoksblk {\et@xlblk 5\toks }
394 \def\globmarksblk {\et@xgblk 6\marks }
395 \def\locmarksblk {\et@xlblk 6\marks }
396
397 % \def\et@xchkblk#1#1#3#4% <offset>, <type>, <size>, <action>
398
399 \def\et@xgblk#1#2#3#4%
400 {\et@xchkblk#1#2{#4}% make sure there's still room
401 {\allocationnumber\count26#1%
402 \global\advance\count26#1by#4%
403 \global\mathchardef#3\allocationnumber
404 \wlog{\string#3=\string#2blk{\number#4} at
405 \the\allocationnumber}%
406 }%
407 }
408
409 \def\et@xlblk#1#2#3#4%
410 {\et@xchkblk#1#2{#4}% make sure there's still room
411 {\advance\count27#1-#4%
412 \allocationnumber\count27#1%
413 \mathchardef#3\allocationnumber
414 \et@xwlog{\string#3=\string#2blk{\number#4} at
415 \the\allocationnumber\space(local)}%
416 }%
417 }
418
419 \def\et@xchkblk#1#2#3#4%
420 {\ifnum#3<\z@
421 \errmessage{Negative register block size \number#3}%
422 \else\ifnum\numexpr\count26#1+#3>\count27#1%
423 \errmessage{No room for new #2block of size \number#3}%
424 \else #4\fi \fi
425 }
426
427 \catcode`\G=14
428 \catcode`\I=14
429 \catcode`\N=14
430 \catcode`\C=14
431
432 \ProcessOptions
433
434 %% Declare names for `grouptypes'
435
436 G \chardef \bottomleveltype = 0 % for the outside world
437 G \chardef \simplegrouptype = 1 % for local structure only
438 G \chardef \hboxgrouptype = 2 % for `\hbox{}'
439 G \chardef \adjustedhboxgrouptype = 3 % for `\hbox{}' in vertical mode
440 G \chardef \vboxgrouptype = 4 % for `\vbox{}'
441 G \chardef \vtopgrouptype = 5 % for `\vtop{}'
442 G \chardef \aligngrouptype = 6 % for `\halign{}', `\valign{}'
443 G \chardef \noaligngrouptype = 7 % for `\noalign{}'
444 G \chardef \outputgrouptype = 8 % for output routine
445 G \chardef \mathgrouptype = 9 % for, e.g, `^{}'
446 G \chardef \discgrouptype = 10 % for `\discretionary{}{}{}'
447 G \chardef \insertgrouptype = 11 % for `\insert{}', `\vadjust{}'
448 G \chardef \vcentergrouptype = 12 % for `\vcenter{}'
449 G \chardef \mathchoicegrouptype = 13 % for `\mathchoice{}{}{}{}'
450 G \chardef \semisimplegrouptype = 14 % for `\begingroup...\endgroup'
451 G \chardef \mathshiftgrouptype = 15 % for `$...$'
452 G \chardef \mathleftgrouptype = 16 % for `\left...\right'
453
454 %% Declare names for `interactionmodes'
455
456 I \chardef \batchinteractionmode = 0 % omits all stops and omits terminal output
457 I \chardef \nonstopinteractionmode = 1 % omits all stops
458 I \chardef \scrollinteractionmode = 2 % omits error stops
459 I \chardef \errorstopinteractionmode = 3 % stops at every opportunity to interact
460
461 %% Declare names for `nodetypes'
462
463 N \chardef \charnode = 0 % character nodes
464 N \chardef \hlistnode = 1 % hlist nodes
465 N \chardef \vlistnode = 2 % vlist nodes
466 N \chardef \rulenode = 3 % rule nodes
467 N \chardef \insnode = 4 % insertion nodes
468 N \chardef \marknode = 5 % a mark node
469 N \chardef \adjustnode = 6 % an adjust node
470 N \chardef \ligaturenode = 7 % a ligature node
471 N \chardef \discnode = 8 % a discretionary node
472 N \chardef \whatsitnode = 9 % special extension nodes
473 N \chardef \mathnode = 10 % a math node
474 N \chardef \gluenode = 11 % node that points to a glue specification
475 N \chardef \kernnode = 12 % a kern node
476 N \chardef \penaltynode = 13 % a penalty node
477 N \chardef \unsetnode = 14 % an unset node
478 N \chardef \mathsnodes = 15 % nodes that occur only in maths mode
479
480 %% Declare names for `iftypes'
481
482 C \chardef \charif = 1 % \if
483 C \chardef \catif = 2 % \ifcat
484 C \chardef \numif = 3 % \ifnum
485 C \chardef \dimif = 4 % \ifdim
486 C \chardef \oddif = 5 % \ifodd
487 C \chardef \vmodeif = 6 % \ifvmode
488 C \chardef \hmodeif = 7 % \ifhmode
489 C \chardef \mmodeif = 8 % \ifmmode
490 C \chardef \innerif = 9 % \ifinner
491 C \chardef \voidif = 10 % \ifvoid
492 C \chardef \hboxif = 11 % \ifhbox
493 C \chardef \vboxif = 12 % \ifvbox
494 C \chardef \xif = 13 % \ifx
495 C \chardef \eofif = 14 % \ifeof
496 C \chardef \trueif = 15 % \iftrue
497 C \chardef \falseif = 16 % \iffalse
498 C \chardef \caseif = 17 % \ifcase
499 C \chardef \definedif = 18 % \ifdefined
500 C \chardef \csnameif = 19 % \ifcsname
501 C \chardef \fontcharif = 20 % \iffontchar
502
503 \catcode`\G=11
504 \catcode`\I=11
505 \catcode`\N=11
506 \catcode`\C=11
507