Skip to content

Commit 26bd582

Browse files
reknihlaurmaedje
andauthored
Add template bundling and first templates (typst#394)
Co-authored-by: Laurenz <[email protected]>
1 parent ec48802 commit 26bd582

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3323
-57
lines changed

.github/pull_request_template.md

+5
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ I have read and followed the submission guidelines and, in particular, I
2525
- [ ] have chosen a license and added a `LICENSE` file or linked one in my `README.md`
2626
- [ ] tested my package locally on my system and it worked
2727
- [ ] `exclude`d PDFs or README images, if any, but not the LICENSE
28+
29+
<!--
30+
The following box only needs to be checked for **template** submissions. If you're submitting a package that isn't a template, you can delete the following section. See the guidelines section about licenses in the README for more details.
31+
-->
32+
- [ ] ensured that my package is licensed such that users can use and distribute the contents of its template directory without restriction, after modifying them through normal use.

CATEGORIES.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Typst Package Categories
2+
Categories help users explore packages, make finding the right one easier, and
3+
provide package authors with a reference for best-practices in similar packages.
4+
In addition to categories, packages can also specify a list of [disciplines]
5+
describing their target audience.
6+
7+
Each package can declare itself a part of up to three categories.
8+
9+
There are two kinds of package categories: Functional categories that describe
10+
what a package does on a technical level and publication categories that
11+
describe for which kind of deliverable a package may be used.
12+
13+
Package authors are not required to pick a category from each of the two
14+
groups. Instead, they can omit one group completely if it is not applicable to
15+
their package, or use two categories for another group. Publication categories,
16+
for example, are of big relevance to template packages and less so to a general
17+
utility package that may apply to most publication kinds.
18+
19+
## Functional Categories
20+
- **`components`:** Building blocks for documents. This includes boxes, layout
21+
elements, marginals, icon packs, color palettes, and more.
22+
- **`visualization`:** Packages producing compelling visual representations of
23+
data, information, and models.
24+
- **`model`:** Tools for managing semantic information and references. Examples
25+
could be glossaries and bibliographic tools.
26+
- **`layout`:** Primitives and helpers to achieve advanced layouts and set up a
27+
page with headers, margins, and multiple content flows.
28+
- **`text`:** Packages that transform text and strings or are focused on fonts.
29+
- **`languages`:** Tools for localization and internationalization as well as
30+
dealing with different scripts and languages in the same document.
31+
- **`scripting`:** Packages/libraries focused on the programmatic aspect of
32+
Typst, useful for automating documents.
33+
- **`integration`:** Integrations with third-party tools and formats. In
34+
particular, this includes packages that embed a third-party binary as a
35+
plugin.
36+
- **`utility`:** Auxiliary packages/tools, for example for creating
37+
compatibility and authoring packages.
38+
- **`fun`:** Unique uses of Typst that are not necessarily practical, but
39+
always entertaining.
40+
41+
## Publication Categories
42+
- **`book`:** Long-form fiction and non-fiction books with multiple chapters.
43+
- **`report`:** A multipage informational or investigative document focused on
44+
a single topic. This category contains templates for tech reports, homework,
45+
proposals and more.
46+
- **`paper`:** A scientific treatment on a research question. Usually published
47+
in a journal or conference proceedings.
48+
- **`thesis`:** A final long-form deliverable concluding an academic degree.
49+
- **`poster`:** A large-scale graphics-heavy presentation of a topic. A poster
50+
is intended to give its reader a first overview over a topic at a glance.
51+
- **`flyer`:** Graphics-heavy, small leaflets intended for massive circulation
52+
and to inform or convince.
53+
- **`presentation`:** Slides for a projected, oral presentation.
54+
- **`cv`:** A résumé or curriculum vitæ presenting the author's professional
55+
achievements in a compelling manner.
56+
- **`office`:** Staples for the day-to-day in an office, such as a letter or an
57+
invoice.
58+
59+
[disciplines]: https://github.com/typst/packages/blob/main/DISCIPLINES.md

DISCIPLINES.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Typst Package Disciplines
2+
Disciplines define the target audience of a package, making it easy for users to
3+
discover domain-specific packages and templates. Not all packages are
4+
domain-specific, those can simply omit the `disciplines` key from their
5+
manifest. In addition to disciplines, packages can also specify a list of
6+
[categories] describing their functionality.
7+
8+
Disciplines are standardized for discoverability. If you want to submit a
9+
domain-specific package, but there isn't a fitting discipline in the list below,
10+
please reach out to us!
11+
12+
The following disciplines are currently defined:
13+
14+
- `agriculture`
15+
- `anthropology`
16+
- `archaeology`
17+
- `architecture`
18+
- `biology`
19+
- `business`
20+
- `chemistry`
21+
- `communication`
22+
- `computer-science`
23+
- `design`
24+
- `drawing`
25+
- `economics`
26+
- `education`
27+
- `engineering`
28+
- `fashion`
29+
- `film`
30+
- `geography`
31+
- `geology`
32+
- `history`
33+
- `journalism`
34+
- `law`
35+
- `linguistics`
36+
- `literature`
37+
- `mathematics`
38+
- `medicine`
39+
- `music`
40+
- `painting`
41+
- `philosophy`
42+
- `photography`
43+
- `physics`
44+
- `politics`
45+
- `psychology`
46+
- `sociology`
47+
- `theater`
48+
- `theology`
49+
- `transportation`
50+
51+
[categories]: https://github.com/typst/packages/blob/main/CATEGORIES.md

README.md

+106-22
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name = "example"
1313
version = "0.1.0"
1414
entrypoint = "lib.typ"
1515
authors = ["The Typst Project Developers"]
16-
license = "Unlicense"
16+
license = "MIT"
1717
description = "An example package."
1818
```
1919

@@ -34,12 +34,17 @@ Required for submissions to this repository:
3434
grammar and spelling mistakes as it will appear in the [package list][list].
3535

3636
Optional:
37-
- `homepage`: A link to the package's web presence where there could be more
37+
- `homepage`: A link to the package's web presence, where there could be more
3838
details, an issue tracker, or something else. Will be linked to from the
3939
package list.
4040
- `repository`: A link to the repository where this package is developed. Will
4141
be linked to from the package list if there is no homepage.
4242
- `keywords`: An array of search keywords for the package.
43+
- `categories`: An array with up to three categories from the
44+
[list of categories][categories] to help users discover the package.
45+
- `disciplines`: An array of [disciplines] defining the target audience for
46+
which the package is useful. Should be empty if the package is generally
47+
applicable.
4348
- `compiler`: The minimum Typst compiler version required for this package to
4449
work.
4550
- `exclude`: An array of globs specifying files that should not be part of the
@@ -48,6 +53,60 @@ Optional:
4853
otherwise unnecessarily increase the bundle size. Don't exclude the README or
4954
the LICENSE.
5055

56+
Packages always live in folders named as `{name}/{version}`. The name and
57+
version in the folder name and manifest must match. Paths in a package are local
58+
to that package. Absolute paths start in the package root, while relative paths
59+
are relative to the file they are used in.
60+
61+
### Templates
62+
Packages can act as templates for user projects. In addition to the module that
63+
a regular package provides, a template package also contains a set of template
64+
files that Typst copies into the directory of a new project.
65+
66+
In most cases, the template files should not include the styling code for the
67+
template. Instead, the template's entrypoint file should import a function from
68+
the package. Then, this function is used with a show rule to apply it to the
69+
rest of the document.
70+
71+
Template packages (also informally called templates) must declare the
72+
`[template]` key in their `typst.toml` file. A template package's `typst.toml`
73+
could look like this:
74+
75+
```toml
76+
[package]
77+
name = "charged-ieee"
78+
version = "0.1.0"
79+
entrypoint = "lib.typ"
80+
authors = ["Typst GmbH <https://typst.app>"]
81+
license = "MIT-0"
82+
description = "An IEEE-style paper template to publish at conferences and journals for Electrical Engineering, Computer Science, and Computer Engineering"
83+
84+
[template]
85+
path = "template"
86+
entrypoint = "main.typ"
87+
thumbnail = "thumbnail.png"
88+
```
89+
90+
Required by the compiler:
91+
- `path`: The directory within the package that contains the files that should
92+
be copied into the user's new project directory.
93+
- `entrypoint`: A path _relative to the template's path_ that points to the file
94+
serving as the compilation target. This file will become the previewed file in
95+
the Typst web application.
96+
97+
Required for submissions to this repository:
98+
- `thumbnail`: A path relative to the package's root that points to a PNG or
99+
lossless WebP thumbnail for the template. The thumbnail must depict one of the
100+
pages of the template **as initialized.** The longer edge of the image must be
101+
at least 1080px in length. Its file size must not exceed 3MB. Exporting a PNG
102+
at 250 DPI resolution is usually a good way to generate a thumbnail. You are
103+
encouraged to use [oxipng] to reduce the thumbnail's file size. The thumbnail
104+
will automatically be excluded from the package files and must not be
105+
referenced anywhere in the package.
106+
107+
Template packages must specify at least one category in `package.categories`.
108+
109+
### Third-party metadata
51110
Third-party tools can add their own entry under the `[tool]` section to attach
52111
their Typst-specific configuration to the manifest.
53112

@@ -59,11 +118,6 @@ their Typst-specific configuration to the manifest.
59118
foo = "bar"
60119
```
61120

62-
Packages always live in folders named as `{name}/{version}`. The name and
63-
version in the folder name and manifest must match. Paths in a package are local
64-
to that package. Absolute paths start in the package root while relative paths
65-
are relative to the file they are used in.
66-
67121
## Published packages
68122
This repository contains a collection of published packages. Due to its early
69123
and experimental nature, all packages in this repository are scoped in a
@@ -72,6 +126,10 @@ and experimental nature, all packages in this repository are scoped in a
72126
Typst as `#import "@preview/{name}:{version}"`. You must always specify the full
73127
package version.
74128

129+
You can use template packages to create new Typst projects with the CLI with
130+
the `typst init` command or the web application by clicking the _Start from
131+
template_ button.
132+
75133
### Submission guidelines
76134
To submit a package, simply make a pull request with the package to this
77135
repository. There are a few requirements for getting a package published, which
@@ -85,28 +143,66 @@ are detailed below:
85143
is redundant). If they contain multiple words, names should use `kebab-case`.
86144
Look at existing packages and PRs to get a feel for what's allowed and what's
87145
not.
146+
147+
*Additional guidance for template packages:* It is often desirable for
148+
template names to feature the name of the organization or publication the
149+
template is intended for. However, it is still important to us to accommodate
150+
multiple templates for the same purpose. Hence, template names shall consist
151+
of a unique, non-descriptive part followed by a descriptive part. For example,
152+
a template package for the fictitious _American Journal of Proceedings (AJP)_
153+
could be called `organized-ajp` or `eternal-ajp`. Package names should be
154+
short and use the official entity abbreviation. Template authors are
155+
encouraged to add the full name of the affiliated entity as a keyword.
156+
157+
The unamended entity name (e.g. `ajp`) is reserved for official template
158+
packages by their respective entities. Please make it clear in your PR if you
159+
are submitting an official package. We will then outline steps to authenticate
160+
you as a member of the affiliated organization.
161+
162+
If you are an author of an original template not affiliated with any
163+
organization, only the standard package naming guidelines apply to you.
164+
88165
- **Functionality:** Packages should conceivably be useful to other users and
89166
should expose their capabilities in a reasonable fashion.
167+
90168
- **Documentation:** Packages must contain a `README.md` file documenting (at
91169
least briefly) what the package does and all definitions intended for usage by
92170
downstream users. Examples in the README should show how to use the package
93171
through an `@preview` import. If you have images in your README, you might
94172
want to check whether they also work in dark mode. Also consider running
95173
[`typos`][typos] through your package before release.
174+
96175
- **Style:** No specific code style is mandated, but two spaces of indent and
97176
kebab-case for variable and function names are recommended.
177+
98178
- **License:** Packages must be licensed under the terms of an
99179
[OSI-approved][OSI] license. In addition to specifying the license in the
100180
TOML manifest, a package must either contain a `LICENSE` file or link to one
101181
in its `README.md`.
182+
183+
*Additional details for template packages:* If you expect the package
184+
license's provisions to apply to the contents of the template directory (used
185+
to scaffold a project) after being modified through normal use, especially if
186+
it still meets the _threshold of originality,_ you must ensure that users of
187+
your template can use and distribute the modified contents without
188+
restriction. In such cases, we recommend licensing at least the template
189+
directory under a license that requires neither attribution nor distribution
190+
of the license text. Such licenses include MIT-0 and Zero-Clause BSD. You can
191+
use an SPDX AND expression to selectively apply different licenses to parts of
192+
your package. In this case, the README or package files must make clear under
193+
which license they fall. If you explain the license distinction in the README
194+
file, you must not exclude it from the package.
195+
102196
- **Size:** Packages should not contain large files or a large number of files.
103197
This will be judged on a case-by-case basis, but if it needs more than ten
104198
files, it should be well-motivated. To keep the package small and fast to
105199
download, please `exclude` images for the README or PDF files with
106200
documentation from the bundle. Alternatively, you can link to images hosted on
107201
a githubusercontent.com URL (just drag the image into an issue).
202+
108203
- **Security:** Packages must not attempt to exploit the compiler or packaging
109204
implementation, in particular not to exfiltrate user data.
205+
110206
- **Safety:** Names and package contents must be safe for work.
111207

