Imagine I have a complete latex file and I want to extract only the text that appears in a specified environment (i.e., within a custom hypothesis
environment)
For example:
\begin{document}
...
Lots of stuff that I don't want extracted
\begin{hypothesis}
The content that I want to extract
\end{hypothesis}
...
Lots more stuff I don't want to exract
...
\begin{hypothesis}
Some more content that I want to extract
\end{hypothesis}
\end{document}
The question: What's a simple way of taking a complete latex source file and extracting just the text in a specified environment and saving it to a new text file?
Although I'm not an expert I've heard a lot of people talk about Perl scripts being good for string manipulation. I also sometimes use regular expressions. Thus, in addition to a specific solution to the above problem, I would be interested to hear about general approaches to related LaTeX text manipulation tasks.
Update: Copying and pasting is not a desired option because the environment occurs over 20 times in a 20,000 word document.
cat file.tex | perl -lne '/^\\end{hypothesis}/ && $c = 0; $c and print; /^\\begin{hypothesis}/ && $c = 1;'
. An answer more suitable for this site would have LaTeX write out the file when the document was compiled! This is certainly possible as it is what beamer does for "fragile" frames..tex
file where you define a bunch of macros like\def\hypothesis1{Ice melts faster than wood} ... \def\hypothesisN{....}
Then you could use the macros in both places.hypothesis
block? If so, do you want them to be expanded before the external file gets written? For example, if you have\begin{hypothesis}\textbf{Foo}\end{hypothesis}
, can you tell us specifically how you want the output file to look?