Skip to content

Commit

Permalink
✨ Implement make-glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
BattleCh1cken committed May 21, 2024
1 parent ae63080 commit 09baab2
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 80 deletions.
41 changes: 25 additions & 16 deletions themes/linear/components/glossary.typ
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
#import "../../../utils.typ"

#let glossary() = utils.print-glossary(
glossary => {
stack(
dir: ttb,
spacing: 15pt,
..for entry in glossary {([
#box(inset: 0.5em, fill: gray)[== #entry.word]
#h(5pt)
#box(baseline: -10pt, width: 1fr, line(length: 100%))
#import "/utils.typ"

#entry.definition
],)}
)
}
)
#let glossary = utils.make-glossary(glossary => {
stack(
dir: ttb,
spacing: 15pt,
..for entry in glossary {
(
[
#box(
inset: 0.5em,
fill: gray,
)[== #entry.word]
#h(5pt)
#box(
baseline: -10pt,
width: 1fr,
line(length: 100%),
)

#entry.definition
],
)
},
)
})
116 changes: 70 additions & 46 deletions themes/linear/components/toc.typ
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,75 @@
/// #components.toc()
/// ]
/// ```
#let toc() = utils.print-toc(
(_, body, appendix) => style(
styles => {
let previous-date

let toc = stack(
dir: ttb,
spacing: 0.3em,
..for entry in body {
let date-content = if entry.date == previous-date {} else {
box(inset: 5pt, fill: white, entry.date.display("[day]/[month]/[year]"))
}

previous-date = entry.date
([
// Single line content
#box(baseline: 0.35em, width: 5em)[
#set align(center)
#date-content
]
#h(1em)
#box(
fill: entry-type-metadata.at(entry.type),
inset: (x: .4em, y: .6em),
baseline: 25%,
)[#entry.title #h(1.4em)]
#h(1em)
#box(width: 1fr, line(length: 100%, start: (0pt, -.35em)))
#h(1em)
#entry.page-number
],)
},
)

let height = measure(toc, styles).height

box[
#place(
top + left,
dx: 2.5em,
dy: 1em,
line(angle: 90deg, length: height - 12pt),
#let toc = utils.make-toc((
_,
body,
appendix,
) => {
let previous-date

let toc = stack(
dir: ttb,
spacing: 0.3em,
..for entry in body {
let date-content = if entry.date == previous-date { } else {
box(
inset: 5pt,
fill: white,
entry.date.display("[day]/[month]/[year]"),
)
#toc
]
}

previous-date = entry.date
(
[
// Single line content
#box(
baseline: 0.35em,
width: 5em,
)[
#set align(center)
#date-content
]
#h(1em)
#box(
fill: entry-type-metadata.at(entry.type),
inset: (
x: .4em,
y: .6em,
),
baseline: 25%,
)[#entry.title #h(1.4em)]
#h(1em)
#box(
width: 1fr,
line(
length: 100%,
start: (
0pt,
-.35em,
),
),
)
#h(1em)
#entry.page-number
],
)
},
),
)
)

let height = measure(toc).height

box[
#place(
top + left,
dx: 2.5em,
dy: 1em,
line(
angle: 90deg,
length: height - 12pt,
),
)
#toc
]
})
2 changes: 1 addition & 1 deletion themes/radial/components/glossary.typ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// #components.glossary()
/// ]
/// ```
#let glossary() = utils.print-glossary(glossary => {
#let glossary = utils.make-glossary(glossary => {
columns(2)[
#for entry in glossary {
box[
Expand Down
33 changes: 30 additions & 3 deletions utils/components.typ
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// })
/// ```
/// - callback (function): A function which takes the #link(<ctx>)[ctx] of all entries as input, and returns the content of the entire table of contents.
/// -> content
/// -> function
#let make-toc(
callback,
) = {
Expand Down Expand Up @@ -62,7 +62,6 @@
return result
}


return () => context {
let frontmatter-entries = helper("frontmatter")
let body-entries = helper("body")
Expand All @@ -76,6 +75,34 @@
}
}

// Glossary
/// Constructor for a glossary function
/// - callback (function): A function that returns the content of the glossary
/// -> function
#let make-glossary(
callback,
) = {
return () => context {
let sorted-glossary = globals.glossary-entries.final().sorted(key: (
(
word: word,
definition: definition,
),
) => word)
callback(sorted-glossary)
}
}

// Pro / Con
#let make-pro-con(
callback,
) = { }

// Decision Matrix
#let make-decision-matrix(
callback,
) = { }

// TODO: add method for these extra components:
// - plot
// - pie chart
//
14 changes: 0 additions & 14 deletions utils/misc.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@



/// A utility function meant to help themes implement a glossary
/// - callback (function): A function that returns the content of the glossary
/// -> content
#let print-glossary(
callback,
) = locate(loc => {
let sorted-glossary = globals.glossary-entries.final(loc).sorted(key: (
(
word: word,
definition: definition,
),
) => word)
callback(sorted-glossary)
})

/// A utility function that does the calculation for decision matrices for you
///
Expand Down

0 comments on commit 09baab2

Please sign in to comment.