As a follow up to this Question
Situation
I would like to create an excerpt from a script that I have TeX'ed as a compendium of the most important statements (theorems & definitions).
I seek to import parts of a file in a way to keep the original numbering (as in the above mentioned question), which is why the MWE imports all, but does not print certain parts.
In order to make the import easier, I would prefer just one (or two) type(s) of tag(s): %<*include> ... %</include> (& %<*exclude> ... %</exclude>).
In the file for the shortened version I need a way to go through all tags and display some (while hiding others).
This would mean a lot less work! Is there a way to achieve this by importing with a loop, macro or maybe some other package ?
QUESTION
Is it possible to have a loop or some macro import all tagged parts of a file while excluding others?
Note: A similar unanswered question does not take into account the numbering and thus different import
MWE by touhami (slightly altered)
first file (with tags)
\documentclass{amsart}
\usepackage{lipsum}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\begin{document}
%<*tag>
\lipsum[1]
Here we go
%</tag>
%<*atag>
\begin{definition}
some bla bla
\end{definition}
%</atag>
\begin{theorem}
more bla bla
\end{theorem}
\begin{definition}
some bla bla
\end{definition}
%<*btag>
\begin{definition}
some bla bla
\end{definition}
\begin{theorem}
more bla bla
\end{theorem}
%</btag>
%<*ctag>
\lipsum[1-2]
%</ctag>
%<*dtag>
\begin{lemma}
more bla bla
\end{lemma}
\begin{theorem}
more bla bla
\end{theorem}
%</dtag>
%<*etag>
\lipsum[1-2]
\begin{example}
some bla bla
\end{example}
%</etag>
\begin{theorem}
more bla bla
\end{theorem}
\end{document}
final file
\documentclass{amsart}
\usepackage{lipsum}
\usepackage{catchfilebetweentags}
\newtoks\temptoken
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\begin{document}
\lipsum[1]
\CatchFileBetweenTags\temptoken{equ}{tag}% capture part1
\setbox0=\vbox{\the\temptoken}% skip part1
\CatchFileBetweenTags\temptoken{equ}{atag}% capture part2
\the\temptoken % display part2
\CatchFileBetweenTags\temptoken{equ}{btag}% capture part3
\setbox0=\vbox{\the\temptoken}% skip part3
\CatchFileBetweenTags\temptoken{equ}{ctag}% capture part4
\setbox0=\vbox{\the\temptoken}% skip part4
\CatchFileBetweenTags\temptoken{equ}{dtag}% capture part5
\the\temptoken% display part5
\end{document}
(the odd numbering is intended!)

\bgroupand\egroupcommands to specify the range of effect for the preceding commands ? Also, I have structured the complete version in chapter files. I suppose the best way to use this is by just defining an environment per file or would you recommend something else? – BadAtLaTeX Mar 05 '16 at 13:52\bgroupand\egroupspecify the range skipped here needed to define the environment 3) you need only one evironment per document (not per file)excludeenvironment does not harmonize withfigureenvironments. Even though including figures is not a problem, placing them in excludes is. – BadAtLaTeX Mar 12 '16 at 13:36