Great! The conditional terminal period warrants a new topic (Appending a period to a heading conditionally based on headings's content's last character). Therefore, I now have:
#set par(
justify: true,
// first-line-indent: 1em,
first-line-indent: 1em,
spacing: 0.6em
)
#let body-size = 11pt
#set text(font: "New Computer Modern", size: body-size)
#set heading(numbering: "1.1.")
#show heading.where(level: 1): set align(center)
#show heading.where(level: 1): set text(size: 13pt, weight: "regular")
#show heading.where(level: 1): smallcaps
#show heading.where(level: 1): it => {
show h.where(amount: 0.3em): sym.space.quad
it
}
#show heading.where(level: 2): set text(size: body-size)
#show heading.where(level: 3): set text(size: body-size, weight: "regular")
#show heading.where(level: 3): emph
#let space-above-inline-headings = 1em
#show selector.or(..(2, 3).map(n => heading.where(level: n))): it => {
v(space-above-inline-headings)
// The alternative to negative h() is the trick from https://forum.typst.app/t/how-can-i-prevent-indent-on-paragraphs-with-run-in-headings/3214/2 which breaks the other trick to reduce space between consecutive headings.
h(-par.first-line-indent.amount)
counter(heading).display()
sym.space.quad
it.body
/* To be move to a new thread: conditionally append a period to the inline heading when no end-of-sentence punctuation is already present.
let message = "Have to convert to string with t4t package after all"
assert("text" in it.body.fields(), message: message)
if it.body.text.last() not in ".?!" [.]
*/
sym.dash.em
h(0pt, weak: true)
}
// Clever trick to reduce spacing between consecutive headings.
// Must be defined after the destructive show rules.
// See https://github.com/typst/typst/issues/2953#issuecomment-3187505828
#show heading: it => {
let previous-headings = query(
selector(heading).before(here(), inclusive: false)
)
if previous-headings.len() > 0 {
let prev = previous-headings.last().location().position()
let cur = it.location().position() // Curent position.
let delta = 30pt // Threshold
if (cur.page == prev.page and cur.x == prev.x and cur.y - prev.y < delta) {
// Amount to reduce spacing, could make this dependent on it.level
v(-10pt)
}
}
it
}
= Introduction
#lorem(25)
#lorem(15)
== Motivation
#lorem(20)
=== Subsubsection a
#lorem(15)
=== Subsubsection b
#lorem(20)
=== Subsubsection c
This single-line paragraph lacks adequate space after.
== Etc.
=== Subsubsection
#lorem(10)
Screenshot:
This is progressing nicely. Now I need to fiddle with the trick on spacing between sections 1.1.3 and 1.2.
