% End document if it's a stand alone and decrease documentdepth otherwise
\ifnum\value{documentdepth}>0
  \setcounter{documentdepth}{\value{documentdepth}-1}
  \endinput
\else
  \end{document}
\fi
