0

This question already has an answer here:

Can I \lstset to define both Matlab code and Python code? or will last one override the first one? or does listings know the difference when there is a .m or .py extension and use the correct \lstset?

marked as duplicate by egreg, Werner, jub0bs, mafp, Stefan Kottwitz Sep 26 '13 at 22:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You can do:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=Python, caption={Some Python code}]
class example(object):
    pass
\end{lstlisting}
\begin{lstlisting}[language=Matlab, caption={Some Matlab code}]
function [y1, y2] = funfun(x1, x2)
    disp(x1)
end
\end{lstlisting}
\end{document}

Or you can \lstset the language before the listing.

Not the answer you're looking for? Browse other questions tagged or ask your own question.