langs.sty
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 30 Sep 2016 19:55:35 +0100
changeset 464 f76e1456b365
parent 345 7f0ac1355f0b
permissions -rw-r--r--
updated
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
345
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    42
\lstdefinelanguage{JavaScript}{
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    43
  keywords={break, case, catch, continue, debugger, default, delete, do, else, false, finally, for, function, if, in, instanceof, new, null, return, switch, this, throw, true, try, typeof, var, void, while, with},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    44
  morecomment=[l]{//},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    45
  morecomment=[s]{/*}{*/},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    46
  morestring=[b]',
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    47
  morestring=[b]",
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    48
  ndkeywords={class, export, boolean, throw, implements, import, this},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    49
  keywordstyle=\color{codepurple},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    50
  ndkeywordstyle=\color{codepurple},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    51
  identifierstyle=\color{black},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    52
  commentstyle=\color{codegreen},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    53
  stringstyle=\color{codegreen},
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    54
  sensitive=true
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    55
}
7f0ac1355f0b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 336
diff changeset
    56
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
\lstdefinestyle{mystyle}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
       {basicstyle=\ttfamily,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
	keywordstyle=\color{codepurple}\bfseries,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
	stringstyle=\color{codegreen},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
	commentstyle=\color{codegreen},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
	morecomment=[s][\color{codedocblue}]{/**}{*/},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
	numbers=left,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
	numberstyle=\tiny\color{black},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
	stepnumber=1,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
	numbersep=10pt,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
	tabsize=2,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
	showspaces=false,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
	showstringspaces=false,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
        xleftmargin=8mm,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
        emphstyle=\color{codeblue}\bfseries,
336
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    72
        keepspaces
3cb200fa6d6a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 164
diff changeset
    73
}
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
\lstset{language=Scala,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
        style=mystyle}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
\newcommand{\code}[1]{{\lstinline{#1}}}
160
4cbd6ca025e6 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 157
diff changeset
    80
\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
    81
\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
    82
\makeatother