summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/stex/hwexam.sty
blob: c94d727ea8951fab7dd05aad1cdf9f504d4d15a9 (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
173
174
175
%%
%% This is file `hwexam.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% hwexam.dtx  (with options: `package')
%% 
\ProvidesExplPackage{hwexam}{2023/10/13}{3.4.0}{homework assignments and exams}
\RequirePackage{l3keys2e}

\keys_define:nn {hwexam / pkg}{
multiple  .default:n  = { false },
multiple .bool_set:N  = \c_hwexam_multiple_bool,
unknown   .code:n  = {
\PassOptionsToPackage{\CurrentOption}{problem}
}
}
\ProcessKeysOptions{ hwexam /pkg }
\RequirePackage{problem}
\AddToHook{begindocument}{
\ExplSyntaxOn\makeatletter
\input{hwexam-english.ldf}
\ltx@ifpackageloaded{babel}{
\clist_set:Nx \l_tmpa_clist {\exp_args:No \tl_to_str:n \bbl@loaded}
\exp_args:NNx \clist_if_in:NnT \l_tmpa_clist {\detokenize{ngerman}}{
\input{hwexam-ngerman.ldf}
}
\exp_args:NNx \clist_if_in:NnT \l_tmpa_clist {\detokenize{finnish}}{
\input{hwexam-finnish.ldf}
}
\exp_args:NNx \clist_if_in:NnT \l_tmpa_clist {\detokenize{french}}{
\input{hwexam-french.ldf}
}
\exp_args:NNx \clist_if_in:NnT \l_tmpa_clist {\detokenize{russian}}{
\input{hwexam-russian.ldf}
}
}{}
\makeatother\ExplSyntaxOff
}
\stex_keys_define:nnnn{ assignment }{
  \tl_clear:N \l_stex_key_number_tl
\tl_clear:N \l_stex_key_given_tl
\tl_clear:N \l_stex_key_due_tl
}{
  number  .tl_set:N     = \l_stex_key_number_tl,
  given   .tl_set:N     = \l_stex_key_given_tl,
  due     .tl_set:N     = \l_stex_key_due_tl,
unknown .code:n = {}
}{id,title,style}

\newcounter{assignment}
\stex_new_stylable_env:nnnnnnn {assignment}{O{}}{
  \cs_if_exist:NTF \l_hwexam_includeassignment_keys_tl {
    \tl_put_left:Nn \l_hwexam_includeassignment_keys_tl {#1,}
    \exp_args:Nno \stex_keys_set:nn{assignment}{
      \l_hwexam_includeassignment_keys_tl
    }
  }{
    \stex_keys_set:nn{assignment}{#1}
  }
\tl_if_empty:NF \l_stex_key_number_tl {
\global\setcounter{assignment}{\int_eval:n{\l_stex_key_number_tl-1}}
}
\global\refstepcounter{assignment}
\setcounter{sproblem}{0}
\def\thesproblem{\theassignment.\arabic{sproblem}}
\stex_style_apply:
\_stex_do_id:
}{
\stex_style_apply:
}{
\par\begin{center}
\textbf{\Large\assignmentautorefname~\theassignment
\tl_if_empty:NF \l_stex_key_title_tl {
{~}--~\l_stex_key_title_tl
}
}\par\smallskip
\textbf{
\tl_if_empty:NF \l_stex_key_given_tl {
\hwexam@kw@given :~\l_stex_key_given_tl\quad
}
\tl_if_empty:NF \l_stex_key_due_tl {
\hwexam@kw@due :~\l_stex_key_due_tl\quad
}
}
\end{center}
\par\bigskip
}{
\par\pagebreak
}{}
\NewDocumentCommand\includeassignment{O{} m}{
\group_begin:
\tl_set:Nn \l_hwexam_includeassignment_keys_tl {#1}
\stex_keys_set:nn{includeproblem}{#1}
\exp_args:Nno \use:nn{\inputref[}\l_stex_key_mhrepos_str]{#2}
\group_end:
}
\prop_new:N \c__problems_problems_prop
\tl_set:Nn \c__problems_total_mins_tl {0}
\tl_set:Nn \c__problems_total_pts_tl {0}
\int_new:N \c__problems_total_problems_int
\cs_set_protected:Npn \problem@restore #1 #2 #3 {
\int_gincr:N \c__problems_total_problems_int
\prop_gput:Nnn \c__problems_problems_prop {#1}{{#2}{#3}}
\tl_gset:Nx \c__problems_total_pts_tl { \int_eval:n { \c__problems_total_pts_tl + #2 }}
\tl_gset:Nx \c__problems_total_mins_tl { \int_eval:n { \c__problems_total_mins_tl + #2 }}
}
\newcommand\correction@table{
\int_compare:nNnT \c__problems_total_problems_int = 0 {
\int_incr:N \c__problems_total_problems_int
\prop_put:Nnn \c__problems_problems_prop {~}{{~}{~}}
}
\tl_clear:N \l_tmpa_tl
\tl_clear:N \l_tmpb_tl
\tl_clear:N \l_tmpc_tl
\prop_map_inline:Nn \c__problems_problems_prop {
\tl_put_right:Nn \l_tmpa_tl { ##1 & }
\tl_put_right:Nx \l_tmpb_tl { \use_i:nn ##2 & }
\tl_put_right:Nn \l_tmpc_tl { & }
}
\resizebox{\textwidth}{!}{%
\exp_args:Nne \begin{tabular}{|l|*{\int_use:N \c__problems_total_problems_int}{c|}c||l|}\hline
&\exp_args:Ne \multicolumn{\int_eval:n{ \c__problems_total_problems_int + 1}}{c||}
{\footnotesize\hwexam@kw@forgrading} &\\\hline
\hwexam@kw@probs & \l_tmpa_tl \hwexam@kw@sum & \hwexam@kw@grade\\\hline
\hwexam@kw@pts & \l_tmpb_tl \c__problems_total_pts_tl & \\\hline
\hwexam@kw@reached & \l_tmpc_tl & \\[.7cm]\hline
\end{tabular}}}
\def\hwexamheader{\input{hwexam-default.header}}

\def\hwexamminutes{
\tl_if_empty:NTF \hwexam@duration {
{\hwexam@min}~\hwexam@minutes@kw
}{
\hwexam@duration
}
}

\stex_keys_define:nnnn{ hwexam / testheading }{
\tl_clear:N \hwexam@min
\tl_clear:N \hwexam@duration
\tl_clear:N \hwexam@reqpts
\tl_clear:N \hwexam@tools
}{
min  .tl_set:N  = \hwexam@min,
duration .tl_set:N  = \hwexam@duration,
reqpts .tl_set:N  = \hwexam@reqpts,
tools .tl_set:N  = \hwexam@tools
}{}

\newenvironment{testheading}[1][]{
\stex_keys_set:nn { hwexam / testheading}{#1}

\tl_set_eq:NN \hwexam@totalpts \c__problems_total_pts_tl
\tl_set_eq:NN \hwexam@totalmin \c__problems_total_mins_tl
\tl_set:Nx \hwexam@checktime {\int_eval:n { \hwexam@min - \hwexam@totalmin }}

\newif\if@bonuspoints
\tl_if_empty:NTF \hwexam@reqpts {
\@bonuspointsfalse
}{
\tl_set:Nx \hwexam@bonuspts {
\int_eval:n{\hwexam@totalpts - \hwexam@reqpts}
}
\@bonuspointstrue
}

\makeatletter\hwexamheader\makeatother
}{
\newpage
}
\endinput
%%
%% End of file `hwexam.sty'.