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}

1 Answer 1

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}
3
  • I think I see now. If I delete the 'language=R' line I can effectively redefine the environment; is that correct?
    – Geoff
    Oct 2, 2019 at 8:57
  • No, you just set your params in enviroment. No need for first lstset Oct 2, 2019 at 9:00
  • Many thanks for the help!
    – Geoff
    Oct 2, 2019 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .