From f0026818378558a91000c3b606f3cbf88c5e6db0 Mon Sep 17 00:00:00 2001 From: Clemens Niederberger Date: Wed, 7 Apr 2021 11:41:45 +0200 Subject: [PATCH] counter exercises in a collection --- HISTORY | 2 ++ code/xsim.collections.code.tex | 21 ++++++++++++++++++++- code/xsim.sty | 21 ++++++++++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index 2f501fc..090a264 100644 --- a/HISTORY +++ b/HISTORY @@ -189,3 +189,5 @@ HISTORY: solution files - add option /use-unmatched - document option `blank/fill' + - add counter foreach type and collection that holds the + number of exercises of a type in a collection diff --git a/code/xsim.collections.code.tex b/code/xsim.collections.code.tex index 62b8cf0..dd02de5 100644 --- a/code/xsim.collections.code.tex +++ b/code/xsim.collections.code.tex @@ -54,8 +54,26 @@ \xsim_attribute_set:nnn {collection:conditions} {#1} {#2} \seq_gput_right:Nn \g__xsim_collections_seq {#1} \xsim_new_list:n {collection:#1} + \xsim_before_begin_document:n + { + \xsim_foreach_exercise_type:n + { + \int_new:c {g_xsim_collection_##1_in_#1_int} + \newcounter {total##1in#1} + } + } \xsim_at_end_document:n - { \xsim_update_list:n {collection:#1} } + { + \xsim_update_list:n {collection:#1} + \xsim_foreach_exercise_type:n + { + \xsim_write_to_aux:x + { + \token_to_str:N \setcounter {total##1in#1} + { \int_use:c {g_xsim_collection_##1_in_#1_int} } + } + } + } } } @@ -247,6 +265,7 @@ { \clist_put_right:Nn \l__xsim_tmpa_clist {#1} } \xsim_set_property:nnnV {#2} {#3} {collections} \l__xsim_tmpa_clist \xsim_add_to_list:nn {collection:#1} {#2-#3} + \int_gincr:c {g_xsim_collection_#2_in_#1_int} } % ---------------------------------------------------------------------------- diff --git a/code/xsim.sty b/code/xsim.sty index 4303806..bdb0e0e 100644 --- a/code/xsim.sty +++ b/code/xsim.sty @@ -3635,8 +3635,26 @@ \xsim_attribute_set:nnn {collection:conditions} {#1} {#2} \seq_gput_right:Nn \g__xsim_collections_seq {#1} \xsim_new_list:n {collection:#1} + \xsim_before_begin_document:n + { + \xsim_foreach_exercise_type:n + { + \int_new:c {g_xsim_collection_##1_in_#1_int} + \newcounter {total##1in#1} + } + } \xsim_at_end_document:n - { \xsim_update_list:n {collection:#1} } + { + \xsim_update_list:n {collection:#1} + \xsim_foreach_exercise_type:n + { + \xsim_write_to_aux:x + { + \token_to_str:N \setcounter {total##1in#1} + { \int_use:c {g_xsim_collection_##1_in_#1_int} } + } + } + } } } @@ -3828,6 +3846,7 @@ { \clist_put_right:Nn \l__xsim_tmpa_clist {#1} } \xsim_set_property:nnnV {#2} {#3} {collections} \l__xsim_tmpa_clist \xsim_add_to_list:nn {collection:#1} {#2-#3} + \int_gincr:c {g_xsim_collection_#2_in_#1_int} } % ----------------------------------------------------------------------------