summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/totcount
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-04-15 18:36:55 +0000
committerKarl Berry <karl@freefriends.org>2009-04-15 18:36:55 +0000
commit3617ef0fc28f0485785df18efeccd6bbd6b33bf1 (patch)
tree9d3430109e013d92405f713460a70d305c4b1a8a /Master/texmf-dist/tex/latex/totcount
parente802015081c281d89ccb87b4e29bd063d3ea427f (diff)
new latex package totcount (14apr09)
git-svn-id: svn://tug.org/texlive/trunk@12727 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/totcount')
-rw-r--r--Master/texmf-dist/tex/latex/totcount/totcount.sty157
1 files changed, 157 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/totcount/totcount.sty b/Master/texmf-dist/tex/latex/totcount/totcount.sty
new file mode 100644
index 00000000000..532ac391ebd
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/totcount/totcount.sty
@@ -0,0 +1,157 @@
+%%
+%% This is file `totcount.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% totcount.dtx (with options: `sty')
+%%
+%% The TotCount package, version 1.0, 2009/04/14
+%%
+%% Copyright (c) [2009] Vasileios Koutavas (Vasileios.Koutavas@cs.tcd.ie)
+%%
+%% This program may be re-distributed and/or modified under the terms of the
+%% LaTeX Project Public License version 1.3c, or any later version.
+%% The latest version of this license is in
+%% CTAN:macros/latex/base/lppl.txt
+%%
+\def\fileversion{1.0}
+\def\filedate{2009/04/14}
+\def\docdate{14 April 2009}
+\NeedsTeXFormat{LaTeX2e}
+ \date{\docdate}
+\ProvidesPackage{totcount}
+ [\filedate \space v\fileversion \space package for getting%
+ the total value of LaTeX counters]
+%%
+%% Import of the \xpackage{keyval} package \cite{keyval}:
+\RequirePackage{keyval}
+%%
+%% Creates a new counter and registers it as a total counter. This is the
+%% top-level dispatch of the macro, depending on whether there is an optional
+%% argument or not.
+\def\newtotcounter{%
+ \@ifnextchar[\newtotcounter@newaux\newtotcounter@mainaux}
+%%
+%% This is the version of the |\newtotcounter| macro that uses a separate
+%% auxiliary file. It first creates the counter (second argument) and then
+%% calls the macro |\regtotcounter|.
+\def\newtotcounter@newaux[#1]#2{%
+ \newcounter{#2}%
+ \regtotcounter[#1]{#2}%
+}
+%%
+%% This is the version of the |\newtotcounter| macro that uses the main
+%% auxiliary file. It first creates the counter (argument) and then calls
+%% the macro |\regtotcounter|.
+\def\newtotcounter@mainaux#1{%
+ \newcounter{#1}%
+%% Register the counter:
+ \regtotcounter{#1}%
+}
+%%
+%% Registers a counter as a total counter. This is the top-level dispatch of
+%% the macro, depending on whether there is an optional argument or not.
+\def\regtotcounter{%
+ \@ifnextchar[\regtotcounter@newaux\regtotcounter@mainaux}
+%%
+%% The following is the definition of the |auxfile| key for specifying an
+%% alternative auxiliary file when calling the macro |\regtotcounter| (see
+%% \cite{keyval}).
+\define@key{totcounter}{auxfile}{\def\this@auxfile{#1}}
+%%
+%% This is the version of the |\regtotcounter| macro that uses a separate
+%% auxiliary file. The auxiliary file is passed as a first argument in the
+%% form of a key--value pair |[auxfile=|\meta{file}|]|, and the counter to be
+%% registered is passed as the second argument.
+%% \begin{macrocode}
+\def\regtotcounter@newaux[#1]#2{%
+ \setkeys{totcounter}{#1}%
+%% Try to load the contents of the file:
+ \InputIfFileExists{\this@auxfile}{}{}%
+%% Make sure that the auxiliary file is open; \LaTeX\ will close it at the end:
+ \expandafter\ifx\csname \this@auxfile @open\endcsname\relax%
+ \expandafter\gdef\csname \this@auxfile @open\endcsname{}%
+ \expandafter\newwrite\csname \this@auxfile @stream\endcsname%
+ \immediate\expandafter\openout%
+ \csname \this@auxfile @stream\endcsname=\this@auxfile%
+ \fi%
+%% Create a new counter holding the total number of the actual counter:
+ \expandafter\ifx\csname c@#2@totc\endcsname\relax%
+ \newcounter{#2@totc}%
+ \setcounter{#2@totc}{-1}%
+ \fi%
+%% At the end of the document write code in the auxiliary file to update the
+%% total counter with the value of the actual counter:
+ \AtEndDocument{%
+ \def\sp{ }%
+ \immediate\expandafter\write%
+ \csname \this@auxfile @stream\endcsname{%
+ \string\expandafter\string\ifx%
+ \string\csname\sp c@#2@totc\string\endcsname\string\relax%
+ \string\newcounter{#2@totc}%
+ \string\fi%
+ \string\setcounter{#2@totc}{\number\value{#2}}%
+ }%
+ }%
+}
+%%
+%% This is the version of the |\regtotcounter| macro that uses the main
+%% auxiliary file. The counter to be registered is passed as the second
+%% argument.
+\def\regtotcounter@mainaux#1{%
+%% Create a new counter holding the total number of the actual counter:
+ \expandafter\ifx\csname c@#1@totc\endcsname\relax%
+ \newcounter{#1@totc}%
+ \setcounter{#1@totc}{-1}%
+ \fi%
+%% At the end of the document write code in the auxiliary file to update the
+%% total counter with the value of the actual counter:
+ \AtEndDocument{%
+ \def\sp{ }%
+ \immediate\write\@mainaux{%
+ \string\expandafter\string\ifx%
+ \string\csname\sp c@#1@totc\string\endcsname\string\relax%
+ \string\newcounter{\string #1@totc}%
+ \string\fi%
+ \string\setcounter{\string #1@totc}{\number\value{#1}}%
+ }%
+ }%
+}
+%%
+%% Prints the total value of a registered total counter that is passed as
+%% argument. If the total value is yet to be computed (at the first time
+%% \LaTeX\ runs on the document) then its value is |-1| and the output of the
+%% command is $??$.
+\newcommand\total[1]{%
+ \def\tmp@val{\value{#1@totc}}%
+ \ifnum\tmp@val=-1%
+ \message{Rerun to get correct total counts}%
+ $??$%
+ \else%
+ \number\value{#1@totc}%
+ \fi%
+}
+%%
+%% Returns the numeric total value of a registered total counter that is
+%% passed as argument. Note that if the counter's value is not yet computed
+%% (at the first time \LaTeX\ runs on the document) this macro returns |-1|.
+\newcommand\totvalue[1]{\value{#1@totc}}
+%%
+%% Inputs an auxiliary file that should contain total-counter
+%% definitions. It outputs a warning message in the terminal if the file
+%% doesn't exist. This command should be used \emph{instead} of registering a
+%% counter.
+\newcommand\usetotcountfile[1]{%
+ \InputIfFileExists{#1}{%
+ \message{TotCount inputs file '#1'}%
+ }{%
+ \message{TotCount Warning: File '#1' does not exist!}%
+ \message{\space\space\space\space\space\space\space\space\space%
+ \space\space\space\space\space\space\space\space\space%
+ Ignoring \string\usetotcountfile{#1}.}%
+ }%
+}
+\endinput
+%%
+%% End of file `totcount.sty'.