Repository navigation
Expand file tree
/
Copy pathgwbar.sty
More file actions
440 lines (377 loc) · 16.8 KB
/
Copy pathgwbar.sty
File metadata and controls
440 lines (377 loc) · 16.8 KB
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
%% start of file `gwbar.sty'.
%% Copyright 2025 Max Melching (m-melching@web.de).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License version 1.3c,
% available at http://www.latex-project.org/lppl/.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gwbar}
% -- Option definitions
\RequirePackage{etoolbox}
\newcommand{\gwbar@templatefilename}{"generic_template.txt"}
\newlength{\gwbar@leftpadding} % Where signal starts, measured from left end of frame
\newlength{\gwbar@rightpadding} % Where signal ends, measured from right end of frame
\newlength{\gwbar@signalheight} % Set automatically in template (at the moment)
\newlength{\gwbar@signalwidth} % Calculated based on leftpadding, rightpadding
\newlength{\gwbar@signalupshift} % Amount by which signal is shifted up from where frametitle ends and subtitle begins
\newlength{\gwbar@yshiftpicture} % Calculated automatically in template
\newlength{\gwbar@bottompadding@nosubtitle} % Spacings that are applied below the gwbar (can be controlled separately for frames with/without subtitle)
\newlength{\gwbar@bottompadding@withsubtitle}
\newtoggle{gwbar@declaretitlebox} % Determines if frametitle or headline template is provided for beamer files
\def\gwbar@backgroundtemplatefilename{"none"}
\newtoggle{gwbar@progressbar} % Whether progressbar effect is visible in beamer files
\newlength{\gwbar@totalwidth} % Controls total width of lines drawn
% -- Set sensible defaults
\setlength{\gwbar@bottompadding@nosubtitle}{0pt}
\setlength{\gwbar@bottompadding@withsubtitle}{0pt}
\@ifclassloaded{beamer}{
\setlength{\gwbar@leftpadding}{0.6\textwidth}
\setlength{\gwbar@rightpadding}{0.1\paperwidth}
\setlength{\gwbar@signalupshift}{3pt}
% -- Fiducial default value, is nice for some separation between
% -- line and framesubtitle
\def\gwbar@signalheight@given{"frametitleheight"}
% -- Not a length for convenient comparisons, despite being slightly
% -- less robust because it can now be any value. We choose some default
% -- that does not make sense here for comparisons later in code.
\setlength{\gwbar@signalheight}{2em} % Set some default
\setlength{\gwbar@totalwidth}{\paperwidth}
\toggletrue{gwbar@declaretitlebox}
\toggletrue{gwbar@progressbar}
}{
\setlength{\gwbar@leftpadding}{0.45\textwidth}
\setlength{\gwbar@rightpadding}{0.05\textwidth}
\setlength{\gwbar@signalupshift}{-0.5em}
\def\gwbar@signalheight@given{\headheight}
\setlength{\gwbar@signalheight}{2em} % Set some default
\setlength{\gwbar@totalwidth}{\textwidth}
\togglefalse{gwbar@declaretitlebox}
\togglefalse{gwbar@progressbar}
}
% -- Define and process package options
\RequirePackage{xkeyval}
\DeclareOptionX{templatefile}{\renewcommand{\gwbar@templatefilename}{#1}}
\DeclareOptionX{leftpadding}{\setlength{\gwbar@leftpadding}{#1}}
\DeclareOptionX{rightpadding}{\setlength{\gwbar@rightpadding}{#1}}
\DeclareOptionX{signalheight}{\renewcommand{\gwbar@signalheight@given}{#1}}
\DeclareOptionX{signalupshift}{\setlength{\gwbar@signalupshift}{#1}}
\DeclareOptionX{bottompaddingnosubtitle}{\setlength{\gwbar@bottompadding@nosubtitle}{#1}}
\DeclareOptionX{bottompaddingwithsubtitle}{\setlength{\gwbar@bottompadding@withsubtitle}{#1}}
\DeclareOptionX{declaretitlebox}{\settoggle{gwbar@declaretitlebox}{#1}}
\DeclareOptionX{backgroundsignal}{\renewcommand{\gwbar@backgroundtemplatefilename}{#1}}
\DeclareOptionX{progressbar}{\settoggle{gwbar@progressbar}{#1}}
\DeclareOptionX{totalwidth}{\setlength{\gwbar@totalwidth}{#1}}
\ProcessOptionsX
\@ifclassloaded{beamer}{
}{
% -- Ensure compatibility, this would set beamer boxes
\togglefalse{gwbar@declaretitlebox}
\togglefalse{gwbar@progressbar}
}
\RequirePackage{pgf}
\pgfkeys{
/gwbar/.is family, /gwbar,
% -- No need to define default style, every variable has one already
templatefile/.estore in = \gwbar@templatefilename,
leftpadding/.estore in = \gwbar@leftpadding,
rightpadding/.estore in = \gwbar@rightpadding,
signalheight/.estore in = \gwbar@signalheight@given,
signalupshift/.estore in = \gwbar@signalupshift,
bottompaddingnosubtitle/.estore in = \gwbar@bottompadding@nosubtitle,
bottompaddingwithsubtitle/.estore in = \gwbar@bottompadding@withsubtitle,
declaretitlebox/.code = {\settoggle{gwbar@declaretitlebox}{#1}},
backgroundsignal/.estore in = \gwbar@backgroundtemplatefilename,
progressbar/.code = {\settoggle{gwbar@progressbar}{#1}},
% progressbar/.estore in = \gwbar@progressbar,
totalwidth/.estore in = \gwbar@totalwidth,
}
\newcommand{\UpdateGWBarOptions}[1][]{%
\pgfkeys{/gwbar, #1}%
}
% -- Manage remaining dependencies
\RequirePackage{calc} % For length calculations
\RequirePackage{xifthen}
\RequirePackage{tikz}
\usetikzlibrary{calc}
\@ifclassloaded{beamer}{
\RequirePackage{beamerbasecompatibility} % Standard for beamer packages
}{}
% -- Note: credits for box measuring code to
% -- https://tex.stackexchange.com/questions/401377/adjust-logo-height-to-match-frametitle-box-height
% -- (this is where all the "<- NEW" markers come from). The rest is mine.
% -- Boxes and box lengths
\newsavebox{\beamer@titlebox}% <- NEW
\newlength{\gwbar@frametitleheight}% <- NEW
\newsavebox{\beamer@titleboxnosubtitle}% <- NEW
\newlength{\gwbar@frametitleheightnosubtitle}% <- NEW
\newsavebox{\gwbar@subtitlebox}
\newlength{\gwbar@subtitleboxheight}
% -- Define custom styles for all elements, so that they can be customized easily
\@ifclassloaded{beamer}{
\tikzset{
gwbar@linestyle/.style={
fg,
smooth,
line width=0.7pt,
},
gwbar@bglinestyle/.style={
gray!50!bg,
opacity=0.42,
smooth,
line width=0.7pt,
},
gwbar@fillinglayer/.style={
fill,
white, % Default color of frame background canvas
},
}
}{
\tikzset{
gwbar@linestyle/.style={
smooth,
line width=0.7pt,
},
gwbar@bglinestyle/.style={
smooth,
gray!42,
line width=0.7pt,
},
}
}
% -- Define custom environment, more robust than if statement so start env in \gwbar@gettikzpicture
% \newenvironment{gwbartikzpicture}[1][]{%
\newenvironment{gwbartikzpicture}{%
\@ifclassloaded{beamer}{%
\begin{tikzpicture}[
% #1,
remember picture,
overlay,
% shift={($(current page.north west)+({(\paperwidth - \gwbar@totalwidth)/2},\gwbar@yshiftpicture)$)}, % Centered in x-direction
shift={($(current page.north west)+(0,\gwbar@yshiftpicture)$)},
]
}{%
\begin{tikzpicture}[
% #1,
remember picture,
overlay,
% shift={($({(\textwidth - \gwbar@totalwidth)/2},0)$)}, % Centered in x-direction
]%
}%
}{%
\end{tikzpicture}
}
\newcommand{\gwbar@gettikzpicture}{%
\begin{gwbartikzpicture}
% -- NOTE: order in this picture matters for color and overlay etc
% -- (which is why we often have part one and two). Also, spaces don't
% -- matter in tikzpictures, so at least no issues with that.
\iftoggle{gwbar@declaretitlebox}{
\ifx\insertframesubtitle\@empty
% -- Important in case where signalupshift is non-zero (and if no framesubtitle is set)
\ifdim\gwbar@signalupshift=0pt
\else
\draw[
gwbar@fillinglayer,
shift={(0, -\gwbar@frametitleheight + \gwbar@frametitleheightnosubtitle)},
] (0, 0) rectangle (\paperwidth, \gwbar@signalupshift);
\fi
\fi
}{}
% -- Order matters, first one is supposed to serve as background
% -- signal (if a background signal is given).
\begin{scope}[
gwbar@bglinestyle,
x=\gwbar@signalwidth,
y=\gwbar@signalheight,
shift={(\gwbar@leftpadding, \gwbar@signalupshift)}, % Shifting here is important for clipping to work
]
\ifthenelse{\equal{\gwbar@backgroundtemplatefilename}{"none"}}{
\iftoggle{gwbar@progressbar}{
\clip ({(\gwbar@signalwidth + \gwbar@rightpadding) * \insertframenumber / \inserttotalframenumber}, -5) rectangle ({\gwbar@signalwidth + \gwbar@rightpadding}, 5);
% -- y is not +-1 to make sure we do not clip signal off, 1 would not account for linewidth
\ifthenelse{\equal{\gwbar@templatefilename}{"none"}}{
\draw[
] (0, 0) -- (\gwbar@signalwidth, 0);
}{
\draw[
] plot file {\gwbar@templatefilename};
}
}{
\ifthenelse{\equal{\gwbar@templatefilename}{"none"}}{
\draw[
] (0, 0) -- (\gwbar@signalwidth, 0);
}{
\draw[
] plot file {\gwbar@templatefilename};
}
}
}{
\draw[
] plot file {\gwbar@backgroundtemplatefilename};
}
\draw[
shift={(-\gwbar@leftpadding, 0pt)},
] ({\gwbar@totalwidth - \gwbar@rightpadding}, 0) -- (\gwbar@totalwidth, 0);
\end{scope}
% -- Plot part of signal that is visible for current progress
\begin{scope}[
gwbar@linestyle,
shift={(0pt, \gwbar@signalupshift)},
]
\draw[
] (0, 0) -- (\gwbar@leftpadding, 0);
\begin{scope}[
x=\gwbar@signalwidth,%+\gwbar@rightpadding,
y=\gwbar@signalheight,
shift={(\gwbar@leftpadding, 0pt)}, % Shifting here is important for clipping to work
]
\iftoggle{gwbar@progressbar}{
\clip (0, -5) rectangle ({(\gwbar@signalwidth + \gwbar@rightpadding) * \insertframenumber / \inserttotalframenumber}, 5);
% -- y is not +-1 to make sure we do not clip signal off, 1 would not account for linewidth
}{}
\ifthenelse{\equal{\gwbar@templatefilename}{"none"}}{
\draw[
] (0, 0) -- (\gwbar@signalwidth, 0);
}{
\draw[
] plot file {\gwbar@templatefilename};
}
\draw[
shift={(-\gwbar@leftpadding, 0pt)},
] ({\gwbar@totalwidth - \gwbar@rightpadding}, 0) -- (\gwbar@totalwidth, 0);
\end{scope}
\end{scope}
\end{gwbartikzpicture}%
}
\newcommand{\gwbar}[1][]{%
\pgfkeys{/gwbar, #1}%
%
\iftoggle{gwbar@declaretitlebox}{%
% -- Box measurements first
% -- NOTE: not having blank lines is important for spacing reasons.
% -- Always put a comment in.
\ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
\@tempdima=\textwidth%
\advance\@tempdima by\beamer@leftmargin%
\advance\@tempdima by\beamer@rightmargin%
%
%
\sbox{\beamer@titleboxnosubtitle}{% <- NEW
\begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}%
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\if@tempswa\else\csname beamer@fteleft\endcsname\fi%
\strut\insertframetitle\strut\par%
\vskip-1ex%
\if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
\end{beamercolorbox}%
}% <- NEW
%
%
\sbox{\beamer@titlebox}{% <- NEW
\begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}%
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\if@tempswa\else\csname beamer@fteleft\endcsname\fi%
\strut\insertframetitle\strut\par%
{%
\ifx\insertframesubtitle\@empty%
\else%
{\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
\fi%
}%
\vskip-1ex%
\if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
\end{beamercolorbox}%
}% <- NEW
\usebox{\beamer@titlebox}% <- NEW
%
\settoheight{\gwbar@frametitleheight}{\usebox{\beamer@titlebox}}% <- NEW
\addtolength{\gwbar@frametitleheight}{\headheight}%
%
\settoheight{\gwbar@frametitleheightnosubtitle}{\usebox{\beamer@titleboxnosubtitle}}% <- NEW
\addtolength{\gwbar@frametitleheightnosubtitle}{\headheight}%
%
%
\setlength{\gwbar@yshiftpicture}{-\gwbar@frametitleheightnosubtitle}%
%
\setlength{\gwbar@signalwidth}{\gwbar@totalwidth - \gwbar@leftpadding - \gwbar@rightpadding}%
\ifthenelse{\equal{\gwbar@signalheight@given}{"frametitleheight"}}{%
\setlength{\gwbar@signalheight}{\gwbar@frametitleheightnosubtitle - \gwbar@signalupshift}%
% -- -\gwbar@signalupshift to account for potential asymmetry.
}{%
\ifthenelse{\equal{\gwbar@signalheight@given}{"framesubtitleheight"}}{%
\ifx\insertframesubtitle\@empty%
% -- Problem: setting and unsetting the framesubtitle and reading
% -- out the height of \beamer@titlebox in between does not work.
% -- Thus we have to redefine a new box with a placeholder at
% -- framesubtitle and this is what \gwbar@subtitlebox is for.
\sbox{\gwbar@subtitlebox}{%
\begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}%
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\if@tempswa\else\csname beamer@fteleft\endcsname\fi%
\strut\insertframetitle\strut\par%
{%
{\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}Frame Subtitle\strut\par}%
}%
\vskip-1ex%
\if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
\end{beamercolorbox}%
}%
%
\settoheight{\gwbar@subtitleboxheight}{\usebox{\gwbar@subtitlebox}}%
\addtolength{\gwbar@subtitleboxheight}{\headheight}%
\else%
\setlength{\gwbar@subtitleboxheight}{\gwbar@frametitleheight}%
\fi%
%
\setlength{\gwbar@signalheight}{\gwbar@subtitleboxheight - \gwbar@frametitleheightnosubtitle + \gwbar@signalupshift}%
}{%
% -- Numerical input has been given
\setlength{\gwbar@signalheight}{\gwbar@signalheight@given}%
}%
}%
%
\gwbar@gettikzpicture{}%
%
}{%
%
\ifthenelse{\equal{\gwbar@signalheight@given}{"frametitleheight"} \or \equal{\gwbar@signalheight@given}{"framesubtitleheight"}}{%
% -- Use default value of signalheight
}{%
\setlength{\gwbar@signalheight}{\gwbar@signalheight@given}%
}%
\setlength{\gwbar@signalwidth}{\gwbar@totalwidth - \gwbar@leftpadding - \gwbar@rightpadding}%
% \setlength{\gwbar@yshiftpicture}{\gwbar@signalupshift}%
\setlength{\gwbar@yshiftpicture}{0pt}%
% -- Could just use signalupshift in options below, but I can see
% -- already how this leads to issues when I do copy+paste.
%
\gwbar@gettikzpicture{}%
%
}%
%
% -- Account for some of the offset, while not pushing into the signal
\@ifclassloaded{beamer}{%
\ifx\insertframesubtitle\@empty%
% \vspace*{0.25\gwbar@signalheight}%
\vspace*{\gwbar@bottompadding@nosubtitle}%
\else%
\vspace*{\gwbar@bottompadding@withsubtitle}%
\fi%
}{}%
% -- Any desired offset can added using \addtobeamertemplate for beamer files
% -- or using commands like \setlength{\headheight}{<input>} in other
% -- LaTeX classes, possibly in combination with signalupshift.
}
% -- Still define beamertemplates for more straightforward use
\@ifclassloaded{beamer}{
\iftoggle{gwbar@declaretitlebox}{
\defbeamertemplate{frametitle}{gwbar}{\gwbar}
}{
\defbeamertemplate{headline}{gwbar}{\gwbar}
}
% -- We do NOT want to use * here because \addtobeamertemplate is a valid use
% -- use now, so we do not want to force use via headilne template.
}{}