# Use multiple languages using lstset? [duplicate]

My MWE :

\documentclass[12pt,a4paper]{report}
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
language=Matlab,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=left,
numberstyle=\tiny\color{black},
keywordstyle=\color{blue},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true
tabsize=3
}

\begin{document}

\begin{lstlisting}
e=1;e2=1;e3=1 %%control variable for ON mode
\end{lstlisting}
\end{document}


I have a Python code that I want to add, but the language set currently is only for matlab. How can I define it for two languages ?

## marked as duplicate by hpesoj626, Andrew Swann, Thorsten, Werner, Tom BombadilApr 26 '13 at 16:46

You can set this when you input the file, e.g.:

\lstinputlisting[language=Matlab]{matlabfile.m}

\lstinputlisting[language=python]{pythonfile.py}


• If you are copying just part of your code, wouldn't the verbatim environment be more useful to you? – Mario S. E. Apr 26 '13 at 16:17
• The main advantage of using this is that don't have to update the code in LaTeX if you make any changes to the file. The argument of the lstinputlistings command points directly to the file, so any change made to it will reflect in your pdf output. – Mario S. E. Apr 26 '13 at 16:33
• well, the command \lstset is for the settings that are going to affect both files, so "frame" there is affecting both the matlab and the python file – Mario S. E. Apr 26 '13 at 18:24