Debian Codegraph @

texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex

raw
1 %% Documentation for cntperchap.sty
2 %%
3 %% Version 0.3 (2015/06/01}
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 `maintained'.
19 %%
20 %% This work consists of all files listed in README
21 %%
22
23
24 \documentclass[12pt,english]{ltxdoc}
25 \usepackage{scrlayer-scrpage}
26 \usepackage[tikz]{bclogo}
27 \usepackage[lmargin=3cm,rmargin=3cm,a4paper]{geometry}
28 \usepackage{savesym}%
29 \usepackage{bbding}%
30 \savesymbol{Cross}%
31
32 \usepackage{blindtext}%
33 \usepackage{enumitem}%
34 \usepackage{datetime}%
35 \usepackage{imakeidx}%
36
37
38 \usepackage[most]{tcolorbox}
39 \usepackage{cntperchap}
40
41 \RegisterCounters{section,subsection,subsubsection,table,figure}
42
43
44 \tcbuselibrary{documentation}
45
46 \tcbset{color command={blue}}
47
48
49
50
51 \newcommand{\tcolorboxdoclink}{http://mirrors.ctan.org/macros/latex/contrib/tcolorbox/tcolorbox.pdf}
52
53 \newcommand{\packagename}[1]{\fbox{\textcolor{blue}{\textbf{\ding{41}~#1}}}\index{Package!#1}}%
54 \newcommand{\classname}[1]{\fbox{\textcolor{brown}{\textbf{\Writinghand~#1}}}\index{Class!#1}}%
55
56
57 \newcommand{\handrightnote}{\tcbdocmarginnote{\ding{43}}}
58
59
60 \newtcolorbox{docCommandArgs}[1]{colbacktitle={blue},coltitle={white},title={Description of arguments of command \cs{#1}}}
61
62
63 \def\packageversion{0.3}%
64
65 \makeindex
66
67 \newcommand{\PackageDocName}{\cpspackagename.sty}%
68
69
70 \hypersetup{breaklinks=true}
71
72 \begin{document}
73 \mmddyyyydate
74
75
76 \setlength{\parindent}{0pt}
77
78 \thispagestyle{empty}%
79
80 \begin{center}
81 \begin{tcolorbox}[boxrule=1mm,arc=4mm,colback=yellow!30!white,width=0.8\textwidth]
82 \large \bfseries%
83 \begin{center}%
84 \begin{tabular}{c}%
85 \textsc{\PackageDocName} \tabularnewline
86 \tabularnewline
87 Store counter values per chapter \tabularnewline
88 (or other section levels) \tabularnewline
89 \tabularnewline
90 Version \packageversion \tabularnewline
91 \tabularnewline
92 \today \tabularnewline
93 \tabularnewline
94 \addtocounter{footnote}{2}
95 Author: Christian Hupfer\(^\mathrm{\fnsymbol{footnote}}\)
96 \tabularnewline
97 \end{tabular}
98 \end{center}
99 \end{tcolorbox}
100 \makeatletter
101 \renewcommand{\thefootnote}{\fnsymbol{footnote}}%
102 \footnotetext{[email protected]}%
103 \makeatother
104
105 \end{center}
106
107 \tableofcontents
108 \clearpage
109
110
111
112
113 \pagestyle{scrheadings}%
114 \setheadsepline{2pt}[\color{blue}]
115
116 \setcounter{footnote}{0}
117
118
119 \section{Disclaimer}
120 This package as of its version \packageversion\ is under constant development and as such subject to macro interface changes as well as renaming of macros.
121
122 Although the example in this manual treats with the \docCounter{page} counter, it is not recommended to use this package in conjunction with the page counter for a serious document. The page counter is quite difficult to track.
123
124 \section{Introduction}
125
126 The aim of this package is to provide support for a summary in advance how many sections, subsections, etc. or figures, tables, equations there will be in predefined section level, for example per chapters. The values are stored at the beginning of a new chapter and written to \cs{jobname.cpsfoo} files, where \docCounter{foo} is short for the relevant counter name. The section level can be one of standard levels
127 \begin{itemize}
128 \item \cs{part}
129 \item \cs{chapter}
130 \item \cs{section}
131 \item \cs{subsection}
132 \item \cs{subsubsection}
133 \item \cs{paragraph}
134 \item \cs{subparagraph}
135 \end{itemize}
136
137 The section level can be specified as an option (see \ref{section::package_options}), but is preconfigured on the underlying document class. For \classname{book}-like classes, the section level defaults to \cs{chapter}, for \classname{article}-like documentclasses it defaults to \cs{section}.
138
139 In fact, there is no need of having a section level at all. Basically any environment can serve as a track level, however, only one environment type per document so far only.
140
141
142 This package is the consequence of the question \url{http://tex.stackexchange.com/questions/241559/how-to-count-the-total-number-of-sections-within-a-chapter} by the user \texttt{gsl}.
143
144 \begin{tcolorbox}[title={Statistics of the local chapter},colbacktitle=yellow,coltitle=black]
145 \ShowStatistics[1]
146 \end{tcolorbox}
147
148 \subsection{Basic usage}
149
150 \tcbdocmarginnote{\ding{43}} If \refAuxcs{nofiles} is used, no package related files are generated or included, similar to the behaviour for \refAuxcs{tableofcontents} etc.
151
152 \begin{tcblisting}{listing only}
153 \documentclass{book}
154 \usepackage{cntperchap}
155
156 \RegisterCounters{section,subsection,subsubsection,table,figure}
157
158 \begin{document}
159 \section{First section}
160 \ShowStatistics
161 \end{document}
162 \end{tcblisting}
163
164 \section{Package options}%
165 \label{section::package_options}
166
167 As of version \packageversion~ the package has only following options so far:
168
169
170 \begin{itemize}
171
172 \item \begin{docKey}{autodefine}{}{}
173 This option enables the automatic counter definition if some undefined counter is specified during the registration process.
174 \end{docKey}
175
176 \item \begin{docKey}{draft}{}{default is draft}
177 This option enables the explicit statistics
178 \end{docKey}
179 \item \begin{docKey}{final}{}{default is off}
180 This option disables the explicit statistics
181 \end{docKey}
182
183 \item \begin{docKey}{noendclose}{}{default is false}
184 This option prevents the explicit closing of output files and provides the means to enter a hook into the \cs{AfterEndDocument} command.
185 \end{docKey}
186
187
188 \item \begin{docKey}{tracklevel}{\meta{=chapter}}{chapter}
189 This option sets the sectioning level or the environment under supervision (tracked). If not specified, the counters are stored on a per chapter base, if set to \texttt{section}, the counter values are stored on a per section level etc. The section level has to be specified without the blackslash $\backslash$.
190
191 Unknown section levels or environment (counters) will lead to a compilation error. As of version \packageversion~ this requires that the environment and the corresponding counter share the same name.
192 \end{docKey}
193
194
195 \item \begin{docKey}{verbose}{}{}
196 This option enables verbose output during compilation.
197 \end{docKey}
198
199
200
201 \end{itemize}
202
203 \section{Requirements and incompatibilities}%
204
205 \subsection{Required packages}
206
207 \begin{itemize}
208 \item \packagename{assoccnt}%
209 \item \packagename{etoolbox}%
210 \item \packagename{ifthen}%
211 \item \packagename{morewrites}%
212 \item \packagename{xkeyval}%
213 \item \packagename{xparse}%
214 \end{itemize}
215
216 The packages \packagename{etoolbox} and \packagename{xkeyval} are already loaded by \packagename{assoccnt}.
217
218 \subsection{Incompatibilities}
219
220 This package has been tested with the standard classes \classname{article}, \classname{book} and \classname{report} as well as with \classname{memoir} and the relevant \classname{KOMA} equivalents. As of version \packageversion\ for those classes there are no known incompatibilities with the general behaviour of the package, however, there is an issue with \packagename{assoccnt} and \packagename{xifthen} which is not solved so far.
221
222 \marginnote{\bcbombe} It would be nice to adapt the package for usage on a per frame base with the \classname{beamer} class, but this seems both not really necessary as well as quite difficult, since \classname{beamer} follows different strategies about the usage of ``pages'' or ``sections'', see \ref{section::todo}
223
224
225 %This package will so far if the document class does not provide the chapter command. It should work with the standard document classes of \classname{book} and \classname{report} as well as with \classname{memoir} and the relevant \classname{KOMA} equivalents.
226
227
228 \section{Documentation of Macros}
229
230 \subsection{Preamble only commands}
231
232
233
234
235 \begin{docCommand}{RegisterCounter}{\oarg{options}\marg{counter}}
236
237 This provides the means to let the package know that a counter should be tracked for values per chapter
238
239 \begin{docCommandArgs}{RegisterCounter}%
240
241 \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
242 \item \oarg{options}:
243
244 \begin{docKey}{autodefine}{\meta{true,false}}{false}
245 This will enable the automatic definition of a counter if the name specified as 2nd mandatory argument is not identified as \LaTeX\ counter.
246 \end{docKey}
247
248 \item \marg{counter}
249 This contains the counter name which should be tracked for counting itself.
250 \end{enumerate}
251 \end{docCommandArgs}
252
253 \end{docCommand}%
254
255 \begin{docCommand}{RegisterCounters}{\marg{counter1,counter2,...}}
256
257 This macro allows for specification of a CSV list of counter names -- internally this will call \refCom{RegisterCounter}
258
259 \begin{docCommandArgs}{RegisterCounters}%
260 \begin{itemize}
261 \item \marg{counter1,counter2,...}
262 \end{itemize}
263 This contains a comma separated list of counter names which should be tracked for counting itself.
264 \end{docCommandArgs}
265
266 \end{docCommand}
267
268 \handrightnote Please note, that both \refCom{RegisterCounter} and \refCom{RegisterCounters} can be used only in the preamble of a document.
269
270 \handrightnote It is safe to use \refCom{RegisterCounters} with just one counter name.
271
272 \begin{docCommand}{PrepareTocCommand}{\marg{toc command}}
273 This command disables the usage of the automatic counter storage for ToC - like macros (\cs{tableofcontents},\cs{listoffigures},\cs{listoftables}, since those use \cs{chapter*} and confuse the tracking counter thereby.
274
275 \begin{docCommandArgs}{PrepareTocCommand}
276 \marg{toc command} This is intented to be a command such as \cs{tableofcontents} etc., but it could be any command actually.
277 \end{docCommandArgs}
278
279 Please use this command with care!
280
281 By default, \cs{tableofcontents},\cs{listoffigures},\cs{listoftables} and \cs{printindex} are used with this feature.
282 \tcbdocmarginnote{\tcbdocnew{2015-05-08}}
283 \end{docCommand}
284
285 \subsection{User macros}
286
287 \begin{docCommand}{GetStoredCounterValue}{\oarg{chapter number}\marg{counter}}
288 This macro gets the stored value of the counter (specified as 2nd argument) per chapter and stores this number to the counter \docCounter{cps@@tempcounterstorage}. If the counter could not be found, the result is -1.
289 This macro should be expandable.
290 \begin{docCommandArgs}{GetStoredCounterValue}%
291 \begin{itemize}
292 \item \oarg{chapter number}
293 This optional argument contains the number of the chapter from which the counter value should be extracted. If this is not given, the current chapter is used.
294 \item \marg{counter}
295 This is the name of of the counter whose per chapter value should be displayed.
296 \end{itemize}
297 \end{docCommandArgs}
298 \end{docCommand}
299
300 \begin{docCommand}{FetchStoredCounterValue}{\oarg{chapter number}\marg{counter}}
301 \tcbdocmarginnote{\tcbdocnew{2015-06-01}}
302 This macro gets the stored value of the counter (specified as 2nd argument) per chapter and returns the value. This macro is expandable and is the convenience version of \cs{GetStoredCounterValue}. If the counter could not be found (i.e. the corresponding counter has not been used so far in the document) the result will be -1.
303 \begin{docCommandArgs}{FetchStoredCounterValue}%
304 \begin{itemize}
305 \item \oarg{chapter number}
306 This optional argument contains the number of the chapter from which the counter value should be extracted. If this is not given, the current chapter is used.
307 \item \marg{counter}
308 This is the name of of the counter whose per chapter value should be displayed.
309 \end{itemize}
310 \end{docCommandArgs}
311
312 \end{docCommand}
313
314 \begin{docCommand}{IndividualCounterStatistics}{\oarg{chapter number}\marg{counter}}
315 This returns the total value of the counter (specified as 2nd argument) per chapter.
316 \begin{docCommandArgs}{IndividualCounterStatistics}
317 \begin{itemize}
318 \item \oarg{chapter number}
319 This optional argument contains the number of the chapter from which the counter value should be extracted. If this is not given, the current chapter is used.
320 \item \marg{counter}
321 This is the name of of the counter whose per chapter value should be displayed together with the counter name.
322 \end{itemize}
323 \end{docCommandArgs}
324
325 \end{docCommand}
326
327
328 \begin{docCommand}{ShowStatistics}{\oarg{chapter number}}
329 This returns the all total values of the counters registered by \refCom{RegisterCounter} or \refCom{RegisterCounters} per chapter.
330 \begin{docCommandArgs}{ShowStatistics}
331 \begin{itemize}
332 \item \oarg{chapter number}
333 This optional argument contains the number of the chapter from which the counter value should be extracted. If this is not given, the current chapter is used.
334 \end{itemize}
335 \end{docCommandArgs}
336
337 Both \refCom{ShowStatistics} and \refCom{IndividualCounterStatistics} are defined to provide nothing if \refKey{final} is given as package option.
338
339
340 \end{docCommand}
341
342
343 \begin{docCommand}{Fullstatistics}{}
344 \tcbdocmarginnote{\tcbdocnew{2015-05-07}}
345 This will show an overview of all registered counters throughout the document (unless storage was locally disabled).
346 \end{docCommand}
347
348 \begin{tcblisting}{}
349 \Fullstatistics
350 \end{tcblisting}
351
352
353
354 \begin{docCommand}{StoreCounters}{}
355
356 This macro stores all registrated counter values to the file.
357
358 %This command is automatically called before a new chapter starts and at the end of the document, but if there is only one chapter in file and some \cs{printindex} - like command pretty near the document end, the last counter values are not stored correctly. In this case, it's better to issue this command before \cs{printindex} manually, but not in other setups.
359
360 \textit{Remark: This command was named \cs{StoreCountersPerChapter} in previous versions}
361 \end{docCommand}
362
363 \begin{docCommand}{StopCounting}{}
364
365 This macro stores all registrated counter values to the file.
366
367 This command is automatically called at the end of the document, but can be used before too. It is useful, if there is some \cs{printindex} etc. at the end and only one chapter. In this case, the finalizing storage would not be done automatically.
368
369 % new chapter starts and at the end of the document, but if there is only one chapter in file and some \cs{printindex} - like command pretty near the document end, the last counter values are not stored correctly. In this case, it's better to issue this command before \cs{printindex} manually, but not in other setups.
370
371 \end{docCommand}
372
373 \begin{docCommand}{RestoreCounter}{\marg{counter}}
374 This macro restores the counter \marg{counter} to zero.
375
376 \handrightnote It is not necessary to use this macro directly in almost any case.
377 \end{docCommand}
378
379
380 \begin{docCommand}{RestoreCounters}{}
381 This macro restores all registrated counters to zero. This happens every time if a new driving section level is used.
382 \end{docCommand}
383
384 \section{Informational macros}
385
386 \begin{docCommand}{numberofstoredcounters}{}
387 This macro just returns the number of registered counters. It will not return the internal counter name which holds the number.
388 \end{docCommand}
389
390 \section{Conditionals}
391
392 The package knows some conditionals:
393
394 \begin{docCommand}{ifcpsstorage}{}
395 \tcbdocmarginnote{\tcbdocnew{2015-05-08}}
396 This status variable enables or disables the storage of counters per chapter (section,$\ldots$). It is a classical \TeX\ \cs{newif} statement and can be set to true by saying \cs{cpsstoragetrue} or false \cs{cpsstorefalse}. However, there are two small macros to wrap this enabling or disabling into to more memorable names: \refCom{EnableCPSStorage} and \refCom{DisableCPSStorage}.
397
398 \end{docCommand}
399
400 \begin{docCommand}{EnableCPSStorage}{}
401 Enables the storage of counters per chapter (etc.)
402 \tcbdocmarginnote{\tcbdocnew{2015-05-08}}
403 \end{docCommand}
404
405 \begin{docCommand}{DisableCPSStorage}{}
406 Enables the storage of counters per chapter (etc.)
407 \tcbdocmarginnote{\tcbdocnew{2015-05-08}}
408 \end{docCommand}
409
410 \begin{docCommand}{ifcpsdraftmode}{}
411 This is a classical \TeX\ conditional defined by \cs{newif}. It can be used to enable draft mode locally by saying \cs{cpsdraftmodetrue} and disable in return using \cs{cpsdraftmodefalse}.
412 \tcbdocmarginnote{\tcbdocnew{2015-05-03}}
413 \end{docCommand}
414
415
416
417 \clearpage
418
419 \section{Generated files}
420
421 The package uses the same approach as \LaTeX commands to write content to the table of content files. It creates \texttt{.cpsfoo} files, where \cs{foo} is the name of the relevant counter. Those files are constantly updated if the main document has been changed. It's safe to delete those files, however, the correct values appear only after the 2nd and consecutive runs.
422
423 \section{Error messages}
424
425 If one of the tracked counters is deleted in the \refCom{RegisterCounters} - list between two compilation runs, there will be an error message. Just delete all relevant \texttt{*.cps*} files then and recompile twice.
426
427 \section{To-Do list}\label{section::todo}
428
429 \begin{itemize}
430 \item Better error handling (no checks for many features so far).
431 \item Squeeze the usage of multiple files for each counter value into a more sophisticated approach.
432 \item More options for fine control of the behaviour package and macros.
433 \item Easy - adaption for other documentclasses, especially for \classname{beamer}
434 \item Improve documentation
435
436 \end{itemize}
437
438 If you
439
440 \begin{itemize}
441 \item find bugs
442 \item errors in the documentation
443 \item have suggestions
444 \item have feature requests
445 \end{itemize}
446
447 don't hesitate and contact me via \makeatletter [email protected]\makeatother
448
449 \clearpage
450
451 \section{Acknowledgments}
452
453 I would like to express my gratitudes to the developpers of fine \LaTeX{} packages and of course
454 to the users at \url{tex.stackexchange.com}, especially to
455
456 \begin{itemize}
457 \item Enrico Gregorio
458 \item Joseph Wright
459 \item David Carlisle
460 \item Paulo Roberto Massa Cereda
461 \item Werner Doe (;-))
462 \item Johannes B\"ottcher (for some remarks/checking on KOMA related issues)
463 \end{itemize}
464
465 for their invaluable help on many questions on macros.
466
467 \vspace{2\baselineskip}
468 A special gratitude goes to Prof. Dr. Dr. Thomas Sturm for providing the wonderful \packagename{tcolorbox} package which was used to
469 write this documentation.
470
471 \clearpage
472
473 \section{Version history}
474 \begin{itemize}
475 \item 0.3:
476 \begin{itemize}
477 \item Added some remarks about other tracklevels
478 \item Added some remarks about \classname{beamer}
479 \item Added \cs{FetchStoredCounterValue} for quicker access to the counter value, instead of using \docCounter{cps@@tempcounterstorage}.
480 \item Corrected the wrong name of the \cs{GetStoredCounterValue} in the documentation
481 \end{itemize}
482 \item 0.2:
483 \begin{itemize}
484 \item Introduced the possibility to disable the storage temporarily
485 \item Fixed a severe bug concerning the file handle generation
486 \item Added support for `tracklevel=option`, allowing for arbitray section levels as watch
487 \item Renamed some macros which had `Chapter` in name
488 \item Added a check if the relevant section level sequence exists at all
489 \item Added a total counter for the section level and limited the `\cs{GetTotalCounters}` max value
490 \item Fixed typos in documentation
491 \end{itemize}
492
493 \item 0.1: Initial version, fixed errors with \cs{dolistcsloop} for getting the counter values and replaced it with \cs{forlistcsloop}
494 \item 0.01: Bootstrap version
495
496
497 \end{itemize}
498
499 \clearpage
500 \StopCounting
501
502 %%%% Index of commands
503
504 \printindex
505
506 \end{document}