Skip to content

Instantly share code, notes, and snippets.

@GitHelge
Forked from chriseidhof/swift.tex
Last active January 5, 2022 14:14
Show Gist options
  • Save GitHelge/3c592265a9560e71bab80c6579b0c343 to your computer and use it in GitHub Desktop.
Save GitHelge/3c592265a9560e71bab80c6579b0c343 to your computer and use it in GitHub Desktop.
Listings Swift config
\lstdefinelanguage{swift}
{
morekeywords={
func,if,then,else,for,in,while,do,switch,case,default,where,break,continue,fallthrough,return,
typealias,struct,class,super,enum,protocol,var,func,let,get,set,willSet,didSet,inout,init,deinit,extension,
subscript,prefix,operator,infix,postfix,precedence,associativity,left,right,none,convenience,dynamic,
final,lazy,mutating,nonmutating,optional,override,required,static,unowned,safe,weak,internal,
private,public,is,as,self,unsafe,dynamicType,true,false,nil,Type,Protocol,import,@IBOutlet,@IBAction, guard
},
morekeywords=[2]{Double,Int,Float,Bool,String},
morecomment=[l]{//}, % l is for line comment
morecomment=[s]{/*}{*/}, % s is for start and end delimiter
morestring=[b]" % defines that strings are enclosed in double quotes
}
\definecolor{keyword}{HTML}{BA2CA3}
\definecolor{string}{HTML}{D12F1B}
\definecolor{comment}{HTML}{008400}
\definecolor{classname}{HTML}{663399}
\definecolor{numbers}{HTML}{0000CC}
\newcommand{\ProcessDigit}[1]
{%
\ifnum\lst@mode=\lst@Pmode\relax%
{\digitstyle #1}%
\else
#1%
\fi
}
\newcommand*{\FormatDigit}[1]{
\textcolor{numbers}{#1}
}
\lstset{
language=swift,
basicstyle=\ttfamily,
showstringspaces=false, % lets spaces in strings appear as real spaces
columns=fixed,
breaklines=true,
aboveskip=20pt,
belowskip=10pt,
%numbers=left,
frame=top,
frame=bottom,
captionpos=b,
keepspaces=true,
keywordstyle=\color{keyword},
keywordstyle=[1]{\color{keyword}},
keywordstyle=[2]{\color{classname}},
stringstyle=\color{string},
commentstyle=\color{comment}}
\lstset{literate=
*{0}{{{\color{numbers}0}}}1
{1}{{{\color{numbers}1}}}1
{2}{{{\color{numbers}2}}}1
{3}{{{\color{numbers}3}}}1
{4}{{{\color{numbers}4}}}1
{5}{{{\color{numbers}5}}}1
{6}{{{\color{numbers}6}}}1
{7}{{{\color{numbers}7}}}1
{8}{{{\color{numbers}8}}}1
{9}{{{\color{numbers}9}}}1
{.0}{{\FormatDigit{.0}}}{2}% Following is to ensure that only periods
{.1}{{\FormatDigit{.1}}}{2}% followed by a digit are changed.
{.2}{{\FormatDigit{.2}}}{2}%
{.3}{{\FormatDigit{.3}}}{2}%
{.4}{{\FormatDigit{.4}}}{2}%
{.5}{{\FormatDigit{.5}}}{2}%
{.6}{{\FormatDigit{.6}}}{2}%
{.7}{{\FormatDigit{.7}}}{2}%
{.8}{{\FormatDigit{.8}}}{2}%
{.9}{{\FormatDigit{.9}}}{2}%
}
@GitHelge
Copy link
Author

Adds Xcode-style colors to integer and decimal numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment