Debian Codegraph @

texmf-dist/doc/latex/xassoccnt/xassoccnt_example.tex

raw
1 %% LaTeX package xassoccnt - version 2.0 (2021/11/21 -- 12:14:58)
2 %% Example file for xassoccnt.sty
3 %%
4 %%
5 %% -------------------------------------------------------------------------------------------
6 %% Copyright (c) 2015 -- 2021 by Dr. Christian Hupfer <>
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 2005/12/01 or later.
16 %%
17 %%
18 %% This work has the LPPL maintenance status `unmaintained`
19 %%
20 %%
21
22 \documentclass[a4paper,12pt]{book}%
23
24
25 % Some packages only for output and dummy pages
26 \usepackage{blindtext}
27 \usepackage{forloop}
28 \usepackage[svgnames]{xcolor}
29 \usepackage{tcolorbox}
30
31 \usepackage{totcount}
32 \usepackage{xassoccnt}
33
34
35
36 \newcounter{loopcounter}%
37
38 \newcommand{\QuickSections}[2]{%
39 \forloop{loopcounter}{1}{\value{loopcounter} < \numexpr #1+1}{%
40 \csuse{#2}{Dummy #2 -- \theloopcounter}
41 }%
42 }%
43
44 \newcommand{\ShowNiceCounterOutput}[6]{%
45 \begin{center}%
46 \begin{tabular}{lllll}%
47 & & & & \tabularnewline
48 & \multicolumn{4}{c}{totcount page values} \tabularnewline
49 Page & \textcolor{red}{#1} & \textcolor{blue}{#2} & \textcolor{gray}{#3} & \textcolor{violet}{#4}\tabularnewline
50 \thepage & \textcolor{red}{\number\totvalue{#1}} & \textcolor{blue}{\number\value{#2}} & \textcolor{gray}{\number\value{#3}} & \textcolor{violet}{\number\totvalue{#4}} \tabularnewline
51 Section & \textcolor{red}{#5} & Subsection & \textcolor{blue}{#6} & \tabularnewline%
52 \thesection & \textcolor{red}{\number\totvalue{#5}} & \thesubsection & \textcolor{blue}{\number\totvalue{#6}} & \tabularnewline
53 & & & & \tabularnewline
54 \end{tabular}
55 \end{center}%
56 }%
57
58
59 \newcommand{\QuickOutput}[1]{%
60 %
61 \forloop{loopcounter}{1}{\value{loopcounter} < \numexpr #1+1}{%
62 \pagenumbering{arabic}% -> pagenumber reset to zero , on purpose inside the loop
63 \ShowNiceCounterOutput{page}{associatedpages}{anotherpagescounter}{yetanotherpagescounter}{associatedsections}{associatedsubsections}%
64 \blindtext%
65 \newpage% some pages
66 }%
67 }%
68
69
70
71 \newcounter{associatedpages}%
72 \newcounter{anotherpagescounter}%
73
74 \regtotcounter{page} % Register a total value counter --> this will be the driver counter
75 \newtotcounter{yetanotherpagescounter}% 3rd driven counter
76 \newtotcounter{associatedsections}%
77
78 \newtotcounter{associatedsubsections}%
79
80
81 \DeclareAssociatedCounters{page}{associatedpages,anotherpagescounter,associatedpages,yetanotherpagescounter}% Register the driver and the driven counters
82 \DeclareAssociatedCounters{section}{associatedsections}%
83 \DeclareAssociatedCounters{subsection}{associatedsubsections}%
84
85
86
87
88 \begin{document}
89 \tableofcontents%
90
91 \chapter*{Introduction}
92
93 This is a dummy document -- it just shows how some of the commands work.
94 In section \ref{section::query} same queries and statistics are shown.
95
96 \chapter{Chapter one}
97
98 \section{First}
99 \QuickSections{10}{subsection}%
100
101
102 \QuickOutput{10}
103 % Suspend the associatedsubsections counters%
104 \typeout{Hello!}
105 \SuspendCounters{associatedsubsections,associatedpages}%
106
107 \QuickOutput{10}
108
109 \clearpage
110
111 \subsection[Suspended counters checking]{Checking for suspended counters}
112
113 \IsSuspendedCounter{associatedsubsections}{Yes, Counter associatedsubsections is suspended}{No!}
114
115 \IsSuspendedCounter{yetanothertotalpages}{Yes}{No!}
116
117 \clearpage
118
119 \section{Dummy section}%
120
121 \QuickSections{10}{subsection}%
122
123 % Resume all counters
124 \ResumeAllSuspendedCounters
125 \QuickSections{20}{subsection}%
126
127
128
129 \clearpage
130
131 \section{Query routines} \label{section::query}%
132 \setlength{\parindent}{0pt}%
133
134 \IsAssociatedCounter{totalsections}{Yes, it's associated}{Nope, it's not associated}
135
136 \IsAssociatedCounter{anotherpagescounter}{Yes, it's associated}{Nope, it's not associated}
137
138
139 \hrule\par
140
141 Setting counter section explicitly to another value:
142
143 \setcounter{section}{12}%
144
145 \hrule\par
146
147 Setting counter section explicitly to another value with option enabled:
148
149 \SetDocumentCounter[onlycounters={associatedpages,anotherpagescounter,gandalf}]{page}{20}%
150
151
152 \AddAssociatedCounters{page}{associatedpages}%
153 \AddAssociatedCounters{page}{associatedpages}%
154
155 \end{document}
156