The following code is used to indicate the title of the chapter at the top of a presentation.
This no longer works in 0.13.
Can anyone solve this function?
Thank you for your reply.
#let current-chapter-title() = locate(loc => {
let headings = query(selector(heading.where(level:1)).before(loc))
if headings != () {
headings.last().body
} else {
"Aucun titre trouvé"
}
})
Example 1
In this chapter (#current-chapter-title())...
Example 2
#set page(columns: 1,height: 1080pt, width: 1920pt, margin: (top: 55mm, right: 30mm, bottom: 30mm, left: 35mm),
background: [#image("2.jpg", width: 101%)],
header: [#place(dx: 1mm, dy: 9mm, left, text([#context counter(heading).display() - #current-chapter-title() | page #context counter(page).display()]
,stroke: 0pt, size: 40pt, font: "DejaVu Serif"))]
)
Hey. This is a breaking change. You should look at any breaking changes in the new version before switching to it.
#let current-chapter-title() = context {
let headings = query(heading.where(level: 1).before(here()))
if headings == () { panic("Aucun titre trouvé") }
headings.last().body
}
= Heading
#current-chapter-title()
1 Like
Hey @Suizii, welcome to the forum! I’ve changed your question post’s title to better fit our guidelines: How to post in the Questions category
Make sure your title is a question you’d ask to a friend about Typst. 
To further clarify Andrew’s answer: the original functionality of the locate
function was removed in Typst 0.13 (after being deprecated since Typst 0.11), and should be replaced with context { ... }
. To get loc
again, you can use let loc = here()
, but that’s usually no longer necessary, as most operations which previously required a loc
no longer do. Some examples:
// Before Typst 0.11:
#locate(loc => {
let header-numbers = counter(heading).at(loc)
let all-headings = query(heading, loc)
let last-value-of-my-state = state("key", 3).final(loc)
let headings-before-here = query(selector(heading).before(loc))
let current-page = loc.page()
// ...
})
// After Typst 0.11:
#context {
let header-numbers = counter(heading).get()
let all-headings = query(heading)
let last-value-of-my-state = state("key", 3).final()
// These still need the current location
// It can be retrieved with `here()`
let headings-before-here = query(selector(heading).before(here()))
let current-page = here().page()
// ...
})
Note that the function named locate
now has a new purpose: locate(<abc>)
in a context
will now return the location object of something with that label.
2 Likes
thank you for taking the time to explain this to me