Production of solution sheets in L^{A}TEX 2ε

Copyright (C) 1994 by Mike Piff

April 21, 1995

Contents

1 Introduction

This package is a modification of the author’s previous style option answers, which has been in use for a few years, and was based upon the TEXbook idea of binding solutions to exercises. I have taken the opportunity with this revision to alter the format of the solutions, so that they are now presented as L^{A}TEX environments rather than being started with a command and ended with the end of the surrounding environment, a wholely un-L^{A}TEXy way of doing things!

The other main change is that several files are allowed to be active at once. This allows some solutions in a book (for instance) to go to the appendices, and some to go to a separate file, to be printed and handed to the students as the course progresses.

Finally, any number of solution-types may now be bound to any file, not just the two old ones, solution and hint.

2 User interface

The package needs to be included with the command

             \usepackage{answers}

\Newassociation After that, there should be several declarations of the form

        \Newassociation{xxx}{yyy}{zzz}

where xxx is an environment in the document, and yyy is an environment which will surround the contents of xxx when it is written to file zzz.sol

\solutionextension  The command \solutionextension can be redefined to change sol to some

other extension.

\Opensolutionfile At some point the user types

\Closesolutionfile
        \Opensolutionfile{zzz}
        ...
        \Closesolutionfile{zzz}

to create several files of solutions written by environments xxx to environments

yyy.

\Writetofile In addition, material can be written directly to a file by means of \Writetofile.

Its first argument is the file zzz and its second is the line of text to be written,

Filesave with any control words preceded by \protect. Alternatively, a block of text can be saved to zzz by means of

        \begin{Filesave}{zzz}
           ....
        \end{Filesave}

around it once zzz has been opened.

\Readsolutionfile One of the generated files can be read using

        \Readsolutionfile{zzz}

or simply \input if preferred.

None of the file operations should have any effect if the file zzz has not been opened.

3 An example

The following is an example of the use of package answers. It also uses some of the refinements described later. 1 ⟨∗example⟩

 2 \documentclass[12pt,a4paper]{article}
 3 \usepackage{answers}

4

 5 \newtheorem{Ex}{Exercise}%% to produce the reference label

6

 7 \Newassociation{solution}{Soln}{test}
 8 \renewcommand{\Solnlabel}[1]{\emph{Solution #1}}
 9 \Newassociation{hint}{Hint}{test}
10 \renewcommand{\Hintlabel}[1]{\emph{Hint #1}}
11 \Newassociation{Solution}{sSol}{testtwo}
12 \renewcommand{\sSollabel}[1]{\emph{Solution to #1}}
13 \renewcommand{\sSolparams}{{\Currentlabel(p.\thepage)}}

14

15 \begin{document}
16 \Opensolutionfile{test}
17 \Writetofile{test}{\protect\section{Solutions}}
18 \Opensolutionfile{testtwo}
19 \Writetofile{testtwo}{\protect\section{Extra Solutions}}
20 \section{First}
21 \begin{Ex}
22 An exercise with a solution.
23 \begin{solution}
24  This is a solution.
25  \relax{}
26 \end{solution}
27 \end{Ex}

28 \begin{Ex}
29 An exercise with a hint and a secret solution.
30 \begin{hint}
31  This is a hint.
32 \end{hint}
33 \begin{Solution}
34  This is a secret solution.
35 \end{Solution}
36 \end{Ex}
37 \begin{Ex}
38 An exercise with a hint.
39 \begin{hint}
40  This is a hint.
41 \end{hint}
42 \end{Ex}
43 \Closesolutionfile{test}
44 \Readsolutionfile{test}
45 \clearpage
46 \Closesolutionfile{testtwo}
47 \Readsolutionfile{testtwo}

48

49 \end{document}

50 ⟨/example⟩