[OS X TeX] Backanswers in Memoir

David Arnold dwarnold45 at suddenlink.net
Sun Apr 5 19:24:46 EDT 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}

\newenvironment{backanswer}%
	{\begin{lrbox}{\backans}}
	{\end{lrbox}\ifodd\theexercise{%
		\addtostream{backansout}{\par\noindent\textbf{\theexercise.}}
		\addtostream{backansout}{\usebox{\backans}}}\fi}

I get this error:

(./QuestionAnswerExperiments.backans
! 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}

\newcommand{\printbackanswers}{%
	\subsection{Backanswers}
	\input{\jobname.backans}}

\newsavebox{\backans}

\newenvironment{backanswer}%
	{\begin{lrbox}{\backans}}
	{\end{lrbox}\ifodd\theexercise{%
		\addtostream{backansout}{\par\noindent\textbf{\theexercise.}}
		\addtostream{backansout}{\usebox{\backans}}}\fi}

\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$?
\begin{backanswer}
$-17$
\end{backanswer}

\end{exercise}

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

\begin{backanswer}
$17$
\end{backanswer}

\end{exercise}

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

\begin{backanswer}
$13$
\end{backanswer}

\end{exercise}

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

\end{exercise}

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

\begin{backanswer}
$17$
\end{backanswer}

\end{exercise}

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

\begin{backanswer}
$13$
\end{backanswer}

\end{exercise}

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

\end{exercise}

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

\begin{backanswer}
$17$
\end{backanswer}

\end{exercise}

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

\begin{backanswer}
$13$
\end{backanswer}

\end{exercise}

\end{Exercises}

\subsection{Answers}

\input{\jobname.backans}

\end{document}



More information about the MacOSX-TeX mailing list