forked from CS234319/safot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyogi-code.sty
380 lines (332 loc) · 10.9 KB
/
yogi-code.sty
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{yogi-code}[2011/02/01 v0.3
Print out code excerpts in various programming languages
]
\RequirePackage{amstext}
\RequirePackage{times}
\RequirePackage{listings}
\RequirePackage{yogi-lines}
\providecommand\kk[1]{\textcolor{RoyalBlue}{\text{\textup{\textbf{\texttt{#1}}}}}}
\providecommand\cc[1]{\textcolor{Sepia}{\text{\textup{\textbf{\texttt{#1}}}}}}
\newcommand\@codedisplayspace{2pt}
\DeclareOption{terse}{}
\DeclareOption{verbose}{}
\newcommand\codesize\scriptsize
\DeclareOption{normalsize}{\renewcommand\codesize\normalsize}
\DeclareOption{small}{\renewcommand\codesize\small}
\DeclareOption{large}{\renewcommand\codesize\large}
\DeclareOption{Large}{\renewcommand\codesize\Large}
\DeclareOption{LARGE}{\renewcommand\codesize\LARGE}
\DeclareOption{huge}{\renewcommand\codesize\huge}
\DeclareOption{Huge}{\renewcommand\codesize\Huge}
\DeclareOption{scriptsize}{\renewcommand\codesize\scriptsize}
\DeclareOption{footnotesize}{\renewcommand\codesize\footnotesize}
\DeclareOption{tiny}{\renewcommand\codesize\tiny}
\DeclareOption{dense}{\renewcommand\@codedisplayspace{0pt}}
\newcommand\inlinesize{}
\ProcessOptions
\providecommand\ensureLR[1]{\ifdefined\LR\LR{#1}\else{#1}\fi}
\providecommand\ensureLTR{\ifdefined\setLTR\setLTR\fi}
\lstset{defaultdialect=[GNU]C++}
% These two macros are defined for quick and trouble free placement of short
% code and keywords of any programming language within the document.
\ifdefined\LR
\def\@LR#1{\LR{#1}}%
\else
\def\@LR#1{#1}%
\fi
\def\cd#1{\begingroup
\listingsfont
\inlinesize
\upshape
\@LR{#1}%
\endgroup
}
\newcommand\kw[1]{\cd{\textbf{#1}}}
% Begin with generating a general purpose code style. Use a mono-spaced font
% for everything but comments. Keywords are bold face, strings are in italics,
% while comments are in italics roman font. The escape character is back-quote.
\definecolor{stringColor}{rgb}{0.16,0.00,1.00}
\definecolor{annotationColor}{rgb}{0.39,0.39,0.39}
\definecolor{keywordColor}{rgb}{0.50,0.00,0.33}
\definecolor{commentColor}{rgb}{0.25,0.50,0.37}
\definecolor{javadocColor}{rgb}{0.25,0.37,0.75}
\definecolor{jTagColor}{rgb}{0.50,0.62,0.75}
\definecolor{eTagColor}{rgb}{0.50,0.62,0.75}
\definecolor{lineNumberColor}{rgb}{0.47,0.47,0.47}
\definecolor{darkblue}{rgb}{0.1,0.1,0.9}
\lstdefinestyle{code}{
basicstyle={\listingsfont\codesize},
stringstyle={\listingsfont\itshape\color{stringColor}\codesize},
commentstyle={\commentsfont\slshape\color{commentColor}\codesize},
keywordstyle={\listingsfont\bfseries\color{keywordColor}\codesize},
keywordstyle={[2]\listingsfont\bfseries\color{darkblue}\codesize},
showstringspaces=false,
backgroundcolor=\color{yellow!20},
frame=lines,
escapechar=¢,
}
\lstdefinestyle{inline}{
basicstyle={\listingsfont\inlinesize},
stringstyle={\listingsfont\itshape\inlinesize},
commentstyle={\commentsfont\slshape\inlinesize},
keywordstyle={\listingsfont\bfseries\inlinesize},
showstringspaces=false,
escapechar=⌘,
}
% Second general style for displayed code. Same as "code" style, but with
% minimal spacing around the displayed code
\lstdefinestyle{display}{
style=code,
columns={[c]fullflexible},
xleftmargin=1ex,
aboveskip=\@codedisplayspace,
belowskip=\@codedisplayspace,
}
% General style for numbered displayed code. Same as "display" style,
% but with minimal spacing for the numbering.
\lstdefinestyle{numbered}{
style=display,
numbers=left,
stepnumber=1,
numbersep=2pt,
xleftmargin=3ex,
numberblanklines=false,
numberstyle=\tiny\bf,
}
\lstdefinelanguage{Go}{
% Keywords as defined in the BNF
morekeywords=[1]{break,default,func,interface,%
case,defer,go,map,struct,chan,else,goto,package,%
switch,const,fallthrough,if,range,type,continue,%
for,import,return,var,select},
% Special identifiers, builtin functions
morekeywords=[2]{make,new,nil,len,cap,copy,cmplx,%
real,imag,panic,recover,print,println,iota,close,%
closed,_},
% Basic types
morekeywords=[3]{%
string,int,uint,uintptr,double,float,complex,byte,%
int8,int16,int32,int64,int128,%
uint8,uint16,uint32,uint64,uint128,%
float32,float64,complex64,complex128},
% Strings : "toto", 'toto', `toto`
morestring=[b]{"},
morestring=[b]{'},
morestring=[b]{`},
% Comments : /* comment */ and // comment
comment=[l]{//},
morecomment=[s]{/*}{*/},
% Options
sensitive=true
}
\lstdefinelanguage[JTL]{Java}[]{Java}%
{morekeywords={
name,Alias,
enum,strictfp,@interface, %%%% --- missing Java keywords
NULL,TYPE,MEMBER,STRING,PACKAGE,SCRATCH, %%%% --- kinds
TYPES,STRINGS,MEMBERS, %%%% --- lists
typename,membername, %%%% --- entry definitions
This,Result, %%%% --- variables
and,or,not, %%%% --- operators
is,equal,equals, %%%% --- builtin predicates
all,exist,exists,has,many,multiple,no,one,empty, %%%% --- quantifiers
optional,
partition,imply,implies,disjoint,supersetof, %%%% --- set operators
extends+,implements+,extends*,implements*, %%%% --- closure of \Java operators
% nothing,otherwise, %%%% --- Y.G., crazy
first,last,between, %%%% --- Iterators
},%
deletestring=[b]{'},
comment=[l]{--},
alsoletter={+*},
morecomment=[s][\codesize\sf]{\\[}{\\]},
stringstyle={\codesize\sf},
}
\lstdefinelanguage{kernel}{
language=Lisp,
keywords=[1]{atom,car,cdr,cond,cons,eq,error,eval,set},
keywords=[2]{quote,defun,lambda,nlambda,nil,t,null,ndefun},
}
\lstdefinelanguage{Go}{
% Keywords as defined in the BNF
morekeywords=[1]{break,default,func,interface,%
case,defer,go,map,struct,chan,else,goto,package,%
switch,const,fallthrough,if,range,type,continue,%
for,import,return,var,select},
% Special identifiers, builtin functions
morekeywords=[2]{make,new,nil,len,cap,copy,cmplx,%
real,imag,panic,recover,print,println,iota,close,%
closed,_},
% Basic types
morekeywords=[3]{%
string,int,uint,uintptr,double,float,complex,byte,%
int8,int16,int32,int64,int128,%
uint8,uint16,uint32,uint64,uint128,%
float32,float64,complex64,complex128},
% Strings : "toto", 'toto', `toto`
morestring=[b]{"},
morestring=[b]{'},
morestring=[b]{`},
% Comments : /* comment */ and // comment
comment=[l]{//},
morecomment=[s]{/*}{*/},
% Options
sensitive=true
}
% #1 Language name, as it is known to the listing package.
% #2 Changes to the language definition, as in the listing package
% #3 Name of the environment of the newly defined language.
% #4 Name of the command for inlining language code.
% #5 Name of the short version of the command for inlining language code.
\def\newLanguage#1#2#3#4#5{%
\lstnewenvironment{#3}[1][]{%
\pagebreak[3]%
\lstset{language=#1,style=display,##1}
\ensureLTR
}{\pagebreak[3]}%
\lstnewenvironment{#3n}[1][]{%
\ensureLTR\lstset{language=#1,style=display,style=numbered,##1}
}{}%
\lstnewenvironment{#3e}[1][]{%
\pagebreak[3]
\ensureLTR\lstset{language=#1,style=display,numbers=none,##1}}{\pagebreak[3]}%
\expandafter\newcommand\csname#4\endcsname[1]{%
\begingroup
\lstset{language=#1,style=inline}%
\LR{\lstinline/##1/}%
\endgroup
}
\expandafter\newcommand\csname#5\endcsname[1]{%
\begingroup
\lstset{language=#1,style=inline}%
\ensureLTR\lstinline!##1!%
\endgroup
}%
}
\lstdefinelanguage{Golang}{
% Keywords as defined in the BNF
morekeywords=[1]{break,default,func,interface,%
case,defer,go,map,struct,chan,else,goto,package,%
switch,const,fallthrough,if,range,type,continue,%
for,import,return,var,select},
sensitive=true,%
morecomment=[l]{//},%
morecomment=[s]{/*}{*/},%
morestring=[b]',%
morestring=[b]",%
morestring=[s]{`}{`},%
% Predefined constants
morekeywords=[2]{
true,
false,
nil,
_
},
% Predefined types
morekeywords=[3]{%
ComplexType,
FloatType,
IntegerType,
Type,
bool,
byte,
complex128,
complex64,
error,
float32,
float64,
int,
int16,
int32,
int64,
int8,
rune,
string,
uint,
uint16,
uint32,
uint64,
uint8,
uintptr,
},
% Predefined functions
morekeywords=[4]{%
append,
cap,
close,
complex,
copy,
delete,
imag,
len,
make,
new,
panic,
print,
println,
real,
recover,
},
% Strings : "toto", 'toto', `toto`
morestring=[b]{"},
morestring=[b]{'},
morestring=[b]{`},
% Comments : /* comment */ and // comment
comment=[l]{//},
morecomment=[s]{/*}{*/},
% Options
sensitive=true
}
%---- Concrete Common Languages (Sorted Alphabetically --------------
\newLanguage{Ada}{}{ADA}{ada}{adaShort}
\newLanguage{[AspectJ]Java}{morekeywords={remotecall,shakein,declare,precedence,parents}}{AJ}{aj}{ajx}
\newLanguage{AWK}{}{AWKPROG}{awk}{aw}
\newLanguage{}{}{BNF}{bnf}{bn}
\newLanguage{[GNU]C++}{directivestyle={\listingsfont\bfseries\codesize\color{olive}}}{CPP}{cpp}{cp}
\newLanguage{[Sharp]C}{morekeywords={select,in,from,where,var}}{CSHARP}{csharp}{csharpShort}
\newLanguage{Cobol}{}{COBOL}{cobol}{cobolShort}
\newLanguage{Python}{}{PYTHON}{python}{py}
\newLanguage{Go}{}{GO}{go}{gocd}
\newLanguage{}{}{DATALOG}{datalog}{dlog}
\newLanguage{Eiffel}{morekeywords={create,factory,note}}{EIFFEL}{eiffel}{eiff}
\newLanguage{kernel}{}{LISP}{lisp}{lsp}
\newLanguage{HTML}{alsoletter={-}}{HTML}{html}{htm}
\newLanguage{Java}{}{JAVA}{java}{ja}
\newLanguage{}{}{NONE}{none}{non}
\newLanguage{Oberon-2}{}{OBERON}{oberon}{ob}
\newLanguage{Pascal}{}{PASCAL}{pascal}{pas}
\newLanguage{XML}{alsoletter={-}}{XML}{xml}{xm}
\lstdefinestyle{SQL}{
language={SQL},
style=display,
morekeywords={REFERENCES},
}
%--------------- Java Dialects -------------------
\lstdefinestyle{AJ}{
style=numbered,
escapechar=¢
}
\lstdefinestyle{JTL}{
language={[JTL]Java},
style=code,
stringstyle={\codesize\sf},
escapechar=¢
}
\lstdefinestyle{JTLstring}{
language={},
basicstyle={\sf\codesize\color{Brown}},
xleftmargin=1ex,
aboveskip=2pt,belowskip=2pt,
}
% Macro \cpp is used for long inlined C++ code, i.e., inlined code which does
% not need a "~" before it. In contrast, macro \cp, which is identical to
% \cpp, should be used for shorter C++ text, as in, e.g., "variable~\cp{i}" as
% the example indicates, one should have a non-breaking space before \cp. This
% is easy to achieve with a global search and replace of " \cp{" to "~\cp{".
% Same for Java inlined code. \java is intended for the long version
\newcommand\sql[1]{\text{\lstinline[style=SQL]{#1}}}
\newcommand\jtlstr[1]{\text{\lstinline[style=JTLstring]{#1}}}
\lstnewenvironment{JTLstr}{\lstset{style=JTLstring}}{}
\lstnewenvironment{SQLprog}{\lstset{style=SQL}}{}
\lstnewenvironment{SQLe}{\lstset{style=SQL,numbers=none}}{}