summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-05-04 23:33:48 +0000
committerKarl Berry <karl@freefriends.org>2015-05-04 23:33:48 +0000
commitf97a5d61adae591bc262091b48989cf2ab69f6ec (patch)
treefc8c12aafb53ce0e02aafa5f72515406c257570d
parent38a1779d664014b9d281aabaece754557cdf7200 (diff)
cntperchap (4may15)
git-svn-id: svn://tug.org/texlive/trunk@37188 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/README31
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdfbin0 -> 157916 bytes
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex360
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdfbin0 -> 86630 bytes
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.tex108
-rw-r--r--Master/texmf-dist/tex/latex/cntperchap/cntperchap.sty246
-rwxr-xr-xMaster/tlpkg/bin/tlpkg-ctan-check2
-rw-r--r--Master/tlpkg/tlpsrc/cntperchap.tlpsrc0
-rw-r--r--Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc1
9 files changed, 747 insertions, 1 deletions
diff --git a/Master/texmf-dist/doc/latex/cntperchap/README b/Master/texmf-dist/doc/latex/cntperchap/README
new file mode 100644
index 00000000000..c9676105b6d
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/cntperchap/README
@@ -0,0 +1,31 @@
+%% LaTeX package cntperchap - version 0.1 (2015/05/03)
+%%
+%% -------------------------------------------------------------------------------------------
+%% 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 `maintained'.
+%%
+%% This work consists of all files listed in README
+%%
+
+
+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 a chapter. The values are stored at the beginning of a new chapter and written to \jobname.cpsfoo files, where foo is shorthand for the relevant counter name.
+
+
+
+Directory listing:
+
+ cntperchap_doc.pdf 157916 05/03/15 23:40:36
+ cntperchap_doc.tex 11048 05/03/15 23:39:24
+cntperchap_example.pdf 86630 05/03/15 23:40:34
+cntperchap_example.tex 2202 05/03/15 22:59:19
+ cntperchap.sty 5913 05/03/15 23:40:36
diff --git a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdf b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdf
new file mode 100644
index 00000000000..f15a2bb7238
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex
new file mode 100644
index 00000000000..f71eaed4059
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex
@@ -0,0 +1,360 @@
+%% Documentation for cntperchap.sty
+%%
+%% Version 0.1 (2015/05/04}
+%%
+%%
+%% -------------------------------------------------------------------------------------------
+%% 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[12pt,english]{book}
+\usepackage{scrlayer-scrpage}
+\usepackage[lmargin=2cm,rmargin=2cm,a4paper]{geometry}
+\usepackage{savesym}%
+\usepackage{bbding}%
+\savesymbol{Cross}%
+
+\usepackage{blindtext}%
+\usepackage{enumitem}%
+\usepackage{datetime}%
+\usepackage{imakeidx}%
+
+
+\usepackage[most]{tcolorbox}
+\usepackage{cntperchap}
+
+\RegisterCountersPerChapter{page,section,subsection,subsubsection,table,figure}
+
+
+\tcbuselibrary{documentation}
+
+
+
+\newcommand{\tcolorboxdoclink}{http://mirrors.ctan.org/macros/latex/contrib/tcolorbox/tcolorbox.pdf}
+
+
+
+\newcommand{\packagename}[1]{\fbox{\textcolor{blue}{\textbf{\Envelope~#1}}}\index{Package!#1}}%
+
+\newcommand{\classname}[1]{\fbox{\textcolor{brown}{\textbf{\Writinghand~#1}}}\index{Class!#1}}%
+
+
+\newcommand{\MarkupPackageName}[2][lightgray]{%
+\colorbox{#1}{\textcolor{black}{#2}}%
+}%
+
+\newcommand{\MarkupCounterName}[2][yellow]{%
+\colorbox{#1}{\textcolor{black}{\texttt{#2}}}%
+}%
+
+
+\newtcolorbox{docCommandArgs}[1]{colbacktitle={blue},coltitle={white},title={Description of arguments of command \cs{#1}}}
+
+
+\def\packageversion{0.1}%
+
+\makeindex
+
+\newcommand{\PackageDocName}{cntperchap.sty}%
+
+
+\hypersetup{breaklinks=true}
+
+\begin{document}
+\mmddyyyydate
+
+
+\setlength{\parindent}{0pt}
+
+\thispagestyle{empty}%
+
+\begin{center}
+\begin{tcolorbox}[boxrule=1mm,arc=4mm,colback=yellow!30!white,width=0.8\textwidth]
+\large \bfseries%
+\begin{center}%
+\begin{tabular}{c}%
+\textsc{\PackageDocName} \tabularnewline
+\tabularnewline
+Store counter values per chapter \tabularnewline
+\tabularnewline
+Version \packageversion \tabularnewline
+\tabularnewline
+\today \tabularnewline
+\tabularnewline
+\addtocounter{footnote}{2}
+Author: Christian Hupfer\(^\mathrm{\fnsymbol{footnote}}\)
+\tabularnewline
+\end{tabular}
+\end{center}
+\end{tcolorbox}
+\makeatletter
+\renewcommand{\thefootnote}{\fnsymbol{footnote}}%
+\footnotetext{christian.hupfer@yahoo.de}%
+\makeatother
+
+\end{center}
+
+\tableofcontents
+\clearpage
+
+
+
+
+\pagestyle{scrheadings}%
+\setheadsepline{2pt}[\color{blue}]
+
+\setcounter{footnote}{0}
+
+
+\chapter{Documentation}
+
+
+\section{Introduction}
+
+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 a chapter. 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.
+
+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}.
+
+\begin{tcolorbox}[title={Statistics of the local chapter},colbacktitle=yellow,coltitle=black]
+\ShowStatistics
+\end{tcolorbox}
+
+\subsection{Basic usage}
+
+\begin{tcblisting}{listing only}
+\documentclass{book}
+\usepackage{cntpersec}
+
+\RegisterCountersPerChapter{page,section,subsection,subsubsection,table,%
+ figure}
+
+\begin{document}
+\chapter{First}
+\ShowStatistics
+\section{First section}
+
+\end{document}
+\end{tcblisting}
+
+\section{Package options}%
+
+\newcommand{\mk}[1]{%
+}
+
+As of version \packageversion~ the package has only the \oarg{draft,final,autodefine} options so far.
+
+\begin{itemize}
+\item \begin{docKey}{draft}{\meta{}}{default is draft}
+ This option enables the explicit statistics
+ \end{docKey}
+\item \begin{docKey}{final}{\meta{}}{default is off}
+ This option disables the explicit statistics
+ \end{docKey}
+
+\item \begin{docKey}{autodefine}{\meta{}}{initially empty}
+ This option enables the automatic counter definition if some undefined counter is specified during the registration process.
+ \end{docKey}
+
+
+\end{itemize}
+
+\section{Requirements and incompatibilities}%
+
+\subsection{Required packages}
+
+\begin{itemize}
+\item \packagename{assoccnt}%
+\item \packagename{etoolbox}%
+\item \packagename{ifthen}%
+\item \packagename{morewrites}%
+\item \packagename{xkeyval}%
+\item \packagename{xparse}%
+\end{itemize}
+
+The packages \packagename{etoolbox} and \packagename{xkeyval} are already loaded by \packagename{assocnt}.
+
+\subsection{Incompatibilities}
+
+This package will not work 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}, but at the moment it does not work with their \classname{KOMA} equivalents.
+
+
+\section{Documentation of Macros}
+\tcbset{color command={blue}}
+
+\subsection{Preamble only commands}
+
+
+
+
+\begin{docCommand}{RegisterCounterPerChapter}{\oarg{options}\marg{counter}}
+
+This provides the means to let the package know that a counter should be tracked for values per chapter
+
+\begin{docCommandArgs}{RegisterCounterPerChapter}%
+
+ \begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
+ \item \oarg{options}:
+
+ \begin{docKey}{autodefine}{\meta{true,false}}{false}
+ This will enable the automatic definition of a counter if the name specified as 2nd mandatory argument is not identified as \LaTeX\ counter.
+ \end{docKey}
+
+ \item \marg{counter}
+ This contains the counter name which should be tracked for counting itself.
+\end{enumerate}
+\end{docCommandArgs}
+
+\end{docCommand}%
+
+\begin{docCommand}{RegisterCountersPerChapter}{\marg{counter1,counter2,...}}
+
+This macro allows for specification of a CSV list of counter names -- internally this will call \refCom{RegisterCounterPerChapter}
+
+\begin{docCommandArgs}{RegisterCountersPerChapter}%
+\begin{itemize}
+ \item \marg{counter1,counter2,...}
+ \end{itemize}
+ This contains a comma separated list of counter names which should be tracked for counting itself.
+\end{docCommandArgs}
+
+\end{docCommand}
+
+Please note, that both \refCom{RegisterCounterPerChapter} and \refCom{RegisterCountersPerChapter} can be used only in the preamble of a document.
+
+\subsection{User macros}
+
+\begin{docCommand}{GetTotalCounter}{\oarg{chapter number}\marg{counter}}
+This returns the total value of the counter (specified as 2nd argument) per chapter. This macro should be expandable.
+\begin{docCommandArgs}{GetTotalCounter}%
+\begin{itemize}
+ \item \oarg{chapter number}
+ 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.
+ \item \marg{counter}
+ This is the name of of the counter whose per chapter value should be displayed.
+ \end{itemize}
+\end{docCommandArgs}
+
+
+
+
+\end{docCommand}
+
+\begin{docCommand}{IndividualCounterStatistics}{\oarg{chapter number}\marg{counter}}
+This returns the total value of the counter (specified as 2nd argument) per chapter.
+\begin{docCommandArgs}{IndividualCounterStatistics}
+\begin{itemize}
+\item \oarg{chapter number}
+ 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.
+ \item \marg{counter}
+ This is the name of of the counter whose per chapter value should be displayed together with the counter name.
+ \end{itemize}
+\end{docCommandArgs}
+
+\end{docCommand}
+
+
+\begin{docCommand}{ShowStatistics}{\oarg{chapter number}}
+This returns the all total values of the counters registered by \refCom{RegisterCounterPerChapter} or \refCom{RegisterCountersPerChapter} per chapter.
+\begin{docCommandArgs}{ShowStatistics}
+\begin{itemize}
+\item \oarg{chapter number}
+ 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.
+ \end{itemize}
+\end{docCommandArgs}
+
+Both \refCom{ShowStatistics} and \refCom{IndividualCounterStatistics} are defined to provide nothing if \refKey{final} is given as package option.
+
+
+\end{docCommand}
+
+
+\begin{docCommand}{StoreCountersPerChapter}{}
+
+This macro stores all registrated counter values to the file.
+
+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.
+
+\end{docCommand}
+
+
+
+\clearpage
+\section{Generated files}
+
+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.
+\section{To-Do list}
+
+\begin{itemize}
+\item Better error handling (no checks for many features so far).
+\item Squeeze the usage of multiple files for each counter value into a more sophisticated approach.
+\item More options for fine control of the behaviour package and macros.
+\item Easy - adaption for other documentclasses.
+\item Improve documentation
+\end{itemize}
+
+If you
+
+\begin{itemize}
+ \item find bugs
+ \item errors in the documentation
+ \item have suggestions
+ \item have feature requests
+\end{itemize}
+
+don't hesitate and contact me via \makeatletter christian.hupfer@yahoo.de\makeatother
+
+\clearpage
+
+\section{Acknowledgments}
+
+I would like to express my gratitudes to the developpers of fine \LaTeX{} packages and of course
+to the users at \url{tex.stackexchange.com}, especially to
+
+\begin{itemize}
+ \item Enrico Gregorio
+ \item Joseph Wright
+ \item David Carlisle
+ \item Paulo Roberto Massa Cereda
+ \item Werner Doe (;-))
+\end{itemize}
+
+for their invaluable help on many questions on macros.
+
+\vspace{2\baselineskip}
+A special gratitude goes to Prof. Dr. Dr. Thomas Sturm for providing the wonderful \MarkupPackageName{tcolorbox} package which was used to
+write this documentation.
+
+\clearpage
+
+\section{Version history}
+\begin{itemize}
+
+\item 0.1: Initial version, fixed errors with \cs{dolistcsloop} for getting the counter values and replaced it with \cs{forlistcsloop}
+\item 0.01: Bootstrap version
+
+
+\end{itemize}
+
+\clearpage
+\StoreCountersPerChapter
+%\chapter{Dummy}
+
+%%%% Index of commands
+
+\printindex
+
+\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdf b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdf
new file mode 100644
index 00000000000..6c57faaf687
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.tex b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.tex
new file mode 100644
index 00000000000..d28297021a5
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.tex
@@ -0,0 +1,108 @@
+%% Example file for cntperchap.sty
+%%
+%% License: LaTeX Project Public License version 1.3
+%% Copyright (2015) Dr. Christian Hupfer
+%% Author: Christian Hupfer christian.hupfer@yahoo.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 `maintained'.
+%%
+%% This work consists of all files listed in README
+%%
+%%%%
+
+
+\documentclass{book}
+
+
+\usepackage{cntperchap}
+\usepackage{amsthm}
+\usepackage{blindtext}
+\usepackage{pgffor}
+
+
+% Register the most important counters
+\RegisterCountersPerChapter{equation,figure,table,section,subsection,subsubsection,paragraph,subparagraph}
+
+% generate the counter automatically by using 'autodefine=true' otherwise the registration would fail
+%\RegisterCounterPerChapter[autodefine=true]{theorem}
+% Define some theorem for using a non-standard-counter
+\newtheorem{theorem}{theorem}
+
+\newtheorem{lemma}{lemma}
+\RegisterCounterPerChapter{lemma}
+
+
+% To show/number the lower levels too
+\setcounter{secnumdepth}{5}
+
+\begin{document}
+%\tableofcontents
+
+
+\chapter{First}
+\ShowStatistics
+
+but
+
+\ShowStatistics[4]
+\section{First}
+\begin{table}
+\caption{faketable}
+\caption{other faketable}
+
+\end{table}
+\section{Second}
+
+\chapter{Second}
+\ShowStatistics
+
+\section{First}
+\section{Second}
+\section{Third}
+\section{Fourth}
+
+
+
+% Now a really large chapter
+\chapter*{Third}
+\ShowStatistics
+
+\foreach \x in {1,...,5} {%
+\section{Section \x~in chapter \thechapter}
+}
+\chapter{Fourth}
+\ShowStatistics
+
+\begin{figure}
+\caption{fake figure}
+\caption{other fakefigure 1}
+\caption{other fakefigure 2}
+\caption{other fakefigure 3}
+\caption{other fakefigure 4}
+
+\end{figure}
+
+\foreach \x in {1,...,10} {%
+\begin{equation}
+ E = mc^2
+\end{equation}
+}
+
+
+\section{A single section}
+
+\begin{theorem}
+\blindtext
+\end{theorem}
+\subsection{A small subsection}
+\subsubsection{An even smaller subsubsection}
+
+\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/cntperchap/cntperchap.sty b/Master/texmf-dist/tex/latex/cntperchap/cntperchap.sty
new file mode 100644
index 00000000000..62c1e57f6e5
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/cntperchap/cntperchap.sty
@@ -0,0 +1,246 @@
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{cntperchap}[2015/05/03 v0.1 -- store counter values per chapter]%
+%%
+%% License: LaTeX Project Public License version 1.3
+%% Copyright (2015) Dr. Christian Hupfer
+%% Author: Christian Hupfer christian.hupfer@yahoo.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 `maintained'.
+%%
+%% This work consists of all files listed in README
+%%
+%%%%
+
+
+\RequirePackage{ifthen}
+\RequirePackage{assoccnt}
+\RequirePackage{morewrites}
+\RequirePackage{xpatch}
+\RequirePackage{xparse}
+
+
+
+%%%% Command options
+
+\define@boolkey{cpskeys}{autodefine}[false]{}
+
+\presetkeys{cpskeys}{autodefine=false}{}%
+
+
+%%%% Package options
+\newif\ifcpsautodefine
+\cpsautodefinefalse
+\newif\ifcpsdraftmode
+\cpsdraftmodetrue
+
+\DeclareOptionX{draft}{\cpsdraftmodetrue}
+\DeclareOptionX{final}{\cpsdraftmodefalse}
+\DeclareOptionX{autodefine}{\cpsautodefinetrue\presetkeys{cpskeys}{autodefine=true}{}}
+
+\ProcessOptionsX*
+
+\newcommand{\cpscounterlistname}{@counterstowatch}
+
+\listcsadd{\cpscounterlistname}{}
+
+
+
+%%%% Internal commands
+
+\newcounter{cps@@currentchapter}
+\newcounter{cps@@togglecounter}
+\newcounter{cps@@tempcounter}
+\newcounter{cps@@cpscounters}
+
+\NewDocumentCommand{\cpschapterstarthook}{}{%
+ \stepcounter{cps@@currentchapter}%
+ \ifnumgreater{\value{cps@@currentchapter}}{0}{%
+ \StoreCountersPerChapter%
+ }{}%
+ \ResetTotalCounters%
+}
+
+
+% Prepending the \chapter command with some starter hook
+
+\xpretocmd{\chapter}{\cpschapterstarthook}{}{}
+
+
+% This is a modified version from \@starttoc, being defined in latex.ltx
+\newcommand{\@startcountertoc}[1]{%
+ \begingroup%
+ % Generate the file handle first
+ \expandafter\newwrite\csname tf@cps#1\endcsname%
+ \makeatletter
+ % Read first before deleting it
+ \ifcsdef{tf@cps#1}{%
+ \IfFileExists{\jobname.cps#1}{%
+ \immediate\openin\csname tf@cps#1\endcsname \jobname.cps#1\relax%
+ \@readcounternumbersfromfile{#1}%
+ }{%
+ % Oops, the file is not there :-(
+ }%
+ }{%
+ \typeout{No #1{} counter values so far}%
+ }%
+ \if@filesw
+ % Write only if not `\nofiles` is specified
+ \immediate\openout \csname tf@cps#1\endcsname \jobname.cps#1\relax%
+ \fi%
+ \@nobreakfalse%
+ \endgroup%
+}
+
+
+\newcommand{\@readcounternumbersfromfile}[1]{%
+ \setcounter{cps@@togglecounter}{0}%
+ \whiledo {\value{cps@@togglecounter} < 1}{%
+ \expandafter\read\csname tf@cps#1\endcsname to \cps@@numberfromfile%
+ \ifeof\csname tf@cps#1\endcsname%
+ \stepcounter{cps@@togglecounter}%
+ \else%
+ \listcsxadd{#1countlist}{\cps@@numberfromfile}%
+ \fi%
+ }%
+}
+
+\newcommand{\@cpsstorecounter}[1]{%
+ \addtocontents{cps#1}{%
+ \number\value{cps@total#1}%
+ }%
+}
+
+
+\newcommand{\@cpscsloop}[1]{%
+ \ifnumgreater{\value{cps@@cpscounters}}{0}{%
+ \expandafter\forlistcsloop{\csname #1\endcsname}{\cpscounterlistname}
+ }{%
+ }%
+}
+
+\newcommand{\@cpsloopstorecounters}{%
+ \ifnumgreater{\value{cps@@cpscounters}}{0}{%
+ \forlistcsloop{\@cpsstorecounter}{\cpscounterlistname}%
+ }{%
+ }%
+}
+
+\newcommand{\@registercounterperchapter}[1]{%
+ \listcsxadd{\cpscounterlistname}{#1}%
+ \stepcounter{cps@@cpscounters}%
+ \listcsxadd{#1countlist}{}%
+ \newcounter{cps@total#1}%
+ \DeclareAssociatedCounters{#1}{cps@total#1}%
+}
+
+%% Searches the list of counter values for the correct chapter
+\newcommand{\@cpssearchcountervalue}[3]{%
+ \ifnumequal{#1}{\value{#2}}{%
+ #3\listbreak%
+ }{%
+ \stepcounter{#2}%
+ }%
+}
+
+
+%%%%%%%%%%%%%% User commands %%%%%%%%%%%%%%%%%%%%
+
+
+\newcommand{\RegisterCounterPerChapter}[2][]{%
+ \begingroup
+ \setkeys{cpskeys}{#1}%
+ \ifltxcounter{#2}{%
+ \@registercounterperchapter{#2}%
+ }{%
+ \ifKV@cpskeys@autodefine
+ \newcounter{#2}%
+ \@registercounterperchapter{#2}%
+ \else%
+ % Ignore non existing counters
+ \fi
+ }%
+ \endgroup
+}
+
+\newcommand{\RegisterCountersPerChapter}[1]{%
+ \forcsvlist{\RegisterCounterPerChapter}{#1}%
+}
+
+% Prevent usage later in document body
+\@onlypreamble{\RegisterCounterPerChapter}
+\@onlypreamble{\RegisterCountersPerChapter}
+
+\newcommand{\ResetTotalCounter}[1]{%
+ \setcounter{cps@total#1}{0}%
+}
+
+
+% Reset all total counters
+\newcommand{\ResetTotalCounters}{%
+ \ifnumgreater{\value{cps@@cpscounters}}{0}{%
+ \forlistcsloop{\ResetTotalCounter}{\cpscounterlistname}%
+ }{}%
+}
+
+%% Only for statistical purposes. Do not use it in a production run
+\newcommand{\IndividualCounterStatistics}[2][\number\value{cps@@currentchapter}]{%
+ \ifcpsdraftmode
+ \noindent Chapter #1~ has \GetTotalCounter[#1]{#2} #2(s)\par
+ \fi
+}%
+
+
+
+
+%% Only for statistical purposes. Do not use it in a production run
+\newcommand{\ShowStatistics}[1][\number\value{cps@@currentchapter}]{%
+ \ifcpsdraftmode%
+ \ifnumgreater{\value{cps@@cpscounters}}{0}{%
+ \forlistcsloop{\IndividualCounterStatistics[\number#1]}{\cpscounterlistname}%
+ }{%
+ \typeout{No counters registered}%
+ }%
+ \fi%
+}
+
+\newcommand{\GetTotalCounter}[2][\number\value{cps@@currentchapter}]{%
+ \setcounter{cps@@tempcounter}{0}%
+ \ifcsdef{#2countlist}{%
+ \forlistcsloop{\@cpssearchcountervalue{#1}{cps@@tempcounter}}{#2countlist}%
+ }{%
+ \typeout{Warning: List for counter #2 not defined}%
+ }% Failure branch should be improved
+}
+
+\newcommand{\StartCounterToc}{%
+ \ifnumgreater{\value{cps@@cpscounters}}{0}{%
+ \forlistcsloop{\@startcountertoc}{\cpscounterlistname}%
+ }{%
+ }%
+}
+
+\newcommand{\StoreCountersPerChapter}{%
+ \@cpsloopstorecounters%
+}
+
+\AtBeginDocument{%
+ % Grab the counter 'tocs'
+ \StartCounterToc%
+}
+
+
+\AtEndDocument{%
+ % Write the counter values to the file
+ \StoreCountersPerChapter%
+}
+
+
+\endinput
diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check
index a5eb7bf94fe..cde0dc749a7 100755
--- a/Master/tlpkg/bin/tlpkg-ctan-check
+++ b/Master/tlpkg/bin/tlpkg-ctan-check
@@ -128,7 +128,7 @@ my @TLP_working = qw(
clock clrscode clrscode3e cm-lgc cm-super cm-unicode
cmap cmarrows cmbright cmcyr
cmdstring cmdtrack cmextra cmll cmpica cmpj cmsd cmtiup
- cnbwp cnltx cntformats
+ cnbwp cnltx cntformats cntperchap
codedoc codepage codesection codicefiscaleitaliano
collcell collectbox collref colordoc colorinfo colorsep colortab
colortbl colorwav colorweb colourchange
diff --git a/Master/tlpkg/tlpsrc/cntperchap.tlpsrc b/Master/tlpkg/tlpsrc/cntperchap.tlpsrc
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/Master/tlpkg/tlpsrc/cntperchap.tlpsrc
diff --git a/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc b/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc
index 49046bd71da..2c306ee9df3 100644
--- a/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc
+++ b/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc
@@ -139,6 +139,7 @@ depend cmdtrack
depend cmsd
depend cnltx
depend cntformats
+depend cntperchap
depend codedoc
depend codepage
depend codesection