How to export locations through command line query?

I am experimenting with preparing a checklist, and then being able to scan the print and identify whether particular items are checked off. (Think poor man’s optical multiple choice bubble sheets.)

To draw and locate the circle is straight-forward:

#circle(radius: 10mm)<my_circle>

#context [
  circle location: #locate(<my_circle>).position()
]<circle_locator>

However, when I introspect from the command-line using typst query test.typ "<circle_locator>", hoping to be able to pick out a value, it only returns that <circle_locator> is a context.

[{
    "func":"context", 
    "label":"<circle_locator>" 
}]

I then tried a variety of more and more contorted wrap in metadata and so on, but it seems what’s inside the context is completely opaque.

Is there a way to pull out location of objects on the command line query?

Hi, the following should work:

#circle(radius: 10mm)<my_circle>

#context [
  // Just wrap it inside anything that can be queried
  #metadata(
    (
      circle-location: locate(<my_circle>).position()
    )
  )<circle_locator> // Moved the label inside of the context block
]

Giving the following output:

typst query tmp.typ '<circle_locator>'
[{
  "func" : "metadata",
  "value" : {
    "circle-location" : {
      "page" : 1,
      "x" : "70.87pt",
      "y" : "70.87pt"
    }
  },
  "label" : "<circle_locator>"
}]
2 Likes

Thank you!

What is the inner parenthesis doing inside the metatdata()?

The inner expression creates a dictionary, in this case with the single key circle-location. I was just mimicking the text you had before. You could also put the location directly into the metadata.

1 Like