# Include only specific environments

I wish to typeset a document and only include occurrences of one specific environment for the output.

One thing I tried was using the comment package and putting \begin{comment}just after \begin{document} and \end{comment} just before \end{document}. Then I redefined the environment I wanted to include to begin with \end{comment} and end with \begin{comment}. This way only this environment should be uncommented. It compiled fine but gave no page as output.

Another option might be to use the tagging package, but as far as I understand this lets you exclude certain parts. I want to do the opposite, only include certain parts.

EDIT: The background is that I am working on a thesis in linguistics with a large number glossed and numbered examples (sentences with detailed morpheme-by-morpheme translations). There are around hundred of them in total spread around the text and they are all in an example environment from the covington package. I want to generate a document containing only the examples to proofread them extra carefully and to check them against the recordings they are transcribed from.

• Why don't you just comment the rest out? Please provide a Minimal Working Example which illustrates the problem you are experiencing and gives us some idea of what you are trying to do. – cfr May 30 '14 at 0:33
• Have a look at the package: extract. – Pierre May 30 '14 at 0:51
• @cfr: Commenting stuff out is not always an option, especially if you are deciding during compile time whether to include some material or not - for instance via a command line option. – Peter Grill May 30 '14 at 6:06
• @PeterGrill Sure. My point was just that the question wasn't really detailed enough to give a clear picture of what might or might not work as a solution. – cfr May 30 '14 at 21:01
• @cfr I'll expand the question a bit to make it clearer. – Andreas May 31 '14 at 13:12

You can use xcomment package. Put the environment to be typeset inside the argument of \xcomment macro like:

\xcomment{enumerate}   %% only enumerate environment is typeset


Code:

\documentclass{article}
\usepackage{xcomment}
\xcomment{enumerate}   %% only enumerate environment is typeset
\begin{document}
\begin{enumerate}
\item Enumerate item
\end{enumerate}
\begin{itemize}
\item itemize item
\end{itemize}
\begin{figure}
A figure
\end{figure}
\begin{table}
A table
\end{table}
\end{document}


• There is also the package extract – Pierre May 30 '14 at 0:50
• Doesn't seem to work if there is an itemize within an enumerate - don't know if the OP requires that though. – Peter Grill May 30 '14 at 6:03
• Works perfectly for my purposes. Surprisingly simple solution. – Andreas May 30 '14 at 9:57

If your document is not that big, you can selectively de-activate environments using the environ package:

\documentclass{article}
\usepackage{environ}

% environ: 2013/04/01 v0.3 and earlier
\makeatletter
\providecommand{\env@itemize@save@env}{}
\providecommand{\env@itemize@process}{}
\providecommand{\env@figure@save@env}{}
\providecommand{\env@figure@process}{}
\providecommand{\env@table@save@env}{}
\providecommand{\env@table@process}{}
\makeatother

\RenewEnviron{itemize}{}% De-activate itemize
\RenewEnviron{figure}[1][]{}% De-activate figure
\RenewEnviron{table}[1][]{}% De-activate table

\begin{document}

\begin{enumerate}
\item Enumerate item
\end{enumerate}

\begin{itemize}
\item itemize item
\end{itemize}

\begin{figure}
A figure
\end{figure}

\begin{table}
A table
\end{table}

\end{document}