For a personal project I’m trying to find a way to automate the import process.
I noticed that Typst doesn’t seem to support something like import folder/*.typ to import all files in a directory. Is there any way to achieve this directly, or is it a planned feature?
Can Typst’s web app environment execute a Python script (or other scripting language) to automate the generation of imports in main.typ? For instance, a script that scans a folder and dynamically adds import statements to the main file?
Alternatively would it be possible to use a Python script to generate a list of names .typ and then use for loop within main.typ to include all those files?
Are there any other methods or best practices for managing a large number of imports efficiently in Typst without clearly knowing the file name?
If anyone has experience with this or ideas on how to approach it, I’d greatly appreciate your insights. I suppose it would be quite a security constraint to be able to run arbitrary code on remote machine. Thanks in advance for your help!
Edit2: In this post, I mistakenly provided an answer for include instead of import.
Hi @Alex,
as you have already discovered, this is not currently possible, but I believe it will be in the future. There is an open issue regarding this.
Typst’s web app and Typst itself cannot execute any scripts, you would have to run the script externally and provide the output to Typst.
Yes, I believe the best approach would be to use Python to generate the list and then include the items via a loop. You can use read to read the file.
#let include-files(file-list) = {
let files = read(file-list).split("\n")
for file in files {
include file
}
}
#include-files("file-list.txt")
Edit: I just saw you wrote import, I guess you mean include (documentation)?