Skip to content

Include files outside of the project root via CLI #5978

Closed as duplicate
Closed as duplicate

Description

@jmpunkt

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.

Activity

  1. T0mstone commented on Feb 28, 2025

    @T0mstone
    Contributor

    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.

  2. added
    cli
    change request
    on Feb 28, 2025
  3. laurmaedje commented on Apr 2, 2025

    @laurmaedje
    Member

    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.

  4. T0mstone commented on Apr 3, 2025

    @T0mstone
    Contributor

    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.

  5. jmpunkt commented on Apr 3, 2025

    @jmpunkt
    Author

    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?!

  6. leggewie commented on May 11, 2025

    @leggewie

    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.

  7. added
    feature request
    and removed
    change request
    on Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clifeature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions