# [OS X TeX] Backanswers in Memoir

Mon Apr 6 04:28:28 CEST 2009

OK.

Tried the following, but no go. Getting this error:

! Argument of \verbatim at start has an extra }.
<inserted text>
\par

?

\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}}

{\ifodd\theexercise{%
\begin{writeverbatim}{backansout}}\else{\begin{comment}}\fi}
{\ifodd\theexercise{%
\end{writeverbatim}}\else{\end{comment}}\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$?
$-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}

\input{\jobname.backans}

\end{document}

On Apr 5, 2009, at 5:05 PM, Ross Moore wrote:

> Hi David,
>
> On 06/04/2009, at 9:24 AM, David Arnold wrote:
>
>> 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{%
>
> You cannot do it this way.
> You need to be writing out into the file,
> the text that lies between
>  ...
>
> By trying to write out the *result* of having typeset
> this info into a box, you will get lots of stuff that
> you cannot control --- as you are discovering.
>
>>
>> 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.
>
>
> I'd advise you to look at:  \usepackage{comment} .
> This lets you define environment that can be switched
> between inclusion or exclusion.
>
>>
>
>>
>> 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
>
>
> Hope this helps,
>
> 	Ross Moore
>
> ------------------------------------------------------------------------
> Ross Moore                                       ross at maths.mq.edu.au
> Mathematics Department                           office: E7A-419
> Macquarie University                             tel: +61 (0)2 9850
> 8955
> Sydney, Australia  2109                          fax: +61 (0)2 9850
> 8114
> ------------------------------------------------------------------------
>
>
>
> ----------- Please Consult the Following Before Posting -----------
> TeX FAQ: http://www.tex.ac.uk/faq
> List Reminders and Etiquette: http://email.esm.psu.edu/mac-tex/
> List Archive: http://tug.org/pipermail/macostex-archives/
> TeX on Mac OS X Website: http://mactex-wiki.tug.org/
> List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex
>