5
votes

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?

4
I wish I had a good answer for you, but in the past when faced with this problem, I found it easier to hack the .aux files to get consecutive page numbering, generate each document separately, and then glue the DVI files together (this was going on eight years ago, now I imagine it would be the same but with PDFs).zwol

4 Answers

6
votes

I see two approaches here. Either carefully structure your documents, or use some hacky TeX magic:

The smart way

Break your smaller documents into a header part, a footer part and a content part.

header.tex:

\documentclass{article}
...
\begin{document}

footer.tex:

\end{document}

foo-content.tex:

In this paper, we discuss an new approach to metasyntactic variables...

foo.tex (the small paper version):

\include{header}
\include{foo-content}
\include{footer}

In your .tex for the collected articles document:

\include{foo-content}

The hacky TeX way

Put this in some common include file, used by your individual files:

\ifx\ismaindoc\undefined
\newcommand{\inbpdocument}{\begin{document}}
\newcommand{\outbpdocument}{\end{document}}
\else
\newcommand{\inbpdocument}{}
\newcommand{\outbpdocument}{}
\fi

Use \inbpdocument and \outbpdocument in your individual files, in place of \begin{document} and \end{document}. In your main file, put in a \def \ismaindoc {} before including or importing anything.

2
votes

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.

1
votes

There's another hack you could use, which wouldn't require modifying the individual files... just temporarily redefine the {document} environment (to something benign, i.e. a no-op), \include the individual files, and then restore the {document} environment definition.

If I recall correctly, the commands to do this are \let and \renewenvironment.

Hm. You might also have to temporarily redefine \documentclass and \usepackage, too. It's a hack, yes, but I think it should work.

0
votes

I haven't used it, but it looks like the "subfiles" package does exactly what you want: http://en.wikibooks.org/wiki/LaTeX/Modular_Documents#Subfiles_package