Skip to content

Commit a1a14b2

Browse files
✨ Added some missing features to the default theme (#22)
1 parent 499e050 commit a1a14b2

File tree

2 files changed

+108
-18
lines changed

2 files changed

+108
-18
lines changed

themes/default/components.typ

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#import "/packages.typ": tablex
2+
#import tablex: tablex, cellx
3+
#import "/utils.typ"
4+
5+
/// Print out the table of contents
6+
///
7+
/// Example Usage:
8+
/// ```typ
9+
/// #create-frontmatter-entry(title: "Table of Contents")[
10+
/// #components.toc()
11+
/// ]
12+
/// ```
13+
#let toc() = utils.print-toc((_, body, appendix) => {
14+
heading[Contents]
15+
stack(spacing: 0.5em, ..for entry in body {
16+
([
17+
#entry.title
18+
#box(width: 1fr, line(length: 100%, stroke: (dash: "dotted")))
19+
#entry.page-number
20+
],)
21+
})
22+
23+
heading[Appendix]
24+
stack(..for entry in appendix {
25+
([
26+
#entry.title
27+
#box(width: 1fr, line(length: 100%, stroke: (dash: "dotted")))
28+
#entry.page-number
29+
],)
30+
})
31+
})
32+
33+
/// Print out the glossary
34+
///
35+
/// Example Usage:
36+
///
37+
/// ```typ
38+
/// #create-frontmatter-entry(title: "Glossary")[
39+
/// #components.glossary()
40+
/// ]
41+
/// ```
42+
#let glossary() = utils.print-glossary(glossary => {
43+
stack(spacing: 0.5em, ..for entry in glossary {
44+
([
45+
= #entry.word
46+
47+
#entry.definition
48+
],)
49+
})
50+
})
51+
52+
/// A decision matrix table.
53+
///
54+
/// - properties (array): A list of the properties that each choice will be rated by
55+
/// - ..choices (array): An array containing the name of the choices as its first member,
56+
/// and values for each of the properties at its following indices
57+
/// -> content
58+
#let decision-matrix(properties: (), ..choices) = {
59+
let data = utils.calc-decision-matrix(properties: properties, ..choices)
60+
tablex(
61+
columns: for _ in range(properties.len() + 2) {
62+
(1fr,)
63+
},
64+
[], // Blank box
65+
..for property in properties {
66+
([ *#property.name* ],)
67+
},
68+
[*Total*],
69+
..for choice in data {
70+
// Override the fill if the choice has the highest score
71+
let cell = if choice.values.total.highest { cellx.with(fill: green) } else { cellx }
72+
(cell[*#choice.name*], ..for value in choice.values {
73+
(cell[#value.at(1).value],)
74+
})
75+
},
76+
)
77+
}
78+
79+
/// A table displaying pros and cons.
80+
///
81+
/// - pros (content): The positive aspects
82+
/// - cons (content): The negative aspects
83+
/// -> content
84+
#let pro-con(pros: [], cons: []) = {
85+
tablex(
86+
columns: (1fr, 1fr),
87+
cellx(fill: green)[*Pros*],
88+
cellx(fill: red)[*Cons*],
89+
[#pros],
90+
[#cons],
91+
)
92+
}

themes/default/default.typ

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import "/utils.typ"
1+
#import "./components.typ"
22

33
#let rules(doc) = {
44
doc
@@ -9,33 +9,31 @@
99
*Default Cover*
1010
]
1111

12-
#let toc() = utils.print-toc((_, body, appendix) => {
13-
for entry in body [
14-
#entry.title
15-
#box(width: 1fr, line(length: 100%, stroke: (dash: "dotted")))
16-
#entry.page-number
17-
]
18-
19-
for entry in appendix [
20-
#entry.title
21-
#box(width: 1fr, line(length: 100%, stroke: (dash: "dotted")))
22-
#entry.page-number
23-
]
24-
})
25-
2612
#let frontmatter-entry(context: (:), body) = {
27-
show: page.with(header: [ = Frontmatter header ], footer: [Frontmatter footer])
13+
show: page.with(
14+
header: [ = #context.title
15+
#box(width: 1fr, line(length: 100%)) ],
16+
footer: align(center, counter(page).display()),
17+
)
2818

2919
body
3020
}
3121

3222
#let body-entry(context: (:), body) = {
33-
show: page.with(header: [ = Body header ], footer: [Body footer])
23+
show: page.with(
24+
header: [ = #context.title
25+
#box(width: 1fr, line(length: 100%)) ],
26+
footer: align(center, counter(page).display()),
27+
)
3428

3529
body
3630
}
3731
#let appendix-entry(context: (:), body) = {
38-
show: page.with(header: [ = Appendix header ], footer: [Appendix footer])
32+
show: page.with(
33+
header: [ = #context.title
34+
#box(width: 1fr, line(length: 100%)) ],
35+
footer: align(center, counter(page).display()),
36+
)
3937

4038
body
4139
}

0 commit comments

Comments
 (0)