langs.sty
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 07 Oct 2014 09:37:47 +0100
changeset 224 b07777a393dc
parent 164 08a6e035223e
child 336 3cb200fa6d6a
permissions -rw-r--r--
added format string args
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
164
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    11
\definecolor{darkgray}{rgb}{.4,.4,.4}
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
\BeforeBeginEnvironment{lstlisting}{\par\noindent\begin{minipage}{\linewidth}}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
\AfterEndEnvironment{lstlisting}{\end{minipage}\par}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
164
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    16
\lstdefinelanguage{JavaScript}{
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    17
  keywords={break,case,catch,continue,debugger,default,% 
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    18
    delete,do,else,false,finally,for,function,if,in,instanceof,% 
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    19
    new,null,return,switch,this,throw,true,try,typeof,var,void,while,with},
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    20
  morecomment=[l]{//},
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    21
  morecomment=[s]{/*}{*/},
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    22
  morestring=[b]',
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    23
  morestring=[b]",
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    24
  ndkeywords={class,export,boolean,throw,implements,import,this},
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    25
  keywordstyle=\color{codepurple}\bfseries,
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    26
  ndkeywordstyle=\color{darkgray}\bfseries,
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    27
  identifierstyle=\color{black},
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    28
  commentstyle=\color{codegreen}\ttfamily,
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    29
  stringstyle=\color{codegreen}\ttfamily,
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    30
  sensitive=true
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    31
}
08a6e035223e updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 160
diff changeset
    32
157
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
\lstdefinelanguage{Scala}{
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  morekeywords={abstract,case,catch,class,def,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
    do,else,extends,false,final,finally,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
    for,if,implicit,import,match,mixin,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
    new,null,object,override,package,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
    private,protected,requires,return,sealed,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
    super,this,throw,trait,true,try,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
    type,val,var,while,with,yield},%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  sensitive=true,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  %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
    44
  %moredelim=*[directive]:,%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  morecomment=[l]{//},%
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  morecomment=[n]{/*}{*/},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  morestring=[b]",
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
  morestring=[b]',
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  morestring=[b]"""
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
}[keywords,comments,strings]
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
\lstdefinelanguage{While}{
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  morekeywords={if,then,else,while,do,true,false,write,upto,for,skip},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
  otherkeywords={=,!=,:=,<,>,;},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  sensitive=true,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  morecomment=[n]{/*}{*/},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
\lstdefinestyle{mystyle}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
       {basicstyle=\ttfamily,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
	keywordstyle=\color{codepurple}\bfseries,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
        %directivestyle=\color{codeblue}\bfseries,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
	stringstyle=\color{codegreen},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
	commentstyle=\color{codegreen},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
	morecomment=[s][\color{codedocblue}]{/**}{*/},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
	numbers=left,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
	numberstyle=\tiny\color{black},
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
	stepnumber=1,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
	numbersep=10pt,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
	tabsize=2,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
	showspaces=false,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
	showstringspaces=false,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
        xleftmargin=8mm,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
        emphstyle=\color{codeblue}\bfseries,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
        keepspaces}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
\lstset{language=Scala,
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
        style=mystyle}
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
3a8fff66d62b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
\newcommand{\code}[1]{{\lstinline{#1}}}
160
4cbd6ca025e6 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 157
diff changeset
    82
\newcommand{\pcode}[1]{\mbox{\lstset{language={},keywordstyle=\color{black}}\lstinline!#1!}}
4cbd6ca025e6 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 157
diff changeset
    83
\makeatother