% \iffalse meta-comment
%
% File: regstats.dtx
% Version: 2011/08/23 v1.0f
%
% Copyright (C) 2011 by
%    H.-Martin M"unch <Martin dot Muench at Uni-Bonn dot de>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
%    http://www.latex-project.org/lppl/lppl-1-3c.txt
% and the latest version of this license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work is H.-Martin Muench.
%
% This work consists of the main source file regstats.dtx
% and the derived files
%    regstats.sty, regstats.pdf, regstats.ins, regstats.drv,
%    regstats-example.tex.
%
% Distribution:
%    CTAN:macros/latex/contrib/regstats/regstats.dtx
%    CTAN:macros/latex/contrib/regstats/regstats.pdf
%    CTAN:install/macros/latex/contrib/regstats.tds.zip
%
% Unpacking:
%    (a) If regstats.ins is present:
%           tex regstats.ins
%    (b) Without regstats.ins:
%           tex regstats.dtx
%    (c) If you insist on using LaTeX
%           latex \let\install=y\input{regstats.dtx}
%        (quote the arguments according to the demands of your shell)
%
% Documentation:
%    (a) If regstats.drv is present:
%           (pdf)latex regstats.drv
%           makeindex -s gind.ist regstats.idx
%           (pdf)latex regstats.drv
%           makeindex -s gind.ist regstats.idx
%           (pdf)latex regstats.drv
%    (b) Without regstats.drv:
%           (pdf)latex regstats.dtx
%           makeindex -s gind.ist regstats.idx
%           (pdf)latex regstats.dtx
%           makeindex -s gind.ist regstats.idx
%           (pdf)latex regstats.dtx
%
%    The class ltxdoc loads the configuration file ltxdoc.cfg
%    if available. Here you can specify further options, e.g.
%    use DIN A4 as paper format:
%       \PassOptionsToClass{a4paper}{article}
%
% Installation:
%    TDS:tex/latex/regstats/regstats.sty
%    TDS:doc/latex/regstats/regstats.pdf
%    TDS:doc/latex/regstats/regstats-example.tex
%    TDS:doc/latex/regstats/regstats-example.log
%    TDS:source/latex/regstats/regstats.dtx
%
%<*ignore>
\begingroup
  \catcode123=1 %
  \catcode125=2 %
  \def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
         \ifx\csname processbatchFile\endcsname\relax\else1\fi
         \ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{******************************************************************}
\Msg{* Installation}
\Msg{* Package: regstats 2011/08/23 v1.0f Counting used registers (HMM)}
\Msg{******************************************************************}

\keepsilent
\askforoverwritefalse

\let\MetaPrefix\relax
\preamble

This is a generated file.

Project: regstats
Version: 2011/08/23 v1.0f

Copyright (C) 2011 by
    H.-Martin M"unch <Martin dot Muench at Uni-Bonn dot de>

The usual disclaimer applys:
If it doesn't work right that's your problem.
(Nevertheless, send an e-mail to the maintainer
 when you find an error in this package.)

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. This version of this license is in
   http://www.latex-project.org/lppl/lppl-1-3c.txt
and the latest version of this license is in
   http://www.latex-project.org/lppl.txt
and version 1.3c or later is part of all distributions of
LaTeX version 2005/12/01 or later.

This work has the LPPL maintenance status "maintained".

The Current Maintainer of this work is H.-Martin Muench.

This work consists of the main source file regstats.dtx
and the derived files
   regstats.sty, regstats.pdf, regstats.ins, regstats.drv,
   regstats-example.tex.

\endpreamble
\let\MetaPrefix\DoubleperCent

\generate{%
  \file{regstats.ins}{\from{regstats.dtx}{install}}%
  \file{regstats.drv}{\from{regstats.dtx}{driver}}%
  \usedir{tex/latex/regstats}%
  \file{regstats.sty}{\from{regstats.dtx}{package}}%
  \usedir{doc/latex/regstats}%
  \file{regstats-example.tex}{\from{regstats.dtx}{example}}%
}

