latex header added to wrong child when compiling a child that uses set_parent() and has children of its own

This solves an issue were only the inner most child document would get a document header (documentclass and premble) when compiling a child that sets set_parent() which also contains sub-children.

Without this the .tex file of such a document would look like this:

```latex
Outer child output

\documentclass{...}
\usepackage{...}
\begin{document}

Inner child output

\end{document}

Further output from outer child
```

I have no idea if this breaks something else but everything seems to work fine for me.