Repository navigation
Read font path from environment variables - #649
Conversation
|
Before proceeding with this, I would like to take a step back and discuss which kinds of use cases people have and whether they are best handled with env var, CLI flag, or something in the Typst file itself. This is of course a simple change, but once people start relying on it, it's not easy to take it away again. Therefore, I want to be sure we are making the right choice here. The env var solves certain problems with the CLI flag (which I might have merged to quickly), but maybe listing the font dirs in the Typst file itself would be even better for certain cases? The use case you describe where you set a global font path seems to me as if the font should just be installed on the system. If Typst doesn't find certain system fonts currently that's something we have to fix. |
|
I see your point. In my use case, having a typst instruction that points to the relative file path (probably
|
|
Okay, I feel like I haven't elaborated on the Docker part well enough, even though that's probably the most important use case. Usecase 3.1Imagine some Docker container that either runs typst directly or has some application executing typst (like some invoicing app, generating invoices with typst). In that app, everything can be customized using the web interface, but of course, you cannot install system fonts - since you can only change configuration via the web interface. In this case, we can assume the Docker container is a black box since we don't want to create a custom Dockerfile and build it (all sorts of stuff could go wrong there). So what can we do? Simply mount your fonts to docker run -it --rm -v /home/michi/fonts:/fonts -e TYPST_FONT_DIR=/fonts some-typst-appThis is especially useful in Kubernetes or cloud environments like AWS Fargate, since I can deploy a given Docker container with custom fonts. Usecase 3.2A second use case (one I personally have) is devcontainers. I use them in combination with vs code to develop stuff without installing different versions of SDKs or other software. I use some arbitrary base OS like Ubuntu and then use the typst layer to setup typst: devcontainer config{
"name": "Ubuntu",
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/guiyomh/features/just:0": {},
"ghcr.io/michidk/devcontainers-features/typst:0": {}
},
"customizations": {
"vscode": {
"extensions": [
"nvarner.typst-lsp",
"tomoki1207.pdf",
"zengfanfan.zeng-color-picker"
]
}
}
}With environment variables this gets very easy. The devcontainer config: {
"name": "Ubuntu",
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/guiyomh/features/just:0": {},
"ghcr.io/michidk/devcontainers-features/typst:0": {}
},
"mounts": [
"source=/home/michi/fonts,target=/fonts,type=bind"
],
"containerEnv": {
"TYPST_FONT_DIR": "/fonts"
},
"customizations": {
...
}
} |
|
Hoping for a more detailed description about this ENV variable, e.g. WHAT is the expected seperator when there is more than one path; Which directory level should this PATH point to, 'xxx/share/fonts/opentype/SourceCodePro-Black.otf' or 'xxx/share/fonts/opentype' or 'xxx/share/fonts' ? |
Hallo 😃,
It would be great if we could read font paths from the environment variables (env vars).
Advantages:
This change enables the "env" feature of clap, which handles the env parsing for us. Command line arguments will take precedence over env vars.