% Copyright 2006 Konstantin Korikov <lostclus@ua.fm>
%
% 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 Konstantin Korikov.
%
% This work consists of all files listed in manifest.txt.
%

%
% This is automaticaly generated file, do not edit it.
%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xespdtotal}[2020/03/20 v1.00 Total number of tables, figures, etc]

\RequirePackage{xespdsect}

\let\XESPD@old@caption\@caption
\let\XESPD@old@bibitem\bibitem

\newcounter{XESPD@figure}
\newcounter{XESPD@table}
\newcounter{XESPD@bibitem}

\long\def\@caption#1[#2]#3{%
  \stepcounter{XESPD@#1}%
  \XESPD@old@caption{#1}[#2]{#3}}

\long\def\bibitem{%
  \stepcounter{XESPD@bibitem}%
  \XESPD@old@bibitem}

\def\XESPD@total@save#1#2{%
  \immediate\write\@auxout{%
    \string\gdef\string\XESPD@total@saved@\string#1{\arabic{#2}}}}

\AtEndDocument{%
  \XESPD@total@save{figure}{XESPD@figure}
  \XESPD@total@save{table}{XESPD@table}
  \XESPD@total@save{bibitem}{XESPD@bibitem}
  \XESPD@total@save{appendix}{appendix}
  \clearpage
  \addtocounter{page}{-1}
  \XESPD@total@save{page}{page}
  \addtocounter{page}{1}}

\newcommand{\XESPDtotal}[1]{%
  \@ifundefined{XESPD@total@saved@#1}{?}{%
    \@nameuse{XESPD@total@saved@#1}}}

