LaTeX 仅使一些列表使用颜色而不是全部(列表包)

LaTeX make only some listing use colour and not all (listings package)

我使用以下方法为我在乳胶中创建的列表添加了颜色,

\usepackage{listings}% http://ctan.org/pkg/listings
\lstset{
  basicstyle=\ttfamily,
  mathescape
}
\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}
\usepackage[colorinlistoftodos]{todonotes}

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

这会将颜色应用于我创建的所有列表,我想创建一个不使用任何颜色的新列表,同时保留其他列表的颜色。

谁能告诉我该怎么做,或者是否可能?

谢谢

提供给 \lstset 的所有命令都可以作为特定列表的可选参数。

所以你可以做到

\begin{lstlisting}[keywordstyle=\color{black},
  commentstyle=\color{black},
  stringstyle=\color{black},
]
< your program >

其他所有参数保持不变,但您可以根据需要更改具体值。

另一种方式,是定义样式。

\lstdefinestyle{nocoloring}{
    keywordstyle=\color{black},
    commentstyle=\color{black},
    stringstyle=\color{black}
}

\begin{lstlisting}{style=nocoloring}
< your program >