-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListingsSetup.tex
197 lines (188 loc) · 11.5 KB
/
ListingsSetup.tex
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
\usepackage{listings}
\usepackage{lstautogobble}
\def\transpPerc{100}
\lstdefinestyle{MyCpp}{
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
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=none , % adds a frame around the code
numbers=none, % 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{black}, % the style that is used for the line-numbers
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=2, % the step between two line-numbers. If it's 1, each line will be numbered
stringstyle=\color{OliveGreen}, % string literal style
tabsize=2, % sets default tabsize to 2 spaces
title=\lstname, % show the filename of files included with \lstinputlisting; also try caption instead of title
%
%Base style for this presentation
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code
% (possibly needs columns=flexible)
keywordstyle=\color{Cyan}, % keyword style
language=C++,
basicstyle=\ttfamily\scriptsize\color{black},
keywordstyle=\color{OliveGreen},
stringstyle=\color{ForestGreen},
commentstyle=\color{red},
moredelim=[is][\color{ForestGreen}]{|+}{+|},
moredelim=[is][\color{black}]{|=}{=|},
literate=% literate={<replace>}{<replacement text>}{<width>}
{\#define}{{{\color{CarnationPink}\#define}}}{6}
{\#if}{{{\color{CarnationPink}\#if}}}{3}
{\#include}{{{\color{CarnationPink}\#include}}}{7},
morekeywords={size_t, T, pair, tuple, array, unordered_map, string, map, Widget,
BadWidget, is_integral, initializer_list, byte, Type, logic_error,
error_info, variant, optional, any, string_view, filesystem, list, byte,
stringstream, char_traits, bad_variant_access, var_t, bad_any_cast, path,
sequenced_policy, parallel_policy, parallel_unsequenced_policy, vector, C,
mdspan, expected},
emph=[1]{main, get_mix, type_name, make_tuple, status, find, end, message, zip, boolalpha, size,
isIntegral, foo, bar, is_success, do_something, do_something_ref, my_callback, is_error,
splice, invoke, apply, get, visit, index, in_place_type, to_int, eof, slice, value_or,
substr, min, find_first_not_of, remove_prefix, getSV, what, make_optional, any_cast, make_any,
copy_file, create_directory, append, exists, file_size, space, push_back, find,
for_each, begin, uncaught_exception, uncaught_exceptions, print},
emphstyle=[1]{\color{NavyBlue}}, %Functions
emph=[2]{x, y, z, cout, uns, n, pi, letter, label, mapping, key, content, argc, argv, it, m, s,
gadget, x2, x3, x4, b1, b2, b3, b4, ei, err, message, var, v, w, i, oi, stm, number, a, b,
str, start, finish, nullopt, bad, e, filePath, fileSize, tmpPath, par, longVector, result,
obj, obj2, vec, arg},
emphstyle=[2]{\color{Orange}}, %Variables
emph=[3]{if, else, while, do, for, case, switch, inline, try, catch, goto},
emphstyle=[3]{\color{violet}}, %Loops, if, etc.
emph=[4]{const, auto, break, continue, default, static, return, struct, NULL, sizeof, typedef, using, this,
template, typename, true, false, throw, public, class, constexpr, decltype, namespace, enum},
emphstyle=[4]{\color{ProcessBlue}}, %Logical keywords
emph=[5]{std, boost, literals, fs, execution},
emphstyle=[5]{\color{Maroon}}, %Namespaces
emph=[6]{__FUNCTION__, __has_include, static_assert, assert},
emphstyle=[6]{\color{Gray}}, %Macros
emph=[7]{second, value, id, count, available},
emphstyle=[7]{\color{Peach!50!Purple}}, %Members
emph=[8]{OK, Bad, type_A, type_B},
emphstyle=[8]{\color{Blue}}, % Enum members
emph=[9]{nodiscard, maybe_unused, fallthrough},
emphstyle=[9]{\color{Goldenrod!50!black}}, %Attributes
emph=[10]{ns1, ns2, ns3},
emphstyle=[10]{\color{MediumSeaGreen}}, %Attributes
% Further functionality
autogobble=true, % lstautogobble needed!
}
\def\CPP{\lstinline[style=MyCpp, basicstyle=\ttfamily\color{black}]}
\lstnewenvironment{Cpp}[1][]
{\lstset{style=MyCpp, belowskip=-7mm, aboveskip=0pt,#1}}
{}
\makeatletter
\newenvironment{CenteredBox}{%
\begin{Sbox}}{% Save the content in a box
\end{Sbox}\centerline{\parbox{\wd\@Sbox}{\TheSbox}}}% And output it centered
\makeatother
% =====> Copied from https://raw.githubusercontent.com/AxelKrypton/Bash_lecture_2020/master/TeX/InitialMaterial/ListingsSetupSlides.tex
%Colors for listings
\colorlet{background-color}{gray!20}
\colorlet{basic-color}{black}
\colorlet{keywords-color}{Goldenrod}
\colorlet{comment-color}{red!95!black}
\colorlet{strings-color}{ForestGreen}
\colorlet{builtins-color}{MediumBlue!90!black}
\colorlet{functions-color}{NavyBlue}
\colorlet{variables-color}{DarkOrange}
\colorlet{environment-color}{Gray}
\colorlet{external-color}{SteelBlue}
% https://tex.stackexchange.com/a/34000
\makeatletter
\lst@Key{countblanklines}{true}[t]%
{\lstKV@SetIf{#1}\lst@ifcountblanklines}
\lst@AddToHook{OnEmptyLine}{%
\lst@ifnumberblanklines\else%
\lst@ifcountblanklines\else%
\advance\c@lstnumber-\@ne\relax%
\fi%
\fi}
\makeatother
\lstdefinestyle{MyBash}{
backgroundcolor=\color{background-color}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
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
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=single, % adds a frame around the code
framerule=0pt, % Width of the frame rule
framesep=3pt, % separation around text
linewidth=\textwidth, % defines the base line width for listings
xleftmargin=6mm, % Margin left
xrightmargin=6mm, % Margin right
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
numberblanklines=false, % suppress numbers on empty lines
countblanklines=false, % NOT standard! Avoid counting empty lines: https://tex.stackexchange.com/a/34000
numbersep=8pt, % how far the line-numbers are from the code
numberstyle=\tiny\color{black}, % the style that is used for the line-numbers
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
tabsize=2, % sets default tabsize to 2 spaces
title=\lstname, % show the filename of files included with \lstinputlisting; also try caption instead of title
%
%Base style for this presentation
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code
% (possibly needs columns=flexible)
language=bash,
basicstyle=\ttfamily\scriptsize\color{basic-color},
keywordstyle=\color{keywords-color},
stringstyle=\color{strings-color},
commentstyle=\color{comment-color},
morestring=[b][\color{strings-color}]{"},
morestring=[d][\color{strings-color}]{'},
moredelim=[is][\color{basic-color}]{|+}{+|}, % I will use this for terminal output
literate={`}{\textasciigrave}1, % https://tex.stackexchange.com/a/466224/128737
literate={~}{{\textasciitilde}}1,
% literate=% literate={<replace>}{<replacement text>}{<width>}
% {\#define}{{{\color{CarnationPink}\#define}}}{6}
% {\#include}{{{\color{CarnationPink}\#include}}}{7},
alsoletter=0123456789![]/\{\}.:+, % This to mark the symbols in keyword/emph[5] to be highlighted (otherkeywords does not work i.e. it highlights also in comments!) -> manual at page 45
morekeywords={if, then, else, elif, fi, case, esac, for, select, while, until, do, done, in, function, time, [[, ]], \{, \}, !, coproc}, %https://askubuntu.com/a/513712
emph=[1]{},
emphstyle=[1]{\color{functions-color}}, %Functions
emph=[2]{br},
emphstyle=[2]{\color{variables-color}}, %Variables
emph=[4]{PATH, SHELL, IFS, BASH_ALIASES, BASH_REMATCH, PS3, REPLY, HOME, LANGUAGE, EDITOR, PIPESTATUS, PWD, FUNCNEST,
DIRSTACK, PWD, OLDPWD, SHELLOPTS, BASHOPTS, TIMEFORMAT, COMP_CWORD, COMP_LINE, COMP_POINT, COMP_TYPE, COMP_KEY,
COMP_WORDBREAKS, COMP_WORDS, COMPREPLY, INPUTRC},
emphstyle=[4]{\color{environment-color}}, %Environment variables
emph=[5]{alias, bg, bind, break, builtin, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval,
exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, popd, printf, pushd, pwd,
read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, true, type, typeset, ulimit, umask,
% case, if, until, while % <--- these built-in are keywords and I leave them highlighted as such
unalias, unset, wait, :, ., [, ]},
emphstyle=[5]{\color{builtins-color}}, %Shell built-in
emph=[6]{man, apropos, ls, rm, g++, chmod, cp, awk, sed, cut, perl, args, date, grep, sleep, tput, seq, cat, wc, sort, uniq, tail,
head, sdiff, tar, mktemp, mkdir, ps, emacs, systemd, timeout, parallel, xargs, gnuplot, pdflatex, vi, ping, bash,
egrep, shuf, stat, find, fgrep, bc, tr, paste, expr, diff, touch, git},
emphstyle=[6]{\color{external-color}}, %(External) commands
emph=[7]{},
emphstyle=[7]{\color{variables-color}}, %Class for local variables (usually with bad names)
emph=[8]{},
emphstyle=[8]{\color{builtins-color}}, %Class for local commands (usually with bad names)
%
%Additional customizations
belowskip=-7mm,
aboveskip=3pt,
autogobble=true, % lstautogobble needed!
}
\lstnewenvironment{Bash}[1][]
{\lstset{style=MyBash, belowskip=-7mm, aboveskip=0pt,#1}}
{}