diff options
Diffstat (limited to 'macros/latex/contrib/xsim/code/xsim.exercises.code.tex')
-rw-r--r-- | macros/latex/contrib/xsim/code/xsim.exercises.code.tex | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/macros/latex/contrib/xsim/code/xsim.exercises.code.tex b/macros/latex/contrib/xsim/code/xsim.exercises.code.tex index 2fc9e4d142..9ba49c6803 100644 --- a/macros/latex/contrib/xsim/code/xsim.exercises.code.tex +++ b/macros/latex/contrib/xsim/code/xsim.exercises.code.tex @@ -33,15 +33,16 @@ collections } +\seq_new:N \l__xsim_exercise_types_seq \seq_new:N \l__xsim_parameters_seq \seq_new:N \l__xsim_fixed_parameters_seq \seq_new:N \l__xsim_mandatory_parameters_seq -\prop_new:N \g__xsim_exercises_prop \int_gzero_new:N \g_xsim_id_int \int_gzero_new:N \g_xsim_max_id_int \tl_new:N \l_xsim_current_id_tl \tl_new:N \g_xsim_exercise_id_tl \tl_new:N \ExerciseID +\tl_new:N \ExerciseType \bool_new:N \l____xsim_print_bool % ---------------------------------------------------------------------------- @@ -73,6 +74,28 @@ } % ---------------------------------------------------------------------------- +% #1: type +% #2: parameter +% #3: value +\cs_new_protected:Npn \__xsim_set_parameter_type:nnn #1#2#3 + { \xsim_attribute_set:nnn {#1} {#2} {#3} } + +% #1: type +% #2: parameter +\cs_new:Npn \xsim_get_parameter:nn #1#2 + { \xsim_attribute_get:nn {#1} {#2} } +\cs_generate_variant:Nn \xsim_get_parameter:nn {o} + +% #1: type +% #2: parameter +\prg_new_conditional:Npnn \xsim_if_parameter_set:nn #1#2 {p,T,F,TF} + { + \xsim_attribute_if_set:nnTF {#1} {#2} + { \prg_return_true: } + { \prg_return_false: } + } + +% ---------------------------------------------------------------------------- \xsim_new_list:n {types} @@ -141,7 +164,7 @@ % #1: type \prg_new_conditional:Npnn \xsim_if_type:n #1 {p,T,F,TF} { - \prop_if_exist:cTF {l__xsim_#1_type_parameters_prop} + \seq_if_in:NnTF \l__xsim_exercise_types_seq {#1} { \prg_return_true: } { \prg_return_false: } } @@ -167,31 +190,18 @@ { \xsim_verbose:n { Setting~ parameter~ `#2'~ for~ type~ `#1'~ to~ `#3'. } - \prop_put:cnn {l__xsim_#1_type_parameters_prop} {#2} {#3} + \__xsim_set_parameter_type:nnn {#1} {#2} {#3} } } { \xsim_verbose:n { Setting~ parameter~ `#2'~ for~ type~ `#1'~ to~ `#3'. } - \prop_put:cnn {l__xsim_#1_type_parameters_prop} {#2} {#3} + \__xsim_set_parameter_type:nnn {#1} {#2} {#3} } } } \cs_generate_variant:Nn \xsim_set_parameter:nnn {nnx,nxx} -% #1: type -% #2: parameter -\cs_new:Npn \xsim_get_parameter:nn #1#2 - { \prop_item:cn {l__xsim_#1_type_parameters_prop} {#2} } -\cs_generate_variant:Nn \xsim_get_parameter:nn {o} - -\prg_new_conditional:Npnn \xsim_if_parameter_set:nn #1#2 {p,T,F,TF} - { - \prop_if_in:cnTF {l__xsim_#1_type_parameters_prop} {#2} - { \prg_return_true: } - { \prg_return_false: } - } - \cs_new:Npn \__xsim_get_parameter_tmp:n #1 {} \cs_generate_variant:Nn \__xsim_get_parameter_tmp:n {V} @@ -274,7 +284,7 @@ \cs_new_protected:Npn \xsim_define_exercise_type_variables:n #1 { - \prop_new:c {l__xsim_#1_type_parameters_prop} + \seq_put_right:Nn \l__xsim_exercise_types_seq {#1} \bool_new:c {l__xsim_#1_solution_print_bool} \bool_new:c {l__xsim_#1_exercise_print_bool} \bool_new:c {l__xsim_#1_exercise_use_bool} @@ -320,22 +330,22 @@ \xsim_if_parameter_set:nnF {#1} {exercises-name} { \xsim_set_parameters:nn {#1} - { exercises-name = \xsim_get_parameter:nn {#1} {exercise-name} s } + { exercises-name = \xsim_get_parameter:nn {#1} {exercise-name} s } } \xsim_if_parameter_set:nnF {#1} {solutions-name} { \xsim_set_parameters:nn {#1} - { solutions-name = \xsim_get_parameter:nn {#1} {solution-name} s } + { solutions-name = \xsim_get_parameter:nn {#1} {solution-name} s } } \xsim_if_parameter_set:nnF {#1} {counter} { \xsim_set_parameters:nx {#1} - { counter = \xsim_get_parameter:nn {#1} {exercise-env} } + { counter = \xsim_get_parameter:nn {#1} {exercise-env} } } \xsim_if_parameter_set:nnF {#1} {solution-counter} { \xsim_set_parameters:nx {#1} - { solution-counter = \xsim_get_parameter:nn {#1} {solution-env} } + { solution-counter = \xsim_get_parameter:nn {#1} {solution-env} } } \xsim_define_counters:n {#1} \xsim_verbose:n { Defining~ options~ for~ new~ exercise~ type~ `#1' } @@ -363,8 +373,12 @@ .code:n = \xsim_set_parameter:nnn {#1} {solution-template} {####1} , \xsim_get_parameter:nn {#1} {exercise-env} / name .code:n = \xsim_set_parameter:nnn {#1} {exercise-name} {####1} , + \xsim_get_parameter:nn {#1} {exercise-env} s / name + .code:n = \xsim_set_parameter:nnn {#1} {exercises-name} {####1} , \xsim_get_parameter:nn {#1} {solution-env} / name .code:n = \xsim_set_parameter:nnn {#1} {solution-name} {####1} , + \xsim_get_parameter:nn {#1} {solution-env} s / name + .code:n = \xsim_set_parameter:nnn {#1} {solutions-name} {####1} , \xsim_get_parameter:nn {#1} {exercise-env} / heading .code:n = \xsim_set_parameter:nnn {#1} {exercise-heading} {####1} , \xsim_get_parameter:nn {#1} {solution-env} / heading @@ -395,6 +409,7 @@ \int_compare:nF { \g_xsim_max_id_int > \g_xsim_id_int } { \int_gset_eq:NN \g_xsim_max_id_int \g_xsim_id_int } \tl_gset:Nx \g_xsim_exercise_id_tl { \int_use:N \g_xsim_id_int } + \tl_gset:Nn \g_xsim_exercise_type_tl {#1} % save the goal values from the auxiliary files: \xsim_foreach_goal:n { @@ -467,11 +482,8 @@ chapter = \thechapter } } - % \tl_gclear:N \g_xsim_exercise_id_tl - % \xsim_gsave_property:nVnN {#1} \l__xsim_tmpa_tl {id} - % \g_xsim_exercise_id_tl - \tl_gset_eq:NN \ExerciseID \g_xsim_exercise_id_tl - \tl_gset:Nn \ExerciseType {#1} + \tl_set_eq:NN \ExerciseID \g_xsim_exercise_id_tl + \tl_set:Nn \ExerciseType {#1} \xsim_verbose:x { Starting~ exercise~ type~ `#1' with~ id~ @@ -505,7 +517,11 @@ } } -\cs_new_protected:Npn \xsim_stop_exercise:n #1 {} +\cs_new_protected:Npn \xsim_stop_exercise:n #1 + { + \xsim_if_insert_mode:F + { \tl_gset_eq:NN \g_xsim_exercise_id_tl \ExerciseID } + } % ---------------------------------------------------------------------------- % #1: type @@ -615,3 +631,6 @@ \file_input_stop: 2020/02/21 - implement issue #2 +2020/03/01 - add options `<ex-env>s/name` and `<sol-env>/name` +2020/03/07 - set \ExerciseID and \ExerciseType only locally +2020/03/14 - performance optimizations |