# Killing a keyword in listings

I happen to use as a variable the word distance within my R code and I notice that it is always being treated as some kind of keyword. I saw in How can I delete non-letter keywords (such as '<-')? that there are options available (the three commented out lines below in the MWE) but no matter which I choose he word distance remains blue. So what is this word distance? How can I get at it?

\documentclass{article}

\usepackage{xcolor}
\usepackage{listings}

\lstset{
language=R,
% keywords={},
% otherkeywords={},
% deletekeywords={distance},
keywordstyle=\color{blue},
}

\lstnewenvironment{R}{\lstset{language=R}}{}

\begin{document}

\begin{R}
distance <- 1:10
\end{R}

\end{document}


You actually mixed two commands, just add deletekeywords to lstnewenvironment

\documentclass{article}

\usepackage{xcolor}
\usepackage{listings}

\lstnewenvironment{R}{\lstset{
language=R,
deletekeywords={distance},
keywordstyle=\color{blue}
}}{}

\begin{document}

\begin{R}
distance <- 1:10
m <- mean(distance)
\end{R}

\end{document}

• I think I see now. If I delete the 'language=R' line I can effectively redefine the environment; is that correct? Oct 2 '19 at 8:57
• No, you just set your params in enviroment. No need for first lstset Oct 2 '19 at 9:00
• Many thanks for the help! Oct 2 '19 at 9:04