summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/ans/ans.sty
blob: 28f9d588a1a368b60ac19ee1fe5de5e06784a96b (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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
\typeout{Exercise and Answer macros} 
\typeout{Charles Wells cfw2@po.cwru.edu}
\typeout{24 February 1994}

% Copyright 1994 by Charles Frederick Wells.
% May be freely redistributed, provided that the files ans.sty,
% ansdoc.tex and onceexam.tex are distributed together and are not
% changed.

\makeatletter
% Counters for exercise and subexercise numbers
\newcounter{exercounter}
\newcounter{subexercounter}[exercounter]
% % \renewcommand{\thesubexercounter}{\subexerstyle{subexercounter}}
\newif\ifsols
\newif\ifanswerson
\newif\ifanswer
\newif\ifsubanswer
% Used to determine if the current exercise or subexercise
% has an answer


\def\exerbody{%
\setcounter{exercounter}{0}%
\ifanswerson\answerfalse\subanswerfalse\@wrheader\fi%
\ifsols\@wrsolheader\fi}
\newcommand{\exes}[1]{\exersection{#1}\exerbody}
% You can comment out the forms you don't want:
\newcommand{\exercises}{\exes{Exercises}}
\newcommand{\exercise}{\exes{Exercise}}
\newcommand{\problems}{\exes{Problems}}
\newcommand{\extraproblems}{\exes{Extra Credit Problems}}
\newcommand{\samplequestions}{\exes{Sample Test Questions}}

% Amount of vertical space between exercises.
% It would be better to have this space depend on the
% type size.  In hindsight, I think each exercise section
% should be a specially created LaTeX list environment.
% But that's for the next revision!
\newskip\exerskipamount
\exerskipamount=6pt plus 1 pt 
\newcommand{\medgap}{\par\vskip\exerskipamount\noindent}

% \answermark is the symbol that marks questions with answers. 
% Put another symbol here in place of \bullet if you wish.  The
% spacing will take care of itself.  I hope.
\newcommand\answermark{\mbox{$^\bullet$}}

% The following commands set the numbering style for exercises and
% subexercises.  See page 92 of LaTeX book for other
% possibilities.
\def\exerstyle{\arabic}
\def\subexerstyle{\alph}

% The quantities below control the spacing after the problem number
% before the problem starts.  If you change \exerspace all the
% others should change automatically.  The idea is that all the
% problems start with the same indentation and the answer and hard
% symbols are stuck between without affecting the indentation.
% \newdimen{\hardback}
\newdimen{\answerspace}
\newdimen{\exerspace}
\newdimen{\tempdim}
\newdimen{\labeldim}
\settowidth{\labeldim}{\bf5}
\setlength{\exerspace}{\parindent}
\advance\exerspace by -\labeldim
\setlength{\answerspace}{\exerspace}
\settowidth{\tempdim}{\answermark}
\advance\answerspace by -\tempdim

% \@pns is the style of the problem number.  It is set to
% boldface.  Changing \@pns will change the styles of all the
% problem numbers and subproblem letters in both the exercise
% sections and the answer sections.  If you don't want them all
% the same you will have to search the file and change them by
% hand.  
\def\@pns{\bf}

% The following commands head exercises and subexercises.  (See
% ansdoc.tex for a more complete explanation.)  
\newcommand{\exer}{%
\ifnum\c@exercounter>0
\pagebreak[2]\else\nopagebreak\fi\medgap% 
\ifanswerson\ifanswer\noanserror\fi\answerfalse% 
\ifsubanswer\nosubanserror\fi\subanswerfalse\fi
\refstepcounter{exercounter}\setcounter{subexercounter}{0}% 
\@pns\exerstyle{exercounter}.\hspace{\exerspace}\rm}

% \exhead is a header for a set of exercises
\newcommand{\exhead}[1]{\ifnum\c@exercounter>0
\pagebreak[3]\else\nopagebreak\fi
\par\bigskip\noindent{\fbox{%
\advance\textwidth by -1em\parbox{\textwidth}{#1}}}}

% The two lines below produce a version of exhead that does
% not enclose the header in a box.  I changed to the boxed
% version when I noticed that a substantial number of students
% overlooked the header.
% \newcommand{\exhead}{\ifnum\c@exercounter>0
% \pagebreak[3]\else\nopagebreak\fi\par\bigskip\noindent}


\newcommand{\@ssa}% "offset subanswer"
{\phantom{\bf\exerstyle{exercounter}.\ }%
\bf\subexerstyle{subexercounter}}

\newcommand{\exera}{\ifnum\c@exercounter>0
\pagebreak[2]\else\nopagebreak\fi\medgap% 
\ifanswerson\ifanswer\noanserror\fi% 
\ifsubanswer\nosubanserror\fi\subanswerfalse\answertrue\fi
\refstepcounter{exercounter}\setcounter{subexercounter}{0}% 
\@pns\exerstyle{exercounter}.\answermark\hspace{\answerspace}\rm}

\def\eexer{\ifanswerson\ifanswer\noanserror\fi% 
\ifsubanswer\nosubanserror\fi\pagebreak[3]\@wrtail\fi%
\ifsols\@wrsoltail\fi}

\newcommand{\subexer}{\ifanswerson% 
\ifsubanswer\nosubanserror\fi\subanswerfalse\fi% 
\refstepcounter{subexercounter}% 
\nopagebreak[1]\par\noindent\@ssa.\hspace{\exerspace}\rm}

\newcommand{\subexera}{\ifanswerson% 
\ifsubanswer\nosubanserror\fi\answerfalse\subanswertrue\fi% 
\refstepcounter{subexercounter}% 
\nopagebreak[1]\par\noindent\@ssa.%
\answermark\hspace{\answerspace}\rm}

\newcommand{\immsubexer}{\ifanswerson% 
\ifsubanswer\nosubanserror\fi\subanswerfalse\fi% 
\refstepcounter{subexercounter}
\hspace{-\labeldim}\@pns\subexerstyle{subexercounter}.%
\hspace{\exerspace}\rm} 

\newcommand{\immsubexera}{\ifanswerson% 
\ifsubanswer\nosubanserror\fi\answerfalse\subanswertrue\fi% 
\refstepcounter{subexercounter}% 
\hspace{-\labeldim}\@pns\subexerstyle{subexercounter}.%
\answermark\hspace{\answerspace}\rm}

%%The following places the word "(#1)" in boldface after the
% exercise number. 
% I use it to mark exercises "hard", "requires Mathematica",
% etc.
\def\annot#1{\hspace{-\answerspace}{{\bf (#1)}}}

% These are the error messages for problems marked with the
% answermark that don't have answers and vice versa.
\newcommand\anserror{
\typeout{Warning:}
\typeout{Exercise \exerstyle{exercounter} has an answer but is not % 
marked}}
\newcommand\noanserror{
\typeout{Warning:}
\typeout{Exercise \exerstyle{exercounter} has no answer}}
\newcommand\nosubanserror{
\typeout{Warning:} 
\typeout{Exercise \exerstyle{exercounter}.%
\subexerstyle{subexercounter} % 
has no answer}}
\newcommand\subanserror{
\typeout{Warning:}
\typeout{Exercise \exerstyle{exercounter}.%
\subexerstyle{subexercounter} % 
has an answer but is not marked}}

% Following is a modification of the makeindex code.
% It defines the various answer macros that write appropriate
% headers to the answer file.  The answer file has the same name
% as the main file, with the extension ".ans".
% The stuff concerning rightmark etc. control the running heads in
% the answer section.  They won't appear unless you put
% \pagestyle{headings} in the preamble.
% The line in @wrheader beginning \string\ansection* controls what
% is printed before the answers to each section.
% The line saying \typeout controls the message on the screen.
\def\makeanswers{\answersontrue\if@filesw \newwrite\answerfile
  \immediate\openout\answerfile=\jobname.ans%
%makeanswers continues...
  \def\answer{\ifanswer\else\anserror\fi\answerfalse\par
\putinans{\string\antwort[\exerstyle{exercounter}]}\copytoblankline}%
%makeanswers continues...
  \def\subanswer{\ifsubanswer\else\subanserror\fi\subanswerfalse\par
      \ifnum\value{subexercounter}=1
    \putinans{\string\immsubantwort[\exerstyle{exercounter}]%
[\subexerstyle{subexercounter}]}\else 
    \putinans{\string\subantwort[%\string\phantom%
\exerstyle{exercounter}]%
[\subexerstyle{subexercounter}]}\fi
      \copytoblankline}%
%makeanswers continues...
  \def\immsubanswer{\subanswerfalse\par
  \putinans{\string\immsubantwort[\exerstyle{exercounter}]%
[\subexerstyle{subexercounter}]}% 
      \copytoblankline}%
   \typeout{Writing answer file \jobname.ans }\fi}% END \makeanswers

% The command \makesolutions below produces a second file of
% answers for the problems that aren't marked as having answers!
% By putting \dosolutions at the very end of the printout you can
% have a booklet of "answers to problems not answered in the
% text."
\def\makesolutions{\solstrue\if@filesw \newwrite\solutionfile
\newwrite\solutionfile
  \immediate\openout\solutionfile=\jobname.sol%
  \def\solution{\par
    \putinsol%
     {\string\antwort[\exerstyle{exercounter}]}%
     \copysoltoblankline\@esphack}%
  \def\subsolution{\par
      \ifnum\value{subexercounter}=1
    \putinsol{\string\immsubantwort[\exerstyle{exercounter}]%
[\subexerstyle{subexercounter}]}\else 
    \putinans{\string\subantwort[%\string\phantom%
{\exerstyle{exercounter}}]%
[\subexerstyle{subexercounter}]}\fi
      \copysoltoblankline}%
  \def\immsubsolution{\par
  \putinsol{\string\immsubantwort[\exerstyle{exercounter}]%
[\subexerstyle{subexercounter}]}% 
      \copysoltoblankline}%
   \typeout{Writing solutions file \jobname.sol}\fi}% END 


\def\skiplf{\catcode`\^^J=9} 

% The following is by D. Knuth
% It reads a line up to a CR then writes it to file #1
% If it comes to a blank line it quits
% DON'T MESS WITH THIS CODE.  EVEN BREAKING OR COMBINING THE 
% LINES CAN MESS IT UP.
\def\copytoblankline{\begingroup\setupcopy\copyans}
\def\copysoltoblankline{\begingroup\setupcopy\copysol}
   \def\setupcopy{\def\do##1{\catcode`##1=\other}\dospecials
   \catcode`\|=\other \obeylines}
   {\obeylines \gdef\copyans#1
     {\def\next{#1}% 
      \ifx\next\empty\let\next=\endgroup% 
      \else\immediate\write\answerfile{\next} \let\next=\copyans\fi\next}}
   {\obeylines \gdef\copysol#1
     {\def\next{#1}% 
      \ifx\next\empty\let\next=\endgroup% 
      \else\immediate\write\solutionfile{\next} \let\next=\copysol\fi\next}}

% The following modification of copytoblankline is used 
% when answers are turned off
\def\throwaway{\begingroup\setupcopy\killans}
   {\obeylines \gdef\killans#1
     {\def\next{#1}% 
      \ifx\next\empty\let\next=\endgroup % 
      \else\let\next=\killans\fi\next}}

\chardef\other=12 

% The following commands take effect if \makeanswers is not 
% in preamble
% They are intended to do nothing
\def\@wrheader{\relax}
\def\@wrtail{\relax}
\def\@wrsolheader{\relax}
\def\@wrsoltail{\relax}
\def\answer{\throwaway}
\def\solution{\throwaway}
\def\subanswer{\throwaway}
\def\immsubanswer{\throwaway}



\answersonfalse
\solsfalse

% The words containing "antwort" format the answers in the
% answer file.

\def\ant{\@startsection
 {paragraph}{4}{\z@}{-6pt plus -2pt minus -1pt}{-1em plus
-.2em}{\normalsize\@pns}}


\def\antwort[#1]{\ant{#1.}} %%Note the period
% \def\subantwort[#1][#2]{\par\noindent\@pns#1\phantom{.}\ \ #2.\ \rm}
\def\subantwort[#1][#2]{\pagebreak[1]%
\medgap\@pns\phantom{#1.}\ \ #2.\ \rm}
\def\immsubantwort[#1][#2]{\pagebreak[2]\medgap\@pns#1.\ \ #2.\ \rm} 


% Here are some commands used repeatedly in \makeanswers and in
% the option commands \artsec, \bkchap, etc.
\def\putinans{\immediate\write\answerfile}
\def\putinsol{\immediate\write\solutionfile}
\def\putbreak{\string\pagebreak[3]\string\medbreak\noindent}

% This command is called by doanswers and can be used to customize
% the answer section.  For example, if you want the answers in
% small type, you could put "\def\@therstuff{\small}" in the
% preamble.
\def\@therstuff{\relax}

\def\do@nswers[#1]{
\ifanswerson\putinans{\string\par}
\immediate\closeout\answerfile% \fi
\@therstuff
\def\rightmark{\expandafter\@rightmark\botmark}
\def\leftmark{\expandafter\@leftmark\firstmark}\fi
\answersonfalse % minor kludge because answerfile is closed
\anshead
\input{#1.ans}
\eject}
 
% The following command should be put at place in the book where the
% answers go, e.g. after the bibliography and before the index.
% "Answers to selected exercises" heads the whole section.
% Answers to each section are headed by "Section #.#".  
% That is controlled by \@wrheader (above).
\def\doanswers{\@ifnextchar [{\do@nswers}{\do@nswers[\jobname]}}

\def\dos@ls[#1]{
\immediate\write\solutionfile{\string\par}
\immediate\closeout\solutionfile
\@therstuff
\setcounter{page}{1}
\def\rightmark{\expandafter\@rightmark\botmark}
\def\leftmark{\expandafter\@leftmark\firstmark}
\raggedbottom% In case not used earlier
\solhead
\input{#1.sol}
\eject}

% The command \dosolutions produces a booklet of answers to
% questions not answered in the text (provided you write the
% answers!)  It could be put at the end of the .tex file after
% resetting the page number.
\def\dosolutions{\@ifnextchar [{\dos@ls}{\dos@ls[\jobname]}}

% The following commands allow ans.sty to be used with book.sty or
% article.sty, with various arrangements of the exercises.

% Use this command in your preamble if you are using article style
% and have (at most) one section of exercises per section.
\def\artsec{%
  \def\exersection{\subsection}%
  \def\ansection{\section}%
  \def\anshead{%
    \section*{Answers to selected exercises}\label{ansec}
    \sectionmark{}}
  \def\solhead{%
    \noindent\section*{Solutions to exercises\protect\\ 
not answered in text}%
    \sectionmark{}}
  \def\@wrheader{\begingroup
      \xdef\@gtempa{%
\putinans{\string\ansection*{Section \thesection}\string\nopagebreak}
 \putinans{\string\typeout{Answers to Section \thesection}}
 \putinans{\string\markboth{Answers for Section \thesection}
{Answers for Section \thesection\string\enskip}}}
        \@gtempa\endgroup}%
   \def\@wrsolheader{\begingroup
      \xdef\@gtempa{%
 \putinsol{\string\ansection*{Section \thesection}\string\nopagebreak}
 \putinsol{\string\typeout{Solutions to Section \thesection}}
 \putinsol{\string\markboth{Solutions for Section \thesection}
{Solutions for Section \thesection\string\enskip}}}
        \@gtempa\endgroup}%
   \def\@wrtail{\xdef\@gtempa{%
 \putinans{\string\markboth{Answers for Section \thesection}
{Answers for Section \thesection\string\enskip}}
  \putinans{\putbreak}}
       \@gtempa}
   \def\@wrsoltail{
\xdef\@gtempa{\putinsol{\string\markboth{Solutions for Section
   \thesection}
{Solutions for Section \thesection\string\enskip}}
    \putinsol{\string\pagebreak[3]\string\medbreak\noindent}}
       \@gtempa}}% end \artsec

% Use this command if you are using bookstyle and have at most one
% set of exercises per chapter.
\def\bkchap{%
  \def\exersection{\section}%
  \def\anstochap{\section}%
  \def\anshead{%
    \addcontentsline{toc}{part}{Answers to selected problems} 
    \chapter*{Answers to selected problems}\label{ansec}
    \chaptermark{}}
  \def\solhead{%
    \chapter*{Solutions to problems\protect\\ 
     not answered in text}
    \chaptermark{}}
   \def\@wrheader{\begingroup
      \xdef\@gtempa{%
 \putinans{\string\anstochap*{Chapter \thechapter}\string\nopagebreak}
 \putinans{\string\typeout{Answers to Chapter \thechapter}}
  \putinans{\string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}
%       \putinans{%
% % The following causes the string "Solutions for Chapter n"
% % to be added IN THE FORMAT OF A SECTION ENTRY in the t.o.c
%  \string\addcontentsline{toc}{section}{\string\protect
%  \string\numberline{0}{Solutions for Chapter \thechapter}}}
}
        \@gtempa\endgroup}%
   \def\@wrsolheader{\begingroup
      \xdef\@gtempa%
 {\putinsol{\string\anstochap*{Chapter \thechapter}\string\nopagebreak}
 \putinsol{\string\typeout{Solutions to Chapter \thechapter}}
 \putinsol{\string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}}
       \@gtempa\endgroup}%
   \def\@wrtail{\xdef\@gtempa{%
 \putinans{\string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}
      \putinans{\putbreak}}
       \@gtempa}
   \def\@wrsoltail{
\xdef\@gtempa{\immediate\write\solutionfile{%
       \string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}
      \immediate\write\solutionfile{\string\pagebreak[3]
         \string\medbreak\noindent}}
       \@gtempa}}% end\bkchap

\def\twocolbkchap{%
  \def\exersection{\section}%
  \def\anstochap{\section}%
  \def\anshead{%
    \addcontentsline{toc}{part}{Answers to selected problems} 
    \chapter*{Answers to selected problems}\label{ansec}
    \chaptermark{}}
  \def\solhead{%
    \chapter*{Solutions to problems\protect\\ 
     not answered in text}
    \chaptermark{}}
   \def\@wrheader{\begingroup
      \xdef\@gtempa{%
 \putinans{\string\anstochap*{Chapter \thechapter}\string\nopagebreak}
 \putinans{\string\typeout{Answers to Chapter \thechapter}}
  \putinans{\string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}
%       \putinans{%
% % The following causes the string "Solutions for Chapter n"
% % to be added IN THE FORMAT OF A SECTION ENTRY in the t.o.c
%  \string\addcontentsline{toc}{section}{\string\protect
%  \string\numberline{0}{Solutions for Chapter \thechapter}}}
}
        \@gtempa\endgroup}%
   \def\@wrsolheader{\begingroup
      \xdef\@gtempa%
 {\putinsol{\string\anstochap*{Chapter \thechapter}\string\nopagebreak}
 \putinsol{\string\typeout{Solutions to Chapter \thechapter}}
 \putinsol{\string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}}
       \@gtempa\endgroup}%
   \def\@wrtail{\xdef\@gtempa{%
 \putinans{\string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}
      \putinans{\putbreak}}
       \@gtempa}
   \def\@wrsoltail{
\xdef\@gtempa{\immediate\write\solutionfile{%
       \string\markboth{Solutions for Chapter \thechapter}
{Solutions for Chapter \thechapter\string\enskip}}
      \immediate\write\solutionfile{\string\pagebreak[3]
         \string\medbreak\noindent}}
       \@gtempa}}% end\bkchap


% Use this command if you are using book style and have at most
% one set of exercises per section.
\def\bksec{%
  \def\exersection{\section}%
  \def\anstochap{\section}%
  \def\ansection{\subsection}%
  \def\anshead{%
    \setcounter{chapter}{-1}
    \setcounter{section}{0}
    \chapter{Answers to selected exercises}\label{ansec}
    \chaptermark{Answers to exercises}}
  \def\solhead{%
    \chapter*{Solutions to exercises\protect\\ not answered in text}
    \chaptermark{Solutions to exercises}}
   \def\@nschap{\ifnum \c@chapter >\z@
      {\begingroup
      \xdef\@gtempa{\putinans{%
      \string\typeout{Chapter \thechapter\space solutions}}
% using several \writes keeps the answer file lines from being too long
      \putinans{%
      \string\noindent%
      \string\anstochap*{Solutions for Chapter \thechapter}%
      \string\nopagebreak}
      \putinans{%
 \string\addcontentsline{toc}{chapter}{\string\protect
 \string\numberline{0}{Solutions for Chapter \thechapter}}}}
        \@gtempa\endgroup}\fi}%
   \def\s@lchap{\ifnum \c@chapter >\z@
      {\begingroup
      \xdef\@gtempa{\putinsol{%
      \string\typeout{Chapter \thechapter\space solutions}}
% using several \writes keeps the answer file lines from being too long
      \putinsol{%
      \string\noindent%
      \string\anstochap*{Solutions for Chapter \thechapter}%
      \string\nopagebreak}}%
        \@gtempa\endgroup}\fi}%
   \def\@wrheader{\begingroup
      \xdef\@gtempa{\putinans{%
       \string\ansection*{Section \thesection}\string\nopagebreak
       \string\markboth{Solutions for section \thesection}
{Solutions for section \thesection\string\enskip}}}
        \@gtempa\endgroup}%
   \def\@wrsolheader{\begingroup
      \xdef\@gtempa{%
 \putinsol{\string\anstochap*{Section \thesection}\string\nopagebreak}
 \putinsol{\string\typeout{Solutions to Section \thesection}}
 \putinsol{\string\markboth{Solutions for Section \thesection}
{Solutions for Section \thesection\string\enskip}}}
        \@gtempa\endgroup}%
% Following rewrites chapter to write heading in answer section
   \let\ch@@@p=\chapter
   \def\chapter{\ch@@@p\@nschap\s@lchap}
   \def\@wrtail{
\xdef\@gtempa{\putinans{%
       \string\markboth{Solutions for section \thesection}
{Solutions for section \thesection\string\enskip}}
      \putinans{\putbreak}}
    \@gtempa}
   \def\@wrsoltail{
\xdef\@gtempa{\putinsol{\string\markboth{Solutions for Section
   \thesection}
{Solutions for Section \thesection\string\enskip}}
    \putinsol{\string\pagebreak[3]\string\medbreak\noindent}}
       \@gtempa}}% end\bksec

\def\once{%
  \renewcommand{\exercises}{\setcounter{exercounter}{0}%
     \ifanswerson\answerfalse\subanswerfalse\fi\@wrheader}
  \def\anshead{\relax}
  \def\@wrheader{\putinans{\string\typeout{Answers}}}
   \def\@wrtail{\relax}
  \ifsols{%
\typeout{Sorry, you can't make a Solutions Manual in this style}
\solsfalse}\fi}% end \once