-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodelisting.tex
More file actions
116 lines (104 loc) · 5.07 KB
/
codelisting.tex
File metadata and controls
116 lines (104 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%CODE LISTING SYNTAX COLORING
%Source code listings from files and present them using Sublime Text
%syntax coloring.
%CALL LISTING PACKAGE IN SEPARATE BEAMER.TEX WITH:
%\newcommand\whiteback{0} %code listing background color (0: black, 1: white)
%\input{\string~/lib/beamer/codelisting}
\usepackage{color} %make custom colors for syntax coloring
\usepackage{listings} %allows code listings
\usepackage{textcomp} %allows apostrophes to be straight (unidirectional)
% \usepackage{framed}
% \usepackage{caption}
\usepackage{bm}
\usepackage{tcolorbox} %use for code listing color definitions
\tcbuselibrary{listings} %allow color defenitions in code listings
\captionsetup[lstlisting]{font={small,tt}}
%Custom Colors
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\definecolor{sublimeblack}{HTML}{272822}
\definecolor{sublimered}{HTML}{F92672}
\definecolor{sublimeblue}{HTML}{66D9EF}
\definecolor{sublimeyellow}{HTML}{E6DB74}
\definecolor{sublimegrey}{HTML}{75715E}
\definecolor{sublimegreen}{HTML}{66CC33}
\definecolor{sublimeorange}{HTML}{FD971F}
\definecolor{sublimepurple}{HTML}{AE81FF}
%White or Black background toggle
% \newcommand\whiteback{0}
\ifnum\whiteback=1%
%White Background
\newcommand\backclr{white}
\newcommand\txtclr{\color{black}}
\newcommand\comclr{\color{mygreen}}
\newcommand\keyclr{\color{blue}}
\newcommand\ndkeyclr{\color{sublimered}}
\newcommand\strclr{\color{mymauve}}
\newcommand\frameon{single} %single-frame box around code
\else
%Black Background (like SublimeText)
\newcommand\backclr{sublimeblack}
\newcommand\txtclr{\color{white}}
\newcommand\comclr{\color{sublimegrey}}
\newcommand\keyclr{\color{sublimeblue}}
\newcommand\ndkeyclr{\color{sublimered}}
\newcommand\strclr{\color{sublimeyellow}}
\newcommand\frameon{false} %no frame for black background
\fi
%Listing Style
\lstdefinestyle{mystyle}{%
% backgroundcolor=\backclr, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
basicstyle=\ttfamily\txtclr\scriptsize, % the SIZE OF THE FONTS that are used for the code
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
% breaklines=true, % sets automatic line breaking
captionpos=b, % sets the caption-position to bottom
commentstyle=\comclr, % comment color
deletekeywords={...}, % if you want to delete keywords from the given language
escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
frame=\frameon, % adds a frame around the code
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
columns=flexible,
otherkeywords={zip,enumerate,True,False,None,...}, %add words to be highlighted
keywordstyle=\keyclr, % keyword (e.g. 'print') color
language=Python, % the language of the code
upquote=true, % make apostrophes straight (unidirectional)
alsoletter={<>=-+*/!}, % to avoid coloring operators when they're not
ndkeywords={=,+,-,*,**,/,+=,*=,-=,/=,<=,>=,==,!=,<,>,... }, % operator keywords
ndkeywordstyle=\ndkeyclr, % style of operator keywords
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
numbersep=5pt, % how far the line-numbers are from the code
numberstyle=\tiny\color{mygray}, % line-number style: size, color
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
showstringspaces=false, % underline spaces within strings only
showtabs=false, % show tabs within strings adding particular underscores
stepnumber=1, % the step between two line-numbers. If it's 1, each line will be numbered
stringstyle=\strclr, % string color
tabsize=4, % sets default tabsize
}
%Function that calls listing of specific file with custom coloring
%first input is filename to list
%next two inputs are start and end line numbers
%(use 0 and large number for all lines)
\newcommand\mylisting[3]{
\tcbinputlisting{
listing file=#1,
arc=0pt,
top=0mm,
bottom=0mm,
left=0mm,
right=0mm,
boxrule=0pt,
colback=\backclr,
listing only,
listing options={
style=mystyle, %use custom style
firstline=#2,lastline=#3, %lines of code to use
firstnumber=#2, %same numbering as script
},
hbox
}
}