%% LaTeX package xcntperchap - version 0.5 (2018/01/05 -- 22:04:12) %% Documentation file for xcntperchap.sty %% %% %% ------------------------------------------------------------------------------------------- %% Copyright (c) 2016 -- 2018 by Dr. Christian Hupfer %% ------------------------------------------------------------------------------------------- %% %% 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` %% %% \documentclass[12pt,a4paper]{article} \usepackage[lmargin=2cm,rmargin=2cm,headheight=15pt]{geometry} \usepackage{savesym} \usepackage{bbding} \savesymbol{Cross} \usepackage{graphicx} \usepackage{blindtext} \usepackage[x11names]{xcolor} \usepackage{imakeidx} \usepackage{fontawesome} \usepackage[most,documentation]{tcolorbox} \usepackage[tikz]{bclogo} \usepackage{marginnote} \usepackage{fancyhdr} \usepackage{datetime} \usepackage{array} \usepackage{xkeyval} \usepackage{xparse} \usepackage{totcount} \usepackage{enumitem} \usepackage{microtype} \usepackage{caption} \usepackage[T1]{fontenc} \usepackage[scaled=0.92]{helvet} \newlist{codeoptionsenum}{enumerate}{1} \setlist[codeoptionsenum,1]{label={\textcolor{blue}{\#\arabic*}}} \renewcommand{\rmdefault}{\sfdefault} \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} \makeatletter \define@key{chdoc}{packageauthor}{% \def\KVchdocpackageauthor{#1}% } \define@key{chdoc}{packageauthormail}{% \def\KVchdocpackageauthormail{#1}% } \define@key{chdoc}{filepurpose}{% \def\KVchdocfilepurpose{#1}% } \newcommand{\chdocextractversion}[1]{% \@nameuse{#1}% } \@namedef{xcntperchapversion0.1}{v0.1 2016-05-22} \@namedef{xcntperchapversion0.2}{v0.2 2016-06-07} \@namedef{xcntperchapversion0.3}{v0.3 2017-01-09} \@namedef{xcntperchapversion0.4}{v0.4 2017-04-19} \@namedef{xcntperchapversion0.5}{v0.5 2018-01-05} \newcommand{\authorname}{Autor} \makeatother \fancypagestyle{plain}{% \fancyfoot[L]{\begin{tabular}[t]{l}\PackageDocName\ \packageversion \tabularnewline \textcopyright\ Dr. Christian Hupfer\end{tabular}}% \fancyfoot[C]{\thepage}% \fancyfoot[R]{\today}% \renewcommand{\headrule}{{\color{blue}% \hrule width\headwidth height\headrulewidth \vskip-\headrulewidth}} \renewcommand{\footrule}{{\color{blue}\vskip-\footruleskip\vskip-\footrulewidth \hrule width\headwidth height\footrulewidth\vskip\footruleskip}} \renewcommand{\footrulewidth}{2pt} \renewcommand{\headrulewidth}{2pt} } \newtcolorbox{CHPackageTitleBox}[1][]{% enhanced jigsaw, drop lifted shadow, colback=yellow!30!white, width=0.8\textwidth, #1 } \presetkeys{chdoc}{packageauthor={Christian Hupfer}}{}% \NewDocumentCommand{\CHPackageTitlePage}{O{}mO{}}{% \setkeys{chdoc}{packageauthor={Christian Hupfer},filepurpose={Documentation},#1}% \begin{center} \begin{CHPackageTitleBox}[#3] \large \bfseries% \begin{center}% \begin{tabular}{C{0.9\textwidth}}% \scshape \PackageDocName \tabularnewline \tabularnewline #2 \tabularnewline \tabularnewline \KVchdocfilepurpose \tabularnewline \tabularnewline Version \packageversion \tabularnewline \tabularnewline \today \tabularnewline \tabularnewline \addtocounter{footnote}{2} \authorname: \KVchdocpackageauthor\(^\mathrm{\fnsymbol{footnote}}\) \tabularnewline \end{tabular} \end{center} \end{CHPackageTitleBox} \renewcommand{\thefootnote}{\fnsymbol{footnote}}% \footnotetext{\mymailtoaddress}% \end{center} } \newtcolorbox{docCommandArgs}[1]{colbacktitle={blue},coltitle={white},title={Description of arguments of command \cs{#1}}} \newcommand{\tcolorboxdoclink}{http://mirrors.ctan.org/macros/latex/contrib/tcolorbox/tcolorbox.pdf} % 'Stolen' from tcolorbox documentation ;-) \newtcolorbox{marker}[1][]{enhanced, before skip=2mm,after skip=3mm, boxrule=0.4pt,left=5mm,right=2mm,top=1mm,bottom=1mm, colback=yellow!50, colframe=yellow!20!black, sharp corners,rounded corners=southeast,arc is angular,arc=3mm, underlay={% \path[fill=tcbcol@back!80!black] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2); \path[draw=tcbcol@frame,shorten <=-0.05mm,shorten >=-0.05mm] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2); \path[fill=yellow!50!black,draw=none] (interior.south west) rectangle node[white]{\Huge\bfseries !} ([xshift=4mm]interior.north west); }, drop fuzzy shadow,#1} %%%% Documentation macros \NewDocumentCommand{\packagename}{sm}{% \textcolor{blue}{\textbf{\faEnvelopeO~#2}}% \IfBooleanF{#1}{% \index{Package!#2} }% } \NewDocumentCommand{\classname}{sm}{% \textcolor{brown}{\textbf{\faBriefcase~#2}}% \IfBooleanF{#1}{% \index{Package!#2}% }% } \NewDocumentCommand{\CHDocPackage}{sm}{% \textcolor{blue}{\textbf{\faEnvelopeO~#2}}% \IfBooleanF{#1}{% \index{Package!#2} }% } \NewDocumentCommand{\CHDocClass}{sm}{% \textcolor{brown}{\textbf{\faBriefcase~#2}}% \IfBooleanF{#1}{% \index{Package!#2}% }% } \NewDocumentCommand{\CHDocKey}{sm}{% \textcolor{red}{\textbf{\faKey~#2}}% \IfBooleanF{#1}{% \index{Option!#2}% }% } \newcommand{\handrightnote}{\tcbdocmarginnote{\ding{43}}} \NewDocumentCommand{\CHDocCounter}{sm}{% \textcolor{Green4}{\textbf{\faCalculator~#2}}% \IfBooleanF{#1}{% \index{Counter!#2}% }% } \NewDocumentCommand{\CHDocTag}{sm}{% \textcolor{violet}{\faTag~#2}% \IfBooleanF{#1}{% \index{Feature!#2}% }% } \NewDocumentCommand{\CHDocFileExt}{sm}{% \faFile~#2% } \NewDocumentCommand{\CHDocFiles}{sm}{% \faFilesO~#2% } \NewDocumentCommand{\CHDocConventions}{}{% \section*{\centering Typographical conventions} Throughout this documentation following symbols and conventions are used: \begin{itemize} \item \CHDocClass*{foo} means a the class \texttt{foo} \item \CHDocPackage*{foo} names a package \texttt{foo} \item \CHDocCounter*{foo} indicates a counter named \texttt{foo} \item \CHDocFileExt*{foo} will indicate either a file named \texttt{foo} or a file extension \texttt{foo} \item \CHDocFiles*{foo} will indicate some files \item \CHDocTag*{foo} names a special feature or tag \texttt{foo} \item \CHDocKey*{foo} deals with a command or package option named \texttt{foo} \end{itemize} } \renewcommand{\tcbdocnew}[1]{#1}% \renewcommand{\tcbdocupdated}[1]{#1}% \newcommand{\CHDocNew}[1]{% \tcbdocmarginnote[doclang/new={N}, colframe=blue, halign=left, colback={blue!20!white}, fontupper={\tiny} ]{% \chdocextractversion{xcntperchapversion#1}% }% } \newcommand{\CHDocUpdate}[1]{\tcbdocmarginnote[doclang/updated={},colback={yellow},colframe={yellow!50!red}, fontupper={\tiny} ]{% \tcbdocupdated{\chdocextractversion{xcntperchapversion#1}}% }% } \newcommand{\CHDocFullVersion}[1]{Version \chdocextractversion{xcntperchapversion#1}} \newcommand{\CHDocExpCommand}[1][Expandable]{% \tcbdocmarginnote[doclang/new={N}, colframe=green!50!blue, halign=left, colback={green!90!blue}, fontupper={\tiny} ]{% #1% }% } \newcommand{\CHDocExperimentalFeature}[1][Experimental]{% \tcbdocmarginnote[doclang/new={N}, colframe=yellow!50!blue, halign=left, colback={blue!10!yellow}, fontupper={\tiny} ]{% #1% }% } \usepackage{xcntperchap} \usepackage{cleveref} \newcommand{\PackageDocName}{xcntperchap}% \newcommand{\mymailtoaddress}{% typography.with.latex@gmail.com } \def\packageversion{\xcntperchappackageversion}% \makeindex[intoc] \RegisterTrackCounter{section}{subsection,subsubsection,table,figure} \hypersetup{breaklinks=true} \hypersetup{breaklinks=true, pdftitle={\jobname.pdf -- version \packageversion}, pdfauthor={Dr. Christian Hupfer}, pdfsubject={Documentation of \PackageDocName\ package}, pdfkeywords={LaTeX, counters}, pdfcreator={LaTeX} } \begin{document} \mmddyyyydate \setlength{\parindent}{0pt} \thispagestyle{empty}% \CHPackageTitlePage[packageauthor={Christian Hupfer}]{Store counter values per chapter (or other track levels)} \clearpage \tableofcontents \clearpage \CHDocConventions \clearpage \pagestyle{plain} \setcounter{footnote}{0} \pagestyle{plain} \section{Disclaimer} This package as of its version \packageversion\ is a rewrite of the former \CHDocPackage{cntperchap} by the same author, is under constant development and as such subject to macro interface changes as well as renaming of macros. Not all features of the previous package has been incorporated so far -- if some functionality of your document depends on \CHDocPackage{assoccnt}, continue using the older version and shift gradually to \CHDocPackage{\PackageDocName} please, which uses the newer \CHDocPackage{xassoccnt}. \begin{marker} Most times class and package authors will benefit of this package, but there might be usual documents that need the features of |\PackageDocName|| \end{marker} \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 predefined track level, for example per chapters. The values are stored at the beginning of such a new track level, say \cs{chapter} and written to a \CHDocFileExt{jobname.cpc} file. \begin{marker} Since the \CHDocCounter*{page} counter is an unrealiable 'friend' it is not advised to use this counter as a track level. \end{marker} As of version \packageversion\ there is no default version of a track level. 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}. \section{Package options}% \label{section::package_options} As of version \packageversion~ the package has no package options. \section{Requirements and incompatibilities}% \subsection{Required packages} Since \CHDocPackage{\PackageDocName} is written using \CHDocPackage{expl3}, it requires the \CHDocPackage{xparse} package. It relies on the features of associated counters introduced by \CHDocPackage{xassoccnt} v1.4. \begin{itemize} \item \CHDocPackage{zref}% \item \CHDocPackage{expl3}% \item \CHDocPackage{xparse}% \item \CHDocPackage{xassoccnt}% \end{itemize} The package \CHDocPackage{xparse} is already loaded by \CHDocPackage{assoccnt} and does not need to be specified again. \subsection{Incompatibilities} 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 \CHDocPackage{assoccnt} and \CHDocPackage{xifthen} which is not solved so far. \marginnote{\bcbombe} It would be nice to adapt the package for usage on a per frame base with the \classname{beamer} class, but this seems both not really necessary as well as quite difficult, since \classname{beamer} follows different strategies about the usage of ``pages'' or ``sections'', see \ref{section::todo} \clearpage \section{Documentation of Macros} \subsection{Preamble only commands} \begin{docCommand}{RegisterTrackCounter}{\marg{track counter}\marg{counter1, counter2,...}} \CHDocNew{0.3} This provides the means to let the package know that the counters should be tracked for values inside a certain track level -- specify this in the document preamble. \begin{docCommandArgs}{RegisterTrackCounter}% \begin{itemize} \item \marg{track counter} This contains the counter name which is the track level, e.g. \CHDocCounter*{section} \item \marg{counter1, counter2,...} This marks the counters to be tracked inside the track level, e.g. \CHDocCounter*{subsection}, \CHDocCounter*{subsubsection} \end{itemize} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{RegisterMultipleTrackCounters}{\marg{track counter 1, track counter 2,...}\marg{counter1, counter2,...}} \CHDocNew{0.3} This provides the means to let the package know that the counters should be tracked for values inside multiple track levels -- specify this in the document preamble. All counters in the 2nd mandatory argument will be tracked by \textbf{all} track levels. \begin{docCommandArgs}{RegisterMultipleTrackCounters}% \begin{itemize} \item \marg{track level 1, track level 2,...} This list contains the counters which are track levels \item \marg{counter1, counter2,...} This marks the counters to be tracked inside of each(!) track level. \end{itemize} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{RegisterCounters}{\marg{track counter}\marg{counter1, counter2,...}} \tcbdocmarginnote{\tcbdocnew{\chdocextractversion{xcntperchapversion0.1}}} \refCom{RegisterCounters} has the some meaning like \refCom{RegisterTrackCounter} and is the old name for this. Use the newer version for new documents since this command will be removed one day. \end{docCommand}% \section{User commands} \begin{docCommand}[doc new={\chdocextractversion{xcntperchapversion0.1}}]{ObtainTrackedValue}{\oarg{counter value}\marg{track level}\marg{tracked counter}}% \tcbdocmarginnote{\tcbdocnew{\chdocextractversion{xcntperchapversion0.1}}} This command prints the value of the tracked counter of a track counter, i.e. the number of subsections in a specific chapter, say, the 5th chapter can be obtained by \begin{dispExample}{listings only} \ObtainTrackedValue[5]{chapter}{subsection} \end{dispExample} \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, the only option is a counter value, say 5 for the 5th chapter. This must be the total number of the relevant track counter, i.e. the 17th total section etc. \item \marg{track counter name}: The name of the track level, i.e. \CHDocCounter*{section}. \item \marg{tracked counter name}: The name of the tracked counter, i.e. \CHDocCounter*{figure}. \end{codeoptionsenum} Please note that the number of entities per track level might be reported wrongly for floats, since those are shifted to some other places. If this should be prevented, a \cs{FloatBarrier} from \CHDocPackage{placeins} might be necessary (see the example file \verb!xcntperchap_driver.tex!) \begin{marker}\tcbdocmarginnote{\tcbdocupdated{\chdocextractversion{xcntperchapversion0.2}}} This macro is not expandable -- for an expandable version use \refCom{ObtainTrackedValueExp} instead. \end{marker} \end{docCommand} \begin{docCommand}[before={\CHDocExpCommand}]{ObtainTrackedValueExp}{\oarg{counter value}\marg{track level}\marg{tracked counter}} \tcbdocmarginnote{\tcbdocnew{\chdocextractversion{xcntperchapversion0.2}}} This command is the expandable version of \refCom{ObtainTrackedValue} and should be used if calculations, comparisions and write - operations to files are requested. The meaning of arguments is the same as in \refCom{ObtainTrackedValue}. \end{docCommand} \section{Experimental features}\CHDocNew{0.3} \begin{marker} The content and description of the features are marked as experimental as of version \packageversion. Features are subject to changes as well as macro names might be revised in future versions. \end{marker} The tracking of counters with respect to some fixed number of a track level counter might get tedious, i.e. it is not very convenient to remember a special section number of which counter \CHDocCounter{foo} should be tracked. \CHDocPackage{\PackageDocName} provides the possibility to add a label to some track level counter and obtaining the running total number of the relevant counter by using \refCom{ObtainTrackedValueByLabel}. \begin{docCommand}{tracklabel}{\oarg{counter name}\marg{label name}} \CHDocNew{0.3} \cs{tracklabel} provides a label given in the first mandatory argument to a track level counter -- the counter is being auto detected with \cs{LastRefSteppedCounter} from \CHDocPackage{xassoccnt}. In addition, the a label with the same name is set with the usual \cs{label} command. Use \refCom{tracklabel*} to suppress the generation of such labels. \begin{codeoptionsenum} \item \oarg{counter name}: This is only used as an optional argument to the \cs{label} command as provided by \CHDocPackage{cleveref}. \item \marg{label name}: A label for a track level counter. \end{codeoptionsenum} \end{docCommand} \begin{docCommand}{tracklabel*}{\oarg{counter name}\marg{label name}} \CHDocNew{0.3} This is the starred version of \refCom{tracklabel} but does not generate a usual label of the name given with the first mandatory argument. The optional argument is ignored as of version \packageversion. \end{docCommand} \begin{marker} Please note that the usability of \refCom{tracklabel} is restricted to track level counters that have been used with \cs{refstepcounter} as of version \packageversion! \end{marker} \begin{docCommand}[before={\CHDocExpCommand}]{ObtainTrackedValueByLabel}{\oarg{counter name}\marg{label name}\marg{tracked counter}} \CHDocNew{0.3} This command uses a label given with \refCom{tracklabel} to some track level counter usage and will return the relevant number of the tracked counter. The underlying track level counter is autodetected using \CHDocPackage{zref} properties. \begin{codeoptionsenum} \item \oarg{counter name}: Use this to override the auto detection of the track level counter. This might cause unpredictable logical errors, however. \item \marg{label name}: A label for a track level counter. \item \marg{tracked counter}: The name of a counter being in the tracking list of the (auto detected) track level counter. \end{codeoptionsenum} \begin{itemize} \item If the given label is not defined, a \texttt{??} is printed instead. As of version \packageversion\ there is no warning or error message. \item This command is expandable! \end{itemize} \end{docCommand} See \Cref{packageexample::tracking_by_label} for an example using the tracking - by - label - feature. \begin{docCommand}{AddToTrackedCounters}{\marg{tracked counters}\marg{counter value}} \CHDocNew{0.3} This macro adds the same value to a comma separated list of tracked counters without using \cs{stepcounter}. \begin{codeoptionsenum} \item \marg{tracked counters}: A comma separated list of counter names. \item \marg{counter value}: An integer value \end{codeoptionsenum} \end{docCommand} \section{Examples} \subsection[Item count of enumerate]{Count the items of an enumerate} \tcbset{breakable} \begin{dispListing} \documentclass{article} \usepackage{xcntperchap} \usepackage{enumitem} \RegisterCounters{section}{enumi} \RegisterCounters{subsection}{enumi} \begin{document} \tableofcontents \section{Section 1 -- with \ObtainTrackedValueExp{section}{enumi} items} \begin{enumerate}[resume] \item Item 1 \item Item 2 \item Item 3 \end{enumerate} \subsection{Another subsection with \ObtainTrackedValueExp{subsection}{enumi} } \begin{enumerate}[resume] \item Item 4 \item Item 5 \end{enumerate} \section{Section 2 -- with \ObtainTrackedValueExp{section}{enumi} items} \begin{enumerate}[resume] \item Item 6 \item Item 7 \end{enumerate} \subsection{Another subsection with \ObtainTrackedValueExp[2]{subsection}{enumi} Items } % Second total subsection to be used. \begin{enumerate}[resume] \item Item 8 \item Item 9 \item Item 10 \item Item 11 \item Item 12 \item Item 13 \end{enumerate} \end{document} \end{dispListing} \subsection[Item count of enumerate -- alternate version]{Count the items of an enumerate -- with label reference}\label{packageexample::tracking_by_label} \tcbset{breakable} \begin{dispListing} \documentclass{article} \usepackage{xcntperchap} \usepackage{enumitem} \RegisterCounters{section}{enumi} \RegisterCounters{subsection}{enumi} \begin{document} \tableofcontents \section{Section 1 -- with \ObtainTrackedValueExp{section}{enumi} items} \tracklabel{sectionlabel} \begin{enumerate}[resume] \item Item 1 \item Item 2 \item Item 3 \end{enumerate} \subsection{Another subsection with \ObtainTrackedValueExp{subsection}{enumi} items} \begin{enumerate}[resume] \item Item 4 \item Item 5 \end{enumerate} \section{Section 2 -- with \ObtainTrackedValueExp{section}{enumi} items} \begin{enumerate}[resume] \item Item 6 \item Item 7 \end{enumerate} \subsection{Another subsection with \ObtainTrackedValueExp[2]{subsection}{enumi} Items } \tracklabel{subsec::somelabel} However, you can use a label as well: \ObtainTrackedValueByLabel{subsec::somelabel}{enumi} Items \begin{enumerate}[resume] \item Item 8 \item Item 9 \item Item 10 \item Item 11 \item Item 12 \item Item 13 \end{enumerate} \end{document} \end{dispListing} \clearpage \section{To-Do list}\label{section::todo} \begin{itemize} \item Better error handling (no checks for many features so far). \item More options for fine control of the behaviour package and macros. \item Easy - adaption for other documentclasses, especially for \classname{beamer} \item Improve documentation \item More examples \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 tex.stackexchange.com, especially: \begin{marker} A special gratitude goes to Prof. Dr. Dr. Thomas Sturm for providing the wonderful \CHDocPackage{tcolorbox} package which was used to write this documentation. \end{marker} \section{Version history} \begin{itemize}[itemsep=15pt] \item \CHDocFullVersion{0.5} Improved the core \cs{setcounter} in order to grab changes for relevant counters there as well. \item \CHDocFullVersion{0.4} Improved the core \cs{stepcounter} in order to fit the \CHDocPackage{expl3} and \CHDocPackage{xparse} changes of Februar - April 2017. \item \CHDocFullVersion{0.3} \begin{itemize} \item \CHDocNew{0.3} Support for obtaining a tracked value level by using labels with \refCom{tracklabel}, \refCom{tracklabel*} and \refCom{ObtainTrackedValueByLabel} \item \CHDocNew{0.3} Added the \refCom{RegisterTrackCounter} and \refCom{RegisterMultipleTrackCounters} as a replacement of \refCom{RegisterCounters}. \item Added \refCom{AddToTrackedCounters} macro to circumvent counter value update problems for specific tracked counters. \end{itemize} \item Version \chdocextractversion{xcntperchapversion0.2} \tcbdocmarginnote{\tcbdocnew{\chdocextractversion{xcntperchapversion0.2}}} \begin{itemize} \item Added the expandable version of \cs{ObtainTrackedValues} \item Removed the bug concerning the missing reset of the associated counters \end{itemize} \item Version \chdocextractversion{xcntperchapversion0.1} \tcbdocmarginnote{\tcbdocnew{\chdocextractversion{xcntperchapversion0.1}}} Bootstrap version, rewrite of previous \CHDocPackage{cntperchap} with LaTeX - 3 - Kernel features \end{itemize} \clearpage \printindex \end{document}