Skip to content

Commit

Permalink
step towards nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
cgnieder committed Mar 8, 2020
1 parent c6f7729 commit 0f90bd6
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 13 deletions.
6 changes: 5 additions & 1 deletion code/xsim.environments.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@
% #3: exercise|solution
\cs_new_protected:Npn \xsim_typeset_environment:nnn #1#2#3
{
\tl_set:Nn \ExerciseType {#1}
\tl_set:Nn \ExerciseID {#2}
\xsim_if_exchange:nnnT {#1} {#2} {#3}
{ \__xsim_set_file_signature:nnn {#1} {#2} {exercise} }
\xsim_verbose:n
Expand Down Expand Up @@ -507,7 +509,7 @@
\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_start_environment:nVnn {#1} \g_xsim_exercise_id_tl {#2} {##2}
}
{
\xsim_stop_environment:nVn {#1} \g_xsim_exercise_id_tl {#2}
Expand All @@ -526,3 +528,5 @@
2020/02/19 - implement issue #33 (solution property)
2020/02/20 - fix issue #27
- implement issue #2
2020/03/08 - correctly re-set \ExerciseType and \ExerciseID for typesetting
(they're no longer local)
29 changes: 19 additions & 10 deletions code/xsim.exercises.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
\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

% ----------------------------------------------------------------------------
Expand Down Expand Up @@ -320,22 +321,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' }
Expand Down Expand Up @@ -363,8 +364,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
Expand Down Expand Up @@ -395,6 +400,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
{
Expand Down Expand Up @@ -467,11 +473,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~
Expand Down Expand Up @@ -505,7 +508,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
Expand Down Expand Up @@ -615,3 +622,5 @@
\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
4 changes: 2 additions & 2 deletions code/xsim.interface.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@
\NewExpandableDocumentCommand \XSIMtranslate {m}
{ \xsim_translate:n {#1} }

\NewDocumentCommand \XSIMexpandcode {+m}
{ \use:x {#1} }
\NewExpandableDocumentCommand \XSIMexpandcode {+m}
{ \use:e {#1} }

\NewExpandableDocumentCommand \XSIMmixedcase {m}
{ \tl_mixed_case:f {#1} }
Expand Down
84 changes: 84 additions & 0 deletions doc/xsim-manual.cls
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,90 @@

\def\xsimman@read@options@[#1]{\pgfqkeys{/cnltx}{#1}}

\RenewDocumentEnvironment{sourcecode}{}
{%
\xsimman@readoptions{%
\setlength\cnltx@sidebysidewidth
{\dimexpr .45\columnwidth -\lst@xleftmargin -\lst@xrightmargin\relax}%
\XSIMexpandcode{%
\noexpand\lstset{
style=cnltx,
\ifboolexpe{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} }
{linewidth=\cnltx@sidebysidewidth,}{}%
\expandonce\cnltx@local@listings@options
}%
}%
\XSIMgobblechars{2}%
}%
}
{%
\XSIMfilewritestop
\cnltxcode[breakable]%
\lstinputlisting[style=cnltx]{\jobname.tmp}%
\endcnltxcode
}

\RenewDocumentEnvironment{example}{}
{%
\xsimman@readoptions{%
\setlength\cnltx@sidebysidewidth
{\dimexpr .45\columnwidth -\lst@xleftmargin -\lst@xrightmargin\relax}%
\XSIMexpandcode{%
\noexpand\lstset{
style=cnltx,
\ifboolexpe{ bool {cnltx@sidebyside} and not bool {cnltx@codeonly} }
{linewidth=\cnltx@sidebysidewidth,}{}%
\expandonce\cnltx@local@listings@options
}%
}%
\XSIMgobblechars{2}%
}%
}
{%
\XSIMfilewritestop
\catcode`\^^M=5
\ifbool{cnltx@sidebyside}
{%
\cnltxcode
\noindent
\minipage[c]{\cnltx@sidebysidewidth}%
\cnltx@pre@source@hook
\lstinputlisting[style=cnltx] {\jobname.tmp}%
\cnltx@after@source@hook
\endminipage\hfill
\minipage[c]{\cnltx@sidebysidewidth}%
\cnltx@pre@example@hook
\input {\jobname.tmp}%
\cnltx@after@example@hook
\endminipage
}
{%
\cnltxcode[breakable]%
\cnltx@pre@source@hook
\lstinputlisting{\jobname.tmp}%
\cnltx@after@source@hook
\tcblower
\cnltx@pre@example@hook
\input {\jobname.tmp}%
\cnltx@after@example@hook
}%
\endcnltxcode
}\newcommand*\xsimman@readoptions[1]{%
\catcode`\^^M=13
\xsimman@read@options{#1}%
}

\begingroup
\catcode`\^^M=13
\gdef\xsimman@read@options#1#2^^M{%
\ifblank{#2}{}{\xsimman@read@options@#2}%
#1%
\XSIMfilewritestart*{\jobname.tmp}%
}%
\endgroup

\def\xsimman@read@options@[#1]{\pgfqkeys{/cnltx}{#1}}

\RenewDocumentEnvironment{sourcecode}{}
{%
\xsimman@readoptions{%
Expand Down

0 comments on commit 0f90bd6

Please sign in to comment.