This is what I came up with to get the links in the outline back:
#show outline.entry: it => {
if it.element.func() == heading {
// don't interfere with figure outlines (optional if you don't have one)
let head = it.element // just to make our code shorter
let number = if head.numbering != none {
numbering(head.numbering, ..counter(heading).at(head.location()))
}
let fill = box(
width: 1fr,
it.fill,
) // ensure the fill doesn't occupy the full page width, just the available space (1fr)
let toc-entry = box(
//stroke: 1pt + red, //used for debugging
link(head.location(), box(number + h(0.75em, weak: true) + head.body + fill + it.page)),
)
if head.level == 1 {
strong(toc-entry)
} else {
toc-entry
}
v(-0.4em, weak: true)
} else {
it // use default style for figure outlines
}
}
#outline(indent: 1.65em)
#pagebreak()
#set page(numbering: "1")
#counter(page).update(1)
#set heading(numbering: "1.1 ")
= First Headline 1
== First Headline 2
== Second Headline 2
#lorem(800)
= Second Headline 1
= Third Headline 1
#heading(numbering: none)[Literature]
What I couldn’t solve:
-
If you need indents for everything below level 1 you get line breaks, messing up the spacing, because the indent “overfills” due to the
1fr
fill.I guess it would be possible to leave the indent and add a own spacing instead, substracting this spacing from theUpdate: I tried that but subsctracting from fractions is not possible or at least would involve further measuring steps. Maybe there is a compact/elegant solution I’m just not seeing? I also tried1fr
, but then the code would bloat even further and another if/loop for subsequent levels would be necessary.pad()
for the indents, but that leads to the same problem, just that the line breaks is below instead of above. -
The spacing needs the weird
v(-0.4em, weak: true)
, which I suppose should not be necessary if done right – I think my code introduces some space where it should not?
Here is an editable link to see the example.
Would be really great if someone more experienced could take a look.