## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Including matlab code as a listing in an appendix Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
gokotai
Posts: 5
Joined: Thu Aug 11, 2022 12:35 pm

### Including matlab code as a listing in an appendix

Hi folks,

I'm using overleaf to write my phd thesis.

I have some matlab code which I'd like to include in my appendix section, so I've uploaded the ".mlx" file to a folder called "programmes" and have called the listings package in the preamble.

I have used the following lines to call the listing:
```\lstset{style=mystyle}
\lstinputlisting[language=Matlab, caption=xyz label=appendix:abc]{Programmes/myMatlab.mlx}```

but the document no longer compiles! I used the same method to include some VBA code, so not sure where I've gone wrong. May I please ask for advice on this?

LaTeXguide.org • LaTeX-Cookbook.net

kaiserkarl13
Posts: 673
Joined: Tue Mar 25, 2008 5:02 pm

### Including matlab code as a listing in an appendix

This worked for me without the `\lstset` line with a short .m file that I included using the report class.

It may be something you changed in your "mystyle" info (whatever that is) or it may be something in your documentclass, neither of which you posted so we can't be sure.

I would say a minimal working example is in order.

gokotai
Posts: 5
Joined: Thu Aug 11, 2022 12:35 pm

### Including matlab code as a listing in an appendix

kaiserkarl13 wrote:This worked for me without the `\lstset` line with a short .m file that I included using the report class.

It may be something you changed in your "mystyle" info (whatever that is) or it may be something in your documentclass, neither of which you posted so we can't be sure.

I would say a minimal working example is in order.

Thank you! I've attached the relevant "mystyle" info and everything else in my preamble related to listings here:

```\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}

\renewcommand{\lstlistingname}{Programme}
\renewcommand{\lstlistlistingname}{Programmes}

\lstset{language=Matlab,
frame=single,
basicstyle=\small\ttfamily,
keywordstyle=[1]\color{Blue}\bfseries,
keywordstyle=[2]\color{Purple},
keywordstyle=[3]\color{Blue}\underbar,
identifierstyle=,
stringstyle=\color{Purple},
showstringspaces=false,
tabsize=5,
morekeywords={xlim,ylim,var,alpha,factorial,poissrnd,normpdf,normcdf},
morekeywords=[2]{on, off, interp},
morecomment=[l][\color{Blue}]{...},
numbers=left,
firstnumber=1,
numberstyle=\tiny\color{Blue},
stepnumber=5
}
\newcommand{\matlabscript}[2]```

gokotai
Posts: 5
Joined: Thu Aug 11, 2022 12:35 pm

### Including matlab code as a listing in an appendix  Topic is solved

So it turns out the error was because the files are .mlx format. Converting them to .m format fixed the issue!