Typst Page Number References

Here is how to get the page number of a label elsewhere in your document in typst:

#let get_page_number = q => locate(query_token => counter(page).at(query(q, query_token).at(0).location()).at(0))

Example usage:

== Forest<forest>
This is a forest, with trees in all directions. To the east, there appears to be sunlight.

To go north, go to page #get_page_number(<clearing>).\
To go south, go to page #get_page_number(<south_forest>).\
To go east, go to page #get_page_number(<forest_path>).
#pagebreak(to: "even")

== Clearing<clearing>
You are in a clearing, with a forest surrounding you on all sides. A path leads south.

Complete concrete example: typst source and compiled pdf.

Six pages of a Gamebook showing three fantasy world locations and directions for moving to other locations by turning to other page numbers

(LaTeX calls this \pageref)