%% LaTeX package xassoccnt - version 0.5 (2016/02/27 -- 19/52/22) %% Documentation file for xassoccnt.sty %% %% %% ------------------------------------------------------------------------------------------- %% Copyright (c) 2016 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,a4]{article} \usepackage[lmargin=2cm,rmargin=2cm,headheight=15pt]{geometry} \usepackage{savesym} \usepackage{bbding} \savesymbol{Cross} \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{lucidabr} \usepackage[scaled=0.92]{helvet} \newlist{codeoptionsenum}{enumerate}{1} \setlist[codeoptionsenum,1]{label={\textcolor{blue}{\#\arabic*}}} \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}% } \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} Author: \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} } \usepackage[autodefinecounters=true]{xassoccnt} \usepackage{amsmath} \usepackage{amssymb} \usepackage{bookmark} \usepackage{cleveref} \newcommand{\PackageDocName}{xassoccnt}% \newcommand{\mymailtoaddress}{% christian.hupfer@yahoo.de } \let\DeclareAssociatedCountersOrig\DeclareAssociatedCounters % -> for use in examples only \def\packageversion{\xassoccntpackageversion}% \makeindex[intoc] \renewcommand{\rmdefault}{\sfdefault} \newtotcounter{totalpages}% \newtotcounter{anothertotalpages}% \newtotcounter{totalproofs}% \newtotcounter{totalsections}% \newtotcounter{totalequations} \newtotcounter{totalsubsections}% \newtotcounter{othertotalsubsections}% \DeclareDocumentCounter{foocntr}% \DeclareDocumentCounter{foobarcntr}% %%%% Declare all the counters here -- \DeclareAssociatedCounters{subsection}{totalsubsections}% \DeclareAssociatedCounters{equation}{totalequations}% \DeclareAssociatedCounters{section}{totalsections}% \DeclareAssociatedCounters{proof}{totalproofs} \DeclareAssociatedCounters{page}{totalpages,anothertotalpages}% \NewTotalDocumentCounter{foototal}% \hypersetup{breaklinks=true, pdftitle={\jobname.pdf -- version \packageversion}, pdfauthor={PACKAGEAUTHOR}, pdfsubject={Documentation of \PackageDocName\ package}, pdfkeywords={LaTeX, counters}, pdfcreator={LaTeX} } \newcommand{\versionzerofourdate}{2016-01-26} \newcommand{\currentversiondate}{2016-02-27} \newcommand{\versionzerofivedate}{\currentversiondate} \begin{document} \mmddyyyydate \setlength{\parindent}{0pt} \thispagestyle{empty}% \CHPackageTitlePage[packageauthor={Christian Hupfer}]{Associated counters stepping simultaneously} \clearpage \tableofcontents \clearpage \CHDocConventions \clearpage \pagestyle{plain} \setcounter{footnote}{0} \section*{Preface} This package is the successor and a complete rewrite of \CHDocPackage{assoccnt}. Not all features of that package are implemented yet -- if some functionality of your document depends on \CHDocPackage{assoccnt}, continue using the older version and shift gradually to \CHDocPackage{\PackageDocName} please. \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 some additional support for example for a package like \CHDocPackage{totcount}. For example, the total number of pages in a document could be achieved by using \begin{dispExample}% \regtotcounter{page} ... The number of pages in the document is \number\totvalue{page} page(s) -- but in fact it has \total{totalpages} pages. \end{dispExample}% This will work, as long there is no reset of the page counter, as it might happen in the case of \cs{setcounter} or \cs{pagenumbering} being applied in the document. The result is a false page counter total value. This package provides associate counters, i.e. counters that are increased simultaneously with a driver counter and are not influenced by a a resetting of the driver counter, as long as not being added to the reset list by definition of the counter or explicitly by \cs{@addtoreset}. This package defines some macros to handle associated counters. The only interception to the standard behaviour is within the redefined commands \cs{addtocounter} and \cs{stepcounter}. The usual commands still work, as there is code added to their definition. In a previous version \cs{refstepcounter} was redefined, but since these use \cs{addtocounter} effectively, it was decided to use the basic command. Internally, the associated counters are stored in one list per counter -- it is not recommended to operate on those lists directly. Please note, that this package does not provide means for simultaneous stepping of counters defined by plain \TeX{} \cs{newcount} command.\marginnote{\bcbombe} \section{Requirements, loading and incompatibilities}% \subsection{Required packages and \TeX\ engine} The package does not require features from Xe\LaTeX\ or Lua\LaTeX\ but can be run with those features as well as with \LaTeX\ or pdf\LaTeX. The compilation documentation requires however pdf\LaTeX as of version \packageversion. \begin{itemize} \item \CHDocPackage{xcolor} \item \CHDocPackage{xparse} \item \CHDocPackage{l3keys2e} \end{itemize} The documentation file requires some more packages such as \CHDocPackage{tcolorbox} but those packages are widely available on CTAN, MikTeX and TeXLive as well. \subsection{Loading of the package} Loading is done with \begin{tcblisting}{listing only} \usepackage[options]{xassoccnt} \end{tcblisting} For the relevant options see \cref{subsection:packageoptions} Concerning the packages \CHDocPackage{hyperref} and \CHDocPackage{cleveref}: The preferred loading order is the usually recommended on: \begin{itemize} \item other packages \item \CHDocPackage{xassoccnt} \item \CHDocPackage{hyperref} \item \CHDocPackage{cleveref} \end{itemize} For potential problems see \cref{subsection:incompatibilities} \subsection{Incompatibilities}\label{subsection:incompatibilities} \begin{itemize} \item This package cannot be used with plain \TeX\ and will not provide support for counters (or better counter registers) that have defined with the \TeX\ primitive \cs{countdef} directly in a \LaTeXe\ document nor will it hook into plain \TeX\ \cs{advance} commands used otherwise than in the usual \LaTeXe\ wrappers \cs{addtocounter} etc. \item This package does not work really well with the \CHDocPackage{calc} package if that one is loaded after \CHDocPackage{\PackageDocName}. Load \CHDocPackage{calc} \textbf{before} \CHDocPackage{\PackageDocName}! \begin{marker} \tcbdocmarginnote{\bcbombe\tcbdocupdated{2015-11-10}} As of version \packageversion\ \CHDocPackage{\PackageDocName} will abort compilation if \CHDocPackage{calc} is loaded after this package, but will issue a warning only if \CHDocPackage{calc} is loaded first. \end{marker} \item \CHDocPackage{\PackageDocName} and \CHDocPackage{perpage} are not compatible completely. As of version \packageversion\ it is not possible to use the command \cs{AddAbsoluteCounter} from \CHDocPackage{perpage} -- this feature is provided already by this package. \tcbdocmarginnote{\tcbdocnew{2015-11-10}} \begin{marker} It is not recommended to use counters under control of \CHDocPackage{perpage} with the association method! \end{marker} % is somewhat similar to \refCom{AddAssociatedCounters} from this package but unless changed manually, the values of and \texttt{perpage} - absolute counter and an associated counter by this package differ by one, since \cs{AddAbsoluteCounter} initializes the counter value to the value of 1. %\item This package does not work together when the Package \CHDocPackage{xifthen} is included. As of version \packageversion~I could not figure out, where the strange behaviour comes in. It's most likely an incompatibility between \CHDocPackage{etoolbox} and \CHDocPackage{xifthen} %\marginnote{\bcbombe} \end{itemize} \subsection{Package options}\label{subsection:packageoptions} As of version \packageversion\ \CHDocPackage{\PackageDocName} supports the option \begin{docKey}{autodefinecounters}{=\meta{true,false}}{initially false} Setting this package option to \texttt{true}, all counters used with the special package macros will be autodefined, unless disabled locally. See the commands \begin{itemize} \item \refCom{DeclareAssociatedCounters} \item \refCom{AddAssociatedCounters} \end{itemize} \end{docKey} \section{Documentation of Macros} \tcbset{color command={blue}} The main purpose of this package is co-stepping of counters, but there are some helper commands in addition to macros provided \LaTeXe\ already, see section \nameref{section::additions_to_l2e}. \begin{itemize} \item Section \nameref{subsection::associatedcounterscmds} describes the most important macros for setting up associated counters \item Section \nameref{subsection::drivercounterscmds} informs about the macros for setting up, removing or clearing driver counters \item Section \nameref{subsection::querycmds} deals with query command sequences about counters being a driver or an associated counters \item Section \nameref{subsection::informationcmds} contains routines that show which counters have been changed last \end{itemize} \subsection[Association macros]{Associated counters commands}\label{subsection::associatedcounterscmds} All macros have the general rule, that the driver counter is specified as 1st mandatory argument to the macro, which is in almost all cases the 2nd argument of the macro. \begin{docCommand}{DeclareAssociatedCounters}{\oarg{options}\marg{driver counter}\marg{associated counters list}} This command is the main macro of the package. It declares the counter names being specified in comma - separated - list (CSV) which should be stepped simultaneously when the driver counter is increased by \cs{stepcounter}. If only counter is to be associated, omit a trailing ","! %\begin{docCommandArgs}{DeclareAssociatedCounters} \begin{codeoptionsenum} \item \oarg{options}: %As of \packageversion, the optional argument \oarg{options} is not used so far, but is reserved for later purposes. \begin{docKey}[][]{autodefine}{=\meta{choice}}{initially none} This choice - key can be specified if the specified counters should be defined if they not already available. Possible values are \begin{itemize} \item \texttt{none} -- no counter is autodefined \item \texttt{all} -- all counters will be autodefined \item \texttt{driver} -- only driver counters will be autodefined \item \texttt{associated} -- only associated counters will be autodefined \end{itemize} \end{docKey} Default is \texttt{none} \begin{docKey}[][]{sloppy}{}{} If \refKey{autodefine} key is used, the \texttt{sloppy} key disables the check whether a counter is defined already. \end{docKey} \item \marg{driver counter} Holds the name of the driver counter to which the list of counters should be associated \item \marg{associated counters list} A comma separated list of counter names that should be associated to the driver counter \end{codeoptionsenum} %\end{docCommandArgs} \begin{itemize} \item This command is a preamble command, i.e. it can be used in the preamble of the document or within other packages or class files only. \item This command should be used as early as possible, i.e. in the preamble of the document, since the driven counters are not increased as long as they are not associated to the driver counter. On the hand, it is possible or may be required to control the starting point of the association at any position in the body of the document, when the association should start later on. Use the command \refCom{AddAssociatedCounters} if counters should be associated within the document body. \end{itemize} % Relax for documentation purposes \renewcommand{\DeclareAssociatedCounters}[3][]{\relax}% \begin{dispExample} %%%% The association of anothertotalpages in this example just takes place here, so the stepping of the counter will start from here and providing a 'wrong' value. %%%% \DeclareAssociatedCounters{page}{totalpages,anothertotalpages}% This document has \number\totvalue{totalpages} (note: \number\totvalue{anothertotalpages}) pages. \end{dispExample} \begin{itemize} \item Current version state: \begin{itemize} \item No checking whether the 2nd and 3rd arguments hold counter names is applied. \item Mutually cross - association of two counters is not supported! The compilation will stop on this! \end{itemize} \item A self-association of the driver counter to itself is ignored internally as this would lead to inconsistent counter values. \item The order of the specification of associated counters in the 2nd arguments is of no importance. \item Specifing an associated counter name multiple times has no effect, only the first occurence of the name will be used. \end{itemize} \end{docCommand} \begin{docCommand}{AddAssociatedCounters}{\oarg{options}\marg{driver counter}\marg{associated counters list}} The usage of this macro is similar to \refCom{DeclareAssociatedCounters}; if it is called in the document preamble (or in package file), \refCom{AddAssociatedCounters} falls back to \begin{center}\refCom{DeclareAssociatedCounters},\end{center} having the same optional argument functionality with \refKey{autodefine} and \refKey{sloppy}; if it is called in the document body, this command adds some counters to the associated counter list for a specific driver counter -- if this list does not exists, the \LaTeX{} run will issue a warning, but add the driver counter to the driver list and the associated counters analogously. \marginnote{\bcbombe} Using \refCom{AddAssociatedCounters} in the document body automated generation of counters is disabled. % You have to use \refCom{DeclareAssociatedCounters} first, to set up the driver counter hook. \begin{docCommandArgs}{AddAssociatedCounters} \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, the optional argument \oarg{options} are the same as for \refCom{DeclareAssociatedCounters}, see \refKey{autodefine} and \refKey{sloppy}. \item \marg{driver counter} Holds the name of the driver counter to which the list of counters should be associated \item \marg{associated counters list} A comma separated list of counter names that should be associated to the driver counter \end{codeoptionsenum} \end{docCommandArgs} % macro of the package. It declares the counter names being specified in comma - separated - list (CSV) which should be stepped simultaneously when the driver counter is increased by \cs{stepcounter}. \end{docCommand}% \begin{docCommand}{RemoveAssociatedCounter}{\marg{driver counter}\marg{associated counter}} This command removes a counter from the existing list for a driver counter, i.e. the counter will not be increased any longer by \cs{stepcounter}. It can be increased however manually, of course. \end{docCommand} \begin{dispExample} \RemoveAssociatedCounter{page}{anothertotalpages} This document has \number\totvalue{totalpages} (beware: \number\totvalue{anothertotalpages}) pages. \end{dispExample} \begin{docCommand}{RemoveAssociatedCounters}{\marg{driver counter}\marg{list of associated counters}} This command removes the comma-separated-value list of counters from the existing list for a driver counter, i.e. the counters will not be increased any longer by \cs{stepcounter}. They can be increased however manually, of course. Take care not to confuse the commands \refCom{RemoveAssociatedCounters} and{}\linebreak \refCom{RemoveAssociatedCounter} \end{docCommand} \begin{docCommand}{ClearAssociatedCounters}{\oarg{options}\marg{driver counter}} This command clears the internal list for all counters associated to the \marg{driver counter}. The counters will not be increased automatically any longer. The optional argument is not used as of version \packageversion. Please note that the driver counter is not removed from the list of driver counters -- this simplifies reassociating of (other) counters to this one later on with the macro \refCom{AddAssociatedCounters} and suppress the relevant warning. If the driver counter and all its associated counters should be removed, use \refCom{RemoveDriverCounter} instead. \end{docCommand} \clearpage \subsection[Driver macros]{Driver counter commands} \label{subsection::drivercounterscmds} \begin{docCommand}{AddDriverCounter}{\oarg{options}\marg{driver counter name}} \begin{docCommandArgs}{AddDriverCounter}% \begin{codeoptionsenum} \item \oarg{options}: As of \packageversion, the optional argument \oarg{options} is not used so far, but is reserved for later purposes. \item \marg{driver counter name} Holds the name of the driver counter that should be added to the list of driver counters. \end{codeoptionsenum} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{RemoveDriverCounter}{\oarg{options}\marg{driver counter}} This command clears the internal list for all counters associated to the \marg{driver counter}. The counters will not be increased automatically any longer. The optional argument is not used as of version \packageversion. If all driver counters should be unregistered, use \refCom{ClearDriverCounters} instead! \end{docCommand} \begin{docCommand}{ClearDriverCounters}{\oarg{options}}% This clears completely the list of driver counters, such that no counters are regarded as being associated -- i.e. no driver is hold as being a driver counter. The optional argument is not used as of version \packageversion. \end{docCommand} \subsection[Query macros]{Commands for queries} \label{subsection::querycmds} Sometimes it might be necessary to get information, whether a counter is regarded as a driver or as an associated counter. This section describes some query macros in order to obtain this information. \begin{docCommand}{IsAssociatedToCounter}{\marg{driver counter}\marg{associated counter}\marg{True branch}\marg{False branch}} This macro checks, whether a counter is associated to a particular given driver counter and expands the corresponding branch. If the internal driver counter list does not exist, the false branch will be used, since this also means, that the possibly associated counter is not associated at all. \begin{docCommandArgs}{IsAssociatedToCounter}% \begin{codeoptionsenum} \item \marg{driver counter} Holds the name of the driver counter to which \marg{associated counter} the could possibly be associated. \item \marg{associated counter} Contains the name of the possibly associated counter. \item \marg{True branch} This code is expanded if the counter is associated to the driver, otherwise it is ignored. \item \marg{True branch} This code is expanded if the counter is \textbf{not} associated to the driver, otherwise it is ignored. \end{codeoptionsenum} \end{docCommandArgs} \begin{dispExample} % Remove associated counter first for demonstration purposes \RemoveAssociatedCounter{page}{anothertotalpages} \IsAssociatedToCounter{page}{totalpages}{Yes, totalpages is associated}{No, totalpages is not associated} \IsAssociatedToCounter{page}{anothertotalpages}{Yes, anothertotalpages is associated}{No, anotherpages is not associated} \end{dispExample} See also \begin{itemize} \item \refCom{IsAssociatedCounter} for checking whether a counter is associated \item \refCom{IsDriverCounter} in order to check whether a counter is a driver. \item \refCom{GetDriverCounter} returns the driver counter name for a given associated counter name \end{itemize} \end{docCommand} \begin{docCommand}{GetDriverCounter}{\marg{counter name}}% This commands returns the driver counter to which the counter name of the first argument is connected to. If the counter is not defined, the macro returns nothing. \begin{itemize} \item No check whether the counter name is defined is performed \item No check whether the counter is associated at all is performed. Usage of this command in conjunction with \refCom{IsAssociatedCounter} is strongly encouraged. \end{itemize} \begin{dispExample}% totalpages is associated to the \textcolor{blue}{\textbf{\GetDriverCounter{totalpages}}} counter. % Try with an undefined counter name humptydumpty is associated to the \textcolor{blue}{\textbf{\GetDriverCounter{humptydumpty}}} counter. \end{dispExample}% \end{docCommand}% \begin{docCommand}{IsAssociatedCounter}{\marg{counter name}\marg{True branch}\marg{False branch}}% This commands tests, whether a given counter name is an associated counter and expands correspondingly the true or the false branch. The command does not tell to which driver the counter it is associated -- this information can be obtained by \refCom{GetDriverCounter}. \begin{docCommandArgs}{IfAssociatedCounter}% \begin{codeoptionsenum} \item \marg{counter name}% Contains the name of the possibly associated counter \item \marg{True branch} This code is expanded if the counter is associated to a driver, otherwise it is ignored \item \marg{True branch} This code is expanded if the counter is \textbf{not} associated a driver, otherwise it is ignored \end{codeoptionsenum} \end{docCommandArgs} \begin{dispExample} \IsAssociatedCounter{section}{Yes, section is an associated counter}{No, section counter does not have the associated counter properties} \IsAssociatedCounter{totalpages}{Yes, totalpages is an associated counter}{No, totalpages counter does not have the associated counter properties} \end{dispExample} \end{docCommand}% \begin{docCommand}{IsDriverCounter}{\marg{driver counter name}\marg{True branch}\marg{False branch}}% This commands tests, whether a given counter name is a driver counter and expands correspondingly the true or the false branch. \begin{docCommandArgs}{IfDriverCounter}% \begin{codeoptionsenum} \item \marg{driver counter name}% Contains the name of the possible driver counter \item \marg{True branch} This code is expanded if the counter is a driver, otherwise it is ignored \item \marg{True branch} This code is expanded if the counter is \textbf{not} a driver, otherwise it is ignored \end{codeoptionsenum} \end{docCommandArgs} \begin{dispExample} \IsDriverCounter{section}{Yes, section is a driver counter}{No, section counter does not have driver properties} \end{dispExample} \end{docCommand}% \begin{docCommand}{IsSuspendedCounter}{\marg{counter name}\marg{true branch}\marg{false branch}} See \nameref{section::suspendedresumedcounters} on this topic. This command checks, whether a counter is suspended, i.e. not updated at all and expands the corresponding branches. %\begin{docCommandArgs}{IfSuspendedCounter}% \begin{codeoptionsenum} \item \marg{counter name}% Contains the name of counter presumed to be suspended \item \marg{True branch} This code is expanded if the counter is suspended, otherwise it is ignored \item \marg{True branch} This code is expanded if the counter is \textbf{not} suspended, otherwise it is ignored \end{codeoptionsenum} %\end{docCommandArgs} \end{docCommand} \subsubsection[\cs{IfIsDocumentCounter}-Queries]{Commands checking whether a name refers to a counter} \CHDocPackage{\PackageDocName}\ provides three commands that are quite similar -- all check whether \marg{name} is an already defined \LaTeXe\ counter (name), in good tradition with the \CHDocPackage{xparse} - syntax: \begin{itemize} \item \begin{docCommand}{IfIsDocumentCounterTF}{\oarg{}\marg{name}\marg{true branch}\marg{false branch}} This macro performs the full branching \end{docCommand} \item \begin{docCommand}{IfIsDocumentCounterT}{\oarg{}\marg{name}\marg{\meta{long} true branch}} This command executes only if the name is a counter. \end{docCommand} \begin{docCommand}{IfIsDocumentCounterF}{\oarg{}\marg{name}\marg{true branch}} This command executes only if the name is not a counter. \end{docCommand} \end{itemize} The optional argument is not used as of version \packageversion\ for none of those three commands. \subsection[Macros about the reset list]{Information macros about the counter reset list} Sometimes it might be necessary or convenient to know how many counters are on a reset list of some other counters, i.e. added by \cs{newcounter}\textbraceleft counter\textbraceright[resetting counter] or \refCom{NewDocumentCounter}. There are some macros that provide this information: \begin{docCommand}{countersresetlistcount}{\marg{counter name}} This macro determines the number of counters being in the reset list of the counter specified as mandatory argument. Please note: This command isn't expandable. The number is stored internally to another macro, which can be accessed with \refCom{getresetlistcount}, which returns a pure integer number. \end{docCommand} \begin{docCommand}{getresetlistcount}{} This macro returns the number of counters being in the reset list of the counter specified as mandatory argument. It needs a previous call of \refCom{countersresetlistcount} first! If the counter has no other counters in its reset list, the value of 0 is returned. \end{docCommand} \begin{docCommand}{IfInResetListTF}{\oarg{}\marg{resetting counter}\marg{reset counter}\marg{true branch}\marg{false branch}} This command sequence tests whether the counter \meta{reset counter} is in the reset list of \meta{resetting counter} and expands the relevant branch then. See the short-circuit commands \refCom{IfInResetListT} and \refCom{IfInResetListF} as well. \end{docCommand} \begin{docCommand}{IfInResetListT}{\oarg{}\marg{resetting counter}\marg{reset counter}\marg{true branch}} This command sequence tests whether the counter \meta{reset counter} is in the reset list of \meta{resetting counter} and expands to the true branch. See the related commands \refCom{IfInResetListTF} and \refCom{IfInResetListF} as well. \end{docCommand} \begin{docCommand}{IfInResetListF}{\oarg{}\marg{resetting counter}\marg{reset counter}\marg{false branch}} This command sequence tests whether the counter \meta{reset counter} is not in the reset list of \meta{resetting counter} and expands to the false branch. See the related commands \refCom{IfInResetListTF} and \refCom{IfInResetListT} as well. \end{docCommand} \subsection[Information macros]{Information on counters} \label{subsection::informationcmds} On occasions it might be important to have some information which counter has been changed last. Since there are four commands manipulating counter values, there are four corresponding routines for this: \begin{docCommand}{LastAddedToCounter}{} This command has no arguments and expands to the name of the counter which was used last in \cs{addtocounter}. There is no further typesetting done with the countername. \begin{dispExample} \newcounter{SomeCounter} \addtocounter{SomeCounter}{10} The last counter something added to was \LastAddedToCounter. \end{dispExample}% \end{docCommand}% \begin{marker} Please note that |LastAddedToCounter| might fail! \end{marker} \begin{docCommand}{LastSteppedCounter}{} This command has no arguments and expands to the name of the counter which was stepped last using \cs{stepcounter}. There is no further typesetting done with the countername. \begin{dispExample} \stepcounter{SomeCounter} The last counter being stepped was \LastSteppedCounter. \end{dispExample}% \end{docCommand}% \begin{docCommand}{LastRefSteppedCounter}{} \begin{dispExample} \begin{equation} E = mc^2 \label{eq::einstein} \end{equation} % \stepcounter{SomeCounter} The last counter being refstepped was \LastRefSteppedCounter. \end{dispExample}% \end{docCommand}% \begin{docCommand}{LastSetCounter}{} This command has no arguments and expands to the name of the counter which was set last using \cs{setcounter}. There is no further typesetting done with the countername. \begin{dispExample} \setcounter{SomeCounter}{21}% The last counter being set was \LastSetCounter. \end{dispExample}% \end{docCommand}% \begin{docCommand}{LastCounterValue}{} This command has no arguments and expands to the value of the very last change of a counter, i.e. using \cs{setcounter} etc. \begin{dispExample} \setcounter{SomeCounter}{100}% The last counter being set was \LastSetCounter and it had the value \LastCounterValue{} then, where as \stepcounter{equation} will yield \fbox{\LastSteppedCounter} and \LastCounterValue! \end{dispExample}% The usage of \refCom{LastSetCounter} is best together with one of the other \cs{Last...} macros. \end{docCommand}% \begin{marker} All of the \cs{Last...} macros are expandable, i.e. it is possible to store the value to an macro defined with \cs{edef} \end{marker} \begin{dispExample} \setcounter{SomeCounter}{50}% \edef\lastcounterset{\LastSetCounter} \edef\lastcountervalue{\LastCounterValue} \setcounter{equation}{81}% The last counter being set was \fbox{\LastSetCounter} and it had the value \LastCounterValue{} then, but we changed \lastcounterset{} earlier and it had the value \lastcountervalue{} then. \end{dispExample}% \setcounter{equation}{1} \begin{marker} Please note, that all of this commands are only working in the current run of compilation, i.e. \underline{after} there has been some operation on the counters. They can't be used for information on the last changed counter in a previous run. \end{marker} \section[Suspending and Resuming]{Suspending and resuming (associated) counters}\label{section::suspendedresumedcounters} Rather than removing an associated counter from the list, it is possible to suspend the automatic stepping for a while and then resume it (or completely drop it), for example, if the value of a counter should not be stepped within a specific chapter etc. \begin{docCommand}{SuspendCounters}{\oarg{options}\marg{counters list}}% \begin{docCommandArgs}{SuspendCounters}% \begin{codeoptionsenum} \item \oarg{options}% Not used so far, reserved for later usages \item \marg{counters list}% Contains the name of counters to be suspended, separated by commas (CSV - list) \end{codeoptionsenum} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{ResumeSuspendedCounters}{\oarg{options}\marg{counters list}} This command revokes the suspension of the counters in the \marg{counters} list. \end{docCommand} \begin{marker} If a driver counter is suspended, all counters associated to it are suspended too! \end{marker} \setcounter{totalequations}{0} \setcounter{equation}{0} \renewcommand{\DeclareAssociatedCounters}[3][]{\relax}% \begin{dispExample} \textbf{This example shows 4 equations, but only two of them are counted} \begin{equation} E_{0} = mc^2 \end{equation} Now suspend the equations: \SuspendCounters{equation} \begin{equation} E^2 = \left({ pc}\right)^2 + E^{2}_{0} \end{equation} \begin{equation} m(v) = \frac{m_{0}}{\sqrt{1-\frac{v^2}{c^2}}} \end{equation} And resume it: \ResumeSuspendedCounters{equation} \begin{equation} E = h \nu \end{equation} There are \number\totvalue{totalequations}~equations in here! \end{dispExample} \section{Additions to standard commands}\label{section::additions_to_l2e} \begin{docCommand}{NewDocumentCounter}{\oarg{options}\marg{counter}\oarg{resetting counter}} This command is a new interface to \cs{newcounter} and behaves effectively the same. %The first optional argument is reserved for later purposes but not used as of version \packageversion. \begin{docKey}{initial}{=\meta{integer value}}{initially 0} This is used for the start value of the new counter. \end{docKey} \end{docCommand}% \begin{docCommand}{DeclareDocumentCounter}{\oarg{options}\marg{counter}\oarg{resetting counter}} This command is the preamble-only version of \refCom{NewDocumentCounter}. \end{docCommand}% \begin{docCommand}{SetDocumentCounter}{\oarg{options}\marg{counter}\marg{counter value}} This command behaves like the standard macro \cs{setcounter}, but has an additional optional 1st argument. %which is not used as of version \packageversion. % This optional argument can be used to enable the setting of the driver counter value as well as the associated counter values at once. \begin{docCommandArgs}{SetDocumentCounter}% \begin{codeoptionsenum} \item \oarg{options}: %As of version \packageversion, this option is not used% the key value argument \begin{docKey}{associatedtoo}{=\meta{true/false}}{initially false} If enabled (\meta{true}), \refCom{SetDocumentCounter} will use the counter value for \underline{all} counters associated to this driver counter as well. Initially, this option is set to \meta{false}. \end{docKey} \begin{docKey}{onlycounters}{=\meta{comma separated list of counters}}{initially empty} If this key is used, only those associated counters are set as well that are given in the comma separated list. Names, that are either not referring to counters at all or to counters that are not associated to the given driver counter will be ignored silently. \end{docKey} \item \marg{counter} Holds the name of the (driver) counter to be set. \item \marg{counter value} Holds the value to be set \end{codeoptionsenum} \end{docCommandArgs} Some notes on \refCom{SetDocumentCounter} \begin{itemize} \item The option keys \refKey{associatedtoo} and \refKey{onlycounters} are mutually exclusive! % \item The counter to be set can be either a driver counter or an otherwise associated counter. \end{itemize} \end{docCommand}% \begin{docCommand}{StepDownCounter}{\oarg{options}\marg{counter}}\tcbdocmarginnote{\tcbdocnew{\versionzerofourdate}} This macro subtracts the value of 1 from the counter and is the counterpart of \cs{stepcounter}. \begin{docCommandArgs}{StepDownCounter}% \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, this option is not used% the key value argument \item \marg{counter} Holds the name of the first counter. \end{codeoptionsenum} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{SubtractFromCounter}{\oarg{options}\marg{counter}\marg{delta value}}\tcbdocmarginnote{\tcbdocnew{\versionzerofourdate}} This macro subtracts the (positive) delta value from the counter and is the counterpart of \cs{addtocounter} \begin{docCommandArgs}{SubtractFromCounter}% \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, this option is not used% the key value argument \item \marg{counter 1} Holds the name of the first counter. \item \marg{delta value} Holds the (positive) value to be subtracted from the counter value. \end{codeoptionsenum} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{CopyDocumentCounters}{\oarg{options}\marg{source counter}\marg{target counter}} This document copies the counter value from the source counter in argument 2 to the target counter in argument 3. \begin{docCommandArgs}{CopyDocumentCounters}% \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, this option is not used% the key value argument \item \marg{source counter} Holds the name of the source counter. \item \marg{target counter} Holds the name of the target counter. \end{codeoptionsenum} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{SwapDocumentCounters}{\oarg{options}\marg{counter 1}\marg{counter 2}} This macro swaps the values of the counters given in arguments 2 and 3 \begin{docCommandArgs}{SwapDocumentCounters}% \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, this option is not used% the key value argument \item \marg{counter 1} Holds the name of the first counter. \item \marg{counter 2} Holds the name of the second counter. \end{codeoptionsenum} \end{docCommandArgs} \end{docCommand}% \begin{docCommand}{SyncCounters}{\oarg{options}\marg{driver counter}} This document synchronizes the driver counter value to the associated values. It has the some options as \refCom{SetDocumentCounter}. If the given counter is no driver counter, nothing is done. \begin{docCommandArgs}{SyncCounters}% \begin{codeoptionsenum} \item \oarg{options}: see \refCom{SetDocumentCounter} \item \marg{source counter} Holds the name of the source counter. \end{codeoptionsenum} \end{docCommandArgs} \end{docCommand}% \begin{dispExample}{breakable=true} \SetDocumentCounter{foocntr}{17} \SetDocumentCounter{foobarcntr}{20} \begin{itemize} \item Displaying counters \thefoocntr\ and \thefoobarcntr \item Swapping counters \SwapDocumentCounters{foocntr}{foobarcntr} \thefoocntr\ and \thefoobarcntr \item Step down counters \StepDownCounter{foocntr} \StepDownCounter{foobarcntr} \thefoocntr\ and \thefoobarcntr \item Subtracting some value from the counters \SubtractFromCounter{foocntr}{5} \SubtractFromCounter{foobarcntr}{10} \thefoocntr\ and \thefoobarcntr \end{itemize} \end{dispExample} \section{Coupled counters}\label{sec::coupledcounters}\tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} \begin{marker} The features described here are very experimental and not fully implemented so far. \end{marker} Occasionally there are requests where the figure or table environment should use the same counter in the sense of using continued counter values, e.g figure 1 is followed by table 2, the next figure is numbered as 3 etc. This can be achieved with the concept of coupled counters. As usual, those counters belonging to a 'group' should be declared first in the preamble. In some sense coupled counters are similar to associated counters. \begin{docCommand}{DeclareCoupledCounters}{\oarg{options}\marg{counter name1, counter name2, \dots}}\tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, this option is not used so far. \item \marg{counter name 1, counter name2, \dots}: The list of counters that should should be stepped together. \end{codeoptionsenum} This macro is a preamble-only command. \end{docCommand} \begin{marker} \begin{itemize} \item As of version \packageversion\ only one coupled counter list is possible. \item There is no \cs{ClearCoupledCounterList} macro yet. \end{itemize} \end{marker} \begin{docCommand}{RemoveCoupledCounters}{\oarg{options}\marg{counter name1, counter name2, \dots}}\tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} This removes the listed counter names from the coupled counter list. The option is not used, the counter name list has the same meaning as in \refCom{DeclareCoupledCounters}. \end{docCommand} \begin{docCommand}{AddCoupledCounters}{\oarg{options}\marg{counter name1, counter name2, \dots}}\tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} This adds the listed counter names to coupled counter list. Please use \refCom{RemoveCoupledCounters} first, then apply \cs{AddCoupledCounters} \end{docCommand} \section{Total counters}\tcbdocmarginnote{\tcbdocnew{2015-11-27}} Similarly to the package \CHDocPackage{totcount} or the features of \CHDocPackage{totalcount} by Axel Sommerfeldt this package provides the possibility of defining a counter that stores its finally value to the auxiliary file and starts from this value then, if not set otherwise to another value. %In order to prevent namespace pollution, the counters have a different name internally, it's possible to have a counter of the name \texttt{foo} and a total counter named \texttt{foo} under the control of the total counter macros. The declaration of a total counter is a preamble - only event and \refCom{NewTotalDocumentCounter} is a preamble-only command in order to prevent counter register confusion. If a certain existing counter should be treated with total counter features, use \refCom{RegisterTotalDocumentCounter} instead. \begin{marker} \tcbdocmarginnote{\bcbombe}The standard \LaTeXe\ commands \cs{stepcounter}, \cs{addtocounter} and \cs{setcounter} support the specification of a total counter, but \cs{refstepcounter} will fail since the usage of a total counter for labelling purposes is most probably of no use (as of version \packageversion) \end{marker} \begin{docCommand}{RegisterTotalDocumentCounter}{\oarg{options}\marg{total counter name}}\tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, only this option is used \begin{docKey}{supertotal}{=\meta{true,false}}{false} Set this key to switch the super total counter on or off. \end{docKey} \item \marg{total counter name}: The name of the total counter. This must be the same like the name of an already existing counter. Internally another counter is defined which has a prefix to prevent name clashes with counter names defined by the package \CHDocPackage{totalcount}. If the counter name does not exist, the compilation exists with an error message. \end{codeoptionsenum} \end{docCommand} \begin{docCommand}{TotalCounterInternalName}{\marg{counter name}} This command reports the internal name of a total counter or the usual name if this counter is not a total one. \end{docCommand} \begin{dispExample} \TotalCounterInternalName{chapter} \TotalCounterInternalName{foototal} \end{dispExample} \stepcounter{foototal} \begin{docCommand}{TotalValue}{\marg{counter name}} This command prints the value of a total counter or falls back to the value of the counter if this is not a total counter. \begin{dispExample} ``Total'' value of the section non-total counter: \TotalValue{section} Total value of the foototal total counter: \TotalValue{foototal} \end{dispExample} \end{docCommand} \begin{docCommand}{IsTotalCounterTF}{\marg{counter name}\marg{true branch}\marg{false branch}} This macro tests if a counter is under the administration of the total counter commands and expands to the relevant branch then. There are two short-circuit commands \refCom{IsTotalCounterT} and \refCom{IsTotalCounterF}. \end{docCommand} \begin{docCommand}{IsTotalCounterT}{\marg{counter name}\marg{true branch}} This macro checks if a counter is under the administration of the total counter commands and expands to the code in the second argument if this is true. \end{docCommand} \begin{docCommand}{IsTotalCounterF}{\marg{counter name}\marg{false branch}} This macro checks if a counter is under the administration of the total counter commands and expands to the code in the second argument if this is not the case. \end{docCommand} \begin{dispExample} \IsTotalCounterTF{foototal}{Yes, this is a total counter}{No, this is no total counter} \IsTotalCounterTF{section}{Yes, this is a total counter}{No, this is no total counter} \IsTotalCounterT{foototal}{Yes, this is a total counter} \IsTotalCounterF{page}{No, page isn't a total counter} \end{dispExample} \begin{marker} The features of using other \CHDocFiles{aux} files or a different external file as provided by \CHDocPackage{totcount} is not (yet) support as of version \packageversion. \end{marker} \section{Super total counters}\label{section:supertotalcounters} \tcbdocmarginnote{\tcbdocnew{2015-11-25}} In addition to the concept of a total counter, there is also the possibility of using super total counters -- those counters survive the reset at the beginning of a compilation, i.e. the value of a super total counter might be stepped in each run and as such the number of compilation runs etc. can be tracked. The values of the last run are persistent as long as the \CHDocFileExt{.aux} file isn't deleted. \begin{docCommand}{NewTotalDocumentCounter}{\oarg{options}\marg{total counter name}} This macro defines a new counter (which mustn't exist before of course) and puts it under control of the total counter features. \begin{codeoptionsenum} \item \oarg{options}: As of version \packageversion, only this option is used \refKey{supertotal} -- this has the same meaning as in \refCom{RegisterTotalDocumentCounter} and defaults to \texttt{false}. \item \marg{total counter name}: The name of the total counter. This must not be the same like the name of any already existing counter. Internally another counter is defined which has a prefix to prevent name clashes with counter names defined by the package \CHDocPackage{totalcount}. \end{codeoptionsenum} If an already existing counter should be tracked with total counter features, use \refCom{RegisterTotalDocumentCounter} instead. \end{docCommand} \begin{docCommand}{IsSuperTotalCounterTF}{\marg{counter name}\marg{true branch}\marg{false branch}} This macro tests if a counter is under the administration of the super total counter commands and expands to the relevant branch then. There are two short-circuit commands \refCom{IsSuperTotalCounterT} and \refCom{IsSuperTotalCounterF}. \end{docCommand} \begin{docCommand}{IsSuperTotalCounterT}{\marg{counter name}\marg{true branch}} This macro checks if a counter is under the administration of the super total counter commands and expands to the code in the second argument if this is true. \end{docCommand} \begin{docCommand}{IsSuperTotalCounterF}{\marg{counter name}\marg{false branch}} This macro checks if a counter is under the administration of the super total counter commands and expands to the code in the second argument if this is not the case. \end{docCommand} \begin{dispExample} \IsSuperTotalCounterTF{numberofruns}{Yes, this is a super total counter}{No, this is no super total counter} \IsSuperTotalCounterT{numberofruns}{Yes, this is a super total counter} \IsSuperTotalCounterTF{chapter}{Yes, this is a total counter}{No, this is no super total counter} \end{dispExample} \subsection{The \CHDocCounter{numberofruns} counter}\label{subsection:numberofruns} This package adds a counter of its own: \CHDocCounter{numberofruns} which is a super total counter and is stepped each compilation run. It's added in \cs{AtBeginDocument} and can be retrieved with \refCom{TotalValue}. \section[Counter backup/restoration]{Backup and restore of counter values}\tcbdocmarginnote{\tcbdocnew{\versionzerofourdate}} It might be necessary to interrupt the current sectioning, e.g. including another document's structure (an external paper, for example) such that the counting should start again and after finishing of the external structure the old values should be restored. \subsection[Macros for backup/restoration]{Description of backup and restoring macros for counter values} \begin{docCommand}{BackupCounterValues}{\oarg{options}\marg{counter name1, counter name2,...}} This macro adds counter names (separated by a comma) to a list and stores the current values of the counters to another list. The values are used from the current state where this command is used, not a previous or a later state is stored. \begin{itemize} \item All counters in the list will be reset to zero (after storing the values) for the next usage, unless the \refKey{resetbackup} key is set to \meta{false}. \item Multiple specification of the same counter name is possible, but only the first occurence will be regarded -- consecutive occurences of the same counter name are not taken into account. \tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} \end{itemize} \begin{docKey}[][]{resetbackup}{=\meta{true/false}}{initially true} This key decides whether \textbf{all} counters in the backup list should be reset to zero or should keep the current value. The default value is \meta{true}. \end{docKey} Please note: If a name does not belong to a counter register the compilation aborts with an error message! Some remarks \begin{marker} If a specific counter name is suffixed with an \textasteriskcentered\ at its end the resetting is disabled for this particular counter, regardless whether \refKey{resetbackup} is set to true or not.\tcbdocmarginnote{\tcbdocnew{\versionzerofourdate}} \end{marker} \begin{marker} Strangely enough, a counter name like \CHDocCounter{foo*} is possible, but \cs{thefoo*} would fail. Be careful about choosing counter names for new counters -- just restrict yourself to the usual letters (and if really needed, using \makeatletter @\makeatother) \end{marker} \end{docCommand}% \begin{docCommand}{RestoreAllCounterValues}{\oarg{options}} \tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} This macro restores all stored counter values corresponding to the counter names. As of version \packageversion\ the optional argument isn't used and reserved for later purposes. The backup list is cleared after the restoring has been finished. \end{docCommand} \begin{marker} The \refCom{RestoreAllCounterValues} was previously called \refCom{RestoreCounterValues} -- that macro is now reserved for updating only particular counters, not all in a row. \end{marker} \begin{docCommand}{RestoreCounterValues}{\oarg{options}\marg{counter name1,counter name2,...}} \tcbdocmarginnote{\tcbdocupdated{\versionzerofivedate}} This macro restores only the stored counter values given by the counter names. As of version \packageversion\ the optional argument isn't used and reserved for later purposes. %The backup list is cleared after the restoring has been finished. \end{docCommand} \begin{dispExample} \captionof{figure}{A dummy figure} \captionof{table}{A dummy table} \BackupCounterValues{figure,table*} \captionof{figure}{Another dummy figure} \captionof{table}{Another dummy table} \captionof{figure}{Even another dummy figure} \captionof{table}{Even another dummy table} Before restoring: \thefigure\ and \thetable \RestoreAllCounterValues Restored the values: \thefigure\ and \thetable \captionof{figure}{Yet another dummy figure} \captionof{table}{Yet another dummy table} \end{dispExample} \begin{docCommand}{AddBackupCounter}{\oarg{options}\marg{counter name1,counter name2,...}} \tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} This is similar to \refCom{BackupCounterValues}, but adds the counter names to an existing global list and can be applied after \refCom{BackupCounterValues}. \end{docCommand} \begin{docCommand}{RemoveBackupCounters}{\oarg{options}\marg{counter name1, counter name2,...}} \tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} This macro removes the counters from the list of backup counters and immediately restores the counter value unless the starred version \refCom{RemoveBackupCounters*} is used. If the package \CHDocPackage{hyperref} is used, the macro \cs{theH...} (see \nameref{subsec::backup_and_hyperref} on this) is restored to the original meaning. As of version \packageversion\ the optional argument isn't used and reserved for later purposes. \end{docCommand} \begin{docCommand}{RemoveBackupCounters*}{\oarg{options}\marg{counter name}} \tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} This command is basically similar to \refCom{RemoveBackupCounters}, but does not restore the counter value right at the place the macro is used. As of version \packageversion\ the optional argument isn't used and reserved for later purposes. \end{docCommand} \subsection{Some notes on the backup features} \label{subsec::backup_and_hyperref} Principally backing up counter values and restoring them later on is not really difficult -- with one exception: If the \packagename{hyperref} package is used, the counter values form up the hypertarget anchors, for example \texttt{chapter.1} for the first chapter. If the chapter counter is reset, there would be a chapter with number one again and as well an anchor name \texttt{chapter.1} -- \packagename{hyperref} will complain 'only' about this but it will put the wrong hyperlink as well, for example for the table of contents and the bookmarks -- this is an undesirable feature. However, there is a solution to this problem: The hypertarget anchors are built up from the specifications of a macro \cs{theH...} where the ellipses stands for the counter name. If for example \cs{theHchapter} is changed after a counter was reset the hypertargets will again be correct, since this will provide a different target name. \cs{BackupCounterValues} does this resetting automatically in an unique way and \cs{RestoreCounterValues} restores as well the old \cs{theH...} macros of all counters that are in the backup list. It tracks the number of calls to \cs{BackupCounterValues} and changes the relevant \cs{theH...} macro definitions to use unique anchor names then -- this way multiple \cs{BackupCounterValues} calls are possible without destroying the hyperlink facicilities with \packagename{hyperref}. \clearpage \section{To - Do list} \begin{itemize} \item Better counter definition/copy counter routines \(\longrightarrow\) another package perhaps \item More examples \item Some macro names might be non-intuitive \item Improve documentation \item Hooks for conditionals on \CHDocCounter*{numberofruns} (see \cref{subsection:numberofruns}) %\item Allow for specific counter to be resumed from suspension instead of resuming all %\item Allow for an associated counter to have multiple masters %\item Complete redesign and rewrite with \CHDocPackage{expl3} -- this will provide better list features \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 using my mail address: \mymailtoaddress. \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 to \begin{itemize} \item Paulo Roberto Massa Cereda \item Enrico Gregorio \item Joseph Wright \item David Carlisle \item Werner \item Gonzalo Medina \item Cosmo Huber (for providing the bug report with the \CHDocPackage{calc} package.) \end{itemize} for their invaluable help on many questions on macros. \vspace{2\baselineskip} \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} \clearpage \section{Version history} \begin{itemize} \item Version 0.5 \begin{itemize}[label={$\checkmark$}] \item Added support (very experimental!) for coupled counters, see \cref{sec::coupledcounters} about this feature! \tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} \item Added \cs{RegisterTotalDocumentCounter} and improved \cs{TotalValue} support\tcbdocmarginnote{\tcbdocnew{\versionzerofivedate}} \end{itemize} \item Version 0.4 \begin{itemize}[label={$\checkmark$}] \item Added \cs{BackupCounterValues} and \cs{RestoreCounterValues} support\tcbdocmarginnote{\tcbdocnew{\versionzerofourdate}} \item Added \cs{StepDownCounter} and \cs{SubtractFromCounter} macros\tcbdocmarginnote{\tcbdocnew{\versionzerofourdate}} \end{itemize} \item Version 0.3 \begin{itemize}[label={$\checkmark$}] \item Added the \CHDocTag{totalcounter} features similar to the packages \CHDocPackage{totcount} or \CHDocPackage{totalcount} \tcbdocmarginnote{\tcbdocnew{2015-11-11}} \item Added the \CHDocTag{super total counter} features\tcbdocmarginnote{\tcbdocnew{2015-25-11}} \item Added the \CHDocCounter*{numberofruns} counter \tcbdocmarginnote{\tcbdocnew{2015-25-11}} \end{itemize} \item Version 0.2 Improved \cs{stepcounter} to remove some incompatibilities with the \CHDocPackage{perpage}. This is only partially managed so far. \item Version: 0.1 A major bug fixed due to some error in usage together with \CHDocPackage{calc} when the driven counters are not stepped any longer. The culprit was in \CHDocPackage{assoccnt} that the counter reset list was not really disabled. Thanks to this question \url{http://tex.stackexchange.com/questions/269731/calc-breaks-assoccnt} this bug was detected. This however lead to some internal inconsistencies and it was decided to rewrite \CHDocPackage{assoccnt} with \CHDocPackage{expl3} and the features of the new \LaTeX\ 3 - Syntax. \end{itemize} \clearpage \phantomsection \appendix\label{examplesappendix} Note: The \cs{DeclareAssociatedCounters} command have to be used in the preamble of the document. It's missing here for the sake of a compact example. \section[Total number of sections]{Example: Total number of sections} In this example, all sections of this document are counted, i.e. the current one as well as all following ones. \begin{dispExample} This document has \total{totalsections} section(s)% \end{dispExample} \section[Subsection with suspension]{Example: Total number of subsections with suspension} In this example, the subsections of this document are counted but later on, the associatedcounter is removed from the list, so it is frozen. \begin{dispExample} \subsection{First dummy subsection} SubSection counter: \thesubsection~-- \number\totvalue{totalsubsections} \subsection{Second dummy subsection} SubSection counter: \thesubsection~-- \number\totvalue{totalsubsections} \RemoveAssociatedCounter{subsection}{totalsubsections}% \subsection{Third dummy subsection after removing the associated counter} SubSection counter: \thesubsection~-- \number\totvalue{totalsubsections} \end{dispExample} \subsection{Suspension of a non-associated counter} This example will show the suspension of a non-associated counter \begin{dispExample} \setcounter{equation}{0}% \SuspendCounters{equation}% \begin{equation} E_{0} = mc^2 \end{equation} \begin{equation} E^2 = \left({ pc}\right)^2 + E^{2}_{0} \end{equation} \begin{equation} m(v) = \frac{m_{0}}{\sqrt{1-\frac{v^2}{c^2}}} \end{equation} There are \number\value{equation}~equations in here! \end{dispExample} \clearpage \markboth{\indexname}{\indexname} %%%% Index of commands etc. \printindex \end{document}