With the minted
package, you can use
\inputminted[<options>]{<language>}{<file>}
Here's an example file code.tex
using your sample file and saving it as Mat1.m
:
\documentclass{article}
\usepackage{xcolor}
\usepackage{minted}
\begin{document}
\inputminted[bgcolor=gray!10]{matlab}{Mat1.m}
\end{document}
The output, after processing with pdflatex --shell-escape code.tex
:
With the listings
package, you can use
\lstinputlisting[<options>]{<file>}
A simple example, again with the previous settings
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
backgroundcolor=\color{gray!10},
keywordstyle=\color{green!40!black},
columns=flexible
}
\begin{document}
\lstinputlisting[language=matlab]{Mat1.m}
\end{document}
The output:
your class defines listing
for an unrelated purpose. If you do not need that you can re-assert the minted
version:
\documentclass[english,12pt]{toptesi}
\usepackage[utf8]{inputenc}
\usepackage{minted}
\let\IWANTTHISlisting=\listing
\begin{document}
\let\listing=\IWANTTHISlisting
\begin{listing}[!ht]
\begin{minted}[tabsize=4]{json}
{
"type": "Room"
}
\end{minted}
\caption{JSON structure for entity}
\end{listing}
\end{document}
Best Answer
There is the
listings
package that does a lot on prettyprinting program code, but you will probably have to configure it to get the same colours as some other tool like CodeBlocks chooses.