% \iffalse meta-comment
% 
% This is file `totalcount.dtx'.
% 
% Copyright (C) 2008 Axel Sommerfeldt
% 
% --------------------------------------------------------------------------
% 
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
% 
% This work has the LPPL maintenance status "maintained".
% 
% This Current Maintainer of this work is Axel Sommerfeldt.
% 
% This work consists of the files totalcount.ins and totalcount.dtx,
% and the derived file totalcount.sty.
% 
% \fi
% \CheckSum{107}
%
% \iffalse
%<*driver>
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesFile{totalcount.drv}[2008/02/25 v1.0 Total values of counters]
\hbadness=9999 \newcount\hbadness \hfuzz=74pt % Make TeX shut up.
%\errorcontextlines=3
%
\documentclass{ltxdoc}
\setlength\parindent{0pt}
\setlength\parskip{\smallskipamount}
%
\usepackage{ifpdf}
\ifpdf
  \usepackage{mathptmx,courier}
  \usepackage[scaled=0.90]{helvet}
% \addtolength\marginparwidth{15pt}
\fi
%
\usepackage[bottom]{footmisc}
\usepackage{hypdoc}
\ifpdf\usepackage{hypdestopt}\fi
\hypersetup{pdfkeywords={LaTeX, package, totalcount},pdfstartpage={},pdfstartview={}}
%
\usepackage{totalcount}[2008/02/16]
%
\newcommand*\purerm[1]{{\upshape\mdseries\rmfamily #1}}
\newcommand*\puresf[1]{{\upshape\mdseries\sffamily #1}}
\newcommand*\purett[1]{{\upshape\mdseries\ttfamily #1}}
\let\package\puresf
\let\env\purett \let\opt\purett
%
\newcommand*\csmarg[1]{\texttt{\char`\{#1\char`\}}}
\newcommand*\csoarg[1]{\texttt{\char`\[#1\char`\]}}
\newcommand*\version[2][]{$v#2$}
\newcommand*\x{\discretionary{-}{}{}}
\newcommand*\xx{\discretionary{}{}{}}
%
\usepackage{marvosym}
\newcommand*\MARGINSYM[1]{\hskip 1sp \marginpar{\raggedleft\textcolor{blue}{{#1}}}}
\newenvironment{info}{\par\bigskip\csname info*\endcsname}{\csname endinfo*\endcsname}
\newenvironment{info*}%
  {\small
   \MARGINSYM{\vbox to \ht\strutbox{\LARGE\Info}}%
   \ignorespaces}%
  {\par}
%
\begin{document}
  \DocInput{totalcount.dtx}
\end{document}
%</driver>
% \fi
%
% \def\thispackage{the \package{totalcount} package}
% \def\Thispackage{The \package{totalcount} package}
%
% \GetFileInfo{totalcount.drv}
% \let\docdate\filedate
% \GetFileInfo{totalcount.sty}
%
% \title{\texorpdfstring{\Thispackage\thanks{%^^A
%          This package has version number \fileversion, last revised \filedate.}}%^^A
%        {The totalcount package}}
% \author{Axel Sommerfeldt\\
%         \url{http://sourceforge.net/projects/latex-caption/}}
% \date{\docdate}
% \maketitle
% 
% \begin{abstract}
% TODO\ldots
% \end{abstract}
%
% \subsection*{Introduction}
% Based on the idea here:\\
% \url{http://texnik.dante.de/cgi-bin/mainFAQ.cgi?file=counter/counter#number}
%
% TODO\ldots
%
% \iffalse
% --------------------------------------------------------------------------- %
% \fi
%
% \StopEventually{}%^^A
%
% \iffalse
% --------------------------------------------------------------------------- %
% \fi
%
% \DoNotIndex{\\,\_,\ ,\@@par}
% \DoNotIndex{\@bsphack}
% \DoNotIndex{\@car,\@cdr,\@classoptionslist,\@cons,\@currext,\@currname}
% \DoNotIndex{\@ehc,\@ehd,\@empty,\@esphack,\@expandtwoargs}
% \DoNotIndex{\@for,\@firstofone,\@firstoftwo}
% \DoNotIndex{\@gobble,\@gobblefour,\@gobbletwo,\@hangfrom}
% \DoNotIndex{\@ifnextchar,\@ifpackagelater,\@ifpackageloaded}
% \DoNotIndex{\@ifstar,\@ifundefined,\@latex@error,\@namedef,\@nameuse}
% \DoNotIndex{\@onlypreamble,\@parboxrestore,\@plus,\@ptionlist}
% \DoNotIndex{\@removeelement,\@restorepar,\@secondoftwo,\@setpar}
% \DoNotIndex{\@tempa,\@tempboxa,\@tempdima,\@tempdimb,\@tempdimc,\@tempb,\@tempc}
% \DoNotIndex{\@testopt}
% \DoNotIndex{\@undefined,\@unprocessedoptions,\@unusedoptionlist}
% \DoNotIndex{\p@,\z@}
% \DoNotIndex{\active,\addtocounter,\addtolength,\advance,\aftergroup}
% \DoNotIndex{\baselineskip,\begin,\begingroup,\bfseries,\box}
% \DoNotIndex{\catcode,\centering,\changes,\csname,\def,\divide,\do,\downarrow}
% \DoNotIndex{\edef,\else,\empty,\end,\endcsname,\endgraf,\endgroup,\expandafter}
% \DoNotIndex{\fi,\footnotesize,\global}
% \DoNotIndex{\hangindent,\hbox,\hfil,\hsize,\hskip,\hspace,\hss}
% \DoNotIndex{\ifcase,\ifdim,\ifnum,\ifodd,\ifvoid,\ifvmode}
% \DoNotIndex{\ifx,\ignorespaces,\itshape}
% \DoNotIndex{\Large,\large,\leavevmode,\leftmargini,\leftskip,\let,\linewidth}
% \DoNotIndex{\llap,\long,\m@ne,\margin,\mdseries,\message}
% \DoNotIndex{\newcommand,\newdimen,\newlength,\newline,\newif,\newsavebox}
% \DoNotIndex{\next,\nobreak,\nobreakspace,\noexpand,\noindent,\numberline}
% \DoNotIndex{\normalcolor,\normalfont,\normalsize,\or,\par,\parbox,\parfillskip}
% \DoNotIndex{\parindent,\parskip,\prevdepth,\protect,\protected@edef,\protected@write}
% \DoNotIndex{\providecommand,\quad}
% \DoNotIndex{\raggedleft,\raggedright,\relax,\renewcommand,\RequirePackage}
% \DoNotIndex{\rightskip,\rmfamily}
% \DoNotIndex{\sbox,\scriptsize,\scshape,\setbox,\setlength,\sffamily,\slshape}
% \DoNotIndex{\small,\string,\space,\strut}
% \DoNotIndex{\textheight,\the,\toks@,\typeout,\ttfamily}
% \DoNotIndex{\unvbox,\uparrow,\upshape,\usebox,\usepackage}
% \DoNotIndex{\value,\vbox,\vsize,\vskip,\wd,\width,\z@skip}
% \DoNotIndex{\AtBeginDocument,\AtEndOfPackage,\CurrentOption,\DeclareOption}
% \DoNotIndex{\ExecuteOptions,\GenericWarning,\IfFileExists,\InputIfFileExists}
% \DoNotIndex{\NeedsTeXFormat,\MessageBreak}
% \DoNotIndex{\PackageError,\PackageInfo,\PackageWarning,\PackageWarningNoLine}
% \DoNotIndex{\PassOptionsToPackage,\ProcessOptions,\ProvidesPackage}
%
% \iffalse
% --------------------------------------------------------------------------- %
% \fi
%
% \setlength{\parskip}{0pt plus 1pt}
% \changes{v1.0}{2008/02/16}{First version}
%
% \iffalse
% --------------------------------------------------------------------------- %
% \fi
%
% \clearpage
% \section{The implementation}
% \iffalse
%<*package>
% \fi
%
% \subsection{Identification}
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{totalcount}[2008/02/27 v0.7 Total values of counters (AR)]
%    \end{macrocode}
%
% \subsection{Initial code}
%
% \begin{macro}{\DeclareTotalCounter}
% |\DeclareTotalCounter|\marg{counter name}
%    \begin{macrocode}
\newcommand*\DeclareTotalCounter[1]{%
  \@ifundefined{c@#1}%
    {\PackageError{totalcount}{Undefined counter `#1'}\@ehc}%
    {\newcounter{total@#1}%
     \@namedef{total#1s}{\nfss@text{\reset@font\bfseries ??}}%
     \@namedef{total#1es}{\nfss@text{\reset@font\bfseries ??}}%
%      \PackageWarning{totalcounter}{Total counter `#1' on page \thepage
%        \space not\MessageBreak available yet}}%
     \@cons\total@counters{{#1}}}}
\@onlypreamble\DeclareTotalCounter
%    \end{macrocode}
%    \begin{macrocode}
\let\total@counters\@empty
%    \end{macrocode}
% \end{macro}
%
% \subsection{Declaration of options}
%
%    \begin{macrocode}
\newcommand*\total@xspace{}
\DeclareOption{xspace}{\renewcommand*\total@xspace{\xspace}}
%    \end{macrocode}
%    \begin{macrocode}
\DeclareOption*{\expandafter\DeclareTotalCounter\expandafter{\CurrentOption}}
%    \end{macrocode}
%
% \subsection{Execution of options}
%
%    \begin{macrocode}
\ProcessOptions\relax
\ifx\total@xspace\@empty\else
  \RequirePackage{xspace}
\fi
%    \end{macrocode}
%
% \subsection{Main code}
%
% \begin{macro}{\total@addtocounter}
% |\total@addtocounter|\marg{counter name}
%    \begin{macrocode}
\newcommand*\total@addtocounter[1]{%
  \@ifundefined{c@total@#1}{}{%
    \addtocounter{total@#1}{\value{#1}}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@stpelt}
% |\@stpelt|\marg{counter name}
%    \begin{macrocode}
\let\total@stpelt@ORI\@stpelt
\renewcommand*\@stpelt[1]{%
  \total@addtocounter{#1}\total@stpelt@ORI{#1}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\AtBeginDocument{\AtEndDocument{%
  \begingroup
    \@tempswafalse
    \def\@elt#1{%
      \total@addtocounter{#1}%
      \xdef\total@tempa{\the\value{total@#1}}%
      \xdef\total@tempb{\total@tempa\noexpand\total@xspace}%
      \expandafter\ifx\csname total#1s\endcsname\total@tempb \else
        \@tempswatrue
      \fi
      \if@filesw
        \immediate\write\@mainaux{%
          \string\gdef\string\total#1s{\total@tempa\string\total@xspace}%
          \string\gdef\string\total#1es{\total@tempa\string\total@xspace}}%
      \fi}%
    \total@counters
    \if@tempswa
      \PackageWarningNoLine{totalcount}{%
        Total counter(s) have changed.\MessageBreak
        Rerun to get them right}%
    \fi
  \endgroup}}%
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
%
% \iffalse
% --------------------------------------------------------------------------- %
% \fi
%
% \Finale
%
\endinput
