Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
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
    
@Peter: Thanks. I fixed the link. –  Martin Scharrer Aug 16 '11 at 7:46
    
@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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.