0

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?

dustin
  • 18,617
  • 23
  • 99
  • 204

1 Answers1

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.

marczellm
  • 11,809