\catcode32=13\relax% active space
\let =\space%
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* file into a directory searched by TeX:}
\Msg{*}
\Msg{*     regstats.sty*}
\Msg{*}
\Msg{* To produce the documentation run the file `regstats.drv'}
\Msg{* through (pdf)LaTeX, e.g.}
\Msg{*  pdflatex regstats.drv}
\Msg{*  makeindex -s gind.ist regstats.idx}
\Msg{*  pdflatex regstats.drv}
\Msg{*  makeindex -s gind.ist regstats.idx}
\Msg{*  pdflatex regstats.drv}
\Msg{*}
\Msg{* At least three runs are necessary e.g. to get the}
\Msg{*  references right!}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}

\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%
% \section{The documentation driver file}
%
% The next bit of code contains the documentation driver file for
% \TeX{}, i.\,e., the file that will produce the documentation you
% are currently reading. It will be extracted from this file by the
% \texttt{docstrip} programme. That is, run \LaTeX\ on \texttt{docstrip}
% and specify the \texttt{driver} option when \texttt{docstrip}
% asks for options.
%
%    \begin{macrocode}
%<*driver>
\NeedsTeXFormat{LaTeX2e}[2011/06/24]%
\ProvidesFile{regstats.drv}%
  [2011/08/23 v1.0f Counting used registers (HMM)]%
\documentclass{ltxdoc}[2007/11/11]% v2.0u
\usepackage{pdflscape}[2008/08/11]% v0.10
\usepackage{holtxdoc}[2011/02/04]% v0.21
%% regstats may work with earlier versions of LaTeX2e and those
%% class and packages, but this was not tested.
%% Please consider updating your LaTeX, class, and packages
%% to the most recent version (if they are not already the most
%% recent version).
\hypersetup{%
 pdfsubject={Information about used number of TeX registers (HMM)},%
 pdfkeywords={LaTeX, regstats, registers, read, write, language, box, dimen, counter, toks, skip, muskip, math family, insertion, Hans-Martin Muench},%
 pdfencoding=auto,%
 pdflang={en},%
 breaklinks=true,%
 linktoc=all,%
 pdfstartview=FitH,%
 pdfpagelayout=OneColumn,%
 bookmarksnumbered=true,%
 bookmarksopen=true,%
 bookmarksopenlevel=3,%
 pdfmenubar=true,%
 pdftoolbar=true,%
 pdfwindowui=true,%
 pdfnewwindow=true%
}
\CodelineIndex
\hyphenation{printing docu-ment}
\gdef\unit#1{\mathord{\thinspace\mathrm{#1}}}%
\begin{document}
  \DocInput{regstats.dtx}%
\end{document}
%</driver>
%    \end{macrocode}
%
% \fi
%
% \CheckSum{541}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \GetFileInfo{regstats.drv}
%
% \begingroup
%   \def\x{\#,\$,\^,\_,\~,\ ,\&,\{,\},\%}%
%   \makeatletter
%   \@onelevel@sanitize\x
% \expandafter\endgroup
% \expandafter\DoNotIndex\expandafter{\x}
% \expandafter\DoNotIndex\expandafter{\string\ }
% \begingroup
%   \makeatletter
%     \lccode`9=32\relax
%     \lowercase{%^^A
%       \edef\x{\noexpand\DoNotIndex{\@backslashchar9}}%^^A
%     }%^^A
%   \expandafter\endgroup\x
%
% \DoNotIndex{\\}
% \DoNotIndex{\documentclass,\usepackage,\ProvidesPackage,\begin,\end}
% \DoNotIndex{\message,\MessageBreak}
% \DoNotIndex{\NeedsTeXFormat,\DoNotIndex,\verb}
% \DoNotIndex{\def,\edef,\gdef,\global}
% \DoNotIndex{\ifx,\kvoptions,\listfiles,\mathord,\mathrm,\ProcessKeyvalOptions}
% \DoNotIndex{\SetupKeyvalOptions}
% \DoNotIndex{\bigskip,\space,\thinspace,\Large,\linebreak,\lipsum}
% \DoNotIndex{\ldots,\indent,\noindent,\newline,\pagebreak,\pagenumbering}
% \DoNotIndex{\textbf,\textit,\textsf,\texttt,\textquotedblleft,\textquotedblright}
% \DoNotIndex{\plainTeX,\TeX,\LaTeX,\pdfLaTeX}
% \DoNotIndex{\chapter,\section,\regstats@test,\the,\csname,\endscname}
% \DoNotIndex{\value,\setcounter,\addtocounter,\arabic,\csname,\endscname}
%
% \title{The \xpackage{regstats} package}
% \date{2011/08/23 v1.0f}
% \author{H.-Martin M\"{u}nch\\\xemail{Martin.Muench at Uni-Bonn.de}}
%
% \maketitle
%
% \begin{abstract}
%  This \LaTeX\ package allows to count the number of used registers
% (counter, dimen, skip, muskip, box, token, input, output,
% math families, languages, insertions)
% and compare these to the maximum available number of such registers.
% The time needed for a compilation run can be announced.
% \end{abstract}
%
% \bigskip
%
% \noindent Disclaimer for web links: The author is not responsible for any contents
% referred to in this work unless he has full knowledge of illegal contents.
% If any damage occurs by the use of information presented there, only the
% author of the respective pages might be liable, not the one who has referred
% to these pages.
%
% \bigskip
%
% \noindent {\color{green} Save per page about $200\unit{ml}$ water,
% $2\unit{g}$ CO$_{2}$ and $2\unit{g}$ wood:\\
% Therefore please print only if this is really necessary.}
%
% \pagebreak
%
% \tableofcontents
%
% \bigskip
%
% \section{Introduction}
%
% \indent This \LaTeX\ package allows to count the number of used registers
% (counter, dimen, skip, muskip, box, token, input, output,
% math families, languages, insertions).
% Therefore the according |\count| is read. While |\count10| should be the number
% of the counters, |\count11| the one of the dimens, and so on, it is possible to use
% option |proof|, in which case a new one of each register is used and looked at
% |\the\allocationnumber|, and this is compared to the number determined by reading
% the |\count|. The result for each register is compared to the maximum available
% number of the respective register
% (comparison independent of usage of option |proof|).
% With option |left| additionally the number of remaining registers of each type
% is given, and with option |timer| the time needed for the compilation run.
%
% \pagebreak
%
% \section{Usage}
%
% \indent Just load the package placing
% \begin{quote}
%   |\usepackage[<|\textit{options}|>]{regstats}|
% \end{quote}
% \noindent at the end of the preamble of your \LaTeXe\ source file. When you load
% packages |\AtBeginDocument|, \xpackage{regstats} should be the last one of
% those packages. The resulting message will be presented at the end of the
% compilation messages at the screen and in the \xfile{log} file.
%
% \subsection{Options}
% \DescribeMacro{options}
% \indent The \xpackage{regstats} package takes the following options:
%
% \subsubsection{proof\label{sss:proof}}
% \DescribeMacro{proof}
% \indent When option \texttt{proof} (or \texttt{proof=true}) is chosen,
% a new one of each register is used and looked at |\the\allocationnumber|,
% and this is compared to the number determined by reading the |\count|.
% The default is \texttt{proof=false}.
%
% \subsubsection{left\label{sss:left}}
% \DescribeMacro{left}
% \indent When option \texttt{left} (or \texttt{left=true}) is chosen,
% also the number of remaining registers of each type is given. The default
% is \texttt{left=false}.
%
% \subsubsection{timer\label{sss:timer}}
% \DescribeMacro{timer}
% \indent When option \texttt{timer} (or \texttt{timer=true}) is chosen,
% also the the time needed for the compilation run is given. The default
% is \texttt{timer=false}.
%
% \section{Alternatives\label{sec:Alternatives}}
%
% \begin{description}
% \item[-] \xpackage{regcount}, 1999/08/03, v1.0, by \textsc{Jean-Pierre F. Drucbert},
%   provides the command |\rgcounts|, which can write the numbers of used registers
%   into the \xfile{log} file anywhere (not only at the end) and does this automatically
%   |\AtBeginDocument| and |\AtEndDocument| (but not |\AtVeryVeryEnd|). The number of
%   allocated insertions is \emph{wrong} in my opinion, because these are not numbered
%   $1, 2,\ldots$, but start at a high number, which is then decreased. The package is
%   compatibel with the \xpackage{regstats} package (i.\,e.~you can use both packages
%   at the same time in one document) and available at
%   \url{http://www.ctan.org/pkg/regcount}.
%
% \item[-] One can manually search for the last appearance of
%   |\count|, |\dimen|, |\skip|, |\muskip|, |\box|, |\toks|, |\read| (input),
%   |\write| (output), |\mathgroup| (math familiy), |\language|, and |\insert|,
%   and find the according number there. (This does not provide any information
%   about the number of remaining registers, of course.)
% \end{description}
%
% \bigskip
%
% \noindent (You programmed or found another alternative,
%  which is available at \CTAN{}?\\
%  OK, send an e-mail to me with the name, location at \CTAN{},
%  and a short notice, and I will probably include it in
%  the list above.)
%
% \newpage
%
% \section{Example}
%
%    \begin{macrocode}
%<*example>
\documentclass[british]{article}[2007/10/19]% v1.4h
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% \usepackage{etex}[1998/03/26]% v2.0
%% Uncomment the preceding line, if you want to use the eTeX-package
%% (which requires eTeX, of course).
\usepackage{hyperref}[2011/08/19]% v6.82h
\hypersetup{extension=pdf,%
 plainpages=false,%
 pdfpagelabels=true,%
 hyperindex=false,%
 pdflang={en},%
 pdftitle={regstats package example},%
 pdfauthor={Hans-Martin Muench},%
 pdfsubject={Example for the regstats package},%
 pdfkeywords={LaTeX, registers, read, write, language, box, dimen,%
 count, toks, muskip, skip, counter, regstats, Hans-Martin Muench},%
 pdfview=Fit,pdfstartview=Fit,%
 pdfpagelayout=SinglePage%
}
\usepackage[proof=false,left=true,timer=true]{regstats}[2011/08/23]% v1.0f
\gdef\unit#1{\mathord{\thinspace\mathrm{#1}}}%
\listfiles
\begin{document}
\pagenumbering{arabic}
\section*{Example for regstats}

This example demonstrates the use of package\newline
\textsf{regstats}, v1.0f as of 2011/08/23 (HMM).\newline
The used options were \texttt{proof=false,left=true,timer=true}.\newline
\texttt{proof=false} is the default, but neither \texttt{left=true}
nor \texttt{timer=true} are defaults (\texttt{left=false,timer=false}
would be the defaults).\newline

If $\varepsilon$-\TeX\ is available with your \LaTeX -distribution
and you want to use it, uncomment the\newline
\verb|%% \usepackage{etex}[1998/03/26]% v2.0|\newline
line in the preamble of this document.\newline
(Also \verb|\eTeX| instead of \verb|$\varepsilon$-\TeX|
would be available with it).\newline

For more details please see the documentation!\newline

\noindent Save per page about $200\unit{ml}$ water,
$2\unit{g}$ CO$_{2}$ and $2\unit{g}$ wood:\newline
Therefore please print only if this is really necessary.\newline

For the resulting message, please compile regstats-example.tex and
have a look at the end of the log-file.

Because the compilation time for this example is usually quite short,
option \texttt{timer} is not demonstrated very spectacular.

\end{document}
%</example>
%    \end{macrocode}
%
% \StopEventually{}
%
% \newpage
%
% \section{The implementation}
%
% We start off by checking that we are loading into \LaTeXe\ and
% announcing the name and version of this package.
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\ProvidesPackage{regstats}[2011/08/23 v1.0f
              Counting used registers (HMM)]

%    \end{macrocode}
%
% A short description of the \xpackage{regstats} package:
%
%    \begin{macrocode}
%% Allows to count the number of used registers
%% (counter, dimen, skip, muskip, box, token, input, output,
%%  math families, languages, insertions)
%% and compare these to the maximum available number of such registers.

%    \end{macrocode}
%
% We need the \xpackage{kvoptions} and \xpackage{atveryend} packages
% by \textsc{Heiko Oberdiek}:
%
%    \begin{macrocode}
\RequirePackage{kvoptions}[2010/12/23]% v3.10
\RequirePackage{atveryend}[2011/06/30]% v1.8

%    \end{macrocode}
%
% A last information for the user:
%
%    \begin{macrocode}
%% regstats may work with earlier versions of LaTeX and these
%% packages, but this was not tested. Please consider updating
%% your LaTeX and packages to the most recent version
%% (if they are not already the most recent version).

%    \end{macrocode}
%
% \indent See subsection~\ref{ss:Downloads} about how to get them.\\
%
% We process the options:
%
%    \begin{macrocode}
\SetupKeyvalOptions{family=regstats,prefix=regstats@}
\DeclareBoolOption{proof}% \regstats@proof
\DeclareBoolOption{left}
\DeclareBoolOption{timer}

\ProcessKeyvalOptions*

\ifregstats@proof
  \PackageInfo{regstats}{%
    This package will use one of each kind of register itself!\MessageBreak%
    (And other packages used by this package\MessageBreak%
    probably use additional resources,\MessageBreak%
    if those packages are not used anyway.)\MessageBreak%
   }
\else
  \PackageInfo{regstats}{%
    This package will use one counter itself!\MessageBreak%
    (And other packages used by this package\MessageBreak%
    probably use additional resources,\MessageBreak%
    if those packages are not used anyway.)\MessageBreak%
   }
\fi

%    \end{macrocode}
%
% But that counter will be created not before |\AtVeryVeryEnd|,
% therefore if it is the one counter too much, it should not
% interfere with the creation of the document. (The other kinds
% of registers are used not before |\AtVeryVeryEnd|, too.)\\
%
%    \begin{macrocode}
\ifregstats@timer
  \RequirePackage{intcalc}[2007/09/27]% v1.1
\fi

%    \end{macrocode}
%
% \LaTeXe{} 2011/06/27 changed the |\enddocument| command and thus
% broke the \xpackage{atveryend} package, which was then fixed.
% If new \LaTeXe{} and old \xpackage{atveryend} are combined,
% |\AtVeryVeryEnd| will never be called. Therefore we\\
% |\let\AtVeryVeryEnd\AtEndAfterFileList| and give an error message.
% It is no problem at all for the \xpackage{regstats} package,
% but other packages might really need |\AtVeryVeryEnd|,
% and the user might lose code and never get to know it
% (and just run into problems of unknown origin).\\
% |\@ifl@t@r\fmtversion| is from |\@needsf@rmat| as in\\
% \texttt{File L: ltclass.dtx Date: 2007/08/05 Version v1.1h}, line~259,\\
% of The \LaTeXe{} Sources\\
% by \textsc{Johannes Braams, David Carlisle, Alan Jeffrey, Leslie Lamport,%
% Frank Mittelbach, Chris Rowley, and Rainer Sch\"{o}pf},\\
% as of 2009/09/24.
%
%    \begin{macrocode}
\@ifl@t@r\fmtversion{2011/06/27}%
  {\@ifpackagelater{atveryend}{2011/06/29}%
     {% 2011/06/30, v1.8, or even more recent
     }{% older version
       \PackageError{regstats}{Outdated atveryend package}%
         {You use \fmtname \space <\fmtversion>, but only \MessageBreak%
          `\csname ver@atveryend.\@currext\endcsname',\MessageBreak%
          which is incompatibel with \fmtname \space <\fmtversion>.\MessageBreak%
          Please update your atveryend package!\MessageBreak%
          The regstats package now replaces \string\AtVeryVeryEnd \MessageBreak%
          by \string\AtEndAfterFileList.\MessageBreak%
         }%
       \let\AtVeryVeryEnd\AtEndAfterFileList%
     }%
  }{%
%    \end{macrocode}
%
% In this case the used \TeX{} format is outdated, but when\\
% |\NeedsTeXFormat{LaTeX2e}[2011/06/27]|\\
% is executed at the beginning of \xpackage{regstats} package,
% the appropriate warning message is issued automatically.
% (And \xpackage{regstats} should also work with older versions,
% I~used it with a 2003/12/01 version myself.)
%
%    \begin{macrocode}
  }

%    \end{macrocode}
%
% We try to determine, whether $\varepsilon$-\TeX{} is available in the
% \LaTeX{} distribution used to compile the document
% and really loaded by the user. Because it is possible to
% load packages |\AtBeginDocument|, but |\@ifpackageloaded|
% cannot be used after |\AtBeginDocument|, we check for
% $\varepsilon$-\TeX{} |\AtBeginDocument| (and herewith ask the user
% to please load \xpackage{regstats} as very last package,
% at least after the \xpackage{etex} package):
%
%    \begin{macrocode}
\AtBeginDocument{%
  \newif\ifetex
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname eTeXversion\endcsname\relax
      \etexfalse
  \else
      \@ifpackageloaded{etex}{\etextrue}{\etexfalse}
  \fi
  \ifetex
    \PackageInfo{regstats}{e-TeX found.}
  \else
    \PackageWarning{regstats}{Could not find e-TeX.\MessageBreak%
      That can mean that e-TeX was disabled or\MessageBreak%
      that your distribution of TeX does not contain e-TeX\MessageBreak%
      or that you forgot to say \string\usepackage{etex}\MessageBreak%
      in the preamble of \jobname.tex.\MessageBreak%
      Some packages will not work without e-TeX,\MessageBreak%
      but should give according messages.\MessageBreak%
     }
  \fi

%    \end{macrocode}
%
% |\AtVeryEndDocument| we write to |\AtVeryVeryEnd|, thus the code will be executed
% quite late during the compilation. (Please load \xpackage{regstats} as very last
% package!) We define a new command to determine the sigular/plural form,
% maximum of available registers, and (if option |left| was chosen)
% the number of remaining registers of that type.
%
%    \begin{macrocode}
  \AtEndDocument{%
   \BeforeClearDocument{%
    \AfterLastShipout{%
     \AtVeryEndDocument{%
      \AtEndAfterFileList{%
       \AtVeryVeryEnd{%
        \def\regstats@lft{}%
        \newcommand{\regstats@regstat}[5]{%
%    \end{macrocode}
%
% The five parameters are: number of used registers of that type,
% singular ending, plural ending, number of available registers without
% $\varepsilon$-\TeX{}, number of availabe registers with $\varepsilon$-\TeX{}
% (in this order).
%
%    \begin{macrocode}
        \setcounter{regstatscount}{#1}
        \ifnum \value{regstatscount}=0
          \setcounter{regstatscount}{2}
        \fi
        \ifnum \value{regstatscount}>1
          \gdef\regstats@pl{#3}
        \else
          \gdef\regstats@pl{#2}
        \fi
        \ifetex\edef\regstats@max{#5}\else\edef\regstats@max{#4}\fi
        \ifregstats@left
          \setcounter{regstatscount}{\regstats@max}
          \addtocounter{regstatscount}{-#1}
          \ifnum \value{regstatscount}>0
            \edef\regstats@lft{, left: \arabic{regstatscount}}
          \else
            \ifnum \value{regstatscount}=0
              \edef\regstats@lft{, left: \arabic{regstatscount} !!!}
            \else% \value{regstatscount}<0
              \edef\regstats@lft{, left: \arabic{regstatscount} **********}
            \fi
          \fi
%    \end{macrocode}
%
% |         \else| |\regstats@lft| will stay |\empty|.
%
%    \begin{macrocode}
        \fi
      }
      \newcounter{regstatscount}
      \edef\regstats@counter{\the\allocationnumber}
%    \end{macrocode}
%
% When option |proof| was chosen, a new register of the named types is used
% and its number compared with the according |count| number.
% We give a warning about the use of additional registers.
%
%    \begin{macrocode}
      \ifregstats@proof
        \PackageWarning{regstats}{%
          Package regstats loaded with option 'proof'.\MessageBreak%
          This package itself will now use\MessageBreak%
           one of each register for testing!%
          }%
        \def\regstats@proof{1}
        \edef\regstats@test{\the\count10}
        \ifx\regstats@counter\regstats@test
        \else
          \message{Discrepancy when counting count registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newdimen{\regstatsdimen}
        \edef\regstats@dimen{\the\allocationnumber}
        \edef\regstats@test{\the\count11}
        \ifx\regstats@dimen\regstats@test
        \else
          \message{Discrepancy when counting dimen registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newskip\regstatsskip
        \edef\regstats@skip{\the\allocationnumber}
        \edef\regstats@test{\the\count12}
        \ifx\regstats@skip\regstats@test
        \else
          \message{Discrepancy when counting skip registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newmuskip\regstatsmuskip
        \edef\regstats@muskip{\the\allocationnumber}
        \edef\regstats@test{\the\count13}
        \ifx\regstats@muskip\regstats@test
        \else
          \message{Discrepancy when counting muskip registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newbox\regstatsbox
        \edef\regstats@box{\the\allocationnumber}
        \edef\regstats@test{\the\count14}
        \ifx\regstats@box\regstats@test
        \else
          \message{Discrepancy when counting box registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newtoks\regstatstoks
        \edef\regstats@toks{\the\allocationnumber}
        \edef\regstats@test{\the\count15}
        \ifx\regstats@toks\regstats@test
        \else
          \message{Discrepancy when counting toks registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newread\regstatsread
        \edef\regstats@read{\the\allocationnumber}
        \edef\regstats@test{\the\count16}
        \ifx\regstats@read\regstats@test
        \else
          \message{Discrepancy when counting read registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newwrite\regstatswrite
        \edef\regstats@write{\the\allocationnumber}
        \edef\regstats@test{\the\count17}
        \ifx\regstats@write\regstats@test
        \else
          \message{Discrepancy when counting write registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newfam\regstatsfam
        \edef\regstats@fam{\the\allocationnumber}
        \edef\regstats@test{\the\count18}
        \ifx\regstats@fam\regstats@test
        \else
          \message{Discrepancy when counting fam registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newlanguage\regstatslanguage
        \edef\regstats@language{\the\allocationnumber}
        \edef\regstats@test{\the\count19}
        \ifx\regstats@language\regstats@test
        \else
          \message{Discrepancy when counting language registers.^^J}
          \def\regstats@proof{0}
        \fi
        \newinsert\regstatsinsert
        \edef\regstats@insert{\the\allocationnumber}
        \edef\regstats@test{\the\count20}
        \ifx\regstats@insert\regstats@test
        \else
          \message{Discrepancy when counting insert registers.^^J}
          \def\regstats@proof{0}
        \fi
%    \end{macrocode}
%
% When there was a discrepancy somewhere, we give the according message.
%
%    \begin{macrocode}
        \edef\regstats@test{0}
        \ifx\regstats@proof\regstats@test
          \message{Regstats test for register numbers failed.^^J}
          \message{Therefore option 'proof' is necessary to get the %
                   right numbers.^^J}
        \fi
      \else
%    \end{macrocode}
%
% Without option |proof|, we just take the values of the various |count|s.
%
%    \begin{macrocode}
        \edef\regstats@dimen{\the\count11}
        \edef\regstats@skip{\the\count12}
        \edef\regstats@muskip{\the\count13}
        \edef\regstats@box{\the\count14}
        \edef\regstats@toks{\the\count15}
        \edef\regstats@read{\the\count16}
        \edef\regstats@write{\the\count17}
        \edef\regstats@fam{\the\count18}
        \edef\regstats@language{\the\count19}
        \edef\regstats@insert{\the\count20}
      \fi
%    \end{macrocode}
%
% |insert|s are used starting with a high number and moving downward.
%
%    \begin{macrocode}
      \setcounter{regstatscount}{233}
      \addtocounter{regstatscount}{-\regstats@insert}
      \addtocounter{regstatscount}{+1}
      \edef\regstats@insert{\arabic{regstatscount}}
%    \end{macrocode}
%
% \newpage
% \begin{landscape}
%
% The number of used registers of each type and the number of available ones
% (estimated, probably dependent on distribution and its version, here just
% distinguished according to availability of $\varepsilon$-\TeX{}) is written
% to screen and \xfile{log} file. (Additional spaces are just for increased ease
% of readability of the code and will appear neither at the scree output nor
% in the \xfile{log}~file.)
%
%    \begin{macrocode}
      \message{^^J}
      \message{Here is how much of TeX's registers you used^^J}%
      \message{\space (numbers of available registers are estimated!):^^J}%
      \regstats@regstat{\regstats@counter}{}{s}{233}{32767}
      \message{ \regstats@counter\space  counter register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@dimen}{}{s}{233}{32767}
      \message{ \regstats@dimen\space    dimen   register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@skip}{}{s}{233}{32767}
      \message{ \regstats@skip\space     skip    register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@muskip}{}{s}{255}{32767}
      \message{ \regstats@muskip\space   muskip  register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@box}{}{s}{233}{32767}
      \message{ \regstats@box\space      box     register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@toks}{}{s}{255}{32767}
      \message{ \regstats@toks\space     toks    register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@read}{}{s}{15}{15}
      \message{ \regstats@read\space     input stream\regstats@pl\space (read)   out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@write}{}{s}{15}{15}
      \message{ \regstats@write\space    output stream\regstats@pl\space (write) out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@fam}{y}{ies}{15}{15}
      \message{ \regstats@fam\space      math famil\regstats@pl\space (fam)      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@language}{}{s}{255}{255}
      \message{ \regstats@language\space language code\regstats@pl\space         out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@insert}{}{s}{101}{124}
      \message{ \regstats@insert\space   insertion\regstats@pl\space             out of \regstats@max \regstats@lft ^^J}
%    \end{macrocode}
%
% \pagebreak
% \end{landscape}
%
% When option |timer| (or |timer=true|) was used, the \xpackage{regstats} package
% additionally gives the time, which was needed for the (last) compilation (run).
% When more than one compilation run are necessary to compile the document,
% the individual times have to be added up manually.
% If~|\pdfelapsedtime| was reset by another package, the result is not correct,
% of course, but unfortunately it is not possible to check for this. You could say
% |\def\pdfresettimer{\relax}| immediately after |\documentclass[...]{...}|
% to prevent this. Better use\\
% |\long\def\pdfresettimer{%|\\
% \ |\PackageError{regstats}{\string\pdfresettimer\space used}}|\\
% to be notified thereof. This redefinition could be implemented in this
% \xpackage{regstats} package, but this would have no effect for the use of
% |\pdfresettimer| before this package is called. Because this package
% should be called as late as immediately before |\begin{document}|, this would mean
% that resetting would be possible during the whole loading of all packages.
%
%    \begin{macrocode}
      \ifregstats@timer
        \message{^^J}
        \setcounter{regstatscount}{\the\pdfelapsedtime}
        \edef\regstatselapsedtime{\arabic{regstatscount}}
        \divide \value{regstatscount} by 65536% scaledseconds -> seconds
        \edef\regstatsseconds{\arabic{regstatscount}}
        \ifnum \value{regstatscount} > 59
          \edef\regstatsseconds{\intcalcMod{\value{regstatscount}}{60}}
          \divide \value{regstatscount} by 60% seconds -> minutes
        \else
          \setcounter{regstatscount}{0}% minutes = 0
        \fi
        \ifnum \regstatsseconds < 10
          \message{Time elapsed for the last compiler run:^^J%
            about \arabic{regstatscount}:0\regstatsseconds\space%
            (m:ss; \regstatselapsedtime /65536 s).^^J}
        \else
          \message{Time elapsed for the last compiler run:^^J%
            about \arabic{regstatscount}:\regstatsseconds \space%
            (m:ss; \regstatselapsedtime /65536 s).^^J}
        \fi
      \fi
      }%
     }%
    }%
   }%
  }%
 }%
}

%    \end{macrocode}
%
% That's it!
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \newpage
%
% \section{Installation}
%
% \subsection{Downloads\label{ss:Downloads}}
%
% Everything will become available at \CTAN{}, \url{http://www.ctan.org/tex-archive/},
% but may need additional packages themselves.\\
%
% \DescribeMacro{regstats.dtx}
% For unpacking the |regstats.dtx| file and constructing the documentation it is required:
% \begin{description}
% \item[-] \TeX Format \LaTeXe{}: \url{http://www.CTAN.org/}
%
% \item[-] document class \xpackage{ltxdoc}, 2007/11/11, v2.0u,\\
%           \CTAN{macros/latex/base/ltxdoc.dtx}
%
% \item[-] package \xpackage{pdflscape}, 2008/08/11, v0.10,\\
%           \CTAN{macros/latex/contrib/oberdiek/pdflscape.dtx}
%
% \item[-] package \xpackage{holtxdoc}, 2011/02/04, v0.21,\\
%           \CTAN{macros/latex/contrib/oberdiek/holtxdoc.dtx}
%
% \item[-] package \xpackage{hypdoc}, 2010/03/26, v1.9,\\
%           \CTAN{macros/latex/contrib/oberdiek/hypdoc.dtx}
% \end{description}
%
% \DescribeMacro{regstats.sty}
% The \texttt{regstats.sty} for \LaTeXe\ (i.\,e. each document using
% the \xpackage{regstats} package) requires:
% \begin{description}
% \item[-] \TeX Format \LaTeXe{}, \url{http://www.CTAN.org/}
%
% \item[-] package \xpackage{kvoptions}, 2010/12/23, v3.10,\\
%           \CTAN{macros/latex/contrib/oberdiek/kvoptions.dtx}
%
% \item[-] package \xpackage{atveryend}, 2011/06/30, v1.8,\\
%           \CTAN{macros/latex/contrib/oberdiek/atveryend.dtx}
% \end{description}
%
% When option |timer| is used, additionally
% \begin{description}
% \item[-] package \xpackage{intcalc}, 2007/09/27, v1.1,\\
%           \CTAN{macros/latex/contrib/oberdiek/intcalc.dtx}
% \end{description}
% is needed.\\
%
% \DescribeMacro{regstats-example.tex}
% The \texttt{regstats-example.tex} requires the same files as all
% documents using the \xpackage{regstats} package, i.\,e. the ones
% named above and additionally:
% \begin{description}
% \item[-] class \xpackage{article}, 2007/10/19, v1.4h, from \xpackage{classes.dtx}:\\
%           \CTAN{macros/latex/base/classes.dtx}
%
% \item[-] package \xpackage{regstats}, 2011/08/23, v1.0f,\\
%           \CTAN{macros/latex/contrib/regstats/regstats.dtx}\\
%   (Well, it is the example file for this package, and because you are reading the
%    documentation for the \xpackage{regstats} package, it can be assumed that you already
%    have some version of it -- is it the current one?)
% \end{description}
%
% \DescribeMacro{Alternative}
% As possible alternative in section \ref{sec:Alternatives} there is listed
% \begin{description}
% \item[-] \xpackage{regcount}, 1999/08/03, v1.0:\\
%            \url{http://www.ctan.org/pkg/regcount}
% \end{description}
%
% \DescribeMacro{Oberdiek}
% \DescribeMacro{holtxdoc}
% \DescribeMacro{kvoptions}
% \DescribeMacro{atveryend}
% \DescribeMacro{intcalc}
% \DescribeMacro{pdflscape}
% All packages of \textsc{Heiko Oberdiek's} bundle `oberdiek'
% (especially \xpackage{holtxdoc}, \xpackage{kvoptions}, \xpackage{atveryend},
% \xpackage{intcalc}, and \xpackage{pdflscape})
% are also available in a TDS compliant ZIP archive:\\
% \CTAN{install/macros/latex/contrib/oberdiek.tds.zip}.\\
% It is probably best to download and use this, because the packages in there
% are quite probably both recent and compatible among themselves.\\
%
% \DescribeMacro{hyperref}
% \noindent \xpackage{hyperref} is not included in that bundle and needs to be downloaded
% separately,\\
% \url{http://mirror.ctan.org/install/macros/latex/contrib/hyperref.tds.zip}.\\
%
% \DescribeMacro{M\"{u}nch}
% A hyperlinked list of my (other) packages can be found at
% \url{http://www.Uni-Bonn.de/~uzs5pv/LaTeX.html}.\\
%
% \subsection{Package, unpacking TDS}
%
% \paragraph{Package.} This package is available on \CTAN{}
% \begin{description}
% \item[\CTAN{macros/latex/contrib/regstats/regstats.dtx}]\hspace*{0.1cm} \\
%       The source file.
% \item[\CTAN{macros/latex/contrib/regstats/regstats.pdf}]\hspace*{0.1cm} \\
%       The documentation.
% \item[\CTAN{macros/latex/contrib/regstats/regstats-example.pdf}]\hspace*{0.1cm} \\
%       The compiled example file, as it should look like.
% \item[\CTAN{macros/latex/contrib/regstats/README}]\hspace*{0.1cm} \\
%       The README file.
% \item[\CTAN{install/macros/latex/contrib/regstats.tds.zip}]\hspace*{0.1cm} \\
%       Everything in TDS compliant, compiled format.
% \end{description}
% which additionally contains\\
% \begin{tabular}{ll}
% regstats.ins & The installation file.\\
% regstats.drv & The driver to generate the documentation.\\
% regstats.sty & The \xext{sty}le file.\\
% regstats-example.tex & The example file.\\
% regstats-example.log & A \xfile{log} file for the example.%
% \end{tabular}
%
% \bigskip
%
% \noindent For required other packages, see the preceding subsection.
%
% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
% \docstrip\ archive. The files are extracted by running the
% \xfile{.dtx} through \plainTeX:
% \begin{quote}
%   \verb|tex regstats.dtx|
% \end{quote}
%
% About generating the documentation see paragraph~\ref{GenDoc} below.\\
%
% \paragraph{TDS.} Now the different files must be moved into
% the different directories in your installation TDS tree
% (also known as \xfile{texmf} tree):
% \begin{quote}
% \def\t{^^A
% \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
%   regstats.sty & tex/latex/regstats.sty\\
%   regstats.pdf & doc/latex/regstats.pdf\\
%   regstats-example.tex & doc/latex/regstats-example.tex\\
%   regstats-example.pdf & doc/latex/regstats-example.pdf\\
%   regstats-example.log & doc/latex/regstats-example.log\\
%   regstats.dtx & source/latex/regstats.dtx\\
% \end{tabular}^^A
% }^^A
% \sbox0{\t}^^A
% \ifdim\wd0>\linewidth
%   \begingroup
%     \advance\linewidth by\leftmargin
%     \advance\linewidth by\rightmargin
%   \edef\x{\endgroup
%     \def\noexpand\lw{\the\linewidth}^^A
%   }\x
%   \def\lwbox{^^A
%     \leavevmode
%     \hbox to \linewidth{^^A
%       \kern-\leftmargin\relax
%       \hss
%       \usebox0
%       \hss
%       \kern-\rightmargin\relax
%     }^^A
%   }^^A
%   \ifdim\wd0>\lw
%     \sbox0{\small\t}^^A
%     \ifdim\wd0>\linewidth
%       \ifdim\wd0>\lw
%         \sbox0{\footnotesize\t}^^A
%         \ifdim\wd0>\linewidth
%           \ifdim\wd0>\lw
%             \sbox0{\scriptsize\t}^^A
%             \ifdim\wd0>\linewidth
%               \ifdim\wd0>\lw
%                 \sbox0{\tiny\t}^^A
%                 \ifdim\wd0>\linewidth
%                   \lwbox
%                 \else
%                   \usebox0
%                 \fi
%               \else
%                 \lwbox
%               \fi
%             \else
%               \usebox0
%             \fi
%           \else
%             \lwbox
%           \fi
%         \else
%           \usebox0
%         \fi
%       \else
%         \lwbox
%       \fi
%     \else
%       \usebox0
%     \fi
%   \else
%     \lwbox
%   \fi
% \else
%   \usebox0
% \fi
% \end{quote}
% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
% TDS installing feature, then some files can already be in the right
% place, see the documentation of \docstrip.
%
% \subsection{Refresh file name databases}
%
% If your \TeX~distribution (\teTeX, \mikTeX,\dots) relies on file name
% databases, you must refresh these. For example, \teTeX\ users run
% \verb|texhash| or \verb|mktexlsr|.
%
% \subsection{Some details for the interested}
%
% \paragraph{Unpacking with \LaTeX.}
% The \xfile{.dtx} chooses its action depending on the format:
% \begin{description}
% \item[\plainTeX:] Run \docstrip\ and extract the files.
% \item[\LaTeX:] Generate the documentation.
% \end{description}
% If you insist on using \LaTeX\ for \docstrip\ (really,
% \docstrip\ does not need \LaTeX), then inform the autodetect routine
% about your intention:
% \begin{quote}
%   \verb|latex \let\install=y\input{regstats.dtx}|
% \end{quote}
% Do not forget to quote the argument according to the demands
% of your shell.
%
% \paragraph{Generating the documentation.\label{GenDoc}}
% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
% the documentation. The process can be configured by a
% configuration file \xfile{ltxdoc.cfg}. For instance, put this
% line into this file, if you want to have A4 as paper format:
% \begin{quote}
%   \verb|\PassOptionsToClass{a4paper}{article}|
% \end{quote}
%
% \noindent An example follows how to generate the
% documentation with \pdfLaTeX :
%
% \begin{quote}
%\begin{verbatim}
%pdflatex regstats.dtx
%makeindex -s gind.ist regstats.idx
%pdflatex regstats.dtx
%makeindex -s gind.ist regstats.idx
%pdflatex regstats.dtx
%\end{verbatim}
% \end{quote}
%
% \subsection{Compiling the example}
%
% The example file, \textsf{regstats-example.tex}, can be compiled via\\
% |(pdf)latex regstats-example.tex|.\\
%
% \section{Acknowledgements}
%
% I would like to thank \textsc{Heiko Oberdiek} for providing
% the \xpackage{hyperref} and \xpackage{atveryend} as well as
% a~lot~(!) of other useful packages (from which I also got everything
% I know about creating a file in \xext{dtx} format, ok, say it: copying),
% \textsc{Jean-Pierre F. Drucbert} for his \xpackage{regcount} package,
% \textsc{Robin Fairbairns} for pointing me to the \xpackage{regcount} package,
% and the \Newsgroup{comp.text.tex} and \Newsgroup{de.comp.text.tex}
% newsgroups for their help in all things \TeX{}.
%
% \pagebreak
%
% \phantomsection
% \begin{History}\label{History}
%   \begin{Version}{2011/05/14 v1.0a}
%     \item Upload to \CTAN{}.
%   \end{Version}
%   \begin{Version}{2011/05/16 v1.0b}
%     \item Name clash with \xfile{regcount} package, fixed.
%     \item \xfile{regcount} package listed as possible alternative.
%     \item Bug: skip and muskip mixed up, fixed.
%     \item Counting of skips, math families, and insertions added.
%     \item Bug fix: insertions are numbered high to low.
%     \item Option |proof| added.
%     \item Diverse details.
%   \end{Version}
%   \begin{Version}{2011/06/08 v1.0c}
%     \item Bug Fix: Number of available |\skip| registers with $\varepsilon$-\TeX{}.
%     \item Change in $\varepsilon$-\TeX{}-detection.
%     \item New option |left|.
%     \item Minor details.
%   \end{Version}
%   \begin{Version}{2011/06/18 v1.0d}
%     \item Bug Fix: Information about used registers/counter fixed.
%     \item New option |timer|.
%     \item Some details.
%   \end{Version}
%   \begin{Version}{2011/08/22 v1.0e}
%     \item The information about the used registers is now presented even later.
%     \item Quite some details in the documentation.
%     \item Updated to \TeX live2011.
%     \item Hot fix: \TeX{} 2011/06/27 has changed |\enddocument| and
%             thus broken the |\AtVeryVeryEnd| command/hooking
%             of \xpackage{atveryend} package as of 2011/04/23, v1.7.
%             Until it is fixed, |\AtEndAfterFileList| is used.
%   \end{Version}
%   \begin{Version}{2011/08/23 v1.0f}
%     \item The \xpackage{atveryend} package was fixed (2011/06/30, v.1.8).
%             Now \xpackage{regstats} differentiates according to \TeX{} format
%             and \xpackage{atveryend} package version. 2011/06/30, v.1.8
%             will become available at CTAN soon. \xpackage{regstats} also
%             works with the old version, the information is just presented
%             a little bit earlier during compilation, thus theoretically
%             there could be missed some register use after that information,
%             which would be obviouse in the \xfile{log}-file.
%     \item New \xpackage{hyperref} package used for the documentation.
%   \end{Version}
% \end{History}
%
% \bigskip
%
% When you find a mistake or have a suggestion for an improvement of this package,
% please send an e-mail to the maintainer, thanks! (Please see BUG REPORTS in the README.)
%
% \bigskip
%
% \PrintIndex
%
% \Finale
\endinput