In my LaTeX documents I tend to use a huge number of examples based on \usepackage{gb4e} (\begin{exe} \ex bla bla bla \end{exe}). I would like to compile a PDF file that lists all the examples in a long text (and nothing else). This file should be compiled in addition to the standard PDF (which includes the examples, too).

It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that shows a small sample document, and an example of the desired output you wanted to get from that document. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving the problem.
–
Peter GrillNov 18 '12 at 20:04

1 Answer
1

This is a two-part answer: (a) What you ask for; (b) what you (probably) need.

Let's start with what you ask: To extract the contents of all gb4e example environments, you can use the extract package. Briefly, you name one or more environment names and it writes the contents to a file of your choice (here, myexamples.tex):

\usepackage[active, generate=myexamples, extract-env={exe}]{extract}

(If you omit the option active, extract does nothing.) This will dump just the examples in a raw file, which you can easily \input into a separate wrapper file with a proper title, margins, etc:

Disclaimer: Not tested; this is to give you the general idea. Try it out, read the extract documentation, and check back if there are problems you can't solve. You may also want to look at this for other ways to achieve the same thing.

Now for what you need: You're looking for a way to pull your examples out of a long text, probably in preparation for creating a handout. If you dump the examples, clean them up into a handout, and then change some examples in either the original text or in the handout, you'll have to re-synchronize and will eventually miss something. That's the problem with working with a copy.

A more viable solution would be to consider the beamer package, which has a built-in mechanism for allowing selected parts of your document source to be typeset: You can produce a full paper, a handout, or a slide presentation from the same document. If beamer is not your cup of tea, look for another solution along these lines (selective typesetting from a single source document), instead of dumping and editing a separate copy of your examples.

It took me quite some time to figure how the extract usepackage is working. But now that I got it, the extract-usepackage proves itself to be remarkably helpful. So thank you so much for this answer. Here my minimal working solution. Just in case other users are trying desperately as well. \documentclass[14pt]{book} \usepackage[active, copydocumentclass=true, generate=myitems, extract-env={exe}]{extract} \usepackage{gb4e} \begin{extract} \usepackage{gb4e} \end{extract} \begin{document} \begin{exe} \ex asdf \end{exe} \end{document}
–
PhilipDec 25 '12 at 16:01