[OS X TeX] Tried comment environment in Memoir

Ross Moore ross at ics.mq.edu.au
Mon Apr 6 00:08:41 EDT 2009


Hi David,

On 06/04/2009, at 12:38 PM, David Arnold wrote:

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

This cannot work, as the first instance of
    \begin{writeverbatim}
will never finish.

It never encounters the corresponding  \end{writeverbatim} ,
as the first (and every subsequent) \end{backanswer}  does not
expand --- since we are in verbatim-mode at that point.





>
> Here's the full code example:

The coding that I attach works just fine.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: arnoldAnswers.tex
Type: application/octet-stream
Size: 2860 bytes
Desc: not available
URL: <http://email.esm.psu.edu/pipermail/macosx-tex/attachments/20090406/24b0c3e3/attachment.obj>
-------------- next part --------------


The main tricks are:

   1.  write all the answers into the back-answer file,
       tagged as {evenanswer} or {oddanswer} environments;

   2.  use \newenvironment{oddanswer}
       and \newenvironment{evenanswer}
       to layout the answers as you want, but ...

   3.  use  \excludecomment{evenanswer}  to bypass these
       when you read the answers back in.
       If you choose to show all the answers, simply
       comment-out this single line!

   4.  organise your questions&solutions as follows:


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



The apparent extra \end{writeverbatim}  closes of
the  \begin{writeverbatim}  in the expansion of
  \begin{backanswer} .

viz.

\newenvironment{backanswer}%
	{\ifodd\theexercise{%
		\addtostream{backansout}{\protect\begin{oddexercise}{\theexercise}}%
	 }\else{%
		\addtostream{backansout}{\protect\begin{evenexercise}{\theexercise}}%
	}\fi
	\begin{writeverbatim}{backansout}}%
%
	{\ifodd\theexercise{%
		\addtostream{backansout}{\protect\end{oddexercise}}%
	 }\else{%
		\addtostream{backansout}{\protect\end{evenexercise}}%
	}\fi}
	
\newenvironment{oddexercise}[1]{\par\noindent\textbf{#1.}}{}
\newenvironment{evenexercise}[1]{\par\noindent\textbf{#1.}}{}

%\includecomment{oddexercise}
\excludecomment{evenexercise}


> \end{Exercises}
>
> \subsection{Answers}
>
> \input{\jobname.backans}
>
> \end{document}


Hope this helps,

	Ross

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





More information about the MacOSX-TeX mailing list