How to add content to page using the crate in web assembly?

You should definitely avoid generating a very long piece of Typst source code (see e.g. Why does Typst crash with large amounts of content?), but there is an alternative other than creating the Typst data structures directly in Rust code; you can load the JSON file into Typst and use Typst scripting to create the document.

In LaTeX it may seem natural to use code generation when trying to incorporate external data into a document, but in Typst it’s actually very easy to use scripting for that purpose, and being able to generate large documents from external data is IMO one of the main use cases for Typst. See data-loading for other relevant topics.

I would definitely at least attempt using “regular” Typst here, and only drop down to Rust if it’s measurably too slow, since you’re losing a lot of versatility when making that switch.

1 Like