I am seeking to modify the format of headings to allow mixed styling. I’ll lead with the two main sections of code I’ve written for this purpose.
// set up numbering
#set heading(
numbering: (..n) => {
let n = n.pos()
// if this is a first-level heading, use higher font size
// and roman numerals
if n.len() == 1 {
text(
size: 10pt,
weight: "regular",
numbering("I.", n.at(0)),
)
// otherwise, use A/B/C, smaller text size, and italics,
// omitting parent heading labels
} else {
text(
size: 8pt,
weight: "regular",
numbering("A.", n.last()),
)
}
}
)
The code above works as you would expect, until I try to style the rest of it.
// set up styling inside the line
#show heading => it {
// ISSUE #1 (and the main issue): `it.level` is always 1.
// I assume this is due in part to function purity?
// If this were not always 1, I could call `numbering` manually.
if it.level == 1 {
text(
size: 10pt,
weight: "regular",
// large capital first letter followed by 8pt smallcaps
[
// ISSUE #2: I can't find a way to extract numbering content
// from `it`, and using `it.body.text` strips the numbering away.
#upper(it.body.text.first())#text(
size: 8pt,
smallcaps(it.body.text.slice(1)),
)
],
)
} else {
// ...
}
}
I’ve denoted my two issues as comments in the second code block. I only need one of them to be worked around.
To avoid an XY problem, I want to clarify that all I’m really looking for is a convenient way to create self-numbered blocks of text with mixed styles inside of said text, in such a way that headings like these can be styled with no extra thought put into it.
= Introduction
== Sub-Introduction
= Conclusion
Thanks in advance.