Search code examples
lateximportconditional-statements

Conditional Import in LaTeX?


I'm going to be taking a ton of lecture notes, and then compiling them into LaTeX so that I can have excellent documents for future me to look over. I'm trying to organize things so that I can have a bunch of little documents containing the notes from a lecture, and then compile them at the end of the semester into one large document containing all of them. I have used import/include etc. successfully in the past, but I've had to remove the content at the head and foot of the sub-documents before compiling the main document. For example, I would have to remove:

\begin{document}

and

\end{document}

from every sub-document before compiling the main document. This is fine for a report with 5 or so sections, but a pain in the ass for something with 100+. Any recommendations for ignoring the contents of a LaTeX file programmatically when using the import command?


Solution

  • Here's another possible approach: if you put magic strings (i.e., % % BEGIN LECTURE % % ... % % END LECTURE % %) in the individual files, you could awk out the guts of the individual files, assemble them using make/sh, and then \include them.