From 3d16d49a99b851e8d36c62113f6ee34b8b41a477 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 26 Jan 2016 22:51:14 +0000 Subject: xassoccnt (26jan15) git-svn-id: svn://tug.org/texlive/trunk@39485 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/xassoccnt/xassoccnt.sty | 144 +++++++++++++++++++-- 1 file changed, 134 insertions(+), 10 deletions(-) (limited to 'Master/texmf-dist/tex/latex/xassoccnt') diff --git a/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty b/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty index bcd25c90962..7a475a6745c 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.3 (2016/01/08 -- 10/54/13) +%% LaTeX package xassoccnt - version 0.4 (2016/01/26 -- 10/46/26) %% Source file for xassoccnt.sty %% %% @@ -19,10 +19,10 @@ %% %% -\def\xassoccntpackageversion{0.3} +\def\xassoccntpackageversion{0.4} \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{xassoccnt}[2016/01/08 - v\xassoccntpackageversion] +\ProvidesPackage{xassoccnt}[2016/01/26 - v\xassoccntpackageversion] \RequirePackage{xcolor} \RequirePackage{xparse} @@ -31,10 +31,14 @@ + + \ExplSyntaxOn % First some local or global values +\bool_new:N \l__xassoccnt_hyperrefpackage_loaded_bool + \str_const:Nn \c__xassoccnt_modulename_str {xassoccnt} \bool_new:N \l__xassoccnt_calcpackage_loaded @@ -61,6 +65,14 @@ \seq_new:N \l__xassoccnt_counterreset_seq +%%% +\int_new:N \g__xassoccnt_backupcalls_int +\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 + + \cs_new:Nn \__xassoccnt_toggle_bool:n {% \bool_if:nTF{#1}{\bool_set_false:n {#1}}{\bool_set_false:n {#1}} } @@ -143,7 +155,9 @@ }, countertype .initial:n={ general }, - supertotal .bool_set:N={\l__xassoccnt_is_supertotalcounter_bool } + supertotal .bool_set:N={\l__xassoccnt_is_supertotalcounter_bool }, + + resetbackup .bool_set:N={\l__xassoccnt_resetbackupcounters_bool } } \ProcessKeysOptions{xassoccnt} @@ -153,6 +167,11 @@ Error:~Counter~#1~already~exists\\ } +\msg_new:nnn{xassoccnt}{nameisnocounter}{% + Error:~Entity~#1~does~not~name~a~counter\\ +} + + \msg_new:nnn{xassoccnt}{crossassociation}{% Error:~You~can't~cross-associate~two~counters\\ @@ -204,6 +223,17 @@ \cs_set_eq:NN \xassoccnt_standardaddtocounter \addtocounter \cs_set_eq:NN \xassoccnt_standardsetcounter \setcounter + +% Needed for Backup/Restore features + +\AtBeginDocument{% + \@ifpackageloaded{hyperref}{% + \bool_set_true:N \l__xassoccnt_hyperrefpackage_loaded_bool% + }{}% +} + + + % A little patch for perpage \@ifpackageloaded{perpage}{% @@ -823,6 +853,18 @@ \__xassoccnt_setdocumentcounter:nnn {#1}{#2}{#3} % copy the driver counter value to all associated counters } + + +\NewDocumentCommand{\StepDownCounter}{O{}m}{% + \SubtractFromCounter[#1]{#2}{1}% +} + +\NewDocumentCommand{\SubtractFromCounter}{O{}mm}{% + \xassoccnt_addtocounter{#2}{-#3}[#1]% +} + + + \NewDocumentCommand{\SyncCounters}{om}{% \IfValueTF{#1}{% \__xassoccnt_synccounters:nn {#1}{#2} @@ -1076,13 +1118,95 @@ { #2 } } -%\NewDocumentCommand{\AddSuperTotalCounter}{m}{% -% \__xassoccnt_add_supertotalcounter:n {#1}% -%} +%%% Counter backup list features + + +\cs_new:Nn \__xassoccnt_renew_theHmacros:n {% + \bool_if:NT \l__xassoccnt_hyperrefpackage_loaded_bool {% + \cs_if_exist:cT {theH#1} {% + \cs_gset_eq:cc {xassoccnt_theH#1} {theH#1}% + \expandafter\renewcommand\csname theH#1\endcsname{xassoccnt.\int_use:N \g__xassoccnt_backupcalls_int.#1.\number\value{#1}}% + }% + } +} +\cs_new:Nn \__xassoccnt_restore_theHmacros:n {% + \bool_if:NT \l__xassoccnt_hyperrefpackage_loaded_bool {% + \cs_if_exist:cT {theH#1} {% + \cs_gset_eq:cc {theH#1} {xassoccnt_theH#1} % + }% + }% +} + +\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% +} + + +\seq_new:N \l__xassoccnt_backupresetlist_seq + + + +\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 + \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} + } + } + + \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! + % 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}% + }% + }% + + \seq_clear:N \l__xassoccnt_backupresetlist_seq% +} + +\NewDocumentCommand{\RestoreCounterValues}{O{}}{% + \int_zero:N \l_tmpa_int % dummy 'counter' + \seq_map_inline:Nn \l__xassoccnt_counternamesbackup_seq {% + \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}% + } + \seq_clear:N \l__xassoccnt_countervaluesbackup_seq % clear the value list + \seq_clear:N \l__xassoccnt_counternamesbackup_seq % clear the name list +} + -%\NewDocumentCommand{\RemoveSuperTotalCounter}{m}{% -% \__xassoccnt_remove_supertotalcounter:n {#1}% -%} \ExplSyntaxOff -- cgit v1.2.3