I'd like to nest load one document inside another, skipping the preamble and \begin{document} and \end{document} of the nested document.
So
\documentclass{article}
% load some packages here
\begin{document}
\loaddocument{otherdocument}
text
\end{document}
should be the same as if \loaddocument were replaced with \input except that only the bits between \begin{document} and \end{document} of otherdocument.tex are loaded.
I could probably achieve this using LuaLaTeX but I can't be the first to be looking for this functionality yet I can't find a solution on this forum. Is there an existing solution?
****** EDIT ******
I thank Sam Carter for pointing out subfiles but that package doesn't allow packages to be loaded in the preamble. If the nested file is like this
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
x=\quad y.
\end{equation}
\end{document}
then compilation stops, so the subfiles package won't do.
The closest to what I have in mind, judging by its documentation, is newclude but that package is old and the documentation claims it provides an \includeenv command, which LaTeX doesn't recognize. But, unless something changes, I'll accept that answer and write my own LuaLaTeX routine.
* SECOND EDIT *
fwiw, I have written a simple LuaLaTeX routine that takes care of the problem.
standalonepackage. – egreg Jun 22 '17 at 18:13otherdocumentin a separate file that can be input into both its own preamble inotherdocument.texand in to the current document. – David Carlisle Jun 22 '17 at 18:29more robust, what issues are you referring to? – JPi Jun 22 '17 at 18:30\def\documentclass#1\begin{\begin}plus a local definition of the document enviornment to do nothing, but any such local definition has the possibility of breaking something, that's just how tex is:-) – David Carlisle Jun 22 '17 at 18:34\begin{document}and everything from\end{document}to the end..... Should be pretty robust. – JPi Jun 22 '17 at 18:54\usepackage{amsmath}in the nested document (see the code fragment at the bottom of my question). It appears that one can't load packages in the nested document. – JPi Jun 22 '17 at 19:31