Debian Codegraph @

texmf-dist/doc/latex/assoccnt/assoccnt_doc.tex

raw
1 %% LaTeX package assoccnt - version 0.8 (2015/09/29)
2 %% Documentation for assoccnt.sty
3 %%
4 %%
5 %%
6 %% -------------------------------------------------------------------------------------------
7 %% Copyright (c) 2015 by Dr. Christian Hupfer <christian dot hupfer at yahoo dot de>
8 %% -------------------------------------------------------------------------------------------
9 %%
10 %% This work may be distributed and/or modified under the
11 %% conditions of the LaTeX Project Public License, either version 1.3
12 %% of this license or (at your option) any later version.
13 %% The latest version of this license is in
14 %% http://www.latex-project.org/lppl.txt
15 %% and version 1.3 or later is part of all distributions of LaTeX
16 %% version 2005/12/01 or later.
17 %%
18 %% This work has the LPPL maintenance status `author-maintained'.
19 %%
20 %% This work consists of all files listed in README
21 %%
22
23
24 \documentclass[12pt,paper=a4]{article}
25
26
27 \usepackage[lmargin=2cm,rmargin=2cm]{geometry}
28 \usepackage{savesym}%
29 \usepackage{bbding}%
30 \savesymbol{Cross}%
31
32 \usepackage{blindtext}%
33 \usepackage{xcolor}
34 \usepackage{imakeidx}%
35 \usepackage{tcolorbox}
36 \usepackage[tikz]{bclogo}
37 \usepackage{marginnote}
38
39 \usepackage{datetime}%
40
41 \usepackage{scrlayer-scrpage}%
42
43
44
45 \tcbuselibrary{listings}%
46 \tcbuselibrary{documentation}%
47
48 \usepackage{array}%
49
50
51
52 \usepackage{amsmath}%
53 \usepackage{amsthm}%
54
55 %\usepackage{calc} % Only for testing
56 \usepackage{totcount}%
57 \usepackage{enumitem}%
58
59 \usepackage[globalsuspend=true]{assoccnt}%
60
61
62
63 \usepackage{bookmark}%
64
65
66 \newcommand{\packagename}[1]{\textcolor{blue}{\textbf{\Envelope~#1}}\index{Paket!#1}}%
67
68
69
70 \newcommand{\MarkupPackageName}[2][lightgray]{%
71 \colorbox{#1}{\textcolor{black}{#2}}%
72 }%
73
74 \newcommand{\MarkupCounterName}[2][yellow]{%
75 \colorbox{#1}{\textcolor{black}{\texttt{#2}}}%
76 }%
77
78
79 \let\DeclareAssociatedCountersOrig\DeclareAssociatedCounters
80
81
82 \newtcolorbox{docCommandArgs}[1]{colbacktitle={blue},coltitle={white},title={Description of arguments of command \cs{#1}}}
83
84
85 \def\packageversion{\assoccntpackageversion}%
86
87 \makeindex
88
89 \newcommand{\PackageDocName}{assoccnt}%
90
91
92 \newtotcounter{totalpages}%
93 \newtotcounter{anothertotalpages}%
94
95 \newtotcounter{totalproofs}%
96 \newtotcounter{totalsections}%
97
98 \DeclareAssociatedCounters{section}{totalsections}%
99 \DeclareAssociatedCounters{proof}{totalproofs}
100
101
102 \DeclareAssociatedCounters{page}{totalpages,anothertotalpages}%
103
104
105
106 \begin{document}
107 \mmddyyyydate
108
109
110 \setlength{\parindent}{0pt}
111
112 \thispagestyle{empty}%
113
114 \begin{center}
115 \begin{tcolorbox}[colback=yellow!30!white,width=0.8\textwidth]
116 \large \bfseries%
117 \begin{center}%
118 \begin{tabular}{c}%
119 \textsc{\PackageDocName} \tabularnewline
120 \tabularnewline
121 Associate counters stepping simultaneously \tabularnewline
122 \tabularnewline
123 Version \packageversion \tabularnewline
124 \tabularnewline
125 \today \tabularnewline
126 \tabularnewline
127 \addtocounter{footnote}{2}
128 Author: Christian Hupfer\(^\mathrm{\fnsymbol{footnote}}\)% }{\makeatletter [email protected]}
129 \tabularnewline
130 \end{tabular}
131 \end{center}
132 \end{tcolorbox}
133 \makeatletter
134 \renewcommand{\thefootnote}{\fnsymbol{footnote}}%
135 \footnotetext{[email protected]}%
136 \makeatother
137
138 \end{center}
139
140 \tableofcontents
141 \clearpage
142
143
144
145
146 \pagestyle{scrheadings}%
147 \setheadsepline{2pt}[\color{blue}]
148 \setfootsepline{2pt}[\color{brown}]
149 \ifoot{\PackageDocName}
150 \cfoot{\packageversion}
151 \ofoot{\today}
152
153 \setcounter{footnote}{0}
154
155
156 \section{Introduction}
157
158 The aim of this package is to provide some additional support for example for a package like \MarkupPackageName{totcount}.
159
160 For example, the total number of pages in a document could be achieved by using
161
162 \begin{dispExample}%
163 \regtotcounter{page}
164 ...
165 The number of pages in the document is \number\totvalue{page} page(s).
166 \end{dispExample}%
167
168 This will work, as long there is no reset of the page counter, as it might happen in the case of \cs{setcounter} or \cs{pagenumbering} being applied in the document. The result is a false page counter total value.
169
170 This package provides associate counters, i.e. counters that are increased simultaneously with a driver counter and are not influenced by a a resetting of the driver counter, as long as not being added to the reset list by definition of the counter or explicitly by \cs{@addtoreset}.
171
172 This package defines some macros to handle associated counters. The only interception to the standard behaviour is within the redefined commands \cs{addtocounter} and \cs{setcounter}. The usual commands still work, as there is code added to their definition. In a previous version, \cs{stepcounter} and \cs{refstepcounter} were redefined, but since these use \cs{addtocounter} effectively, it was decided to use the basic command.
173
174 Internally, the associated counters are stored in one list per counter -- it is not recommended to operate on those lists directly.
175
176 Please note, that this package does not provide means for simultaneous stepping of counters defined by plain \TeX{} \cs{newcount} command.
177
178
179 \section{Package options}%
180
181 As of version \packageversion~ the package has only one option, regarding the suspending of counters globally, regardless, whether they are drivers or associated counters (more on this facility of the package, see \ref{section::suspendedresumedcounters}).
182
183 \begin{docKey}{globalsuspend}{=\meta{true/false}}{initially false}
184 If this key is set to \meta{true}, a a general driver can be set to the suspended list, i.e, it is not updated via \cs{addtocounter}. If unsure, do not use this option or say explicitly
185
186 \begin{dispListing}
187 \usepackage[globalsuspend=false]{assoccnt}
188 \end{dispListing}%
189 \end{docKey}
190
191
192
193 \section{Requirements and incompatibilities}%
194
195 \subsection{Required packages}
196
197 \begin{itemize}
198 \item \packagename{etoolbox}
199 \item \packagename{xkeyval}
200 \item \packagename{xcolor}
201 \item \packagename{xstring}
202 \end{itemize}
203
204 \subsection{Incompatibilities}
205
206
207 \begin{itemize}
208 \item This package does not work really well with the \packagename{calc} package. Load \packagename{calc} \textbf{before} \packagename{\PackageDocName}! \marginnote{\bcbombe}
209 \item This package does not work together when the Package \packagename{xifthen} is included. As of version \packageversion~I could not figure out, where the strange behaviour comes in. It's most likely an incompatibility between \packagename{etoolbox} and \packagename{xifthen}
210 \marginnote{\bcbombe}
211 \end{itemize}
212
213 \section{Documentation of Macros}
214 \tcbset{color command={blue}}
215
216 \subsection{Redefined standard commands}
217
218 \begin{docCommand}{setcounter}{\oarg{options}\marg{counter}\marg{counter value}}
219
220 This command behaves like the standard macro \cs{setcounter}, but has an additional optional 1st argument. This optional argument can be used to enable the setting of the driver counter value as well as the associated counter values at once.
221
222 \begin{docCommandArgs}{setcounter}%
223
224
225 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
226 \item \oarg{options}: As of version \packageversion, the only option is the key value argument
227
228 \begin{docKey}{AssociatedToo}{=\meta{true/false}}{initially false}
229 If enabled (\meta{true}), \cs{setcounter} will use the counter value for \underline{all} counters associated to this driver counter as well. Initially, this option is set to \meta{false}.
230 \end{docKey}
231
232 \begin{docKey}{AssociatedCounters}{=\meta{csv list of counters}}{initially unset}
233 If the comma separated list of counter is set, \cs{setcounter} increases those counters only, that are driven counters of the 2nd argument, any unknown counter in this list will generate a warning and is ignored otherwise.
234 \end{docKey}
235 The option keys \refKey{AssociatedToo} and \refKey{AssociatedCounters} are mutually exclusive!
236
237 \item \marg{counter}
238
239 Holds the name of the counter to be set.
240 \item \marg{counter value}
241 Holds the value to be set
242 \end{enumerate}
243 \end{docCommandArgs}
244
245 \end{docCommand}%
246
247
248 \subsection{Associated counters commands}
249
250 All macros have the general rule, that the driver counter is specified as 1st argument to the macro.
251
252
253 \begin{docCommand}{DeclareAssociatedCounters}{\oarg{options}\marg{driver counter}\marg{associated counters list}}
254 This command is the main macro of the package. It declares the counter names being specified in comma - separated - list (CSV) which should be stepped simultaneously when the driver counter is increased by \cs{stepcounter}.
255
256 \begin{docCommandArgs}{DeclareAssociatedCounters}
257
258 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
259 \item \oarg{options}: As of \packageversion, the optional argument \oarg{options} is not used so far, but is reserved for later purposes.
260
261 \item \marg{driver counter}
262
263 Holds the name of the driver counter to which the list of counters should be associated
264 \item \marg{associated counters list}
265
266 A comma separated list of counter names that should be associated to the driver counter
267 \end{enumerate}
268 \end{docCommandArgs}
269
270
271 \begin{itemize}
272 \item This command will be a preamble command in future
273 \item This command should be used as early as possible, i.e. in the preamble of the document, since the driven counters are not increased as long as they are not associated to the driver counter. On the hand, it is possible, to control the starting point of the association at any position in the body of the document, when the association should start later on.
274 \end{itemize}
275
276
277 % Relax for documentation purposes
278 \renewcommand{\DeclareAssociatedCounters}[3][]{\relax}%
279 \begin{dispExample}
280 %%%% The association of anothertotalpages in this example just takes place here, so the stepping of the counter will start from here and providing a 'wrong' value.
281 %%%%
282 \DeclareAssociatedCounters{page}{totalpages,anothertotalpages}%
283 This document has \number\totvalue{totalpages} (note: \number\totvalue{anothertotalpages}) pages.
284 \end{dispExample}
285 %\let\DeclareAssociatedCounters\DeclareAssociatedCountersOrig%
286
287 \begin{itemize}
288 \item Current version state:
289 \begin{itemize}
290 \item No checking whether the 2nd and 3rd arguments hold counter names is applied.
291 \item No check is done whether two (or more) associated counters are mutually associated.
292 \end{itemize}
293 \item A self-association of the driver counter to itself is ignored internally as this would lead to inconsistent counter values.
294 \item The order of the specification of associated counters in the 2nd arguments is of no importance.
295 \item Specifing an associated counter name multiple times has no effect, only the first occurence of the name will be used.
296 \end{itemize}
297
298 \end{docCommand}
299
300
301 \begin{docCommand}{AddAssociatedCounters}{\oarg{options}\marg{driver counter}\marg{associated counters list}}
302 This command adds some counters to the associated counter list for a specific driver counter -- if this list does not exists, the \LaTeX{} run will be stopped. You have to use \refCom{DeclareAssociatedCounters} first, to set up the driver counter hook.
303
304
305 \begin{docCommandArgs}{AddAssociatedCounters}
306
307 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
308 \item \oarg{options}: As of \packageversion, the optional argument \oarg{options} is not used so far, but is reserved for later purposes.
309
310 \item \marg{driver counter}
311
312 Holds the name of the driver counter to which the list of counters should be associated
313 \item \marg{associated counters list}
314
315 A comma separated list of counter names that should be associated to the driver counter
316 \end{enumerate}
317 \end{docCommandArgs}
318
319
320 % macro of the package. It declares the counter names being specified in comma - separated - list (CSV) which should be stepped simultaneously when the driver counter is increased by \cs{stepcounter}.
321
322 \end{docCommand}%
323
324 \begin{docCommand}{RemoveAssociatedCounter}{\marg{driver counter}\marg{associated counter}}
325 This command removes a counter from the existing list for a driver counter, i.e. the counter will not be increased any longer by \cs{stepcounter}. It can be increased however manually, of course.
326 \end{docCommand}
327
328
329
330 \begin{dispExample}
331 \RemoveAssociatedCounter{page}{anothertotalpages}
332 This document has \number\totvalue{totalpages} (beware: \number\totvalue{anothertotalpages}) pages.
333 \end{dispExample}
334
335
336
337 \begin{docCommand}{RemoveAssociatedCounters}{\marg{driver counter}\marg{list of associated counters}}
338 This command removes the comma-separated-value list of counters from the existing list for a driver counter, i.e. the counters will not be increased any longer by \cs{stepcounter}. They can be increased however manually, of course.
339
340 Take care not to confuse the commands \refCom{RemoveAssociatedCounters}
341 and{}\linebreak \refCom{RemoveAssociatedCounter}
342 \end{docCommand}
343
344 \begin{docCommand}{ClearAssociatedCounters}{\marg{driver counter}}
345 This command clears the internal list for all counters associated to the \marg{driver counter}. The counters will not be increased automatically.
346 \end{docCommand}
347
348
349 \clearpage
350
351
352 \subsection{Driver counter commands}
353
354
355 \begin{docCommand}{AddDriverCounter}{\oarg{options}\marg{driver counter name}}
356
357 \begin{docCommandArgs}{AddDriverCounter}%
358
359 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
360 \item \oarg{options}: As of \packageversion, the optional argument \oarg{options} is not used so far, but is reserved for later purposes.
361
362 \item \marg{driver counter name}
363
364 Holds the name of the driver counter that should be added to the list of driver counters.
365 \end{enumerate}
366
367 \end{docCommandArgs}
368
369 \end{docCommand}%
370
371
372 \begin{docCommand}{ClearDriverCounter}{\oarg{options}}%
373
374 This clears completely the list of driver counters, such that no counters are regarded as being associated -- i.e. no driver is hold as being a driver counter.
375
376 The optional argument is not used as of version \packageversion.
377
378 \end{docCommand}
379
380
381 \subsection{Commands for queries}
382
383 Sometimes it might be necessary to get information, whether a counter is regarded as a driver or as an associated counter. This section describes some query macros in order to obtain this information.
384
385
386 \begin{docCommand}{IsAssociatedToCounter}{\marg{driver counter}\marg{associated counter}\marg{True branch}\marg{False branch}}
387 This macro checks, whether a counter is associated to a particular given driver counter and expands the corresponding branch. If the internal driver counter list does not exist, the false branch will be used, since this also means, that the possibly associated counter is not associated at all.
388
389
390
391 \begin{docCommandArgs}{IsAssociatedToCounter}%
392
393 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
394 \item \marg{driver counter}
395
396 Holds the name of the driver counter to which \marg{associated counter} the could possibly be associated.
397 \item \marg{associated counter}
398
399 Contains the name of the possibly associated counter.
400
401 \item \marg{True branch}
402
403 This code is expanded if the counter is associated to the driver, otherwise it is ignored.
404
405 \item \marg{True branch}
406
407 This code is expanded if the counter is \textbf{not} associated to the driver, otherwise it is ignored.
408
409 \end{enumerate}
410 \end{docCommandArgs}
411
412
413 \begin{dispExample}
414 % Remove associated counter first for demonstration purposes
415 \RemoveAssociatedCounter{page}{anothertotalpages}
416 \IsAssociatedToCounter{page}{totalpages}{Yes, totalpages is associated}{No, totalpages is not associated}
417
418 \IsAssociatedToCounter{page}{anothertotalpages}{Yes, anothertotalpages is associated}{No, anotherpages is not associated}
419 \end{dispExample}
420
421 See also
422
423 \begin{itemize}
424 \item \refCom{IsAssociatedCounter} for checking whether a counter is associated
425 \item \refCom{IsDriverCounter} in order to check whether a counter is a driver.
426 \item \refCom{GetDriverCounter} returns the driver counter name for a given associated counter name
427 \item \refCom{AssociatedDriverCounterInfo} prints verbose information to the document (not to the screen!)
428 \end{itemize}
429
430
431 \end{docCommand}
432
433
434 \begin{docCommand}{GetDriverCounter}{\marg{counter name}}%
435
436 This commands returns the driver counter to which the counter name of the first argument is connected to. If the counter is not defined, the macro returns nothing.
437
438 \begin{itemize}
439 \item No check whether the counter name is defined is performed
440 \item No check whether the counter is associated at all is performed. Usage of this command in conjunction with \refCom{IsAssociatedCounter} is strongly encouraged.
441 \end{itemize}
442
443
444 \begin{dispExample}%
445 totalpages is associated to the \textcolor{blue}{\textbf{\GetDriverCounter{totalpages}}} counter.
446 % Try with an undefined counter name
447 humptydumpty is associated to the \textcolor{blue}{\textbf{\GetDriverCounter{humptydumpty}}} counter.
448
449 \end{dispExample}%
450
451 \end{docCommand}%
452
453
454 \begin{docCommand}{IsAssociatedCounter}{\marg{counter name}\marg{True branch}\marg{False branch}}%
455
456 This commands tests, whether a given counter name is an associated counter and expands correspondingly the true or the false branch. The command does not tell to which driver the counter it is associated -- this information can be obtained by \refCom{GetDriverCounter}.
457
458 \begin{docCommandArgs}{IfAssociatedCounter}%
459
460 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
461 \item \marg{counter name}%
462
463 Contains the name of the possibly associated counter
464
465 \item \marg{True branch}
466
467 This code is expanded if the counter is associated to a driver, otherwise it is ignored
468
469 \item \marg{True branch}
470
471 This code is expanded if the counter is \textbf{not} associated a driver, otherwise it is ignored
472
473 \end{enumerate}
474 \end{docCommandArgs}
475
476
477 \begin{dispExample}
478 \IsAssociatedCounter{section}{Yes, section is an associated counter}{No, section counter does not have the associated counter properties}
479 \IsAssociatedCounter{totalpages}{Yes, totalpages is an associated counter}{No, totalpages counter does not have the associated counter properties}
480 \end{dispExample}
481
482 \end{docCommand}%
483
484
485
486 \begin{docCommand}{IsDriverCounter}{\marg{driver counter name}\marg{True branch}\marg{False branch}}%
487
488 This commands tests, whether a given counter name is a driver counter and expands correspondingly the true or the false branch.
489
490 \begin{docCommandArgs}{IfDriverCounter}%
491
492 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
493 \item \marg{driver counter name}%
494
495 Contains the name of the possible driver counter
496
497 \item \marg{True branch}
498
499 This code is expanded if the counter is a driver, otherwise it is ignored
500
501 \item \marg{True branch}
502
503 This code is expanded if the counter is \textbf{not} a driver, otherwise it is ignored
504 \end{enumerate}
505 \end{docCommandArgs}
506
507
508 \begin{dispExample}
509 \IsDriverCounter{section}{Yes, section is a driver counter}{No, section counter does not have driver properties}
510 \end{dispExample}
511
512 \end{docCommand}%
513
514 \begin{docCommand}{IsSuspendedCounter}{\marg{counter name}\marg{true branch}\marg{false branch}}
515 See \nameref{section::suspendedresumedcounters} on this topic.
516
517 This command checks, whether a counter is suspended, i.e. not updated at all and expands the corresponding branches.
518
519 \begin{docCommandArgs}{IfSuspendedCounter}%
520
521 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
522 \item \marg{counter name}%
523
524 Contains the name of counter presumed to be suspended
525
526 \item \marg{True branch}
527
528 This code is expanded if the counter is suspended, otherwise it is ignored
529
530 \item \marg{True branch}
531
532 This code is expanded if the counter is \textbf{not} suspended, otherwise it is ignored
533
534 \end{enumerate}
535 \end{docCommandArgs}
536
537
538
539 \end{docCommand}
540
541
542 \begin{docCommand}{AssociatedDriverCounterInfo}{\marg{counter name}}
543
544 This command is purposed for statistics only, for package/class authors for example and should not be used in a real document, as it generates verbose output to the document.
545
546
547
548 \begin{dispExample}
549 %% Adding the counter anothertotalpages first
550 \AddAssociatedCounters{page}{anothertotalpages}%
551 \AssociatedDriverCounterInfo{page}%
552 \end{dispExample}
553
554 \begin{dispExample}
555 % This shows information on an associated counter
556 \AssociatedDriverCounterInfo{totalpages}%
557 \end{dispExample}
558
559 \begin{dispExample}
560 % This shows information on a counter which is neither a driver nor an associated counter
561 \AssociatedDriverCounterInfo{equation}%
562 \end{dispExample}
563
564
565 \end{docCommand}%
566
567 \subsection{Information on counters}
568
569 On occasions it might be important to have some information which counter has been changed last. Since there are four commands manipulating counter values, there are four corresponding routines for this:
570
571 \begin{docCommand}{LastAddedToCounter}{}
572 This command has no arguments and expands to the name of the counter which was used last in \cs{addtocounter}. There is no further typesetting done with the countername.
573
574 \begin{dispExample}
575 \newcounter{SomeCounter}
576
577 \addtocounter{SomeCounter}{10}
578
579 The last counter something added to was \PrettyPrintCounterName{\LastAddedToCounter}.
580 \end{dispExample}%
581
582 \end{docCommand}%
583
584 \begin{docCommand}{LastSteppedCounter}{}
585 This command has no arguments and expands to the name of the counter which was stepped last using \cs{stepcounter}. There is no further typesetting done with the countername.
586
587 \begin{dispExample}
588 \stepcounter{SomeCounter}
589
590 The last counter being stepped was \PrettyPrintCounterName{\LastSteppedCounter}.
591 \end{dispExample}%
592
593 \end{docCommand}%
594
595 \begin{docCommand}{LastRefSteppedCounter}{}
596
597 \begin{dispExample}
598 \begin{equation}
599 E = mc^2 \label{eq::einstein}
600 \end{equation}
601 % \stepcounter{SomeCounter}
602
603 The last counter being refstepped was \PrettyPrintCounterName{\LastRefSteppedCounter}.
604 \end{dispExample}%
605
606 \end{docCommand}%
607
608
609
610
611
612 \begin{docCommand}{LastSetCounter}{}
613 This command has no arguments and expands to the name of the counter which was set last using \refCom{setcounter}. There is no further typesetting done with the countername.
614
615 \begin{dispExample}
616 \setcounter{SomeCounter}{21}%
617
618 The last counter being stepped was \PrettyPrintCounterName{\LastSetCounter}.
619 \end{dispExample}%
620
621 \end{docCommand}%
622
623 Please note, that all of this commands are only working in the current run of compilation, i.e. \underline{after} there has been some operation on the counters. They can't be used for information on the last changed counter in a previous run.
624
625 \subsection{Minor macros}
626
627 For the informational output on counter properties in conjunction with the macro
628 \refCom{AssociatedDriverCounterInfo}, some helper macros have been defined:
629
630 \begin{docCommand}{PrettyPrintCounterName}{\oarg{countertype}\marg{counter name}}
631 This command just prints a counter name with frame. It's meant of informational use only.
632 \begin{docCommandArgs}{PrettyPrintCounterName}
633 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
634 \item \oarg{options}%
635
636 As of version \packageversion, the only option is a key value:
637 \begin{docKey}{countertype}{=\meta{general,driver,associated}}{general}
638 Use
639 \begin{itemize}
640 \item \meta{general} for an arbitrary counter name
641 \item \meta{driver} for a driver counter
642 \item \meta{associated} for an associated counter
643 \end{itemize}
644 \end{docKey}
645
646 \item \marg{counter name}
647 Contains the name of counters to be displayed
648
649 \end{enumerate}
650 \end{docCommandArgs}%
651
652 Please note, that as of version \packageversion, this command does not autodetect the property of the counter nor if the 2nd argument holds a real counter name at all
653 \end{docCommand}%
654
655 \begin{docCommand}{GeneralCounterInfoColor}{}
656 This macro holds the text color for a general counter, it defaults to \meta{\textcolor{\GeneralCounterInfoColor}{\expandafter{\GeneralCounterInfoColor}}}%
657 \end{docCommand}
658
659
660 \begin{docCommand}{DriverCounterInfoColor}{}
661 This macro holds the text color for a driver counter, it defaults to \meta{\textcolor{\DriverCounterInfoColor}{\expandafter{\DriverCounterInfoColor}}}%
662 \end{docCommand}
663
664 \begin{docCommand}{AssociatedCounterInfoColor}{}
665 This macro holds the text color for an associated counter, it defaults to \meta{\textcolor{\AssociatedCounterInfoColor}{\expandafter\AssociatedCounterInfoColor}}%
666 \end{docCommand}
667
668 \begin{dispExample}
669 \PrettyPrintCounterName[countertype=general]{equation}
670 \end{dispExample}
671
672
673
674 \section{Suspending and resuming associated counters}\label{section::suspendedresumedcounters}
675
676 Rather than remove an associated counter from the list, it is possible to suspend the automatic stepping for a while and then resume it, for example, if the value of a counter should not be stepped within a specific chapter etc.
677
678 \begin{docCommand}{SuspendCounters}{\oarg{options}\marg{counters list}}%
679 \begin{docCommandArgs}{SuspendCounters}%
680
681 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
682 \item \oarg{options}%
683
684 Not used so far, reserved for later usages
685
686 \item \marg{counters list}%
687
688 Contains the name of counters to be suspended, separated by commas (CSV - list)
689 \end{enumerate}
690
691 \end{docCommandArgs}
692 \end{docCommand}%
693
694 \begin{docCommand}{ResumeSuspendedCounters}{}
695 This command has no arguments and revokes the suspension of \textbf{all} counters.
696 \end{docCommand}
697
698
699 Some remarks:
700
701 \begin{itemize}
702 \item
703 Please note, that it is possible, to suspend an arbitrary counter, if the package option \refKey{globalsuspend} is set to \meta{true}. Handle this option with care!
704 \item If a driver counter is suspended, all counters associated to it are suspended too!
705 \end{itemize}%
706
707 \begin{dispExample}
708 \textbf{This example shows 4 equations, but only two of them are counted}
709 \newtotcounter{totalequations}
710 \DeclareAssociatedCounters{equation}{totalequations}
711
712 \begin{equation}
713 E_{0} = mc^2
714 \end{equation}
715
716 Now suspend the totalequations:
717
718 \SuspendCounters{totalequations}
719 \begin{equation}
720 E^2 = \left({ pc}\right)^2 + E^{2}_{0}
721 \end{equation}
722
723 \begin{equation}
724 m(v) = \frac{m_{0}}{\sqrt{1-\frac{v^2}{c^2}}}
725 \end{equation}
726
727 And resume it: \ResumeSuspendedCounters
728
729 \begin{equation}
730 E = h \nu
731 \end{equation}
732
733 There are \number\totvalue{totalequations}~equations in here!
734 \end{dispExample}
735
736
737
738
739 \section{Internals commands}
740
741 Basically spoken, all internal commands use \cs{@@assoccnt@@} as prefix and are designed to be used only within the package. There is no need to call them in a document directly. Nevertheless, the macros are described for completeness. The direct usage is discouraged, however, if needed, they have to included in a \cs{makeatletter} \ldots \cs{makeatother} pair\footnote{Well, \cs{makeatother} could be omitted, but it is not advised to do so}.
742
743 \begin{docCommand}{@@assoccnt@@removefromlist}{\marg{list name}\marg{entry name}}
744
745 This command removes an entry (i.e. a counter name) from a general list -- it is not connected to the associated counter features at all.
746 \begin{docCommandArgs}{@@assoccnt@@removefromlist}%
747 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
748 \item \marg{list command sequence name}%
749
750 Contains the name of the list
751
752 \item \marg{entry name}
753
754 This argument should contain the name to be removed from the list. If this name is not present, the original list is maintained unchanged.
755
756 \end{enumerate}
757 \end{docCommandArgs}
758
759 \end{docCommand}%
760
761
762 \begin{docCommand}{@@assoccnt@@generateboundtocounterslist}{\marg{associated counter name}}
763
764 This command generates a list for each associated counter, holding the counter names to which this counter is associated to. As of version \packageversion~this list can contain only \textbf{one} entry, since a counter cannot not be associated to multiple driver counters.
765
766 The only argument \marg{associated counter name} holds the name of the associated counter name. The list name is managed internally and should not be redefined.
767
768 \makeatletter
769 \begin{dispExample}
770 \@@assoccnt@@generateboundtocounterslist{totalpages}%
771 \end{dispExample}%
772 \makeatother
773
774 \end{docCommand}%
775
776
777 \begin{docCommand}{@@assoccnt@@addassociatedcounter}{\oarg{option}\marg{associated counters list name}\marg{associated counter name}}
778
779 This is the low level command, that
780 \begin{enumerate}
781 \item adds a single counter as an associated one to the appropiate list and prevents a multiple addition to this list
782 \item adds a driver counter to the list of driver counters
783 \item prevents multiple addition of the associated counter to other lists
784 \end{enumerate}
785
786 Use the wrapper command \cs{AddAssociatedCounter} for proper usage.
787
788 \begin{docCommandArgs}{@@assoccnt@@addassociatedcounter}%
789 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
790 \item \oarg{driver counter name}
791
792 Contains the name of driver counter
793
794 \item \marg{associated counters list name}
795
796 This argument should contain the list name for the per driver counter list of associated counters, i.e. use \cs{@@assoccnt@@generatelistname} for this argument
797
798 \item \marg{associated counter name}
799
800 The name of the counter to be associated.
801
802 \end{enumerate}
803 \end{docCommandArgs}
804
805 \end{docCommand}
806
807
808
809 \begin{docCommand}{@@assoccnt@@associatedcounterslistsuffix}{}
810 This command holds the name of the suffix for the associated counters list. It should not be redefined.
811 \end{docCommand}
812
813
814 \begin{docCommand}{@@assoccnt@@generatelistname}{\marg{driver counter name}}
815
816 This macro generates a list from the driver counter name and the driver counter list suffix (see \refCom{@@assoccnt@@associatedcounterslistsuffix})
817
818 \makeatletter
819 \begin{dispExample}
820 \@@assoccnt@@generatelistname{page}
821 \end{dispExample}
822 \makeatother
823
824 \end{docCommand}
825
826
827 \clearpage
828
829 \section{To-Do list}
830
831 \begin{itemize}
832 \item Better counter definition/copy counter routines \(\longrightarrow\) another package perhaps
833 \item Check the existence of driver and associated counters
834 \item Provide a better internal list organization
835 \item Some macro names might be non-intuitive
836 \item Improve documentation
837 \item Allow for specific counter to be resumed from suspension instead of resuming all
838 \item Allow for an associated counter to have multiple masters
839 \item Complete redesign and rewrite with \packagename{expl3} -- this will provide better list features
840 \end{itemize}
841
842 If you
843
844 \begin{itemize}
845 \item find bugs
846 \item errors in the documentation
847 \item have suggestions
848 \item have feature requests
849 \end{itemize}
850
851 don't hesitate and contact me via \makeatletter [email protected]\makeatother
852
853 \clearpage
854
855 \section{Acknowledgments}
856
857 I would like to express my gratitudes to the developpers of fine \LaTeX{} packages and of course
858 to the users at tex.stackexchange.com, especially to
859
860 \begin{itemize}
861 \item Paulo Roberto Massa Cereda
862 \item Enrico Gregorio
863 \item Joseph Wright
864 \item David Carlisle
865 \item Werner
866 \item Gonzalo Medina
867 \item Cosmo Huber (for providing the bug report with the \packagename{calc} package.)
868 \end{itemize}
869
870 for their invaluable help on many questions on macros.
871
872 \vspace{2\baselineskip}
873 A special gratitude goes to Prof. Dr. Dr. Thomas Sturm for providing the wonderful \MarkupPackageName{tcolorbox} package which was used to
874 write this documentation.
875
876 \clearpage
877
878 \section{Version history}
879 Note the pre - 0.6 - version history has to be reestablished
880 \begin{itemize}
881 \item 0.8: A second bug fix for usage version 0.7 -- packagename{calc} and this package do not really work together.
882 \item 0.7: A second bug fix for usage with \packagename{calc} has been done.
883 \item 0.6: \begin{itemize}
884 \item A major bug fixed due to some error in usage together with \packagename{calc} when the driven counters are not stepped any longer.
885 The culprit was in \PackageDocName that the counter reset list was not really disabled.
886
887 Thanks to this question \url{http://tex.stackexchange.com/questions/269731/calc-breaks-assoccnt} this bug was detected.
888 \item The documentation was renamed from `assoccntdoc` to `\url{assoccnt_doc}`
889 \end{itemize}
890 \end{itemize}
891
892
893 \phantomsection
894 \appendix\label{examplesappendix}
895
896
897
898 \section[Total number of sections]{Example: Total number of sections}
899 In this example, all sections of this document are counted, i.e. the current one as well as all following ones.
900 \begin{dispExample}
901 This document has \total{totalsections} section(s)%
902 \end{dispExample}
903
904
905
906 \section[Subsection with suspension]{Example: Total number of subsections with suspension}
907
908 In this example, the subsections of this document are counted but later on, the associatedcounter is removed from the list, so it is frozen.
909
910 %\DeclareAssociatedCounters{subsection}{totalsubsections}%
911
912 %\renewcommand{\DeclareAssociatedCounters}[3]{\relax}%
913
914 \begin{dispExample}
915 \newtotcounter{totalsubsections}%
916 \newtotcounter{othertotalsubsections}%
917 \DeclareAssociatedCounters{subsection}{totalsubsections}%
918
919 \subsection{First dummy subsection}
920 SubSection counter: \thesubsection~-- \number\totvalue{totalsubsections}
921 \subsection{Second dummy subsection}
922 SubSection counter: \thesubsection~-- \number\totvalue{totalsubsections}
923
924 \RemoveAssociatedCounter{subsection}{totalsubsections}%
925 \subsection{Third dummy subsection after removing the associated counter}
926
927 SubSection counter: \thesubsection~-- \number\totvalue{totalsubsections}
928
929 \end{dispExample}
930
931 \section[Total number of proofs]{Example: Total number of proofs}
932
933
934 \begin{dispExample}
935 % \usepackage{amsthm} is needed
936 \newcounter{proof}%
937 \newtotcounter{anotherproofcounter}%
938 \newtheorem{Proof}[proof]{Proof}%
939 \DeclareAssociatedCounters{proof}{totalproofs,anotherproofcounter}
940 \begin{Proof}
941 It's trivial.
942 \end{Proof}
943
944 \begin{Proof}[On Brontosaurs]
945 See excavations!
946 \end{Proof}
947
948 %%% Manipulate the counter
949 \setcounter{proof}{17}
950
951 \begin{Proof}[Yet another proof]
952 \begin{align*}
953 E &= m c^2
954 \end{align*}
955 \end{Proof}
956
957 This document has \number\value{anotherproofcounter} proofs %
958 Now let us manipulate the counter proof again:
959 \setcounter[AssociatedCounters={totalproofs}]{proof}{200}
960
961 This document has \number\totvalue{totalproofs} (manipulated counter) proofs where as the unmanipulated counter still shows \number\value{anotherproofcounter} proofs %
962 \end{dispExample}
963
964 This example shows, that the usage of the options to \cs{setcounter} should be used with care!
965
966
967 \subsection{Suspension of a non-associated counter}
968 This example will show the suspension of a non-associated counter
969
970
971 \begin{dispExample}
972 \setcounter{equation}{0}%
973 \SuspendCounters{equation}%
974 \begin{equation}
975 E_{0} = mc^2
976 \end{equation}
977
978 \begin{equation}
979 E^2 = \left({ pc}\right)^2 + E^{2}_{0}
980 \end{equation}
981
982 \begin{equation}
983 m(v) = \frac{m_{0}}{\sqrt{1-\frac{v^2}{c^2}}}
984 \end{equation}
985
986
987 There are \number\value{equation}~equations in here!
988 \end{dispExample}
989
990
991 \clearpage
992
993 %%%% Index of commands
994
995 \printindex
996
997 \end{document}