-
Notifications
You must be signed in to change notification settings - Fork 0
/
sopra-standard.sty
261 lines (224 loc) · 9.79 KB
/
sopra-standard.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
% sopra-standard.sty
% Version: 1.0
% Author: Florian Sihler, 23.01.2020
%
% This LaTeX2e Package offers environments and further commands
% to allow the management of file-, type-, message-, ... definitions
% ulm university, WiSe2019
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sopra-standard}[2020/01/23 EagleoutIce - Definition-Environments]
% Lengths and Registers
\newcounter{sosversion} \setcounter{sosversion}\@m
\def\resetRegisters{%
\gdef\sos@reg@authors{}%
\gdef\sos@reg@authors@multiple{}%
\gdef\sos@reg@bookmarklvl{3}%
\gdef\sos@reg@presentsymbol{$\circ$}
\gdef\sos@reg@prefixtitle{Definition}%
\gdef\sos@reg@counter{ctrdef}%
\gdef\sos@reg@flags{}%
\gdef\sos@reg@status{OK}}
% make command to create new environment
% till then we will fake a counter:
\newcounter{ctrdef}
% Basic Packages
% nicer symbols for definitions
\RequirePackage{fontawesome,xstring,array}
% We will integrate the changelog-mechanism
\RequirePackage{sopra-changelog}
% The Basic Environment
\newcommand\measurepage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}
\newcommand\@sosensure[1]{\ifdim\measurepage<#1\baselineskip\relax\null\newpage\relax\fi}%
% the basic layout of an definition
% #1 opt args | internal name | titel | Startersion | Änderungen für die Version ein bettung
\newenvironment{sos@definition}[5][]{%
\addvspace{1.25em plus .75em minus .275em}\phantomsection\begingroup
\resetRegisters{}% reset author, bookmark....
% Start the Parser for the optargs:
\expandafter\sos@@parser@optargs#1,\@nil
\relax\leavevmode\noindent
% Step counter:
\refstepcounter{\sos@reg@counter}%
%
\label{std:#2}% label it :D
\ignorespaces\begin{version}[#5]{#4}{#2}%
% Set the Symbol outside of Text-Block
\@ifundefined{@sop@registers@#2@removed}{\pdfbookmark[\sos@reg@bookmarklvl]{\sosFormatTitle{\sos@reg@prefixtitle}{\@nameuse{the\sos@reg@counter}}#3}{sos@id@\sos@reg@prefixtitle @\@nameuse{the\sos@reg@counter}}}% removed - ag
{\pdfbookmark[\sos@reg@bookmarklvl]{[ENTFERNT] \sosFormatTitle{\sos@reg@prefixtitle}{\@nameuse{the\sos@reg@counter}}#3}{sos@id@\sos@reg@prefixtitle @\@nameuse{the\sos@reg@counter}}}% handle might-bees:
\relax\leavevmode\noindent%
\begin{minipage}{\textwidth}\ignorespaces%
\hspace*{-1ex}\llap{\sos@reg@presentsymbol}\hspace*{1ex}% Title
\sosFormatTitle{\sos@reg@prefixtitle}{\@nameuse{the\sos@reg@counter}}#3% leftside maybe ensure with parbox?
\hbox{}\hfill\sosFormatFlags{\sos@reg@flags}\\*%
% now we will deploy the changelog and author section referencing all important metadata for the definiton.
\nopagebreak[4]\hbox{}\hfill\begin{minipage}{.975\textwidth}%
\scriptsize\ifx\sos@reg@authors@multiple\@empty Autor:\else Autoren:\fi%z
\space\sos@reg@authors.\hfill(\sos@reg@status)\relax\\*%
\end{minipage}\end{minipage}\hfill\hbox{}\smallskip\\*%
\@ifundefined{@sop@registers@#2@removed}{}{% already-removed?
\ifnum\value{soc@compile@target@version}<\@nameuse{@sop@registers@#2@removed}% nope
\else\noindent\imptext{Hinweis: Diese Definition wurde in Version \@socmp{\@nameuse{@sop@registers@#2@removed}} des Dokuments entfernt!}\quad\fi
}%
}{%
\end{version}%
\endgroup\par\ignorespacesafterend
}
% The (custom) KV-Parser
\def\sos@trimspace#1{#1}
\def\sos@@parser@optargs@parse#1: #2\@nil{%
\edef\farg{\expandafter\sos@trimspace #1}%
\@ifundefined{@sos@parser@keyhandler@\farg}{%
% not unkown
\PackageError{sopra-standard}{The Key '\farg' is unknown. No registered handler was found!}%
}
{%
% found a handler, call it:
\@nameuse{@sos@parser@keyhandler@\farg}{\farg}{#2}%
}%
}
\def\sos@@parser@optargs#1,#2\@nil{\ignorespaces
\ifx!#1!\else
% now do single parse
\expandafter\sos@@parser@optargs@parse#1\@nil
\ifx!#2!\else% recursive call
\expandafter\sos@@parser@optargs#2,\@nil
\fi
\fi
}
% the keyhandler to handler 'author: AUTHORNAME'
% the anme will be appeded to the list
% will be called with: '#1 = author' and '#2 = <supplied name>'
\def\@sos@parser@keyhandler@author#1#2{% will append the author
\ifx\sos@reg@authors\@empty% was empty:
\gdef\sos@reg@authors{#2}%
\else% append:
\let\tmp@cur@a\sos@reg@authors%
\protected@xdef\sos@reg@authors{\tmp@cur@a, #2}%
\gdef\sos@reg@authors@multiple{XXX}% Set append flag!
\fi
}
\def\@sos@parser@keyhandler@bookmark#1#2{% will set bookmark depth
\gdef\sos@reg@bookmarklvl{#2}%
}
\@namedef{@sos@parser@keyhandler@symbol}#1#2{% will set symbol to be set
\gdef\sos@reg@presentsymbol{#2}%
}
\@namedef{@sos@parser@keyhandler@title}#1#2{% will set symbol to be set
\gdef\sos@reg@prefixtitle{#2}%
}
\def\@sos@parser@keyhandler@flags#1#2{% will set special flags for the environment
\gdef\sos@reg@flags{#2}%
}
\def\@sos@parser@keyhandler@status#1#2{% will set the status flag
\gdef\sos@reg@status{#2}%
}
\def\@sos@parser@keyhandler@counter#1#2{% will set the counter flag
\gdef\sos@reg@counter{#2}%
}
% The additional User-Functions :D
\def\sos@thesosversion#1#2#3#4\@nil{{v#1.#2.#3#4}}
\edef\sos@version@str{\noexpand\sos@thesosversion\arabic{sosversion}\noexpand\@nil}
\edef\thesosversion{\sos@version@str}
% Formtters
\def\sosFormatTitle#1#2{\begingroup\bfseries#1 #2:\space\endgroup}
\def\sosFormatFlags#1{\begingroup\scriptsize\itshape#1\endgroup}
% Create new Environment type
% #1 optional Args to be passed every Time
% #2 environment name
% #3 counter name
\def\CreateNewStandardType#1#2#3{
% \begingroup\globaldefs=1
\global\newcounter{#3}
\newenvironment{#2}[5][]{%
\sos@definition[#1,counter: #3,##1]{##2}{##3}{##4}{##5}%
}{\endsos@definition}
%\endgroup
}
% Basic Environments
\CreateNewStandardType{symbol: \raisebox{\p@}{\footnotesize\faFileTextO},title: Datei Definition}{filedef}{ctrfiledefs}
\CreateNewStandardType{symbol: \footnotesize\faCommentsO,title: Kommentar}{comment}{ctrcomment}
\CreateNewStandardType{symbol: \raisebox{2pt}{\footnotesize\{\}},title: Datentyp Definition}{datadef}{ctrdatatype}
\CreateNewStandardType{symbol: \footnotesize\faCode,title: Nachricht Definition}{messagedef}{ctrjsonmessage}
\CreateNewStandardType{symbol: \footnotesize\faTerminal,title: Kommandozeilenparameter}{cmdlinedef}{ctrcommandline}
\CreateNewStandardType{title: Begriffsdefinition}{begdef}{ctrbegref}
% Extra Handler for sopra-listings
% Note: this code should only be used if sopra-listings is in effect
% it will add hyperlinks for datatypes inside of the code
% #1 Length
% #2 Codefragment
% #3 hltarget
\def\@CreateCodeHyperLink#1#2#3{%
\typeout{Create HL for '#2' using length '#1' and target '#3'}%
\expandafter\gdef\csname#2\endcsname{\solGet{keywordC}{\hyperref[#3]{#2}{}}}
\lstset{add to literate={:#2}{{\@nameuse{#2}}}{#1}}%
\lstset{add to literate={|#2|}{{\@nameuse{#2}}}{#1}}% Sicher gehen und so :/
}
% Codefragment | hltarget
\newcommand\CreateCodeHyperLink[2][]{%
\IfStrEq{#1}{}{%
\@for\@elem:=#2\do{%
\StrLen{\@elem}[\@cclen]%
\protected@edef\@tmp{\noexpand\@CreateCodeHyperLink{\@cclen}{\@elem}{std:\@elem}}\@tmp
}
}{
\StrLen{#1}[\@cclen]%
\@CreateCodeHyperLink{\@cclen}{#1}{#2}%
}
}
\solSetLeftMargin{21pt} % find ich übersichtlicher mit den ganzen Defs...
% Toc - Annotations
% get little setion summaries in the toc - this will hopefully look nice - even
% if the LaTeX-Code isn't :D
% register for current s-comment - wuuup wuup
\def\currentTocComment{}
% acts basically as \chapter{#1}, but will be '\setComment' aware
\def\Chapter#1{%
\ifx\currentTocComment\@empty\chapter{#1}\else
\begingroup
% \newcommand\voidpdfbookmark[3][]{}%
% \let\pdfbookmark\voidpdfbookmark%
\pgfmathsetmacro\nextchap{int(\value{chapter}+1)}%
\hypertarget{sopchapter.\nextchap}{}\nopagebreak%
\chapter[{\parbox[t]{\linewidth-1.5cm}{#1\\[.5\topsep]\strut\mdseries{\itshape\scriptsize{\currentTocComment}\strut}}}]{#1}% ~~~
\endgroup
% \endgroup
\fi\gdef\currentTocComment{}%
\pdfbookmark[0]{#1}{ms@chp@@id@\thechapter}%
}
\let\oldsection\section
\def\section{\@sosensure{6.25}\@ifstar\@star@section\@nostar@section}
\def\@star@section#1{\oldsection*{#1}}
\def\@nostar@section#1{\oldsection{#1}%
\pdfbookmark[1]{#1}{ms@sec@@id@\thesection}}
\let\oldsubsection\subsection
\def\subsection#1{%
\oldsubsection{#1}%
\pdfbookmark[2]{#1}{ms@sec@@id@\thesection @\thesubsection}%
}
\let\oldsubsubsection\subsubsection
\def\subsubsubsection#1{%
\oldsubsubsection{#1}%
\pdfbookmark[3]{#1}{ms@sec@@id@\thesection @\thesubsection @\thesubsubsection}%
}
\def\longspread{\setstretch{1.007}\scriptsize}% hihi
\long\def\setComment#1{\gdef\currentTocComment{\color{cprimary!75!cwhite}\faAngleDoubleRight~\parbox[t]{\linewidth-.75em}{\protect\longspread#1}}}
% Generic Stuff
% optional Arguments
\def\opt{\mdseries\itshape}
\setlist{nolistsep}
\setlist[description,1]{align=left,style=standard}
\newlist{specs}{description}{1}
\setlist[specs,1]{widest=Beschreibung:,leftmargin=*,font=\mdseries\itshape,itemsep=4pt plus 3pt minus 0pt,align=right}
\newcounter{counterDefinitions}
\def\begriff#1{\phantomsection\label{BEGRIFF:#1}\refstepcounter{counterDefinitions}%
%\addcontentsline{toc}{subsubsection}{Begriff \thecounterDefinitions: #1}
\pdfbookmark[3]{Begriff \thecounterDefinitions: #1}{ms@shead@@bg@#1}
}
\newcommand\begriffref[2][]{\pref{BEGRIFF:#2}{\ifx!#1!#2\else#1\fi}} % => sopra-tables
\newcolumntype{B}{>{\bfseries}K}
\long\def\say#1{\glqq#1\grqq{}}
% Change the behaviour - sadly, this will enable be to keep hyperlinks inside of the Grahics, which i consider to be more effective
\newcommand*\GetSopra[2][1]{\centering\resizebox{#1\linewidth}{!}{\input{figures/sopra_#2.tex}}}% -compressed
\newcommand*\figref[1]{\hyperref[{#1}]{\autoref*{#1} (\nameref*{#1})}} % One single link
\newcommand\info[1]{\begingroup\footnotesize\itshape#1\endgroup}
\endinput