diff options
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty | 608 |
1 files changed, 542 insertions, 66 deletions
diff --git a/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty b/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty index 7a475a6745c..1e0137d168e 100644 --- a/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty +++ b/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty @@ -1,4 +1,4 @@ -%% LaTeX package xassoccnt - version 0.4 (2016/01/26 -- 10/46/26) +%% LaTeX package xassoccnt - version 0.5 (2016/02/27 -- 19/52/22) %% Source file for xassoccnt.sty %% %% @@ -19,20 +19,15 @@ %% %% -\def\xassoccntpackageversion{0.4} +\def\xassoccntpackageversion{0.5} \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{xassoccnt}[2016/01/26 - v\xassoccntpackageversion] +\ProvidesPackage{xassoccnt}[2016/02/27 - v\xassoccntpackageversion] \RequirePackage{xcolor} \RequirePackage{xparse} \RequirePackage{l3keys2e} - - - - - \ExplSyntaxOn % First some local or global values @@ -70,7 +65,12 @@ \int_new:N \l__xassoccnt_backuptmpa_int \seq_new:N \l__xassoccnt_counternamesbackup_seq \seq_new:N \l__xassoccnt_countervaluesbackup_seq -\bool_new:N \l__xassoccnt_counternamestarred_bool +\seq_new:N \l__xassoccnt_backupresetlist_seq +\bool_new:N \l__xassoccnt_counternamestarred_bool % Not needed actually + +\seq_new:N \g__xassoccnt_counternamesbackuplist_seq + + \cs_new:Nn \__xassoccnt_toggle_bool:n {% @@ -191,6 +191,12 @@ } +\msg_new:nnn{xassoccnt}{backupcollectionundefined}{% + Error:~Backup~collection~#1~not~defined\\ + Use~\DeclareBackupCollection~to~define~the~collection +} + + \msg_new:nnn{xassoccnt}{incompatiblepackagenonfatal}{% Warning:~Package~"#1"~is~loaded~--~this~is~not~recommended~for~\c__xassoccnt_modulename_str\\ } @@ -201,8 +207,11 @@ } +\msg_new:nnn{xassoccnt}{containeralreadyexists}{% + Error:~Container~named~#1~already~exists\\ +} + -%\cs_new:Nn \__xassoccnt_stpelt:n{\global\csname c@#1\endcsname\c_minus_one\xassoccnt_addtocounter{#1}{\c_one}}% \cs_new:Nn \__xassoccnt_intinc:n {\int_gincr:N \l_xassoccnt_resetlist_counter}% @@ -610,7 +619,7 @@ \seq_clear:N \l_tmpa_seq \seq_map_inline:cn {\__xassoccnt_mastercontainer:}{% \seq_if_in:cnT{\__xassoccnt_drivercontainer:n{##1}}{#2}{% - \seq_put_right:Nn \l_tmpa_seq{##1} + \seq_put_right:Nn \l_tmpa_seq {##1} }% }% \seq_if_empty:NTF \l_tmpa_seq{--}{\seq_use:Nn \l_tmpa_seq {#1}} @@ -744,40 +753,357 @@ \cs_new_nopar:Nn \__xassoccnt_translate_countername:cn {% \tl_set:cn {#1}{#2}% - \seq_if_in:NxT \g__xassoccnt_supertotalcounter_container {#2} {% + \seq_if_in:NxTF \g__xassoccnt_supertotalcounter_container {#2} {% \tl_set:cn {#1}{\__xassoccnt_expand_totalcountername:n {#2} }% + }{% + } +} + + +%%% + + +%% More generic macros (hidding the internal features of the lists) + + +\cs_new:Nn \xassoccnt_container_datatype: {seq} + + +\cs_new:Nn \__xassoccnt_construct_cs:n {% + \use:c{\xassoccnt_container_datatype:#1} +} + + + + +\cs_new:Nn \xassoccnt_container_new:N {% + \__xassoccnt_construct_cs:n{_new:N} #1 +} + + +\cs_new:Nn \xassoccnt_container_clear:N {% + \__xassoccnt_construct_cs:n{_clear:N} #1 +} + +\cs_new:Nn \xassoccnt_container_gclear:N {% + \__xassoccnt_construct_cs:n{_gclear:N} #1 +} + + + +\cs_new:Nn \xassoccnt_container_set_eq:NN {% + \__xassoccnt_construct_cs:n{_set_eq:NN} #1 #2 +} + + +\cs_new:Nn \xassoccnt_container_gset_eq:NN {% + \__xassoccnt_construct_cs:n{_gset_eq:NN} #1 #2 +} + + +\cs_new:Nn \xassoccnt_container_put_right:Nn {% + \__xassoccnt_construct_cs:n{_put_right:Nn} #1 {#2} +} + +\cs_new:Nn \xassoccnt_container_gput_right:Nn {% + \__xassoccnt_construct_cs:n{_gput_right:Nn} #1 {#2} +} + +\cs_new:Nn \xassoccnt_container_put_left:Nn {% + \__xassoccnt_construct_cs:n{_put_left:Nn} #1 {#2} +} + +\cs_new:Nn \xassoccnt_container_gput_left:Nn {% + \__xassoccnt_construct_cs:n{_gput_left:Nn} #1 {#2} +} + + +\cs_new:Nn \xassoccnt_container_get_item:Nn {% + \__xassoccnt_construct_cs:n{_get_item:Nn} #1 {#2} +} + +\cs_new:Nn \xassoccnt_container_remove_duplicates:N {% + \__xassoccnt_construct_cs:n{_remove_duplicates:N} #1 +} + +\cs_new:Nn \xassoccnt_container_gremove_duplicates:N {% + \__xassoccnt_construct_cs:n{_gremove_duplicates:N} #1 +} + +\cs_new:Nn \xassoccnt_container_remove_all:Nn {% + \__xassoccnt_construct_cs:n{_remove_all:Nn} #1 {#2} +} + +\cs_new:Nn \xassoccnt_container_gremove_all:Nn {% + \__xassoccnt_construct_cs:n{_gremove_all:Nn} #1 {#2} +} + +\cs_new:Nn \xassoccnt_container_map_inline:Nn {% + \__xassoccnt_construct_cs:n{_map_inline:Nn} #1 {#2} +} + +\cs_new:Nn \xassoccnt_container_count:N {% + \__xassoccnt_construct_cs:n{_count:N} #1 +} + +\cs_new:Nn \xassoccnt_container_set_from_clist:NN {% + \__xassoccnt_construct_cs:n{_set_from_clist:NN} #1 #2 +} + +\cs_new:Nn \xassoccnt_container_gset_from_clist:NN {% + \__xassoccnt_construct_cs:n{_gset_from_clist:NN} #1 #2 +} + +\cs_new:Nn \xassoccnt_container_remove_by_clist:Nn {% + \clist_set:Nn \l_tmpa_tl {#2} + \clist_map_inline:Nn \l_tmpa_tl { + \xassoccnt_container_remove_all:Nn #1 {##1} + } +} + + +\cs_new:Nn \xassoccnt_container_use:Nn {% + \__xassoccnt_construct_cs:n{_use:Nn} #1 {#2} +} + + + +\prg_new_conditional:Nnn \xassoccnt_container_if_exist:N {TF,T,F}% +{ + \__xassoccnt_construct_cs:n{_if_exist:NTF} #1 + {\prg_return_true:} + {\prg_return_false:} +} + + +\prg_new_conditional:Nnn \xassoccnt_container_if_in:Nn {TF,T,F}% +{ + % \seq_if_in:NnTF #1 {#2} + \__xassoccnt_construct_cs:n{_if_in:NnTF} #1 {#2} + {\prg_return_true:} + {\prg_return_false:} +} + +\prg_new_conditional:Nnn \xassoccnt_container_if_empty:N {TF,T,F}% +{ + \__xassoccnt_construct_cs:n{_if_empty:NTF} + {\prg_return_true:} + {\prg_return_false:} +} + + +\prg_new_conditional:Nnn \xassoccnt_container_if_empty:c {T,F,TF} +{ + \__xassoccnt_construct_cs:n{_if_empty:cTF} + {\prg_return_true:} + {\prg_return_false:} +} + + + + +\cs_generate_variant:Nn \xassoccnt_container_new:N {c} +\cs_generate_variant:Nn \xassoccnt_container_clear:N {c} +\cs_generate_variant:Nn \xassoccnt_container_gclear:N {c} +\cs_generate_variant:Nn \xassoccnt_container_set_eq:NN {cN,Nc,cc} +\cs_generate_variant:Nn \xassoccnt_container_gset_eq:NN {cN,Nc,cc} + +\cs_generate_variant:Nn \xassoccnt_container_put_right:Nn {NV,Nv,No,Nx,cn,cV,cv,co,cx} +\cs_generate_variant:Nn \xassoccnt_container_gput_right:Nn {NV,Nv,No,Nx,cn,cV,cv,co,cx} +\cs_generate_variant:Nn \xassoccnt_container_put_left:Nn {NV,Nv,No,Nx,cn,cV,cv,co,cx} +\cs_generate_variant:Nn \xassoccnt_container_gput_left:Nn {NV,Nv,No,Nx,cn,cV,cv,co,cx} + +\cs_generate_variant:Nn \xassoccnt_container_get_item:Nn {cn} + +\cs_generate_variant:Nn \xassoccnt_container_remove_duplicates:N {c} +\cs_generate_variant:Nn \xassoccnt_container_gremove_duplicates:N {c} + +\cs_generate_variant:Nn \xassoccnt_container_remove_all:Nn {cn} +\cs_generate_variant:Nn \xassoccnt_container_gremove_all:Nn {cn} + +\cs_generate_variant:Nn \xassoccnt_container_remove_by_clist:Nn {cn,nn} + +\cs_generate_variant:Nn \xassoccnt_container_map_inline:Nn {cn} + +\cs_generate_variant:Nn \xassoccnt_container_count:N {c} + +\cs_generate_variant:Nn \xassoccnt_container_set_from_clist:NN {cN,cc,Nc,Nn,cn} +\cs_generate_variant:Nn \xassoccnt_container_gset_from_clist:NN {cN,cc,Nc,Nn,cn} + +\cs_generate_variant:Nn \xassoccnt_container_use:Nn {cn} + + +\cs_generate_variant:Nn \xassoccnt_container_if_in:NnTF {NVTF,NvTF,NoTF,NxTF,cnTF,cVTF,cvTF,coTF,cxTF} +\cs_generate_variant:Nn \xassoccnt_container_if_in:NnT {NVT,NvT,NoT,NxT,cnT,cVT,cvT,coT,cxT} +\cs_generate_variant:Nn \xassoccnt_container_if_in:NnF {NVF,NvF,NoF,NxF,cnF,cVF,cvF,coF,cxF} + +\cs_generate_variant:Nn \xassoccnt_container_if_exist:NTF {cTF} +\cs_generate_variant:Nn \xassoccnt_container_if_exist:NT {cT} +\cs_generate_variant:Nn \xassoccnt_container_if_exist:NF {cF} + +\bool_new:N \l__xassoccnt_feature_bool +\bool_new:N \l__xassoccnt_sublists_bool + +\keys_define:nn {xassoccnt_container} { + feature .bool_set:N=\l__xassoccnt_feature_bool, + sublists .bool_set:N=\l__xassoccnt_sublists_bool +} + +\seq_new:N \g__xassoccnt_feature_seq % The master control !!!! + +\seq_new:N \g__xassoccnt_sublists_seq + +\cs_new:Nn \xassoccnt_create_featurename:n { xassoccnt_feature#1 } + +\cs_new:Nn \xassoccnt_featurename:n { xassoccnt_feature#1 } + + +%% A feature is actually a super container that has sub containers (i.e. a list/seq of counters that have this feature + +%% Multiple counters may occur in the per - feature - specific container list + +\cs_new:Nn \xassoccnt_add_feature:nn {% + \keys_set:nn {xassoccnt_container} {#1} + \seq_if_exist:NT \g__xassoccnt_feature_seq {% Unique addition of a feature only! + \seq_if_in:NnF \g__xassoccnt_feature_seq {#2} {% + \seq_gput_right:Nn \g__xassoccnt_feature_seq {#2}% + \xassoccnt_create_container:nc {feature=true} { \xassoccnt_featurename:n { #2 } } + \bool_if:NTF \l__xassoccnt_sublists_bool { \seq_gput_right:NV \g__xassoccnt_sublists_seq {\c_one }} { \seq_gput_right:NV \g__xassoccnt_sublists_seq {\c_zero }} + }% End of \seq_if_in + } +} + + + + +\prg_new_conditional:Nnn \xassoccnt_feature_if_in:n {TF,T,F} +{ + \seq_if_in:NnTF { \g__xassoccnt_feature_seq } {#1} + {\prg_return_true:} + {\prg_return_false:} +} + +\cs_generate_variant:Nn \xassoccnt_feature_if_in:nTF {c} +\cs_generate_variant:Nn \xassoccnt_feature_if_in:nT {c} +\cs_generate_variant:Nn \xassoccnt_feature_if_in:nF {c} + +\cs_new:Nn \xassoccnt_remove_feature:nn {% + % keys from #1 to be set + + \seq_if_exist:NTF \g__xassoccnt_feature_seq {% + \seq_remove_all:Nn \g__xassoccnt_feature_seq {#2} + \cs_undefine:c { \xassoccnt_featurename:n { #2 }} % Remove the sequence as a macro + }{ + % To be done! + } +} + +\cs_new:Nn \xassoccnt_add_container_to_feature:nn {% + \xassoccnt_feature_if_in:nTF { #1 } {% + \xassoccnt_add_to_containerlist:cn { \xassoccnt_featurename:n { feature#1 }} {#2 } + }{% + % To be done + } +} + + +\cs_new:Nn \xassoccnt_create_container:nN { + \keys_set:nn {xassoccnt_container} {#1} + \xassoccnt_container_if_exist:NTF #2 {% + % A existing container must not be redefined + \msg_error:nnn{xassoccnt}{containeralreadyexists}{#2}% Error! + }{ + \xassoccnt_container_new:N {#2} + } +} + + + +\cs_generate_variant:Nn \xassoccnt_create_container:nN {nc,nx} + +\cs_new:Nn \xassoccnt_add_to_containerlist:Nn {% + \clist_set:Nx \l_tmpa_clist {#2} + \xassoccnt_container_if_exist:NTF #1 {% + \clist_map_inline:Nn \l_tmpa_clist {% + \xassoccnt_container_put_right:Nn #1 {##1}% Append data + } + }{ + \xassoccnt_create_container:nN {feature=false} #1 + \xassoccnt_container_set_from_clist:NN #1 \l_tmpa_clist } } +\cs_generate_variant:Nn \xassoccnt_add_to_containerlist:Nn {cn,nn} + + + +\NewDocumentCommand{\AddFeature}{O{sublists=false}m}{% + \xassoccnt_add_feature:nn {#1} {#2} +} + +\NewDocumentCommand{\RemoveFeature}{O{}m}{% + \xassoccnt_remove_feature:nn {#1} {#2} +} + + + +\NewDocumentCommand{\NewContainer}{m}{% + \xassoccnt_create_container:nc {feature=false} {#1} +} + + +\NewDocumentCommand{\DeclareCoupledCounters}{O{}m}{% + \xassoccnt_add_to_containerlist:cn {\xassoccnt_featurename:n {coupledcounters} } {#2}% +} + +\NewDocumentCommand{\AddCoupledCounters}{O{}m}{% + \xassoccnt_add_to_containerlist:cn {\xassoccnt_featurename:n {coupledcounters} } {#2}% +} + +\NewDocumentCommand{\RemoveCoupledCounters}{O{}m}{% + \xassoccnt_container_remove_by_clist:cn { \xassoccnt_featurename:n {coupledcounters} } {#2} +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%% Redefinition of standard counter macros \RenewDocumentCommand{\stepcounter}{m}{% \__xassoccnt_translate_countername:cn {l_tmpa_tl} {#1}% \xassoccnt_is_suspendedcounter:nF{#1}{% - \cs_gset_nopar:Nn \__xassoccnt_laststeppedcounter: {\l_tmpa_tl}% - \xassoccnt_countersinresetlist:n{\l_tmpa_tl}% - \__xassoccnt_getresetlist:n {\l_tmpa_tl}% - \seq_if_empty:NTF \l__xassoccnt_counterreset_seq - {% - \xassoccnt_standardaddtocounter{\l_tmpa_tl}{\c_one}% Use the original one! - \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{\l_tmpa_tl}}% - \__xassoccnt_step_associatedcounters:n {\l_tmpa_tl} - }{ % reset list is not empty! - % This is the replacement of \csname cl@#1\endcsname - \xassoccnt_standardaddtocounter{\l_tmpa_tl}{\c_one} - \seq_map_inline:Nn \l__xassoccnt_counterreset_seq {% - \csname c@##1\endcsname\c_minus_one + \xassoccnt_container_if_in:cxTF { \xassoccnt_featurename:n {coupledcounters} } {#1} {% + \xassoccnt_container_map_inline:cn {\xassoccnt_featurename:n {coupledcounters} } {% \xassoccnt_standardstepcounter{##1}% } - \__xassoccnt_step_associatedcounters:n {\l_tmpa_tl} % step the remaining associated counters - }% End of not empty reset list + } + {% + \cs_gset_nopar:Nn \__xassoccnt_laststeppedcounter: {\l_tmpa_tl}% + \xassoccnt_countersinresetlist:n{\l_tmpa_tl}% + \__xassoccnt_getresetlist:n {\l_tmpa_tl}% + \seq_if_empty:NTF \l__xassoccnt_counterreset_seq + {% + \xassoccnt_standardaddtocounter{\l_tmpa_tl}{\c_one}% Use the original one! + \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{\l_tmpa_tl}}% + \__xassoccnt_step_associatedcounters:n {\l_tmpa_tl} + }{ % reset list is not empty! + % This is the replacement of \csname cl@#1\endcsname + \xassoccnt_standardaddtocounter{\l_tmpa_tl}{\c_one} + \seq_map_inline:Nn \l__xassoccnt_counterreset_seq {% + \csname c@##1\endcsname\c_minus_one + \xassoccnt_standardstepcounter{##1}% + } + \__xassoccnt_step_associatedcounters:n {\l_tmpa_tl} % step the remaining associated counters + }% End of not empty reset list + }% End of coupled counters } % end of not suspended counter } + \NewDocumentCommand{\xassoccnt_addtocounter}{mmO{}}{% % Only add to a counter if this counter isn't on the suspended counters list! \xassoccnt_is_suspendedcounter:nF{#1}{% @@ -1030,26 +1356,48 @@ { #2 } } - \NewDocumentCommand{\NewTotalDocumentCounter}{O{}m}{% \keys_set:nn {xassoccnt} {supertotal=false,#1} - \DeclareDocumentCounter[sloppy=false]{#2}% - \cs_if_exist:cF { c\__xassoccnt_expand_totalcountername:n{#2} } + \__xassoccnt_ifis_latexcounter:nF {#2} {% Define the counter + \DeclareDocumentCounter[sloppy=false]{#2}% + }% + \__xassoccnt_registertotaldocumentcounter:nn{#1}{#2} +} + +\cs_new:Nn \__xassoccnt_registertotaldocumentcounter:nn {% + \keys_set:nn {xassoccnt} {supertotal=false,#1} + \__xassoccnt_ifis_latexcounter:nF {#2} {% Counter does not exist -- do not autodefine + \msg_error:nnn{xassoccnt}{nameisnocounter}{#2}% + }% + % If the counter already exists -> check for the internal totalcounter name + \cs_if_exist:cF { c@\__xassoccnt_expand_totalcountername:n{#2} } { \DeclareDocumentCounter[sloppy=false,initial={\c_minus_one}]{\__xassoccnt_expand_totalcountername:n{#2}} - } - \seq_gput_right:Nx \g__xassoccnt_totalcounter_container {\__xassoccnt_expand_totalcountername:n{#2}} - \bool_if:NT \l__xassoccnt_is_supertotalcounter_bool {% - \__xassoccnt_add_supertotalcounter:n {#2} - } - \AtEndDocument{% - \__xassoccnt_writetotalcounters:nn {#2}{#2} + \seq_gput_right:Nx \g__xassoccnt_totalcounter_container {\__xassoccnt_expand_totalcountername:n{#2}} + \bool_if:NT \l__xassoccnt_is_supertotalcounter_bool {% + \__xassoccnt_add_supertotalcounter:n {#2} + } + \AtEndDocument{% + \__xassoccnt_writetotalcounters:nn {#2}{#2} + }% }% } +\NewDocumentCommand{\RegisterTotalDocumentCounter}{O{}m}{% + \__xassoccnt_registertotaldocumentcounter:nn{#1}{#2}% +} + \NewDocumentCommand{\TotalValue}{m}{% - \__xassoccnt_translate_countername:cn {l_tmpa_tl} {#1} + \tl_set:Nx \l_tmpa_tl {\__xassoccnt_expand_totalcountername:n{#1}} + \tl_set:Nx \l_tmpb_tl {#1}% + \seq_if_in:NnTF \g__xassoccnt_supertotalcounter_container {\l_tmpb_tl }{% + \tl_set:Nx \l_tmpa_tl {\__xassoccnt_expand_totalcountername:n{#1}} + }{% + \seq_if_in:NVF \g__xassoccnt_totalcounter_container {\l_tmpa_tl }{% + \tl_set:Nn \l_tmpa_tl {#1}% + } + } \number\value{\l_tmpa_tl}% } @@ -1120,6 +1468,8 @@ %%% Counter backup list features +% Those macros all deal with the global reset list% + \cs_new:Nn \__xassoccnt_renew_theHmacros:n {% \bool_if:NT \l__xassoccnt_hyperrefpackage_loaded_bool {% @@ -1137,42 +1487,59 @@ }% } -\cs_new:Nn \__xassoccnt_removestar:n {% - \tl_set:Nn \l_tmpa_tl {#1} - \tl_reverse:n \l_tmpa_tl - \tl_set_eq:NN \l_tmpb_tl \l_tmpa_tl - \tl_trim_spaces:N \l_tmpa_tl - \tl_if_in:NnT \l_tmpa_tl {*} {\tl_remove_once:Nn \l_tmpb_tl {*} } - \bool_set_true:N \l__xassoccnt_counternamestarred_bool% + +\cs_new:Nn \__xassoccnt_addcountertobackuplist_with_reset:nn {% + % Prevent multiple addition of a counter name + \seq_if_in:NnF #1 {#2} + { + \seq_gput_right:Nn \l__xassoccnt_backupresetlist_seq {\c_zero} + \seq_gput_right:Nn #1 { #2 } + } } -\seq_new:N \l__xassoccnt_backupresetlist_seq - +\cs_new:Nn \__xassoccnt_addcountertobackuplist_without_reset:nn {% + % Prevent multiple addition of a counter name + \seq_if_in:NnF #1 {#2} + { + \seq_gput_right:Nn \l__xassoccnt_backupresetlist_seq {\c_one} + \seq_gput_right:NV #1 {#2} + } +} -\NewDocumentCommand{\BackupCounterValues}{O{resetbackup=true}m}{% - \keys_set:nn{xassoccnt}{#1} - \int_incr:N \g__xassoccnt_backupcalls_int - \int_zero:N \l_tmpa_int - \clist_set:Nx \l_tmpa_clist {#2} - \seq_clear:N \l__xassoccnt_countervaluesbackup_seq - \seq_clear:N \l__xassoccnt_backupresetlist_seq + +\cs_new:Nn \__xassoccnt_removestar:n {% + \tl_clear:N \l_tmpa_tl + \clist_set:Nx \l_tmpa_clist {#1} \clist_map_inline:Nn \l_tmpa_clist {% \tl_clear:N \l_tmpa_tl% \tl_if_in:nnTF {##1} {*} { - \seq_gput_right:Nn \l__xassoccnt_backupresetlist_seq {\c_zero} \tl_set:Nn \l_tmpa_tl {##1} \tl_remove_all:Nn \l_tmpa_tl {*} - \seq_gput_right:NV \l__xassoccnt_counternamesbackup_seq { \l_tmpa_tl } - } - { - \seq_gput_right:Nn \l__xassoccnt_backupresetlist_seq {\c_one} - \seq_gput_right:Nn \l__xassoccnt_counternamesbackup_seq {##1} + \__xassoccnt_addcountertobackuplist_without_reset:nn { \l__xassoccnt_counternamesbackup_seq } {\l_tmpa_tl } + }{% + \__xassoccnt_addcountertobackuplist_with_reset:nn {\l__xassoccnt_counternamesbackup_seq} {##1} } + }% +} + +\cs_new:Nn \__xassoccnt_removestarsinglevalue:n {% + \tl_clear:N \l_tmpa_tl% + \tl_if_in:nnTF {#1} {*} + { + \tl_set:Nn \l_tmpa_tl {#1} + \tl_remove_all:Nn \l_tmpa_tl {*} + \__xassoccnt_addcountertobackuplist_without_reset:nn { \l__xassoccnt_counternamesbackup_seq } {\l_tmpa_tl } + }{% + \__xassoccnt_addcountertobackuplist_with_reset:nn {\l__xassoccnt_counternamesbackup_seq} {#1} } +} + + +\cs_new:Nn \__xassoccnt_backupcountervalues:nnn {% \seq_map_inline:Nn \l__xassoccnt_counternamesbackup_seq {% \int_incr:N \l_tmpa_int \__xassoccnt_ifis_latexcounter:nTF {##1} {% Check whether this is a counter at all! @@ -1190,24 +1557,125 @@ \msg_error:nnn{xassoccnt}{nameisnocounter}{##1}% }% }% +} - \seq_clear:N \l__xassoccnt_backupresetlist_seq% + +\cs_new:Nn \__xassoccnt_backupsinglecountervalue:n {% + \int_set:Nn \l_tmpa_int {\seq_count:N \l__xassoccnt_backupresetlist_seq}% + \__xassoccnt_ifis_latexcounter:nTF {#1} {% Check whether this is a counter at all! + % Store the old `\theH....` definition if preset + \__xassoccnt_renew_theHmacros:n { #1 } + \seq_gput_right:Nx \l__xassoccnt_countervaluesbackup_seq { \number\value{#1} } + % Check first if the counter name is starred -> no resetting then + \int_compare:nNnF { \seq_item:Nn \l__xassoccnt_backupresetlist_seq {\int_use:N \l_tmpa_int }} = { \c_zero } + {% + \bool_if:NT \l__xassoccnt_resetbackupcounters_bool {% + \setcounter{#1}{\c_zero}% + }% + }% + }{% + \msg_error:nnn{xassoccnt}{nameisnocounter}{#1}% + }% } - -\NewDocumentCommand{\RestoreCounterValues}{O{}}{% + + +\cs_new:Nn \__xassoccnt_restorecountervalues:n { \int_zero:N \l_tmpa_int % dummy 'counter' - \seq_map_inline:Nn \l__xassoccnt_counternamesbackup_seq {% + \seq_map_inline:cn {#1} {% \int_incr:N \l_tmpa_int % Increment the local 'counter' - \typeout{resetting(##1)~with~\seq_item:Nn \l__xassoccnt_countervaluesbackup_seq {\int_use:N \l_tmpa_int }} \setcounter{##1}{\seq_item:Nn \l__xassoccnt_countervaluesbackup_seq {\int_use:N \l_tmpa_int }} \__xassoccnt_restore_theHmacros:n {##1}% } +} + + +\NewDocumentCommand{\BackupCounterValues}{O{resetbackup=true}m}{% + \keys_set:nn{xassoccnt}{#1} + \int_incr:N \g__xassoccnt_backupcalls_int + \int_zero:N \l_tmpa_int + \seq_clear:N \l__xassoccnt_countervaluesbackup_seq + \seq_clear:N \l__xassoccnt_backupresetlist_seq + \__xassoccnt_addbackupcounter:nnn {#1}{}{#2}% + \seq_clear:N \l__xassoccnt_backupresetlist_seq% +} + +\NewDocumentCommand{\RemoveBackupCounterInternal}{sO{}m}{% + \tl_set:Nn \l_tmpa_tl {#3} + \int_zero:N \l_tmpa_int% + \int_zero:N \l_tmpb_int% + \seq_clear:N \l_tmpa_seq% + \seq_if_in:NnT \l__xassoccnt_counternamesbackup_seq {#3} {% + \seq_map_inline:Nn \l__xassoccnt_counternamesbackup_seq + {% + \int_incr:N \l_tmpa_int + \tl_set:Nn \l_tmpb_tl {##1} + % Get the value of the current counter + \int_set:Nn \l_tmpb_int {\seq_item:Nn \l__xassoccnt_countervaluesbackup_seq {\l_tmpa_int }} + \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl + { % Restore the old \theH#3 definition + \__xassoccnt_restore_theHmacros:n {#3}% + \IfBooleanF{#1}{ \setcounter{#3}{\l_tmpb_int } } + }{ + \seq_put_right:NV \l_tmpa_seq { \l_tmpa_int } + }% End of \tl_if_eq:NNTF + }% End of \seq_map_inline + } % No F - Branch needed here (most likely ;-)) +} + + + + +\NewDocumentCommand{\RemoveBackupCounters}{sO{}m}{% + \clist_set:Nn \l_tmpa_clist {#3} + % Loop through the list + \clist_map_inline:Nn \l_tmpa_clist {% + \IfBooleanTF{#1}{% + \RemoveBackupCounterInternal*{##1}% + }{% + \RemoveBackupCounterInternal*{##1}% + } + } +} + +\NewDocumentCommand{\RestoreAllCounterValues}{O{}}{% + \__xassoccnt_restorecountervalues:n {l__xassoccnt_counternamesbackup_seq } \seq_clear:N \l__xassoccnt_countervaluesbackup_seq % clear the value list \seq_clear:N \l__xassoccnt_counternamesbackup_seq % clear the name list } - +% \Restore is \Remove with restoring (of course) +\NewDocumentCommand{\RestoreCounterValues}{O{}m}{% + \clist_set:Nn \l_tmpa_clist {#2} + \clist_map_inline:Nn \l_tmpa_clist {% + \RemoveBackupCounterInternal{##1}% + } +} + + +\cs_new:Nn \__xassoccnt_addbackupcounter:nnn {% + % Remove first the stars from the counter names that should not be reset! + \__xassoccnt_removestar:n {#3} + % Now backup the counter values + \__xassoccnt_backupcountervalues:nnn {#3}{}{} +} + + +\NewDocumentCommand{\AddBackupCounter}{O{}m}{% + \clist_set:Nx \l_tmpa_clist {#2} + \clist_map_inline:Nn \l_tmpa_clist {% + \__xassoccnt_removestarsinglevalue:n{##1}% + \__xassoccnt_backupsinglecountervalue:n{##1}% + } +} + + + +%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%% \ExplSyntaxOff @@ -1233,8 +1701,11 @@ } \@onlypreamble{\NewTotalDocumentCounter} +\@onlypreamble{\RegisterTotalDocumentCounter} \@onlypreamble{\DeclareAssociatedCounters} \@onlypreamble{\DeclareDocumentCounter} +\@onlypreamble{\DeclareCoupledCounters} + \NewTotalDocumentCounter[supertotal=true]{numberofruns} @@ -1247,4 +1718,9 @@ \newcommand{\TotalCounterInfoColor}{violet} +\AddFeature{coupledcounters} % New style, not fully implemented so far + + +% Some more to be done + \endinput
\ No newline at end of file |