All,

I have a files of exercises written in latex that I'd like to parse. I am new to this so be kind.

The exercise occurs between

\begin{exer} \end{exer}
pairs. Inside this pair are pairs:

\begin{exertext}...\end{exertext} delimiting the problem statement.

\begin{soln}...\end{soln} delimiting the problem solution

\begin{answer}...\end{answer} delimiting a backanswer that goes in the back of the textbook.

Finally, there are sporadic directions that are included betwen \begin{instructions}...\end{instructions} pairs. A short example:

\begin{instructions} In Exercises~\ref{2.nformst} and~\ref{2.nformend +} , given the function $\phi$, place the ordinary differential equation $\phi(t,y,y')=0$ in normal form. \end{instructions} \begin{exer} \begin{exertext} \label{2.nformst} $\phi(x,y,z)=x^2z+(1+x)y$ \end{exertext} \begin{soln} $\phi(t,y,y') = t^2y'+(1+t)y = 0$ must be solved for $y'$. We get $$y'= -\frac{(1+t)y}{t^2}.$$ \end{soln} \begin{answer}$y'= -\dfrac{(1+t)y}{t^2}.$\end{answer} \end{exer} \begin{exer} \begin{exertext} \label{2.nformend} $\phi(x,y,z)=xz-2y-x^2$ \end{exertext} \begin{soln} $\phi(t,y,y')=ty'-2y-t^2$ must be solved for $y'$. We get $$y'=\frac{2y+t^2}{t}.$$ \end{soln} \end{exer} \begin{instructions} In Exercises~\ref{2.1st}--\ref{exer2.1.6}, show that the given solution is a general solution of the differential equation. Use a computer or calculator to sketch the solutions for the given values of the arbitrary constant. Experiment with different intervals for $t$ until +you have a plot that shows what you consider to be the most important behavior of the family. \end{instructions} \begin{exer} \begin{exertext} \label{2.1st} $y'=-ty$, $y(t)=Ce^{-(1/2)\,t^2}$, $C=-3,-2,\ldots,3$ \end{exertext} \begin{soln} $y(t)' = -Cte^{-(1/2)\,t^2}$ and $-ty(t) = -tCe^{-(1/2)\,t^2}$, so $y'=-ty$. \par \exfig{ex2.1ans01} \end{soln} \begin{answer}\exfig{ex2.1ans01}\end{answer} \end{exer}

Is there a module on CPAN which I can use to parse this document. My goal is to put all the exercise problem statements (delimited by \begin{exertext}...\end{exertext}) in a file, all the solutions in a second file, all the backanswers in a third file, etc.

Thanks.


In reply to Parsing Exercise set by David Arnold

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.