summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/README12
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdfbin157916 -> 171311 bytes
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex220
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdfbin86630 -> 87225 bytes
-rw-r--r--Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.tex69
-rw-r--r--Master/texmf-dist/tex/latex/cntperchap/cntperchap.sty400
6 files changed, 558 insertions, 143 deletions
diff --git a/Master/texmf-dist/doc/latex/cntperchap/README b/Master/texmf-dist/doc/latex/cntperchap/README
index c9676105b6d..25e50cd8d89 100644
--- a/Master/texmf-dist/doc/latex/cntperchap/README
+++ b/Master/texmf-dist/doc/latex/cntperchap/README
@@ -1,4 +1,4 @@
-%% LaTeX package cntperchap - version 0.1 (2015/05/03)
+%% LaTeX package cntperchap - version 0.2 (2015/05/09)
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2015 by Dr. Christian Hupfer <christian dot hupfer at yahoo dot de>
@@ -24,8 +24,8 @@ The aim of this package is to provide support for a summary in advance how many
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
+ cntperchap_doc.pdf 171311 05/09/15 19:52:36
+ cntperchap_doc.tex 17206 05/09/15 19:51:57
+cntperchap_example.pdf 87225 05/09/15 19:52:32
+cntperchap_example.tex 2802 05/09/15 19:51:57
+ cntperchap.sty 11993 05/09/15 19:52:36
diff --git a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdf b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdf
index f15a2bb7238..79206a9925e 100644
--- a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.pdf
+++ 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
index f71eaed4059..d361b412caf 100644
--- a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex
+++ b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_doc.tex
@@ -1,6 +1,6 @@
%% Documentation for cntperchap.sty
%%
-%% Version 0.1 (2015/05/04}
+%% Version 0.2 (2015/05/09}
%%
%%
%% -------------------------------------------------------------------------------------------
@@ -15,15 +15,15 @@
%% 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 has the LPPL maintenance status `maintained'.
%%
%% This work consists of all files listed in README
%%
-\documentclass[12pt,english]{book}
+\documentclass[12pt,english]{ltxdoc}
\usepackage{scrlayer-scrpage}
-\usepackage[lmargin=2cm,rmargin=2cm,a4paper]{geometry}
+\usepackage[lmargin=3cm,rmargin=3cm,a4paper]{geometry}
\usepackage{savesym}%
\usepackage{bbding}%
\savesymbol{Cross}%
@@ -37,39 +37,33 @@
\usepackage[most]{tcolorbox}
\usepackage{cntperchap}
-\RegisterCountersPerChapter{page,section,subsection,subsubsection,table,figure}
+\RegisterCounters{page,section,subsection,subsubsection,table,figure}
\tcbuselibrary{documentation}
+\tcbset{color command={blue}}
-\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{\tcolorboxdoclink}{http://mirrors.ctan.org/macros/latex/contrib/tcolorbox/tcolorbox.pdf}
+\newcommand{\packagename}[1]{\fbox{\textcolor{blue}{\textbf{\ding{41}~#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}}}%
-}%
+\newcommand{\handrightnote}{\tcbdocmarginnote{\ding{43}}}
\newtcolorbox{docCommandArgs}[1]{colbacktitle={blue},coltitle={white},title={Description of arguments of command \cs{#1}}}
-\def\packageversion{0.1}%
+\def\packageversion{0.2}%
\makeindex
-\newcommand{\PackageDocName}{cntperchap.sty}%
+\newcommand{\PackageDocName}{\cpspackagename.sty}%
\hypersetup{breaklinks=true}
@@ -90,6 +84,7 @@
\textsc{\PackageDocName} \tabularnewline
\tabularnewline
Store counter values per chapter \tabularnewline
+(or other section levels) \tabularnewline
\tabularnewline
Version \packageversion \tabularnewline
\tabularnewline
@@ -120,56 +115,84 @@ Author: Christian Hupfer\(^\mathrm{\fnsymbol{footnote}}\)
\setcounter{footnote}{0}
-\chapter{Documentation}
-
+\section{Disclaimer}
+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.
\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.
+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
+\begin{itemize}
+ \item \cs{part}
+ \item \cs{chapter}
+ \item \cs{section}
+ \item \cs{subsection}
+ \item \cs{subsubsection}
+ \item \cs{paragraph}
+ \item \cs{subparagraph}
+\end{itemize}
+
+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}.
+
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
+\ShowStatistics[1]
\end{tcolorbox}
\subsection{Basic usage}
+\tcbdocmarginnote{\ding{43}} If \refAuxcs{nofiles} is used, no package related files are generated or included, similar to the behaviour for \refAuxcs{tableofcontents} etc.
+
\begin{tcblisting}{listing only}
\documentclass{book}
-\usepackage{cntpersec}
+\usepackage{cntperchap}
-\RegisterCountersPerChapter{page,section,subsection,subsubsection,table,%
- figure}
+\RegisterCounters{page,section,subsection,subsubsection,table,figure}
\begin{document}
-\chapter{First}
-\ShowStatistics
\section{First section}
-
+\ShowStatistics
\end{document}
\end{tcblisting}
\section{Package options}%
+\label{section::package_options}
-\newcommand{\mk}[1]{%
-}
+As of version \packageversion~ the package has only following options so far:
-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}
+
+\item \begin{docKey}{autodefine}{}{}
+ This option enables the automatic counter definition if some undefined counter is specified during the registration process.
+ \end{docKey}
+
+\item \begin{docKey}{draft}{}{default is draft}
This option enables the explicit statistics
\end{docKey}
-\item \begin{docKey}{final}{\meta{}}{default is off}
+\item \begin{docKey}{final}{}{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.
+ \item \begin{docKey}{noendclose}{}{default is false}
+ This option prevents the explicit closing of output files and provides the means to enter a hook into the \cs{AfterEndDocument} command.
+ \end{docKey}
+
+
+\item \begin{docKey}{tracklevel}{\meta{=chapter}}{chapter}
+ This option sets the sectioning level 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$.
+
+Unknown section levels will lead to a compilation error.
+ \end{docKey}
+
+
+\item \begin{docKey}{verbose}{}{}
+ This option enables verbose output during compilation.
\end{docKey}
+
\end{itemize}
\section{Requirements and incompatibilities}%
@@ -185,26 +208,30 @@ As of version \packageversion~ the package has only the \oarg{draft,final,autode
\item \packagename{xparse}%
\end{itemize}
-The packages \packagename{etoolbox} and \packagename{xkeyval} are already loaded by \packagename{assocnt}.
+The packages \packagename{etoolbox} and \packagename{xkeyval} are already loaded by \packagename{assoccnt}.
\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.
+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.
+
+It would be nice to adapt the package for usage on a per frame base with the \classname{beamer} class, see \ref{section::todo}
+
+
+%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.
\section{Documentation of Macros}
-\tcbset{color command={blue}}
\subsection{Preamble only commands}
-\begin{docCommand}{RegisterCounterPerChapter}{\oarg{options}\marg{counter}}
+\begin{docCommand}{RegisterCounter}{\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{docCommandArgs}{RegisterCounter}%
\begin{enumerate}[label={\textcolor{blue}{\#\arabic*}}]
\item \oarg{options}:
@@ -220,11 +247,11 @@ This provides the means to let the package know that a counter should be tracked
\end{docCommand}%
-\begin{docCommand}{RegisterCountersPerChapter}{\marg{counter1,counter2,...}}
+\begin{docCommand}{RegisterCounters}{\marg{counter1,counter2,...}}
-This macro allows for specification of a CSV list of counter names -- internally this will call \refCom{RegisterCounterPerChapter}
+This macro allows for specification of a CSV list of counter names -- internally this will call \refCom{RegisterCounter}
-\begin{docCommandArgs}{RegisterCountersPerChapter}%
+\begin{docCommandArgs}{RegisterCounters}%
\begin{itemize}
\item \marg{counter1,counter2,...}
\end{itemize}
@@ -233,7 +260,22 @@ This macro allows for specification of a CSV list of counter names -- internally
\end{docCommand}
-Please note, that both \refCom{RegisterCounterPerChapter} and \refCom{RegisterCountersPerChapter} can be used only in the preamble of a document.
+\handrightnote Please note, that both \refCom{RegisterCounter} and \refCom{RegisterCounters} can be used only in the preamble of a document.
+
+\handrightnote It is safe to use \refCom{RegisterCounters} with just one counter name.
+
+\begin{docCommand}{PrepareTocCommand}{\marg{toc command}}
+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.
+
+\begin{docCommandArgs}{PrepareTocCommand}
+ \marg{toc command} This is intented to be a command such as \cs{tableofcontents} etc., but it could be any command actually.
+\end{docCommandArgs}
+
+Please use this command with care!
+
+By default, \cs{tableofcontents},\cs{listoffigures},\cs{listoftables} and \cs{printindex} are used with this feature.
+\tcbdocmarginnote{\tcbdocnew{2015-05-08}}
+\end{docCommand}
\subsection{User macros}
@@ -268,7 +310,7 @@ This returns the total value of the counter (specified as 2nd argument) per chap
\begin{docCommand}{ShowStatistics}{\oarg{chapter number}}
-This returns the all total values of the counters registered by \refCom{RegisterCounterPerChapter} or \refCom{RegisterCountersPerChapter} per chapter.
+This returns the all total values of the counters registered by \refCom{RegisterCounter} or \refCom{RegisterCounters} per chapter.
\begin{docCommandArgs}{ShowStatistics}
\begin{itemize}
\item \oarg{chapter number}
@@ -282,12 +324,76 @@ Both \refCom{ShowStatistics} and \refCom{IndividualCounterStatistics} are define
\end{docCommand}
-\begin{docCommand}{StoreCountersPerChapter}{}
+\begin{docCommand}{Fullstatistics}{}
+\tcbdocmarginnote{\tcbdocnew{2015-05-07}}
+ This will show an overview of all registered counters throughout the document (unless storage was locally disabled).
+\end{docCommand}
+
+\begin{tcblisting}{}
+\Fullstatistics
+\end{tcblisting}
+
+
+
+\begin{docCommand}{StoreCounters}{}
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.
+%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.
+\textit{Remark: This command was named \cs{StoreCountersPerChapter} in previous versions}
+\end{docCommand}
+
+\begin{docCommand}{StopCounting}{}
+
+This macro stores all registrated counter values to the file.
+
+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.
+
+% 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}
+
+\begin{docCommand}{RestoreCounter}{\marg{counter}}
+This macro restores the counter \marg{counter} to zero.
+
+\handrightnote It is not necessary to use this macro directly in almost any case.
+\end{docCommand}
+
+
+\begin{docCommand}{RestoreCounters}{}
+This macro restores all registrated counters to zero. This happens every time if a new driving section level is used.
+\end{docCommand}
+
+\section{Informational macros}
+
+\begin{docCommand}{numberofstoredcounters}{}
+This macro just returns the number of registered counters. It will not return the internal counter name which holds the number.
+\end{docCommand}
+
+\section{Conditionals}
+
+The package knows some conditionals:
+
+\begin{docCommand}{ifcpsstorage}{}
+\tcbdocmarginnote{\tcbdocnew{2015-05-08}}
+ 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}.
+
+\end{docCommand}
+
+\begin{docCommand}{EnableCPSStorage}{}
+Enables the storage of counters per chapter (etc.)
+\tcbdocmarginnote{\tcbdocnew{2015-05-08}}
+\end{docCommand}
+
+\begin{docCommand}{DisableCPSStorage}{}
+Enables the storage of counters per chapter (etc.)
+\tcbdocmarginnote{\tcbdocnew{2015-05-08}}
+\end{docCommand}
+
+\begin{docCommand}{ifcpsdraftmode}{}
+ 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}.
+\tcbdocmarginnote{\tcbdocnew{2015-05-03}}
\end{docCommand}
@@ -296,14 +402,15 @@ This command is automatically called before a new chapter starts and at the end
\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}
+\section{To-Do list}\label{section::todo}
\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 Easy - adaption for other documentclasses, especially for \classname{beamer}
\item Improve documentation
+
\end{itemize}
If you
@@ -330,12 +437,13 @@ to the users at \url{tex.stackexchange.com}, especially to
\item David Carlisle
\item Paulo Roberto Massa Cereda
\item Werner Doe (;-))
+ \item Johannes B\"ottcher (for some remarks/checking on KOMA related issues)
\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
+A special gratitude goes to Prof. Dr. Dr. Thomas Sturm for providing the wonderful \packagename{tcolorbox} package which was used to
write this documentation.
\clearpage
@@ -343,6 +451,17 @@ write this documentation.
\section{Version history}
\begin{itemize}
+\item 0.2:
+ \begin{itemize}
+ \item Introduced the possibility to disable the storage temporarily
+ \item Fixed a severe bug concerning the file handle generation
+ \item Added support for `tracklevel=option`, allowing for arbitray section levels as watch
+ \item Renamed some macros which had `Chapter` in name
+ \item Added a check if the relevant section level sequence exists at all
+ \item Added a total counter for the section level and limited the `\cs{GetTotalCounters}` max value
+ \item Fixed typos in documentation
+ \end{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
@@ -350,8 +469,7 @@ write this documentation.
\end{itemize}
\clearpage
-\StoreCountersPerChapter
-%\chapter{Dummy}
+\StopCounting
%%%% Index of commands
diff --git a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdf b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdf
index 6c57faaf687..333263e9c3e 100644
--- a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.pdf
+++ 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
index d28297021a5..cb154640e00 100644
--- a/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.tex
+++ b/Master/texmf-dist/doc/latex/cntperchap/cntperchap_example.tex
@@ -19,41 +19,81 @@
%%%%
-\documentclass{book}
+\documentclass[verbose]{scrbook}
+\usepackage{tcolorbox}
\usepackage{cntperchap}
+
\usepackage{amsthm}
\usepackage{blindtext}
\usepackage{pgffor}
+
% Register the most important counters
-\RegisterCountersPerChapter{equation,figure,table,section,subsection,subsubsection,paragraph,subparagraph}
+\RegisterCounters{equation,figure,table,section,subsection,subsubsection,paragraph,subparagraph,enumi,enumii,enumiii,enumiv}
% 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}
+\RegisterCounter{lemma}
% To show/number the lower levels too
\setcounter{secnumdepth}{5}
\begin{document}
-%\tableofcontents
+\begin{tcolorbox}[title={Document statistics for demonstration},colbacktitle=red,coltitle=black]
+There are \numberofstoredcounters\ counters tracked.
+
+ \Fullstatistics
+\end{tcolorbox}
+
+\tableofcontents
+\listoffigures
+\listoftables
\chapter{First}
-\ShowStatistics
+\ShowStatistics[1]
+
+\begin{enumerate}
+\item Groucho
+\item Zeppo
+\item Harpo
+\item Chico
+\end{enumerate}
+
+\begin{equation}
+ c^2 = a^2 + b^2
+\end{equation}
but
\ShowStatistics[4]
\section{First}
+
+
+\begin{enumerate}
+\item This
+\item \begin{enumerate}
+ \item is
+ \begin{enumerate}
+ \item a
+ \begin{enumerate}
+ \item useless
+ \end{enumerate}
+ \end{enumerate}
+ \end{enumerate}
+\item List \theenumiv
+\end{enumerate}
+
+
+
+
\begin{table}
\caption{faketable}
\caption{other faketable}
@@ -79,7 +119,7 @@ but
\section{Section \x~in chapter \thechapter}
}
\chapter{Fourth}
-\ShowStatistics
+\ShowStatistics[3]
\begin{figure}
\caption{fake figure}
@@ -90,14 +130,10 @@ but
\end{figure}
-\foreach \x in {1,...,10} {%
-\begin{equation}
- E = mc^2
-\end{equation}
-}
-\section{A single section}
+
+\section*{A single section}
\begin{theorem}
\blindtext
@@ -105,4 +141,11 @@ but
\subsection{A small subsection}
\subsubsection{An even smaller subsubsection}
+\foreach \x in {1,...,10} {%
+\begin{equation}
+ E = mc^2
+\end{equation}
+}
+
+
\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
index 62c1e57f6e5..94b202903fd 100644
--- a/Master/texmf-dist/tex/latex/cntperchap/cntperchap.sty
+++ b/Master/texmf-dist/tex/latex/cntperchap/cntperchap.sty
@@ -1,5 +1,5 @@
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{cntperchap}[2015/05/03 v0.1 -- store counter values per chapter]%
+\ProvidesPackage{cntperchap}[2015/05/09 v0.2 -- store counter values per chapter]%
%%
%% License: LaTeX Project Public License version 1.3
%% Copyright (2015) Dr. Christian Hupfer
@@ -26,220 +26,474 @@
\RequirePackage{xpatch}
\RequirePackage{xparse}
+%%%% Data macros
+
+
+\def\cps@@data@@tracklevel{chapter}
+\edef\cps@@data@@packagename{\@currname} % Store the actual packagename
+
+\newcommand{\cpspackagename}{%
+ \cps@@data@@packagename%
+}
+
+\newcommand{\@cps@@writefilehandleprefix}{tf@cps}
+
+%%%%%
+
+%%%% Preconfiguration depending on the class in the background
+
+
+\edef\cps@@config@@tracklevel{\cps@@data@@tracklevel}%
+
+\@ifclassloaded{article}{%
+ \edef\cps@@config@@tracklevel{section}
+}{%
+ \@ifclassloaded{scrartcl}{%
+ \edef\cps@@config@@tracklevel{section}%
+ }{%
+ }%
+}
+
+
+\newif\ifcpsstorage
+
+\newcommand{\EnableCPSStorage}{%
+ \cpsstoragetrue%
+}
+
+\newcommand{\DisableCPSStorage}{%
+ \cpsstoragefalse%
+}
+
+\EnableCPSStorage
%%%% Command options
\define@boolkey{cpskeys}{autodefine}[false]{}
-\presetkeys{cpskeys}{autodefine=false}{}%
+\define@key{cpskeys}{tracklevel}[\cps@@config@@tracklevel]{%
+ \gdef\@cps@@keymacro@@tracklevel{#1}%
+}
+
+\presetkeys{cpskeys}{autodefine=false,tracklevel=\cps@@config@@tracklevel}{}%
+
+\NewDocumentCommand{\DeclareCPSCounter}{s+O{cps}m}{%
+ \ifltxcounter{#3}{%
+ }{%
+ \newcounter{#2@@cps@@#3}%
+ }
+ % Not really useful so far
+ % \expandafter\newcommand\csname #3countername\endcsname{#2@@cps@@#3}%
+}
+
+\@onlypreamble{\DeclareCPSCounter}
%%%% Package options
+
+\newif\ifcpsnoendclose
+\cpsnoendclosefalse
+
+\newif\ifcpsverbose
+\cpsverbosefalse
+
\newif\ifcpsautodefine
\cpsautodefinefalse
+
\newif\ifcpsdraftmode
\cpsdraftmodetrue
+
+\DeclareOptionX{autodefine}{\cpsautodefinetrue\presetkeys{cpskeys}{autodefine=true}{}}
\DeclareOptionX{draft}{\cpsdraftmodetrue}
\DeclareOptionX{final}{\cpsdraftmodefalse}
-\DeclareOptionX{autodefine}{\cpsautodefinetrue\presetkeys{cpskeys}{autodefine=true}{}}
+\DeclareOptionX{noendclose}{\cpsnoendclosetrue}
+\DeclareOptionX{tracklevel}{\presetkeys{cpskeys}{tracklevel=#1}{}}
+\DeclareOptionX{verbose}{\cpsverbosetrue}
+
\ProcessOptionsX*
-\newcommand{\cpscounterlistname}{@counterstowatch}
-\listcsadd{\cpscounterlistname}{}
+\newcommand{\@cps@@counterlistname}{cps@@counterstostore}
+\listcsadd{\@cps@@counterlistname}{}
+
+
%%%% Internal commands
-\newcounter{cps@@currentchapter}
+% Instead of using totcount package
+\newcounter{cps@@totaltracklevelcount}
+
+% Intermediate package counters
+\newcounter{cps@@currentlevelcount}
\newcounter{cps@@togglecounter}
\newcounter{cps@@tempcounter}
+\newcounter{cps@@tempcounterstorage}
\newcounter{cps@@cpscounters}
-\NewDocumentCommand{\cpschapterstarthook}{}{%
- \stepcounter{cps@@currentchapter}%
- \ifnumgreater{\value{cps@@currentchapter}}{0}{%
- \StoreCountersPerChapter%
+
+\newcommand{\@cps@@cpscountersname}{%
+ cps@@cpscounters%
+}
+
+
+\newcommand{\@cps@@typeout}[1]{%
+ \ifcpsverbose%
+ \typeout{\cps@@data@@packagename: #1}%
+ \fi%
+}
+
+
+\NewDocumentCommand{\@cps@@tracklevelstarthook}{}{%
+ \stepcounter{cps@@currentlevelcount}%
+ \ifnumgreater{\value{cps@@currentlevelcount}}{0}{%
+ \StoreCounters%
}{}%
- \ResetTotalCounters%
+ \ResetStoredCounters%
+}
+
+
+% This disables the usage of the automatic counter storage for ToC - like macros, since those use `\chapter*` and confuse the tracking counter
+\NewDocumentCommand{\PrepareTocCommand}{m}{%
+ \xpretocmd{#1}{\DisableCPSStorage}{}{}% Lazy so far
+ \xapptocmd{#1}{\EnableCPSStorage}{}{}% Lazy so far
+}
+
+
+
+\AtBeginDocument{%
+ % Do a check first whether the given tracklevel does exist at all
+ \expandafter\ifx\csname \@cps@@keymacro@@tracklevel\endcsname\relax
+ \GenericError{Error}{Error in \jobname.tex: At line \the\inputlineno: The section level \@cps@@keymacro@@tracklevel\ is unknown}{%
+ Please check your document class and the tracklevel option}{%
+ }%
+ \else
+ % Generate a read file handle
+ \@cps@@generatereadfilehandle%
+ % Prepending the \csname \@cps@keymacro@tracklevel\endcsname command with some starter hook
+ \expandafter\xpretocmd\expandafter{\csname \@cps@@keymacro@@tracklevel\endcsname}{\@cps@@tracklevelstarthook}{\typeout{\@cps@@keymacro@@tracklevel{} command redefined}}{}%
+ \PrepareTocCommand{\tableofcontents}%
+ \PrepareTocCommand{\listoffigures}%
+ \PrepareTocCommand{\listoftables}%
+ \PrepareTocCommand{\printindex}%
+ \fi%
+}
+
+\AtEndDocument{%
+ % Store the total value of the considered sectioning level to the `.aux` file
+ \immediate\write\@auxout{%
+ \string\setcounter{cps@@totaltracklevelcount}{\number\value{cps@@currentlevelcount}}^^J
+ }% End of \immediate\write
+}
+
+\newcommand{\@cps@@readfilehandlename}{%
+ tfr@cpsreadfile%
+}
+
+\newcommand{\@cps@@readfilehandle}{%
+ \csname\@cps@@readfilehandlename\endcsname%
}
-% Prepending the \chapter command with some starter hook
+\newcommand{\@cps@@generatereadfilehandle}{%
+ \@cps@@typeout{Generating read filehandle}%
+ \expandafter\newread\csname \@cps@@readfilehandlename\endcsname%
+}
+
+\newcommand{\@cps@@generatewritefilehandle}[1]{%
+ \@cps@@typeout{Generating write filehandle #1}%
+ \expandafter\newwrite\csname\@cps@@writefilehandlename{#1}\endcsname% Generate the file handles
+}
+
+\newcommand{\@cps@@writefilehandle}[1]{%
+ \csname\@cps@@writefilehandlename{#1}\endcsname% Generate the file handles
+}
+
+
+\newcommand{\@cps@@writefilehandlename}[1]{%
+ \@cps@@writefilehandleprefix#1%
+}
+
+\newcommand{\@cps@@closeinfile}[1]{%
+ \immediate\closein#1%
+}
+
+\newcommand{\@cps@@openincpsfile}[2][\@cps@@readfilehandle]{%
+ \expandafter\immediate\openin#1=\jobname.cps#2\relax%
+}
+
+\newcommand{\@cps@@openoutcpsfile}[1]{%
+ \expandafter\immediate\openout\@cps@@writefilehandle{#1}=\jobname.cps#1\relax%
+}
+
+\newcommand{\@cps@@closeoutfile}[1]{%
+ \immediate\closeout#1%
+}
+
+\newcommand{\@cps@@closeoutcpsfile}[1]{%
+ \@cps@@typeout{Closing cps#1 file}%
+ \@cps@@closeoutfile{\csname\@cps@@writefilehandlename{#1}\endcsname}%
+}
-\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%
+ % The file handles are generated either by `\@registercounterspertracklevel` or in \AtBeginDocument
\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 :-(
- }%
+ \IfFileExists{\jobname.cps#1}{%
+ \@cps@@openincpsfile{#1}%
+ \@cps@@readcounternumbers{\@cps@@readfilehandle}{#1}%
+ \@cps@@closeinfile{\@cps@@readfilehandle}%
}{%
\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%
+ \@cps@@openoutcpsfile{#1}%
\fi%
\@nobreakfalse%
\endgroup%
}
-\newcommand{\@readcounternumbersfromfile}[1]{%
+
+\newcommand{\@cps@@readcounternumbers}[2]{%
\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%
+ \read#1 to \@cps@@numberfromfile%
+ \ifeof #1%
\stepcounter{cps@@togglecounter}%
\else%
- \listcsxadd{#1countlist}{\cps@@numberfromfile}%
+ \listcsxadd{#2countlist}{\@cps@@numberfromfile}%
\fi%
}%
}
-\newcommand{\@cpsstorecounter}[1]{%
+\newcommand{\@cps@@storecounter}[1]{%
\addtocontents{cps#1}{%
- \number\value{cps@total#1}%
+ \number\value{cps@@cps@@total#1}%
}%
}
-\newcommand{\@cpscsloop}[1]{%
- \ifnumgreater{\value{cps@@cpscounters}}{0}{%
- \expandafter\forlistcsloop{\csname #1\endcsname}{\cpscounterlistname}
+\newcommand{\@cps@@csloop}[1]{%
+ \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
+ \expandafter\forlistcsloop{\csname #1\endcsname}{\@cps@@counterlistname}
}{%
}%
}
-\newcommand{\@cpsloopstorecounters}{%
- \ifnumgreater{\value{cps@@cpscounters}}{0}{%
- \forlistcsloop{\@cpsstorecounter}{\cpscounterlistname}%
+\newcommand{\@cps@@loopstorecounters}{%
+ \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
+ \forlistcsloop{\@cps@@storecounter}{\@cps@@counterlistname}%
}{%
}%
}
-\newcommand{\@registercounterperchapter}[1]{%
- \listcsxadd{\cpscounterlistname}{#1}%
+
+\newcommand{\@cps@@registercounter}[1]{%
+ \listcsxadd{\@cps@@counterlistname}{#1}%
\stepcounter{cps@@cpscounters}%
\listcsxadd{#1countlist}{}%
- \newcounter{cps@total#1}%
- \DeclareAssociatedCounters{#1}{cps@total#1}%
+ \DeclareCPSCounter{total#1}%
+ \DeclareCPSCounter{grandtotaltemp#1}%
+ \DeclareCPSCounter{grandtotal#1}%
+ \@cps@@generatewritefilehandle{#1}%
+ % This needs some work to do
+ \DeclareAssociatedCounters{#1}{cps@@cps@@total#1,cps@@cps@@grandtotaltemp#1}%
}
-%% Searches the list of counter values for the correct chapter
-\newcommand{\@cpssearchcountervalue}[3]{%
+%% Searches the list of counter values for the tracklevel (#2)
+\newcommand{\@cps@@searchcountervalue}[3]{%
+ \setcounter{cps@@tempcounterstorage}{-1}%
\ifnumequal{#1}{\value{#2}}{%
- #3\listbreak%
+ % Value found, store it temporarily
+ \setcounter{cps@@tempcounterstorage}{#3}%
+ \listbreak%
}{%
\stepcounter{#2}%
}%
}
+\newcommand{\@cps@@auxsetcounter}[2]{%
+ \immediate\write\@auxout{%
+ \string\setcounter{#1}{\number\value{#2}}
+ }
+}%
+
+\newcommand{\@cps@@storegrandtotal}[1]{%
+ \@cps@@auxsetcounter{cps@@cps@@grandtotal#1}{cps@@cps@@grandtotaltemp#1}%
+}
+
+
+
+
%%%%%%%%%%%%%% User commands %%%%%%%%%%%%%%%%%%%%
-\newcommand{\RegisterCounterPerChapter}[2][]{%
+\newcommand{\RegisterCounter}[2][]{%
\begingroup
\setkeys{cpskeys}{#1}%
\ifltxcounter{#2}{%
- \@registercounterperchapter{#2}%
+ \@cps@@registercounter{#2}%
}{%
\ifKV@cpskeys@autodefine
\newcounter{#2}%
- \@registercounterperchapter{#2}%
+ \@cps@@registercounter{#2}%
\else%
% Ignore non existing counters
+ \GenericWarning{Counter #1 is not defined}{}%
\fi
}%
\endgroup
}
-\newcommand{\RegisterCountersPerChapter}[1]{%
- \forcsvlist{\RegisterCounterPerChapter}{#1}%
+\newcommand{\RegisterCounters}[1]{%
+ \forcsvlist{\RegisterCounter}{#1}%
}
% Prevent usage later in document body
-\@onlypreamble{\RegisterCounterPerChapter}
-\@onlypreamble{\RegisterCountersPerChapter}
-\newcommand{\ResetTotalCounter}[1]{%
- \setcounter{cps@total#1}{0}%
+\@onlypreamble{\@registercounters}
+\@onlypreamble{\RegisterCounter}
+\@onlypreamble{\RegisterCounters}
+\@onlypreamble{\PrepareToCCommands}
+
+
+\newcommand{\ResetStoredCounter}[1]{%
+ \setcounter{cps@@cps@@total#1}{0}%
}
% Reset all total counters
-\newcommand{\ResetTotalCounters}{%
- \ifnumgreater{\value{cps@@cpscounters}}{0}{%
- \forlistcsloop{\ResetTotalCounter}{\cpscounterlistname}%
+\newcommand{\ResetStoredCounters}{%
+ \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
+ \forlistcsloop{\ResetStoredCounter}{\@cps@@counterlistname}%
}{}%
}
%% Only for statistical purposes. Do not use it in a production run
-\newcommand{\IndividualCounterStatistics}[2][\number\value{cps@@currentchapter}]{%
+\newcommand{\IndividualCounterStatistics}[2][\number\value{cps@@currentlevelcount}]{%
\ifcpsdraftmode
- \noindent Chapter #1~ has \GetTotalCounter[#1]{#2} #2(s)\par
+ \GetStoredCounterValue[#1]{#2}%
+ \ifnumgreater{\value{cps@@tempcounterstorage}}{-1}{%
+ \noindent \@cps@@keymacro@@tracklevel\ #1~has \number\value{cps@@tempcounterstorage} #2(s)\par
+ }{}
\fi
}%
-
-
-
%% Only for statistical purposes. Do not use it in a production run
-\newcommand{\ShowStatistics}[1][\number\value{cps@@currentchapter}]{%
+\newcommand{\ShowStatistics}[1][\number\value{cps@@currentlevelcount}]{%
\ifcpsdraftmode%
- \ifnumgreater{\value{cps@@cpscounters}}{0}{%
- \forlistcsloop{\IndividualCounterStatistics[\number#1]}{\cpscounterlistname}%
+ \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
+ \forlistcsloop{\IndividualCounterStatistics[\number#1]}{\@cps@@counterlistname}%
}{%
\typeout{No counters registered}%
}%
\fi%
}
-\newcommand{\GetTotalCounter}[2][\number\value{cps@@currentchapter}]{%
+\newcommand{\fullstatistics}[1]{%
+\hspace{1cm} \number\value{cps@@cps@@grandtotal#1}{} #1(s)%
+
+}
+
+
+\newcommand{\Fullstatistics}{%
+ This document has
+
+ \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
+ \forlistcsloop{\fullstatistics}{\@cps@@counterlistname}%
+ }{%
+ \typeout{No counters registered}%
+ }%
+}
+
+
+\newcommand{\GetStoredCounterValue}[2][\number\value{cps@@currentlevelcount}]{%
\setcounter{cps@@tempcounter}{0}%
+ \ifnumgreater{#1}{\value{cps@@totaltracklevelcount}}{%
+ \def\cps@@trackleveltoshow{\value{cps@@totaltracklevelcount}}%
+ }{%
+ \def\cps@@trackleveltoshow{#1}%
+ }
\ifcsdef{#2countlist}{%
- \forlistcsloop{\@cpssearchcountervalue{#1}{cps@@tempcounter}}{#2countlist}%
+ \forlistcsloop{\@cps@@searchcountervalue{\cps@@trackleveltoshow}{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}%
+ \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
+ \forlistcsloop{\@startcountertoc}{\@cps@@counterlistname}%
}{%
}%
}
-\newcommand{\StoreCountersPerChapter}{%
- \@cpsloopstorecounters%
+
+
+\newcommand{\CloseCPSFiles}{%
+ \ifnumgreater{\value{\@cps@@cpscountersname}}{0}{%
+ \forlistcsloop{\@cps@@closeoutcpsfile}{\@cps@@counterlistname}%
+ }{%
+ }%
+}
+
+\newcommand{\StoreCounters}{%
+ \ifcpsstorage% Only store counters if \cpsstoragetrue
+ \@cps@@loopstorecounters%
+ \fi%
+}
+
+\newcommand{\StoreGrandTotalCounters}{%
+ \forlistcsloop{\@cps@@storegrandtotal}{\@cps@@counterlistname}%
+}
+
+
+\newcommand{\StopCounting}{%
+ \StoreCounters%
+}
+
+
+
+%% Informational macros -- very hackish so far
+
+\newcommand{\CPSGetCounterList}{%
+ \csname\@cps@@counterlistname\endcsname%
+}
+
+\newcommand{\numberofstoredcounters}{%
+ \number\value{\@cps@@cpscountersname}%
}
\AtBeginDocument{%
- % Grab the counter 'tocs'
\StartCounterToc%
}
\AtEndDocument{%
- % Write the counter values to the file
- \StoreCountersPerChapter%
+ % Write the last counter values to the file
+ \StopCounting%
+ % Full counter values
+ \StoreGrandTotalCounters%
+}
+
+%% etoolbox - addition
+\AfterEndDocument{%
+ \ifcpsnoendclose
+ % Prevent the explicit closing
+ \else
+ \CloseCPSFiles%
+ \fi
}