Last active
June 4, 2025 05:56
-
-
Save baptiste/c9f1c885445e44a23017ec43b3d25c76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## query sizes | |
typst query test.typ --input strings='["foo", "$ alpha = beta / (gamma + x^2)$"]' '<dimensions>' --field value | |
## produce images | |
typst compile test.typ --input strings='["foo", "$ alpha = beta / (gamma + x^2)$"]' '{p}.svg' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#let test-strings = ` | |
["0", "0.5", "1", "Typst"] | |
`.text | |
#let strings = sys.inputs.at("strings", default: test-strings) | |
#let strings = json(bytes(strings)) | |
#let strings = strings.map(s => eval(s, mode: "markup")) | |
#let measurements(body) = context { | |
let (width, height) = measure({ | |
set text(top-edge: "bounds", bottom-edge: "bounds") | |
body | |
}) | |
let ascender = measure({ | |
set text(top-edge: "ascender", bottom-edge: "baseline") | |
body | |
}).height | |
let descender = measure({ | |
set text(top-edge: "baseline", bottom-edge: "descender") | |
body | |
}).height | |
let dimensions = (height: height, width: width, descender: descender, ascender: ascender) | |
[#metadata(dimensions)<dimensions>] | |
} | |
#set page(width: auto, height: auto, margin: 0pt) | |
#set text(top-edge: "bounds", bottom-edge: "bounds") | |
#for string in strings { | |
measurements(string) | |
string | |
pagebreak() | |
} | |
// for debugging only | |
#context query(<dimensions>).map(m => m.value) |
Author
baptiste
commented
Jun 4, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment