summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/stex/problem/problem.dtx
blob: 546ca44273fc18374fbe54cc7342e3762b83dcf2 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
% \iffalse meta-comment
% An Infrastructure for Problems 
% Copyright (c) 2006-2008 Michael Kohlhase, all rights reserved
%               this file is released under the
%               LaTeX Project Public License (LPPL)
% The original of this file is in the public repository at 
% http://github.com/KWARC/sTeX/
% \fi
% 
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{problem}[2016/04/07 v1.2 Semantic Markup for Problems]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{url,float,xspace}
\usepackage[solutions,hints,notes]{problem}
\usepackage[show]{ed}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\addbibresource{kwarcpubs.bib}
\addbibresource{extpubs.bib}
\addbibresource{kwarccrossrefs.bib}
\addbibresource{extcrossrefs.bib}
\usepackage{stex-logo}
\usepackage{ctangit}
\usepackage{hyperref}
\makeindex
\def\latexml{\hbox{{\LaTeX}ML}\xspace}
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\def\tracissue#1{\cite{sTeX:online}, \hyperlink{http://trac.kwarc.info/sTeX/ticket/#1}{issue #1}}
\begin{document}\DocInput{problem.dtx}\end{document}
%</driver>
% \fi
% 
% \CheckSum{318}
%
% \changes{v0.9}{2006/09/18}{First Version with Documentation}
% \changes{v0.9a}{2007/01/02}{Renamed to \texttt{problem.sty}}
% \changes{v0.9c}{2010/01/03}{based on \texttt{omd.sty} now}
% \changes{v1.0}{2013/10/09}{adding \texttt{\textbackslash start/stopsolution}}
% \changes{v1.1}{2013/12/12}{adding MathHub support}
% \changes{v1.2}{2015/11/04}{moving MathHub support out to separate package}
% 
% \GetFileInfo{problem.sty}
% 
% \MakeShortVerb{\|}
%
% \title{\texttt{problem.sty}: An Infrastructure for formatting Problems\thanks{Version {\fileversion} (last revised
%        {\filedate})}}
%    \author{Michael Kohlhase\\
%            Jacobs University, Bremen\\
%            \url{http://kwarc.info/kohlhase}}
% \maketitle
%
% \begin{abstract}
%   The |problem| package supplies an infrastructure that allows specify problems and to
%   reuse them efficiently in multiple environments.
% \end{abstract}
% \setcounter{tocdepth}{2}\tableofcontents\newpage
%
%\section{Introduction}\label{sec:intro}
%
% The |problem| package supplies an infrastructure that allows specify problem.  Problems
% are text fragments that come with auxiliary functions: hints, notes, and
% solutions\footnote{for the moment multiple choice problems are not supported, but may
%   well be in a future version}. Furthermore, we can specify how long the solution to a
% given problem is estimated to take and how many points will be awarded for a perfect
% solution.
% 
% Finally, the |problem| package facilitates the management of problems in small files,
% so that problems can be re-used in multiple environment. 
% 
% \section{The User Interface}\label{sec:ui}
%
% \subsection{Package Options}
% The |problem| package takes the options \DescribeMacro{solutions}|solutions| (should
% solutions be output?), \DescribeMacro{notes}|notes| (should the problem notes be
% presented?), \DescribeMacro{hints}|hints| (do we give the hints?),
% \DescribeMacro{pts}|pts| (do we display the points awarded for solving the problem?),
% \DescribeMacro{min}|min| (do we display the estimated minutes for problem soling). If
% theses are specified, then the corresponding auxiliary parts of the problems are output,
% otherwise, they remain invisible.
% 
% The \DescribeMacro{boxed}|boxed| option specifies that problems should be formatted in
% framed boxes so that they are more visible in the text. Finally, the
% \DescribeMacro{test}|test| option signifies that we are in a test situation, so this
% option does not show the solutions (of course), but leaves space for the students to
% solve them.
% 
% Finally, if the \DescribeMacro{showmeta}|showmeta| is set, then the metadata keys are
% shown (see~\cite{Kohlhase:metakeys:ctan} for details and customization options).
% 
% \subsection{Problems and Solutions}\label{sec:user:probsols}
%
% \DescribeEnv{problem} The main environment provided by the |problem| package is
% (surprise surprise) the |problem| environment. It is used to mark up problems and
% exercises. The environment takes an optional KeyVal argument with the keys
% \DescribeMacro{id}|id| as an identifier that can be reference later,
% \DescribeMacro{pts}|pts| for the points to be gained from this exercise in homework or
% quiz situations, \DescribeMacro{min}|min| for the estimated minutes needed to solve the
% problem, and finally \DescribeMacro{title}|title| for an informative title of the
% problem. For an example of a marked up problem see Figure~\ref{fig:problem} and the
% resulting markup see Figure~\ref{fig:result}. 
%
%\begin{exfig}
% \begin{verbatim}
% \usepackage[solutions,hints,pts,min]{problem}
% \begin{document}
%   \begin{problem}[id=elefants,pts=10,min=2,title=Fitting Elefants]
%     How many Elefants can you fit into a Volkswagen beetle?
% \begin{hint}
%   Think positively, this is simple!
% \end{hint}
% \begin{exnote}
%   Justify your answer
% \end{exnote}
% \begin{solution}[for=elefants,height=3cm]
%   Four, two in the front seats, and two in the back.
% \end{solution}
%   \end{problem}
% \end{document}
% \end{verbatim}
% \caption{A marked up Problem}\label{fig:problem}
% \end{exfig}
%
% \DescribeEnv{solution} The |solution| environment can be to specify a solution to a
% problem. If the \DescribeMacro{solutions}|solutions| option is set or |\solutionstrue|
% is set in the text, then the solution will be presented in the output. The |solution|
% environment takes an optional KeyVal argument with the keys \DescribeMacro{id}|id| for
% an identifier that can be reference \DescribeMacro{for}|for| to specify which problem
% this is a solution for, and \DescribeMacro{height}|height| that allows to specify the
% amount of space to be left in test situations (i.e. if the \DescribeMacro{test}|test|
% option is set in the |\usepackage| statement).
%
%\begin{exfig}
% \begin{minipage}{.9\linewidth}
% \begin{problem}[id=elefants.prob,title=Fitting Elefants]
%   How many Elefants can you fit into a Volkswagen beetle?
% \begin{hint}
%   Think positively, this is simple!
% \end{hint}
% \begin{exnote}
%   Justify your answer
% \end{exnote}
% \smallskip\noindent\hrule\textbf{Solution:}
%   Four, two in the front seats, and two in the back.
% \hrule
% \end{problem}
% \end{minipage}
% \caption{The Formatted Problem from Figure~\ref{fig:problem}}\label{fig:result}
% \end{exfig}
% 
% \DescribeEnv{hint}\DescribeEnv{note}, the |hint| and |exnote| environments can be used
% in a |problem| environment to give hints and to make notes that elaborate certain aspects
% of the problem.
%
% \subsection{Starting and Stopping Solutions}
% 
% Sometimes we would like to locally override the |solutions| option we have given to the
% package. To turn on solutions we use the
% \DescribeMacro{\startsolutions}|\startsolutions|, to turn them off,
% \DescribeMacro{\stopsolutions}|\stopsolutions|. These two can be used at any point in
% the documents. 
%
% \subsection{Including Problems}\label{sec:user:includeproblem}
% 
% The \DescribeMacro{\includeproblem}|\includeproblem| macro can be used to include a
% problem from another file. It takes an optional KeyVal argument and a second argument
% which is a path to the file containing the problem (the macro assumes that there is only
% one problem in the include file). The keys \DescribeMacro{title}|title|,
% \DescribeMacro{min}|min|, and \DescribeMacro{pts}|pts| specify the problem title, the
% estimated minutes for solving the problem and the points to be gained, and their values
% (if given) overwrite the ones specified in the |problem| environment in the included
% file.
% 
% \subsection{Reporting Metadata}\label{sec:user:reporting}
% 
% The sum of the points and estimated minutes (that we specified in the |pts| and |min|
% keys to the |problem| environment or the |\includeproblem| macro) to the log file and
% the screen after each run. This is useful in preparing exams, where we want to make sure
% that the students can indeed solve the problems in an allotted time period.
% 
% The |\min| and |\pts| macros allow to specify (i.e. to print to the margin) the
% distribution of time and reward to parts of a problem, if the |pts| and |pts| package
% options are set. This allows to give students hints about the estimated time and the
% points to be awarded.
%
% \section{Limitations}\label{sec:limitations}
% 
% In this section we document known limitations. If you want to help alleviate them,
% please feel free to contact the package author. Some of them are currently discussed in
% the \sTeX GitHub repository~\cite{sTeX:github:on}. 
% \begin{compactenum}
% \item none reported yet
% \end{compactenum}
% 
% \StopEventually{\newpage\PrintChanges}
% \newpage
%
% \section{The Implementation}\label{sec:implementation}
%
% \subsection{Package Options}\label{sec:impl:options}
% 
% The first step is to declare (a few) package options that handle whether certain
% information is printed or not. They all come with their own conditionals that are set by
% the options.
%
%    \begin{macrocode}
%<*package>
\newif\if@problem@mh@\@problem@mh@false
\DeclareOption{mh}{\@problem@mh@true}
\newif\ifexnotes\exnotesfalse
\DeclareOption{notes}{\exnotestrue}
\newif\ifhints\hintsfalse
\DeclareOption{hints}{\hintstrue}
\newif\ifsolutions\solutionsfalse
\DeclareOption{solutions}{\solutionstrue}
\newif\ifpts\ptsfalse
\DeclareOption{pts}{\ptstrue}
\newif\ifmin\minfalse
\DeclareOption{min}{\mintrue}
\newif\ifboxed\boxedfalse
\DeclareOption{boxed}{\boxedtrue}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{omtext}}
\ProcessOptions
%    \end{macrocode}
%
% Then we make sure that the necessary packages are loaded (in the right versions).
%    \begin{macrocode}
\if@problem@mh@\RequirePackage{problem-mh}\fi
\RequirePackage{omtext}
\RequirePackage{comment}
\RequirePackage{mdframed}
\RequirePackage[base]{babel}
%    \end{macrocode}
%
% \begin{macro}{\prob@*@kw}
%   For multilinguality, we define internal macros for keywords that can be specialized in
%   |*.ldf| files. 
%    \begin{macrocode}
\AfterBabelLanguage{ngerman}{\input{problem-ngerman.ldf}}
\def\prob@problem@kw{Problem}
\def\prob@solution@kw{Solution}
%    \end{macrocode}
% \end{macro}
% 
% \subsection{Problems and Solutions}\label{sec:impl:probsols}
% 
% We now prepare the KeyVal support for problems. The key macros just set appropriate
% internal macros.
%
%    \begin{macrocode}
\srefaddidkey[prefix=prob.]{problem}
\addmetakey{problem}{pts}
\addmetakey{problem}{min}
\addmetakey*{problem}{title}
\addmetakey{problem}{refnum}
%    \end{macrocode}
%
% Then we set up a counter for problems.
% \begin{macro}{\numberproblemsin}
%    \begin{macrocode}
\newcounter{problem}
\newcommand\numberproblemsin[1]{\@addtoreset{problem}{#1}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\prob@label}
%   We provide the macro |\prob@label| to redefine later to get context involved. 
%    \begin{macrocode}
\newcommand\prob@label[1]{#1} 
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\prob@number}
%   We consolidate the problem number into a reusable internal macro
% \begin{macrocode}
\def\prob@number{\ifx\inclprob@refnum\@empty%
\ifx\problem@refnum\@empty\prob@label\theproblem%
\else\prob@label\problem@refnum\fi%
\else\prob@label\inclprob@refnum\fi}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\prob@title}
%   We consolidate the problem title into a reusable internal macro as well. |\prob@title|
%   takes three arguments the first is the fallback when no title is given at all, the
%   second and third go around the title, if one is given.
% \begin{macrocode}
\newcommand\prob@title[3]{%
\ifx\inclprob@title\@empty% if there is no outside title
\ifx\problem@title\@empty{#1}\else{#2\problem@title{#3}}\fi
\else{#2}\inclprob@title{#3}\fi}% else show the outside title
%    \end{macrocode}
% \end{macro}
% 
% With these the problem header is a one-liner
%
% \begin{macro}{\prob@heading}
%   We consolidate the problem header line into a separate internal macro that can be
%   reused in various settings. 
% \begin{macrocode}
\def\prob@heading{\prob@problem@kw~\prob@number\prob@title{ }{ (}{)\strut\\}%
\sref@label@id{\prob@problem@kw~\prob@number}}
%    \end{macrocode}
% \end{macro}
% 
% With this in place, we can now define the |problem| environment. It comes in two shapes,
% depending on whether we are in boxed mode or not. In both cases we increment the problem
% number and output the points and minutes (depending) on whether the respective options
% are set.
% \begin{environment}{problem}
%    \begin{macrocode}
\newenvironment{problem}[1][]{\metasetkeys{problem}{#1}\sref@target%
\@in@omtexttrue% we are in a statement (for inline definitions)
\stepcounter{problem}\record@problem%
\def\current@section@level{\prob@problem@kw}%
\par\noindent\textbf\prob@heading\show@pts\show@min\rm\noindent\ignorespaces}
{\smallskip}
\ifboxed\surroundwithmdframed{problem}\fi
%    \end{macrocode}
% \end{environment}
% 
% \begin{macro}{\record@problem}
%   This macro records information about the problems in the |*.aux| file. 
%    \begin{macrocode}
\def\record@problem{\protected@write\@auxout{}%
{\string\@problem{\prob@number}%
{\ifx\inclprob@pts\@empty\problem@pts\else\inclprob@pts\fi}%
{\ifx\inclprob@min\@empty\problem@min\else\inclprob@min\fi}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@problem}
%   This macro acts on a problem's record in the |*.aux| file. It does not have any
%   functionality here, but can be redefined elsewhere (e.g. in the |assignment|
%   package). 
%    \begin{macrocode}
\def\@problem#1#2#3{}
%    \end{macrocode}
% \end{macro}
% 
% The \DescribeEnv{solution}|solution| environment is similar to the |problem|
% environment, only that it is independent of the boxed mode. It also has it's own keys
% that we need to define first.
% 
%    \begin{macrocode}
\srefaddidkey{soln}
\addmetakey{soln}{for}
\addmetakey{soln}{height}
\addmetakey{soln}{creators}
\addmetakey{soln}{contributors}
\addmetakey{soln}{srccite}
%    \begin{macrocode}
% the next step is to define a helper macro that does what is needed to start a solution. 
%    \begin{macrocode}
\newcommand\@startsolution[1][]{\metasetkeys{soln}{#1}%
\@in@omtexttrue% we are in a statement.
\ifboxed\else\hrule\fi\smallskip\noindent{\textbf\prob@solution@kw: }\begin{small}%
\def\current@section@level{\prob@solution@kw}%
\ignorespaces}
%    \end{macrocode}
%
% \begin{macro}{\startsolutions}
% for the |\startsolutions| macro we use the |\specialcomment| macro from the |comment|
% package. Note that we use the |\@startsolution| macro in the start codes, that parses
% the optional argument. 
%    \begin{macrocode}
\newcommand\startsolutions{\specialcomment{solution}{\@startsolution}%
{\ifboxed\else\hrule\medskip\fi\end{small}}%
\ifboxed\surroundwithmdframed{solution}\fi}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\stopsolutions}
%    \begin{macrocode}
\newcommand\stopsolutions{\excludecomment{solution}}
%    \end{macrocode}
% \end{macro}
% 
% so it only remains to start/stop solutions depending on what option was specified.
%
%    \begin{macrocode}
\ifsolutions\startsolutions\else\stopsolutions\fi
%    \end{macrocode}
%
%    \begin{macrocode}
\ifexnotes
\newenvironment{exnote}[1][]%
{\par\smallskip\hrule\smallskip\noindent\textbf{Note: }\small}
{\smallskip\hrule}
\else%ifexnotes
\excludecomment{exnote}
\fi%ifexnotes
\ifhints
\newenvironment{hint}[1][]%
{\par\smallskip\hrule\smallskip\noindent\textbf{Hint: }\small}
{\smallskip\hrule}
\newenvironment{exhint}[1][]%
{\par\smallskip\hrule\smallskip\noindent\textbf{Hint: }\small}
{\smallskip\hrule}
\else%ifhints
\excludecomment{hint}
\excludecomment{exhint}
\fi%ifhints
%    \end{macrocode}
% 
% \subsection{Including Problems}\label{sec:impl:includeproblem}
%
% \begin{macro}{\includeproblem}
%   The |\includeproblem| command is essentially a glorified |\input| statement, it sets
%   some internal macros first that overwrite the local points. Importantly, it resets the
%   |inclprob| keys after the input. 
%    \begin{macrocode}
\addmetakey{inclprob}{pts}
\addmetakey{inclprob}{min}
\addmetakey*{inclprob}{title}
\addmetakey{inclprob}{refnum}
\addmetakey{inclprob}{mhrepos}
\clear@inclprob@keys%initially
\newcommand\includeproblem[2][]{\metasetkeys{inclprob}{#1}%
\input{#2}\clear@inclprob@keys}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Reporting Metadata}
%
%    \begin{macrocode}
\def\pts#1{\ifpts\marginpar{#1 pt}\fi}
\def\min#1{\ifmin\marginpar{#1 min}\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\AtEndDocument{\ifpts\message{Total: \arabic{pts} points}\fi
\ifmin\message{Total: \arabic{min} minutes}\fi}
%    \end{macrocode}
%
% \begin{macro}{\show@pts}
%   The |\show@pts| shows the points: if no points are given from the outside and also no
%   points are given locally do nothing, else show and add. If there are outside points
%   then we show them in the margin.
%    \begin{macrocode}
\newcounter{pts}
\def\show@pts{\ifx\inclprob@pts\@empty%
\ifx\problem@pts\@empty\else%
\ifpts\marginpar{\problem@pts pt\smallskip}\addtocounter{pts}{\problem@pts}\fi%
\fi\else% inclprob@pts nonempty
\ifpts\marginpar{\inclprob@pts pt\smallskip}\addtocounter{pts}{\inclprob@pts}\fi%
\fi}
%    \end{macrocode}
% \end{macro}
% and now the same for the minutes
% \begin{macro}{\show@min}
%    \begin{macrocode}
\newcounter{min}
\def\show@min{\ifx\inclprob@min\@empty%
\ifx\problem@min\@empty\else%
\ifmin\marginpar{\problem@min min}\addtocounter{min}{\problem@min}\fi%
\fi\else%
\ifmin\marginpar{\inclprob@min min}\addtocounter{min}{\inclprob@min}\fi
\fi}
%</package>
%    \end{macrocode}
% \end{macro}
% \Finale
\endinput
% \iffalse
% LocalWords:  GPL structuresharing STR dtx pts keyval xcomment CPERL DefKeyVal iffalse
%%% Local Variables: 
%%% mode: doctex
%%% TeX-master: t
%%% End: 
% \fi
% LocalWords:  RequirePackage Semiverbatim DefEnvironment OptionalKeyVals soln texttt baz
% LocalWords:  exnote DefConstructor inclprob NeedsTeXFormat omd.sty textbackslash exfig
%  LocalWords:  stopsolution fileversion filedate maketitle setcounter tocdepth newpage
%  LocalWords:  tableofcontents showmeta showmeta solutionstrue usepackage minipage hrule
%  LocalWords:  linewidth elefants.prob Elefants smallskip noindent textbf startsolutions
%  LocalWords:  startsolutions stopsolutions stopsolutions includeproblem includeproblem
%  LocalWords:  textsf HorIacJuc cscpnrr11 includemhproblem includemhproblem importmodule
%  LocalWords:  importmhmodule foobar ldots latexml mhcurrentrepos mh-variants mh-variant
%  LocalWords:  compactenum langle rangle langle rangle ltxml metakeys newif ifexnotes rm
%  LocalWords:  exnotesfalse exnotestrue ifhints hintsfalse hintstrue ifsolutions ifpts
%  LocalWords:  solutionsfalse ptsfalse ptstrue ifmin minfalse mintrue ifboxed boxedfalse
%  LocalWords:  boxedtrue sref mdframed marginpar prob srefaddidkey addmetakey refnum kv
%  LocalWords:  newcounter ifx thesection theproblem hfill newenvironment metasetkeys ltx
%  LocalWords:  stepcounter currentsectionlevel xspace ignorespaces surroundwithmdframed
%  LocalWords:  omdoc autoopen autoclose solvedinminutes kvi qw vals newcommand exhint
%  LocalWords:  specialcomment excludecomment mhrepos xref marginpar addtocounter doctex
%  LocalWords:  mh@currentrepos endinput