[texhax] More exercises

James Smith sf at aleph-one.com
Thu Jun 14 14:46:28 CEST 2007


Hi,

thanks for all the replies on this subject and apologies for not getting
back in person (too busy).

Okay, so I have a simple command \exercise which numbers and italisizes
exercises and a command \answer which I can place inside exercises to
grab the exercise number. The answers are saved in a vbox and
regurgitated by the \showAllAnswers command. I understand the workings
of the vbox stuff well enough, I believe although embedding the answer
within the exercise means that I have to effectively `embed' an \upshape
command in the \itshape command, but no matter at this point.

My problem is that this design does not support verbatims in the
answers, which are essential. I understand the reason, I cannot pass
verbatims as parts of command arguments. How can I work around this? I
can define the answer command as an environment instead, but how do I
get hold of the contents of the environment? I have trawled through the
exercise package in order to get this far but cannot deduce how it grabs
the contents of its own answer environment, or if it takes this approach
at all. 

One further thing to note. I have tried to google simple commands such
as \unvbox and other (I guess) low level TeX commands found in the .sty
files but google comes up with nothing pertinent. Whatever documentation
or discussion there is available on the web relating to this kind of
stuff just doesn't seem to get indexed.

Thanks again everyone for the advice so far.

The code for what I have so far follows. It works until I replace the
ellipses with a verbatim.

Regards,

James

+++

\documentclass{book}

\usepackage{fancyvrb}

\newcounter{exercise}
\newcommand{\beginExercises}{\newbox\allAnswersBox\setcounter{exercise}{
0}}
\newcommand{\showAllAnswers}{\unvbox\allAnswersBox}

\newcommand{\nb}{\textbf{\thechapter.\theexercise\hspace{.25em}}}
\newcommand{\Exercise}[1]%
{%
\addtocounter{exercise}{1}%
\bigskip\noindent\textbf{Exercise \nb}%
\itshape{#1}%
}
\newcommand{\Answer}[1]%
{%
\newbox\tempAnswerBox\setbox\tempAnswerBox\vbox{\unvbox\allAnswersBox\sm
allskip\noindent\upshape{\nb#1}}%
\global\setbox\allAnswersBox\copy\tempAnswerBox%
}

\begin{document}

\chapter{Test}

\section{Exercises}

\beginExercises

\Exercise{Set up a web application context on the web server of your
choice with an
application name `/jasper/'.

\Answer{
Place the following lines in the `test.html' template file:

...

Remember that these statements only hold true if no temporary or form
variables clash
with these configuration variables. Additional variables can be added to
the global
configuration file and their values echoed in a similar manner.}}

\section{Answers}

\showAllAnswers

\end{document}


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.472 / Virus Database: 269.8.15/848 - Release Date:
13/06/2007 12:50
 



More information about the texhax mailing list