[OS X TeX] putting questions and answers into solutions manual

Art Werschulz agw at comcast.net
Sun Aug 31 04:45:32 CEST 2008


Hi all.

I am currently working on a textbook, which will have an exercise set at
the end of each chapter.  I'm using the answers package as my main help
here.

The overall setup of a chapter is as follows:

   \chapterwithexercises{Foo}

   Material.

   \begin{exercises}
   \begin{ex}
      The first problem.
      \begin{soln}
         First problem's solution.
      \end{soln}
   \end{ex}
   \begin{ex}
      The second problem.
      \begin{soln}
         Second problem's solution.
      \end{soln}
   \end{ex}
   \end{exercises}

I'm defining the following in the book's preamble:

   \usepackage{answers}
   \Newassociation{soln}{solution}{answers}
   \newcounter{chapterans}
   \newcommand\chapterwithexercises[1]{
       \chapter{#1}
       \setcounter{chapterans}{\value{chapter}}
       \addtocounter{chapterans}{-1}
       \Writetofile{answers}{}
       \Writetofile{answers}{\protect\setcounter{chapter} 
{\arabic{chapterans}}}
       \Writetofile{answers}{\protect\chapter{#1}}
   }
   \newenvironment{exercises}{\section*{Exercises}}{}
   \newenvironment{problist}%
     {\renewcommand{\labelenumi}{(\alph{enumi})}\begin{enumerate}}%
     {\end{enumerate}}
   \theoremstyle{definition}
   \newtheorem{ex}{}[chapter]

This has the effect of writing the following to the file answers.tex
(I'm ignoring whitespace):

   \setcounter{chapter}{1}
   \chapter{Foo}
   \begin{solution}{2.1}
      First problem's solution.
   \end{solution}
   \begin{solution}{2.2}
      Second problem's solution.
   \end{solution}

This is okay so far.  However, my coauthors would prefer that the
solutions manual also contain the text of each problem.  My first
thought was to change the definition of the exercises environment as
follows:
   \newenvironment{exercises}%
     {\section*{Exercises}\begin{Filesave}{answers}}%
     {\end{Filesave}}
In other words, everything in the exercises environment would be saved  
to
the files answers.tex.  The problem is that the \end{exercises} line is
also being saved to answers.tex, i.e.:

   \setcounter{chapter}{1}
   \chapter{Foo}
   \begin{ex}
      The first problem.
      \begin{soln}
         First problem's solution.
      \end{soln}
   \end{ex}
   \begin{ex}
      The second problem.
      \begin{soln}
         Second problem's solution.
      \end{soln}
   \end{ex}
   \end{exercises}

Of course, this wreaks major havoc, since there's no previous
   \begin{exercises}
in answers.tex.

As per http://tinyurl.com/6xbbf3, when you have
   \newenvironment{nam}{begdef}{enddef}
"enddef" is the text substituted for every occurrence of "\end{nam}".
I don't understand why
   \end{exercises}
is appearing in answers.tex.

More to the point, can anybody tell me how to not have the line
   \end{exercises}
appear in answers.tex?

Many thanks!


Art Werschulz (8-{)}   "Metaphors be with you."  -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y?
Internet: agw STRUDEL comcast.net






More information about the macostex-archives mailing list