On Thu, Sep 16, 2010 at 11:05:03AM +0100, Chris Rowley wrote: > Thanks for this, Heiko. Note there is no upper range check in the code > here: > > >> \reserveinserts is a macro of etex.sty: > > | %% And we define \reserveinserts, so that you can say \reserveinserts{17} > | %% in order to reserve room for up to 17 additional insertion classes, that > | %% will not be taken away by \newcount, \newdimen, \newskip, or \newbox. > | > | \outer\def \reserveinserts#1% > | {\global\insc@unt\numexpr \et@xins \ifnum#1>\z@ -#1\fi \relax} AFAIK there is no need: latex.ltx defines: \def\newcount{\alloc@0\count\countdef\insc@unt} \def\newdimen{\alloc@1\dimen\dimendef\insc@unt} etex.sty defines: \def\alloc@#1#2#3#4#5% {\ifnum\count1#1<#4% make sure there's still room \allocationnumber\count1#1 \global\advance\count1#1\@ne \global#3#5\allocationnumber \wlog{\string#5=\string#2\the\allocationnumber}% \else\ifnum#1<6 \begingroup \escapechar\m@ne \expandafter\alloc@@\expandafter{\string#2}#5% \else\errmessage{No room for a new #2}\fi\fi } * \insc@unt is the upper range for the register allocation numbers of \count, \dimen, ... in the lower area. * \insc@unt is used in macro \alloc in the comparison: \ifnum\count1#1<#4 (#4=\insc@unt). If \insc@unt is negative then the \ifnum is always false, because \count1#1 are the current allocation numbers of \count, \dimen, ... that are growing only and thus have positive values. Failing the test means etex.sty switches to the extended pool immediately. If you say \reserveinserts{300} then there isn't an error, but if you try to allocate 300 insertion registers, then this will fail sooner or later. Test file: \RequirePackage{etex} \reserveinserts{300} \count@=\z@ \@whilenum\count@<300\do{% \advance\count@ by\@ne \newinsert\foobar \message{<\the\count@>}% } \@@end Result: 132 \newinserts are possible, then ! No room for a new \dimen. Also \reserveinserts ignores previous calls of \reserveinsert. Thus the second call of \reserveinserts in \RequirePackage{etex} \reserveinserts{20} \reserveinserts{10} actually decreases the reserved number of inserts from 20 to 10, leaving more room for the other registers in the lower area. I tried a more elaborate version of \reserveinserts: \RequirePackage{etex} \makeatletter \outer\def \reserveinserts#1{% \begingroup \@tempcnta=\numexpr#1\relax \ifnum\@tempcnta<\z@ \PackageWarning{etex}{% Negative number (\the\@tempcnta) for % \@backslashchar reserveinserts,\MessageBreak assuming 0% }% \@tempcnta=\z@ \fi \count@\count10 % count \ifnum\count11>\count@ \count@\count11 \fi % dimen \ifnum\count12>\count@ \count@\count12 \fi % skip \ifnum\count14>\count@ \count@\count14 \fi % box \count@=\numexpr\et@xins-\count@\relax \PackageInfo{etex}{% Maximum for \@backslashchar reserveinserts is \the\count@ }% \ifnum\@tempcnta>\count@ \PackageError{etex}{% \the\@tempcnta\space insertion register% \ifnum\@tempcnta=\@ne \space is \else s are \fi requested,\MessageBreak \ifnum\count@<\@ne but no more registers can be reserved% \else but only \the\count@\space register% \ifnum\count@=\@ne\else s\fi\space can be reserved% \fi }\@ehc \@tempcnta=\count@ \fi \global\insc@unt\numexpr\et@xins-\@tempcnta\relax \endgroup } % some rudimentary testing \reserveinserts{-1} \reserveinserts{0} \reserveinserts{131} \reserveinserts{132} \reserveinserts{133} \count@=\z@ \@whilenum\count@<134\do{% \advance\count@ by\@ne \newinsert\foobar \message{<\the\count@>}% } \@@end Yours sincerely Heiko <[log in to unmask]>