summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/beamer-contrib/themes/metropolis/source/beamerinnerthememetropolis.dtx
blob: 24f5c5f90c965d31f85bfc229a0ceb013bcdbbdd (plain)
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
% \iffalse meta-comment -------------------------------------------------------
% Copyright 2015 Matthias Vogelgesang and the LaTeX community. A full list of
% contributors can be found at
%
%     https://github.com/matze/mtheme/graphs/contributors
%
% and the original template was based on the HSRM theme by Benjamin Weiss.
%
% This work is licensed under a Creative Commons Attribution-ShareAlike 4.0
% International License (https://creativecommons.org/licenses/by-sa/4.0/).
% ------------------------------------------------------------------------- \fi
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerinnerthememetropolis}[2017/01/23 Metropolis inner theme]
%</package>
% \fi
% \CheckSum{0}
% \StopEventually{}
% \iffalse
%<*package>
% ------------------------------------------------------------------------- \fi
%
% \subsection{\themename inner theme}
%
% A |beamer| inner theme dictates the style of the frame elements traditionally
% set in the ``body'' of each slide. These include:
%
% \begin{itemize}
%   \item title, part, and section pages;
%   \item itemize, enumerate, and description environments;
%   \item block environments including theorems and proofs;
%   \item figures and tables; and
%   \item footnotes and plain text.
% \end{itemize}
%
%
%
% \subsubsection{Package dependencies}
%
%    \begin{macrocode}
\RequirePackage{etoolbox}
\RequirePackage{keyval}
\RequirePackage{calc}
\RequirePackage{pgfopts}
\RequirePackage{tikz}
%    \end{macrocode}
%
%
%
% \subsubsection{Options}
%
% \begin{macro}{sectionpage}
%    Optionally add a slide marking the beginning of each section.
%    \begin{macrocode}
\pgfkeys{
  /metropolis/inner/sectionpage/.cd,
    .is choice,
    none/.code=\metropolis@disablesectionpage,
    simple/.code={\metropolis@enablesectionpage
                  \setbeamertemplate{section page}[simple]},
    progressbar/.code={\metropolis@enablesectionpage
                       \setbeamertemplate{section page}[progressbar]},
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{subsectionpage}
%    Optionally add a slide marking the beginning of each subsection.
%    \begin{macrocode}
\pgfkeys{
  /metropolis/inner/subsectionpage/.cd,
    .is choice,
    none/.code=\metropolis@disablesubsectionpage,
    simple/.code={\metropolis@enablesubsectionpage
                  \setbeamertemplate{section page}[simple]},
    progressbar/.code={\metropolis@enablesubsectionpage
                       \setbeamertemplate{section page}[progressbar]},
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\metropolis@inner@setdefaults}
% Set default values for inner theme options.
%    \begin{macrocode}
\newcommand{\metropolis@inner@setdefaults}{
  \pgfkeys{/metropolis/inner/.cd,
    sectionpage=progressbar,
    subsectionpage=none
  }
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Title page}
%
% \begin{macro}{title page}
% Template for the title page. Each element is only typset if it is defined
% by the user. If |\subtitle| is empty, for example, it won't leave a blank
% space on the title slide.
%    \begin{macrocode}
\setbeamertemplate{title page}{
  \begin{minipage}[b][\paperheight]{\textwidth}
    \ifx\inserttitlegraphic\@empty\else\usebeamertemplate*{title graphic}\fi
    \vfill%
    \ifx\inserttitle\@empty\else\usebeamertemplate*{title}\fi
    \ifx\insertsubtitle\@empty\else\usebeamertemplate*{subtitle}\fi
    \usebeamertemplate*{title separator}
%    \end{macrocode}
%
% Beamer's definition of |\insertauthor| is always nonempty, so we have
% to test another macro initialized by |\author{...}| to see if the user has
% defined an author. This solution was suggested by Enrico Gregorio in an
% answer to \href{https://tex.stackexchange.com/questions/241306/}{this
% Stack Exchange question}.
%
%    \begin{macrocode}
    \ifx\beamer@shortauthor\@empty\else\usebeamertemplate*{author}\fi
    \ifx\insertdate\@empty\else\usebeamertemplate*{date}\fi
    \ifx\insertinstitute\@empty\else\usebeamertemplate*{institute}\fi
    \vfill
    \vspace*{1mm}
  \end{minipage}
}
%    \end{macrocode}
% \end{macro}%
%
% Normal people should use |\maketitle| or |\titlepage| instead of using the
% |title page| beamer template directly. Beamer already defines these macros,
% but we patch them here to make the title page |[plain]| by default, remove
% |\@thanks|, and ensure the title frame number doesn't count.
%
% \begin{macro}{\maketitle}
% \begin{macro}{\titlepage}
%
%   Inserts the title frame, or causes the current frame to use the
%   |title page| template.
%
%    \begin{macrocode}
\def\maketitle{%
  \ifbeamer@inframe
    \titlepage
  \else
    \frame[plain,noframenumbering]{\titlepage}
  \fi
}
\def\titlepage{%
  \usebeamertemplate{title page}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{title graphic}
%   Set the title graphic in a zero-height box, so it doesn't change the
%   position of other elements.
%    \begin{macrocode}
\setbeamertemplate{title graphic}{
  \vbox to 0pt {
    \vspace*{2em}
    \inserttitlegraphic%
  }%
  \nointerlineskip%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{title}
%   Set the title on the title page.
%    \begin{macrocode}
\setbeamertemplate{title}{
  \raggedright%
  \linespread{1.0}%
  \inserttitle%
  \par%
  \vspace*{0.5em}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{subtitle}
%   Set the subtitle on the title page.
%    \begin{macrocode}
\setbeamertemplate{subtitle}{
  \raggedright%
  \insertsubtitle%
  \par%
  \vspace*{0.5em}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{title separator}
%   Template to set the title graphic in a zero-height box. (It won't
%   change the position of other elements.)
%    \begin{macrocode}
\newlength{\metropolis@titleseparator@linewidth}
\setlength{\metropolis@titleseparator@linewidth}{0.4pt}
\setbeamertemplate{title separator}{
  \begin{tikzpicture}
    \fill[fg] (0,0) rectangle (\textwidth, \metropolis@titleseparator@linewidth);
  \end{tikzpicture}%
  \par%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{author}
%   Set the author on the title page.
%    \begin{macrocode}
\setbeamertemplate{author}{
  \vspace*{2em}
  \insertauthor%
  \par%
  \vspace*{0.25em}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{date}
%   Set the date on the title page.
%    \begin{macrocode}
\setbeamertemplate{date}{
  \insertdate%
  \par%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{institute}
%   Set the institute on the title page.
%    \begin{macrocode}
\setbeamertemplate{institute}{
  \vspace*{3mm}
  \insertinstitute%
  \par%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Section page}
%
% \begin{macro}{section page}
%
%   Template for the section title slide at the beginning of each section.
%
%    \begin{macrocode}
\defbeamertemplate{section page}{simple}{
  \begin{center}
    \usebeamercolor[fg]{section title}
    \usebeamerfont{section title}
    \insertsectionhead\par
    \ifx\insertsubsectionhead\@empty\else
      \usebeamercolor[fg]{subsection title}
      \usebeamerfont{subsection title}
      \insertsubsectionhead
    \fi
  \end{center}
}
\defbeamertemplate{section page}{progressbar}{
  \centering
  \begin{minipage}{22em}
    \raggedright
    \usebeamercolor[fg]{section title}
    \usebeamerfont{section title}
    \insertsectionhead\\[-1ex]
    \usebeamertemplate*{progress bar in section page}
    \par
    \ifx\insertsubsectionhead\@empty\else%
      \usebeamercolor[fg]{subsection title}%
      \usebeamerfont{subsection title}%
      \insertsubsectionhead
    \fi
  \end{minipage}
  \par
  \vspace{\baselineskip}
}
\newcommand{\metropolis@disablesectionpage}{
  \AtBeginSection{
    % intentionally empty
  }
}
\newcommand{\metropolis@enablesectionpage}{
  \AtBeginSection{
    \ifbeamer@inframe
      \sectionpage
    \else
      \frame[plain,c,noframenumbering]{\sectionpage}
    \fi
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{subsection page}
%
%   Template for the subsection title slide that can optionally be added to
%   at the beginning of each subsection.
%
%    \begin{macrocode}
\setbeamertemplate{subsection page}{%
  \usebeamertemplate*{section page}
}
\newcommand{\metropolis@disablesubsectionpage}{
  \AtBeginSubsection{
    % intentionally empty
  }
}
\newcommand{\metropolis@enablesubsectionpage}{
  \AtBeginSubsection{
    \ifbeamer@inframe
      \subsectionpage
    \else
      \frame[plain,c,noframenumbering]{\subsectionpage}
    \fi
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{progress bar in section page}
%
%   Template for the progress bar displayed by default on the section page.
%   This code is duplicated in large part in the outer theme's template
%   |progress bar in head/foot|.
%
%    \begin{macrocode}
\newlength{\metropolis@progressonsectionpage}
\newlength{\metropolis@progressonsectionpage@linewidth}
\setlength{\metropolis@progressonsectionpage@linewidth}{0.4pt}
\setbeamertemplate{progress bar in section page}{
  \setlength{\metropolis@progressonsectionpage}{%
    \textwidth * \ratio{\insertframenumber pt}{\inserttotalframenumber pt}%
  }%
  \begin{tikzpicture}
    \fill[bg] (0,0) rectangle (\textwidth, \metropolis@progressonsectionpage@linewidth);
    \fill[fg] (0,0) rectangle (\metropolis@progressonsectionpage, \metropolis@progressonsectionpage@linewidth);
  \end{tikzpicture}%
}
%    \end{macrocode}
%
%   The above code assumes that |\insertframenumber| is less than or equal to
%   |\inserttotalframenumber|. However, this is not true on the first compile;
%   in the absence of an |.aux| file, |\inserttotalframenumber| defaults to 1.
%   This behaviour could cause fatal errors for long presentations, as
%   |\metropolis@progressonsectionpage| would exceed \TeX's maximum length
%   (16383.99999pt, roughly 5.75 metres or 18.9 feet).
%   To avoid this, we increase the default value for |\inserttotalframenumber|;
%   presentations with over 4000 slides will still break on first compile, but
%   users in that situation likely have deeper problems to solve.
%
%    \begin{macrocode}
\def\inserttotalframenumber{100}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Block environments}
%
%
% \begin{macro}{block}
% \begin{macro}{block alerted}
% \begin{macro}{block example}
%
%    The three different block environments differ only in their colours.
%    Rather than repeat the essentially the same template three times, we use
%    the auxiliary macro |\metropolis@block| to define all three templates.
%
%    \begin{macrocode}
\newlength{\metropolis@blocksep}
\newlength{\metropolis@blockadjust}
\setlength{\metropolis@blocksep}{0.75ex}
\setlength{\metropolis@blockadjust}{0.25ex}
\providecommand{\metropolis@strut}{%
  \vphantom{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz()}%
}
\newcommand{\metropolis@block}[1]{
  \par\vskip\medskipamount%
  \setlength{\parskip}{0pt}
%    \end{macrocode}
%
%    If a background color is defined for the block title or body, we need to
%    add a little bit of padding to the corresponding box. Ideally, this would
%    be accomplished by setting |colsep=0.75ex|, which is intended to add
%    ``color separation space'' only when the box has a colored background.
%    Unfortunately, |colsep| also adds this separation if the background color
%    is inherited, even if the inherited color is actually empty.
%    (The technical reason for this boils down to the fact that the |\ifx|
%    directive does not expand macros.)
%
%    To achieve the correct spacing for |alertblock|s and |exampleblock|s
%    as well as for normal blocks, we have to begin the |beamercolorbox|
%    differently based on whether |block title| has an empty background.
%
%    If the |block title| background is empty, or the user has explicitly
%    removed the background from (e.g.) |block title alerted|, we just need to
%    set a rightskip for a nice ragged-right block title.
%
%    \begin{macrocode}
  \ifbeamercolorempty[bg]{block title#1}{%
    \begin{beamercolorbox}[rightskip=0pt plus 4em]{block title#1}}{%
  \ifbeamercolorempty[bg]{block title}{%
    \begin{beamercolorbox}[rightskip=0pt plus 4em]{block title#1}%
  }%
%   \end{macrocode}
%
%   Otherwise, if the |block title| has a background, we set the padding based
%   on |\metropolis@blockskip|. However, we have to visually compensate for
%   the |\metropolis@strut| added to the block title (see below) by
%   subtracting |\metropolis@blockadjust| from the top and bottom padding.
%
%   \begin{macrocode}
  {%
    \begin{beamercolorbox}[
      sep=\dimexpr\metropolis@blocksep-\metropolis@blockadjust\relax,
      leftskip=\metropolis@blockadjust,
      rightskip=\dimexpr\metropolis@blockadjust plus 4em\relax
    ]{block title#1}%
  }}%
%   \end{macrocode}
%
%   We can now set the contents of the |block title|. The zero-width but
%   positive-height box |\metropolis@strut| ensures that the block title box
%   has a consistent height, even if it lacks punctuation, ascenders, or
%   descenders.
%
%   \begin{macrocode}
      \usebeamerfont*{block title#1}%
      \metropolis@strut%
      \insertblocktitle%
      \metropolis@strut%
  \end{beamercolorbox}%
%   \end{macrocode}
%
%   Next, we typeset the |block body|. This the code is similar to, but simpler
%   than, the |block title| code since we don't need to adjust for any struts.
%
%   \begin{macrocode}
  \nointerlineskip%
  \ifbeamercolorempty[bg]{block body#1}{%
    \begin{beamercolorbox}[vmode]{block body#1}}{
  \ifbeamercolorempty[bg]{block body}{%
    \begin{beamercolorbox}[vmode]{block body#1}%
  }{%
    \begin{beamercolorbox}[sep=\metropolis@blocksep, vmode]{block body#1}%
    \vspace{-\metropolis@parskip}
  }}%
      \usebeamerfont{block body#1}%
      \setlength{\parskip}{\metropolis@parskip}%
}
%    \end{macrocode}
%
%    This concludes the auxiliary macro |\metropolis@block|. Finally,
%    we define the block beamer templates using this macro.
%
%    \begin{macrocode}
\setbeamertemplate{block begin}{\metropolis@block{}}
\setbeamertemplate{block alerted begin}{\metropolis@block{ alerted}}
\setbeamertemplate{block example begin}{\metropolis@block{ example}}
\setbeamertemplate{block end}{\end{beamercolorbox}\vspace*{0.2ex}}
\setbeamertemplate{block alerted end}{\end{beamercolorbox}\vspace*{0.2ex}}
\setbeamertemplate{block example end}{\end{beamercolorbox}\vspace*{0.2ex}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{Lists and floats}
%
%    \begin{macrocode}
\setbeamertemplate{itemize items}{\textbullet}
\setbeamertemplate{caption label separator}{: }
\setbeamertemplate{caption}[numbered]
%    \end{macrocode}
%
%
%
% \subsubsection{Footnotes}
%    \begin{macrocode}
\setbeamertemplate{footnote}{%
  \parindent 0em\noindent%
  \raggedright
  \usebeamercolor{footnote}\hbox to 0.8em{\hfil\insertfootnotemark}\insertfootnotetext\par%
}
%    \end{macrocode}
%
%
%
% \subsubsection{Text and spacing settings}
%
%    \begin{macrocode}
\newlength{\metropolis@parskip}
\setlength{\metropolis@parskip}{0.5em}
\setlength{\parskip}{\metropolis@parskip}
\linespread{1.15}
%    \end{macrocode}
%
% By default, Beamer frames offer the |c| option to \textit{almost} vertically
% center the text, but the placement is a little too high. To fix this, we
% redefine the |c| option to equalize |\beamer@frametopskip| and
% |\beamer@framebottomskip|. This solution was suggested by Enrico Gregorio in
% an answer to \href{http://tex.stackexchange.com/questions/247826/}{this
% Stack Exchange question}.
%
%    \begin{macrocode}
\define@key{beamerframe}{c}[true]{% centered
  \beamer@frametopskip=0pt plus 1fill\relax%
  \beamer@framebottomskip=0pt plus 1fill\relax%
  \beamer@frametopskipautobreak=0pt plus .4\paperheight\relax%
  \beamer@framebottomskipautobreak=0pt plus .6\paperheight\relax%
  \def\beamer@initfirstlineunskip{}%
}
%    \end{macrocode}
%
%
%
% \subsubsection{Standout frames}
%
% \themename offers a custom frame format with large, centered text and an
% inverted background. To use it, add the key |standout| to the frame:
% |\begin{frame}[standout] ... \end{frame}|.
%
% \begin{macro}{standout}
%
%     Optional arguments to Beamer's frames are implemented using
%     |\define@key| from the |keyval| package, which will execute code when the
%     defined option is called. For the |standout| option, we begin a group,
%     change the colors and fonts, and set a \centering alignment.
%
%    \begin{macrocode}
\providebool{metropolis@standout}
\define@key{beamerframe}{standout}[true]{%
  \booltrue{metropolis@standout}
  \begingroup
    \setkeys{beamerframe}{c}
    \setkeys{beamerframe}{noframenumbering}
    \ifbeamercolorempty[bg]{palette primary}{
      \setbeamercolor{background canvas}{
        use=palette primary,
        bg=-palette primary.fg
      }
    }{
      \setbeamercolor{background canvas}{
        use=palette primary,
        bg=palette primary.bg
      }
    }
  \centering
  \usebeamercolor[fg]{palette primary}
  \usebeamerfont{standout}
}
%    \end{macrocode}
%
%    Then we just have to close the group after the standout slide is finished
%    in order to restore the colours and fonts for the rest of the
%    presentation. Unfortunately, we cannot use \AfterEndEnvironment{frame} for
%    this (see \url{http://tex.stackexchange.com/questions/226319/}).
%    Instead, we add the |\endgroup| to |\beamer@reseteecodes|, which is run
%    exactly once at the end of each slide.
%
%    \begin{macrocode}
  \apptocmd{\beamer@reseteecodes}{%
    \ifbool{metropolis@standout}{
      \endgroup
      \boolfalse{metropolis@standout}
    }{}
  }{}{}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Process package options}
%
%    \begin{macrocode}
\metropolis@inner@setdefaults
\ProcessPgfPackageOptions{/metropolis/inner}
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale
\endinput