# Need to show MATLAB code in TeX document, using pdfLaTeX [duplicate]

I am trying to make a simple document, showing MATLAB code, and some images. This is my template that I am using.

\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amsfonts}

\hyphenation{}

\begin{document}

I want to put MATLAB code here.

\begin{figure}[H]
\begin{center}
\includegraphics[width=6in]{case2Rect.png}
\caption{Blah}
\label{fig1}
\end{center}
\end{figure}

\end{document}


The problem is that MATLAB code is full of comments that use '%', and so when I try to compile using pdfLaTeX, it crashes. I am using TexMaker btw. Anyway, I was wondering what technique might be used to go around this problem. I simply need to show MATLAB code, along with some images. I am relatively new to LaTeX.

Thanks.

• There have been a few similar questions, see if any of these help: tex.stackexchange.com/questions/75116/… , tex.stackexchange.com/questions/84777/… tex.stackexchange.com/questions/69382/inline-matlab-code Sep 30 '13 at 18:30
• @TorbjørnT. Thanks, I now get this error "! LaTeX Error: File mcode.sty' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty) Enter file name: ! Emergency stop." when I just simply try to add the mcode package. I thought I had this setup to update packages automatically... Sep 30 '13 at 18:37
• mcode isn't part of either MikTeX or TeX Live, so either use plain listings or download and install mcode: mathworks.com/matlabcentral/fileexchange/… Sep 30 '13 at 18:39
• @TorbjørnT. Ok... I guess my question then is how do I set up TexMaker to automatically download packages... :-/ I honestly do not know how to install packages. I tried once and it was a complete and utter nightmare. Sep 30 '13 at 18:49
• How about substitute every % in your code with \%`? Sep 30 '13 at 18:52