langs.sty
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 02 Dec 2014 12:27:12 +0000
changeset 343 9a27fa14c17c
parent 336 3cb200fa6d6a
child 345 7f0ac1355f0b
permissions -rw-r--r--
u
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\usepackage{listings}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{etoolbox}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\setmonofont[Scale=.95]{Consolas}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
\newfontfamily{\consolas}{Consolas}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\definecolor{codered}{rgb}{0.6,0,0}            % for strings
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\definecolor{codegreen}{rgb}{0.25,0.5,0.35}    % comments
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
\definecolor{codepurple}{rgb}{0.5,0,0.35}      % keywords
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
\definecolor{codedocblue}{rgb}{0.25,0.35,0.75} % doc
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
\definecolor{codeblue}{rgb}{0.25,0.35,0.75}    % types
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
\BeforeBeginEnvironment{lstlisting}{\par\noindent\begin{minipage}{\linewidth}}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
\AfterEndEnvironment{lstlisting}{\end{minipage}\par}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
\lstdefinelanguage{Scala}{
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
  morekeywords={abstract,case,catch,class,def,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
    do,else,extends,false,final,finally,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
    for,if,implicit,import,match,mixin,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
    new,null,object,override,package,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
    private,protected,requires,return,sealed,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
    super,this,throw,trait,true,try,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
    type,val,var,while,with,yield},%
336
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    23
  otherkeywords={=>,<-,<\%,<:,>:,\#},%
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  sensitive=true,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  %directives={Int,Char,Rexp,String,Boolean,BigInt,Unit,List,Set},%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  %moredelim=*[directive]:,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  morecomment=[l]{//},%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  morecomment=[n]{/*}{*/},
336
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    29
  morestring=[s]{"""}{"""},
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  morestring=[b]",
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  morestring=[b]',
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
}[keywords,comments,strings]
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
\lstdefinelanguage{While}{
336
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    35
  morekeywords={if,then,else,while,do,true,false,write,upto,read,for,skip},
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    36
  morecomment=[l]{//},
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  morecomment=[n]{/*}{*/},
336
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    38
  morestring=[b]",
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    39
  otherkeywords={=,!=,:=,<,>,\%;*,/},
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    40
}[keywords,comments,strings]
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
\lstdefinestyle{mystyle}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
       {basicstyle=\ttfamily,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
	keywordstyle=\color{codepurple}\bfseries,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
	stringstyle=\color{codegreen},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
	commentstyle=\color{codegreen},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
	morecomment=[s][\color{codedocblue}]{/**}{*/},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
	numbers=left,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
	numberstyle=\tiny\color{black},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
	stepnumber=1,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
	numbersep=10pt,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
	tabsize=2,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
	showspaces=false,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
	showstringspaces=false,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
        xleftmargin=8mm,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
        emphstyle=\color{codeblue}\bfseries,
336
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    57
        keepspaces
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    58
}
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
\lstset{language=Scala,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
        style=mystyle}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
\newcommand{\code}[1]{{\lstinline{#1}}}
160
4cbd6ca025e6 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 157
diff changeset
    65
\newcommand{\pcode}[1]{\mbox{\lstset{language={},keywordstyle=\color{black}}\lstinline!#1!}}
336
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    66
\newcommand{\scode}[1]{\mbox{\lstset{language={},basicstyle=\ttfamily\color{codegreen}}\lstinline!#1!}}
160
4cbd6ca025e6 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 157
diff changeset
    67
\makeatother