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