[Tex/LaTex] Using keywords including a dot in the name with the listings package

highlightinglistingssyntax

I am using the listings package which works like charm in most cases.

I tried to define new languages for my needs with the help of morekeywords options in \lstset, but entering special keywords having a dot in the name just do not work. E.g.:

\lstset{morekeywords={read.table}}

I know I could set this keyword in two and set read and table to be also keywords, but I do not want every read to be highlighted in the source code.

Do you have an idea how to set this keyword or how to escape the dot?

Best Answer

After trying to do this by changing the catcode of . to letter and a short look through the listings code I decided to RTFM and found the alsoletter option quite quickly. You also may want to use the alsodigit option instead.

\documentclass{article}

\usepackage{listings}

\lstset{alsoletter={.},morekeywords={read.table}}
\begin{document}

\begin{lstlisting}
   read read.table table read-table
   test
\end{lstlisting}

\end{document}