# Delimit a single auxiliary file into chunks, and include these at separate places?

I have a LaTeX file for inclusion, automatically generated by a code-documentation tool, so the fact it’s a single file is non-negotiable. However, I want to include it not all at once, but some parts in one place, some in another — so I’d like to put some sort of delimiting information into the auxiliary file, perhaps giving labels to specific chunks, and then have a syntax for including the individual chunks as though there.

I’m imagining something the following: an auxiliary file quotations.tex looking something like:

\begin{chunk}{shakespeare}
\begin{quote}To be or not to be?''\end{quote}
\end{chunk}

There might also be other content between the chunks, like this.

\begin{chunk}{pythagoras}
$x^2 + y^2 = z^2$
\end{chunk}


and then in the main file,

[preamble etc.]

Shakespeare wrote:
\includechunk{quotations.tex}{shakespeare}

Pythagoras proved:
\includechunk{quotations.tex}{pythagoras}


(In my actual document, the chunks are much longer than this — typically a page or two.) Is there a good way of doing something like this? The include file is generated by coqdoc, if that’s relevant.

-
Have a look at the catchfilebetweentag package. – Martin Scharrer Aug 15 '11 at 20:03
@Martin: wonderful, thankyou — that looks perfect for my purpose! I clearly need to improve my tex-package google-fu. If you make that an answer, I’ll accept it. – Peter LeFanu Lumsdaine Aug 15 '11 at 20:16
Don't worry there are a lot of packages on CTAN which I don't know either. :-) – Martin Scharrer Aug 15 '11 at 20:31

The catchfilebetweentags package can be used to read a file into a macro between two tags or other markers. I'm not sure if using a chunk environment is a good idea, because the end-marker would then be identical for every chunk, but it might actually work, assuming the package reads to the first occurrence of the end-marker.
Yes, catchfilebetweentags’s ability to use custom delimiters works much better for me than doing it as an environment. Thanks again; this seems to work just as I’d hoped. – Peter LeFanu Lumsdaine Aug 15 '11 at 21:05
@Martin: The link you provided for catchfilebetweentag does not seem to be working. – Peter Grill Aug 16 '11 at 3:55
Nevermind; got it working with \CatchFileBetweenTags{\whatever}{filename}{tagname} \whatever – Andrew Bolster Oct 18 '11 at 11:02