summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/beamertheme-metropolis/beamerfontthememetropolis.dtx
blob: 3e629526ff4f8ede4ece347c3c2393702eb4044f (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
% \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{beamerfontthememetropolis}[2017/01/23 Metropolis font theme]
%</package>
% \fi
% \CheckSum{0}
% \StopEventually{}
% \iffalse
%<*package>
% ------------------------------------------------------------------------- \fi
%
% \subsection{\themename font theme}
%
% A |beamer| font theme sets the style of the font used in the document.
%
%
%
% \subsubsection{Package dependencies}
%
%    \begin{macrocode}
\RequirePackage{etoolbox}
\RequirePackage{ifxetex}
\RequirePackage{ifluatex}
\RequirePackage{pgfopts}
%    \end{macrocode}
%
%
%
% \subsubsection{Load Fira fonts}
%
% If the presentation is compiled with Xe\LaTeX{} or Lua\LaTeX{}, the fontspec
% package is loaded and we search for the |Fira| fonts.
%
%    \begin{macrocode}
\ifboolexpr{bool {xetex} or bool {luatex}}{
  \@ifpackageloaded{fontspec}{
    \PassOptionsToPackage{no-math}{fontspec}
  }{
    \RequirePackage[no-math]{fontspec}
  }
%    \end{macrocode}
%
% \begin{macro}{\checkfont}
%    Checks if a font is installed; if not, |fontsnotfound| is increased.
%    \begin{macrocode}
  \newcounter{fontsnotfound}
  \newcommand{\checkfont}[1]{%
    \suppressfontnotfounderror=1%
    \font\x = "#1" at 10pt
    \selectfont
    \ifx\x\nullfont%
      \stepcounter{fontsnotfound}%
    \fi%
    \suppressfontnotfounderror=0%
  }

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\iffontsavailable}
%    Resets the |fontsnotfound| counter and calls |\checkfont| for each font in
%    the comma separated list in the first argument.
%    \begin{macrocode}
  \newcommand{\iffontsavailable}[3]{%
    \setcounter{fontsnotfound}{0}%
    \expandafter\forcsvlist\expandafter%
    \checkfont\expandafter{#1}%
    \ifnum\value{fontsnotfound}=0%
      #2%
    \else%
      #3%
    \fi%
  }
%    \end{macrocode}
% \end{macro}
%
% We search for regular, italic, light, light italic, mono, and mono bold
% fonts under the default |Fira Sans| and |Fira Mono| names. If this fails,
% the suffix OT --- used by some Linux distributions --- will be tried. If this
% also fails, a warning will be displayed and the standard fonts will be used.
%
%    \begin{macrocode}
  \iffontsavailable{Fira Sans Light,%
                    Fira Sans Light Italic,%
                    Fira Sans,%
                    Fira Sans Italic}%
  {%
    \setsansfont[ItalicFont={Fira Sans Light Italic},%
                 BoldFont={Fira Sans},%
                 BoldItalicFont={Fira Sans Italic}]%
                {Fira Sans Light}%
  }{%
    \iffontsavailable{Fira Sans Light OT,%
                      Fira Sans Light Italic OT,%
                      Fira Sans OT,%
                      Fira Sans Italic OT}%
    {%
      \setsansfont[ItalicFont={Fira Sans Light Italic OT},%
                   BoldFont={Fira Sans OT},%
                   BoldItalicFont={Fira Sans Italic OT}]%
                  {Fira Sans Light OT}%
    }{%
      \PackageWarning{beamerthememetropolis}{%
        Could not find Fira Sans fonts%
      }
    }
  }
  \iffontsavailable{Fira Mono, Fira Mono Bold}{%
    \setmonofont[BoldFont={Fira Mono Medium}]{Fira Mono}%
  }{%
    \iffontsavailable{Fira Mono OT, Fira Mono Bold OT}{%
      \setmonofont[BoldFont={Fira Mono Medium OT}]{Fira Mono OT}%
    }{%
      \PackageWarning{beamerthememetropolis}{%
        Could not find Fira Mono fonts%
      }
    }
  }
  \AtBeginEnvironment{tabular}{%
    \addfontfeature{Numbers={Monospaced}}%
  }
}{%
  \PackageWarning{beamerthememetropolis}{%
    You need to compile with XeLaTeX or LuaLaTeX to use the Fira fonts%
  }
}
%    \end{macrocode}
%
% This concludes the portion of the code which is only run when compiled with
% Xe\LaTeX{} or Lua\LaTeX{}. The remainder of this package applies regardless
% of the compiling engine.
%
%
%
% \subsubsection{General font definitions}
%
%    \begin{macrocode}
\setbeamerfont{title}{size=\Large,%
                      series=\bfseries}
\setbeamerfont{author}{size=\small}
\setbeamerfont{date}{size=\small}
\setbeamerfont{section title}{size=\Large,%
                              series=\bfseries}
\setbeamerfont{block title}{size=\normalsize,%
                            series=\bfseries}
\setbeamerfont{block title alerted}{size=\normalsize,%
                                    series=\bfseries}
\setbeamerfont*{subtitle}{size=\large}
\setbeamerfont{frametitle}{size=\large,%
                           series=\bfseries}
\setbeamerfont{caption}{size=\small}
\setbeamerfont{caption name}{series=\bfseries}
\setbeamerfont{description item}{series=\bfseries}
\setbeamerfont{page number in head/foot}{size=\scriptsize}
\setbeamerfont{bibliography entry author}{size=\normalsize,%
                                          series=\normalfont}
\setbeamerfont{bibliography entry title}{size=\normalsize,%
                                         series=\bfseries}
\setbeamerfont{bibliography entry location}{size=\normalsize,%
                                            series=\normalfont}
\setbeamerfont{bibliography entry note}{size=\small,%
                                        series=\normalfont}
\setbeamerfont{standout}{size=\Large,%
                         series=\bfseries}
%    \end{macrocode}
%
%
%
% \subsubsection{Title format options}
%
% \begin{macro}{titleformat title}
%    Controls the format of the title.
%    \begin{macrocode}
\pgfkeys{
  /metropolis/font/titleformat title/.cd,
    .is choice,
    regular/.code={%
      \let\metropolis@titleformat\@empty%
      \setbeamerfont{title}{shape=\normalfont}%
    },
    smallcaps/.code={%
      \let\metropolis@titleformat\@empty%
      \setbeamerfont{title}{shape=\scshape}%
    },
    allsmallcaps/.code={%
      \let\metropolis@titleformat\lowercase%
      \setbeamerfont{title}{shape=\scshape}%
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat title=allsmallcaps can lead to problems%
      }
    },
    allcaps/.code={%
      \let\metropolis@titleformat\uppercase%
      \setbeamerfont{title}{shape=\normalfont}
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat title=allcaps can lead to problems%
      }
    },
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{titleformat subtitle}
%    Control the format of the subtitle.
%    \begin{macrocode}
\pgfkeys{
  /metropolis/font/titleformat subtitle/.cd,
    .is choice,
    regular/.code={%
      \let\metropolis@subtitleformat\@empty%
      \setbeamerfont{subtitle}{shape=\normalfont}%
    },
    smallcaps/.code={%
      \let\metropolis@subtitleformat\@empty%
      \setbeamerfont{subtitle}{shape=\scshape}%
    },
    allsmallcaps/.code={%
      \let\metropolis@subtitleformat\lowercase%
      \setbeamerfont{subtitle}{shape=\scshape}%
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat subtitle=allsmallcaps can lead to problems%
      }
    },
    allcaps/.code={%
      \let\metropolis@subtitleformat\uppercase%
      \setbeamerfont{subtitle}{shape=\normalfont}%
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat subtitle=allcaps can lead to problems%
      }
    },
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{titleformat section}
%    Controls the format of the section title.
%    \begin{macrocode}
\pgfkeys{
  /metropolis/font/titleformat section/.cd,
    .is choice,
    regular/.code={%
      \let\metropolis@sectiontitleformat\@empty%
      \setbeamerfont{section title}{shape=\normalfont}%
    },
    smallcaps/.code={%
      \let\metropolis@sectiontitleformat\@empty%
      \setbeamerfont{section title}{shape=\scshape}%
    },
    allsmallcaps/.code={%
      \let\metropolis@sectiontitleformat\MakeLowercase%
      \setbeamerfont{section title}{shape=\scshape}%
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat section=allsmallcaps can lead to problems%
      }
    },
    allcaps/.code={%
      \let\metropolis@sectiontitleformat\MakeUppercase%
      \setbeamerfont{section title}{shape=\normalfont}%
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat section=allcaps can lead to problems%
      }
    },
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{frametitleformat}
%    Control the format of the frame title.
%    \begin{macrocode}
\pgfkeys{
  /metropolis/font/titleformat frame/.cd,
    .is choice,
    regular/.code={%
      \let\metropolis@frametitleformat\@empty%
      \setbeamerfont{frametitle}{shape=\normalfont}%
    },
    smallcaps/.code={%
      \let\metropolis@frametitleformat\@empty%
      \setbeamerfont{frametitle}{shape=\scshape}%
    },
    allsmallcaps/.code={%
      \let\metropolis@frametitleformat\MakeLowercase%
      \setbeamerfont{frametitle}{shape=\scshape}%
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat frame=allsmallcaps can lead to problems%
      }
    },
    allcaps/.code={%
      \let\metropolis@frametitleformat\MakeUppercase%
      \setbeamerfont{frametitle}{shape=\normalfont}
      \PackageWarning{beamerthememetropolis}{%
        Be aware that titleformat frame=allcaps can lead to problems%
      }
    },
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{titleformat aliases}
%    Allows |titleformat title| et al. to be used in the |\usetheme|
%    declaration, where \LaTeX{} automatically removes all spaces.
%    \begin{macrocode}
\pgfkeys{
  /metropolis/font/.cd,
  titleformattitle/.code=\pgfkeysalso{titleformat title=#1},
  titleformatsubtitle/.code=\pgfkeysalso{titleformat subtitle=#1},
  titleformatsection/.code=\pgfkeysalso{titleformat section=#1},
  titleformatframe/.code=\pgfkeysalso{titleformat frame=#1},
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\metropolis@font@setdefaults}
%    Sets default values for font theme options.
%    \begin{macrocode}
\newcommand{\metropolis@font@setdefaults}{
  \pgfkeys{/metropolis/font/.cd,
    titleformat title=regular,
    titleformat subtitle=regular,
    titleformat section=regular,
    titleformat frame=regular,
  }
}
%    \end{macrocode}
% \end{macro}
%
% We first define hooks to change the case format of the titles.
%
%    \begin{macrocode}
\def\metropolis@titleformat#1{#1}
\def\metropolis@subtitleformat#1{#1}
\def\metropolis@sectiontitleformat#1{#1}
\def\metropolis@frametitleformat#1{#1}
%    \end{macrocode}
%
% To make the uppercase and lowercase macros work in the title, subtitle, etc.,
% we have to patch the appropriate |beamer| commands that set their values.
% This solution was suggested by Enrico Gregorio in an answer to
% \href{http://tex.stackexchange.com/questions/112526/}{this StackExchange
% question}.
%
%    \begin{macrocode}
\patchcmd{\beamer@title}%
  {\def\inserttitle{#2}}%
  {\def\inserttitle{\metropolis@titleformat{#2}}}%
  {}%
  {\PackageError{beamerfontthememetropolis}{Patching title failed}\@ehc}
\patchcmd{\beamer@subtitle}%
  {\def\insertsubtitle{#2}}%
  {\def\insertsubtitle{\metropolis@subtitleformat{#2}}}%
  {}%
  {\PackageError{beamerfontthememetropolis}{Patching subtitle failed}\@ehc}
\patchcmd{\sectionentry}
  {\def\insertsectionhead{#2}}
  {\def\insertsectionhead{\metropolis@sectiontitleformat{#2}}}
  {}
  {\PackageError{beamerfontthememetropolis}{Patching section title failed}\@ehc}
\@tempswafalse
\patchcmd{\beamer@section}
  {\def\insertsectionhead{\hyperlink{Navigation\the\c@page}{#1}}}
  {\def\insertsectionhead{\hyperlink{Navigation\the\c@page}{%
    \metropolis@sectiontitleformat{#1}}}}
  {\@tempswatrue}
  {}
\patchcmd{\beamer@section}
  {\protected@edef\insertsectionhead{\noexpand\hyperlink{Navigation\the\c@page}{#1}}}
  {\protected@edef\insertsectionhead{\noexpand\hyperlink{Navigation\the\c@page}{%
    \noexpand\metropolis@sectiontitleformat{#1}}}}
  {\@tempswatrue}
  {}
\if@tempswa\else
  \PackageError{beamerfontthememetropolis}{Patching section title failed}\@ehc
\fi
\@tempswafalse
\patchcmd{\beamer@subsection}
  {\def\insertsubsectionhead{\hyperlink{Navigation\the\c@page}{#1}}}
  {\def\insertsubsectionhead{\hyperlink{Navigation\the\c@page}{%
    \metropolis@sectiontitleformat{#1}}}}
  {\@tempswatrue}
  {}
\patchcmd{\beamer@subsection}
  {\protected@edef\insertsubsectionhead{\noexpand\hyperlink{Navigation\the\c@page}{#1}}}
  {\protected@edef\insertsubsectionhead{\noexpand\hyperlink{Navigation\the\c@page}{%
    \noexpand\metropolis@sectiontitleformat{#1}}}}
  {\@tempswatrue}
  {}
\if@tempswa\else
  \PackageError{beamerfontthememetropolis}{Patching section title failed}\@ehc
\fi
%    \end{macrocode}
%
% Similarly, to make the |\MakeLowercase| and |\MakeUppercase| macros work in
% the frame title we have to patch |\beamer@@frametitle|.
%
%    \begin{macrocode}
\patchcmd{\beamer@@frametitle}
  {{%
      \gdef\insertframetitle{{#2\ifnum\beamer@autobreakcount>0\relax{}\space%
      \usebeamertemplate*{frametitle continuation}\fi}}%
    \gdef\beamer@frametitle{#2}%
    \gdef\beamer@shortframetitle{#1}%
    }}
  {{%
      \gdef\insertframetitle{{\metropolis@frametitleformat{#2}\ifnum%
      \beamer@autobreakcount>0\relax{}\space%
      \usebeamertemplate*{frametitle continuation}\fi}}%
    \gdef\beamer@frametitle{#2}%
    \gdef\beamer@shortframetitle{#1}%
    }}
  {}
  {\PackageError{beamerfontthememetropolis}{Patching frame title failed}\@ehc}
%    \end{macrocode}
%
%
%
% \subsubsection{Process package options}
%
%    \begin{macrocode}
\metropolis@font@setdefaults
\ProcessPgfPackageOptions{/metropolis/font}
%    \end{macrocode}
% \iffalse
%</package>
% \fi
% \Finale
\endinput