Skip to content

Pageref in Typst like it exists in LaTeX #2873

@Smightym8

Description

@Smightym8

Description

A possibility to get the page number when referencing an image or table would be good. Below is my own implementation that I use in Typst right now. It takes the label text and tries to find the label in the document. If the label is found it determines the page number of the label and formats it as a link to the label. In case the label is not defined it throws an error so it is not possible to compile the document with unresolved references when using pageref.

#let pageref(labelText) = {
  locate(loc => {
    let label = label(labelText)
    let elems = query(selector(label), loc)

    if elems.len() == 1 {
      let pageNumber = elems.at(0).location().page()
      link(label, str(pageNumber))
    } else {
      let errorMessage = "Label '" + labelText + "' is not defined"
      panic(errorMessage)
    }
  })
}

Use Case

Sometimes it can be handy to reference the page number in a document for example "As you can see in fig. x on page y".

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or requestmodelRelated to model category, which is all about structure and semantics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions