# Defining keywords for SQL using listings

Problem:

I use listings package to highlight SQL code but for some reason, unknown to me, I can't get certain keywords in SQL to highlight in a different color.

Minimal Working Example:

\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}}%
\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,
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}


This code produce the following:

Desired outcome:

The word "athletics" and all other predefined words should be in color blue.

• Your example does not compile, and is a lot more complicated than it need to be. The problem here is that alsodigit={.:;}, makes athletics; into a single construction. If you remove the alsodigit then it changes color. How to fix this, no idea at the moment, but I'd advise you to greatly simplify the MWE. – daleif Jun 22 '15 at 7:12
• This seemed to be the solution. Now it changed color perfectly. – kexxcream Jun 22 '15 at 7:16
• @daleif: Your comment was apparently the solution. Do you want to answer? – user31729 Jan 3 '16 at 22:20

The main problem here is that alsodigit={.:;} makes athletics; into a single entity with a single color. Removing alsodigit seems to work.