From 23550e4b6a7407977d39f6339f6f9fe2db2ba99e Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 4 Sep 2014 21:10:23 +0000 Subject: assoccnt (4sep14) git-svn-id: svn://tug.org/texlive/trunk@35106 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/assoccnt/assoccnt.sty | 274 ++++++++++++++++++---- 1 file changed, 234 insertions(+), 40 deletions(-) (limited to 'Master/texmf-dist/tex/latex/assoccnt') diff --git a/Master/texmf-dist/tex/latex/assoccnt/assoccnt.sty b/Master/texmf-dist/tex/latex/assoccnt/assoccnt.sty index 08697e37332..1a08056afd3 100644 --- a/Master/texmf-dist/tex/latex/assoccnt/assoccnt.sty +++ b/Master/texmf-dist/tex/latex/assoccnt/assoccnt.sty @@ -1,26 +1,52 @@ \NeedsTeXFormat{LaTeX2e}% -\ProvidesPackage{assoccnt}[2014/08/21 v0.3 -- Associate counters stepping]% +\ProvidesPackage{assoccnt}[2014/09/01 v0.4 -- Associate counters stepping]% %%% %% License: LaTeX Project Public License %% Copyright (2014) Dr. Christian Hupfer -%% Author: Christian Hupfer christian.hupfer@siebenfelsen.de +%% Author: Christian Hupfer christian.hupfer@yahoo.de %% %%%% %%% Some options later on %%%% +\def\@@assoccnt@@keys{assoccntkeyfamily}% + +\def\@@assoccnt@@packagename{assoccnt.sty}% +\def\@@assoccnt@@keyprefix{@@assoccnt@@pkg@@}% + \RequirePackage{etoolbox}[2011/01/03 2.2]% \RequirePackage{xkeyval}[2012/10/14 v2.6b]% +\RequirePackage{xstring}% + +%%%% Defining package options + +\newtoggle{GlobalSuspend}% +\settoggle{GlobalSuspend}{false}% + + +% Option for enabling the global suspend facility for an arbitray counters +\define@boolkey{\@@assoccnt@@packagename}[@@assoccnt@@pkg@@]{globalsuspend}[false]{% + \if@@assoccnt@@pkg@@globalsuspend% + \toggletrue{GlobalSuspend}% + \else% + \togglefalse{GlobalSuspend}% + \fi% +}% +\DeclareOptionX*{\PackageWarning{\@@assoccnt@@packagename}{Option '\CurrentOption ' ignored}}% -\def\@@assoccnt@@keys{@@assoccnt@@keyfamily}% +\ProcessOptionsX% + +%%%%% \newcounter{@@assoccnt@@internalcounter}% \let\@@assoccnt@@standardstepcounter\stepcounter% \let\@@assoccnt@@standardrefstepcounter\refstepcounter% +\let\@@assoccnt@@standardsetcounter\setcounter% +\let\@@assoccnt@@standardaddtocounter\addtocounter% % Just for a quick suffix @@ -85,22 +111,21 @@ AssociatedCountersList% \newcommand{\@@assoccnt@@addassociatedcounter}[3][]{% - \ifcsdef{\@@assoccnt@@generateboundtocounterslist{#3}}{% - % The counter is already to some other counter, it should not be multiply associated! - }{% - \csgdef{\@@assoccnt@@generateboundtocounterslist{#3}}{}% - \listcsgadd{\@@assoccnt@@generateboundtocounterslist{#3}}{#1} - \ifcsdef{#2}{% - \ifinlistcs{#3}{#2}{% - % Do nothing, since counter is already in the list, prevent multiple list insertion - }{% - \listcsgadd{#2}{#3}% - }% + \ifcsdef{#2}{% + % driver counter list exists, check, whether it is already there + \ifinlistcs{#3}{#2}{% + % Do nothing, since counter is already in the list, prevent multiple list insertion }{% - % Nothing in here + \listcsgadd{#2}{#3}% + \listcsgadd{\@@assoccnt@@generateboundtocounterslist{#3}}{#1} }% + }{% + \listcsgadd{\@@assoccnt@@generatelistname{#1}}{#3}% + \listcsgadd{\@@assoccnt@@generateboundtocounterslist{#3}}{#1}% }% -}% +}% + + @@ -108,7 +133,7 @@ AssociatedCountersList% % #1 --> options % #2 --> driver counter % #3 --> CSV list of counters, that should be stepped, if the driver counter is stepped -\setkeys{\@@assoccnt@@keys}{#1}% + \setkeys{\@@assoccnt@@keys}{#1}% \ifcsdef{\@@assoccnt@@generatelistname{#2}}{% % % Nothing to be done --> List already exists \forcsvlist{\@@assoccnt@@addassociatedcounter[#2]{\@@assoccnt@@generatelistname{#2}}}{#3}% @@ -126,13 +151,13 @@ AssociatedCountersList% % #1 --> options % #2 --> driver counter % #3 --> CSV list of other counters, that should be stepped, if the driver counter is stepped -\setkeys{\@@assoccnt@@keys}{#1}% + \setkeys{\@@assoccnt@@keys}{#1}% \ifcsdef{\@@assoccnt@@generatelistname{#2}}{% % % Nothing to be done --> List already exists \GenericWarning{}{Warning: List of associated counters for driver counter #2 already exists}% }{% \AddDriverCounter{#2}% - \csgdef{\@@assoccnt@@generatelistname{#2}}{}% Define some global list + \listcsgadd{\@@assoccnt@@generatelistname{#2}}{}% Define some global list }% % Now add the counter names from #3 to the list % Note: Currently, it is not checked whether a counter is already added! @@ -141,6 +166,7 @@ AssociatedCountersList% \RemoveAssociatedCounter{#2}{#2}% }% +% Later on %\@onlypreamble{\DeclareAssociatedCounters}% @@ -148,22 +174,45 @@ AssociatedCountersList% + +\newcommand{\@@assoccnt@@copylist}[2]{% + \ifstrequal{#1}{#2}{% + % Nothing to be done + }{% + \csundef{#2}% + \renewcommand*{\do}[1]{% + \listcsgadd{#2}{##1}% + }% + \dolistcsloop{#1}% + }% +}% + + + %%% A generic macro, that removes a list entry from the list by %%% defining a temporary list and omitting the \newcommand{\@@assoccnt@@removefromlist}[2]{% % #1 list name % #2 element to be removed \ifcsdef{#1}{% - \gdef\@@assoccnt@@mytemplist{}% + \ifcsdef{@@assoccnt@@templist}{% + \csundef{@@assoccnt@@templist}% + }{}% + \listcsgadd{@@assoccnt@@templist}{}% + \@@assoccnt@@standardsetcounter{@@assoccnt@@internalcounter}{0}% \renewcommand*{\do}[1]{% - \ifstrequal{##1}{#2}{ + \ifstrequal{##1}{#2}{% % Later one some success routine etc. ??? }{% - \listgadd{\@@assoccnt@@mytemplist}{##1}% + \listcsgadd{@@assoccnt@@templist}{##1}% + \@@assoccnt@@standardstepcounter{@@assoccnt@@internalcounter}% }% }% \dolistcsloop{#1}% - \csxdef{#1}{\@@assoccnt@@mytemplist}% + \csundef{#1}% + \ifnumgreater{\number\value{@@assoccnt@@internalcounter}}{0}{% + \@@assoccnt@@copylist{@@assoccnt@@templist}{#1}% + }{}% }{% % The list is not defined at all, can't remove something from something not existing... }% @@ -176,6 +225,7 @@ AssociatedCountersList% % #1 arg: driver counter % #2 arg: counter name to be removed \@@assoccnt@@removefromlist{\@@assoccnt@@generatelistname{#1}}{#2}% + \@@assoccnt@@removefromlist{\@@assoccnt@@generateboundtocounterslist{#1}}{#2}% }% %% Remove a CSV list of counters from the list of associated counters @@ -230,6 +280,61 @@ AssociatedCountersList% }% +\newcommand{\@@assoccnt@@itemizedshowassociatedcounters}[1]{% + \begin{itemize} + \renewcommand*{\do}[1]{% + \item \@@assoccnt@@showassociatedcounterlist{##1} -- \fbox{\number\value{##1}}% + }% + \dolistcsloop{\@@assoccnt@@generatelistname{#1}}% + \end{itemize}% +}% + +\newcommand{\GeneralCounterInfoColor}{orange} +\newcommand{\DriverCounterInfoColor}{blue} +\newcommand{\AssociatedCounterInfoColor}{red} + +\define@key{\@@assoccnt@@keys}{countertype}[driver]{% + \def\@@assoccnt@@keymacro@@countertype{#1}% +}% + + +\newcommand{\PrettyPrintCounterName}[2][countertype={general}]{% + \setkeys{\@@assoccnt@@keys}{#1}% + \IfStrEq{\@@assoccnt@@keymacro@@countertype}{driver}{% + \fbox{\textcolor{\DriverCounterInfoColor}{\textbf{#2{}}}}% + }{% + \IfStrEq{\@@assoccnt@@keymacro@@countertype}{associated}{% + \fbox{\textcolor{\AssociatedCounterInfoColor}{\textbf{#2{}}}}% + }{% + \fbox{\textcolor{\GeneralCounterInfoColor}{\textbf{#2}}}% + }% + }% +}% + + +\newcommand{\AssociatedDriverCounterInfo}[1]{% + \textbf{Associated/Driver counter information on counter \PrettyPrintCounterName[countertype=general]{#1}}\par + \IsAssociatedCounter{#1}{% + Counter \PrettyPrintCounterName[countertype=associated]{#1} is associated to \PrettyPrintCounterName[countertype=driver]{\GetDriverCounter{#1}}% + \IsDriverCounter{#1}{% + Counter \PrettyPrintCounterName[countertype=driver]{#1} is driver counter of + \@@assoccnt@@itemizedshowassociatedcounters{#1}% + % + }{}% + }{% + \IsDriverCounter{#1}{% + Counter \PrettyPrintCounterName[countertype=driver]{#1} is driver counter of + \@@assoccnt@@itemizedshowassociatedcounters{#1}% + }{% + Counter \PrettyPrintCounterName[countertype=general]{#1} is neither driver nor associated counter % + }% + }% +}% + + + + + \newcommand{\GetDriverCounter}[1]{% \setcounter{@@assoccnt@@internalcounter}{0}% \renewcommand*{\do}[1]{% @@ -243,7 +348,7 @@ AssociatedCountersList% }% \newcommand{\@@assoccnt@@showassociatedcounterlist}[1]{% - \textcolor{red}{\textbf{#1{ }}}% + \PrettyPrintCounterName[countertype=associated]{\textbf{#1{ }}}% }% \newcommand{\@@assoccnt@@showdrivercounterlist}[1]{% @@ -259,6 +364,35 @@ AssociatedCountersList% }% +\define@key{\@@assoccnt@@keys}{SuspendCounters}{% + \def\@@assoccnt@@keymacro@@suspendedcounters{#1}% + \forcsvlist{\listgadd{\@@assoccnt@@suspendedcounterslist}}{#1}% +}% + + +% A convenience macro -- do not change% +\newcommand{\@@assoccnt@@wrapperaddsuspendedcounter}[1]{% + \listcsgadd{@@assoccnt@@suspendedcounterslist}{#1}% +}% + + +\newcommand{\SuspendCounters}[2][]{% + \forcsvlist{\@@assoccnt@@wrapperaddsuspendedcounter}{#2}% +}% + +%% Not much in here +\newcommand{\ResumeSuspendedCounters}{% + \undef{\@@assoccnt@@suspendedcounterslist}% +}% + + +\newcommand{\IsSuspendedCounter}[3]{% + \ifinlistcs{#1}{@@assoccnt@@suspendedcounterslist}{% + #2% + }{% + #3% + }% +}% %%% The stepcounter wrapper for the standard stepcounter command %%% This is just for convenience, if the command as to be improved/extended later on in future @@ -266,36 +400,96 @@ AssociatedCountersList% \@@assoccnt@@standardstepcounter{#1}% }% +%%% The setcounter wrapper +\newcommand{\@@assocccnt@@setcounter}[2]{% + \@@assoccnt@@standardsetcounter{#1}{#2}% +}% + +%%% addtocounter wrapper -- needs to switch the arguments for the command for the list usage!!! +\newcommand{\@@assoccnt@@addtocounter}[2]{% + \ifcsdef{@@assoccnt@@suspendedcounterslist}{% + % Now, there are suspended counters -- do not update them! + \IsSuspendedCounter{#2}{% + % Nothing to be done + }{% + \@@assoccnt@@standardaddtocounter{#2}{#1}% + }% + }{% + \@@assoccnt@@standardaddtocounter{#2}{#1}% + }% +}% + +%%% addtocounter wrapper -- needs to switch the arguments for the command for the list usage!!! +\newcommand{\@@assoccnt@@setcounter}[3]{% + \IsAssociatedToCounter{#1}{#3}{% + \@@assoccnt@@standardsetcounter{#3}{#2}% + }{% + \GenericWarning{}{Warning: Counter "#3" is not part of the associated list counters to driver counter "#1"}% + }% +}% + + + %%% Not needed so far -\newcommand{\@@assoccnt@refstepcounter}[1]{% +\newcommand{\@@assoccnt@@refstepcounter}[1]{% \@@assoccnt@@standardrefstepcounter{#1}% }% -%%%% Redefinition of the \stepcounter command -\renewcommand{\stepcounter}[1]{% - \@@assoccnt@@standardstepcounter{#1}% Traditional behaviour, since this is expected! + + +\renewcommand{\addtocounter}[2]{% + \iftoggle{GlobalSuspend}{% + \IsSuspendedCounter{#1}{% + % No, do nothing at all% + }{% + \@@assoccnt@@standardaddtocounter{#1}{#2}% + } + }{% + \@@assoccnt@@standardaddtocounter{#1}{#2}% + }% \ifcsdef{\@@assoccnt@@generatelistname{#1}}{% Check first, whether the list exists at all, - \forlistcsloop{\@@assoccnt@@stepcounter}{\@@assoccnt@@generatelistname{#1}}% March through the list + \forlistcsloop{\@@assoccnt@@addtocounter{#2}}{\@@assoccnt@@generatelistname{#1}}% March through the list }{% - %No list -> do nothing at all + % No list -> do nothing at all }% }% +\listgadd{\@@assoccnt@@tempcounterlist}{}% This should be renamed later one... treated more generally +\newcommand{\@@assoccnt@@setcounterwrapper}[3]{% + \ifcsdef{\@@assoccnt@@generatelistname{#1}}{% Check first, whether the per driver list exists at all, + \forlistcsloop{\@@assoccnt@@setcounter{#1}{#2}}{#3}% + }{}% +}% +\define@boolkey{\@@assoccnt@@keys}{AssociatedToo}[false]{% +}% -%%%% Redefinition of the \stepcounter command -\renewcommand{\refstepcounter}[1]{% - \@@assoccnt@@standardstepcounter{#1}% Traditional behaviour, since this is expected! - \protected@edef\@currentlabel% - {\csname p@#1\endcsname\csname the#1\endcsname}% - \ifcsdef{\@@assoccnt@@generatelistname{#1}}{% Check first, whether the list exists at all, - \forlistcsloop{\@@assoccnt@@stepcounter}{\@@assoccnt@@generatelistname{#1}}% March through the list - }{% - %No list -> do nothing at all - }% + + +\define@key{\@@assoccnt@@keys}{AssociatedCounters}{% + \undef{\@@assoccnt@@tempcounterlist}% + \def\@@assoccnt@@keymacro@@associatedcounters{#1}% + \forcsvlist{\listgadd{\@@assoccnt@@tempcounterlist}}{#1}% }% +%% Redefined \setcounter -- with additional optional key% + +\renewcommand{\setcounter}[3][]{% + \@@assoccnt@@standardsetcounter{#2}{#3}% + \setkeys{\@@assoccnt@@keys}{AssociatedToo=false,#1}% + \ifKV@assoccntkeyfamily@AssociatedToo + \@@assoccnt@@setcounterwrapper{#2}{#3}{\@@assoccnt@@generatelistname{#2}}% + \else% + \ifdef{\@@assoccnt@@keymacro@@associatedcounters}{% + \@@assoccnt@@setcounterwrapper{#2}{#3}{@@assoccnt@@tempcounterlist}% + \undef{\@@assoccnt@@tempcounterlist}% Clear the counter list + \listgadd{\@@assoccnt@@tempcounterlist}{}% Redefine the list for future use% + \undef{\@@assoccnt@@keymacro@@associatedcounters}% + }{}% + \fi% +}% + \endinput% \ No newline at end of file -- cgit v1.2.3