问题:
我使用listings
包来突出显示SQL
代码,但是由于某种我不知道的原因,我无法使用SQL
不同的颜色突出显示某些关键字。
最小工作示例:
\documentclass{scrreprt}
\usepackage{xcolor}
\usepackage{upquote}
\usepackage{listings}
\usepackage[most]{tcolorbox}
\usepackage{calc}
\usepackage{xparse}
\usepackage{ragged2e}
\definecolor{editorLightGray}{cmyk}{0.05, 0.05, 0.05, 0.1}
\definecolor{editorWhite}{cmyk}{0, 0, 0, 0}
\definecolor{editorOrange}{cmyk}{0, 0.8, 1, 0}
\definecolor{editorBlue}{cmyk}{1, 0.6, 0, 0}
\thispagestyle{empty}
\newlength{\titleboxwidth}
\newtcolorbox{codelanguagebox}[2][]{boxrule=0pt,coltext=white,colback=labelPurple,arc=0pt,auto outer arc,width={#2},boxsep=0pt,left=5pt,right=5pt,halign=center,#1}
\NewDocumentCommand{\codelabel}{O{}mO{}}{%
\begin{tcolorbox}[boxrule=0pt,boxsep=0pt,right=2.5pt,top=2pt,bottom=2pt,colback=editorLightGray,arc=0pt,auto outer arc,#1]
\setlength{\titleboxwidth}{\widthof{#2}}%
\RaggedLeft\begin{codelanguagebox}[add to width=0.5cm,#3]{\the\titleboxwidth}
\bfseries #2%
\end{codelanguagebox}%
\end{tcolorbox} %
}
\lstdefinelanguage{php}{
morestring=[s]{'}{'},
morecomment=[l]{//},
sensitive=false,
keywords=[4]{athletics},
}
\lstset{%
% Basic design
backgroundcolor=\color{editorWhite},
basicstyle={\footnotesize\ttfamily},
frame=l,
% Line numbers
xleftmargin={0cm},
numbers=left,
stepnumber=1,
firstnumber=1,
numberfirstline=true,
% Code design
identifierstyle=\color{editorOrange},
keywordstyle=[1]\color{editorPink}\bfseries,
keywordstyle=[2]\color{editorBlue}\bfseries,
keywordstyle=[3]\color{editorBlack}\bfseries,
keywordstyle=[4]\color{editorBlue}\bfseries,
commentstyle=\color{editorGray}\ttfamily,
stringstyle=\color{editorPurple},
% Code
language=php,
alsodigit={.:;},
tabsize=2,
showtabs=false,
showspaces=false,
showstringspaces=false,
extendedchars=true,
breaklines=false,
% Support for German umlauts
literate=%
{Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}1
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
}
\begin{document}
\codelabel[colback=editorLightGray]{\small\ttfamily SQL}[colback=editorOrange]
\begin{lstlisting}
DROP DATABASE athletics;
\end{lstlisting}
\end{document}
此代码产生以下内容:
期望的结果:
“athletics”一词和所有其他预定义词语应为蓝色。
答案1
这里的主要问题是使其alsodigit={.:;}
成为athletics;
具有单一颜色的单一实体。删除alsodigit
似乎有效。