Preview of multiple pages document in VS code using Typstry.jl

I’m looking for a way to deal with multiple pages preview when using Typstry.jl in VS code with the Julia extension (using PrettyTables typst backend in this example just for fun).

# Init
using Typstry, PrettyTables, DataFrames
io = IOBuffer()
pretty_table(io,DataFrame(a=1:15),backend = :typst)
pt_df = String(take!(io))

If I create a single “A4” page document with height:auto, I can see the preview in the Julia Plots but the generated PDF will be an unusable single page document :

single_page_doc = TypstString(TypstText("""
#set page("a4", height:auto)
$pt_df
#lorem(500)
"""))
render(single_page_doc;input="ok.typ",output="ok.pdf",open=false)

If I want a document with more than 1 page (without height: auto), there’s no preview of the document in Julia Plots since a TypstCommandError is thrown, but the PDF will be fine with multiple pages :

# ERROR: TypstCommandError: failed to run a `TypstCommand (["compile", "--font-path", "....julia/artifacts/...", "--format", "png", "-", "-"])
multiple_page_doc = TypstString(TypstText("""
#set page("a4")
$pt_df
#lorem(500)
"""))
render(multiple_page_doc;input="bug.typ",output="bug.pdf",open=false)

So now I’m setting the page’s height to auto to have a preview and remove it when I want to render the final PDF…
Is there a better way to have a multiple page preview working using Typstry.jl in VS code without using other typst extension ?

VSCode does this natively using a terminal emulator. Not all support graphic rendering in the first place and AFAIK none of those that do are able to cope reliably with multipage images. The pdf comes in as stdio in a l o o o n g string. stream of pixels so the buffer gets clobbered. I’ve heard tell that Some terminals implement protocols that enable direct image rendering. Some terminals implement protocols that enable direct image rendering. I’ve seen reports that VSCode extensions like PDF Viewer (by mathematic) or PDF Preview embed Mozilla’s pdf.js library right into the IDE. This gives you a native-feeling PDF reader with full layout controls, a sidebar index, smooth scrolling, and text highlighting, completely bypassing the terminal’s limitations. For my money if composing in VSCode or another IDE running a Typst watch command is the process to display on save in a different window is the way to go.

Hi there! I ran the code you provided in a new environment and am unable to reproduce the error. Would you be able to provide a script that produces the error you describe? I’m happy to help :slight_smile:

(@v1.12) pkg> activate --temp
  Activating new project at `/tmp/jl_wpoM7S`

(jl_wpoM7S) pkg> add Typstry, DataFrames, PrettyTables
   Resolving package versions...
    Updating `/tmp/jl_wpoM7S/Project.toml`
    ...

julia> using Typstry, PrettyTables, DataFrames

julia> io = IOBuffer();

julia> pretty_table(io,DataFrame(a=1:15),backend = :typst)

julia> pt_df = String(take!(io));

julia> single_page_doc = TypstString(TypstText("""
       #set page("a4", height:auto)
       $pt_df
       #lorem(500)
       """));

julia> render(single_page_doc;input="ok.typ",output="ok.pdf",open=false)

julia> multiple_page_doc = TypstString(TypstText("""
       #set page("a4")
       $pt_df
       #lorem(500)
       """));

# this did not error for me
julia> render(multiple_page_doc;input="bug.typ",output="bug.pdf",open=false)

but the PDF will be fine with multiple pages

Oh, is it that the PDF renders (as my attempt shows) but some other environment throws the error? Could you elaborate on that? I do not use VSCode and do not know where to look.