# Attach matlab code in latex

 P: 235 Attach matlab code in latex I second the use of the listings package. I put the following in my document preamble whenever I need to include MATLAB code in a LaTeX document: \usepackage{listings} \usepackage[usenames,dvipsnames]{color} % This is the color used for MATLAB comments below \definecolor{MyDarkGreen}{rgb}{0.0,0.4,0.0} % For faster processing, load Matlab syntax for listings \lstloadlanguages{Matlab}% \lstset{language=Matlab, % Use MATLAB frame=single, % Single frame around code basicstyle=\small\ttfamily, % Use small true type font keywordstyle=[1]\color{Blue}\bf, % MATLAB functions bold and blue keywordstyle=[2]\color{Purple}, % MATLAB function arguments purple keywordstyle=[3]\color{Blue}\underbar, % User functions underlined and blue identifierstyle=, % Nothing special about identifiers % Comments small dark green courier commentstyle=\usefont{T1}{pcr}{m}{sl}\color{MyDarkGreen}\small, stringstyle=\color{Purple}, % Strings are purple showstringspaces=false, % Don't put marks in string spaces tabsize=5, % 5 spaces per tab % %%% Put standard MATLAB functions not included in the default %%% language here morekeywords={xlim,ylim,var,alpha,factorial,poissrnd,normpdf,normcdf}, % %%% Put MATLAB function parameters here morekeywords=[2]{on, off, interp}, % %%% Put user defined functions here morekeywords=[3]{FindESS, homework_example}, % morecomment=[l][\color{Blue}]{...}, % Line continuation (...) like blue comment numbers=left, % Line numbers on left firstnumber=1, % Line numbers start with line 1 numberstyle=\tiny\color{Blue}, % Line numbers are blue stepnumber=5 % Line numbers go in steps of 5 } % Includes a MATLAB script. % The first parameter is the label, which also is the name of the script % without the .m. % The second parameter is the optional caption. \newcommand{\matlabscript}[2] {\begin{itemize}\item[]\lstinputlisting[caption=#2,label=#1]{#1.m}\end{itemize}} These settings are based on those used in a LaTeX homework template by Ted Pavlic.