Is it possible to get the page number given a cursor location within typst source code?

I’m trying to set up some workflow tooling, trying to replicate the jump_from_cursor logic from Typst’s web IDE where I display only the rendered typst page where my (personal) IDE cursor position is.

Two approaches I’ve tried:

  1. Tried looking for some arguments to pass my IDE cursor position either into typst.exe compile to only render that page, or into typst.exe query to extract the page number, so then I could pass it to typst.exe compile.

Unfortunately doesn’t look like anything exists.

  1. Inject some Typst code (such as a label or some metadata) at/or near my IDE cursor beforehand, then use typst.exe query to extract out it’s page location to use with typst.exe compile.

While this approach works, it’s hacky and very fragile, since it’s pretty easy to create uncompile-able code without being clever about where you inject this code in.

Eg. I’ve tried injecting #context[ #here().page() <cur>] at the closest empty line to my cursor, but this breaks if that’s within a code block.

Is there a non-hacky way to accomplish what I want to do?

hello! Not answering your question but if you are looking to get the source/preview jump from Typst’s web IDE, there exists a preview feature in tinymist which does that. Clicking on source leads you to that location in the preview, and vice-versa.

See also: