Debian Codegraph @

texmf-dist/source/latex/totalcount/totalcount.dtx

raw
1 % \iffalse meta-comment
2 %
3 % This is file `totalcount.dtx'.
4 %
5 % Copyright (C) 2010-2018 Axel Sommerfeldt ([email protected])
6 %
7 % --------------------------------------------------------------------------
8 %
9 % This work may be distributed and/or modified under the
10 % conditions of the LaTeX Project Public License, either version 1.3
11 % of this license or (at your option) any later version.
12 % The latest version of this license is in
13 % http://www.latex-project.org/lppl.txt
14 % and version 1.3 or later is part of all distributions of LaTeX
15 % version 2003/12/01 or later.
16 %
17 % This work has the LPPL maintenance status "maintained".
18 %
19 % This Current Maintainer of this work is Axel Sommerfeldt.
20 %
21 % This work consists of the files totalcount.ins, totalcount.dtx,
22 % and the derived file totalcount.sty.
23 %
24 % \fi
25 % \CheckSum{126}
26 %
27 % \iffalse
28 %<*driver>
29 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
30 \ProvidesFile{totalcount.drv}[2013/05/12 v1.0 Total values of counters]
31 \hbadness=9999 \newcount\hbadness \hfuzz=74pt % Make TeX shut up.
32 %\errorcontextlines=3
33 %
34 \documentclass{ltxdoc}
35 \setlength\parindent{0pt}
36 \setlength\parskip{\smallskipamount}
37 %
38 \usepackage{ifpdf}
39 \ifpdf
40 \usepackage{mathptmx,courier}
41 \usepackage[scaled=0.90]{helvet}
42 % \addtolength\marginparwidth{15pt}
43 \fi
44 %
45 \usepackage[bottom]{footmisc}
46 \usepackage{hypdoc}
47 \ifpdf\usepackage{hypdestopt}\fi
48 \hypersetup{pdfkeywords={LaTeX, package, totalcount},pdfstartpage={},pdfstartview={}}
49 %
50 \usepackage{totalcount}[2008/02/16]
51 %
52 \newcommand*\purerm[1]{{\upshape\mdseries\rmfamily #1}}
53 \newcommand*\puresf[1]{{\upshape\mdseries\sffamily #1}}
54 \newcommand*\purett[1]{{\upshape\mdseries\ttfamily #1}}
55 \let\package\puresf
56 \let\env\purett \let\opt\purett
57 %
58 \newcommand*\csmarg[1]{\texttt{\char`\{#1\char`\}}}
59 \newcommand*\csoarg[1]{\texttt{\char`\[#1\char`\]}}
60 \newcommand*\version[2][]{$v#2$}
61 %
62 \usepackage{marvosym}
63 \makeatletter
64 \newcommand*\INFO{\@ifstar{\@INFO{}}{\@INFO{\vbox to \ht\strutbox}}}
65 \newcommand*\@INFO[1]{\MARGINSYM{#1{\LARGE\Info}}}
66 \makeatother
67 %
68 \begin{document}
69 \DocInput{totalcount.dtx}
70 \end{document}
71 %</driver>
72 % \fi
73 %
74 % \def\thispackage{the \package{totalcount} package}
75 % \def\Thispackage{The \package{totalcount} package}
76 %
77 % \GetFileInfo{totalcount.drv}
78 % \let\docdate\filedate
79 % \let\docversion\fileversion
80 % \GetFileInfo{totalcount.sty}
81 %
82 % \title{\texorpdfstring{\Thispackage\thanks{%^^A
83 % This package has version number \docversion.}}%^^A
84 % {The totalcount package}}
85 % \author{Axel Sommerfeldt\\
86 % \url{https://gitlab.com/axelsommerfeldt/totalcount}}
87 % \date{\docdate}
88 % \maketitle
89 %
90 % \begin{abstract}
91 % This package offers commands for typesetting total values of counters.
92 % \end{abstract}
93 %
94 % \iffalse\clearpage\fi
95 % \setcounter{tocdepth}{2}
96 % \tableofcontents
97 %
98 % \iffalse\clearpage\fi
99 % \pagebreak[3]
100 % \section{Loading the package}
101 %
102 % Load this package using
103 % \begin{quote}
104 % |\usepackage|\oarg{options}|{totalcount}|\quad,
105 % \end{quote}
106 % where \meta{options} is a list of names of \LaTeX\ counters, e.g.:
107 % \begin{quote}
108 % |\usepackage[figure,table]{totalcount}|\quad.
109 % \end{quote}
110 % \pagebreak[3]
111 % This way the commands |\total|\-|figures| and |\total|\-|tables| will be defined which
112 % are typesetting the total number of figures resp.~tables, e.g.:
113 % \begin{quote}
114 % |This document contains \totalfigures\ figures.|
115 % \end{quote}
116 % \pagebreak[3]
117 % Furthermore the commands |\if|\-|total|\-|figures| and |\if|\-|total|\-|tables| are offered
118 % for typesetting text only if the document contains figures resp.~tables at all, e.g.:
119 % \begin{quote}
120 % |\iftotalfigures|\\
121 % | \listoffigures|\\
122 % |\fi|
123 % \end{quote}
124 % \pagebreak[3]
125 % This should work with other counters as well (for example |equation|,
126 % or |lst|\-|listing| offered by the \package{listings} package~\cite{listings}),
127 % but please note that using the |page| counter here is not supported.
128 %
129 % \pagebreak[3]
130 % \section{\cs{DeclareTotalCounter}}
131 % \begin{quote}
132 % |\DeclareTotalCounter|\marg{counter}
133 % \end{quote}
134 % actually defines the commands |\total|\meta{counter}|s| and |\if|\-|total|\meta{counter}|s|.
135 %
136 % \pagebreak[3]
137 % So in fact
138 % \begin{quote}
139 % |\usepackage[figure,table]{totalcount}|
140 % \end{quote}
141 % is identical to
142 % \begin{quote}
143 % |\usepackage{totalcount}|\\
144 % |\DeclareTotalCounter{figure}|\\
145 % |\DeclareTotalCounter{table}|
146 % \end{quote}
147 %
148 % \pagebreak[3]
149 % \section{Spacing}
150 % The space after all \LaTeX\ commands without (optional or mandatory) arguments
151 % like |\total|\-|figures| will not be typeset,
152 % so these commands needs to be finished with an additional backslash or an empty
153 % pair of curly braces right before the space character,
154 % or to be finished with a tilde (swung dash),
155 % so \TeX\ will be prevented from omitting the following space character.
156 %
157 % \pagebreak[3]
158 % This could be avoided by defining new commands with the help of
159 % the \package{xspace} package~\cite{xspace}.
160 % When using \thispackage\ with the package option |xspace| this will be actually done,
161 % so after
162 % \begin{quote}
163 % |\usepackage[figure,table,xspace]{totalcount}|
164 % \end{quote}
165 % code like
166 % \begin{quote}
167 % |This document contains \totalfigures figures.|
168 % \end{quote}
169 % will give correct results without a missing space between the total number of figures
170 % and the word ``figures''.
171 %
172 % \pagebreak[3]
173 % \section{Thanks}
174 % I would like to thank Herbert Vo\ss\ since the implementation of this package is
175 % based on an idea from him which could be found at
176 % \url{http://texnik.dante.de/cgi-bin/mainFAQ.cgi?file=counter/counter#number}.
177 %
178 % \iffalse
179 % --------------------------------------------------------------------------- %
180 % \fi
181 %
182 % \StopEventually{%^^A
183 % \begin{thebibliography}{9}
184 % \bibitem{listings}
185 % Carsten Heinz \& Brooks Moses:\\
186 % \href{http://www.ctan.org/pkg/listings}%
187 % {\emph{The Listings Package}},\\
188 % 2007/02/22
189 % \bibitem{xspace}
190 % David Carlisle and Morten H\o gholm:\\
191 % \href{http://www.ctan.org/pkg/xspace}%
192 % {\emph{The xspace package}},
193 % 2009/10/20
194 % \end{thebibliography}
195 % }
196 %
197 % \iffalse
198 % --------------------------------------------------------------------------- %
199 % \fi
200 %
201 % \DoNotIndex{\\,\_,\ ,\@@par}
202 % \DoNotIndex{\@bsphack}
203 % \DoNotIndex{\@car,\@cdr,\@classoptionslist,\@cons,\@currext,\@currname}
204 % \DoNotIndex{\@ehc,\@ehd,\@empty,\@esphack,\@expandtwoargs}
205 % \DoNotIndex{\@for,\@firstofone,\@firstoftwo}
206 % \DoNotIndex{\@gobble,\@gobblefour,\@gobbletwo,\@hangfrom}
207 % \DoNotIndex{\@ifnextchar,\@ifpackagelater,\@ifpackageloaded}
208 % \DoNotIndex{\@ifstar,\@ifundefined,\@latex@error,\@namedef,\@nameuse}
209 % \DoNotIndex{\@onlypreamble,\@parboxrestore,\@plus,\@ptionlist}
210 % \DoNotIndex{\@removeelement,\@restorepar,\@secondoftwo,\@setpar}
211 % \DoNotIndex{\@tempa,\@tempboxa,\@tempdima,\@tempdimb,\@tempdimc,\@tempb,\@tempc}
212 % \DoNotIndex{\@testopt}
213 % \DoNotIndex{\@undefined,\@unprocessedoptions,\@unusedoptionlist}
214 % \DoNotIndex{\p@,\z@}
215 % \DoNotIndex{\active,\addtocounter,\addtolength,\advance,\aftergroup}
216 % \DoNotIndex{\baselineskip,\begin,\begingroup,\bfseries,\box}
217 % \DoNotIndex{\catcode,\centering,\changes,\csname,\def,\divide,\do,\downarrow}
218 % \DoNotIndex{\edef,\else,\empty,\end,\endcsname,\endgraf,\endgroup,\expandafter}
219 % \DoNotIndex{\fi,\footnotesize,\global}
220 % \DoNotIndex{\hangindent,\hbox,\hfil,\hsize,\hskip,\hspace,\hss}
221 % \DoNotIndex{\ifcase,\ifdim,\ifnum,\ifodd,\ifvoid,\ifvmode}
222 % \DoNotIndex{\ifx,\ignorespaces,\itshape}
223 % \DoNotIndex{\Large,\large,\leavevmode,\leftmargini,\leftskip,\let,\linewidth}
224 % \DoNotIndex{\llap,\long,\m@ne,\margin,\mdseries,\message}
225 % \DoNotIndex{\newcommand,\newdimen,\newlength,\newline,\newif,\newsavebox}
226 % \DoNotIndex{\next,\nobreak,\nobreakspace,\noexpand,\noindent,\numberline}
227 % \DoNotIndex{\normalcolor,\normalfont,\normalsize,\or,\par,\parbox,\parfillskip}
228 % \DoNotIndex{\parindent,\parskip,\prevdepth,\protect,\protected@edef,\protected@write}
229 % \DoNotIndex{\providecommand,\quad}
230 % \DoNotIndex{\raggedleft,\raggedright,\relax,\renewcommand,\RequirePackage}
231 % \DoNotIndex{\rightskip,\rmfamily}
232 % \DoNotIndex{\sbox,\scriptsize,\scshape,\setbox,\setlength,\sffamily,\slshape}
233 % \DoNotIndex{\small,\string,\space,\strut}
234 % \DoNotIndex{\textheight,\the,\toks@,\typeout,\ttfamily}
235 % \DoNotIndex{\unvbox,\uparrow,\upshape,\usebox,\usepackage}
236 % \DoNotIndex{\value,\vbox,\vsize,\vskip,\wd,\width,\z@skip}
237 % \DoNotIndex{\AtBeginDocument,\AtEndOfPackage,\CurrentOption,\DeclareOption}
238 % \DoNotIndex{\ExecuteOptions,\GenericWarning,\IfFileExists,\InputIfFileExists}
239 % \DoNotIndex{\NeedsTeXFormat,\MessageBreak}
240 % \DoNotIndex{\PackageError,\PackageInfo,\PackageWarning,\PackageWarningNoLine}
241 % \DoNotIndex{\PassOptionsToPackage,\ProcessOptions,\ProvidesPackage}
242 %
243 % \iffalse
244 % --------------------------------------------------------------------------- %
245 % \fi
246 %
247 % \setlength{\parskip}{0pt plus 1pt}
248 % \changes{v1.0}{2008/02/16}{First version}
249 %
250 % \iffalse
251 % --------------------------------------------------------------------------- %
252 % \fi
253 %
254 % \clearpage
255 % \section{The implementation}
256 % \iffalse
257 %<*package>
258 % \fi
259 %
260 % \subsection{Identification}
261 %
262 % \begin{macrocode}
263 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
264 \ProvidesPackage{totalcount}[2018/01/21 v1.0a Total values of counters (AR)]
265 % \end{macrocode}
266 %
267 % \subsection{Initial code}
268 %
269 % \begin{macro}{\DeclareTotalCounter}
270 % \changes{v1.0}{2013/05/12}{Usage of \cs{totalcount@counters} delayed}
271 % |\DeclareTotalCounter|\marg{counter name}
272 % \begin{macrocode}
273 \newcommand*\DeclareTotalCounter[1]{%
274 \newcounter{totalcount@#1}%
275 \@namedef{total#1s}{\nfss@text{\reset@font\bfseries ??}}%
276 \@namedef{total#1es}{\@nameuse{total#1s}}%
277 \expandafter\newif\csname iftotal#1s\endcsname
278 \@namedef{iftotal#1es}{\@nameuse{iftotal#1s}}%
279 % \@nameuse{totalcount@set@#1}%
280 \AtBeginDocument{\@ifundefined{c@#1}%
281 {\PackageError{totalcount}{Undefined counter `#1'}\@ehc}%
282 {\@cons\totalcount@counters{{#1}}}}}
283 \@onlypreamble\DeclareTotalCounter
284 % \end{macrocode}
285 % \begin{macrocode}
286 \let\totalcount@counters\@empty
287 % \end{macrocode}
288 % \end{macro}
289 %
290 % \subsection{Declaration of options}
291 %
292 % \begin{macrocode}
293 \newcommand*\totalcount@xspace{}
294 \DeclareOption{xspace}{\renewcommand*\totalcount@xspace{\xspace}}
295 % \end{macrocode}
296 % \begin{macrocode}
297 \DeclareOption*{\expandafter\DeclareTotalCounter\expandafter{\CurrentOption}}
298 % \end{macrocode}
299 %
300 % \subsection{Execution of options}
301 %
302 % \begin{macrocode}
303 \ProcessOptions\relax
304 \ifx\totalcount@xspace\@empty\else
305 \RequirePackage{xspace}
306 \fi
307 % \end{macrocode}
308 %
309 % \subsection{Main code}
310 %
311 % \begin{macro}{\totalcount@addtocounter}
312 % |\totalcount@addtocounter|\marg{counter name}
313 % \begin{macrocode}
314 \newcommand*\totalcount@addtocounter[1]{%
315 \@ifundefined{c@totalcount@#1}{}{%
316 \addtocounter{totalcount@#1}{\value{#1}}}}
317 % \end{macrocode}
318 % \end{macro}
319 %
320 % \begin{macro}{\@stpelt}
321 % |\@stpelt|\marg{counter name}
322 % \begin{macrocode}
323 \let\totalcount@stpelt@ORI\@stpelt
324 \renewcommand*\@stpelt[1]{%
325 \totalcount@addtocounter{#1}%
326 \totalcount@stpelt@ORI{#1}}
327 % \end{macrocode}
328 % \end{macro}
329 %
330 % \begin{macro}{\totalcount@set}
331 % \changes{v1.0a}{2018/01/21}{A negative counter value will be handled correctly now}
332 % |\totalcount@set|\marg{counter name}\marg{value}
333 % \begin{macrocode}
334 \newcommand*\totalcount@set[2]{%
335 \@ifundefined{c@totalcount@#1}%
336 % {\global\@namedef{totalcount@set@#1}{\totalcount@set{#1}{#2}}}%
337 {}%
338 {\global\@namedef{total#1s}{#2\totalcount@xspace}%
339 \ifnum#2<1\relax \else
340 \global\@nameuse{total#1strue}%
341 \fi}}
342 % \end{macrocode}
343 % \end{macro}
344 %
345 % \begin{macrocode}
346 \AtBeginDocument{\AtEndDocument{%
347 \begingroup
348 \@tempswafalse
349 \if@filesw
350 \immediate\write\@mainaux{%
351 \string\providecommand\string\totalcount@set[2]{}}%
352 \fi
353 \def\@elt#1{%
354 \totalcount@addtocounter{#1}%
355 \edef\totalcount@tempa{\the\value{totalcount@#1}}%
356 \expandafter\let\expandafter\totalcount@tempb\csname total#1s\endcsname
357 \@expandtwoargs\totalcount@set{#1}{\totalcount@tempa}%
358 \expandafter\ifx\csname total#1s\endcsname\totalcount@tempb \else
359 \@tempswatrue
360 \fi
361 \if@filesw
362 \immediate\write\@mainaux{%
363 \string\totalcount@set{#1}{\totalcount@tempa}}%
364 \fi}%
365 \totalcount@counters
366 \if@tempswa
367 \PackageWarningNoLine{totalcount}{%
368 Total counter(s) have changed.\MessageBreak
369 Rerun to get them right}%
370 \fi
371 \endgroup}}%
372 % \end{macrocode}
373 %
374 % \iffalse
375 %</package>
376 % \fi
377 %
378 % \iffalse
379 % --------------------------------------------------------------------------- %
380 % \fi
381 %
382 % \Finale
383 %
384 \endinput