langs.sty
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 17 Sep 2023 19:12:57 +0100
changeset 919 53f08d873e09
parent 908 0138618eff73
child 920 7af2eea19646
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
218
8f3f8d82da8b added two new packages
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\usepackage{listings}
238
527fdb90fffe updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 237
diff changeset
     2
\usepackage{etoolbox}
630
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     3
%\setmonofont[Scale=.95]{Consolas}
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     4
%\newfontfamily{\consolas}{Consolas}
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     5
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     6
\makeatletter
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     7
\let\old@lstKV@SwitchCases\lstKV@SwitchCases
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     8
\def\lstKV@SwitchCases#1#2#3{}
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     9
\makeatother
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    10
\usepackage{lstlinebgrd}
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    11
\makeatletter
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    12
\let\lstKV@SwitchCases\old@lstKV@SwitchCases
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    13
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    14
\lst@Key{numbers}{none}{%
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    15
    \def\lst@PlaceNumber{\lst@linebgrd}%
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    16
    \lstKV@SwitchCases{#1}%
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    17
    {none:\\%
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    18
     left:\def\lst@PlaceNumber{\llap{\normalfont
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    19
                \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\\%
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    20
     right:\def\lst@PlaceNumber{\rlap{\normalfont
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    21
                \kern\linewidth \kern\lst@numbersep
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    22
                \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    23
    }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    24
\makeatother
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    25
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    26
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
    27
218
8f3f8d82da8b added two new packages
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    29
\definecolor{codered}{rgb}{0.6,0,0}            % for strings
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    30
\definecolor{codegreen}{rgb}{0.25,0.5,0.35}    % comments
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    31
\definecolor{codepurple}{rgb}{0.5,0,0.35}      % keywords
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    32
\definecolor{codedocblue}{rgb}{0.25,0.35,0.75} % doc
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    33
\definecolor{codeblue}{rgb}{0.25,0.35,0.75}    % types
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    34
238
527fdb90fffe updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 237
diff changeset
    35
\BeforeBeginEnvironment{lstlisting}{\par\noindent\begin{minipage}{\linewidth}}
527fdb90fffe updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 237
diff changeset
    36
\AfterEndEnvironment{lstlisting}{\end{minipage}\par}
218
8f3f8d82da8b added two new packages
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    38
\lstdefinelanguage{Scala}{
820
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 819
diff changeset
    39
  morekeywords={abstract,then,case,catch,class,def,%
873
a25da86f7c8c updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 820
diff changeset
    40
    do,else,enum,extends,false,final,finally,%
a25da86f7c8c updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 820
diff changeset
    41
    for,given,if,implicit,import,lazy,match,mixin,%
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    42
    new,null,object,override,package,%
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    43
    private,protected,requires,return,sealed,%
873
a25da86f7c8c updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 820
diff changeset
    44
    super,this,then,throw,trait,true,try,%
a25da86f7c8c updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 820
diff changeset
    45
    type,val,var,while,with,yield,write,read},%
591
863e502f6a5c updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
    46
  literate={==>}{{\mbox{\color{codepurple}{\textbf{\texttt{==>}}}}}}2,%
863e502f6a5c updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
    47
  otherkeywords={=>,<-,<\%,<:,>:,\#},%
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    48
  sensitive=true,%
235
bc460179148c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 234
diff changeset
    49
  %directives={Int,Char,Rexp,String,Boolean,BigInt,Unit,List,Set},%
bc460179148c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 234
diff changeset
    50
  %moredelim=*[directive]:,%
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    51
  morecomment=[l]{//},%
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    52
  morecomment=[n]{/*}{*/},
254
dcd4688690ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
    53
  morestring=[s]{"""}{"""},
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    54
  morestring=[b]",
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    55
  morestring=[b]',
235
bc460179148c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 234
diff changeset
    56
}[keywords,comments,strings]
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    57
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    58
\lstdefinelanguage{While}{
690
8d57433c7b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 680
diff changeset
    59
  morekeywords={if,then,else,while,do,true,false,write,upto,read,for,skip,new},
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
    60
  morecomment=[l]{//},
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    61
  morecomment=[n]{/*}{*/},
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
    62
  morestring=[b]",
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
    63
  otherkeywords={=,!=,:=,<,>,\%;*,/},
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
    64
}[keywords,comments,strings]
234
bf7eecc9cefe updated scala ho
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    65
218
8f3f8d82da8b added two new packages
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
711
6f3f3dd01786 updated
Christian Urban <urbanc@in.tum.de>
parents: 709
diff changeset
    67
\lstdefinelanguage{JVMIS2}[]{JVMIS}
6f3f3dd01786 updated
Christian Urban <urbanc@in.tum.de>
parents: 709
diff changeset
    68
{
712
e71eb9ce2373 updated
Christian Urban <urbanc@in.tum.de>
parents: 711
diff changeset
    69
  morekeywords={if_icmpgt,if_icmpge,iconst_m1,if_icmple}
647
180600c04da2 updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
    70
}[keywords]
180600c04da2 updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
    71
680
eecc4d5a2172 updated
Christian Urban <urbanc@in.tum.de>
parents: 647
diff changeset
    72
\lstdefinelanguage{LLVMIR}{
908
0138618eff73 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 873
diff changeset
    73
  otherkeywords={let,in,add,mul,KLet,return,call},
680
eecc4d5a2172 updated
Christian Urban <urbanc@in.tum.de>
parents: 647
diff changeset
    74
}[strings]
607
3f4fc76dab2f updated
Christian Urban <urbanc@in.tum.de>
parents: 591
diff changeset
    75
237
370c0647a9bf more material
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 235
diff changeset
    76
\newcommand{\code}[1]{{\lstinline{#1}}}
711
6f3f3dd01786 updated
Christian Urban <urbanc@in.tum.de>
parents: 709
diff changeset
    77
\newcommand{\instr}[1]{\mbox{\lstinline[language=JVMIS2]{#1}}}
242
35104ee14f87 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    78
\newcommand{\pcode}[1]{\mbox{\lstset{language={},keywordstyle=\color{black}}\lstinline!#1!}}
254
dcd4688690ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 242
diff changeset
    79
\newcommand{\scode}[1]{\mbox{\lstset{language={},basicstyle=\ttfamily\color{codegreen}}\lstinline!#1!}}
242
35104ee14f87 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    80
\makeatother
399
5c1fbb39c93e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
    81
427
546f2090ce12 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 399
diff changeset
    82
%%\lstset{escapeinside={(*@}{@*)}}
546f2090ce12 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 399
diff changeset
    83
\lstset{escapeinside={/*@}{@*/}}
480
9e42ccbbd1e6 updated
Christian Urban <urbanc@in.tum.de>
parents: 427
diff changeset
    84
9e42ccbbd1e6 updated
Christian Urban <urbanc@in.tum.de>
parents: 427
diff changeset
    85
%% stripy code
9e42ccbbd1e6 updated
Christian Urban <urbanc@in.tum.de>
parents: 427
diff changeset
    86
\usepackage{lstlinebgrd}
9e42ccbbd1e6 updated
Christian Urban <urbanc@in.tum.de>
parents: 427
diff changeset
    87
\definecolor{capri}{rgb}{0.0, 0.75, 1.0}
490
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    88
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    89
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    90
\lstdefinestyle{mystyle}
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    91
       {basicstyle=\ttfamily,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    92
	keywordstyle=\color{codepurple}\bfseries,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    93
	stringstyle=\color{codegreen},
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    94
	commentstyle=\color{codegreen},
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    95
	morecomment=[s][\color{codedocblue}]{/**}{*/},
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    96
	numbers=none,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    97
	numberstyle=\tiny\color{black},
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    98
	stepnumber=1,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
    99
	numbersep=10pt,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   100
	tabsize=2,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   101
	showspaces=false,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   102
	showstringspaces=false,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   103
        xleftmargin=8mm,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   104
        emphstyle=\color{codeblue}\bfseries,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   105
        keepspaces,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   106
        linebackgroundcolor={\ifodd\value{lstnumber}\color{capri!3}\fi}
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   107
}
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   108
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   109
\lstset{language=Scala,
4fee50f38305 updated
Christian Urban <urbanc@in.tum.de>
parents: 480
diff changeset
   110
        style=mystyle}