Hello Typsters,
I often have to deal with documents where every heading, paragraph, list item, enum item, figure caption, really every chunk of text, has to be labeled with some kind of marker. For some element types this is totally straightforward, for some I’m left wondering if there’s a better way, and for others I have no idea how to achieve this. For headings and semantic paragraphs this is pretty easy. For this:
#let labelThings(lab : "D", x) = {
show par: it => block([*(#lab)* ] + it.body)
show heading : it => block([*(#lab)* ] + it.body)
x
}
#labelThings[
= Heading1
#lorem(10)
]
I get something like:
(I’m only allowed to attach two images as a new user, so take my word for the fact that this works as expected)
For figures, I have to “rebuild” the default caption rendering in order to get what I want, but it works. For this:
#let labelThings(lab : "D", x) = {
show par: it => block([*(#lab)* ] + it.body)
show heading : it => block([*(#lab)* ] + it.body)
show figure.caption: it => block([*(#lab)* ] + it.supplement + [ ] + it.numbering + [: ] + it.body)
x
}
#labelThings[
= Heading1
#lorem(10)
#figure(caption: [Some Figure],
block(box(stroke:1pt, inset: 1em, [Some Figure])))
]
I get something like:
The fact that I can only update the entire figure caption with a show rule, rather than strictly the caption contents feels sort of like I’m holding it wrong, but I haven’t worked out a different way to do it.
Lists and enums are where things get strange. If I leave these show rules as-is and add some list and enum elements like so:
#let labelThings(lab : "D", x) = {
show par: it => block([*(#lab)* ] + it.body)
show heading : it => block([*(#lab)* ] + it.body)
show figure.caption: it => block([*(#lab)* ] + it.supplement + [ ] + it.numbering + [: ] + it.body)
x
}
#labelThings[
= Heading1
#lorem(10)
#figure(caption: [Some Figure],
block(box(stroke:1pt, inset: 1em, [Some Figure])))
- First item
- Second item
- Subsecond item
- Third item
- Subthird item
- Subsubthird item
+ First enum
+ Second enum
+ Subsecond enum
+ Third enum
+ Subthird enum
+ Subsubthird enum
]
I get something unexpected:
By elimination it’s the par rule that’s causing this. It seems that list and enum elements that have children become paragraphs, but not those without children. I’ve played around with show rules on list and list.item, but similar to figure captions I suspect that the only way I’d be able to render what I want is to make a show rule that re-implements the default rendering.
So, my questions are:
- Is there a better way to recursively add something to every text chunk in a body of content like this?
- Is there a better way to reach into a figure caption’s body or list/enum item’s body and modify it?
- Why do list/enum items become paragraphs when they have children? Is there a good reason for this or is it a bug?


