summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/xassoccnt/xassoccnt_example.tex
blob: 2045a13e5bacd2ca46eaf8bfe09c55abaa06c2c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
%% LaTeX package xassoccnt - version 1.0 (2016/07/28 -- 21/05/18)
%% Example file for xassoccnt.sty
%%
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2015 -- 2016 by Dr. Christian Hupfer <christian dot hupfer at yahoo dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%%
%% This work has the LPPL maintenance status `author-maintained`
%%
%%

%% Example file for xassoccnt.sty v0.2 (2015/11/10)
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2015 by Dr. Christian Hupfer <christian dot hupfer at yahoo dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This work consists of all files listed in README
%%


\documentclass[a4paper,12pt]{book}%


% Some packages only for output and dummy pages
\usepackage{blindtext}
\usepackage{forloop}  
\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}

\usepackage{totcount}
\usepackage{xassoccnt}



\newcounter{loopcounter}%

\newcommand{\QuickSections}[2]{%
\forloop{loopcounter}{1}{\value{loopcounter} < \numexpr #1+1}{%
\csuse{#2}{Dummy #2 -- \theloopcounter}
}%
}%

\newcommand{\ShowNiceCounterOutput}[6]{%
\begin{center}%
\begin{tabular}{lllll}%
& & & & \tabularnewline 
& \multicolumn{4}{c}{totcount page values} \tabularnewline
Page & \textcolor{red}{#1} & \textcolor{blue}{#2} & \textcolor{gray}{#3} & \textcolor{violet}{#4}\tabularnewline
\thepage & \textcolor{red}{\number\totvalue{#1}} & \textcolor{blue}{\number\value{#2}} & \textcolor{gray}{\number\value{#3}} & \textcolor{violet}{\number\totvalue{#4}} \tabularnewline
Section & \textcolor{red}{#5} & Subsection & \textcolor{blue}{#6}  & \tabularnewline% 
\thesection & \textcolor{red}{\number\totvalue{#5}} & \thesubsection & \textcolor{blue}{\number\totvalue{#6}}  & \tabularnewline
& & & & \tabularnewline 
\end{tabular}
\end{center}%
}%


\newcommand{\QuickOutput}[1]{%
%
\forloop{loopcounter}{1}{\value{loopcounter} < \numexpr #1+1}{%
\pagenumbering{arabic}%  -> pagenumber reset to zero , on purpose inside the loop
\ShowNiceCounterOutput{page}{associatedpages}{anotherpagescounter}{yetanotherpagescounter}{associatedsections}{associatedsubsections}%
\blindtext%
\newpage%  some pages
}%
}%



\newcounter{associatedpages}%
\newcounter{anotherpagescounter}%

\regtotcounter{page} % Register a total value counter --> this will be the driver counter
\newtotcounter{yetanotherpagescounter}% 3rd driven counter 
\newtotcounter{associatedsections}%

\newtotcounter{associatedsubsections}%


\DeclareAssociatedCounters{page}{associatedpages,anotherpagescounter,associatedpages,yetanotherpagescounter}%  Register the driver and the driven counters
\DeclareAssociatedCounters{section}{associatedsections}%
\DeclareAssociatedCounters{subsection}{associatedsubsections}%




\begin{document}
\tableofcontents%

\chapter*{Introduction}

This is a dummy document -- it just shows how some of the commands work.
In section \ref{section::query} same queries and statistics are shown. 

\chapter{Chapter one}

\section{First}
\QuickSections{10}{subsection}%


\QuickOutput{10}
% Suspend the associatedsubsections counters%
\typeout{Hello!}
\SuspendCounters{associatedsubsections,associatedpages}%

\QuickOutput{10}

\clearpage

\subsection[Suspended counters checking]{Checking for suspended counters}

\IsSuspendedCounter{associatedsubsections}{Yes, Counter associatedsubsections is suspended}{No!}

\IsSuspendedCounter{yetanothertotalpages}{Yes}{No!}

\clearpage

\section{Dummy section}%

\QuickSections{10}{subsection}%

% Resume all counters
\ResumeAllSuspendedCounters
\QuickSections{20}{subsection}%



\clearpage

\section{Query routines} \label{section::query}% 
\setlength{\parindent}{0pt}%

\IsAssociatedCounter{totalsections}{Yes, it's associated}{Nope, it's not associated}

\IsAssociatedCounter{anotherpagescounter}{Yes, it's associated}{Nope, it's not associated}


\hrule\par

Setting counter section explicitly to another value: 

\setcounter{section}{12}%

\hrule\par

Setting counter section explicitly to another value with option enabled: 

\SetDocumentCounter[onlycounters={associatedpages,anotherpagescounter,gandalf}]{page}{20}%


\AddAssociatedCounters{page}{associatedpages}%
\AddAssociatedCounters{page}{associatedpages}%

\end{document}