[Tex/LaTex] How to highlight SPSS Syntax code with the listings package

highlightinglistingssyntax

I'm writing my master thesis at the moment and I want to add some code listings to the appendix. The code is written in "Syntax", the programming language of SPSS Statistics.

Is there a way to enable syntax highlighting for SPSS Syntax code in listings? Or is it possible to define words by myself that are highlighted afterwards?
I'm working with Lyx, if that matters.

Ideally, the typeset listing should look something like this:

enter image description here

Here is some sample code:

USE ALL.

*Filter für Gültige.

COMPUTE gueltig=0.    
EXECUTE.

IF ((Ernsthaftigkeit1nurmalgucken5ernsthaftdabei > 2) AND (Alter < 75) AND (Aufmerksamkeit1abgelenkt5konzentriert > 2) AND (Musik1keine2Hobby3Profi > 0)) gueltig=1.    
EXECUTE.    
FILTER BY gueltig.

*Filter für deutsch erkannt (Audio und Verständnis korrekt).
USE ALL.

RECODE erkannteSprache ('d'=1) ('de'=1) ('Detsch'=1) ('deusch'=1) ('deustch'=1) ('Deutch'=1) ('deutsc'=1) ('deutscg'=1) ('deutsch'=1) ('Deutsch'=1) ('DEUTSCH'=1) ('Deutts'=1) ('german'=1) ('German'=1) ('German.'=1) ('Gernab'=1) (ELSE=0)
INTO deutscherkannt.    
EXECUTE.

FILTER BY deutscherkannt.

*Filter für deutsche Sprache.    
USE ALL.    
RECODE ausgewählteSprache ("de"=1) (ELSE=0) INTO deutsch.    
EXECUTE.       

*Filter für auszuwählende Fälle.    
USE ALL.

COMPUTE auswahl=0.
EXECUTE.    
IF ((gueltig=1) AND (deutscherkannt=1)) auswahl=1.    
EXECUTE.    
FILTER BY auswahl.

Best Answer

The listings package doesn't define any language corresponding to SPSS, but defining one is easy enough.

enter image description here

\documentclass{article}

\usepackage{xcolor}
\usepackage{textcomp}
\usepackage{listings}

\lstset{inputencoding=utf8/latin1}

\lstdefinelanguage{SPSS}
{
  sensitive    = true,
  morekeywords = {ALL, AND, BY, EQ, GE, GT, LE, LT, NE, NOT, OR, TO, WITH},
  morecomment  = [s]*.,
  morecomment  = [s]{/*}{*/},
  morestring   = [s]'',
  morestring   = [s]"",
}

\lstdefinestyle{mySPSSstyle}
{
  language     = SPSS,
  upquote      = true,
  basicstyle   = \sffamily\scriptsize,
  keywordstyle = \color[RGB]{165,42,42}\bfseries,
  commentstyle = \color{blue},
  stringstyle  = \color[RGB]{255,0,255},
  breaklines   = true,
  columns      = fullflexible,
  frame        = single,
  rulecolor    = \color{black},  
  numbers      = left,
  numberstyle  = \color{gray},
}

\usepackage{filecontents}
\begin{filecontents*}{sample.sps}
USE ALL.

*Filter für Gültige.

COMPUTE gueltig=0.    
EXECUTE.

IF ((Ernsthaftigkeit1nurmalgucken5ernsthaftdabei > 2) AND (Alter < 75) AND (Aufmerksamkeit1abgelenkt5konzentriert > 2) AND (Musik1keine2Hobby3Profi > 0)) gueltig=1.    
EXECUTE.    
FILTER BY gueltig.

*Filter für deutsch erkannt (Audio und Verständnis korrekt).
USE ALL.

RECODE erkannteSprache ('d'=1) ('de'=1) ('Detsch'=1) ('deusch'=1) ('deustch'=1) ('Deutch'=1) ('deutsc'=1) ('deutscg'=1) ('deutsch'=1) ('Deutsch'=1) ('DEUTSCH'=1) ('Deutts'=1) ('german'=1) ('German'=1) ('German.'=1) ('Gernab'=1) (ELSE=0)
INTO deutscherkannt.    
EXECUTE.

FILTER BY deutscherkannt.

*Filter für deutsche Sprache.    
USE ALL.    
RECODE ausgewählteSprache ("de"=1) (ELSE=0) INTO deutsch.    
EXECUTE.       

*Filter für auszuwählende Fälle.    
USE ALL.

COMPUTE auswahl=0.
EXECUTE.    
IF ((gueltig=1) AND (deutscherkannt=1)) auswahl=1.    
EXECUTE.    
FILTER BY auswahl.
\end{filecontents*}

\begin{document}

\lstinputlisting[style=mySPSSstyle]{sample.sps}

\end{document}