Created
October 8, 2014 13:44
-
-
Save chriseidhof/18dbc1c4eef919eab2c7 to your computer and use it in GitHub Desktop.
Listings Swift config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\lstdefinelanguage{swift} | |
{ | |
morekeywords={ | |
func,if,then,else,for,in,while,do,switch,case,default,where,break,continue,fallthrough,return, | |
typealias,struct,class,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, | |
}, | |
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} | |
\lstset{ | |
language=swift, | |
basicstyle=\ttfamily, | |
showstringspaces=false, % lets spaces in strings appear as real spaces | |
columns=fixed, | |
keepspaces=true, | |
keywordstyle=\color{keyword}, | |
stringstyle=\color{string}, | |
commentstyle=\color{comment}, | |
} |
Thank you @chriseidhof!
I added a fork to add correctly colored integer and decimal numbers. Let me know if it works for you.
Not sure if anybody cares, but this is my setup, adding a few more keywords:
% https://gist.github.com/chriseidhof/18dbc1c4eef919eab2c7
% Swift syntax highlight definition for listings
\usepackage{xcolor}
\lstdefinelanguage{swift}
{
morekeywords={
open,catch,@escaping,nil,throws,func,if,then,else,for,in,while,do,switch,case,default,where,break,continue,fallthrough,return,
typealias,struct,class,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,
},
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
breaklines=true,
escapeinside={\%*}{*)},
numbers=left,
captionpos=b,
breakatwhitespace=true,
basicstyle=\linespread{1.0}\ttfamily\footnotesize, % https://tex.stackexchange.com/a/102728/129441
}
\definecolor{keyword}{HTML}{BA2CA3}
\definecolor{string}{HTML}{D12F1B}
\definecolor{comment}{HTML}{008400}
\lstset{
language=swift,
basicstyle=\ttfamily\small,
showstringspaces=false, % lets spaces in strings appear as real spaces
columns=fixed,
keepspaces=true,
keywordstyle=\color{keyword},
stringstyle=\color{string},
commentstyle=\color{comment},
}
I think you're a few keywords short: try
, catch
, guard
"Test message: \(message)" why is the variable also the string color can someone help me pls
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget include the
\usepackage{xcolor}
\usepackage{listings}