summaryrefslogtreecommitdiff
path: root/presentation/kit-slides.typ
blob: b3b5cf87a0dd606d7533bd42a25017264b8c5ad3 (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
//==========================================================
// Karlsruhe Institute of Technology theme for Typst slides.
// Based on the official Powerpoint Theme and Latex Template
//
// You don't need to edit this file. Only presentation.typ
// =========================================================
#import "@preview/polylux:0.3.1": *

#let _kit-outer-margin = 3mm
#let _kit-inner-margin = 11mm
#let _kit-top-margin = 10mm
#let _kit-bottom-margin = 11mm

#let kit-green = rgb(0, 150, 130)
#let kit-blue = rgb(70, 100, 170)
#let green = kit-green
#let blue = kit-blue
#let black70 = rgb(64, 64, 64)
#let brown = rgb(167, 130, 46)
#let purple = rgb(163, 16, 124)
#let cyan = rgb(35, 161, 224)
#let lime = rgb(140, 182, 60)
#let yellow = rgb(252, 229, 0)
#let orange = rgb(223, 155, 27)
#let red = rgb(162, 34, 35)

#let kit-title = state("kit-title", [])
#let kit-subtitle = state("kit-subtitle", [])
#let kit-short-title = state("kit-short-title", none)
#let kit-author = state("kit-author", [])
#let kit-short-author = state("kit-short-author", none)
#let kit-group-logo = state("kit-group-logo", none)
#let kit-institute = state("kit-institute", [])
#let kit-date = state("kit-date", none)
#let kit-show-page-count = state("kit-show-page-count", false)

//=================
// Helper functions
//=================

#let kit-logo(..rest) = context {
  if text.lang == "de" {
    image("/assets/kit/logo-de.svg", ..rest)
  } else {
    image("/assets/kit/logo-en.svg", ..rest)
  }
}

#let kit-rounded-block(radius: 3mm, body) = {
  block(
    radius: (
      top-right: radius,
      bottom-left: radius,
    ),
    clip: true,
    body,
  )
}

#let kit-list-marker = move(
  dy: 0.125em,
  kit-rounded-block(
    radius: 0.15em,
    rect(
      // The latex documentclass uses a size of 1ex, but type only supports em.
      width: 0.5em,
      height: 0.5em,
      fill: kit-green,
    ),
  ),
)

#let kit-theme(
  title: none,
  subtitle: none,
  short-title: none,
  author: none,
  short-author: none,
  language: "de",
  group-logo: none,
  institute: none,
  date: none,
  aspect-ratio: "16-9",
  show-page-count: false,
  body,
) = {

  if language not in ("en", "de") {
    panic("Only English (en) and German (de) are currently supported")
  }
  set page(margin: 0pt, header-ascent: 0pt, footer-descent: 0pt)
  // Use power point page sizes, as they differ from default typst page sizes.
  set page(width: 25.4cm, height: 14.29cm) if aspect-ratio == "16-9"
  set page(width: 25.4cm, height: 15.88cm) if aspect-ratio == "16-10"
  set page(width: 25.4cm, height: 19.05cm) if aspect-ratio == "4-3"
  if aspect-ratio not in ("16-9", "16-10", "4-3") {
    panic("Unsupported aspect ratio")
  }

  set text(lang: language, font: ("Arial", "Helvetica", "Roboto"))

  set list(marker: kit-list-marker)

  kit-title.update(title)
  kit-subtitle.update(subtitle)
  if short-title == none {
    kit-short-title.update(title)
  } else {
    kit-short-title.update(short-title)
  }
  kit-author.update(author)
  if short-author == none {
    kit-short-author.update(author)
  } else {
    kit-short-author.update(short-author)
  }
  kit-institute.update(institute)
  kit-group-logo.update(group-logo)
  kit-date.update(date)
  kit-show-page-count.update(show-page-count)

  body
}

//=================
// slides
//=================

