# [OS X TeX] Backanswers in Memoir

Mon Apr 6 01:24:46 CEST 2009

All,

I'm trying to print only odd backanswers using the memoir class. My
full code sample appears below. The crux of the matter is this new
environment, where I am trying to output the contents of the
environment to \jobname.backans only if the exercise number is odd:

\newsavebox{\backans}

{\begin{lrbox}{\backans}}
{\end{lrbox}\ifodd\theexercise{%

I get this error:

! Undefined control sequence.
l.2 \unhbox \voidb
@x \copy \backans \relax
?

And the contents of \jobname.backans are:

\par \noindent \textbf {1.}
\unhbox \voidb at x \copy \backans \relax
\par \noindent \textbf {3.}
\unhbox \voidb at x \copy \backans \relax
\par \noindent \textbf {5.}
\unhbox \voidb at x \copy \backans \relax
\par \noindent \textbf {7.}
\unhbox \voidb at x \copy \backans \relax
\par \noindent \textbf {9.}
\unhbox \voidb at x \copy \backans \relax

Please be kind. I'm OK using LaTeX to write documents, but I'm pretty
lousy at the coding end and trying to write macros.

Any help appreciated.

As a second request, if anyone could help me get these exercises into
two columns using all of the page (no odd-even large margins), that
would also be appreciated.

Thanks.

David Arnold
College of the Redwoods
http://msemac.redwoods.edu/~darnold/index.php

\documentclass{memoir}

\chapterstyle{bianchi}

\newoutputstream{backansout}

\newenvironment{Exercises}
{\openoutputfile{\jobname.backans}{backansout}}
{\closeoutputstream{backansout}}

\newcounter{exercise}[section]
\renewcommand{\theexercise}{\arabic{exercise}}

\newenvironment{exercise}%
{\refstepcounter{exercise}
\par\noindent\textbf{\theexercise}.}
{\par}

\input{\jobname.backans}}

\newsavebox{\backans}

{\begin{lrbox}{\backans}}
{\end{lrbox}\ifodd\theexercise{%

\begin{document}

\chapter{The Whole Numbers}

\section{Introduction to the Whole Numbers}

Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.

\subsection{Exercises}

\begin{Exercises}

\begin{exercise}
What is the sum of $-2$ and $-15$?
$-17$

\end{exercise}

\begin{exercise}
What is the sum of 2 and 15?

$17$

\end{exercise}

\begin{exercise}
What is the sum of $-2$ and 15?

$13$

\end{exercise}

\begin{exercise}
What is the sum of $-2$ and $-15$?
$-17$

\end{exercise}

\begin{exercise}
What is the sum of 2 and 15?

$17$

\end{exercise}

\begin{exercise}
What is the sum of $-2$ and 15?

$13$

\end{exercise}

\begin{exercise}
What is the sum of $-2$ and $-15$?
$-17$

\end{exercise}

\begin{exercise}
What is the sum of 2 and 15?

$17$

\end{exercise}

\begin{exercise}
What is the sum of $-2$ and 15?

$13$

\end{exercise}

\end{Exercises}