5

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.
1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. You should edit your question to add some some SPSS sample code and explain what kind of style you're looking for.
    – jub0bs
    May 12, 2014 at 14:51

1 Answer 1

5

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}
1
  • 1
    Thats it! Thanks so much for your help! Now i know how to create a style by myself.
    – Weeeh
    May 12, 2014 at 15:59

You must log in to answer this question.

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