509 lines
11 KiB
Plaintext
509 lines
11 KiB
Plaintext
// Glossary engine and class presentation model
|
|
#import "@preview/glossarium:0.5.10": (
|
|
get-entry-back-references, gls, gls-description, glspl, make-glossary,
|
|
print-glossary, register-glossary,
|
|
)
|
|
|
|
// Load project glossaries and presentation model
|
|
#import "../generation/glossary.typ": glossary
|
|
#import "../core/macros.typ" as macros
|
|
#import "../build_config.typ": build-config
|
|
#import "school.typ" as model
|
|
|
|
// Re-export commonly used model functions
|
|
#let gls = gls
|
|
#let gls-description = gls-description
|
|
#let school_presentation = model.school_presentation
|
|
|
|
// Configure the main document model
|
|
#let model(
|
|
variables,
|
|
body,
|
|
theme,
|
|
theme-var,
|
|
) = {
|
|
//----- PDF METADATA -----
|
|
|
|
set document(
|
|
title: variables.title,
|
|
author: variables.copyright,
|
|
)
|
|
|
|
//----- PAGE AND TYPOGRAPHY -----
|
|
|
|
set page(
|
|
paper: "a4",
|
|
margin: (
|
|
top: 2.2cm,
|
|
bottom: 2.4cm,
|
|
left: 2.5cm,
|
|
right: 2.5cm,
|
|
),
|
|
numbering: "1",
|
|
)
|
|
|
|
set text(
|
|
font: theme-var("font"),
|
|
size: 11pt,
|
|
lang: "fr",
|
|
fill: theme.ink,
|
|
)
|
|
|
|
set par(
|
|
justify: true,
|
|
leading: 0.7em,
|
|
first-line-indent: 1em,
|
|
spacing: 0.9em,
|
|
)
|
|
|
|
// Use the theme's heading numbering configuration
|
|
set heading(
|
|
numbering: theme-var("heading-numbering"),
|
|
)
|
|
|
|
//----- HEADING HELPERS -----
|
|
|
|
// Return a heading's displayed number, except for level 1
|
|
let heading-number(it) = {
|
|
if it.level == 1 or it.numbering == none {
|
|
none
|
|
} else {
|
|
counter(heading).display(it.numbering)
|
|
}
|
|
}
|
|
|
|
// Render a heading number using the theme's heading color
|
|
let heading-number-content(it) = {
|
|
let number = heading-number(it)
|
|
|
|
if number == none {
|
|
[]
|
|
} else {
|
|
text(
|
|
weight: "bold",
|
|
fill: theme.heading,
|
|
)[
|
|
#number #h(0.45em)
|
|
]
|
|
}
|
|
}
|
|
|
|
//----- HEADINGS -----
|
|
|
|
// Level 1: major section
|
|
show heading.where(level: 1): set align(center)
|
|
|
|
show heading.where(level: 1): it => block(
|
|
above: 2em,
|
|
below: 1.2em,
|
|
)[
|
|
#text(
|
|
font: theme-var("font"),
|
|
size: 22pt,
|
|
weight: "bold",
|
|
fill: theme.heading,
|
|
)[
|
|
#it.body
|
|
]
|
|
|
|
#stack(
|
|
dir: ltr,
|
|
spacing: 0.4em,
|
|
|
|
// Decorative rule
|
|
[
|
|
#box(
|
|
width: 1.5cm,
|
|
height: 0.5pt,
|
|
fill: theme.heading-accent,
|
|
)
|
|
],
|
|
|
|
// Theme section symbol
|
|
[
|
|
#text(
|
|
size: 7pt,
|
|
baseline: -0.35em,
|
|
fill: theme.heading-accent,
|
|
)[
|
|
#theme-var("section-symbol")
|
|
]
|
|
],
|
|
|
|
// Decorative rule
|
|
[
|
|
#box(
|
|
width: 1.5cm,
|
|
height: 0.5pt,
|
|
fill: theme.heading-accent,
|
|
)
|
|
],
|
|
)
|
|
]
|
|
|
|
// Level 2: section
|
|
show heading.where(level: 2): it => block(
|
|
above: 1.5em,
|
|
below: 0.7em,
|
|
)[
|
|
#text(
|
|
size: 16pt,
|
|
weight: "bold",
|
|
fill: theme.heading,
|
|
)[
|
|
#heading-number-content(it) #it.body
|
|
]
|
|
]
|
|
|
|
// Level 3: subsection
|
|
show heading.where(level: 3): it => block(
|
|
above: 1em,
|
|
below: 0.4em,
|
|
)[
|
|
#text(
|
|
size: 12pt,
|
|
weight: "bold",
|
|
fill: theme.heading-accent,
|
|
)[
|
|
#heading-number-content(it) #it.body
|
|
]
|
|
]
|
|
|
|
// Level 4: minor subsection
|
|
show heading.where(level: 4): it => block(
|
|
above: 0.8em,
|
|
below: 0.3em,
|
|
)[
|
|
#text(
|
|
size: 11pt,
|
|
weight: "bold",
|
|
fill: theme.heading-subtle,
|
|
)[
|
|
#heading-number-content(it) #it.body
|
|
]
|
|
]
|
|
|
|
// Level 5: smallest heading
|
|
show heading.where(level: 5): it => block(
|
|
above: 0.6em,
|
|
below: 0.2em,
|
|
)[
|
|
#text(
|
|
size: 10pt,
|
|
weight: "bold",
|
|
fill: theme.heading-subtle,
|
|
)[
|
|
#heading-number-content(it) #it.body
|
|
]
|
|
]
|
|
|
|
//----- INLINE FORMATTING -----
|
|
|
|
// Style strong emphasis using the theme
|
|
show strong: it => text(
|
|
weight: "bold",
|
|
fill: theme.emphasis,
|
|
)[
|
|
#it
|
|
]
|
|
|
|
// Preserve italic emphasis
|
|
// show emph: it =>
|
|
// text(
|
|
// style: "italic",
|
|
// )[
|
|
// #it
|
|
// ]
|
|
|
|
// Apply the theme's link color
|
|
show link: set text(
|
|
fill: theme.link,
|
|
)
|
|
|
|
//----- KEY TERMS -----
|
|
|
|
show "ravenous": (
|
|
text(
|
|
smallcaps("Ravenous"),
|
|
)
|
|
)
|
|
|
|
//----- TABLES -----
|
|
|
|
// Apply the theme's default table border
|
|
set table(
|
|
stroke: 0.5pt + theme.border,
|
|
)
|
|
|
|
//----- GLOSSARY SETUP -----
|
|
|
|
// Enable glossary rendering and register project entries
|
|
show: make-glossary
|
|
register-glossary(glossary)
|
|
|
|
// Color references to glossary entries
|
|
show ref: it => {
|
|
let el = it.element
|
|
|
|
if el != none and el.func() == figure and el.kind == "glossarium_entry" {
|
|
text(fill: theme.blood, it)
|
|
} else {
|
|
it
|
|
}
|
|
}
|
|
|
|
//----- GLOSSARY ENTRY RENDERER -----
|
|
|
|
// Render an individual glossary entry as a themed card
|
|
let print-glossary-entry(entry, ..) = {
|
|
// Capitalize the first grapheme of a string
|
|
let capitalize(s) = {
|
|
if type(s) == str {
|
|
let clusters = s.clusters()
|
|
if clusters.len() < 2 {
|
|
s
|
|
} else {
|
|
upper(clusters.at(0)) + clusters.slice(1).join()
|
|
}
|
|
} else {
|
|
s
|
|
}
|
|
}
|
|
|
|
// Retrieve unique back-references to the entry
|
|
let refs = get-entry-back-references(
|
|
entry,
|
|
deduplicate: true,
|
|
)
|
|
|
|
// Detect optional custom entry features
|
|
let has-icon = (
|
|
entry.custom != none
|
|
and "icon" in entry.custom
|
|
and entry.custom.icon == true
|
|
)
|
|
let has-alts = entry.custom != none and "alts" in entry.custom
|
|
let resisted-by = if entry.custom != none {
|
|
entry.custom.at("resisted_by", default: none)
|
|
} else { none }
|
|
let resistance-difficulty = if entry.custom != none {
|
|
entry.custom.at("difficulty", default: none)
|
|
} else { none }
|
|
let entry-category = if entry.custom != none {
|
|
entry.custom.at("category", default: none)
|
|
} else { none }
|
|
let has-resistance = resisted-by != none
|
|
|
|
// Compact metadata badge used by resistance and category information.
|
|
let metadata-pill(label, value, accent: theme.blood) = box(
|
|
fill: accent.lighten(88%),
|
|
stroke: 0.45pt + accent.lighten(48%),
|
|
inset: (x: 0.55em, y: 0.28em),
|
|
radius: 0.55em,
|
|
baseline: 0.05em,
|
|
)[
|
|
#text(
|
|
size: 0.64em,
|
|
weight: "semibold",
|
|
fill: accent.darken(5%),
|
|
tracking: 0.025em,
|
|
)[#upper(label)]
|
|
#h(0.3em)
|
|
#text(size: 0.78em, weight: "medium", fill: theme.ink)[#value]
|
|
]
|
|
|
|
//----- GLOSSARY CARD -----
|
|
|
|
block(
|
|
width: 100%,
|
|
above: 0.7em,
|
|
below: 0.7em,
|
|
fill: theme.parchment.lighten(90%),
|
|
stroke: (
|
|
left: 2.5pt + theme.blood,
|
|
top: 0.5pt + theme.parchment.darken(7%),
|
|
right: 0.5pt + theme.parchment.darken(7%),
|
|
bottom: 0.5pt + theme.parchment.darken(7%),
|
|
),
|
|
radius: 0.45em,
|
|
inset: (
|
|
left: 0.8em,
|
|
right: 0.8em,
|
|
top: 0.65em,
|
|
bottom: 0.7em,
|
|
),
|
|
)[
|
|
|
|
//----- ENTRY HEADER -----
|
|
|
|
#grid(
|
|
columns: (
|
|
if has-icon { auto } else { 0pt },
|
|
1fr,
|
|
auto,
|
|
),
|
|
gutter: 0.6em,
|
|
align: (center, horizon, center),
|
|
|
|
// Optional entry icon
|
|
if has-icon [
|
|
#box(
|
|
width: 1.8em,
|
|
height: 1.8em,
|
|
fill: theme.blood.lighten(82%),
|
|
radius: 0.35em,
|
|
align(center + horizon)[
|
|
#text(size: 1.05em)[#entry.short]
|
|
],
|
|
)
|
|
] else [],
|
|
|
|
// Entry name and short form
|
|
[
|
|
#text(
|
|
size: 1.08em,
|
|
weight: "semibold",
|
|
fill: theme.blood,
|
|
)[
|
|
#capitalize(if entry.long != none {
|
|
entry.long
|
|
} else {
|
|
entry.short
|
|
})
|
|
]
|
|
|
|
#if entry.long != none and entry.short != none and not has-icon [
|
|
#h(0.35em)
|
|
#text(
|
|
size: 0.76em,
|
|
fill: theme.muted,
|
|
style: "italic",
|
|
)[
|
|
(#capitalize(entry.short))
|
|
]
|
|
]
|
|
],
|
|
|
|
// Reserved space for optional back-references
|
|
// if refs.len() > 0 and refs.len() < 5 [
|
|
// ...
|
|
// ] else [],
|
|
)
|
|
|
|
//----- ENTRY DESCRIPTION -----
|
|
|
|
#if entry.description != none [
|
|
#block(
|
|
inset: (
|
|
left: 0.35em,
|
|
right: 0.6em,
|
|
top: 0.15em,
|
|
bottom: 0.05em,
|
|
),
|
|
)[
|
|
#text(
|
|
size: 0.92em,
|
|
fill: theme.ink,
|
|
)[
|
|
#h(0em) #entry.description
|
|
]
|
|
]
|
|
]
|
|
|
|
//----- CUSTOM RESISTANCE METADATA -----
|
|
|
|
#if has-resistance or entry-category != none [
|
|
#v(0.45em)
|
|
#block(inset: (left: 0.35em, right: 0.35em))[
|
|
#if has-resistance {
|
|
if resisted-by == "Impossible" {
|
|
metadata-pill([Résistance], [Impossible])
|
|
} else {
|
|
metadata-pill(
|
|
[Résisté par],
|
|
[#resisted-by -- (#macros.ddlvl(resistance-difficulty))],
|
|
)
|
|
}
|
|
h(0.35em)
|
|
}
|
|
#if entry-category != none {
|
|
metadata-pill([Catégorie], entry-category, accent: theme.muted)
|
|
}
|
|
]
|
|
]
|
|
|
|
//----- ALTERNATIVE NAMES -----
|
|
|
|
#if has-alts [
|
|
#v(0.55em)
|
|
|
|
#grid(
|
|
columns: auto,
|
|
gutter: 0.5em,
|
|
align: (top, horizon),
|
|
[
|
|
#text(
|
|
size: 0.67em,
|
|
weight: "semibold",
|
|
fill: theme.muted,
|
|
tracking: 0.04em,
|
|
)[Aussi appelé]
|
|
],
|
|
[
|
|
#box(
|
|
fill: theme.blood.lighten(88%),
|
|
inset: (
|
|
x: 0.45em,
|
|
y: 0.22em,
|
|
),
|
|
radius: 0.3em,
|
|
)[
|
|
#text(
|
|
size: 0.78em,
|
|
fill: theme.blood.darken(8%),
|
|
)[
|
|
#entry.custom.alts.join(", ")
|
|
]
|
|
]
|
|
],
|
|
)
|
|
]
|
|
]
|
|
}
|
|
|
|
//----- DOCUMENT AND GLOSSARY -----
|
|
|
|
// Render the main document content
|
|
body
|
|
|
|
// Append the complete glossary
|
|
[= Glossaire]
|
|
set par(
|
|
first-line-indent: 0pt,
|
|
hanging-indent: 0pt,
|
|
)
|
|
let visible-glossary = glossary.filter(entry => {
|
|
let custom = entry.at("custom", default: none)
|
|
let master-only = (
|
|
custom != none
|
|
and custom.at("master_only", default: false) == true
|
|
)
|
|
build-config.master-only or not master-only
|
|
})
|
|
print-glossary(
|
|
visible-glossary,
|
|
entry-sortkey: x => x.sort,
|
|
shorthands: (
|
|
"plural",
|
|
"longplural",
|
|
"capitalize",
|
|
"capitalize-plural",
|
|
"description",
|
|
"short",
|
|
"long",
|
|
),
|
|
show-all: true,
|
|
user-print-gloss: print-glossary-entry,
|
|
)
|
|
}
|