blob: cb7311822d6379fd7da44577c8aa76e086d67189 (
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
|
%%
%% This is file `answers.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% answers.dtx (with options: `answers')
%%
%% Originally developed by Mike Piff
%% Copyright (C) 1990,1994-1996 by Mike Piff
%% Copyright (C) 2009 by
%% Joseph Wright <joseph.wright@morningstar2.co.uk>
%%
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version. The latest
%% version of this license is in the file:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% This work is "maintained" (as per LPPL maintenance status) by
%% Joseph Wright.
%%
\def\fileversion{2.13}
\def\filedate{11 Oct 2010 00:00:00 BST}
\def\filename{answers.dtx}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{answers}
[2010/10/11 v2.13 Production of solution sheets in LaTeX2e]
\newif\ifanswerfiles \answerfilestrue
\DeclareOption{nosolutionfiles}{\answerfilesfalse
\typeout{No answer files being produced}}%
\ProcessOptions
\RequirePackage{verbatim}
\newcommand{\solutionpoint}{.}
\newcommand{\solutionextension}{tex}
\newenvironment{Filesave}[1]{%
\@bsphack
\def\verbatim@processline{}%
\Iffileundefined{#1}{}{%
\Ifopen{#1}{%
\def\verbatim@processline{%
\Ifanswerfiles{%
\immediate\write\@nameuse{#1@file}%
{\the\verbatim@line}%
}{}%
}%
}{}%
}%
\let\do\@makeother\dospecials
\catcode`\^^M\active \catcode`\^^I=12\relax
\verbatim@start
}{\@esphack}
\newcommand{\Writetofile}[2]{%
\@bsphack
\Iffileundefined{#1}{}{%
\Ifopen{#1}{%
{%
\let\protect\string
\Ifanswerfiles{%
\immediate\write\@nameuse{#1@file}{#2}%
}{}%
}%
}{}%
}%
\@esphack
}
\newcommand{\Ifopen}[3]{%
\csname if#1open\endcsname#2\else#3\fi}%
\newcommand{\Iffileundefined}[3]{%
\csname ifx\expandafter\endcsname
\csname #1@file\endcsname\relax
#2\else#3\fi}
\newcommand{\Ifanswerfiles}[2]{%
\ifanswerfiles #1\else #2\fi}
\def\Opensolutionfile#1{%
\@ifnextchar[{\define@filename{#1}}%
{\define@filename{#1}[#1]}}%
\def\define@filename#1[#2]{%
\global\@namedef{#1@filename}{#2\solutionpoint\solutionextension}%
\Ifanswerfiles{%
\typeout{Output from handle #1 going
to #2.\solutionextension}%
}{}%
\Iffileundefined{#1}{%
\expandafter\newwrite\csname #1@file\endcsname
\csname newif\expandafter\endcsname
\csname if#1open\endcsname
\global\csname #1openfalse\endcsname
\expandafter\ifx\csname Open#1hook\endcsname\relax
\global\@namedef{Open#1hook}##1{}%
\fi
\expandafter\ifx\csname Close#1hook\endcsname\relax
\global\@namedef{Close#1hook}##1{}%
\fi
}{}%
\let\Tmp\relax
\Ifopen{#1}{\typeout{File #1 already open}}{%
\Ifanswerfiles{%
\immediate\openout\@nameuse{#1@file}=%
\@nameuse{#1@filename}%
}{}%
\global\csname#1opentrue\endcsname
\def\Tmp{\@nameuse{Open#1hook}{#1}}%
}%
\Tmp
}
\def\Closesolutionfile#1{%
\let\Tmp\relax
\Iffileundefined{#1}{}{%
\Ifopen{#1}{%
\Ifanswerfiles{%
\immediate\closeout\@nameuse{#1@file}%
}{}%
\global\csname #1openfalse\endcsname
\def\Tmp{\@nameuse{Close#1hook}{#1}}%
}{}%
}%
\Tmp
}
\def\Readsolutionfile#1{%
\Ifanswerfiles{%
\Iffileundefined{#1}{}{%
\Ifopen{#1}{%
\typeout{WARNING: attempt to read open file #1}%
}{%
\edef\Tmp{%
\noexpand\InputIfFileExists
{\@nameuse{#1@filename}}{}%
{\noexpand\message{File
\@nameuse{#1@filename}%
\space not found}}%
}%
\Tmp
}%
}%
}{}%
}
\newcommand{\Newassociation}[3]{%
\newsolution{#2}%
\expandafter\ifx\csname #3opentrue\endcsname\relax
\expandafter\newif\csname if#3open\endcsname
\fi
\newenvironment{#1}{%
\Ifanswerfiles{%
\let\Tmp\relax
\Iffileundefined{#3}{}{%
\Ifopen{#3}{%
\immediate\write\@nameuse{#3@file}%
{\string\begin{#2}\@nameuse{#2params}}%
\def\Tmp{\Filesave{#3}}%
}{}%
}%
}{%
\edef\Tmp{\noexpand\begin{#2}\@nameuse{#2params}}%
}%
\csname pre#1\endcsname
\Tmp
}%
{%
\Ifanswerfiles{%
\Iffileundefined{#3}{}{%
\Ifopen{#3}{%
\endFilesave%
\immediate\write\@nameuse{#3@file}%
{\string\end{#2}}%
\csname post#1\endcsname
}{}%
}%
}{%
\end{#2}%
}%
}%
}
\newcommand{\newsolution}[1]{%
\@ifundefined{#1}{%
\global\@definecounter{#1}%
\global\@namedef{#1params}{{\Currentlabel}}%
\newenvironment{#1}[1]%
{%
\refstepcounter{#1}%
\csname pre#1\endcsname
\trivlist
\item[\hskip\itemsep{\@nameuse{#1label}{##1}}]}%
{\csname post#1\endcsname\endtrivlist}%
\global\@namedef{#1label}##1{\solutionstyle{##1}}%
}{\typeout{WARNING: environment #1 already in use}}%
}
\newcommand{\solutionstyle}[1]{\textbf{#1}}
\newcommand{\Currentlabel}{\@currentlabel}
\endinput
%%
%% End of file `answers.sty'.
|