如何设置内联动词文本的背景颜色和字体?

如何设置内联动词文本的背景颜色和字体?

我希望自定义verb命令,以便我可以自定义字体和颜色,以及设置圆角彩色矩形作为背景。

我在 Tcolorbox 手册中找到了这一点:

\DeclareTotalTCBox{\commandbox}{ s v }
{verbatim,colupper=white,colback=black!75!white,colframe=black}
{\IfBooleanTF{#1}{\textcolor{red}{\ttfamily\bfseries > }}{}%
\lstinline[language=command.com,keywordstyle=\color{blue!35!white}\bfseries]^#2^}

这看起来与我想要的类似。但是,我收到许多错误:

- Undefined control sequence
- You can't use `macro parameter character #' in horizontal mode.

这是迄今为止包含上述内容的标题代码:

\documentclass[oneside,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{mathpazo}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{etoolbox}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, skins}

\BeforeBeginEnvironment{minted}{\vspace{2mm}\begin{tcolorbox}[colback=bg, colframe=bg, arc=1.2pt]}%
\AfterEndEnvironment{minted}{\end{tcolorbox}\vspace{2mm}}%

\usepackage{newverbs}
\definecolor{inline}{RGB}{187,57,82}
\newverbcommand{\cverb}{\color{inline}}{}
\usemintedstyle{paraiso-dark}

\definecolor{bg}{RGB}{22,43,58}
\setminted{fontfamily=fdm, fontsize=\footnotesize, gobble=4, baselinestretch=1.2}

\DeclareTotalTCBox{\commandbox}{ s v }
{verbatim,colupper=white,colback=black!75!white,colframe=black}
{\IfBooleanTF{#1}{\textcolor{red}{\ttfamily\bfseries > }}{}%
\lstinline[language=command.com,keywordstyle=\color{blue!35!white}\bfseries]^#2^}

\setlength{\parindent}{0pt}
\title{\Huge{\textbf{Programming in C, Java, \& More}}}
\author{Richard Robinson, B.Eng. Cand.}

\begin{document} 

答案1

使用库xparse

% arara: pdflatex: {shell: 1}
\documentclass[oneside,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{mathpazo}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{etoolbox}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, skins, xparse}

\BeforeBeginEnvironment{minted}{\vspace{2mm}\begin{tcolorbox}[colback=bg, colframe=bg, arc=1.2pt]}%
\AfterEndEnvironment{minted}{\end{tcolorbox}\vspace{2mm}}%

\usepackage{newverbs}
\definecolor{inline}{RGB}{187,57,82}
\newverbcommand{\cverb}{\color{inline}}{}
\usemintedstyle{paraiso-dark}

\definecolor{bg}{RGB}{22,43,58}
\setminted{fontfamily=fdm, fontsize=\footnotesize, gobble=4, baselinestretch=1.2}

\DeclareTotalTCBox{\commandbox}{ s v }
{verbatim,colupper=red!75!black,colback=lightgray, enhanced, frame hidden, arc=2pt}
{\IfBooleanTF{#1}{\textcolor{red}{\ttfamily\bfseries > }}{}%
\lstinline[language=command.com,keywordstyle=\color{blue!35!white}\bfseries]^#2^}

\setlength{\parindent}{0pt}
\title{\Huge{\textbf{Programming in C, Java, \& More}}}
\author{Richard Robinson, B.Eng. Cand.}

\begin{document} 

\commandbox{ABC}

\end{document}

相关内容