#let title-slide(banner: none) = {
  show: polylux-slide
  if banner == none {
    banner = image("/assets/kit/banner.jpg")
  }

  // Top half
  pad(left: _kit-inner-margin, right: 6mm, top: _kit-top-margin)[
    // KIT logo
    #place[
      #kit-logo(width: 45mm)
    ]
    // Group logo
    #place(right)[
      #block(width: 30mm, height: 30mm)[
        #set image(width: 100%)
        #context kit-group-logo.get()
      ]
    ]
    // Title
    #place(dy: 32mm, text(weight: "bold", size: 26pt, kit-title.display()))
    // Subtitle
    #place(dy: 44mm)[
      #set text(weight: "bold", size: 18pt)
      #set par(leading: 0.3em)
      #kit-subtitle.display()
    ]
  ]

  // Bottom half
  align(
    bottom,
    pad(x: _kit-outer-margin)[
      // Banner
      #block(height: 60mm, below: 0pt)[
        #kit-rounded-block(radius: 3mm)[
          #set image(width: 100%, height: 100%)
          #banner
        ]
      ]
      // Footer
      #block(height: _kit-bottom-margin, width: 100%)[
        #grid(
          columns: (auto, 1fr),
          [
            #align(left + horizon)[
              #block(height: 100%)[
                #set text(size: 8pt)
                #context {
                  if text.lang == "en" [
                    KIT - The Research University in the Helmholtz Association
                  ] else if text.lang == "de" [
                    KIT - Die Forschungsuniversität in der Helmholtz-Gemeinschaft
                  ]
                }
              ]
            ]
          ],
          [
            #align(
              right + horizon,
              block(height: 100%)[
                #link(
                  "https://www.kit.edu",
                  text("www.kit.edu", weight: "bold", size: 16.5pt),
                )
              ],
            )
          ],
        )
      ]
    ],
  )
}

#let slide(title: [], body) = {
  // Title bar
  let header = block(width: 100%, height: 100%, inset: (x: _kit-inner-margin))[
    #grid(
      columns: (auto, 1fr),
      [
        #set text(24pt, weight: "bold")
        // We need a block here to force the grid to take the full height of the surrounding block
        #block(height: 100%)[
          #align(left + bottom, title)
        ]
      ],
      [
        #align(right + bottom)[
          #kit-logo(width: 30mm)
        ]
      ],
    )
  ]

  // Content block
  let wrapped-body = block(
    width: 100%,
    height: 100%,
    inset: (x: _kit-inner-margin, top: 15.5mm),
  )[
    #set text(18pt)
    // Default value, but had to be changed for layout
    #set block(above: 1.2em)
    #body
  ]

  // Footer
  let footer = block(width: 100%, inset: (x: _kit-outer-margin))[
    #set block(above: 0pt)
    #set text(size: 9pt)
    #line(stroke: rgb("#d8d8d8"), length: 100%)
    #block(width: 100%, height: 100%)[
      #align(horizon)[
        #grid(
          columns: (20mm, 30mm, 1fr, auto),
          pad(
            left: 6mm,
            context if kit-show-page-count.get() [
              #logic.logical-slide.display()/#strong(utils.last-slide-number)
            ] else [
              #logic.logical-slide.display()
            ],
          ),
          kit-date.display(),
          [#kit-short-author.display() - #kit-short-title.display()],
          align(right, kit-institute.display()),
        )
      ]
    ]
  ]

  set page(
    header: header,
    footer: footer,
    margin: (top: 22.5mm, bottom: _kit-bottom-margin),
  )
  polylux-slide(wrapped-body)
}

// This function is left here for backwards compatibility only. Please use #slide(side-by-side[][]) instead.
#let split-slide(title: [], body-left, body-right) = {
  let body = grid(
    columns: (1fr, 1fr),
    gutter: 2em,
    body-left, body-right,
  )

  slide(title: title, body)
}

#let kit-color-block(title: [], color: [], body) = {
  // 80% is a rough heuristic, that produces the correct result for all predefined colors.
  // Might be adjusted in the future
  let title-color = if luma(color).components().at(0) >= 80% {
    black
  } else {
    white
  }
  kit-rounded-block()[
    #block(
      width: 100%,
      inset: (x: 0.5em, top: 0.3em, bottom: 0.4em),
      fill: gradient.linear(
        (color, 0%),
        (color, 87%),
        (color.lighten(85%), 100%),
        dir: ttb,
      ),
      text(fill: title-color, title),
    )
    #set text(size: 15pt)
    #block(
      inset: 0.5em,
      above: 0pt,
      fill: color.lighten(85%),
      width: 100%,
      body,
    )
  ]
}

#let kit-info-block(title: [], body) = {
  kit-color-block(title: title, color: kit-green, body)
}

#let kit-example-block(title: [], body) = {
  kit-color-block(title: title, color: kit-blue, body)
}

#let kit-alert-block(title: [], body) = {
  kit-color-block(title: title, color: red.lighten(10%), body)
}