Splitting the preamble

When working with big documents, especially when dealing with many lists, graphics, figures and includes, I often come up with a structure roughly looking like this.

\documentclass{beamer}

[preamble for part 1]
[preamble for part 2]
[preamble for part 3]
....

\begin{document}
[part 1 body]
[part 2 body]
[part 3 body]
...
\end{document}


A usual practise is to export the body parts to single files and then \include them.

The subfiles package provides a more comfortable approach by making it possible to compiled the parts independently reusing the preamble of the main file. But subfiles discards the preambles of the subfiles. To make it possible to both modularize preamble and body, each body part must be exported to a subfile part1.tex and each preamble part to a corresponding package part1.sty. The document is then stitched together using \include and \usepackage.

Ideally, preamble and body of the parts should be kept together. Compiling individual pdfs then to connect with \includepdf comes somewhat close to this, but is hard to use especially with beamer when the whole document should be produced in handout mode or with notes. Dealing with overlays or providing a correct table of contents is even more cumbersome.

How I really would like to structure the document is along the lines of this.

%main.tex
\documentclass{beamer}
\include{part1}
\include{part2}
....

%part1.tex
\documentclass{beamer}
[part 1 preamble]
\begin{document}
[part 1 body]
\end{document}

%part2.tex
\documentclass{beamer}
[part 2 preamble]
\begin{document}
[part 2 body]
\end{document}


Is it possible to realize this scheme? Could it even be possible to realize it and be able to compile the parts independently?

-
maybe the standalone could be useful here; related: How to have each slide in a separate file, each compilable, then combine them –  cmhughes Nov 28 '13 at 0:45

Check the package docmute. It is close to what you want as long as the preamble for the main file includes all the other preambles

main.tex

\documentclass{beamer}
\input{fullpreamble}
\usepackage{docmute}
\begin{document}
\input{doc1.tex}
\input{doc2.tex}
\end{document}


doc1.tex

\documentclass{beamer}
\inpute{fullpreamble}
\begin{document}
body1
\end{document}


doc2.tex

\documentclass{beamer}
\inpute{fullpreamble}
\begin{document}
body2
\end{document}


This allows to compile all the parts independently.

-