langs.sty
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 05 Aug 2019 20:14:06 +0100
changeset 269 86a85865e772
parent 185 5ab45f3fee1c
child 276 52faee6d0be2
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\usepackage{listings}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\usepackage{etoolbox}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
\setmonofont[Scale=.95]{Consolas}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
\newfontfamily{\consolas}{Consolas}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
\definecolor{codered}{rgb}{0.6,0,0}            % for strings
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\definecolor{codegreen}{rgb}{0.25,0.5,0.35}    % comments
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
\definecolor{codepurple}{rgb}{0.5,0,0.35}      % keywords
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\definecolor{codedocblue}{rgb}{0.25,0.35,0.75} % doc
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
\definecolor{codeblue}{rgb}{0.25,0.35,0.75}    % types
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
\BeforeBeginEnvironment{lstlisting}{\par\noindent\begin{minipage}{\linewidth}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
\AfterEndEnvironment{lstlisting}{\end{minipage}\par}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
\lstdefinelanguage{Scala}{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  morekeywords={abstract,case,catch,class,def,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
    do,else,extends,false,final,finally,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
    for,if,implicit,import,match,mixin,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
    new,null,object,override,package,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
    private,protected,requires,return,sealed,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
    super,this,throw,trait,true,try,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
    type,val,var,while,with,yield,write,read},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  otherkeywords={=>,<-,<\%,<:,>:,\#},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  sensitive=true,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  %directives={Int,Char,Rexp,String,Boolean,BigInt,Unit,List,Set},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  %moredelim=*[directive]:,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  morecomment=[l]{//},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  morecomment=[n]{/*}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  morestring=[s]{"""}{"""},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  morestring=[b]",
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  morestring=[b]',
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
}[keywords,comments,strings]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
\lstdefinelanguage{While}{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  morekeywords={if,then,else,while,do,true,false,write,upto,read,for,skip},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  morecomment=[l]{//},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  morecomment=[n]{/*}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  morestring=[b]",
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  otherkeywords={=,!=,:=,<,>,\%;*,/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
}[keywords,comments,strings]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
123
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    42
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    43
\newcommand{\code}[1]{{\lstinline{#1}}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    44
\newcommand{\pcode}[1]{\mbox{\lstset{language={},keywordstyle=\color{black}}\lstinline!#1!}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    45
\newcommand{\scode}[1]{\mbox{\lstset{language={},basicstyle=\ttfamily\color{codegreen}}\lstinline!#1!}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    46
\makeatother
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    47
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    48
%%\lstset{escapeinside={(*@}{@*)}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    49
\lstset{escapeinside={/*@}{@*/}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    50
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    51
%% stripy code
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    52
\usepackage{lstlinebgrd}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    53
\definecolor{capri}{rgb}{0.0, 0.75, 1.0}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    54
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    55
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
\lstdefinestyle{mystyle}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
       {basicstyle=\ttfamily,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
	keywordstyle=\color{codepurple}\bfseries,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
	stringstyle=\color{codegreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
	commentstyle=\color{codegreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
	morecomment=[s][\color{codedocblue}]{/**}{*/},
123
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    62
	numbers=none,
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
	numberstyle=\tiny\color{black},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
	stepnumber=1,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
	numbersep=10pt,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
	tabsize=2,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
	showspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
	showstringspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
        xleftmargin=8mm,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
        emphstyle=\color{codeblue}\bfseries,
123
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    71
        keepspaces,
185
5ab45f3fee1c updated
Christian Urban <urbanc@in.tum.de>
parents: 184
diff changeset
    72
        linebackgroundcolor={\ifodd\value{lstnumber}\color{capri!3}\fi}
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
\lstset{language=Scala,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
        style=mystyle}