langs.sty
author Christian Urban <christian.urban@kcl.ac.uk>
Tue, 24 Nov 2020 09:04:06 +0000
changeset 366 1c829680503e
parent 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
276
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
     6
\makeatletter
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
     7
\let\old@lstKV@SwitchCases\lstKV@SwitchCases
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
     8
\def\lstKV@SwitchCases#1#2#3{}
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
     9
\makeatother
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    10
\usepackage{lstlinebgrd}
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    11
\makeatletter
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    12
\let\lstKV@SwitchCases\old@lstKV@SwitchCases
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    13
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    14
\lst@Key{numbers}{none}{%
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    15
    \def\lst@PlaceNumber{\lst@linebgrd}%
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    16
    \lstKV@SwitchCases{#1}%
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    17
    {none:\\%
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    18
     left:\def\lst@PlaceNumber{\llap{\normalfont
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    19
                \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\\%
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    20
     right:\def\lst@PlaceNumber{\rlap{\normalfont
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    21
                \kern\linewidth \kern\lst@numbersep
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    22
                \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    23
    }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    24
\makeatother
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    25
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    26
52faee6d0be2 updated
Christian Urban <urbanc@in.tum.de>
parents: 185
diff changeset
    27
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
\definecolor{codered}{rgb}{0.6,0,0}            % for strings
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
\definecolor{codegreen}{rgb}{0.25,0.5,0.35}    % comments
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
\definecolor{codepurple}{rgb}{0.5,0,0.35}      % keywords
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
\definecolor{codedocblue}{rgb}{0.25,0.35,0.75} % doc
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
\definecolor{codeblue}{rgb}{0.25,0.35,0.75}    % types
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
\BeforeBeginEnvironment{lstlisting}{\par\noindent\begin{minipage}{\linewidth}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
\AfterEndEnvironment{lstlisting}{\end{minipage}\par}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
\lstdefinelanguage{Scala}{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  morekeywords={abstract,case,catch,class,def,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
    do,else,extends,false,final,finally,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
    for,if,implicit,import,match,mixin,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
    new,null,object,override,package,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
    private,protected,requires,return,sealed,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
    super,this,throw,trait,true,try,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
    type,val,var,while,with,yield,write,read},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  otherkeywords={=>,<-,<\%,<:,>:,\#},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  sensitive=true,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  %directives={Int,Char,Rexp,String,Boolean,BigInt,Unit,List,Set},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  %moredelim=*[directive]:,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  morecomment=[l]{//},%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  morecomment=[n]{/*}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  morestring=[s]{"""}{"""},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  morestring=[b]",
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  morestring=[b]',
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
}[keywords,comments,strings]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
\lstdefinelanguage{While}{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  morekeywords={if,then,else,while,do,true,false,write,upto,read,for,skip},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
  morecomment=[l]{//},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  morecomment=[n]{/*}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  morestring=[b]",
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
  otherkeywords={=,!=,:=,<,>,\%;*,/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
}[keywords,comments,strings]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
123
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    64
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    65
\newcommand{\code}[1]{{\lstinline{#1}}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    66
\newcommand{\pcode}[1]{\mbox{\lstset{language={},keywordstyle=\color{black}}\lstinline!#1!}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    67
\newcommand{\scode}[1]{\mbox{\lstset{language={},basicstyle=\ttfamily\color{codegreen}}\lstinline!#1!}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    68
\makeatother
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    69
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    70
%%\lstset{escapeinside={(*@}{@*)}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    71
\lstset{escapeinside={/*@}{@*/}}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    72
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    73
%% stripy code
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    74
\usepackage{lstlinebgrd}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    75
\definecolor{capri}{rgb}{0.0, 0.75, 1.0}
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    76
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    77
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
\lstdefinestyle{mystyle}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
       {basicstyle=\ttfamily,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
	keywordstyle=\color{codepurple}\bfseries,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
	stringstyle=\color{codegreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
	commentstyle=\color{codegreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
	morecomment=[s][\color{codedocblue}]{/**}{*/},
123
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    84
	numbers=none,
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
	numberstyle=\tiny\color{black},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
	stepnumber=1,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
	numbersep=10pt,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
	tabsize=2,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
	showspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
	showstringspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
        xleftmargin=8mm,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
        emphstyle=\color{codeblue}\bfseries,
123
556cd74cbba9 updated
Christian Urban <urbanc@in.tum.de>
parents: 21
diff changeset
    93
        keepspaces,
185
5ab45f3fee1c updated
Christian Urban <urbanc@in.tum.de>
parents: 184
diff changeset
    94
        linebackgroundcolor={\ifodd\value{lstnumber}\color{capri!3}\fi}
21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
\lstset{language=Scala,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
        style=mystyle}