Skip to content

Commit

Permalink
v0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
cgnieder committed Mar 17, 2020
1 parent 2be67f7 commit cbf26b9
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 140 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--------------------------------------------------------------------------
XSIM 2020/03/11 v0.19
XSIM 2020/03/16 v0.19
XSIMVERB 2019/12/29 v0.1a

eXercise Sheets IMproved
Expand Down
51 changes: 19 additions & 32 deletions code/xsim.auxfile.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,8 @@

\xsim_new_aux_property:cpn {readaux}
{
% can I do this with expl3?
% cf. issue #60
\InputIfFileExists { \c_sys_jobname_str .xsim }
{ \xsim_verbose:n { Reading~ \c_sys_jobname_str .xsim } }
{
\xsim_verbose:n { \c_sys_jobname_str .xsim~ not~ found.}
\xsim_rerun:
}
\file_if_exist:nT { \c_sys_jobname_str .xsim }
{ \file_input:n { \c_sys_jobname_str .xsim } }
}

% ----------------------------------------------------------------------------
Expand All @@ -106,27 +100,6 @@
split-aux-lists .initial:n = ||
}

\cs_new_protected:Npn \__xsim_set_list_value:nn #1#2
{
\cs_undefine:c {____xsim_list_ \tl_to_str:n {#1!#2} :}
\cs_new:cpn {____xsim_list_ \tl_to_str:n {#1!#2} :} {}
}

\cs_new_protected:Npn \__xsim_unset_list_value:nn #1#2
{ \cs_undefine:c {____xsim_list_ \tl_to_str:n {#1!#2} :} }

% check if in list:
% #1: name
% #2: entry
\prg_new_conditional:Npnn \xsim_if_in_list:nn #1#2 {p,T,F,TF}
{
\cs_if_exist:cTF {____xsim_list_ \tl_to_str:n {#1!#2} :}
{ \prg_return_true: }
{ \prg_return_false: }
}
\cs_generate_variant:Nn \xsim_if_in_list:nnTF {nx}
\cs_generate_variant:Nn \xsim_if_in_list:nnT {nx}

% define list:
% #1: name
\cs_new_protected:Npn \xsim_new_list:n #1
Expand All @@ -142,7 +115,7 @@
\l__xsim_split_aux_lists_str
{ \tl_to_str:n {##1} }
\seq_map_inline:cn {g__xsim_list_#1_seq}
{ \__xsim_set_list_value:nn {#1} {####1} }
{ \xsim_attribute_set:nnn {#1} {####1} {} }
}
}
\xsim_at_begin_document:n
Expand All @@ -165,6 +138,7 @@
{
\xsim_verbose:n { Adding~ `#2'~ to~ list~ `#1'. }
\str_set:Nn \l__xsim_tmpa_str {#2}
\xsim_attribute_set:nnn {#1} {#2} {}
\seq_if_in:cVT {g__xsim_list_#1_seq} \l__xsim_tmpa_str
{ \seq_gremove_all:cV {g__xsim_list_#1_seq} \l__xsim_tmpa_str }
\seq_gput_right:cV {g__xsim_list_#1_seq} \l__xsim_tmpa_str
Expand All @@ -177,14 +151,27 @@
{
\xsim_verbose:n { Removing~ `#2'~ to~ list~ `#1'. }
\str_set:Nn \l__xsim_tmpa_str {#2}
\__xsim_unset_list_value:nn {#1} {#2}
\xsim_attribute_if_set:nnT {#1} {#2}
{ \xsim_attribute_unset:nn {#1} {#2} }
\seq_if_in:cVT {g__xsim_list_#1_seq} \l__xsim_tmpa_str
{ \seq_gremove_all:cV {g__xsim_list_#1_seq} \l__xsim_tmpa_str }
\seq_if_in:cVT {g__xsim_list_recorded#1_seq} \l__xsim_tmpa_str
{ \seq_gremove_all:cV {g__xsim_list_recorded_#1_seq} \l__xsim_tmpa_str }
}
\cs_generate_variant:Nn \xsim_remove_from_list:nn {nx}

% check if in list:
% #1: name
% #2: entry
\prg_new_conditional:Npnn \xsim_if_in_list:nn #1#2 {p,T,F,TF}
{
\xsim_attribute_if_set:nnTF {#1} {#2}
{ \prg_return_true: }
{ \prg_return_false: }
}
\cs_generate_variant:Nn \xsim_if_in_list:nnTF {nx}
\cs_generate_variant:Nn \xsim_if_in_list:nnT {nx}

\bool_new:N \l__xsim_empty_lists_bool
\cs_new_protected:Npn \xsim_empty_lists:
{ \bool_set_true:N \l__xsim_empty_lists_bool }
Expand Down Expand Up @@ -231,4 +218,4 @@

% ----------------------------------------------------------------------------
\file_input_stop:
2020/03/10 - performance optimizations
2020/03/16 - performance optimizations
82 changes: 79 additions & 3 deletions code/xsim.base.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
\cs_generate_variant:Nn \seq_if_in:NnT {cV}
\cs_generate_variant:Nn \seq_gremove_all:Nn {cV}
\cs_generate_variant:Nn \seq_gput_right:Nn {cV}
\cs_generate_variant:Nn \prop_put:Nnn {cxx}
\cs_generate_variant:Nn \prop_put:Nnn {Nnx,cxx}
\cs_generate_variant:Nn \prop_gput:Nnn {Nx,Nnx,cxx}
\cs_generate_variant:Nn \prop_item:Nn {c}
\cs_generate_variant:Nn \prop_if_in:NnTF {Nx}
Expand All @@ -68,12 +68,11 @@
\cs_generate_variant:Nn \tl_if_eq:nnTF {ff,V}
\cs_generate_variant:Nn \tl_if_eq:nnT {x}
\cs_generate_variant:Nn \tl_if_blank:nTF {f}
\cs_generate_variant:Nn \tl_set_rescan:Nnn {Nnn}
\cs_generate_variant:Nn \tl_set_rescan:Nnn {Nnx}
\cs_generate_variant:Nn \iow_now:Nn {NV}
\cs_generate_variant:Nn \str_if_eq:nnT {x}
\cs_generate_variant:Nn \str_if_eq:nnF {xx}
\cs_generate_variant:Nn \str_if_eq_p:nn {e}
\cs_generate_variant:Nn \iow_now:Nn {NV}
\cs_generate_variant:Nn \prg_new_protected_conditional:Npnn {c}

% ----------------------------------------------------------------------------
Expand Down Expand Up @@ -136,6 +135,13 @@
{ \prg_return_false: }
}

\prg_new_conditional:Npnn \xsim_if_debug: {p,T,F,TF}
{
\bool_if:NTF \g__xsim_debug_bool
{ \prg_return_true: }
{ \prg_return_false: }
}

\prg_new_conditional:Npnn \xsim_if_package_blank: {p,T,F,TF}
{
\bool_if:NTF \g__xsim_blank_bool
Expand Down Expand Up @@ -198,8 +204,78 @@

% ----------------------------------------------------------------------------

\msg_new:nnn {xsim} {attribute-not-set}
{ The~ attribute~ `#1'~ is~ not~ set~ \msg_line_context: }

% #1: attribute
% #2: item
\cs_new_protected:Npn \xsim_attribute_new:nn #1#2
{ \cs_new:cpn {____xsim_attribute_ \tl_to_str:n {#1::#2} :} {} }

% #1: attribute
% #2: item
% #3: value
\cs_new_protected:Npn \xsim_attribute_set:nnn #1#2#3
{ \cs_gset:cpx {____xsim_attribute_ \tl_to_str:n {#1::#2} :} { \exp_not:n {#3} } }
\cs_generate_variant:Nn \xsim_attribute_set:nnn {nnx}

% #1: attribute
% #2: item
\cs_new_protected:Npn \xsim_attribute_unset:nn #1#2
{ \cs_undefine:c {____xsim_attribute_ \tl_to_str:n {#1::#2} :} }

% #1: attribute
% #2: item
\cs_new:Npn \xsim_attribute_get:nn #1#2
{
\cs_if_exist:cTF {____xsim_attribute_ \tl_to_str:n {#1::#2} :}
{ \use:c {____xsim_attribute_ \tl_to_str:n {#1::#2} :} }
{
\xsim_if_debug:T
{ \msg_expandable_error:nnn {xsim} {attribute-not-set} {#1::#2} }
}
}

% #1: attribute
% #2: item
\prg_new_conditional:Npnn \xsim_attribute_if_set:nn #1#2 {p,T,F,TF}
{
\cs_if_exist:cTF {____xsim_attribute_ \tl_to_str:n {#1::#2} :}
{ \prg_return_true: }
{ \prg_return_false: }
}

% #1: attribute
% #2: item
\prg_new_conditional:Npnn \__xsim_if_attribute_eq:nnn #1#2#3 {p,T,F,TF}
{
\tl_if_eq:enTF
{ \use:c {____xsim_attribute_ \tl_to_str:n {#1::#2} :} }
{#3}
{ \prg_return_true: }
{ \prg_return_false: }
}

% #1: attribute
% #2: item
\cs_new_protected:Npn \xsim_attribute_show:nn #1#2
{
\iow_term:n {}
\iow_term:x
{
\c_space_tl \c_space_tl
\tl_to_str:n {#1::#2}
\c_space_tl \c_space_tl == \c_space_tl \c_space_tl
{\use:c {____xsim_attribute_ \tl_to_str:n {#1::#2} :}}
}
\iow_term:n {}
}

% ----------------------------------------------------------------------------

\cs_new_protected:Npn \xsim_setup:n #1
{ \keys_set:nn {xsim} {#1} }

% ----------------------------------------------------------------------------
\file_input_stop:
2020/03/15 - alternative to property lists for performance optimizations
29 changes: 16 additions & 13 deletions code/xsim.collections.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

\xsim_load_modules:n {base}

\prop_new:N \g__xsim_collections_prop
\seq_new:N \g__xsim_collections_seq
\bool_new:N \l____xsim_active_bool

\msg_new:nnn {xsim} {collection-exists}
Expand Down Expand Up @@ -66,7 +66,8 @@
{ \msg_error:nnn {xsim} {collection-exists} {#1} }
{
\xsim_verbose:n { Declaring~ new~ collection~ `#1'. }
\prop_gput:Nnn \g__xsim_collections_prop {#1} { \c_false_bool }
\xsim_attribute_set:nnn {collection} {#1} { \c_false_bool }
\seq_gput_right:Nn \g__xsim_collections_seq {#1}
\xsim_new_list:n {collection:#1}
\seq_new:c {g__xsim_collection_#1_seq}
}
Expand All @@ -75,15 +76,17 @@
% #1: collection name
\prg_new_conditional:Npnn \xsim_if_collection_exist:n #1 {T,F,TF}
{
\prop_if_in:NnTF \g__xsim_collections_prop {#1}
\seq_if_in:NnTF \g__xsim_collections_seq {#1}
{ \prg_return_true: }
{ \prg_return_false: }
}

\xsim_new_collection:n {all~ exercises}

\cs_new_protected:Npn \xsim_foreach_collection:n #1
{ \prop_map_inline:Nn \g__xsim_collections_prop {#1} }
{ \seq_map_inline:Nn \g__xsim_collections_seq {#1} }

\cs_new:Npn \xsim_collection_map_break: { \seq_map_break: }

% ----------------------------------------------------------------------------

Expand All @@ -96,7 +99,7 @@
}
{
\xsim_verbose:n { Activating~ collection~ `#1'. }
\prop_gput:Nnn \g__xsim_collections_prop {#1} { \c_true_bool }
\xsim_attribute_set:nnn {collection} {#1} { \c_true_bool }
\tl_if_blank:nF {#2}
{ \seq_gput_right:cn {g__xsim_collection_#1_seq} {#2} }
}
Expand All @@ -111,8 +114,8 @@
\xsim_if_collection_active:nTF {#1}
{
\xsim_verbose:n { Deactivating~ collection~ `#1'. }
\prop_gput:Nnn \g__xsim_collections_prop {#1} { \c_false_bool }
\seq_gclear:c {g__xsim_collection_#1_seq}
\xsim_attribute_set:nnn {collection} {#1} { \c_false_bool }
% \seq_gclear:c {g__xsim_collection_#1_seq}
}
{ % TODO: warning
}
Expand Down Expand Up @@ -161,7 +164,7 @@
\seq_if_empty:cTF {g__xsim_collection_#1_seq}
{ \__xsim_add_to_collection:nnn {#1} {#2} {#3} }
{
\seq_if_in:cnT {g__xsim_collection_#1_seq} {#2}
\seq_if_in:cnF {g__xsim_collection_#1_seq} {#2}
{ \__xsim_add_to_collection:nnn {#1} {#2} {#3} }
}
}
Expand Down Expand Up @@ -349,11 +352,11 @@
% #1: collection name
\prg_new_conditional:Npnn \xsim_if_collection_active:n #1 {T,F,TF}
{
\prop_if_in:NnTF \g__xsim_collections_prop {#1}
\xsim_attribute_if_set:nnTF {collection} {#1}
{
\bool_lazy_and:nnTF
{ !\str_if_eq_p:en {#1} {all~ exercises} }
{ \prop_item:Nn \g__xsim_collections_prop {#1} }
{ \xsim_attribute_get:nn {collection} {#1} }
{ \prg_return_true: }
{ \prg_return_false: }
}
Expand All @@ -363,12 +366,12 @@
\prg_new_protected_conditional:Npnn \xsim_if_collections_active: {T,F,TF}
{
\bool_set_false:N \l____xsim_active_bool
\prop_map_inline:Nn \g__xsim_collections_prop
\xsim_foreach_collection:n
{
\xsim_if_collection_active:nT {##1}
{
\bool_set_true:N \l____xsim_active_bool
\prop_map_break:
\xsim_collection_map_break:
}
}
\bool_if:NTF \l____xsim_active_bool
Expand All @@ -381,7 +384,7 @@
\xsim_at_begin_document:n
{
\xsim_get_collections:
\xsim_activate_collection:n {all~ exercises}
\xsim_activate_collection:n {all~ exercises}
}

\xsim_at_end_document:n
Expand Down
3 changes: 0 additions & 3 deletions code/xsim.environments.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
\tl_new:N \ExerciseText
\tl_set:Nn \ExerciseText { \msg_error:nn {xsim} {only-in-solution} }

\cs_generate_variant:Nn \tl_set_rescan:Nnn {Nnx}
\cs_generate_variant:Nn \prop_put:Nnn {Nnx}

% ----------------------------------------------------------------------------

\msg_new:nnn {xsim} {only-in-solution}
Expand Down
16 changes: 9 additions & 7 deletions code/xsim.exercises.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
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
Expand Down Expand Up @@ -78,17 +78,19 @@
% #2: parameter
% #3: value
\cs_new_protected:Npn \__xsim_set_parameter_type:nnn #1#2#3
{ \cs_set:cpn {__xsim_parameter_ \tl_to_str:n {#1!#2} :} {#3} }
{ \xsim_attribute_set:nnn {#1} {#2} {#3} }

% #1: type
% #2: parameter
\cs_new:Npn \xsim_get_parameter:nn #1#2
{ \cs_if_exist_use:c {__xsim_parameter_ \tl_to_str:n {#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}
{
\cs_if_exist:cTF {__xsim_parameter_ \tl_to_str:n {#1!#2} :}
\xsim_attribute_if_set:nnTF {#1} {#2}
{ \prg_return_true: }
{ \prg_return_false: }
}
Expand Down Expand Up @@ -162,7 +164,7 @@
% #1: type
\prg_new_conditional:Npnn \xsim_if_type:n #1 {p,T,F,TF}
{
\cs_if_exist:cTF {--__xsim_#1_type_parameter:}
\seq_if_in:NnTF \l__xsim_exercise_types_seq {#1}
{ \prg_return_true: }
{ \prg_return_false: }
}
Expand Down Expand Up @@ -282,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}
Expand Down Expand Up @@ -631,4 +633,4 @@
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/11 - performance optimizations
2020/03/14 - performance optimizations
Loading

0 comments on commit cbf26b9

Please sign in to comment.