# What is the best way of including Matlab code in a LaTeX document? [duplicate]

I know this is a popular problem. I have read that the matlab-prettifier package yields good results. My Editor told me, I am missing this package, though. I don't know how to download the package to ubuntu. Apparently, I have to do it manually.

Anyways, are there any other ways? I have tried the Matlab publishing option. It generates a code, which is more or less just a \begin{verbatim} ... \end{verbatim}

It is not in color.

• matlab-prettifier comes with most TeX distributions. You should be able to install it with whatever package manager you're using. If you post additional info about your system, we might be able to give you more guidance. Feb 24 '17 at 21:21

## 2 Answers

The listings package is very customisable. Might be worth looking into it:

https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings

My favorite way to include code (not just Matlab) in my documents is with the Minted package. The documentation is found here (in PDF). One the plus side, it produces beautiful colorized and syntax-highlighted code, and it supports essentially all languages out there. On the down side, it requires Pygments, a Python module that performs the syntax highlighting, and you need to invoke your Tex engine with -shell-escape.