On Mon, May 21, 2001 at 02:03:35PM +0200, Julien Puydt wrote:
> Bonjour,
>
> I think you may be able to help me on this: I would like to type an
> exercise with its solution in my text, and have the dvi display something
> like "Exercise 172.91: <the question(s)>" at the right place, and in a
> last section of the chapter, "Solution of 172.91: <the solution(s)>".
>
> It would involve being able to store the solutions (with the numbers of
> the exercises they correspond to) until the end of the chapter, and then
> dump everything in an automatically-added section, but since I'm no latex
> guru and just a lyx beginner, I'm quite unable to do it...
I'm assuming you already use an "exercise" paragraph style that gives you the
numbering of your exercises.
Suppose that your exercise counter is called xca (as in the amsbook class).
Put the following in the preamble:
\usepackage{ifthen}
\newcommand{\store}[2]{\expandafter\def\csname sol#1\endcsname{#2}}
\newcommand{\showstored}[1]{\csname sol#1\endcsname}
\newcounter{tmp}
\newcommand{\showall}{\setcounter{tmp}{1}%
\whiledo{\not\(\value{tmp}>\value{xca}\)}{%
\noindent\textbf{Solution of exercise \thechapter.\arabic{tmp}:}%
\showstored{\arabic{tmp}}\par%
\addtocounter{tmp}{1}}}
\newcommand{\solution}[1]{\store{\arabic{xca}}{#1}}
Then, put the solution for an exercise inside a \solution{} command,
namely \solution{<the solution...>}.
Furthermore, put \showall at the end of the chapter.