![定义一个基于 lstlisting 的命令,可在文本的普通行中使用。](https://linux22.com/image/343325/%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AA%E5%9F%BA%E4%BA%8E%20lstlisting%20%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%8C%E5%8F%AF%E5%9C%A8%E6%96%87%E6%9C%AC%E7%9A%84%E6%99%AE%E9%80%9A%E8%A1%8C%E4%B8%AD%E4%BD%BF%E7%94%A8%E3%80%82.png)
答案1
这是由listings
的\lstinline
宏。您可以\lstinline
直接使用,也可以创建别名:
\documentclass{article}
\usepackage{listings,xcolor}
\lstset{
language=c,
basicstyle=\ttfamily,
keywordstyle=\color{blue}
}
\newcommand{\likelisting}{\lstinline}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
Some text
\begin{lstlisting}
int main(void)
\end{lstlisting}
some text \likelisting{int main(void)} some text
some text \likelisting[keywordstyle={\color{red}}]{int main(void)} some text
\end{document}