4

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.

Werner
  • 603,163

1 Answers1

5

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.

Martin Scharrer
  • 262,582
  • 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 03:55
  • @MartinScharrer can you point to a idiot-proof example for this? I can't find anything that actually explains how to use this package to grab and input the tagged sections. – Andrew Bolster Oct 18 '11 at 10:57
  • Nevermind; got it working with \CatchFileBetweenTags{\whatever}{filename}{tagname} \whatever – Andrew Bolster Oct 18 '11 at 11:02
  • @AndrewBolster: Actually I just figured out that you can't use { } inside the \CatchFileBetweenDelims delimiters, but using docstrip-style tags with \CatchFileBetweenTags should work fine. – Martin Scharrer Oct 18 '11 at 11:57