it is defined as an end keyword and can be deleted only with the (deprecated) deletendkeywords
. Looks like a bug to me. However, you have to use the uppercase version of the keyword as it is defined in the language file.:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[keywordstyle=\textbf, language=SQL, deletendkeywords={TIME}]
create table Event (id integer primary key, time date);
\end{lstlisting}
\end{document}
Why morekeywords
doesn't seem to work
Your question stems from a misunderstanding of the morekeywords
key. Contrary to what you think, writing
\lstset{language=Haskell, morekeywords={fix}}
does not alter the definition of listings
' Haskell
language. That's why the fix
identifier is not highlighted in your second listing.
How to modify an existing language
The listings
does not provide a mechanism for "renewing" or modifying an existing language. Of the three approaches you mention, the first one makes the most sense. Note that you don't have to redefine a language from scratch; you can simply define a custom language based on the existing one with your modifications,
\lstdefinelanguage{Haskellana}{%
language = Haskell,
morekeywords = {fix},
}
and then invoke it where needed in place of the original language:
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{Haskellana}{
language = Haskell,
morekeywords = {fix},
}
\begin{document}
Listing 1:
\begin{lstlisting}[language=Haskellana]
fibs = fix ((0:) . scanl (+) 1)
\end{lstlisting}
Listing 2:
\begin{lstlisting}[language=Haskellana]
fibs = fix ((0:) . scanl (+) 1)
\end{lstlisting}
\end{document}
As a Haskeller, strive for laziness :)
To avoid having to invoke the language for each Haskell listing, I suggest declaring a custom lstlisting
environment:
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{Haskellana}{
language = Haskell,
morekeywords = {fix},
}
\lstnewenvironment{haskellcode}
{\lstset{language = Haskellana}}
{}
\begin{document}
Listing 1:
\begin{haskellcode}
fibs = fix ((0:) . scanl (+) 1)
\end{haskellcode}
Listing 2:
\begin{haskellcode}
fibs = fix ((0:) . scanl (+) 1)
\end{haskellcode}
\end{document}
Best Answer
You can use the
keywordsprefix=<prefix>
to specify that anything beginning with the<prefix>
is considered a a keyword. The MWE below highlights any word beginning withB
in blue, but leaves other text alone:However you should note the following limitations form the listings documentation: