0

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}
Geoff
  • 2,637

1 Answers1

4

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}