112208
This list may be extended over time as improvements/issues to the process are
@@ -121,20 +217,6 @@ There is one exception: Minor fixes to the documentation or TOML metadata of a
121217
package are allowed _if_ they can not affect the package in a way that might
122218
break downstream users.
123219

124-
### Templates
125-
**Important:** Please do not submit templates as packages just yet. To make the
126-
experience of using templates as seamless as possible, we want them to show up
127-
in the web app's template gallery and we want the CLI to be able to scaffold a
128-
project from a template. We ask for your patience while we're
129-
[building][template-packages] the necessary infrastructure.
130-
131-
What's the difference between a template and a normal package? The line isn't
132-
100% sharp, but overall a template will aid you in producing a full document
133-
with a particular style, whereas normal packages provide building blocks and
134-
automations useful across a range of documents. In particular, templates will
135-
often ship with one or more template files from which a new project can be
136-
scaffolded. This requires additional package metadata.
137-
138220
### Downloads
139221
The Typst compiler downloads packages from the `preview` namespace on-demand.
140222
Once used, they are cached in `{cache-dir}/typst/packages/preview` where
@@ -173,7 +255,9 @@ the Apache-2.0 license. Packages in `packages/` are licensed under their
173255
respective license.
174256

175257
[list]: https://typst.app/docs/packages/
258+
[categories]: https://github.com/typst/packages/blob/main/CATEGORIES.md
259+
[disciplines]: https://github.com/typst/packages/blob/main/DISCIPLINES.md
176260
[SemVer]: https://semver.org/
177261
[OSI]: https://opensource.org/licenses/
178-
[template-packages]: https://github.com/typst/typst/issues/2432
179262
[typos]: https://github.com/crate-ci/typos
263+
[oxipng]: https://github.com/shssoichiro/oxipng

0 commit comments

Comments
 (0)