Skip to content

Support read for TypstCommand #14

@GunnarFarneback

Description

@GunnarFarneback

TypstCommand can be used with run to to do most typst tasks. However, for typst query you rather want to fetch the output as well.

julia> using Typstry

julia> write("test.typ", "#figure[]<fig>")
16

julia> run(TypstCommand(["query", "test.typ", "<fig>"]));
[{"func":"figure","body":{"func":"sequence","children":[]},"placement":null,"scope":"column","caption":null,"kind":"image","supplement":{"func":"text","text":"Figure"},"numbering":"1","gap":"0.65em","outlined":true,"counter":"counter(figure.where(kind: image))","label":"<fig>"}]

julia> read(TypstCommand(["query", "test.typ", "<fig>"]), String);
ERROR: MethodError: no method matching read(::TypstCommand, ::Type{String})

At the moment a possible workaround is to dip into some internals.

julia> t = TypstCommand(["query", "test.typ", "<fig>"])
typst`query test.typ <fig>`

julia> read(`$(t.compiler) $(t.parameters)`, String)
"[{\"func\":\"figure\",\"body\":{\"func\":\"sequence\",\"children\":[]},\"placement\":null,\"scope\":\"column\",\"caption\":null,\"kind\":\"image\",\"supplement\":{\"func\":\"text\",\"text\":\"Figure\"},\"numbering\":\"1\",\"gap\":\"0.65em\",\"outlined\":true,\"counter\":\"counter(figure.where(kind: image))\",\"label\":\"<fig>\"}]\n"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions