Debian Codegraph @

texmf-dist/doc/latex/totcount/totcount-ex.tex

raw
1 %%
2 %% This is file `totcount-ex.tex',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% totcount.dtx (with options: `ex')
8 %%
9 %% The TotCount package, version 1.2, 2011/01/25
10 %%
11 %% Copyright (c) [2009] Vasileios Koutavas ([email protected])
12 %%
13 %% This program may be re-distributed and/or modified under the terms of the
14 %% LaTeX Project Public License version 1.3c, or any later version.
15 %% The latest version of this license is in
16 %% CTAN:macros/latex/base/lppl.txt
17 %%
18 \def\totcfileversion{1.2}
19 \def\totcfiledate{2011/01/25}
20 \def\totcdocdate{25 Jan 2011}
21 \NeedsTeXFormat{LaTeX2e}
22 \ProvidesFile{totcount-ex.tex}
23 [\totcfiledate \space v\totcfileversion \space%
24 test file for the TotCount package]
25 \documentclass{article}
26 %%
27 %% Import the package
28 \RequirePackage{totcount}
29 %%
30 %% Comment out the following line to use the previously stored total counts in
31 %% 'mycount.aux' (make sure it exists!) instead of computing them again:
32 \def\computemycount{}
33 \expandafter\ifx\csname computemycount\endcsname\relax
34 \usetotcountfile{mycount.aux}
35 \newcounter{mycount} % so that increments of this counter don't break
36 \else
37 \newtotcounter[auxfile=mycount.aux]{mycount}
38 \fi
39 %%
40 %% Register the section and page counters as a total counters:
41 \regtotcounter{section}
42 \regtotcounter{page}
43
44 \begin{document}
45 %%
46 %% A total counter can be declared/registered anywhere:
47 \newtotcounter{yourcount}
48
49 \section{Total Counts}
50 %%
51 %% Increment counters as usual:
52 \addtocounter{mycount}{5}
53 \addtocounter{yourcount}{5}
54 %%
55 %% Print the value of a total counter by using |\total|:
56 The total value of the counter {\tt mycount} is \total{mycount} (should
57 be 10), and the total value of the counter {\tt yourcount} is
58 \total{yourcount} (should be 17).
59
60 %%
61 %% Get the numeric value of a total counter by using |\totvalue|:
62 This document has \total{section}
63 \ifnum\totvalue{section}=1 section \else sections \fi
64 and \total{page}
65 \ifnum\totvalue{page}=1 page. \else pages. \fi
66
67 %%
68 %% The effect of incrementing the counters will be visible the second
69 %% time LaTeX runs:
70 \addtocounter{yourcount}{5}
71 \addtocounter{mycount}{5}
72 \addtocounter{yourcount}{7}
73
74 \section{A Section}
75 \section{Another Section}
76 \section{Yet Another Section}
77
78 \end{document}
79 \endinput
80 %%
81 %% End of file `totcount-ex.tex'.