[Tex/LaTex] deletekeywords in Listings package sometimes doesn’t work

listingspdftex

Using the listings package, I can use deletekeywords to remove keywords, and so the keyword is not rendered in bold. For example, the for from the following is not in bold font:

\lstset{language=[]C++}
\begin{lstlisting}[deletekeywords={for}]
for (int i = 0; i < 8; i++) {}
\end{lstlisting}

This is useful as I like to use the same font for small code snippets within the main body of my text, but don't always want it to appear with keywords in bold. I came up with two commands for convenience:

\newcommand{\code}[1]{\lstinline[deletekeywords=#1]{#1}}
\newcommand{\codeb}[1]{\lstinline[morekeywords=#1]{#1}}

However, with Fortran it doesn't work. The do in the following is still in bold.

\lstset{language=[]Fortran}
\begin{lstlisting}[deletekeywords={do}]
do i = 1,8
end do
\end{lstlisting}

Is there a way to do this? To locally override the keyword/language highlighting settings more generally?

Best Answer

The keyword "DO" is defined as uppercase in lstlang1.sty and the code for Fortran says sensitive=f; so

deletekeywords={DO}

does the trick.