答案1
如何使用tcolorbox
?它提供了对的支持\lstinline
。有关更多详细信息,请参阅文档。
\documentclass{article}
\usepackage[listings]{tcolorbox}
\lstdefinestyle{inlinepy}{%
language=python,
basicstyle=\ttfamily,
commentstyle=\color{green!60!black},
keywordstyle=\color{blue}\bfseries,
stringstyle=\color{red},
keepspaces=true,
}
\DeclareTotalTCBox{\inlinepy}{sv}{verbatim}{\lstinline[style=inlinepy]|#2|}
\begin{document}
\begin{itemize}
\item Python strings: \inlinepy{name = "First name" + "Last name"}
\item Comments: \inlinepy{theta_rad = theta_deg*3.14/180 # angle conversion to radians}
\item Import packages: \inlinepy{import numpy as np}
\end{itemize}
\end{document}