[OS X TeX] Tried comment environment in Memoir

David Arnold dwarnold45 at suddenlink.net
Mon Apr 6 04:38:20 CEST 2009


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

! Argument of \verbatim at start has an extra }.
<inserted text>
                 \par
l.47 \begin{backanswer}

?

Note sure why this doesn't work:

\newenvironment{backanswer}%
	{\ifodd\theexercise{%
		\addtostream{backansout}{\par\noindent\textbf{\theexercise.}}
		\begin{writeverbatim}{backansout}}\else{\begin{comment}}\fi}
	{\ifodd\theexercise{%
		\end{writeverbatim}}\else{\end{comment}}\fi}

Here's the full code example:


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



\newenvironment{backanswer}%
	{\ifodd\theexercise{%
		\addtostream{backansout}{\par\noindent\textbf{\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$?
\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 macostex-archives mailing list