summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xsim/code
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-10-08 03:00:28 +0000
committerNorbert Preining <norbert@preining.info>2019-10-08 03:00:28 +0000
commite5ffc42ed260285f76383ae18dd0f4a603c07fa8 (patch)
tree7d901aebae17ed14f1c9812c9339a88d68dc74e4 /macros/latex/contrib/xsim/code
parentba86549c94b1e8b6b19bc82b01e85a7e513e7586 (diff)
CTAN sync 201910080300
Diffstat (limited to 'macros/latex/contrib/xsim/code')
-rw-r--r--macros/latex/contrib/xsim/code/xsim.environments.code.tex171
-rw-r--r--macros/latex/contrib/xsim/code/xsim.solutions.code.tex3
-rw-r--r--macros/latex/contrib/xsim/code/xsim.sty33
-rw-r--r--macros/latex/contrib/xsim/code/xsim.verbwrite.code.tex15
4 files changed, 170 insertions, 52 deletions
diff --git a/macros/latex/contrib/xsim/code/xsim.environments.code.tex b/macros/latex/contrib/xsim/code/xsim.environments.code.tex
index 49976aa53f..b9235ba555 100644
--- a/macros/latex/contrib/xsim/code/xsim.environments.code.tex
+++ b/macros/latex/contrib/xsim/code/xsim.environments.code.tex
@@ -29,6 +29,20 @@
\xsim_load_modules:n {templates,verbwrite}
+\xsim_if_write_to_files:F
+ {
+ \xsim_declare_property:nnnn
+ { \c_false_bool }
+ { \c_false_bool }
+ { \c_false_bool }
+ {solution-body}
+ \xsim_declare_property:nnnn
+ { \c_false_bool }
+ { \c_false_bool }
+ { \c_false_bool }
+ {exercise-body}
+ }
+
\tl_new:N \l__xsim_file_name_signature_tl
\tl_new:N \l__xsim_file_path_tl
\tl_new:N \l__xsim_file_path_and_name_tl
@@ -40,6 +54,9 @@
\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}
@@ -52,7 +69,7 @@
\keys_define:nn {xsim}
{
- path .tl_set:N = \l__xsim_file_path_tl ,
+ path .tl_set:N = \l__xsim_file_path_tl ,
file-extension .tl_set:N = \l__xsim_file_extension_tl ,
file-extension .initial:n = tex
}
@@ -139,11 +156,29 @@
\cs_generate_variant:Nn \__xsim_file_info:nnnnn {nnnVV}
% ----------------------------------------------------------------------------
+% #1: type
+% #2: id
+% #3: exercise|solution
+% #4: potential environment body
+\cs_new_protected:Npn \xsim_save_environment_body:nnnn #1#2#3#4
+ {
+ \xsim_if_write_to_files:TF
+ { \__xsim_write_environment_body:nnn {#1} {#2} {#3} }
+ { \__xsim_save_environment_body:nnnn {#1} {#2} {#3} {#4} }
+ }
+\cs_new_protected:Npn \xsim_save_environment_body_end:
+ {
+ \xsim_if_write_to_files:TF
+ { \__xsim_write_environment_body_end: }
+ { \__xsim_save_environment_body_end: }
+ }
+
+% writing to files:
% #1: type
% #2: id
% #3: exercise|solution
-\cs_new_protected:Npn \xsim_save_environment_body:nnn #1#2#3
+\cs_new_protected:Npn \__xsim_write_environment_body:nnn #1#2#3
{
\xsim_verbose:n
{ Starting~ to~ write~ #3~ environment~ type~ `#1'~ id~ `#2' }
@@ -157,9 +192,22 @@
\l__xsim_file_path_and_name_tl
}
-\cs_new_protected:Npn \xsim_save_environment_body_end:
+\cs_new_protected:Npn \__xsim_write_environment_body_end:
{ \xsim_file_write_stop: }
+% saving to property lists:
+% #1: type
+% #2: id
+% #3: exercise|solution
+% #4: environment body
+\cs_new_protected:Npn \__xsim_save_environment_body:nnnn #1#2#3#4
+ {
+ \xsim_verbose:n { Saving~ #3~ environment~ type~ `#1'~ id~ `#2' }
+ \xsim_set_property:nnnn {#1} {#2} {#3-body} {#4}
+ }
+
+\cs_new:Npn \__xsim_save_environment_body_end: { }
+
% ----------------------------------------------------------------------------
% #1: type
% #2: exercise|solution
@@ -206,9 +254,10 @@
% #1: type
% #2: id
% #3: exercise|solution
-\cs_new_protected:Npn \xsim_start_environment:nnn #1#2#3
- { \xsim_save_environment_body:nnn {#1} {#2} {#3} }
-\cs_generate_variant:Nn \xsim_start_environment:nnn {nV}
+% #4: potential enironment body
+\cs_new_protected:Npn \xsim_start_environment:nnnn #1#2#3#4
+ { \xsim_save_environment_body:nnnn {#1} {#2} {#3} {#4} }
+\cs_generate_variant:Nn \xsim_start_environment:nnnn {nV}
% #1: type
% #2: id
@@ -237,12 +286,16 @@
{begin}
{ \xsim_get_parameter:nn {#1} {#3-template} }
\xsim_use_hook:nnn {#1} {#3} {begin}
- \file_if_exist:nTF { \exp_not:V \l__xsim_file_path_and_name_tl }
- { \file_input:n { \exp_not:V \l__xsim_file_path_and_name_tl } }
+ \xsim_if_write_to_files:TF
{
- \xsim_verbose:n
- { File~ `\l__xsim_file_path_and_name_tl'~ doesn't~ exist. }
+ \file_if_exist:nTF { \exp_not:V \l__xsim_file_path_and_name_tl }
+ { \file_input:n { \exp_not:V \l__xsim_file_path_and_name_tl } }
+ {
+ \xsim_verbose:n
+ { File~ `\l__xsim_file_path_and_name_tl'~ doesn't~ exist. }
+ }
}
+ { \xsim_get_property:nnn {#1} {#2} {#3-body} }
\xsim_use_hook:nnn {#1} {#3} {end}
\xsim_use_template:nn
{end}
@@ -254,12 +307,34 @@
% #1: type
% #2: id
+% #3: exercise|solution
+\prg_new_protected_conditional:Npnn \xsim_if_exists:nnn #1#2#3 {T,F,TF}
+ {
+ \xsim_if_write_to_files:TF
+ {
+ \__xsim_set_file_signature:nnn {#1} {#2} {#3}
+ \file_if_exist:VTF \l__xsim_file_path_and_name_tl
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+ {
+ \xsim_if_property_exist:nTF {#3-body}
+ {
+ \xsim_if_property_set:nnnTF {#1} {#2} {#3-body}
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+ { \prg_return_false: }
+ }
+ }
+
+% #1: type
+% #2: id
% #3: options
% #4: exercise|solution
\cs_new_protected:Npn \xsim_insert:nnnn #1#2#3#4
{
- \__xsim_set_file_signature:nnn {#1} {#2} {#4}
- \file_if_exist:VTF \l__xsim_file_path_and_name_tl
+ \xsim_if_exists:nnnTF {#1} {#2} {#4}
{
\xsim_verbose:n
{ Inserting~ #4~ type~ `#1'~ id~ `#2'. }
@@ -294,9 +369,16 @@
}
\str_if_eq:nnT {#4} {solution}
{
- \__xsim_set_file_signature:nnn {#1} {#2} {exercise}
- \file_get:nnN {\l__xsim_file_path_and_name_tl} {} \ExerciseText
- \tl_trim_spaces:N \ExerciseText
+ \xsim_if_write_to_files:TF
+ {
+ \__xsim_set_file_signature:nnn {#1} {#2} {exercise}
+ \file_get:nnN {\l__xsim_file_path_and_name_tl} {} \ExerciseText
+ \tl_trim_spaces:N \ExerciseText
+ }
+ {
+ \tl_set:Nx \ExerciseText
+ { \xsim_get_property:nnn {#1} {#2} {exercise-body} }
+ }
}
\use:x
{
@@ -315,8 +397,11 @@
\group_end:
}
{
- \xsim_verbose:x
- { File~ `\l__xsim_file_path_and_name_tl'~ doesn't~ exist. }
+ \xsim_if_write_to_files:T
+ {
+ \xsim_verbose:x
+ { File~ `\l__xsim_file_path_and_name_tl'~ doesn't~ exist. }
+ }
}
}
\cs_generate_variant:Nn \xsim_insert:nnnn {nV,VV,nnnV}
@@ -327,8 +412,12 @@
\cs_new_protected:Npn \xsim_input:nnn #1#2#3
{
\group_begin:
- \__xsim_set_file_signature:nnn {#1} {#2} {#3}
- \file_input:n { \l__xsim_file_path_and_name_tl }
+ \xsim_if_write_to_files:TF
+ {
+ \__xsim_set_file_signature:nnn {#1} {#2} {#3}
+ \file_input:n { \l__xsim_file_path_and_name_tl }
+ }
+ { \xsim_get_property:nnn {#1} {#2} {#3-body} }
\group_end:
}
\cs_generate_variant:Nn \xsim_input:nnn {oo}
@@ -355,23 +444,46 @@
\xsim_new_hook:nnn {#1} {#2} {end}
\xsim_new_hook:nnn {#1} {#2} {post}
\xsim_new_hook:nnn {#1} {#2} {print-false}
- \NewDocumentEnvironment
- { \xsim_get_parameter:nn {#1} {#2-env} } {o}
+ \xsim_if_write_to_files:TF
{
- \IfNoValueTF {##1}
+ \NewDocumentEnvironment
+ { \xsim_get_parameter:nn {#1} {#2-env} } {!o}
{
- \bool_set_false:N \l__xsim_options_given_bool
- \use:c {xsim_start_#2:nn} {#1} {}
+ \IfNoValueTF {##1}
+ {
+ \bool_set_false:N \l__xsim_options_given_bool
+ \use:c {xsim_start_#2:nn} {#1} {}
+ }
+ {
+ \bool_set_true:N \l__xsim_options_given_bool
+ \use:c {xsim_start_#2:nn} {#1} {##1}
+ }
+ \xsim_start_environment:nVnn {#1} \g_xsim_exercise_id_tl {#2} { }
}
{
- \bool_set_true:N \l__xsim_options_given_bool
- \use:c {xsim_start_#2:nn} {#1} {##1}
+ \xsim_stop_environment:nVn {#1} \g_xsim_exercise_id_tl {#2}
+ \use:c {xsim_stop_#2:n} {#1}
}
- \xsim_start_environment:nVn {#1} \g_xsim_exercise_id_tl {#2}
}
{
- \xsim_stop_environment:nVn {#1} \g_xsim_exercise_id_tl {#2}
- \use:c {xsim_stop_#2:n} {#1}
+ \NewDocumentEnvironment
+ { \xsim_get_parameter:nn {#1} {#2-env} } {o+b}
+ {
+ \IfNoValueTF {##1}
+ {
+ \bool_set_false:N \l__xsim_options_given_bool
+ \use:c {xsim_start_#2:nn} {#1} {}
+ }
+ {
+ \bool_set_true:N \l__xsim_options_given_bool
+ \use:c {xsim_start_#2:nn} {#1} {##1}
+ }
+ \xsim_start_environment:nVnn {#1} \g_xsim_exercise_id_tl {#2} {##2}
+ }
+ {
+ \xsim_stop_environment:nVn {#1} \g_xsim_exercise_id_tl {#2}
+ \use:c {xsim_stop_#2:n} {#1}
+ }
}
}
@@ -379,3 +491,4 @@
\file_input_stop:
2019/02/17 - fix issue #43
+2019/10/03 - add possibility to save environment bodies to property list
diff --git a/macros/latex/contrib/xsim/code/xsim.solutions.code.tex b/macros/latex/contrib/xsim/code/xsim.solutions.code.tex
index fda5152a50..23e48d75f4 100644
--- a/macros/latex/contrib/xsim/code/xsim.solutions.code.tex
+++ b/macros/latex/contrib/xsim/code/xsim.solutions.code.tex
@@ -82,8 +82,7 @@
% #2: id
\prg_new_protected_conditional:Npnn \xsim_if_solution_exists:nn #1#2 {T,F,TF}
{
- \__xsim_set_file_signature:nnn {#1} {#2} {solution}
- \file_if_exist:VTF \l__xsim_file_path_and_name_tl
+ \xsim_if_exists:nnnTF {#1} {#2} {solution}
{ \prg_return_true: }
{ \prg_return_false: }
}
diff --git a/macros/latex/contrib/xsim/code/xsim.sty b/macros/latex/contrib/xsim/code/xsim.sty
index 8570e7a186..01dcbd96b3 100644
--- a/macros/latex/contrib/xsim/code/xsim.sty
+++ b/macros/latex/contrib/xsim/code/xsim.sty
@@ -25,13 +25,13 @@
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% ----------------------------------------------------------------------------
-\RequirePackage {expl3,xparse}
+\RequirePackage {expl3,xparse,l3keys2e}
\ExplSyntaxOn
-\tl_const:Nn \c_xsim_date_tl {2019/09/30}
+\tl_const:Nn \c_xsim_date_tl {2019/10/06}
\tl_const:Nn \c_xsim_version_major_number_tl {0}
-\tl_const:Nn \c_xsim_version_minor_number_tl {12}
+\tl_const:Nn \c_xsim_version_minor_number_tl {13}
\tl_const:Nn \c_xsim_version_subrelease_tl {}
\tl_const:Nx \c_xsim_version_number_tl
{
@@ -58,24 +58,25 @@
\bool_new:N \g_xsim_final_bool
\bool_new:N \g_xsim_verbose_bool
\bool_new:N \g_xsim_clear_aux_bool
+\bool_new:N \l__xsim_write_to_file_bool
-\keys_define:nn {xsim}
+\keys_define:nn {xsim/package}
{
- final .bool_gset:N = \g_xsim_final_bool ,
- verbose .bool_gset:N = \g_xsim_verbose_bool ,
- clear-aux .bool_gset:N = \g_xsim_clear_aux_bool
+ final .bool_gset:N = \g_xsim_final_bool ,
+ verbose .bool_gset:N = \g_xsim_verbose_bool ,
+ clear-aux .bool_gset:N = \g_xsim_clear_aux_bool ,
+ no-files .bool_gset_inverse:N = \g__xsim_write_to_file_bool ,
+ no-files .initial:n = false
}
-\DeclareOption {final}
- { \bool_gset_true:N \g_xsim_final_bool }
+\ProcessKeysPackageOptions {xsim/package}
-\DeclareOption {verbose}
- { \bool_gset_true:N \g_xsim_verbose_bool }
-
-\DeclareOption {clear-aux}
- { \bool_gset_true:N \g_xsim_clear_aux_bool }
-
-\ProcessOptions \scan_stop:
+\prg_new_conditional:Npnn \xsim_if_write_to_files: {p,T,F,TF}
+ {
+ \bool_if:NTF \g__xsim_write_to_file_bool
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
% --------------------------------------------------------------------------
diff --git a/macros/latex/contrib/xsim/code/xsim.verbwrite.code.tex b/macros/latex/contrib/xsim/code/xsim.verbwrite.code.tex
index a04ab8fed4..4738dc7786 100644
--- a/macros/latex/contrib/xsim/code/xsim.verbwrite.code.tex
+++ b/macros/latex/contrib/xsim/code/xsim.verbwrite.code.tex
@@ -103,10 +103,18 @@
% see http://tex.stackexchange.com/q/9035/5049 reasons
\use:nx
{ \__xsim_file_write_start:n {#2} }
- { \bool_if:nF {#1} { \c__xsim_active_eol_tl } }
+ { \bool_if:nF {#1} { \exp_not:V \c__xsim_active_eol_tl } }
}
\cs_generate_variant:Nn \xsim_file_write_start:nn {nV}
+\cs_new_protected:Npn \__xsim_set_verb_catcodes:
+ {
+ \seq_map_inline:Nn \l_char_special_seq
+ { \char_set_catcode_other:N ##1 }
+ \int_step_inline:nnnn {128} {1} {255}
+ { \char_set_catcode_letter:n {##1} }
+ }
+
\group_begin:
\char_set_catcode_active:n {13} % ^^M (carriage return, endlinechar)
\char_set_catcode_active:n {12} % ^^L (form feed)
@@ -130,10 +138,7 @@
{ \l_xsim_file_begin_tl } %
} %
} %
- \seq_map_inline:Nn \l_char_special_seq %
- { \char_set_catcode_other:N ##1 } %
- \int_step_inline:nnnn {128} {1} {255} %
- { \char_set_catcode_letter:n {##1} } %
+ \__xsim_set_verb_catcodes: %
\tl_set:Nx \l__xsim_tmpa_tl %
{ \c__xsim_backslash_char_tl end \cs_to_str:N \{ \@currenvir \cs_to_str:N \} } %
\use:x %