diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/xsim/xsim.goals.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/xsim/xsim.goals.code.tex | 92 |
1 files changed, 84 insertions, 8 deletions
diff --git a/Master/texmf-dist/tex/latex/xsim/xsim.goals.code.tex b/Master/texmf-dist/tex/latex/xsim/xsim.goals.code.tex index cf7975c4bd0..6b17d2bc3f5 100644 --- a/Master/texmf-dist/tex/latex/xsim/xsim.goals.code.tex +++ b/Master/texmf-dist/tex/latex/xsim/xsim.goals.code.tex @@ -49,6 +49,7 @@ {#1} \seq_put_right:Nn \l__xsim_goals_seq {#1} \fp_gzero_new:c {g__xsim_goal_#1_fp} + \bool_new:c {l__xsim_goal_#1_given_bool} \fp_gzero_new:c {l__xsim_current_goal_#1_fp} \fp_if_exist:cF {g__xsim_total_goal_#1_fp} { \fp_new:c {g__xsim_total_goal_#1_fp} } @@ -73,6 +74,16 @@ { \prg_return_false: } } +\prg_new_conditional:Npnn \xsim_if_goal_given:n #1 {p,T,F,TF} + { + \bool_if:cTF {l__xsim_goal_#1_given_bool} + { \prg_return_true: } + { \prg_return_false: } + } + +\cs_new_protected:Npn \xsim_goal_given:n #1 + { \bool_set_true:c {l__xsim_goal_#1_given_bool} } + % #1: exercise type % #2: id % #3: goal @@ -99,6 +110,28 @@ \cs_new_protected:Npn \xsim_foreach_goal:n #1 { \seq_map_inline:Nn \l__xsim_goals_seq {#1} } +% #1: type +% #2: id +\cs_new_protected:Npn \xsim_synchronize_goals:nn #1#2 + { + \xsim_foreach_goal:n + { + \xsim_if_property_set:nnnTF {#1} {#2} {##1} + { + \xsim_set_property:nnnx {#1} {#2} {##1} + { \xsim_temporary_goal_get:nnn {#1} {#2} {##1} } + } + { + \fp_compare:nNnT + { \xsim_temporary_goal_get:nnn {#1} {#2} {##1} } > {0} + { + \xsim_set_property:nnnx {#1} {#2} {##1} + { \xsim_temporary_goal_get:nnn {#1} {#2} {##1} } + } + } + } + } + % #1: exercise type % #2: id % #3: goal @@ -108,9 +141,10 @@ \xsim_if_goal_exist:nT {#3} { \xsim_verbose:n { Adding~ `#4'~ to~ `#3'~ goal~ of~ #1~ #2 } - \fp_gadd:cn {g__xsim_goal_#3_fp} {#4} - \fp_gadd:cn {g__xsim_#1_goal_#3_fp} {#4} - \fp_add:cn {l__xsim_current_goal_#3_fp} {#4} + % \fp_gadd:cn {g__xsim_goal_#3_fp} {#4} + % \fp_gadd:cn {g__xsim_#1_goal_#3_fp} {#4} + % \fp_add:cn {l__xsim_current_goal_#3_fp} {#4} + \xsim_temporary_goal_add:nnnn {#1} {#2} {#3} {#4} } } \cs_generate_variant:Nn \xsim_addto_goal:nnnn {xx,nVnx} @@ -129,6 +163,46 @@ \cs_generate_variant:Nn \xsim_if_goal_value:nnnnTF {xx} % ---------------------------------------------------------------------------- +% we need some kind of temporary variable to be able to set goals both as +% option to exercises and within the exercise body + +% #1: type +% #2: id +% #3: goal +\cs_new_protected:Npn \xsim_temporary_goal_new:nnn #1#2#3 + { \fp_new:c {g__xsim_goal_#3_#1_#2_fp} } +\cs_generate_variant:Nn \xsim_temporary_goal_new:nnn {nV} + +% #1: type +% #2: id +% #3: goal +% #4: value +\cs_new_protected:Npn \xsim_temporary_goal_set:nnnn #1#2#3#4 + { \fp_gset:cn {g__xsim_goal_#3_#1_#2_fp} {#4} } +\cs_generate_variant:Nn \xsim_temporary_goal_set:nnnn {nV} + +% #1: type +% #2: id +% #3: goal +% #4: value +\cs_new_protected:Npn \xsim_temporary_goal_add:nnnn #1#2#3#4 + { \fp_gadd:cn {g__xsim_goal_#3_#1_#2_fp} {#4} } +\cs_generate_variant:Nn \xsim_temporary_goal_add:nnnn {nV} + +% #1: type +% #2: id +% #3: goal +\cs_new:Npn \xsim_temporary_goal_get:nnn #1#2#3 + { \fp_to_decimal:c {g__xsim_goal_#3_#1_#2_fp} } +\cs_generate_variant:Nn \xsim_temporary_goal_get:nnn {nV} + +% #1: type +% #2: id +% #3: goal +\cs_new_protected:Npn \__xsim_temporary_goal_show:nnn #1#2#3 + { \fp_show:c {g__xsim_goal_#3_#1_#2_fp} } + +% ---------------------------------------------------------------------------- % a function which can be used to modify how the numbers of a goal are % printed: \cs_new_protected:Npn \__xsim_print_goal:n #1 {#1} @@ -254,12 +328,12 @@ % #1: exercise type % #2: goal % #3: value -\xsim_new_aux_cs:cpn {goal} #1#2#3 +\xsim_new_aux_property:cpn {goal} #1#2#3 { \fp_gset:cn {g__xsim_total_#1_goal_#2_fp} {#3} } % #1: goal % #2: value -\xsim_new_aux_cs:cpn {totalgoal} #1#2 +\xsim_new_aux_property:cpn {totalgoal} #1#2 { \fp_gset:cn {g__xsim_total_goal_#1_fp} {#2} } \xsim_at_begin_document:n @@ -278,7 +352,7 @@ { \xsim_foreach_exercise_type:n { - \xsim_add_cs_to_aux:nn {goal} + \xsim_add_property_to_aux:nn {goal} { {##1} {#1} { \fp_to_decimal:c {g__xsim_##1_goal_#1_fp} } } } \tl_set:Nx \l__xsim_tmpa_tl @@ -286,7 +360,7 @@ \tl_set:Nx \l__xsim_tmpb_tl { \fp_to_decimal:c {g__xsim_total_goal_recorded_#1_fp} } \tl_if_eq:NNF \l__xsim_tmpa_tl \l__xsim_tmpb_tl { \xsim_rerun: } - \xsim_add_cs_to_aux:nn {totalgoal} + \xsim_add_property_to_aux:nn {totalgoal} { {#1} { \fp_to_decimal:c {g__xsim_goal_#1_fp} } } } } @@ -306,4 +380,6 @@ % ---------------------------------------------------------------------------- \file_input_stop: -2019/01/30 bug fix (cf. https://texwelt.de/wissen/fragen/24101/) +2019/01/30 - bug fix (cf. https://texwelt.de/wissen/fragen/24101/) +2020/02/20 - add temporary variables for the whole subpoint thing + (cf. issue #2) |