-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.tex
243 lines (219 loc) · 5.8 KB
/
commands.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
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
% Acronyms
% ========
% The argument appears in small caps.
\newcommand\acro[1]{\textsc{\lowercase{#1}}}
% Variables
% =========
\newcommand\widefiguremargin{-.22\textwidth}
\newcommand\widefigurewidth{.49\textwidth}
\newcommand\widefiguregap{.02\textwidth}
\newcommand\widefiguresum{1.4\textwidth}
% Fachschaft logo
% ===============
\newcommand*{\fslogo}{\raisebox{+1.25ex}{\includegraphics[height=6cm]{graphics/logo-fachschaft}}}
% Wide box
% ========
% Box that runs into both margins. To be used inside a floating environment like figure or table.
\newcommand\widebox[1]{
\hspace{\widefiguremargin}
\begin{minipage}{\widefiguresum}
#1
\end{minipage}
}
% Column rules
% ============
% Adds two rules each spanning approximately half of the available textwidth (as defined by \widefigurewidth).
\newcommand\colrules{
\rule{\widefigurewidth}{0.4pt}
\hspace{\widefiguregap}
\rule{\widefigurewidth}{0.4pt}
}
% Shell command
% ==============
% Mono-spaced text without syntax highlighting.
% Intended for full commands. Wrapped by empty lines.
\newcommand\shell[1]{%
\vspace{.5cm}
\noindent \hspace*{-1em}{\color{lightgray}\texttt{\$ }}\texttt{#1}
\vspace{.5cm}
}
% Command parts
% ===================
% Mono-spaced text without syntax highlighting.
% Intended for parts of shell commands.
% Displayed inline.
\newcommand\sh[1]{%
\texttt{#1}%
}
% Package names
% =============
% Mono-spaced text without syntax highlighting.
% Intended for LaTeX package names.
\newcommand\pkg[1]{%
\ifthenelse{\equal{\listingsmode}{minted}}{%
\texttt{#1}%
}{%
\texttt{#1}%
}%
}
% File paths
% ==========
% Mono-spaced text without syntax highlighting.
% Intended for file names and paths.
\newcommand\file[1]{%
\texttt{#1}%
}
% Mono-spaced words
% =================
% Mono-spaced text without syntax highlighting.
% Intended for single words or small passages without special meaning.
% These can be environments, file extensions, and many more.
\newcommand\mono[1]{%
\texttt{#1}%
}
% Inline code
% ===========
% Code snippets with syntax highlighting.
% TODO: Fix special character mess.
% Caution: Must not be used inside `\textbf{}'
%
% Arguments:
% 1. Language.
% 2. Source code.
\newcommand\code[2]{%
\texttt{#2}%
}
% Code block
% ==========
% Pastes in a non-inline code block using minted or lstlistings
% first parameter: programming language
% path to code file
\lstdefinelanguage{latex}{%
language=[LaTeX]TeX
}
\lstdefinelanguage{csharp}{%
language=[Sharp]C
}
\lstdefinelanguage{bibtex}
{keywords={%
@article,@book,@collectedbook,@conference,@electronic,@ieeetranbstctl,%
@inbook,@incollectedbook,@incollection,@injournal,@inproceedings,%
@manual,@mastersthesis,@misc,@patent,@periodical,@phdthesis,@preamble,%
@proceedings,@standard,@string,@techreport,@unpublished%
},
comment=[l][\itshape]{@comment},
sensitive=false,
}
\newcommand\codeblock[2]{%
\ifthenelse{\equal{\listingsmode}{minted}}{%
\inputminted[breaklines]{#1}{#2}
}{%
\ifthenelse{\equal{#1}{latex}}{%
\lstset{language=#1,
basicstyle=\small\ttfamily,
breaklines=true,
keywordstyle=\color{ForestGreen}\bfseries,
emph={%
subsection, subsubsection, url, includegraphics, toprule,
midrule, bottomrule, cref, setlength, maketitle,
tableofcontents, foreignlanguage, paragraph, subparagraph,
mint, mintinline, inputminted, usemintedstyle, definecolor,
citep, enquote, lstinputlisting%
},
postbreak=\mbox{{$\hookrightarrow$}\space},
emphstyle={\color{ForestGreen}\bfseries},
commentstyle=\color{darkgray},
% Allow special characters in lstlistings.
literate=
{Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}1
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
{é}{{\'e}}1
{…}{\textellipsis}1
}
\lstinputlisting{#2}%
%
}{%
\lstset{
language=#1,
% Allow special characters in lstlistings.
literate=
{Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}1
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
{é}{{\'e}}1
{…}{\textellipsis}1
}
\lstinputlisting{#2}
}
}
}
% Simple code examples
% ====================
% Box for example code next to the rendered example.
%
% Arguments:
% 1. Label.
% 2. Content path without extension. If a corresponding PDF file exists, it gets included as an image. Otherwise, the LaTeX code gets rendered directly.
% 3. Caption.
\newcommand\example[3]{
\Example{#1}{#2}{#2}{#3}
}
% Extended code examples
% ======================
% Box for example code next to the rendered example.
% Depending on the third argument, the source path for the right-side rendering can differ from the source path of the left-side listing.
% Useful if only an excerpt of the document to be rendered affects the entire output.
%
% Arguments:
% 1. Label.
% 2. Content path without extension. If a corresponding PDF file exists, it gets included as an image. Otherwise, the LaTeX code gets rendered directly.
% 3. Alternative path for Rendering (c.f. 2.)
% 4. Caption.
\newcommand\Example[4]{
\begin{figure}[htp]
\widebox{
% Top rules:
\colrules
% Left content: code listing:
\begin{subfigure}{\widefigurewidth}
\codeblock{latex}{listings/#2.tex}
\end{subfigure}
\hspace{\widefiguregap}
% Right content: image or rendered example:
\begin{subfigure}{\widefigurewidth}
\IfFileExists{listings/#3.pdf}{
\includegraphics[width=\linewidth]{listings/#3.pdf}
}{
\medskip
\input{listings/#3}
\medskip
}
\end{subfigure}
% Bottom rules:
\colrules
% Left caption:
\begin{subfigure}[t]{\widefigurewidth}
\caption{\LaTeX-Code}
\label{#1-code}
\end{subfigure}
\hspace{\widefiguregap}
% Right caption:
\begin{subfigure}[t]{\widefigurewidth}
\caption{Result}
\label{#1-result}
\end{subfigure}
}
% General caption:
\caption{#4}
\label{#1}
\end{figure}
}