styles/langs.sty
changeset 493 f7c84bfa3cee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/styles/langs.sty	Mon Nov 10 11:04:33 2025 +0000
@@ -0,0 +1,98 @@
+\usepackage{listings}
+\usepackage{etoolbox}
+\setmonofont[Scale=.95]{Consolas}
+\newfontfamily{\consolas}{Consolas}
+
+\makeatletter
+\let\old@lstKV@SwitchCases\lstKV@SwitchCases
+\def\lstKV@SwitchCases#1#2#3{}
+\makeatother
+\usepackage{lstlinebgrd}
+\makeatletter
+\let\lstKV@SwitchCases\old@lstKV@SwitchCases
+
+\lst@Key{numbers}{none}{%
+    \def\lst@PlaceNumber{\lst@linebgrd}%
+    \lstKV@SwitchCases{#1}%
+    {none:\\%
+     left:\def\lst@PlaceNumber{\llap{\normalfont
+                \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\\%
+     right:\def\lst@PlaceNumber{\rlap{\normalfont
+                \kern\linewidth \kern\lst@numbersep
+                \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
+    }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
+\makeatother
+
+
+
+\definecolor{codered}{rgb}{0.6,0,0}            % for strings
+\definecolor{codegreen}{rgb}{0.25,0.5,0.35}    % comments
+\definecolor{codepurple}{rgb}{0.5,0,0.35}      % keywords
+\definecolor{codedocblue}{rgb}{0.25,0.35,0.75} % doc
+\definecolor{codeblue}{rgb}{0.25,0.35,0.75}    % types
+
+\BeforeBeginEnvironment{lstlisting}{\par\noindent\begin{minipage}{\linewidth}}
+\AfterEndEnvironment{lstlisting}{\end{minipage}\par}
+
+\lstdefinelanguage{Scala}{
+  morekeywords={abstract,case,catch,class,def,%
+    do,else,extends,false,final,finally,%
+    for,if,implicit,import,match,mixin,%
+    new,null,object,override,package,%
+    private,protected,requires,return,sealed,%
+    super,this,throw,trait,then,true,try,%
+    type,val,var,while,with,yield,write,read},%
+  otherkeywords={=>,<-,<\%,<:,>:,\#},%
+  sensitive=true,%
+  %directives={Int,Char,Rexp,String,Boolean,BigInt,Unit,List,Set},%
+  %moredelim=*[directive]:,%
+  morecomment=[l]{//},%
+  morecomment=[n]{/*}{*/},
+  morestring=[s]{"""}{"""},
+  morestring=[b]",
+  morestring=[b]',
+}[keywords,comments,strings]
+
+\lstdefinelanguage{While}{
+  morekeywords={if,then,else,while,do,true,false,write,upto,read,for,skip},
+  morecomment=[l]{//},
+  morecomment=[n]{/*}{*/},
+  morestring=[b]",
+  otherkeywords={=,!=,:=,<,>,\%;*,/},
+}[keywords,comments,strings]
+
+
+\newcommand{\code}[1]{{\lstinline{#1}}}
+\newcommand{\pcode}[1]{\mbox{\lstset{language={},keywordstyle=\color{black}}\lstinline!#1!}}
+\newcommand{\scode}[1]{\mbox{\lstset{language={},basicstyle=\ttfamily\color{codegreen}}\lstinline!#1!}}
+\makeatother
+
+%%\lstset{escapeinside={(*@}{@*)}}
+\lstset{escapeinside={/*@}{@*/}}
+
+%% stripy code
+\usepackage{lstlinebgrd}
+\definecolor{capri}{rgb}{0.0, 0.75, 1.0}
+
+
+\lstdefinestyle{mystyle}
+       {basicstyle=\ttfamily,
+	keywordstyle=\color{codepurple}\bfseries,
+	stringstyle=\color{codegreen},
+	commentstyle=\color{codegreen},
+	morecomment=[s][\color{codedocblue}]{/**}{*/},
+	numbers=none,
+	numberstyle=\tiny\color{black},
+	stepnumber=1,
+	numbersep=10pt,
+	tabsize=2,
+	showspaces=false,
+	showstringspaces=false,
+        xleftmargin=8mm,
+        emphstyle=\color{codeblue}\bfseries,
+        keepspaces,
+        linebackgroundcolor={\ifodd\value{lstnumber}\color{capri!3}\fi}
+}
+
+\lstset{language=Scala,
+        style=mystyle}