#Generating multiple versions of a single document
21 messages · Page 1 of 1 (latest)
Hello. I have a document that I'd like to repeat multiple times ( e.g. https://typst.app/project/r9kdslbzmZQKLQ6Re3TSSh ) but changing specific values inside (let's say variables)
The thing is that currently, as the project function defines various page variables, and as I have a "shared" state, repeating simply the content will not cut it
So, you want to generate many almost identical documents (say, separate PDFs) from the same source?
yes, also by changing things a bit (randomizing stuff, passing variables)
(I can do that using CLI, probably, but maybe there is a way to do that on the web too)
Oh okay
I was gonna suggest using the cli for this cuz it would be easier
Sys.inputs lets you pass cli parameters as variables
And with a script you can run the Typst compile command multiple times with different values
The web app doesn't support sys.inputs directly, but either way that wouldn't be very helpful since u can't run a script to automate the web app
Generally in the web app you just specify the variable's value directly (e.g. if the sys.inputs.name is missing , use this default value instead) since u can modify the source easily
Still that wouldn't be that helpful if u have many students or otherwise many compilations to make
Regarding randomization, you can pass an external seed through sys.inputs and use that in some simple pseudo-random function (e.g. LCG)
thanks, i'll look at that
Let me know if you need help with the script or with such a function
@slim plover Do you know if it's possible to create a pdf with a different name while compiling with different sys.inputs? I want to have a print and a digital version of my document and it would be very convenient to create two pdfs instead of overwrite the compiled one.
Sure, sys.inputs is a global variable , so you can use it for #set document(name: use it here)
Ah very nice thank you! But it's not changing the file name of my pdfs, just the pdf meta data. Is this also possible?
you can set the output name on the command line: typst compile a.typ b.pdf