-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsopra-listings.sty
724 lines (640 loc) · 33.2 KB
/
sopra-listings.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
% sopra-listings.sty
% Version: 1.1
% Author: Florian Sihler, 08.01.2021
% Will contain all the definitions to highlight listings in a document. Note:
% I've reused huge parts of the code I've written for sol@lst@family but ported
% them to be standalone. Furthermore This Package contains 'other' mechanisms.
% This Package doesn't work with the 'minted'-Package
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sopra-listings}[2021/01/08 EagleoutIce - listings for the sopra-team-020]
% Lengths and Registers
\newcounter{solversion} \setcounter{solversion}{1023}
% note this will be used with tcb:
\newdimen\sol@length@lst@outer@spacing \sol@length@lst@outer@spacing=3\p@
\newdimen\sol@length@lst@numsep \sol@length@lst@numsep=9\p@
\newdimen\sol@length@lst@famerule \sol@length@lst@famerule=.75\p@
\newdimen\sol@length@lst@xleftmargin \sol@length@lst@xleftmargin=3\p@
\newdimen\sol@length@lst@xrightmargin \sol@length@lst@xrightmargin=3\p@
\newif\ifsol@encoding@ % automatically load encoding packages
\newif\ifsol@accuspp@available@ % remove line numbers from selection if possible
\newif\ifsol@printmode@% in print, ink will be reduced, adapted to grayscale
\newif\ifsol@defaultlang@% if enabled, listings will try to load some langs
\newif\ifsol@cpalette@% if enabled, listings will adapt their colors according to the color-palettes package
\newif\ifsol@guardspace@% if enabled (default) it will ensure lines
\newif\ifsol@numinpar@% if enabled numbers would be outside of leftmarg
% number-highlighting
\newif\ifsol@highlight@numbers@ % should numbers be highlighted?
% internals:
\newif\ifsol@lst@lastwas@character@ % last segment was from char-class
\newif\ifsol@lst@lastwas@charkeep@ % in char-mode (pass through)
\newif\ifsol@lst@style@upshape@ % add upshape to basicstyle
\newif\ifsol@lst@style@highlights@ % add upshape to basicstyle
\newif\ifsol@lst@style@defaultfont@ % don't change font?
\sol@lst@style@defaultfont@true
\newif\ifsol@lst@style@inlinesize@ % don't change font?
\newif\ifsol@lst@fake@minted@
\newif\ifsol@lst@extended@numerals@
\newif\ifsol@debug@% typeout debug
% Package-Args
% Encoding:
\DeclareOption{encoding}{\sol@encoding@true}
\DeclareOption{noencoding}{\sol@encoding@false}
\sol@encoding@false
% Numbers:
\DeclareOption{hlnumbers}{\sol@highlight@numbers@true} % will only disable
\DeclareOption{nohlnumbers}{\sol@highlight@numbers@false} % auto - highlight
\sol@highlight@numbers@true
% Printmodes
\DeclareOption{defaultmode}{\sol@printmode@false}% probably shouldn't be used
\DeclareOption{print}{\sol@printmode@true}
% Auto-Language
\DeclareOption{loadlangs}{\sol@defaultlang@true}
\DeclareOption{noloadlangs}{\sol@defaultlang@false}
\sol@defaultlang@true
% Color-Palettes
\DeclareOption{cpalette}{\sol@cpalette@true}
\DeclareOption{nocpalette}{\sol@cpalette@false}
% upshape
\DeclareOption{upshape}{\sol@lst@style@upshape@true}
\DeclareOption{noupshape}{\sol@lst@style@upshape@false}
% guard
\DeclareOption{guardspace}{\sol@guardspace@true }
\DeclareOption{noguardspace}{\sol@guardspace@false }
\sol@guardspace@true
% numinpar
\DeclareOption{numinpar}{\sol@numinpar@true}
\DeclareOption{nonuminpar}{\sol@numinpar@false}
% numinpar
\DeclareOption{defaultfont}{\sol@lst@style@defaultfont@true}
\DeclareOption{nodefaultfont}{\sol@lst@style@defaultfont@false}
% inlinesize
\DeclareOption{inlinesize}{\sol@lst@style@inlinesize@true}
\DeclareOption{noinlinesize}{\sol@lst@style@inlinesize@false}
\sol@lst@style@inlinesize@true
\let\soladaptinline\sol@lst@style@inlinesize@true
\let\sollockinline\sol@lst@style@inlinesize@false
% highlights
\DeclareOption{highlights}{\sol@lst@style@highlights@true}
\DeclareOption{nohighlights}{\sol@lst@style@highlights@false}
% minted
\DeclareOption{fakeminted}{\sol@lst@fake@minted@true}
\DeclareOption{nofakeminted}{\sol@lst@fake@minted@false}
% extended numbers
\DeclareOption{extendednums}{\sol@lst@extended@numerals@true}
\DeclareOption{noextendednums}{\sol@lst@extended@numerals@false}
% debug
\DeclareOption{debug}{\sol@debug@true}
\DeclareOption{nodebug}{\sol@debug@false}
% if sob is loaded, the default for the printmode will be passed,
% otherwise we will use defaultmode as the default :D
\@ifundefined{ifsob@printmode@}{% not called from sopra-base-class, we use a
\sol@printmode@false
}{\ifsob@printmode@\global\sol@printmode@true\else\global\sol@printmode@false\fi}
\ProcessOptions\relax
\ifsol@debug@\let\sol@debug\typeout\else\let\sol@debug\@gobble\fi
% Basic Packages Encoding:
\ifsol@encoding@\RequirePackage[T1]{fontenc}\RequirePackage[utf8]{inputenc}\fi
\RequirePackage{etoolbox,xcolor,pgfkeys}
% Listings-Base:
\IfFileExists{listingsutf8.sty}{\RequirePackage{listingsutf8} }%
{\RequirePackage{listings}}
\IfFileExists{accsupp.sty}{\RequirePackage{accsupp} \sol@accuspp@available@true}%
{\sol@accuspp@available@false}%
\ifsol@accuspp@available@
\def\sol@lst@prebreak{\rlap{\BeginAccSupp{method=escape,ActualText={}}\sol@font@fs@numbers$\hookleftarrow$\EndAccSupp{}}} % allow definition of own symbol
\else
\def\sol@lst@prebreak{\rlap{\sol@font@fs@numbers$\hookleftarrow$}} % allow definition of own symbol
\fi
\let\sol@lst@inline@prebreak\sol@lst@prebreak
\ifsol@guardspace@\RequirePackage{needspace}\fi
\ifsol@lst@style@highlights@\RequirePackage{tikz}\fi
% Font Definitions
\ifsol@lst@style@defaultfont@
\AtEndPreamble{\RequirePackage{AnonymousPro}}%
\def\ttdefault{AnonymousPro}\fi
\let\sol@ttfamily\ttfamily \def\T{\texttt}
\def\sol@font@fs@numbers{\footnotesize}
\def\solNumFs#1{\gdef\sol@font@fs@numbers{#1}}
\def\sol@font@fs@normal{}
% \sol@font@size
\newcommand*\lstfs[1][1]{\@ifstar{\@lstfs{#1}{\sol@font@size}}{\@lstfs{#1}}}
\def\@lstfs#1#2{%
\def\sol@font@fs@normal{\fontsize{#2}{#2}\linespread{#1}\selectfont}%
\ifnum#2>7\protected@edef\sol@lst@@subfs{\the\numexpr #2-4}\def\sol@font@fs@numbers{\fontsize\sol@lst@@subfs\sol@lst@@subfs\linespread{#1}\selectfont}%
\else\def\sol@font@fs@numbers{\tiny\linespread{#1}}\fi
}
% Color & Style Definitions
\ifsol@printmode@
\definecolor{sol@colors@border}{HTML}{DDDFE2}
\definecolor{sol@colors@background}{HTML}{FFFFFF}% save ink :D
\else
\definecolor{sol@colors@border}{HTML}{EAECF0}
\definecolor{sol@colors@background}{HTML}{FCFBFB}
\fi
\@ifundefined{thesobversion}{% not called from sopra-base-class, we use a
% default palette
\colorlet{sol@colors@lst@keywordA}{purple} % e.g.: class, public, static...
\colorlet{sol@colors@lst@keywordB}{purple!75!white} % e.g.: int, double ...
\colorlet{sol@colors@lst@keywordC}{purple!90!black} % e.g.: class-names?
\colorlet{sol@colors@lst@numbers}{teal} % well, numbers
\colorlet{sol@colors@lst@literals}{orange!90!brown} % well, numbers
\colorlet{sol@colors@lst@comments}{lightgray!65!gray} % well, comments
\colorlet{sol@colors@lst@highlight}{lime} % sweetspots
\colorlet{sol@colors@lst@command}{sol@colors@lst@keywordB} % sweetspots
}{% we will use the secondary/akzent color as default and choose matching colors
\colorlet{sol@colors@lst@keywordA}{sob@col@uulm@cs} % Examples as above
\colorlet{sol@colors@lst@keywordB}{sob@col@uulm@cs!75!white}
\colorlet{sol@colors@lst@keywordC}{sob@col@uulm@cs!20!gray}
\colorlet{sol@colors@lst@numbers}{teal!60!gray}
\colorlet{sol@colors@lst@literals}{sob@col@uulm!90!blue}
\colorlet{sol@colors@lst@comments}{lightgray!65!darkgray}
\colorlet{sol@colors@lst@highlight}{purple}
\colorlet{sol@colors@lst@command}{sol@colors@lst@keywordB}
}
\colorlet{sol@colors@lst@linenumbers}{gray}
% define the styling definitions
% as we don't know, if 'foreach' is available, we will built our own iter:
\def\sol@lst@style@iter@step#1: #2\@nil{%
\ifx!#1!\else
\expandafter\def\csname#1\endcsname{#2}%
\fi}
\def\sol@lst@style@iter#1,#2\@nil{%
\ifx!#1!\else
\sol@lst@style@iter@step sol@styles@lst@#1\@nil
\ifx!#2!\else\sol@lst@style@iter#2,\@nil\fi\fi}
\def\solSetStyle#1#2{\expandafter\def\csname sol@styles@lst@#1\endcsname{#2}}
\def\sol@list@define@styles#1{\sol@lst@style@iter#1,\@nil}
\let\SolDefineStyles\sol@list@define@styles
% we will write the colors anyway. This way it is easy visible on how to change the
% styles. Will define e.g. \sol@styles@lst@keywo
\ifsol@printmode@
\sol@list@define@styles{%
{keywordA: \@declaredcolor{sol@colors@lst@keywordA}\bfseries},%
{keywordB: \@declaredcolor{sol@colors@lst@keywordB}},%
{keywordC: \@declaredcolor{sol@colors@lst@keywordC}},%
{keywordD: \itshape},%
{numbers: \@declaredcolor{sol@colors@lst@numbers}\itshape},%
{literals: \@declaredcolor{sol@colors@lst@literals}\itshape},%
{comments: \@declaredcolor{sol@colors@lst@comments}},% \scshape
{basic: \sol@ttfamily},%
{command: \@declaredcolor{sol@colors@lst@command}},%
{highlight: \@declaredcolor{sol@colors@lst@highlight}\itshape},%
{linenumbers: \@declaredcolor{sol@colors@lst@linenumbers}\sol@font@fs@numbers\sffamily}%
}
\else
\sol@list@define@styles{%
{keywordA: \@declaredcolor{sol@colors@lst@keywordA}},%
{keywordB: \@declaredcolor{sol@colors@lst@keywordB}},%
{keywordC: \@declaredcolor{sol@colors@lst@keywordC}},%
{keywordD: \itshape},%
{numbers: \@declaredcolor{sol@colors@lst@numbers}},%
{literals: \@declaredcolor{sol@colors@lst@literals}},%
{comments: \@declaredcolor{sol@colors@lst@comments}},%
{basic: \sol@ttfamily},%
{command: \@declaredcolor{sol@colors@lst@command}},%
{linenumbers: \@declaredcolor{sol@colors@lst@linenumbers}\sol@font@fs@numbers\sffamily},%
{highlight: \@declaredcolor{sol@colors@lst@highlight}\itshape}%
}
\fi
\ifsol@lst@style@upshape@
\sol@list@define@styles{{basic: \sol@ttfamily\upshape},}
\fi
% Helper Functions
\def\sol@font@size{\dimexpr\f@size\p@\relax}
\def\sol@thesolversion#1#2#3#4\@nil{v#1.#2.#3#4}
\protected@edef\sol@version@str{\noexpand\sol@thesolversion\arabic{solversion}\noexpand\@nil}
\protected@edef\thesolversion{\sol@version@str}
% We want language specific literate additions:
\def\sol@lst@addToLiterate#1{\protected@edef\lst@literate{\unexpanded\expandafter{\lst@literate}\unexpanded{#1}}}
\lst@Key{add to literate}{}{\sol@lst@addToLiterate{#1}}
% If possible we want to make the line numbers unmarkable, so you can copy
% code without selecting them:
% locally blacklist some numbers
\newif\if@sol@lst@blacklist@is@ghost@
\let\solblacklistisghost\@sol@lst@blacklist@is@ghost@true
\let\solblacklistispresent\@sol@lst@blacklist@is@ghost@false
\def\solblacklistlinenumbers{\@ifstar{\solblacklistispresent\@sol@lst@blacklistlinenumers}{\solblacklistisghost\@sol@lst@blacklistlinenumers}}
\def\@sol@lst@blacklistlinenumers#1{\@for\@num:={#1}\do{\expandafter\let\csname sol@lst@nl@blacklist@\@num\endcsname\@empty}}
% TODO: support for non-integer line markers by not adding stuff if ispresent is true?
% we have to keep a different offset for blacklisted and ghost line numbers
% 1. we must keep ranges intact and
% 2. otherwise the line to be blacklisted would repeat
\newcount\c@sol@lst@blacklisted@linenum@counter
\lst@AddToHook{PreInit}{\c@sol@lst@blacklisted@linenum@counter\z@}
\ifsol@accuspp@available@
\def\sol@lst@num@consume#1{\@ifundefined{sol@lst@nl@blacklist@#1}{\BeginAccSupp{method=escape,ActualText={}}\the\numexpr#1+\c@sol@lst@blacklisted@linenum@counter\EndAccSupp{}}{\if@sol@lst@blacklist@is@ghost@\global\advance\c@sol@lst@blacklisted@linenum@counter\m@ne\fi}}
\else\def\sol@lst@num@consume#1{\@ifundefined{sol@lst@nl@blacklist@#1}{\the\numexpr#1+\c@sol@lst@blacklisted@linenum@counter}{\if@sol@lst@blacklist@is@ghost@\global\advance\c@sol@lst@blacklisted@linenum@counter\m@ne\fi}}
\fi
% So if possible we will eat the number and produce unmarkable text
% Here we will make a small rainbow to present the selected color-theme :D
\def\sol@lst@showstyles@iter#1,#2\@nil{%
\ifx!#1!\else
{\sol@style@get{#1}#1\space}%
\ifx!#2!\else\sol@lst@showstyles@iter#2,\@nil\fi% recursion
\fi
}
\def\sol@lst@showstyles#1{\sol@lst@showstyles@iter#1,\@nil}
\def\solStyles{\sol@lst@showstyles{basic,keywordA,keywordB,keywordC,keywordD,numbers,linenumbers,literals,comments,highlight}}
\def\sol@style@get#1{\sol@styles@lst@basic\csname sol@styles@lst@#1\endcsname}
\long\def\solGet#1#2{\begingroup\solGetStyle{#1}#2\endgroup}
\let\solGetStyle\sol@style@get
\def\solSetLeftMargin#1{\setlength{\sol@length@lst@xleftmargin}{#1}}
\def\solSetRightMargin#1{\setlength{\sol@length@lst@xrightmargin}{#1}}
\def\solSetNumSep#1{\setlength{\sol@length@lst@numsep}{#1}}
\def\solSetFrameRule#1{\setlength{\sol@length@lst@famerule}{#1}}
\def\solPreBreak#1{\def\sol@lst@prebreak{#1}}
\def\solInlinePreBreak#1{\def\sol@lst@inline@prebreak{#1}}
\def\@@sol@numinpar@length{2em}
\ifsol@numinpar@\solSetLeftMargin{\@@sol@numinpar@length}\fi
% Handling of automated number-highlighting in listings;
\def\sol@@lst@hl@digit#1{\begingroup
\ifsol@lst@lastwas@character@
\global\sol@lst@lastwas@charkeep@true#1\else\global\sol@lst@lastwas@charkeep@false
\ifnum\lst@mode=\lst@Pmode\relax% PMode: Not in any special Mode
{\sol@style@get{numbers}#1}% or if keywords are active:
\else\lst@ifkeywords{\sol@style@get{numbers}#1}\else#1\fi\fi
\fi
\endgroup}
\ifsol@highlight@numbers@\let\sol@dgt\sol@@lst@hl@digit
\else\def\sol@dgt#1{#1}\fi
% ^--- shorter and better to read
\def\soldisablenumhl{\def\sol@dgt##1{##1}}
\def\solenablenumhl{\let\sol@dgt\sol@@lst@hl@digit}
% overwrite processor routines to adapt to number
\def\lst@ProcessLetter{%
\lst@whitespacefalse\sol@lst@lastwas@character@true\lst@AppendLetter}
\def\lst@ProcessOther{%
\lst@whitespacefalse\sol@lst@lastwas@charkeep@false\sol@lst@lastwas@character@false\lst@AppendOther}
\def\lst@whitespacetrue{\ifsol@lst@lastwas@charkeep@\sol@lst@lastwas@charkeep@false\sol@lst@lastwas@character@false\else\sol@lst@lastwas@character@false\fi\global\let\lst@ifwhitespace\iftrue}
\def\lst@whitespacefalse{\global\let\lst@ifwhitespace\iffalse}
\def\sol@nc{\ifsol@lst@lastwas@charkeep@\else\sol@lst@lastwas@character@false\fi}
% modify lst-literate routine to apply to the mechanism
\def\lst@Literate#1#2#3{%
\ifx\relax#2\@empty\else
\lst@CArgX #1\relax\lst@CDef\relax
{\let\lst@next\@empty
\lst@ifxliterate
\lst@ifmode\let\lst@next\lst@CArgEmpty\fi
\fi\ifx\lst@next\@empty
\ifx\lst@OutputBox\@gobble\else
\lst@XPrintToken \let\lst@scanmode\lst@scan@m
\lst@token{#2}\lst@length#3\relax
\lst@XPrintToken
\lst@whitespacefalse\sol@nc
\fi
\let\lst@next\lst@CArgEmptyGobble
\fi\lst@next}%
\@empty% splitter for constants
\expandafter\lst@Literate
\fi}
% The basic literate table
\def\SolSetLiterateTable{%
\lstset{add to literate=%
{Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1
{ù}{{\`u}}1 {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1 {ä}{{\"a}}1
{ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1 {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1
{Ö}{{\"O}}1 {Ü}{{\"U}}1 {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
{æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1 {ø}{{\o}}1 {€}{{\texteuro}}1 {£}{{\pounds}}1
{:bs:}{{\@declaredcolor{sol@colors@lst@keywordA}\textbackslash\normalcolor}}1 {:bmath:}{{\sol@style@get{numbers}\$\normalcolor}}1 {:percent:}{{\%}}1
{:emath:}{{{\sol@style@get{numbers}\$\normalcolor}}}1 {:dollar:}{{{\sol@style@get{numbers}\$\normalcolor}}}1 {:plaindollar:}{{\$}}1%spaces
% brace fix
{:space:}{{{ }}}1 {:ws:}{{{ }}}1 {:cdots:}{{{$\cdots$}}}1 {:cdot:}{{{$\cdot$}}}1 {:ldots:}{{{\ldots}}}1 {:circ:}{{{\ensuremath{\circ}}}}1 {:!:}{{!}}1
{:c:}{{{}}}0 {:star:}{{*}}1 {:minus:}{{-}}1
{:float:}{{{\sol@style@get{numbers}f\normalcolor}}}1 {:exp:}{{{\sol@style@get{numbers}e\normalcolor}}}1 {:yields:}{{{$\rightarrow$}}}1%
{:lan:}{{{$\langle$\thinspace}}}1 {:ran:}{{{\thinspace$\rangle$}}}1 {:to:}{{{$\to$}}}2 {:equiv:}{{{$\equiv$}}}1%
{:bcmd:}{\@declaredcolor{sol@colors@lst@keywordA}\textbackslash\normalcolor}1 {:ecmd:}{\normalcolor}0
{0}{{\sol@dgt{0}}}1
{1}{{\sol@dgt{1}}}1 {2}{{\sol@dgt{2}}}1 {3}{{\sol@dgt{3}}}1
{4}{{\sol@dgt{4}}}1 {5}{{\sol@dgt{5}}}1 {6}{{\sol@dgt{6}}}1
{7}{{\sol@dgt{7}}}1 {8}{{\sol@dgt{8}}}1 {9}{{\sol@dgt{9}}}1
{.0}{{\sol@dgt{.0}}}2
{.1}{{\sol@dgt{.1}}}2 {.2}{{\sol@dgt{.2}}}2 {.3}{{\sol@dgt{.3}}}2
{.4}{{\sol@dgt{.4}}}2 {.5}{{\sol@dgt{.5}}}2 {.6}{{\sol@dgt{.6}}}2
{.7}{{\sol@dgt{.7}}}2 {.8}{{\sol@dgt{.8}}}2 {.9}{{\sol@dgt{.9}}}2
{:lmath:}{{\textcolor{sol@colors@lst@numbers}{\textbackslash(}}}2 {:rmath:}{{\textcolor{sol@colors@lst@numbers}{\textbackslash)}}}2 {:ldmath:}{{\textcolor{sol@colors@lst@numbers}{\textbackslash[}}}2 {:rdmath:}{{\textcolor{sol@colors@lst@numbers}{\textbackslash]}}}2 {:ul:}{{\_}}1}
}
\ifsol@lst@extended@numerals@
\def\sol@lst@Ox{\textcolor{gray}{0x}} \def\sol@lst@Ob{\textcolor{gray}{0b}} \def\sol@lst@Oo{\textcolor{gray}{0o}}
\lstset{add to literate={_0}{{\sol@dgt{\textunderscore0}}}2 {_1}{{\sol@dgt{\textunderscore1}}}2 {_2}{{\sol@dgt{\textunderscore2}}}2 {_3}{{\sol@dgt{\textunderscore3}}}2
{_4}{{\sol@dgt{\textunderscore4}}}2 {_5}{{\sol@dgt{\textunderscore5}}}2 {_6}{{\sol@dgt{\textunderscore6}}}2
{_7}{{\sol@dgt{\textunderscore7}}}2 {_8}{{\sol@dgt{\textunderscore8}}}2 {_9}{{\sol@dgt{\textunderscore9}}}2
% TODO: hexa toggle
{0x0}{{\sol@lst@Ox\sol@dgt{0}}}3
{0x1}{{\sol@lst@Ox\sol@dgt{1}}}3 {0x2}{{\sol@lst@Ox\sol@dgt{2}}}3 {0x3}{{\sol@lst@Ox\sol@dgt{3}}}3
{0x4}{{\sol@lst@Ox\sol@dgt{4}}}3 {0x5}{{\sol@lst@Ox\sol@dgt{5}}}3 {0x6}{{\sol@lst@Ox\sol@dgt{6}}}3
{0x6}{{\sol@lst@Ox\sol@dgt{7}}}3 {0x8}{{\sol@lst@Ox\sol@dgt{8}}}3 {0x9}{{\sol@lst@Ox\sol@dgt{9}}}3
{0b0}{{\sol@lst@Ob\sol@dgt{0}}}3 {0b1}{{\sol@lst@Ob\sol@dgt{1}}}3
{0o0}{{\sol@lst@Oo\sol@dgt{0}}}3
{0o1}{{\sol@lst@Oo\sol@dgt{1}}}3 {0o2}{{\sol@lst@Oo\sol@dgt{2}}}3 {0o3}{{\sol@lst@Oo\sol@dgt{3}}}3
{0o4}{{\sol@lst@Oo\sol@dgt{4}}}3 {0o5}{{\sol@lst@Oo\sol@dgt{5}}}3 {0o6}{{\sol@lst@Oo\sol@dgt{6}}}3
{0o6}{{\sol@lst@Oo\sol@dgt{7}}}3
}
\fi
\SolSetLiterateTable
% Basic and internal highlighting definitions
% please note, that they will apply under every condition!
\newif\if@lst@within@inline@
\newcommand*\sol@dlst@default[2][]{%
\begingroup\fboxsep=\z@\fcolorbox{sol@colors@border}{sol@colors@background}{%
\ifsol@lst@style@inlinesize@\@lst@within@inline@true\fi\thinspace\strut\lstinline[prebreak=\sol@lst@inline@prebreak,#1,keepspaces=true,breakatwhitespace,]`#2`\thinspace
}\endgroup}
\newcommand*\sol@dlst@blank[2][]{%
\begingroup\thinspace\ifsol@lst@style@inlinesize@\@lst@within@inline@true\fi\lstinline[prebreak=\sol@lst@inline@prebreak,#1,keepspaces=true,breakatwhitespace]`#2`\endgroup}
\newcommand*\sol@dlst@input[2][]{\begingroup\ifsol@lst@style@inlinesize@\@lst@within@inline@true\fi\lstinputlisting[#1]{#2}\endgroup}
% the defaults come second to overwrite the "ultimate"/global defaults passed in ##1 :D
\def\SolSetInputDefaults#1{\renewcommand*\sol@dlst@input[2][]{\begingroup\ifsol@lst@style@inlinesize@\@lst@within@inline@true\fi\lstinputlisting[##1,#1]{##2}\endgroup}}
\def\SolRemoveInputBackground{\SolSetInputDefaults{frame=none,%
rulecolor={},backgroundcolor={}}}
% Lst styles that will be shipped in each case
\lstdefinestyle{sol@nonum}{xleftmargin=3\p@,xrightmargin=3\p@,%will fix some overhead :D
numbers=none,numbersep=\z@}
% Basic - we-work-in-the-back-hey-bud-environments
% note that '\sol@lst@backcol' is optional and could be ignored by the
% used style
\lstnewenvironment{lstplain}[1][]
{\def\sol@lst@backcol{white}\lstset{xleftmargin=\z@,xrightmargin=\z@,%
numbers=none,numbersep=\z@,frame=none,rulecolor={},backgroundcolor={},#1}}
{\def\sol@lst@backcol{MudWhite}}
\lstnewenvironment{lstnonum}[1][]{\lstset{style=sol@nonum,#1}}{}
% Here we will handle the language-control - right now, tcb will not be used
% for cleaner setup, we will use pgfkeys
\gdef\solset#1{\pgfkeys{/sol@lst@family/.cd,#1}}
% Here we define globals, which are basically applied to every listing - like for example the initial style
\pgfkeys{/sol@lst@family/globals/.cd,listing style/.initial={sol@SOPRA}}
% Just to provide a clearer structure the keys will be defined seperate for all different styles.
\pgfkeys{/sol@lst@family/default/.cd,
listing style/.initial = {\pgfkeysvalueof{/sol@lst@family/globals/listing style}},
command name prefix/.initial={},command name suffix/.initial={},%
constructor command/.initial={sol@NewLstEnvCore},
/sol@lst@family/nonumber/.cd,
listing style/.initial = {\pgfkeysvalueof{/sol@lst@family/globals/listing style}},
command name prefix/.initial={},command name suffix/.initial={*},%
constructor command/.initial={sol@NewLstEnvCoreStarred},
/sol@lst@family/plain/.cd,
listing style/.initial = {\pgfkeysvalueof{/sol@lst@family/globals/listing style},xleftmargin=\z@,xrightmargin=\z@,numbers=none,numbersep=\z@,frame=none,%
rulecolor={},backgroundcolor={}},
command name prefix/.initial={plain},command name suffix/.initial={},%
constructor command/.initial={sol@NewLstEnvPlain},
/sol@lst@family/plain number/.cd,
listing style/.initial = {\pgfkeysvalueof{/sol@lst@family/globals/listing style},%
xrightmargin=\z@,xleftmargin=\z@,frame=none,rulecolor={},backgroundcolor={}},
command name prefix/.initial={plain},command name suffix/.initial={},%
constructor command/.initial={sol@NewLstEnvPlain}}
% Inlines
\pgfkeys{/sol@lst@family/inline default/.cd,
listing style/.initial = {\pgfkeysvalueof{/sol@lst@family/globals/listing style}},
command name prefix/.initial={c},command name suffix/.initial={},
draw command/.initial={sol@dlst@default}}
\pgfkeys{/sol@lst@family/inline blank/.cd,
listing style/.initial = {\pgfkeysvalueof{/sol@lst@family/globals/listing style}},
command name prefix/.initial={b},command name suffix/.initial={},
draw command/.initial={sol@dlst@blank}}
\pgfkeys{/sol@lst@family/inline input/.cd,
listing style/.initial = {\pgfkeysvalueof{/sol@lst@family/globals/listing style}},
command name prefix/.initial={i},command name suffix/.initial={},
draw command/.initial={sol@dlst@input}}
% Language-Registration-Helper
% spacing control
\def\sol@ensure#1{\needspace{#1\baselineskip}}
\def\solguard#1{\gdef\@sol@guard@default{#1}}
\solguard{.8}
\def\sol@guardspace{\ifsol@guardspace@\sol@ensure{\@sol@guard@default}\fi}
% on line:
\lst@AddToHook{PreInit}{\if@lst@within@inline@\else\sol@font@fs@normal\fi}
% we want to allow to overwrite existing envs
\def\lst@allow@redefinition#1{%
\ifcsname #1\endcsname
\PackageWarning{sopra-listings}{Environment '#1' already defined, overwriting it!}%
\expandafter\let\csname#1\endcsname\relax
\expandafter\let\csname end#1\endcsname\relax
\fi
}
% #1 Name #2 Key #3 In Extra #4 Out Extra #5 Language
\def\sol@NewLstEnvCore#1#2#3#4#5{%
\lstnewenvironment{#1}[1][]{#3\lstset{##1}\sol@guardspace}{#4}%
}
% #1 Name #2 Key #3 In Extra #4 Out Extra #5 Language
\def\sol@NewLstEnvCoreStarred#1#2#3#4#5{%
\lstnewenvironment{#1}[1][]{#3\lstset{style=sol@nonum,##1}\sol@guardspace}{#4}%
}
% #1 Name #2 Key #3 In Extra #4 Out Extra #5 Language
\def\sol@NewLstEnvPlain#1#2#3#4#5{%
\lstnewenvironment{#1}[1][]{#3\lstset{##1}\sol@guardspace}{#4}%
}
% #1 Name #2 Key #3 In Extra #4 Out Extra #5 Language
% NOTE: currently no opt arg, as \@ifnextchar breaks scanning of lst@next
\def\sol@NewLstEnvPresent#1#2#3#4#5{%
\expandafter\xdef\csname#1\endcsname{\noexpand\leavevmode\noexpand\presentlst{#5}}%
\expandafter\gdef\csname end#1\endcsname{\endpresentlst}%
}
% #1 KeyName, #2 LanguageName, #3 EnvironName
\def\sol@@NewLstEnv#1#2#3{%
\begingroup
\lst@allow@redefinition{#3}%
\lst@allow@redefinition{#3@}% lstlistings wrap
\protected@edef\sol@xcurlst{\expandafter\noexpand\csname\pgfkeysvalueof{/sol@lst@family/\environName/constructor command}\endcsname{#3}{#1}{\noexpand\lstset{style=\pgfkeysvalueof{/sol@lst@family/\environName/listing style},language=#2}}{}{#2}}%
\global\sol@xcurlst\endgroup
}
% The colossos: core registration handler
% #1 list of aliases
% #2: Name of the Language [java,latex]
% #3: Name of the corresponding lst-Language [lJava, lLatex,...]
\newcommand*\RegisterLanguage[3][]{\begingroup\makeatletter
\ifsol@lst@fake@minted@\protected@edef\@tmp{#1}\ifx\@tmp\@empty
% register a mapping
\expandafter\gdef\csname sol@@minted@#2\endcsname{#3}%
\else
% register all aliases instead
\@for\@alias:=\@tmp\do{\expandafter\gdef\csname sol@@minted@\@alias\endcsname{#3}}%
\fi\fi
% Register the Environments
\def\sol@foreach@basic@env@iter##1,##2\@nil{%
\ifx!##1!\else
\def\environName{##1}%
\protected@edef\environCurName{\pgfkeysvalueof{/sol@lst@family/\environName/command name prefix}#2\pgfkeysvalueof{/sol@lst@family/\environName/command name suffix}}% assign
\sol@debug{> #2/#3 e '##1' (name: \environCurName, ctor: \pgfkeysvalueof{/sol@lst@family/\environName/constructor command})}%
\protected@edef\sol@CreateAnLstEnviron{\noexpand\sol@@NewLstEnv{\environName}{#3}{\environCurName}}% fully expand the Name, otherwise it would be undefined when the environment gets used
\sol@CreateAnLstEnviron
\ifx!##2!\else\sol@foreach@basic@env@iter##2,\@nil\fi
\fi}
\def\sol@foreach@basic@env##1{\sol@foreach@basic@env@iter##1,\@nil}
\sol@foreach@basic@env{default,nonumber,plain}%,presentation}
% This procedure can be used in persistence to iterate over the pgf-keys
% Register 'inline default'
\def\sol@foreach@inline@env@iter##1,##2\@nil{%
\ifx!##1!\else
\def\inlineName{##1}%
\protected@edef\inlineCurName{\pgfkeysvalueof{/sol@lst@family/inline \inlineName/command name prefix}#2\pgfkeysvalueof{/sol@lst@family/inline \inlineName/command name suffix}}% assign
\sol@debug{> #2/#3 i '\inlineName' (cmd: \inlineCurName, sty: \pgfkeysvalueof{/sol@lst@family/inline \inlineName/listing style}, d: \pgfkeysvalueof{/sol@lst@family/inline \inlineName/draw command})}%
% We will construct those with optional arguments, to give the user a chance to pass optional Arguments :D
% luckily we can construct the main Argument without any expansion problems :D
\expandafter\xdef\csname\inlineCurName\endcsname{\noexpand\protect\noexpand\@ifnextchar[{\noexpand\protect\expandafter\noexpand\csname @@hasopt@@\inlineCurName\endcsname}{\noexpand\protect\expandafter\noexpand\csname @@noopt@@\inlineCurName\endcsname}}%
% Variant without optionals :D
\expandafter\xdef\csname @@noopt@@\inlineCurName\endcsname####1{\noexpand\protect\expandafter\noexpand\csname\pgfkeysvalueof{/sol@lst@family/inline \inlineName/draw command}\endcsname[style=\pgfkeysvalueof{/sol@lst@family/inline \inlineName/listing style},language=#3]{####1}}%
\expandafter\xdef\csname @@hasopt@@\inlineCurName\endcsname[####1]####2{\noexpand\protect\expandafter\noexpand\csname\pgfkeysvalueof{/sol@lst@family/inline \inlineName/draw command}\endcsname[style=\pgfkeysvalueof{/sol@lst@family/inline \inlineName/listing style},language=#3,####1]{####2}}%
\expandafter\robustify\csname\inlineCurName\endcsname% robustify
\ifx!##2!\else\sol@foreach@inline@env@iter##2,\@nil\fi
\fi}%
\def\sol@foreach@inline@env##1{\sol@foreach@inline@env@iter##1,\@nil}
\sol@foreach@inline@env{default,blank,input}%,present}
% END: Register Language as present, by definig a command
\endgroup}
% The [hopefully] beautiful 'sopra-style'
\lstdefinestyle{sol@SOPRA}{%
% background and border, the frame
frame = single,framerule = \sol@length@lst@famerule,
lineskip = 0pt,
rulecolor = \@declaredcolor{sol@colors@border},
backgroundcolor = \@declaredcolor{sol@colors@background},
xleftmargin = \sol@length@lst@xleftmargin,
xrightmargin = \sol@length@lst@xrightmargin,
% the 'key'-styles:
stringstyle = \sol@styles@lst@basic\sol@styles@lst@literals,
commentstyle = \sol@styles@lst@basic\sol@styles@lst@comments,
keywordstyle = \sol@styles@lst@basic\sol@styles@lst@keywordA,
keywordstyle = [2]{\sol@styles@lst@basic\sol@styles@lst@keywordB},
keywordstyle = [3]{\sol@styles@lst@basic\sol@styles@lst@keywordC},
keywordstyle = [4]{\sol@styles@lst@basic\sol@styles@lst@keywordD},
basicstyle = \sol@styles@lst@basic,
% line numbers:
numbers = left, numbersep = \sol@length@lst@numsep,
numberstyle = \sol@styles@lst@basic\sol@styles@lst@linenumbers\sol@lst@num@consume,
% line break:
breaklines = true, extendedchars = true,
prebreak = \sol@lst@prebreak,
% escapes:
escapeinside = {!*}{*!},
% space control
keepspaces=false}
% Always present 'void'-Language
\lstdefinelanguage{lVoid}{columns=fixed,moredelim=[is][{}]{|plain|}{|plain|},moredelim=[is][\solGet{highlight}]{|ihl|}{|ihl|}}
\RegisterLanguage{void}{lVoid}
% Now we will define some languages
\def\solLanguageSearchPath{{Languages/}}
% a language will be loaded by the default latex-file mechanis
% the file has to have the signature: 'language_<Name>.cfg'
\def\sol@LoadLanguage@searchPath@iter#1,#2\@nil{%
\ifx!#1!\else
\InputIfFileExists{#1language_\[email protected]}{%
\sol@debug{Loaded '\sol@curlanginputfile' from '#1language_\[email protected]'}
}{\ifx!#2!\else\sol@LoadLanguage@iter#2,\@nil\fi}\fi
}
\def\sol@LoadLanguage@searchPath@resolve%
{% empty-case
\InputIfFileExists{language_\[email protected]}{
\sol@debug{Loaded '\sol@curlanginputfile' (language_\[email protected])}
}{\expandafter\sol@LoadLanguage@searchPath@iter\solLanguageSearchPath,\@nil}}
\def\sol@LoadLanguage@single#1\@nil{\def\sol@curlanginputfile{#1}\sol@LoadLanguage@searchPath@resolve{}}
\def\sol@LoadLanguage@iter#1,#2\@nil{%
\ifx!#1!\else\sol@LoadLanguage@single#1\@nil
\ifx!#2!\else\sol@LoadLanguage@iter#2,\@nil
\fi\fi
}
\def\sol@LoadLanguage#1{\sol@LoadLanguage@iter#1,\@nil}
\let\solLoadLanguage\sol@LoadLanguage
% we also want to make it possible to add a folder to the lang-path:
\ifsol@defaultlang@ \solLoadLanguage{java}\fi
% Change colors
\let\sol@registered@colors@keywordA\@empty \let\sol@registered@colors@keywordB\@empty
\let\sol@registered@colors@keywordC\@empty \let\sol@registered@colors@numbers\@empty
\let\sol@registered@colors@literals\@empty \let\sol@registered@colors@comments\@empty
\let\sol@registered@colors@highlight\@empty \let\sol@registered@colors@command\@empty
\let\sol@registered@colors@linenumbers\@empty
% #1 color name #2 color
\newcommand*\lstcolorlet[2]{%
\@ifundefined{sol@registered@colors@#1}{%
\PackageError{sopra-listings}{The color '#1' is undefined.}%
{Choose one of 'keywordA,keywordB,keywordC,numbers,literals,comments,highlight,command'}%
}{\colorlet{sol@colors@lst@#1}{#2}}%
}
% #1 color mode #2 color name #3 color
\newcommand*\lstcolordef[3][RGB]{%
\@ifundefined{sol@registered@colors@#2}{%
\PackageError{sopra-listings}{The color '#2' is undefined.}%
{Choose one of 'keywordA,keywordB,keywordC,numbers,literals,comments,highlight,command'}%
}{\definecolor{sol@colors@lst@#2}{#1}{#3}}%
}
% Cp-Palette support
\AtEndPreamble{%
\ifsol@cpalette@
\@ifundefined{cpl@registered@palettes}{%
\PackageError{sopra-listings}{cpalette requested, but package not loaded}
{You have to load the 'color-palettes' package yourself if you use the 'cpalette'-Option.}%
}{% Add to the hook..
}%
\let\sol@old@cpl@hooks\cpl@hooks
\def\cpl@hooks{\sol@old@cpl@hooks\sol@cpalette@hook}% Add to the hook
\ifsol@printmode@
\def\sol@cpalette@hook{%
\lstcolorlet{keywordA}{paletteA!90!black}%
\lstcolorlet{keywordB}{paletteB!90!black}%
\lstcolorlet{keywordC}{paletteC!45!black}%
\lstcolorlet{numbers}{paletteB}%
\lstcolorlet{literals}{black}%
\lstcolorlet{comments}{lightgray!45!darkgray!90!black}%
\lstcolorlet{highlight}{paletteD!90!black}%
\lstcolorlet{command}{paletteB!90!black}%
}\else
\def\sol@cpalette@hook{%
\lstcolorlet{keywordA}{paletteA!90!black}%
\lstcolorlet{keywordB}{paletteB!90!black}%
\lstcolorlet{keywordC}{paletteC!90!black}%
\lstcolorlet{numbers}{paletteD!60!gray!90!black}%
\lstcolorlet{literals}{paletteD!60!black}%
\lstcolorlet{comments}{lightgray!65!darkgray!90!black}%
\lstcolorlet{highlight}{paletteD!90!black}%
\lstcolorlet{command}{paletteB!90!black}%
}\fi\fi
}
% Highlights support
\ifsol@lst@style@highlights@
\newenvironment{sol@listings@highlight@env}[1][]
{\begingroup\tikzset{sol@listings@highlight/.style={#1}}\begin{lrbox}{\@tempboxa}}
{\end{lrbox}\sol@highlights@box[sol@listings@highlight]{\@tempboxa}\endgroup}
\newcommand*\sol@highlights@box[2][]{%
\hspace*{-\p@}\tikz[#1]{%
\pgfpathrectangle{\pgfpoint\p@\z@}{\pgfpoint{\wd #2}{\ht #2}}%
\pgfusepath{use as bounding box}%
\node[anchor=base west,outer sep=\z@,inner xsep=\z@,outer xsep=\p@,inner ysep=\z@,rounded corners=1.65\p@,minimum height=\ht\strutbox+\p@,#1]{\hspace*\p@\strut\box#2\hspace*{-.5\p@}};
}\hspace*{\p@}%
}
\def\@solLstHL#1{\begin{sol@listings@highlight@env}[#1]\bgroup\aftergroup\sol@highlights@endenv}
\def\sol@highlights@endenv{\end{sol@listings@highlight@env}\egroup}
\def\solhlboxd#1{\protected@edef\@tmp{\noexpand\@solLstHL{#1}}\@tmp}
\def\solhlbox#1{\@solLstHL{fill=#1!30,draw=#1}}
\colorlet{solwarning}{yellow!90!red}
\def\solcustom{fill=purple!30}
\fi
% only pmode
% Comfort guards
\def\solIfPmode#1#2{\ifnum\lst@mode=\lst@Pmode\relax#1\else#2\fi}
% Hook discretionary
\colorlet{sol@breakcolor}{gray}
\preto\lst@@discretionary{\@declaredcolor{sol@breakcolor}}
\appto\lst@@discretionary{\normalcolor}
\ifsol@lst@fake@minted@
\def\sol@minted@setup#1#2#3{\lstset{style=#1,language=#2,#3}}
% allows to map languages
\def\sol@minted@language@mapping#1{\@ifundefined{sol@@minted@#1}{#1}{\csname sol@@minted@#1\endcsname}}
\def\solmintedmap#1#2{\expandafter\def\csname sol@@minted@#1\endcsname{#2}}
\def\solsetmintedstyle#1{\def\sol@minted@style{#1}}
\solsetmintedstyle{default}
\lstnewenvironment{minted}[2][]{\protected@edef\@tmp{\pgfkeysvalueof{/sol@lst@family/\sol@minted@style/listing style}}\protected@edef\@temp{\sol@minted@language@mapping{#2}}\expandafter\expandafter\expandafter\sol@minted@setup\expandafter\expandafter\expandafter{\expandafter\@tmp\expandafter}\expandafter{\@temp}{#1}}{}
\fi
% based on https://tex.stackexchange.com/a/545948
\def\sol@glowWithColor@#1#2#3#4{\pgfsys@beginscope
\pgfsetroundjoin\pgfsetroundcap
\pdfliteral{1 Tr}% no pgf alternative
\foreach\ind in{#3,...,1}{%
\pgfmathsetmacro\per{(11-\ind)*5}%
\color{#1!\per}%
\pgfsetstrokeopacity{#4}%
\pgfsetlinewidth{\ind/#2}%
\rlap{\sol@text@}%
}%
\pgfsys@endscope}
\def\sol@glowWithColor#1#2{%
\def\sol@text@{#2}%
\sol@glowWithColor@{#1}{2.85}{8}{.025}%
\sol@text@}
\endinput