I want to build a framework for sharing latex mathematics exercises. When trying to assemble exercises from different authors into one "homework assignment", I have a problem. How can I deal with their different macros and settings? Is there some way to do something like this:
I thought about the preview and the minipage package, but I don't quite know how they could do the job.
It is important that exercise 1 and 2 might have conflicting macros, so the environments must be completely isolated and self contained. Also the exercises should be page-breakable.
Does anyone have an idea how to solve this?
Edit: Pseudocode example
\documentclass[preview]{standalone}
\begin{document}
\beginex
\documentclass[preview, varwidth=500]{standalone}
\usepackage{amsmath}
\newenvironment{LAmatrix}{\begin{bmatrix}}{\end{bmatrix}}
...Something
\endex
...
\end{document}
Since this obviously doesn't work, I might use a parser to remove the documentclass and move the packages to the header and use \begingroup ... \endgroup to isolate the rest.

