我的 MWE :
\documentclass[12pt,a4paper]{report}
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\linespread{1.5}
\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},
commentstyle=\color{dkgreen},
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}
我有一个想添加的 Python 代码,但当前设置的语言仅适用于 matlab。我该如何为两种语言定义它?
答案1
您可以在输入文件时设置此项,例如:
\lstinputlisting[language=Matlab]{matlabfile.m}
\lstinputlisting[language=python]{pythonfile.py}
更多信息请访问包装文档