Code Environment (Part 5) – Code Environment

Code Environment (Part 5) - Code Environment #

Author: Erhua

Keywords: Verbatim

In this section, we discuss the verbatim environment, which can be classified into commands and environments. By using the “listings” package, the corresponding environment is “lstlisting”.

\usepackage{listings}% Use the package
\end{lstlisting}% Start the environment
\begin{lstlisting}[language=Python]
\documentclass[]{article}
\usepackage{ctex}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=Python]
import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 2 # Dictionary-like format, key-value pair
mpl.rcParams['lines.color'] = 'r'
\end{lstlisting}
\end{document}