typst / packages

Packages for Typst.
Apache License 2.0
529 stars 326 forks source link

Support multiple templates per package #1059

Closed LasseRosenow closed 1 week ago

LasseRosenow commented 1 week ago

Description

Hello I am the maintainer of the haw-hamburg package.

Background

My package exposes multiple templates as functions to make setup easy:

bachelor-thesis, master-thesis and report.

Problem

If I am not mistaken as of now Typst only allows me to set one specific template folder that contains the files that will be copied if the user clicks on the Create project in app button.

What I would wish for is that I can specify multiple template folders for my 3 flavors.

Possible Solution

A UX/UI solution on the Web App could be that for example if the user clicks on the Create project in app button and there are multiple templates specified, maybe a drop down menu appears that allows to choose between bachelor-thesis, master-thesis and report.

LasseRosenow commented 1 week ago

Alternative Solution

Another solution is that I could just specify templates with more concrete names that have a dependency on the haw-hamburg package?

So we could have the following structure:

Package:

Template:

In theory this could already be done by just putting the templates in separate packages. If you think this is a good solution maybe revert my haw-hamburg:0.2.0 PR. Because I just added the haw-hamburg template in there which maybe not desirable from this perspective.

But the big question here is also: Is it allowed to publish templates without a library dependency? So in this way seeing the template only as a bootstrapping tool that creates you the files that then depend on another (haw-hamburg) package?

elegaanz commented 1 week ago

I don't think we want to support multiple templates per package, and all templates must also be packages, even if their package code is empty or just re-exports from other packages. So something similar to what you suggested would be the best solution:

jamesrswift commented 1 week ago

It would become a pain to update all the templates individually when the package is updated - I think several templates per package is a good idea without any downsides that I can think of

elegaanz commented 1 week ago

The templates can still live in the same repository outside of Universe, which would make updating them more convenient I think. And all the updates can be submitted as one PR to this repository.

The main downside is on Typst's side to be honest, we would have to rework the compiler and Universe to support that feature. It is not that big, but I also don't see many people needing it, so I'm not sure it is worth the effort, given there is this relatively simple alternative. Ideally, it should be done in a way that is backwards compatible as well, and I'm not sure that's easy to do (we don't want people running an old compiler version to see the package index broken). I also like the simplicity of the current design, where one package = one template.

So it's not a hard no, but more that it's not a priority for now. We can always reconsider later if there is more demand for this feature.