[texhax] Continued from previous post...

James Smith james.smith at aleph-one.com
Thu Mar 20 01:20:52 CET 2008


Barbara,

thanks for the prompt reply, in fact I'm still working on this (although
just about to stop).

I found this...

http://compgeom.cs.uiuc.edu/~jeffe/pubs/tex/scribe.sty

...and learned (I think) that correct spacing (not quite the same as
amsthm, still but) can be had with \trivlist, so I've hacked what's
there somewhat and come up with two new commands that basically work
(apologies for the code listings now, you're free to ignore them!)

+++

\ProvidesPackage{myexercise}

\newcounter{exercisectr}
\newbox\@answerbox

\def\newexercise#1{%
    \expandafter\@ifdefinable\csname #1\endcsname{%
        \global\@namedef{#1}{%
            \addtocounter{exercisectr}{1}%
            \trivlist%
            \item[\hskip\labelsep{%
                \upshape\textbf{Exercise \thechapter.\theexercisectr.}%
            }]%
            \itshape%
        }%
        \global\@namedef{end#1}{%
            \endtrivlist%
        }%
    }%
}
\newexercise{myexercise}

\def\newanswer#1{%
    \expandafter\@ifdefinable\csname #1\endcsname{%
        \global\@namedef{#1}{%
            \newbox\@thisbox%
            \setbox\@thisbox\vbox{%
                \medskip\noindent%
                \upshape\textbf{\thechapter.\theexercisectr.}\bgroup%
            }%
        }%
        \global\@namedef{end#1}{%
            \egroup%
            \newbox\@tempbox%
 
\global\setbox\@tempbox\vbox{\unvbox\@answerbox\unvbox\@thisbox}%
            \global\setbox\@answerbox\copy\@tempbox%
        }%
    }%
}
\newanswer{myanswer}

\newcommand{\showAnswers}{%
\unvbox\@answerbox%
\setcounter{exercisectr}{0}%
}

+++

I see in amsthm.sty that \trivlist is also used, so I hope I'm heading
along the right lines in adapting it here. I assume the amsthm package
cancels out the default \parskip and replaces it with it's own spacing?
I searched for your \addvspace and saw this:

+++

    \addvspace\@topsep
    \addvspace{-\parskip}%



More information about the texhax mailing list