答案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}