[Tex/LaTex] Including published Matlab code and figures in separate LaTeX document


I'm writing up a homework set in LaTeX. I'm writing the theoretical parts of the homework using LaTeX, and the implementation in Matlab. I want to combine these two easily. My problem is:

How do you include the Matlab published .tex file in a separate LaTeX document?

I know LaTeX has packages which can import formatted Matlab code into a LaTeX document. You can also import Matlab-generated .eps figures. What I want to do is include the Matlab published .tex file (which includes the code and figures placed appropriately) using \include{publishedMfile.tex} in the middle of my LaTeX document. However, the published .tex file is designed to be standalone, so it has a preamble, which prevents me from including it.

Here's a sample Matlab published file:

Best Answer

I am not sure exactly what the Matlib .tex file looks like, but from your description it is a complete .tex file that can be compiled by itself. If that is the case, you should be able to use the standalone package to input that file into your LaTeX document as such. So, assuming that the file is called publishedMfile.tex, then your main file would just input it as such:


Here is the graph of an ellipse:


For this test, I used the following as the publishedMfile (which is obviously not from Matlib) file:



\coordinate (EllipseOrigin) at (0,0);

\draw [blue, thin, ->] (-5,0) -- (5,0) node [right] {$x$};
\draw [blue, thin, ->] (0,-4) -- (0,4) node [above] {$y$};

\draw [red, ultra thick]% Graph Ellipse
    (EllipseOrigin) ellipse [x radius=\XRadius,y radius=\YRadius];