Skip to content

Commit

Permalink
implement issue #31
Browse files Browse the repository at this point in the history
  • Loading branch information
cgnieder committed Feb 19, 2020
1 parent aeea0ed commit 60ab82e
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Clemens Niederberger
Web: https://github.com/cgnieder/xsim
E-Mail: [email protected]
--------------------------------------------------------------------------
Copyright 2017--2019 Clemens Niederberger
Copyright 2017--2020 Clemens Niederberger

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either version 1.3
Expand Down
15 changes: 9 additions & 6 deletions code/xsim.auxfile.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@

\cs_new_protected:Npn \XSIM #1 { \use:c {XSIMaux#1} }

\cs_new_protected:Npn \xsim_new_aux_cs:cpn #1
\cs_new_protected:Npn \xsim_new_aux_property:cpn #1
{ \cs_new_protected:cpn {XSIMaux#1} }

\cs_new_protected:Npn \xsim_add_cs_to_aux:nn #1#2
\cs_new_protected:Npn \xsim_add_property_to_aux:nn #1#2
{
\xsim_verbose:n { Writing~ command~ \XSIM {#1}~ to~ aux~ file }
\xsim_write_to_aux:x { \token_to_str:N \XSIM {#1} #2 }
Expand Down Expand Up @@ -83,8 +83,11 @@
}
}

\xsim_new_aux_cs:cpn {readaux}
{ \file_input:n { \c_sys_jobname_str .xsim } }
\xsim_new_aux_property:cpn {readaux}
{
\file_if_exist:nT { \c_sys_jobname_str .xsim }
{ \file_input:n { \c_sys_jobname_str .xsim } }
}

% ----------------------------------------------------------------------------
% list for recording values that need to be written to the aux file and
Expand All @@ -105,7 +108,7 @@
\prop_new:c {g__xsim_list_#1_prop}
\seq_new:c {g__xsim_list_#1_seq}
\seq_new:c {g__xsim_list_recorded_#1_seq}
\xsim_new_aux_cs:cpn {#1} ##1
\xsim_new_aux_property:cpn {#1} ##1
{
\prop_gclear:c {g__xsim_list_#1_prop}
\tl_if_blank:nF {##1}
Expand Down Expand Up @@ -193,7 +196,7 @@
{ \xsim_rerun: }
\bool_if:NF \l__xsim_empty_lists_bool
{
\xsim_add_cs_to_aux:nn {#1}
\xsim_add_property_to_aux:nn {#1}
{ { \seq_use:cV {g__xsim_list_#1_seq} \l__xsim_split_aux_lists_str } }
}
}
Expand Down
16 changes: 12 additions & 4 deletions code/xsim.base.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,21 @@

\prg_new_conditional:Npnn \xsim_if_final: {p,T,F,TF}
{
\bool_if:NTF \g_xsim_final_bool
\bool_if:NTF \g__xsim_final_bool
{ \prg_return_true: }
{ \prg_return_false: }
}

\prg_new_conditional:Npnn \xsim_if_verbose: {p,T,F,TF}
{
\bool_if:NTF \g_xsim_verbose_bool
\bool_if:NTF \g__xsim_verbose_bool
{ \prg_return_true: }
{ \prg_return_false: }
}

\prg_new_conditional:Npnn \xsim_if_blank: {p,T,F,TF}
{
\bool_if:NTF \g__xsim_blank_bool
{ \prg_return_true: }
{ \prg_return_false: }
}
Expand Down Expand Up @@ -170,8 +177,9 @@

\prg_new_conditional:Npnn \xsim_if_chapter: {p,T,F,TF}
{
\bool_if:nTF
{ \cs_if_exist_p:N \chapter && \cs_if_exist_p:N \c@chapter }
\bool_lazy_and:nnTF
{ \cs_if_exist_p:N \chapter }
{ \cs_if_exist_p:N \c@chapter }
{ \prg_return_true: }
{ \prg_return_false: }
}
Expand Down
5 changes: 3 additions & 2 deletions code/xsim.blanks.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@
\mode_if_math:TF
{ \hbox_set:Nn \l__xsim_blank_box { $ \m@th \mathpalette{}{#1} $ } }
{ \hbox_set:Nn \l__xsim_blank_box {#1} }
\bool_if:nTF
{ \xsim_if_inside_solution_p: || \l__xsim_fill_blank_bool }
\bool_lazy_or:nnTF
{ \xsim_if_inside_solution_p: }
{ \l__xsim_fill_blank_bool }
{ \xsim_write_cloze_filled:n {#1} }
{
\bool_if:NTF \l__xsim_blank_width_bool
Expand Down
8 changes: 3 additions & 5 deletions code/xsim.collections.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,9 @@
{
\prop_if_in:NnTF \g__xsim_collections_prop {#1}
{
\bool_if:nTF
{
!\str_if_eq_p:en {#1} {all~ exercises} &&
\prop_item:Nn \g__xsim_collections_prop {#1}
}
\bool_lazy_and:nnTF
{ !\str_if_eq_p:en {#1} {all~ exercises} }
{ \prop_item:Nn \g__xsim_collections_prop {#1} }
{ \prg_return_true: }
{ \prg_return_false: }
}
Expand Down
27 changes: 15 additions & 12 deletions code/xsim.definitions.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,21 @@

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

\DeclareExerciseType {exercise} {
exercise-env = exercise ,
solution-env = solution ,
exercise-name = \XSIMtranslate {exercise} ,
exercises-name = \XSIMtranslate {exercises} ,
solution-name = \XSIMtranslate {solution} ,
solutions-name = \XSIMtranslate {solutions} ,
exercise-template = default ,
solution-template = default ,
exercise-heading = \subsection* ,
solution-heading = \subsection*
}
\xsim_if_blank:F
{
\DeclareExerciseType {exercise} {
exercise-env = exercise ,
solution-env = solution ,
exercise-name = \XSIMtranslate {exercise} ,
exercises-name = \XSIMtranslate {exercises} ,
solution-name = \XSIMtranslate {solution} ,
solutions-name = \XSIMtranslate {solutions} ,
exercise-template = default ,
solution-template = default ,
exercise-heading = \subsection* ,
solution-heading = \subsection*
}
}

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

Expand Down
3 changes: 2 additions & 1 deletion code/xsim.environments.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
{ Typesetting~ #3~ environment~ type~ `#1'~ id~ `#2' }
\use:x
{
\exp_not:N \par
\xsim_use_hook:nnn {#1} {#3} {pre}
\xsim_use_template:nn
{begin}
Expand Down Expand Up @@ -492,3 +491,5 @@

2019/02/17 - fix issue #43
2019/10/03 - add possibility to save environment bodies to property list
2020/02/15 - remove spurious \par at the beginning of typeset exercises and
solutions
19 changes: 14 additions & 5 deletions code/xsim.exercises.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,31 @@
{ \int_gset_eq:NN \g_xsim_max_id_int \g_xsim_id_int }
\xsim_set_properties:nxx {#1} { \int_use:N \g_xsim_id_int }
{
% preset options so the user doesn't has to:
print = true ,
use = true ,
% options set by the user:
\exp_not:n {#2} ,
% options which need to have certain values:
id = \int_use:N \g_xsim_id_int ,
section-value = \arabic{section} ,
section = \thesection ,
page-value = \arabic{page} ,
sectioning =
{ \cs_if_exist:NTF \chapter { \arabic{chapter} } {0} }
{ \cs_if_exist:NTF \thechapter { \arabic {chapter} } {0} }
{ \arabic {section} }
{ \arabic {subsection} }
{ \arabic {subsubsection} }
{ \arabic {paragraph} } ,
page = \thepage ,
% this cannot be set, yet (see below):
used = false
}
\xsim_foreach_goal:n
{
\xsim_if_property_given:nT {##1}
{ \xsim_goal_given:n {##1} }
}
\xsim_if_property_exist:nT {chapter}
{
\xsim_set_properties:nxx {#1} { \int_use:N \g_xsim_id_int }
Expand Down Expand Up @@ -524,7 +533,7 @@

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

\xsim_new_aux_cs:cpn {total-number} #1
\xsim_new_aux_property:cpn {total-number} #1
{ \int_gset:Nn \g_xsim_max_id_int {#1} }

\RequirePackage {etoolbox}
Expand All @@ -535,7 +544,7 @@
{
\tl_new:c { number of #1 s }
\tl_set:cn { number of #1 s } {0}
\xsim_new_aux_cs:cpn {#1} ##1
\xsim_new_aux_property:cpn {#1} ##1
{ \tl_gset:cn { number of #1 s } {##1} }
}
}
Expand All @@ -556,10 +565,10 @@
\int_compare:nNnF { \g_xsim_max_id_int } = { \g_xsim_id_int }
{ \xsim_empty_lists: }
}
\xsim_add_cs_to_aux:nn {total-number} { { \int_use:N \g_xsim_id_int } }
\xsim_add_property_to_aux:nn {total-number} { { \int_use:N \g_xsim_id_int } }
\xsim_foreach_exercise_type:n
{
\xsim_add_cs_to_aux:nn {#1}
\xsim_add_property_to_aux:nn {#1}
{ { \arabic { \xsim_get_parameter:nn {#1} {number} } } }
}
\xsim_update_list:n {types}
Expand Down
19 changes: 15 additions & 4 deletions code/xsim.goals.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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} }
Expand All @@ -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
Expand Down Expand Up @@ -254,12 +265,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
Expand All @@ -278,15 +289,15 @@
{
\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
{ \fp_to_decimal:c {g__xsim_total_goal_#1_fp} }
\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} } }
}
}
Expand Down
11 changes: 11 additions & 0 deletions code/xsim.properties.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
\seq_new:N \l__xsim_boolean_properties_seq
\seq_new:N \l__xsim_unique_properties_seq
\seq_new:N \l__xsim_noupdate_properties_seq
\seq_new:N \l__xsim_given_properties_seq
\prop_new:N \g__xsim_properties_prop

% new property:
Expand Down Expand Up @@ -131,6 +132,13 @@
{ \prg_return_false: }
}

\prg_new_conditional:Npnn \xsim_if_property_given:n #1 {p,T,F,TF}
{
\seq_if_in:NnTF \l__xsim_given_properties_seq {#1}
{ \prg_return_true: }
{ \prg_return_false: }
}

% #1: property
% #2: value
\prg_new_conditional:Npnn \xsim_if_property_unique_value:nn #1#2 {p,T,F,TF}
Expand Down Expand Up @@ -309,6 +317,7 @@
% #3: csv list of properties
\cs_new_protected:Npn \xsim_set_properties:nnn #1#2#3
{
\seq_clear:N \l__xsim_given_properties_seq
\clist_map_inline:nn {#3}
{
\seq_set_split:Nnx \l__xsim_tmpa_seq {=} { \tl_trim_spaces:n {##1} }
Expand All @@ -317,6 +326,8 @@
{#2}
{ \seq_item:Nn \l__xsim_tmpa_seq {1} }
{ \seq_item:Nn \l__xsim_tmpa_seq {2} }
\seq_put_right:Nx \l__xsim_given_properties_seq
{ \seq_item:Nn \l__xsim_tmpa_seq {1} }
}
\xsim_property_set_aliases:nn {#1} {#2}
}
Expand Down
Loading

0 comments on commit 60ab82e

Please sign in to comment.