I would like to embed one document in another, in such a way that the child document does not interfere with the parent, it just appears as if it were an image. I would also like to be able to show the code of the child document on the parent. Is this possible?
You’re close. The #include function is what you want for “embedding”, it’s basically copy&paste with the caveat that the content does get evaluated before it gets embedded so maybe there’s some interference but it should be easy to work around it.
As for displaying the code, you can combine raw() and read() like this:
This solves the part of adding the code of the document as an example. But the “include”, if the document is complex, sometimes produces an error. It would have to be run separately and then include the result as if it were an image or a pdf.
So far the read + eval solution makes sense. If, however, your child document introduces any elements which depend on global context such as counters, your best bet is to compile the other document and include it as a figure.