# Listings package: is it possible to exclude keywords from a specific language? [duplicate]

This question already has an answer here:

I'm using the package listings to import R scripts from file (as they are quite long and already nicely typeset). I have defined the colors (blue for keywords) and style, and added a few keywords. Issues are (see also the MWE and output):

1. new keywords that contain a period (e.g. write.xlsx) are not recognized and are half black (also defining them as {write.xlsx} in the preamble doesn't work);
2. Some basic keywords of R are also used as options or arguments, and are (incorrectly) colored blue (e.g. file, append, row.names).

How can I tell listings to format as keywords only those terms that are followed by a (? Or alternatively is it possible to exclude some basic keywords?

\documentclass{article}
\usepackage{color}
\definecolor{codebackgr}{rgb}{0.95,0.95,0.95}
\definecolor{codeblue}{rgb}{0,0,1}
\definecolor{codegreen}{rgb}{0,0.5,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codered}{rgb}{0.5,0,0}
\usepackage{listings}
\lstdefinestyle{mystyle}{
language=R,
backgroundcolor=\color{codebackgr},
commentstyle=\color{codegreen},
keywordstyle=\color{codeblue},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codered},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=t,
numberbychapter=false,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\lstset{
morekeywords={read.xlsx, write.xlsx}
}

\begin{document}
\lstinputlisting[linerange={31-40}, firstnumber=1]{Script.R}

\end{document}


Basically I just want "write.xlsx" in blue and "file", "append" and "row.names" in black.

Thanks a lot!

## marked as duplicate by TeXnician, Community♦Apr 21 '17 at 11:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Your problem with the dot in the read.xlsx etc is the dot. You'd have to literate that or use only xlsx. – TeXnician Apr 21 '17 at 11:27
• Thank you @TeXnician! Somehow I did not find that original question while browsing. The literateoption did the trick, and I just defined xlsx for the other problem. – AMusu Apr 21 '17 at 11:50