I tried to customize a code listing to support some pseudo-code format that suited me best. It was easy to add keywords using otherkeywords
or morekeywords
, but the opposite, the deletekeywords
did not work as expected. If the stem of a word was defined as a keyword, the word would be highlighted. For example, if create is in morekeywords
, then created is also highlighted except the d in the end. Adding created to the deletekeywords
list is not helping.
Please suggest how I could solve this problem.
\documentclass[12pt]{article}
\usepackage{fancyhdr}
\usepackage[ansinew]{inputenc} %Windows-1252 encoding
\usepackage{listings}
\usepackage[english]{babel}
\usepackage[usenames,dvipsnames]{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{lightgray}{rgb}{0.9,0.9,0.9}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{numbers=left,
numbersep=5pt,
basicstyle=\sffamily\tiny,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
backgroundcolor=\color{lightgray},
frame=single,
columns=fullflexible
}
\begin{document}
\title{}
\author{}
\maketitle
\section{somesection}
\lstset{language=Python, caption=somecaption, otherkeywords={smooth}, deletekeywords={smoothed, is, not}}
\begin{figure}[h]
\begin{lstlisting}
smooth is welcome
smoothed is not
\end{lstlisting}
\end{figure}
\end{document}
Best Answer
Rather use
keywords={smooth}
instead ofotherkeywords
. According to thelistings
documentation, the latterHere's an updated MWE showing the desired output:
The above MWE specifies the
keyword
s, but subsequently also overwrites the existing keywords supported by thelanguage
setting. To maintain the existing set and add more/remove some, usemorekeywords={smooth}, deletekeywords={is,not}
.