summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/xsim/xsim.templates.code.tex
blob: 7644074be71bfced4fccb1c8793e4cb6f6be5bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
% ----------------------------------------------------------------------------
% the XSIM package - templates module
% 
%   eXercise Sheets IMproved
% 
% ----------------------------------------------------------------------------
% Clemens Niederberger
% Web:    https://github.com/cgnieder/xsim
% E-Mail: contact@mychemistry.eu
% ----------------------------------------------------------------------------
% 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
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
% 
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Clemens Niederberger.
% ----------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% ----------------------------------------------------------------------------
\XSIMmodule{templates}{properties of exercises}

\xsim_load_modules:n {base}

\msg_new:nnn {xsim} {unknown-template}
  {
    You~ are~ trying~ to~ load~ the~ template~ `#2'~ (template~ type~ `#1')~
    \msg_line_context: .~ This~ template~ does~ not~ seem~ to~ be~ defined.~
    I~ am~ using~ the~ template~ `#3'~ (template~ type~ `#1')~ instead.
  }

% #1: template type
\cs_new_protected:Npn \xsim_new_template_type:n #1
  {
    \xsim_verbose:n { Declaring~ new~ template~ type~ `#1'. }
    \prop_new:c {l__xsim_#1_template_prop}
  }

% #1: template type
% #2: template name
% #3: code
\cs_new_protected:Npn \__xsim_add_template:nnn #1#2#3
  {
    \xsim_verbose:n { Defining~ new~ template~ `#2'~ of~ type~ `#1'. }
    \tl_new:c {l__xsim_template_#1_#2_setup_tl}
    \prop_put:cnn {l__xsim_#1_template_prop} {#2} {#3}
  }

\prg_new_conditional:Npnn \xsim_if_template_exist:nn #1#2 {T,F,TF}
  {
    \prop_if_in:cnTF {l__xsim_#1_template_prop} {#2}
      { \prg_return_true: }
      { \prg_return_false: }
  }

% #1: template type
% #2: template name
\cs_new_protected:Npn \__xsim_get_template:nn #1#2
  { \prop_item:cn {l__xsim_#1_template_prop} {#2} }

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

% environment templates (types `begin' and `end'):
\xsim_new_template_type:n {begin}
\xsim_new_template_type:n {end}

% #1: template name
% #2: begin code
% #3: end code
\cs_new_protected:Npn \xsim_declare_environment_template:nnn #1#2#3
  {
    \__xsim_add_template:nnn {begin} {#1}
      {
        \__xsim_start_template:nn {begin} {#1}
        \__xsim_start_template:nn {end} {#1}
        #2
      }
    \__xsim_add_template:nnn {end} {#1}
      {
        #3
        \__xsim_stop_template:nn {end} {#1}
        \__xsim_stop_template:nn {begin} {#1}
      }
  }

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

% heading templates for the solution list (type `heading'):
\xsim_new_template_type:n {heading}

% #1: template name
% #2: code
\cs_new_protected:Npn \xsim_declare_heading_template:nn #1#2
  {
    \__xsim_add_template:nnn {heading} {#1}
      {
        \__xsim_start_template:nn {heading} {#1}
        #2
        \__xsim_stop_template:nn {heading} {#1}
      }
  }

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

% grading table templates (type `table'):
\xsim_new_template_type:n {table}

% #1: template name
% #2: code
\cs_new_protected:Npn \xsim_declare_table_template:nn #1#2
  {
    \__xsim_add_template:nnn {table} {#1}
      {
        \__xsim_start_template:nn {table} {#1}
        #2
        \__xsim_stop_template:nn {table} {#1}
      }
  }

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

% using templates:
% setup up the next usage of `template name':
% #1: template type
% #2: template name
% #3: setup code
\cs_new_protected:Npn \xsim_setup_template:nnn #1#2#3
  { \tl_set:cn {l__xsim_template_#1_#2_setup_tl} {#3} }
\cs_generate_variant:Nn \xsim_setup_template:nnn {nnV,nVn}

% #1: template type
% #2: template name
\cs_new_protected:Npn \__xsim_setup_template:nn #1#2
  { \tl_use:c {l__xsim_template_#1_#2_setup_tl} }

% #1: template type
% #2: template name
\cs_new_protected:Npn \__xsim_clear_template_setup:nn #1#2
  { \tl_clear:c {l__xsim_template_#1_#2_setup_tl} }

% #1: template type
% #2: template name
\cs_new_protected:Npn \__xsim_start_template:nn #1#2
  { \group_begin: \__xsim_setup_template:nn {#1} {#2} }

% #1: template type
% #2: template name
\cs_new_protected:Npn \__xsim_stop_template:nn #1#2
  { \group_end: \__xsim_clear_template_setup:nn {#1} {#2} }
  
% #1: template type
% #2: template name
\cs_new_protected:Npn \xsim_use_template:nn #1#2
  {
    \xsim_if_template_exist:nnTF {#1} {#2}
      { \__xsim_get_template:nn {#1} {#2} }
      {
        \msg_warning:nnnnn {xsim} {unknown-template} {#1} {#2} {default}
        \__xsim_get_template:nn {#1} {default}
      }
  }
\cs_generate_variant:Nn \xsim_use_template:nn {nx,nV}

% ----------------------------------------------------------------------------  
\file_input_stop: