feat(easy-typography): initial implementation
This commit is contained in:
11 files changed
+347
No files matched your search
@@ -0,0 +1,29 @@
|
||||
// Constants
|
||||
|
||||
// space above H1
|
||||
#let heading-above-max = 1.25em
|
||||
|
||||
// space above H5
|
||||
#let heading-above-min = 0.80em
|
||||
|
||||
// space below H1
|
||||
#let heading-below-max = 0.65em
|
||||
|
||||
// space below H5
|
||||
#let heading-below-min = 0.55em
|
||||
|
||||
// font size for H1
|
||||
#let heading-size-max = 1.10em
|
||||
|
||||
// font size for H5
|
||||
#let heading-size-min = 1.00em
|
||||
|
||||
// default text weight -- light is best for reading, and printers are fine with
|
||||
// it these days
|
||||
#let body-weight = "light"
|
||||
|
||||
// line spacing -- tight; efficient but still readable with good fonts
|
||||
#let line-spacing = 1.30
|
||||
|
||||
// paragraph spacing -- defaults to a double-space
|
||||
#let paragraph-spacing = 1.70
|
||||
@@ -0,0 +1,92 @@
|
||||
#import "constants.typ": *
|
||||
|
||||
/// The main function for easy typography setup.
|
||||
/// - body-size: The size of body text (default 10pt).
|
||||
/// - fonts: A dictionary specifying heading/body fonts.
|
||||
/// - paper: The paper size to use (none to skip).
|
||||
/// - margin: Margin for the page (none to skip).
|
||||
#let easy-typography(
|
||||
body-size: 10pt,
|
||||
fonts: (heading: "Libertinus Sans", body: "Libertinus Serif"),
|
||||
paper: none,
|
||||
margin: none,
|
||||
body
|
||||
) = {
|
||||
// Optional page setup
|
||||
if paper != none {
|
||||
set page(paper: paper)
|
||||
}
|
||||
if margin != none {
|
||||
set page(margin: margin)
|
||||
}
|
||||
|
||||
// Paragraphs
|
||||
set par(
|
||||
leading: line-spacing * 0.5em,
|
||||
spacing: paragraph-spacing * 0.5em,
|
||||
justify: true,
|
||||
linebreaks: "optimized",
|
||||
)
|
||||
|
||||
// Body text
|
||||
set text(
|
||||
font: fonts.body,
|
||||
fallback: false,
|
||||
style: "normal",
|
||||
weight: body-weight,
|
||||
stretch: 100%,
|
||||
size: body-size,
|
||||
tracking: 0pt,
|
||||
spacing: 100% + 0pt,
|
||||
baseline: 0pt,
|
||||
overhang: true,
|
||||
hyphenate: true,
|
||||
kerning: true,
|
||||
ligatures: true,
|
||||
number-type: "lining",
|
||||
)
|
||||
|
||||
// Top-heavy easing function for heading sizes/spacing:
|
||||
// - max = biggest size (H1), min = smallest size (H5), level in [1..5]
|
||||
// - sqrt(t) => gives biggest decrease at top, gentlest at bottom
|
||||
let compute-size(max, min, level) = {
|
||||
if level <= 1 {
|
||||
max
|
||||
} else if level >= 5 {
|
||||
min
|
||||
} else {
|
||||
let t = (level - 1) / 4
|
||||
max - (max - min) * calc.sqrt(t)
|
||||
}
|
||||
}
|
||||
|
||||
// Heading weight logic
|
||||
let compute-weight(level) = {
|
||||
if level <= 1 {
|
||||
"bold"
|
||||
} else if level == 2 {
|
||||
"semibold"
|
||||
} else if level == 3 {
|
||||
"medium"
|
||||
} else {
|
||||
"regular"
|
||||
}
|
||||
}
|
||||
|
||||
// Show headings using computed size/spacing values
|
||||
show heading: it => block(
|
||||
breakable: false,
|
||||
sticky: true,
|
||||
above: compute-size(heading-above-max, heading-above-min, it.level),
|
||||
below: compute-size(heading-below-max, heading-below-min, it.level),
|
||||
text(
|
||||
font: fonts.heading,
|
||||
size: compute-size(heading-size-max, heading-size-min, it.level),
|
||||
weight: compute-weight(it.level),
|
||||
it
|
||||
)
|
||||
)
|
||||
|
||||
// Finally, render the body
|
||||
body
|
||||
}
|
||||
Reference in new issue
Block a user