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