|
| 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 | +} |
0 commit comments