如何使用列表包将单词“base”突出显示为代码,例如 \lstinline{base}?

如何使用列表包将单词“base”突出显示为代码,例如 \lstinline{base}?

当我使用单词baseinside\lstinline{}将其突出显示为内联代码时,我收到一个错误,然后出现不存在的警告(如果不存在错误):

Package xcolor Error: Undefined color `yac'. \lstinline{base}
Usage of package `parskip' together(scrreprt) with a KOMA-Script class is not recommended.
\float@addtolists detected!(scrreprt) Implementation of \float@addtolist became(scrreprt) deprecated in KOMA-Script v3.01 2008/11/14 and(scrreprt) has been replaced by several more flexible(scrreprt) features of package `tocbasic`.
Overfull \hbox (0.64577pt too wide) in paragraph
\float@listhead detected!(scrreprt) Implementation of \float@listhead became(scrreprt) deprecated in KOMA-Script v3.01 2008/11/14 and(scrreprt) has been replaced by several more flexible(scrreprt) features of package `tocbasic`.

当我使用\lstinline{base}\lstinline{<base>}或 时会出现此错误,但使用或\lstinline{a base}时不会出现此错误。所以我很疑惑, 是保留字吗?我该如何使用包突出显示它?顺便说一句。是一个 HTML 元素。\lstinline{Base}\lstinline{abase}baselistingsbase

麦基尔教育学院:

\documentclass{scrreprt}

\usepackage[dvipsnames]{xcolor}
\usepackage{listings}

\lstset{
    emph={square}, 
    emphstyle=\color{blue}\texttt,
    emph={[2]root,base},
    emphstyle={[2]\color{yac}\texttt}
}

\begin{document}
    No error: \lstinline{Base} 
    
    Error: \lstinline{base}
\end{document}

答案1

这就是你要找的东西吗?

\documentclass{scrreprt}

\usepackage[dvipsnames]{xcolor}
\usepackage{listings}

\lstset{
    emph={square}, 
    emphstyle=\color{blue}\texttt,
    emph={[2]root,base},
    emphstyle={[2]\color{red}\texttt},
}

\begin{document}
    No error: \lstinline{square} 
    
    Error: \lstinline{base}
\end{document}

结果:

在此处输入图片描述

相关内容