diff options
author | Karl Berry <karl@freefriends.org> | 2017-01-17 22:24:06 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-01-17 22:24:06 +0000 |
commit | 44710df8ad36ca2a4e67e39764d42b2656c93ed0 (patch) | |
tree | 654547c8dae4b78ad71a0fd014920a763ad7581e /Master/texmf-dist/tex/latex/xcntperchap | |
parent | 83c2afe1e7900bff6c7e2f02de0b10df55de34df (diff) |
xcntperchap
git-svn-id: svn://tug.org/texlive/trunk@42980 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/xcntperchap')
-rw-r--r-- | Master/texmf-dist/tex/latex/xcntperchap/xcntperchap.sty | 123 |
1 files changed, 96 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/latex/xcntperchap/xcntperchap.sty b/Master/texmf-dist/tex/latex/xcntperchap/xcntperchap.sty index b029267ca5b..20edfe8187a 100644 --- a/Master/texmf-dist/tex/latex/xcntperchap/xcntperchap.sty +++ b/Master/texmf-dist/tex/latex/xcntperchap/xcntperchap.sty @@ -1,9 +1,9 @@ -%% LaTeX package xcntperchap - version 0.2 (2016/06/07 -- 09/05/23) +%% LaTeX package xcntperchap - version 0.3 (2017/01/13 -- 23:24:36) %% Source file for xcntperchap.sty %% %% %% ------------------------------------------------------------------------------------------- -%% Copyright (c) 2016 by Dr. Christian Hupfer <christian dot hupfer at yahoo dot de> +%% Copyright (c) 2016 -- 2017 by Dr. Christian Hupfer <typography dot with dot latex at gmail dot com> %% ------------------------------------------------------------------------------------------- %% %% This work may be distributed and/or modified under the @@ -19,11 +19,12 @@ %% %% -\def\xcntperchappackageversion{0.2} +\def\xcntperchappackageversion{0.3} \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{xcntperchap}[2016/06/07 - v\xcntperchappackageversion] +\ProvidesPackage{xcntperchap}[2017/01/13 - v\xcntperchappackageversion] +\RequirePackage[counter]{zref} \RequirePackage{xparse} \RequirePackage{l3keys2e} \RequirePackage[nonumberofruns]{xassoccnt} @@ -33,6 +34,7 @@ \let\latex@@stepcounter\stepcounter +\let\latex@@addtocounter\addtocounter \cs_generate_variant:Nn \int_set:Nn {NV, Nx} @@ -57,10 +59,25 @@ \seq_new:c {g_xcntperchap_tracklevel_#1_seq}% Creating a new container for the counter names to be tracked \prop_new:c {g_xcntperchap_tracklevel_#1_prop}% Creating a new property list for the counter names to be tracked \seq_new:c {g_xcntperchap_tracklevelstored_#1_seq}% Creating a new container for the stored counter values (used later on) + \IfIsDocumentCounterF{cps@@#1trackleveltotal}{% + \NewDocumentCounter{cps@@#1trackleveltotal}% + } + \DeclareAssociatedCounters{#1}{cps@@#1trackleveltotal} + \zref@newprop{cps#1total}{\number\value{cps@@#1trackleveltotal}} }% } -\NewDocumentCommand{\RegisterCounters}{mm}{% + + +\NewDocumentCommand{\RegisterMultipleTrackCounters}{mm}{% + \clist_set:Nn \l_tmpa_clist {#1}% + \clist_map_inline:Nn \l_tmpa_clist {% + \RegisterTrackCounter{##1}{#2}% + } +} + + +\NewDocumentCommand{\RegisterTrackCounter}{mm}{% \xcntperchap_add_tracklevel:n {#1} \seq_set_from_clist:cn {g_xcntperchap_tracklevel_#1_seq} {#2} \seq_remove_duplicates:c {g_xcntperchap_tracklevel_#1_seq} @@ -71,11 +88,12 @@ \NewDocumentCounter{cps@@#1total##1}% \AddAssociatedCounters{##1}{cps@@#1total##1}% Define associated counters } - \prop_put:cnV {g_xcntperchap_tracklevel_#1_prop} {##1} {\l_tmpa_int} % New Version 0.2 - } + \prop_put:cnV {g_xcntperchap_tracklevel_#1_prop} {##1} \l_tmpa_int % New Version 0.2 + } } + \cs_new:Nn \xcntperchap_storetracked_values:n{% \tl_clear:N \l_tmpa_tl \int_zero:N \l_tmpa_int @@ -93,7 +111,7 @@ \iow_now:Nx \g_trackfile_storage_write {\l_tmpa_tl}% } \seq_map_inline:cn {g_xcntperchap_tracklevel_#1_seq} { - \setcounter{cps@@#1total##1}{0}% Reset the total counter values + \setcounter{cps@@#1total##1}{\c_zero}% Reset the total counter values } } } @@ -109,7 +127,7 @@ % Must get reset list first \__xassoccnt_getresetlist:n{#1}% \seq_map_inline:Nn \g_xcntperchap_tracklevel_seq {% - \seq_if_in:NnT \l__xassoccnt_counterreset_seq {##1} { + \seq_if_in:NnT \l__xassoccnt_counterreset_seq {##1} {% \StoreCounterValues{##1}% } } @@ -118,6 +136,16 @@ } +\NewDocumentCommand{\AddToTrackedCounters}{mm}{% + \seq_set_from_clist:Nn \l_tmpa_seq {#1} + \seq_map_inline:Nn \l_tmpa_seq {% + \prg_replicate:nn {#2} {\stepcounter{##1}} + } +} + + + + \cs_new_nopar:Nn \xcntperchap_trackcounters: {% \seq_map_inline:cn {g_xcntperchap_tracklevel_seq} {% @@ -143,6 +171,14 @@ } +\cs_new:Nn \l_xcntperchap_numberoftracks:n {% + \seq_if_exist:cTF { g_xcntperchap_tracklevelstored_#1_seq} {% + \int_eval:n {\seq_count:c {g_xcntperchap_tracklevelstored_#1_seq} / \seq_count:c {g_xcntperchap_tracklevel_#1_seq}} + }{ + \c_zero + } +} + \cs_new:Nn \xcntperchap_open_trackfile_for_read:n {% \ior_open:Nn \g_trackfile_storage_read {#1} @@ -217,24 +253,6 @@ %%%%% 0.2 Expandable Version -\cs_new:Nn \xcntperchap_obtaintrackedvalue_exp_orig:nnn {% - \int_set:Nx \l_tracklevelunit_int {#1} - \seq_if_in:cnT {g_xcntperchap_tracklevel_#2_seq} {#3} - { - \int_set:Nx \l_tracklevel_tracked_int {\seq_count:c {g_xcntperchap_tracklevel_#2_seq}} - \int_zero:N \l_tmpa_int - \seq_map_inline:cn {g_xcntperchap_tracklevel_#2_seq} {% - \int_incr:N \l_tmpa_int - \tl_if_eq:nnT { ##1 } {#3 } { - \seq_map_break: - } - } - \int_set:NV \l_tmpb_int { \l_tmpa_int } - \int_set:Nx \l_tmpa_int { \l_tracklevel_tracked_int * (\l_tracklevelunit_int -1) + \l_tmpb_int } - \seq_item:cn {g_xcntperchap_tracklevelstored_#2_seq} {\int_use:N \l_tmpa_int} - }% -} - \cs_new:Nn \xcntperchap_obtaintrackedvalue_exp:nnn {% Needs some error checking!!! \seq_if_exist:cTF {g_xcntperchap_tracklevel_#2_seq} { @@ -259,9 +277,60 @@ + \ExplSyntaxOff +\newif\if@cpscleverefloaded + +\AtBeginDocument{% + \@ifpackageloaded{cleveref}{% + \@cpscleverefloadedtrue + }{% + \@cpscleverefloadedfalse + } +} + + +\NewDocumentCommand{\tracklabel}{som}{% + \zref@labelbyprops{#3}{counter,cps\LastRefSteppedCounter total}% The counter property is for safety here! + \IfBooleanF{#1}{% No starred version, generate the usual \label + % Check first whether we're using cleveref + \IfValueTF{#2}{% + \@ifcleverefloadedtrue + \label[#2]{#3}% + \else + % ignore the optional argument provided by tracklabel, it's of use since cleveref is not loaded. + \label{#3}% + \fi + }{% No optional argument + \label{#3}% + }% + }% End of checking for starred command +} + + + +\DeclareExpandableDocumentCommand{\ObtainTrackedValueByLabel}{omm}{% + \zref@ifrefundefined{#2}{??}{% + \IfValueTF{#1}{% + \ObtainTrackedValueExp[\zref@extract{#2}{cps#1total}]{#1}{#3}% + }{% + \ObtainTrackedValueExp[\zref@extract{#2}{cps\zref@extract{#2}{counter}total}]{\zref@extract{#2}{counter}}{#3}% + }% + }% +} + + +\NewDocumentCommand{\RegisterCounters}{mm}{% + \RegisterTrackCounter{#1}{#2}% +} + + + +\@onlypreamble\RegisterTrackCounter +\@onlypreamble\RegisterMultipleTrackCounters \@onlypreamble\RegisterCounters + \makeatother |