|
11 | 11 | \RequirePackage{etoolbox} |
12 | 12 | \RequirePackage{answers} |
13 | 13 |
|
| 14 | +% write problems to \oljobname.prb |
| 15 | + |
14 | 16 | \def\solutionextension{prb} |
15 | 17 |
|
16 | 18 | \makeatletter |
17 | 19 |
|
18 | | -% save definition of prob environment as probd |
19 | | -\let\probd\prob |
20 | | -\let\endprobd\endprob |
21 | | -\let\c@probd\c@prob |
22 | | -\makeatother |
| 20 | +% Undefine the prob and probtag environments |
23 | 21 |
|
24 | 22 | \csundef{prob} |
25 | 23 | \csundef{endprob} |
26 | 24 | \csundef{probtag} |
27 | 25 | \csundef{endprobtag} |
28 | 26 |
|
| 27 | +% Instead, make them into environments which write probdeferred and |
| 28 | +% probdeferredtag environments to the problem file using answers.sty |
| 29 | + |
29 | 30 | \Newassociation{prob}{probdeferred}{\jobname} |
30 | 31 | \Newassociation{probtag}{probdeferredtag}{\jobname} |
31 | 32 |
|
32 | | -% Redefine probdeferred as a theorem environment |
33 | | -%\csundef{probdeferred} |
34 | | -%\csundef{endprobdeferred} |
35 | | -%\csundef{c@probdeferred} |
| 33 | +% probdeferred and probdeferredtag are just wrappers for theorem |
| 34 | +% environments which do the actual typesetting. answers.sty writes |
| 35 | +% the number of the problem into the .prb file, but we throw them away |
| 36 | +% and just count them separately. It also throws away the tags. This |
| 37 | +% is a bug; actually probtag should deal with the tags but this |
| 38 | +% requires hacking answers.sty code. |
36 | 39 |
|
37 | 40 | \renewenvironment{probdeferred}[1]{\begin{probd}}{\end{probd}} |
38 | 41 | \renewenvironment{probdeferredtag}[2]{\begin{probd}}{\end{probd}} |
39 | 42 |
|
40 | | -%\declaretheorem[ |
41 | | -% style=definition, |
42 | | -% name=Problem, |
43 | | -% sibling=thm]{probdeferred} |
44 | | -% answers writes current label as argument |
45 | | -%\apptocmd{\probdeferred}{\@gobble}{}{} |
| 43 | +% the probd environment does the actual typesetting. |
46 | 44 |
|
47 | | -% at the end of a chapter, read the solutionfile |
48 | | -\appto\OLEndChapterHook{% |
49 | | - \Closesolutionfile{\jobname} |
50 | | - \Readsolutionfile{\jobname}} |
| 45 | +\declaretheorem[ |
| 46 | + style=definition, numbered=yes, |
| 47 | + name={Problem}]{probd} |
| 48 | + |
| 49 | +% Print the chapter number with the problem number |
51 | 50 |
|
52 | | -% at the end of a \chapter command, open the solution file |
| 51 | +\def\theprobd{\probch.\arabic{probd}} |
| 52 | + |
| 53 | +% make sure the .prb file is open |
| 54 | +\Opensolutionfile{\jobname} |
| 55 | + |
| 56 | +% - `\problemsperchapter`: execute this in the preamble to print the |
| 57 | +% - problem file at the end of every chapter |
| 58 | + |
| 59 | +\newcommand{\problemsperchapter}{% |
| 60 | +% after each chapter command, open the .prb file and write a section |
| 61 | +% header into it |
53 | 62 | \renewcommand\memendofchapterhook{% |
| 63 | + \Closesolutionfile{\jobname} |
54 | 64 | \Opensolutionfile{\jobname} |
55 | | - \Writetofile{\jobname}{\protect\section*{Problems}}} |
| 65 | + \Writetofile{\jobname}{ |
| 66 | + \protect\section*{Problems} |
| 67 | + \protect\def\protect\probch{\thechapter} |
| 68 | + \protect\setcounter{probd}{0}}} |
| 69 | + % at the end of every chapter, close the .prb file and print it |
| 70 | + \appto\OLEndChapterHook{% |
| 71 | + \Closesolutionfile{\jobname} |
| 72 | + \def\probch{\thechapter} |
| 73 | + \Readsolutionfile{\jobname}}} |
| 74 | + |
| 75 | +% - `\collectproblems`: execute this in the preamble to arrange for |
| 76 | +% the printing of problems explicitly, e.g., at the end of the book |
| 77 | + |
| 78 | +\newcommand{\collectproblems}{% |
| 79 | +% at the end of every \chapter command, write a section header into |
| 80 | +% the .prb file and reset counters |
| 81 | +\renewcommand\memendofchapterhook{% |
| 82 | + \Writetofile{\jobname}{ |
| 83 | + \protect\section*{Problems for Chapter~\thechapter} |
| 84 | + \protect\def\protect\probch{\thechapter} |
| 85 | + \protect\setcounter{probd}{0}}}} |
| 86 | + |
| 87 | +% \collectproblems is the default, so we execute it right away |
| 88 | + |
| 89 | +\collectproblems |
| 90 | + |
| 91 | +% - `\stopproblems`: execute at the end of the mainmatter, to stop |
| 92 | +% chapter commands from writing to the .prb file |
| 93 | + |
| 94 | +\newcommand{\stopproblems}{% |
| 95 | + \renewcommand\memendofchapterhook{}} |
| 96 | + |
| 97 | +% - `\printproblems`: closes problem file and prints problems. |
| 98 | + |
| 99 | +\newcommand{\printproblems}{% |
| 100 | + \Closesolutionfile{\jobname} |
| 101 | + \Readsolutionfile{\jobname}} |
| 102 | + |
| 103 | +\makeatother |
| 104 | + |
0 commit comments