我想在一行内包含简短代码,并以灰色背景标记。以下是示例:
我想将code of this form
其包含在文本中间。
答案1
下面是一个示例tcolorbox
。您可以从详细的手动的
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{xparse}
\begin{document}
An example with the \tcboxverb{tcolorbox} package with its \tcboxverb{\tcboxverb} command from the \tcboxverb{xparse} library
\end{document}
答案2
这可能有点脆弱,但有效:
\documentclass{article}
\usepackage{xcolor}
\colorlet{codecolor}{black!30}
\newcommand{\codebox}[1]{%
\colorbox{codecolor}{\ttfamily \detokenize{#1}}%
}
\begin{document}
I want to include \codebox{code of this form} that is in the middle of the text.
I want to include \codebox{code_ of^ this\ form} that is in the middle of the text.
\end{document}