How to handle error catching within a typst document?

My particular use case is inserting images from a list, if they exists, if they don’t exist then do nothing.

#let list = ("A","B","C")

#for v in list [
  // how to catch and ignore error if image do not exist (path is invalid)
  #image("graphic/" + v + ".jpg")
]

I have tried to play around with #assert and #panic but to no avail.

Thanks in advance for the help! It is really appreciated!

Hey,
As far as I know, this is not possible.

Maybe you can try this snippet: Try & Catch - Typst Examples Book (please note the “don’t try this at home”)

A solution is to do the verifying yourself or with a script beforehand and pass the valid files via the --input argument to the Typst file (docs: System Functions – Typst Documentation)


I highly recommend to only use assets which are available to you in a Typst project either from yourself or from packages, instead of relying on a try-catch basis. Meaning, if you provide content through a script or similar, name it accordingly and work with the --input parameter provided by the Typst app.

Typst at the end of the day is a type-setting system.