Is there a way to set the output file name within a .typ-file? I couldn’t find anything about that in the documentation.
In my use case I have a file that contains tasks and solutions. Depending on a variable that determines if the solutions are shown or not, it would be helpful to have different output file names. Of course one can easily just rename it but for further automation it would be helpful. If this feature does not exist I think it would be a good addition.
Hey there, welcome to the forum!
You can’t influence the file name from within Typst, for one, because there may not be a file at all, or there may be multiple, but also because this makes scripts less predictable.
If you want to have different versions for output with and without solutions you should provide the necessary inputs and file names to the command line, possible with some automation too like make
, just
or similar.
Thank you for the response. While it’s a bit inconvenient because now I’ll need separate files (scripts etc.), I understand it makes sense to only have one place where output-parameters are defined.
I have the same workflow for my tutorial. I define a flag in the main document that shows or hides the solution. Actually, I just use:
typst compile main.typ tasks.pdf // for tasks and solution hidden
typst compile main.typ solution.pdf // for solution (+ task)
Because Typst compilation is fast, it is almost painless.
Using sys.inputs
, you could have this
typst compile main.typ tasks.pdf --input=solution=false // for tasks and solution hidden
typst compile main.typ solution.pdf --input=solution=true // for solution (+ task)
without manually (un)setting the flag (or use sed).
Related: Can I configure my document (e.g. draft/release version, color theme) when creating a PDF without modifying the Typst file directly?