While creating the outline like this
set page(numbering: "— 1 / 2 —")
show outline.entry.where(level: 1): it => {
set text(13pt, font: title-font)
v(12pt, weak: true)
strong(it)
}
I get the outline with the following page numbering
Is there a way to get the page numbering in the outline just with the page number (2 in this case)? instead of having the full page numbering?
xkevio
October 7, 2024, 11:34am
3
You can use the “state-outline” trick (Outlines - Typst Examples Book ) which detects if your element is in the outline or not via a state
.
#let in-outline = state("in-outline", false)
#set heading(numbering: "1.1")
#set text(font: "DM Sans")
#set page(numbering: (..n) => context {
if in-outline.get() {
numbering("1", ..n)
} else {
numbering("1 / 1", ..n)
}
})
#show outline: it => {
in-outline.update(true)
it
in-outline.update(false)
}
#show outline.entry.where(level: 1): it => {
set text(13pt, font: "DM Sans")
v(12pt, weak: true)
strong(it)
}
#outline()
= Introduction
== Don't Know
The alternative would be to completely recreate the outline entry via the show-rule which is possible but tedious.
2 Likes
Thank you a lot! This is a perfect solution for the outline, but I was trying to implement something similar for references (as I also have a custom entry for the header) but this works for the first time I reference something but not for the second time.
#let in-ref = state("in-ref", false)
#show ref: it => {
in-ref.update(true)
set text(font-color)
it
in-ref.update(false)
}
#set heading(numbering: (..n) => context {
if in-ref.get() {numbering("1.1", ..n)} else {[
#numbering("1.1", ..n)
#h(0.3em)
#box(width: 1.2pt, height: 1.1em, fill: gray.darken(20%), baseline: 20%)
#h(0.2em)
]}
})
But this result in a behaviour like this
What is going on?
xkevio
October 7, 2024, 5:05pm
5
I am not sure what is going on there specifically but here I would just recommend a normal show-rule instead:
#show ref: r => if r.element.func() == heading [
#let vert-line = box(width: 1.2pt, height: 1.1em, fill: gray.darken(20%), baseline: 20%)
#r#h(0.3em)#vert-line#h(0.2em)
] else { r }
EDIT: Misread and realized you want it the other way around, whoops. See
#show ref: r => if r.element.func() == heading [
#link(r.element.location())[
#r.element.supplement #counter(heading).display("1.1")
]
] else { r }
1 Like