Can LaTeX natively include only specific expressions from an input file (ignoring the rest)? I am not sure how to best word my question. Below is an example of what I'd like to do.
Situation
For example, let's say I have many files with all kinds of code, but each one shares something in common, a summary environment.
I decide to create a document that contains summaries of all of the other documents. For a meaningful document, I need to get the name of the input file and include only the following code from the input:
\begin{summary}
A bunch of text.
\end{summary}
Here is a sample file structure:
Documents/
JimsAdventures.tex
CrazyGorilla.tex
BrightHorizon.tex
MoonLanding.tex
Summaries.tex <-- includes summaries of all other tex files and their file names
It would be great if Summaries.tex could automatically detect new files in the Documents folder such that it is completely automated (obviously that is a bonus and not really a criterion for the question).
I know this is possible with scripting languages by calling a shell script with the --shell-escape
option combined with \immediate\write18
or \include{|myscript.sh}
, but is this possible natively in LaTeX
?
UPDATE June 30, 2015
Solution based on Werner's suggestion:
LaTeX does support this feature with the catchfilebetweentags
package. What it does not support is getting a list of files (e.g. within the same folder) to input automatically (unless the only change between file names is a number: in which case you can use a sequence see Including all files within a directory) .
To avoid using --shell-escape
and maintain an OS-independent workflow, it is possible to achieve the same thing by creating a separate file (e.g. Documents.txt) that contains the names (or paths depending on whether you want to reconstruct paths with a macro or not) of the documents (stories). To have Summaries.tex automated, you can reference this file (e.g. Documents.txt) instead of having LaTeX generate it with --shell-escape
+ external script. Of course, 100% automation would require a system that runs a pre-compilation script that collects all of the tex files you want to include and spits them out into Documents.txt beforehand.
\input
only part of a file. The main suggestion there would be to use tags andcatchfilebetweentags
.standalone
you can set environments of your choice as standalone environments.