# Code snippet highlighting for .arff files (WEKA tool)

I would like to know how to go about getting syntax highlighting for WEKA files. This is a tool used for analyzing large data.

In notepad++ this is an example of how the arff file shows up with the syntax highlighting:

I started with the code found here and was modifying it, but so far have not gotten the desired result. Here is what I have started so far:

\documentclass{book}
\usepackage{listings}
\usepackage{color}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}

\lstset{style=mystyle}

\begin{document}

\begin{lstlisting}[language=Python, caption=WEKA Code]
% Assignment for BIG DATA - FIT DATA
% Author: I AM
% email: email@email.com
% 9 attributes
% 188 instances

@relation FIT

@attribute NUMUORS real   % Number of unique operators
@attribute NUMUANDS real  % Number of unique operands
@attribute TOTOTORS real  % Total number of operators
@attribute TOTOPANDS real % Total number of operands
@attribute VG real        % McCabe's cyclomatic complexity
@attribute NLOGIC real    % Number of logical operators
@attribute LOC real       % Lines of code
@attribute ELOC real      % Executable line of code
@attribute FAULTS real    % Number of faults

@data
22,85,203,174,9,0,362,40,0
21,87,186,165,5,0,379,32,0
30,107,405,306,25,0,756,99,0
6,5,19,6,2,0,160,9,0
21,47,168,148,7,0,352,29,0
28,38,161,114,10,3,375,40,0
27,218,1522,1328,114,0,1026,310,0
\end{lstlisting}

\end{document}

• The language=Python is overriding your style. Either specify your style after the language option, or drop that option, or place both options in \lstset in the appropriate order. – Andrew Swann Feb 10 '17 at 10:04
• @AndrewSwann, can you help me get started? Thanks! – Joe Feb 11 '17 at 23:46

Here is a start. Drop the language=Python, it has nothing to do with the syntax of what you are highlighting. Now you need to define your comment style with

comment=[l]{\%},


saying that rest of the line after a % is a comment, and set-up keywords in two different categories:

keywords={@relation,@attribute,@data},
morekeywords=[2]{real,integer,numeric,string,date},


so you can highlight them with different colours.

\documentclass{book}
\usepackage{listings}
\usepackage{color}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
keywordstyle=\color{blue},
keywordstyle={[2]\color{magenta}},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
comment=[l]{\%},
keywords={@relation,@attribute,@data},
morekeywords=[2]{real,integer,numeric,string,date},
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}

\lstset{style=mystyle}

\begin{document}

\begin{lstlisting}[style=mystyle,caption=WEKA Code]
% Assignment for BIG DATA - FIT DATA
% Author: I AM
% email: email@email.com
% 9 attributes
% 188 instances

@relation FIT

@attribute NUMUORS real   % Number of unique operators
@attribute NUMUANDS real  % Number of unique operands
@attribute TOTOTORS real  % Total number of operators
@attribute TOTOPANDS real % Total number of operands
@attribute VG real        % McCabe's cyclomatic complexity
@attribute NLOGIC real    % Number of logical operators
@attribute LOC real       % Lines of code
@attribute ELOC real      % Executable line of code
@attribute FAULTS real    % Number of faults

@data
22,85,203,174,9,0,362,40,0
21,87,186,165,5,0,379,32,0
30,107,405,306,25,0,756,99,0
6,5,19,6,2,0,160,9,0
21,47,168,148,7,0,352,29,0
28,38,161,114,10,3,375,40,0
27,218,1522,1328,114,0,1026,310,0
\end{lstlisting}

\end{document}


This covers everything in your example. It does not colour the commas in the data, but that may not be possible with listings, cf. How to use a comma in lstlisting keywords?