![类似于 TeX StackExchange 的内联代码格式](https://linux22.com/image/456667/%E7%B1%BB%E4%BC%BC%E4%BA%8E%20TeX%20StackExchange%20%E7%9A%84%E5%86%85%E8%81%94%E4%BB%A3%E7%A0%81%E6%A0%BC%E5%BC%8F.png)
答案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}