Extending the universe - gotpm v0.5.0

I am sorry to disappoint you guys, but I did not build another typst editor instead I have been working on my package manager.

You can now use gotpm to declare dependencies, that are not part of the typst Universe, and use them in your project. Basically any repository on GitHub, Gitlab or another Host can be regarded as a package, that you can use in your project.

Let’s assume you want to use the foobar package that can be found on github.com/foo/bar. You then want to run

gotpm add github.com/foo/bar -t v0.1.2

The package then will be installed for you and the import statement will be noted in the typst.toml file.

[tool.gotpm]
dependencies = [
  "@gotpm/foobar:0.1.2",
]

You can import the package from GitHub in your typst files like so:

#import "@gotpm/foobar:0.1.2": *

The exact sources, from where you added a dependency will be in a lock file.
If another person then wants to compile your Typst project the lock file will be used to install all dependencies for that person. The sync command will do exactly that.

gotpm sync

If you want to install a package just for yourself, without declaring a typst.toml file you might want to use:

gotpm install -r github.com/foo/bar

If your goal is to contribute packages and templates to typst/packages the publish command might make your life easier. For me it was always a struggle to keep the repo of a template I was maintaining in sync with my fork of typst/packages , because in my case Github Actions would commit on my behalf to the fork. Therefore it was a mess when I needed to change something during the review process.

Now I am using the following workflow. I would first set the url to my fork of typst/packages once per machine like so.

gotpm config set fork.url git@github.com:user/typst-packages

And whenever I now want to release a new version of a template I would run the following from the root of the project I want to put onto the typst universe.

gotpm publish

This would then

  • clone the fork onto the machine
  • do a sparse checkout to my package
  • checkout the correct branch
  • package all relevant files, that are not ignored or excluded, into the correct directory
  • commit the changes
  • and finally push to the remote

If you then need to change files during the review process simply commit them in your repo, and run publish again. The last commit message will be preserved.

Maybe this makes your life easier. If so I would love to hear your feedback, and how we/I could improve the tool.

10 Likes

Some updates… I have added some new features you guys might find helpful. Two of the bigger changes I want to show here briefly.

First up you can run pre- and post-publish hooks, which you can use to compile thumbnails and manuals for example. This helps you reduce the amount of binary files in your git repo.

This feature uses an embedded shell, which makes the hooks cross-platform compatible. All the basic Bash commands are supported.

# typst.toml
[tool.gotpm]
pre-publish-hook = ["typst compile thumbnail.typ thumbnail.png"]
post-publish-hook = ["rm thumbnail.png"]

Secondly, an unreleased feature (currently only available when building from source, but will probably be released soon), for managing fonts.

$gotpm font add "JetBrains Mono"

This will embed the used font as metadata in the `typst.toml` and `gotpm.lock` files. Running the `sync` command will then download and install the font.

This currently only supports fonts from Google Fonts.

For typst to find the fonts make sure that you set the environment.

$echo 'export TYPST_FONT_PATHS="$(gotpm locate fonts)"' >> ~/.bashrc
1 Like