Dear all, I am new to package writing (LaTeX2e) and to this forum, and I probably read to much of the TeXBook and not enough on LaTeX.
My package works, except that verbatim is verboten. Given a user input of
\begin{file}
\begin{head}
foo1 (say, an exercise)
\end{head}
\begin{body}
\begin{head}
short answer to foo1
\end{head}
\begin{body}
long explanation of the answer to foo1
\end{body}
\end{body}
\begin{head}
foo2 (say, a theorem)
\end{head}
\begin{body}
long explanation of foo2 (say, a very long
proof that we want to put in an Appendix)
\end{body}
\end{file}
I typeset the content of the head
environments, followed by the content of the body
environments, followed by the body
of the body
, etc:
foo1
foo2
short answer to foo1
long explanation of foo2
long explanation of the answer to foo1
with links pointing from each item in one part to the corresponding item of the previous and next parts. The links are (almost) easy to get with some clever numbering.
The file
environment is only there to allow me to read its contents multiple times: I use Will Robertson's environ.sty
, which defines environments that gobble their content and can use it multiple times. Unfortunately, since the content is read before being executed, catcodes are fixed, and verbatim fails. Also, this is quite slow, and memory consuming.
I see three other ways of doing it:
- 2. I guess I could write a custom output routine: typeset all `head`s in parallel of all `body`s in two (or more in case of nesting) boxes, and only then cut into pages. This would be incompatible at least with the `multicols` package (and I would be limited to ~20 pages stored in a single box: maximum length ~6m).
- 3. Write the content of the `body`s verbatim to an auxiliary file. Then load the auxiliary file and execute its content. I am not yet confortable with the read and write possibilities in (La)TeX, but this might be the way to go. Can one write a file and read from it in the same run?
- 4. My last idea is to use the docstrip trickery: make `\end{file}` input the document again, with some booleans/counters set differently. In order to ignore everything until the `\begin{file}`, I need to set quite a few catcodes. Reaching this `\begin{file}`, I need to switch back, and parse the `\begin` and `\end`. Changing catcodes like this is probably not great for compatibility.
Also, nesting of head
/body
makes some of these approaches harder.
Which one (or more) of the four approaches would you recommend?
file
environment enclosing everything. In fact, I wouldn't mind getting rid of that, keeping only thehead
s andbody
s. Would inputting a/several file/s\AtEndDocument
be reasonable?