You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Include files outside of the project root via CLI #5978
In https://github.com/jmpunkt/ox-typst/ we are using Typst to generate PDF files from Org files (by generating Typst first). We are facing a limitation with the project root limitations. In Org there are many ways to specify files. These file can also be outside of the project root, and they most of the time do that. In our case the project root is always the same directory where the Org file is located. There are ways to workaround these issue, but they seem unintended.
Feature
I was looking for something like --input but for files. So the user would specify an input file in CLI and Typst would read that file and generate a variable which contains the content of the file. Now that Typst 0.13 can work with either a path or the file content directly (which is a beautiful addition), these two should be complement each other perfectly.
How does it work?
So lets say I have a file ~/test.txt. I want the file to be part of my Typst file ~/workspace/typst-project/test.typ. I would expect the Typst file to look something like this
#raw(str(sys.files.test))
Now this file would be compiled like this.
cd~/workspace/typst-project/
typst c --input-file test=~/test.txt test.typ
As a result, we would be able to include files outside of the project root. Since this a manual process, I do not see any security issues for now.
Rational
You may ask why we need this feature, when we can use the path/bytes feature introduced in Typst 0.13.
For everything text based this would work pretty well. When you start including Images, things do not look promising. It is not feasible to generate a Typst files which embeds an Image in the megabyte size. For me, including these files via the CLI seems like a reasonable and elegant solution without breaking the project root.
I like your idea (tho it should probably be called sys.input-files for consistency), but I just want to point out that using symlinks is easy and arguably more natural.
OTOH, configurable input files might also just be benefitial in general, with the same rationale as the regular text inputs.
For text files, you can also do typst c hi.typ --input "key=$(cat file.txt)". For binary data, this would require some sort of encoding, e.g. base64. Still possible though, in principle.
For text files, you can also do typst c hi.typ --input "key=$(cat file.txt)".
I think typst c isn't the thing to think about here, but rather typst w. Because it'd have to update when file.txt is changed, and I'm not sure if the "cat into --input" approach would to that.
For text files, you can also do typst c hi.typ --input "key=$(cat file.txt)". For binary data, this would require some sort of encoding, e.g. base64. Still possible though, in principle.
This would only work for smaller files and only on *nix systems. To my knowledge, there is a limit for shell commands in bytes. I would really like to see this kind of functionality working across operating systems with the same interface.
I think typst c isn't the thing to think about here, but rather typst w. Because it'd have to update when file.txt is changed, and I'm not sure if the "cat into --input" approach would to that.
When reading files with the built-in methods, the file re-compiles?! Then we also have to match this functionality here?!
Activity
T0mstone commentedon Feb 28, 2025
I like your idea (tho it should probably be called
sys.input-filesfor consistency), but I just want to point out that using symlinks is easy and arguably more natural.OTOH, configurable input files might also just be benefitial in general, with the same rationale as the regular text inputs.
laurmaedje commentedon Apr 2, 2025
For text files, you can also do
typst c hi.typ --input "key=$(cat file.txt)". For binary data, this would require some sort of encoding, e.g. base64. Still possible though, in principle.T0mstone commentedon Apr 3, 2025
I think
typst cisn't the thing to think about here, but rathertypst w. Because it'd have to update whenfile.txtis changed, and I'm not sure if the "catinto--input" approach would to that.jmpunkt commentedon Apr 3, 2025
This would only work for smaller files and only on *nix systems. To my knowledge, there is a limit for shell commands in bytes. I would really like to see this kind of functionality working across operating systems with the same interface.
When reading files with the built-in methods, the file re-compiles?! Then we also have to match this functionality here?!
leggewie commentedon May 11, 2025
at the very minimum, do the maintainers the favor of searching through open tickets. this is a duplicate of #5382
please close this ticket and discuss this in #5382 instead. thank you.