diff options
author | Karl Berry <karl@freefriends.org> | 2016-01-08 22:23:22 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-01-08 22:23:22 +0000 |
commit | 0dde4d7f4b9ba62d4c0cbde98fabe06aa2f15764 (patch) | |
tree | 5acf2e2623ee6d2c10957e5e87bd3cc22967fd67 /Master/texmf-dist/tex/latex/xassoccnt | |
parent | d3c8442fa5a4a738b4f4bd1a511d73d07f489d24 (diff) |
xassoccnt (8jan16)
git-svn-id: svn://tug.org/texlive/trunk@39319 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/xassoccnt')
-rw-r--r-- | Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty | 305 |
1 files changed, 267 insertions, 38 deletions
diff --git a/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty b/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty index 2ca160fb86d..bcd25c90962 100644 --- a/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty +++ b/Master/texmf-dist/tex/latex/xassoccnt/xassoccnt.sty @@ -1,9 +1,9 @@ -%% LaTeX package xassoccnt - version 0.2 (2015/11/14 -- 16/08/33) +%% LaTeX package xassoccnt - version 0.3 (2016/01/08 -- 10/54/13) %% Source file for xassoccnt.sty %% %% %% ------------------------------------------------------------------------------------------- -%% Copyright (c) 2015 by Dr. Christian Hupfer <christian dot hupfer at yahoo dot de> +%% Copyright (c) 2016 by Dr. Christian Hupfer <christian dot hupfer at yahoo dot de> %% ------------------------------------------------------------------------------------------- %% %% This work may be distributed and/or modified under the @@ -19,16 +19,18 @@ %% %% -\def\xassoccntpackageversion{0.2} +\def\xassoccntpackageversion{0.3} \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{xassoccnt}[2015/11/14 - v\xassoccntpackageversion] +\ProvidesPackage{xassoccnt}[2016/01/08 - v\xassoccntpackageversion] \RequirePackage{xcolor} \RequirePackage{xparse} \RequirePackage{l3keys2e} + + \ExplSyntaxOn % First some local or global values @@ -53,7 +55,9 @@ \bool_new:N \l__xassoccnt_countertype_general \bool_new:N \l__xassoccnt_countertype_driver \bool_new:N \l__xassoccnt_countertype_associated +\bool_new:N \l__xassoccnt_countertype_total +\bool_new:N \l__xassoccnt_is_supertotalcounter_bool \seq_new:N \l__xassoccnt_counterreset_seq @@ -111,10 +115,35 @@ %% For later purposes countertype .choice:, - countertype / general .code:n= {\bool_set_true:N \l__xassoccnt_countertype_general }, - countertype / driver .code:n= {\bool_set_true:N \l__xassoccnt_countertype_driver }, - countertype / associated .code:n= {\bool_set_true:N \l__xassoccnt_countertype_associated }, - countertype .initial:n={ general } + countertype / general .code:n= {\bool_set_true:N \l__xassoccnt_countertype_general + \__xassoccnt_set_false:n {l__xassoccnt_countertype_driver, + l__xassoccnt_countertype_total, + l__xassoccnt_countertype_associated + } + }, +%\bool_set_false:N \l__xassoccnt_countertype_driver \bool_set_false:N \l__xassoccnt_countertype_associated }, + countertype / driver .code:n= {\bool_set_true:N \l__xassoccnt_countertype_driver + \__xassoccnt_set_false:n {l__xassoccnt_countertype_general, + l__xassoccnt_countertype_total, + l__xassoccnt_countertype_associated + } + }, +% \bool_set_false:N \l__xassoccnt_countertype_assocciated \bool_set_false:N \l__xassoccnt_countertype_general }, + countertype / associated .code:n= {\bool_set_true:N \l__xassoccnt_countertype_associated + \__xassoccnt_set_false:n {l__xassoccnt_countertype_general, + l__xassoccnt_countertype_total, + l__xassoccnt_countertype_driver + } + }, + countertype / total .code:n= {\bool_set_true:N \l__xassoccnt_countertype_total + \__xassoccnt_set_false:n {l__xassoccnt_countertype_driver, + l__xassoccnt_countertype_general, + l__xassoccnt_countertype_associated + } + }, + countertype .initial:n={ general }, + + supertotal .bool_set:N={\l__xassoccnt_is_supertotalcounter_bool } } \ProcessKeysOptions{xassoccnt} @@ -154,12 +183,8 @@ -\cs_new:Nn \__xassoccnt_stpelt:n{\global\csname c@#1\endcsname\c_minus_one\xassoccnt_addtocounter{#1}{\c_one}}% - %\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}% \int_new:N \l_xassoccnt_resetlist_counter @@ -168,7 +193,6 @@ \begingroup \int_zero:N \l_xassoccnt_resetlist_counter \cs_set_eq:NN \@elt \__xassoccnt_intinc:n -% \def\@elt##1{\int_gincr:N \l_xassoccnt_resetlist_counter}% Increase the 'counter' globally \use:c{ cl@#1 } \endgroup } @@ -250,6 +274,8 @@ \cs_new_nopar:Nn \__xassoccnt_container_clear:n {\seq_clear:N #1 } +\seq_new:N \g__xassoccnt_totalcounter_container +\seq_new:N \g__xassoccnt_supertotalcounter_container \cs_new_nopar:Nn \__xassoccnt_container_perdriver_new:n { \seq_if_exist:cF{ \__xassoccnt_drivercontainer:n {#1} } @@ -321,12 +347,28 @@ } +\cs_new_nopar:Nn \__xassoccnt_expand_totalcountername:n {% + xassoccnt@total@#1% +} + + + +\cs_new:Nn \__xassoccnt_translate_counterlist:n {% + \clist_clear:N \l_tmpb_clist + \clist_set:Nx \l_tmpa_clist {#1}% + \clist_map_inline:Nn \l_tmpa_clist {% + \__xassoccnt_is_totalcounter:nTF { ##1 } + { \clist_gput_right:Nx \l_tmpb_clist { \__xassoccnt_expand_totalcountername:n {##1} } } + { \clist_gput_right:Nn \l_tmpb_clist {##1} } + } + \clist_set_eq:NN \l_tmpa_clist \l_tmpb_clist +} \cs_new:Nn \__xassoccnt_addassociatedcounters:nnn {% \keys_set:nn{xassoccnt}{#1} - \clist_set:Nx \l_tmpa_clist {#3}% - \clist_if_in:NnT \l_tmpa_clist{#2}{% Prevent self-association + \clist_set:Nx \l_tmpa_clist {#3} + \clist_if_in:NnT \l_tmpa_clist {#2} {% Prevent self-association \msg_warning:nnn{xassoccnt}{selfassociation}{#2}% Warning \clist_gremove_all:Nn \l_tmpa_clist {#2}% }% @@ -495,13 +537,12 @@ \NewDocumentCommand{\SuspendCounters}{O{}m}{% \keys_set:nn { xassoccnt }{#1}% -% \clist_if_empty:NF \l__xassoccnt_onlycounters_clist {% \__xassoccnt_container_putright:nn{\c_xassoccnt_suspendedname_str}{#2} } \NewDocumentCommand{\ResumeSuspendedCounters}{O{}m}{% - \__xassoccnt_container_removecounter:nn{\c_xassoccnt_suspendedname_str}{#2} + \__xassoccnt_container_removecounter:nn{\c_xassoccnt_suspendedname_str}{#2}% } @@ -648,35 +689,58 @@ + + \cs_new:Nn \__xassoccnt_step_associatedcounters:n {% \seq_if_exist:cT { \__xassoccnt_drivercontainer:n{#1} } { \seq_map_inline:cn {\__xassoccnt_drivercontainer:n{#1} } - { \xassoccnt_addtocounter{##1}{\c_one} } + { + \xassoccnt_addtocounter{##1}{\c_one} + } } % End of \seq_if_exist } +\prg_new_conditional:Nnn \__xassoccnt_is_totalcounter:n {T,F,TF} +{% + \seq_if_in:NxTF \g__xassoccnt_totalcounter_container { \__xassoccnt_expand_totalcountername:n {#1} } + { + \prg_return_true: + }{% + \prg_return_false: + }% +} + + +\cs_new_nopar:Nn \__xassoccnt_translate_countername:cn {% + \tl_set:cn {#1}{#2}% + \seq_if_in:NxT \g__xassoccnt_supertotalcounter_container {#2} {% + \tl_set:cn {#1}{\__xassoccnt_expand_totalcountername:n {#2} }% + } +} + \RenewDocumentCommand{\stepcounter}{m}{% + \__xassoccnt_translate_countername:cn {l_tmpa_tl} {#1}% \xassoccnt_is_suspendedcounter:nF{#1}{% - \cs_gset_nopar:Nn \__xassoccnt_laststeppedcounter: {#1}% - \xassoccnt_countersinresetlist:n{#1}% - \__xassoccnt_getresetlist:n {#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{#1}{\c_one}% Use the original one! - \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{#1}}% - \__xassoccnt_step_associatedcounters:n {#1} + \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{#1}{\c_one} + \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}%{\c_one}% + \xassoccnt_standardstepcounter{##1}% } - \__xassoccnt_step_associatedcounters:n {#1} % step the remaining associated counters + \__xassoccnt_step_associatedcounters:n {\l_tmpa_tl} % step the remaining associated counters }% End of not empty reset list } % end of not suspended counter } @@ -687,20 +751,24 @@ \NewDocumentCommand{\xassoccnt_addtocounter}{mmO{}}{% % Only add to a counter if this counter isn't on the suspended counters list! \xassoccnt_is_suspendedcounter:nF{#1}{% - \xassoccnt_standardaddtocounter{#1}{#2}% - \cs_gset_nopar:Nn \__xassoccnt_lastaddtocounter: {#1}% + \__xassoccnt_translate_countername:cn {l_tmpb_tl} {#1}% + \xassoccnt_standardaddtocounter{\l_tmpb_tl}{#2}% + \cs_gset_nopar:Nn \__xassoccnt_lastaddtocounter: {\l_tmpb_tl}% }% } -\cs_new:Nn \__xassoccnt_setdocumentcounter:nnn { - \xassoccnt_standardsetcounter{#2}{#3}% +\cs_new:Nn \__xassoccnt_setdocumentcounter:nnn {% + \__xassoccnt_translate_countername:cn {l_tmpa_tl} {#2}% + \xassoccnt_standardsetcounter{\l_tmpa_tl}{#3}% \clist_clear:N \l__xassoccnt_onlycounters_clist \keys_set:nn {xassoccnt}{#1}% \bool_if:nTF {\l__xassoccnt_setcounter_associated } {% \seq_if_exist:cT { \__xassoccnt_drivercontainer:n{#2} } { \seq_map_inline:cn {\__xassoccnt_drivercontainer:n{#2} } - { \xassoccnt_standardsetcounter{##1}{#3} } + { + \__xassoccnt_translate_countername:cn {l_tmpb_tl} {##1}% + \xassoccnt_standardsetcounter{\l_tmpb_tl}{#3} } }% End of \seq_if_exist }{% % Check whether the `onlycounters` - clist is empty -- if not, loop through the list @@ -709,13 +777,14 @@ { \clist_map_inline:Nn \l__xassoccnt_onlycounters_clist { % Check first if ##1 is associated to #2 at all - \xassoccnt_is_associatedtocounter:nnT {#2} {##1} { \xassoccnt_standardsetcounter{##1}{#3} } + \__xassoccnt_translate_countername:cn {l_tmpb_tl} {##1}% + \xassoccnt_is_associatedtocounter:nnT {#2} {\l_tmpb_tl} { \xassoccnt_standardsetcounter{\l_tmpb_tl}{#3} } } } } } \cs_gset_nopar:Nn \__xassoccnt_lastsetdocumentcounter: {#2}% - \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{#2}}% + \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{\l_tmpa_tl}}% } @@ -764,20 +833,20 @@ \RenewDocumentCommand{\setcounter}{mm}{% + \__xassoccnt_translate_countername:cn {l_tmpb_tl}{#1}% \cs_gset_nopar:Nn \__xassoccnt_lastsetcounter: {#1} - \xassoccnt_standardsetcounter{#1}{#2}% - \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{#1}}% + \xassoccnt_standardsetcounter{\tl_use:N \l_tmpb_tl}{#2}% + \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{\l_tmpb_tl}}% } \RenewDocumentCommand{\refstepcounter}{m}{% \cs_gset_nopar:Nn \__xassoccnt_lastrefsteppedcounter: {#1} -% \stepcounter{#1}% \xassoccnt_standardrefstepcounter{#1}% \int_gset:Nn \g__xassoccnt_lastcountervalue_int {\number\value{#1}}% } -%%%% Now some wrapper macros for information on the last counter changed +%%%% Now some expandable wrapper macros for information on the last counter changed \newcommand{\LastSteppedCounter}{% \__xassoccnt_laststeppedcounter: @@ -875,9 +944,157 @@ } +% Pretty printing counters + +\NewDocumentCommand{\PrettyPrintCounterName}{+mm}{% + \keys_set:nn {xassoccnt} {countertype=general,#1}% + \bool_if:nTF {\l__xassoccnt_countertype_general} + { + \fbox{\textcolor{\GeneralCounterInfoColor}{\textbf{#2}}} + } + { + \bool_if:nTF {\l__xassoccnt_countertype_driver} { + \fbox{\textcolor{\DriverCounterInfoColor}{\textbf{#2}}}% + }{ + \bool_if:nTF {\l__xassoccnt_countertype_associated } + {% + \fbox{\textcolor{\AssociatedCounterInfoColor}{\textbf{#2}}}% + }{% + \bool_if:nTF {\l__xassoccnt_countertype_total } + {% + \fbox{\textcolor{\TotalCounterInfoColor}{\textbf{#2}}}% + }{ + Error}% + } + }% + }% +} + +%%%%%%%%%%% Total counter features + +\NewDocumentCommand{\IsTotalCounterTF}{m+m+m}{% + \__xassoccnt_is_totalcounter:nTF { #1 } + { #2 } + { #3 } +} + +\NewDocumentCommand{\IsTotalCounterT}{m+m}{% + \__xassoccnt_is_totalcounter:nT { #1 } + { #2 } +} + +\NewDocumentCommand{\IsTotalCounterF}{m+m}{% + \__xassoccnt_is_totalcounter:nF { #1 } + { #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} } + { + \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} + }% +} + + +\NewDocumentCommand{\TotalValue}{m}{% + \__xassoccnt_translate_countername:cn {l_tmpa_tl} {#1} + \number\value{\l_tmpa_tl}% +} + +\cs_new:Nn \__xassoccnt_writetotalcounters:nn {% + \immediate\write\@mainaux {% + \string\IfIsDocumentCounterF\expandafter{\__xassoccnt_expand_totalcountername:n{#1}}{\string\DeclareDocumentCounter\expandafter{\__xassoccnt_expand_totalcountername:n{#1}}} + } + \seq_if_in:NnTF \g__xassoccnt_supertotalcounter_container {#1} {% + \immediate\write\@mainaux{% + \string\setcounter{\__xassoccnt_expand_totalcountername:n{#1}}{\number\value{\__xassoccnt_expand_totalcountername:n{#1}}}% + } + }{ + \immediate\write\@mainaux{% + \string\setcounter{\__xassoccnt_expand_totalcountername:n{#1}}{\number\value{#2}}% + } + } +} + + + +\NewDocumentCommand{\TotalCounterInternalName}{m}{% + \__xassoccnt_is_totalcounter:nTF { #1 } + { \__xassoccnt_expand_totalcountername:n {#1} } + { #1 } % +} + +%%% Super total counter features + +\cs_new:Nn \__xassoccnt_add_supertotalcounter:n {% + \cs_if_exist:cTF {c@#1} {% + \seq_gput_right:Nx \g__xassoccnt_supertotalcounter_container {#1} + }{% + % Some warning/error message later on here! + } +} + +\cs_new:Nn \__xassoccnt_remove_supertotalcounter:n {% + \seq_gremove_all:Nn \g__xassoccnt_supertotalcounter_container {#1} +} + + +\prg_new_conditional:Nnn \__xassoccnt_is_supertotalcounter:n {T,F,TF} +{% + \seq_if_in:NxTF \g__xassoccnt_supertotalcounter_container { #1 } + { + \prg_return_true: + }{% + \prg_return_false: + }% +} + + +\NewDocumentCommand{\IsSuperTotalCounterTF}{m+m+m}{% + \__xassoccnt_is_supertotalcounter:nTF { #1 } + { #2 } + { #3 } +} + +\NewDocumentCommand{\IsSuperTotalCounterT}{m+m}{% + \__xassoccnt_is_supertotalcounter:nT { #1 } + { #2 } +} + +\NewDocumentCommand{\IsSuperTotalCounterF}{m+m}{% + \__xassoccnt_is_supertotalcounter:nF { #1 } + { #2 } +} + +%\NewDocumentCommand{\AddSuperTotalCounter}{m}{% +% \__xassoccnt_add_supertotalcounter:n {#1}% +%} + +%\NewDocumentCommand{\RemoveSuperTotalCounter}{m}{% +% \__xassoccnt_remove_supertotalcounter:n {#1}% +%} + + \ExplSyntaxOff + +\AtBeginDocument{% + \stepcounter{numberofruns} +} + + + %%%%%%%%%%% % Extended interface functions @@ -891,7 +1108,19 @@ }% } +\@onlypreamble{\NewTotalDocumentCounter} \@onlypreamble{\DeclareAssociatedCounters} \@onlypreamble{\DeclareDocumentCounter} + +\NewTotalDocumentCounter[supertotal=true]{numberofruns} + +%%% Colour output routines + +\newcommand{\GeneralCounterInfoColor}{orange} +\newcommand{\DriverCounterInfoColor}{blue} +\newcommand{\AssociatedCounterInfoColor}{red} +\newcommand{\TotalCounterInfoColor}{violet} + + \endinput
\ No newline at end of file |