Here is a discussion about how to get the page number when referencing an image or table. (And if I understand correctly, it should also work for headings.): https://github.com/typst/typst/issues/2873.
In May, Laurenz posted a solution for Typst 0.11:
#let pageref(label) = context { let loc = locate(label) let nums = counter(page).at(loc) link(loc, numbering(loc.page-numbering(), ..nums)) }
You can use it as
see #pageref(<myref>)
This doesn’t seem to work for me using Typst 0.12 and gives an error. Not sure whether the code should be updated or I simply don’t really understand how to use it properly. Here is what I tried:
#let pageref(label) = context {
let loc = locate(label)
let nums = counter(page).at(loc)
link(loc, numbering(loc.page-numbering(), ..nums))
}
= Foos and Bars
<myref>
#lorem(1000)
For more on foo, see #pageref(<myref>).
There is also a similar question by Goossa and there is a solution by Andrew: https://forum.typst.app/t/how-do-i-make-a-reference-that-inserts-name-of-section-and-page-number/461, and it works. But having 2 working solutions is better than 1, right?