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
Allow loading of files outside the project folder (in addition to --root) #5382
Assume you have a file structure that shares a template or other common parts:
project/
- common/
- thesis-1/
- thesis-2/
You can run typst compile thesis-1/main.typ --root ~/project/ or symlink parts (= PITA). But you can't import common files in a way that gets rid of the error message (in this case Tinymist). Because the live syntax check (be it Tinymist or any other future solution) can't know what the scope of the project is, as it is not a permanent setting.
Searching in Discord I found a couple of people with the same issue, be it for books, a thesis (split chapters) etc.
Use Case
Having --root as the only option to include files outside the current directory is, to quote another user, a "too basic of a thing not to have". I would agree with that assessment and propose considering a way for permanent relative imports outside the project root.
Reacted by Noah S, Moritz Lenz, Hauke Schnau, Richard Miller-Smith, Sakib Matin, Gtoasted, Henry Wilkinson, schmeisers, Palanix, ShugarSkull and 28 more
Yes please! For out-of-tree builds that integrate with other tools (e.g., something builds an SVG file that is then incorporated into the Typst->PDF build, all within a build directory), a -I option would be invaluable.
changed the title [-]Allow the import of files outside the project folder (in addition to --root)[/-][+]Allow loading of files outside the project folder (in addition to --root)[/+]on Aug 2, 2025
I thought a bit more about this while looking at the --input-file PR and had the following idea: We could have something like --input-path mykey=path/to/file which will add sys.inputs.mykey of type path (which is to be added soon; this would block the design). Then you could use this path like any other. In particular, you could read from it, import/include it, or join strings to it to perform operations relative to a directory that was provided like this. In the directory case, the path would form its own detached root, and the imported Typst file could perform reads relatively & absolutely to that root, but not escape it.
Some examples of what this would enable:
typst c file.typ --input-path config=config.toml -> toml(sys.inputs.config)
typst c file.typ --input-path img=tiger.png -> image(sys.inputs.img)
typst c file.typ --input-path assets=~/assets -> image(sys.inputs.assets + "path/in/asset/dir.svg")
typst c file.typ --input-path graph=~/graph.typ -> include sys.inputs.graph
Reacted by Kelsey Judson, Andreas Kröpelin, Jakob Hellermann, rbq, Graham Taylor, Robin, Clemens Koza, NJ, Rafael Villar Burke (Pachi), Xiretza and 1 more
In the directory case, the path would form its own detached root, and the imported Typst file could perform reads relatively & absolutely to that root, but not escape it.
The general approach sounds really flexible. My first thought or consideration would be whether a somewhat "separate" method of "adding" to the root would truly be equally handled in detail aspects like error handling or code suggestions (such as typing #import "…" where the file name is suggested). My second consideration would be whether the approach could also facilitate adding an entire directory, for example, including the complete subfolder thesis-1/* with chapter-1.typ, chapter-2.typ, etc. My need for this feature didn't primarily arise from importing or adding single external files, as demonstrated in examples like tiger.png or config.toml (although I understand these examples are meant to highlight the approach's flexibility). Instead, it mostly stemmed from managing documents or projects that share common parts or are split up but are not located in a single folder.
My first thought or consideration would be whether a somewhat "separate" method of "adding" to the root would truly be equally handled in detail aspects like error handling or code suggestions (such as typing #import "…" where the file name is suggested).
It could be if the inputs were correctly configured in your language server. It wouldn't be so much adding to the root, but adding a new root. (Packages are already separate roots.)
My second consideration would be whether the approach could also facilitate adding an entire directory, for example, including the complete subfolder thesis-1/* with chapter-1.typ, chapter-2.typ, etc. My need for this feature didn't primarily arise from importing or adding single external files, as demonstrated in examples like tiger.png or config.toml (although I understand these examples are meant to highlight the approach's flexibility). Instead, it mostly stemmed from managing documents or projects that share common parts or are split up but are not located in a single folder.
That would be possible. If you don't know ahead of times, which files are in the folder, you would combine this feature with #2123 (which is planned).
Reacted by Alexander Wörndl, Robin, Kevin Stephen and Nick Eubank
@Xiretza There isn't active work, but this would be too large for a first contribution. If you'd like to contribute, I suggest starting with something small and building up trust with the maintainers and other contributors.
In the directory case, the path would form its own detached root, and the imported Typst file could perform reads relatively & absolutely to that root, but not escape it.
Some examples of what this would enable:
typst c file.typ --input-path config=config.toml -> toml(sys.inputs.config)
typst c file.typ --input-path img=tiger.png -> image(sys.inputs.img)
typst c file.typ --input-path assets=~/assets -> image(sys.inputs.assets + "path/in/asset/dir.svg")
typst c file.typ --input-path graph=~/graph.typ -> include sys.inputs.graph
What is the advantage of doing this over letting paths work normally (as in: the Rust module will resolve it using OS APIs), first filtered by a path whitelist at the document input level ? The whitelist would be set via CLI in a similar way you described. Absolute path would work and be safe on Unix-like (instead of allowing everything) or work at all (Windows). Relative paths would'n be affected. Both at the same time. Sounds like a simpler solution working around edge cases (because you let the OS handle its path), and real-world use cases described in multiple instances made possible (I have one as well). In this instance: the language server would have valid paths in source documents to follow.
What am I missing? Questioning in #4195 was never answered.
@toine512 A Typst document has multiple roots: The project root and package roots. Absolute paths refer to the root of the project and package folder respectively, depending on where they are used. Using normal OS path semantics would mean there is fundamentally just one root: The real file system's root. It would be somewhat strange how to interpret absolute paths in packages. Of course, they could also be relative to disk root, but that would not feel ideal to me as a package doesn't really have any business in reading from your OS root.
Meanwhile, both absolute and relative paths have a useful definition in terms of a project. You could use include "chapter1.typ" as a relative path, but use image("/assets/image.jpg") from anywhere in your project to consistently refer to the assets folder in the project root.
These semantics obviously present a trade-off compared to using absolute paths to refer to the real file system's root. But I think it's a worthwhile trade-off as it encourages use cases to be safe and reproducible across different machines, which is a requirement as soon as multiple people work on a project.
The proposed --input-path mechanism is a natural extension to the existing roots mechanism that makes any potential irreproducible use case explicit. And it's also not really more annoying to use than an explicit white list. Meanwhile, using absolute paths to refer to the OS disk root would leave the absolute path syntax useless without an explicit whitelist.
Activity
trombonehero commentedon May 6, 2025
Yes please! For out-of-tree builds that integrate with other tools (e.g., something builds an SVG file that is then incorporated into the Typst->PDF build, all within a
builddirectory), a-Ioption would be invaluable.terefang commentedon May 13, 2025
for some usecases it might even be more beneficial to have a search path similar to #6190
[-]Allow the import of files outside the project folder (in addition to --root)[/-][+]Allow loading of files outside the project folder (in addition to --root)[/+]laurmaedje commentedon Aug 4, 2025
I thought a bit more about this while looking at the
--input-filePR and had the following idea: We could have something like--input-path mykey=path/to/filewhich will addsys.inputs.mykeyof typepath(which is to be added soon; this would block the design). Then you could use this path like any other. In particular, you could read from it, import/include it, or join strings to it to perform operations relative to a directory that was provided like this. In the directory case, the path would form its own detached root, and the imported Typst file could perform reads relatively & absolutely to that root, but not escape it.Some examples of what this would enable:
typst c file.typ --input-path config=config.toml->toml(sys.inputs.config)typst c file.typ --input-path img=tiger.png->image(sys.inputs.img)typst c file.typ --input-path assets=~/assets->image(sys.inputs.assets + "path/in/asset/dir.svg")typst c file.typ --input-path graph=~/graph.typ->include sys.inputs.graphwget https://data.org/data.json | typst c file.typ --input-path data=-(stdin) ->json(sys.inputs.data)terefang commentedon Aug 5, 2025
wow!
could
--input-path var=... --input-path var=...be used to make an array ?laurmaedje commentedon Aug 5, 2025
That feels a bit implicit to me, but it'd be easy to write Typst code that turns
--input-path var1=... --input-path var2=...into an array.terefang commentedon Aug 6, 2025
maybe
--input-path var[]=... --input-path var[]=...?woerndl commentedon Aug 6, 2025
The general approach sounds really flexible. My first thought or consideration would be whether a somewhat "separate" method of "adding" to the root would truly be equally handled in detail aspects like error handling or code suggestions (such as typing
#import "…"where the file name is suggested). My second consideration would be whether the approach could also facilitate adding an entire directory, for example, including the complete subfolderthesis-1/*withchapter-1.typ,chapter-2.typ, etc. My need for this feature didn't primarily arise from importing or adding single external files, as demonstrated in examples liketiger.pngorconfig.toml(although I understand these examples are meant to highlight the approach's flexibility). Instead, it mostly stemmed from managing documents or projects that share common parts or are split up but are not located in a single folder.laurmaedje commentedon Aug 6, 2025
It could be if the inputs were correctly configured in your language server. It wouldn't be so much adding to the root, but adding a new root. (Packages are already separate roots.)
That would be possible. If you don't know ahead of times, which files are in the folder, you would combine this feature with #2123 (which is planned).
Xiretza commentedon May 11, 2026
(#5382 (comment))
Is there implementation work for this already? If not, would it make sense for me to start working on it?
laurmaedje commentedon May 12, 2026
@Xiretza There isn't active work, but this would be too large for a first contribution. If you'd like to contribute, I suggest starting with something small and building up trust with the maintainers and other contributors.
toine512 commentedon Jul 13, 2026
Hi,
What is the advantage of doing this over letting paths work normally (as in: the Rust module will resolve it using OS APIs), first filtered by a path whitelist at the document input level ? The whitelist would be set via CLI in a similar way you described. Absolute path would work and be safe on Unix-like (instead of allowing everything) or work at all (Windows). Relative paths would'n be affected. Both at the same time. Sounds like a simpler solution working around edge cases (because you let the OS handle its path), and real-world use cases described in multiple instances made possible (I have one as well). In this instance: the language server would have valid paths in source documents to follow.
What am I missing? Questioning in #4195 was never answered.
laurmaedje commentedon Sep 12, 2026
@toine512 A Typst document has multiple roots: The project root and package roots. Absolute paths refer to the root of the project and package folder respectively, depending on where they are used. Using normal OS path semantics would mean there is fundamentally just one root: The real file system's root. It would be somewhat strange how to interpret absolute paths in packages. Of course, they could also be relative to disk root, but that would not feel ideal to me as a package doesn't really have any business in reading from your OS root.
Meanwhile, both absolute and relative paths have a useful definition in terms of a project. You could use
include "chapter1.typ"as a relative path, but useimage("/assets/image.jpg")from anywhere in your project to consistently refer to theassetsfolder in the project root.These semantics obviously present a trade-off compared to using absolute paths to refer to the real file system's root. But I think it's a worthwhile trade-off as it encourages use cases to be safe and reproducible across different machines, which is a requirement as soon as multiple people work on a project.
The proposed
--input-pathmechanism is a natural extension to the existing roots mechanism that makes any potential irreproducible use case explicit. And it's also not really more annoying to use than an explicit white list. Meanwhile, using absolute paths to refer to the OS disk root would leave the absolute path syntax useless without an explicit whitelist.