I am hoping to use a show
rule to insert an outline at each level 1 heading, where these outlines only show the child headings of each level 1 heading. In other words (assuming no deeper heading levels than 2), for each level 1 heading there should be one outline which shows all the level 2 headings that occur before the next level 1 heading. The idea is like a section table of contents.
I’ve found something that works, but I’m worried I’m overcomplicating things. Is there an easier way to do this?
#set heading(numbering: "(1.1)")
#show heading.where(level:1): it => {
it
let future-level-1-headings = query(selector(heading.where(level:1)).after(here(), inclusive: false))
let child-heading-selector = selector(heading.where(level:2)).after(here())
outline(
title:none,
target: if future-level-1-headings.len() > 0 {
child-heading-selector.before(future-level-1-headings.at(0).location())
} else {
child-heading-selector
}
)
}
=
==
==
==
=
==
==
==
=
==
==
==
Here are some things I can see that would make this easier:
- a way to select children headers directly instead of between
- a
location
object like the one returned forhere()
except for the end of the document (would help simplify theif
statement) - a way to get the subsequent level one heading directly
Are any of these listed options possible in typst?