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

includeMATLAB

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:
file.tex

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:

\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}

\begin{document}
Here is the graph of an ellipse:

\input{publishedMfile}
\end{document}

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

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (EllipseOrigin) at (0,0);
\newcommand*{\XRadius}{4.0}
\newcommand*{\YRadius}{3.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];

\end{tikzpicture}
\end{document}