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.


You can do:

\begin{lstlisting}[language=Python, caption={Some Python code}]
class example(object):
\begin{lstlisting}[language=Matlab, caption={Some Matlab code}]
function [y1, y2] = funfun(x1, x2)

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.