1# Typst {#typst} 2 3Typst can be configured to include packages from [Typst Universe](https://typst.app/universe/) or custom packages. 4 5## Custom Environment {#typst-custom-environment} 6 7You can create a custom Typst environment with a selected set of packages from **Typst Universe** using the following code. It is also possible to specify a Typst package with a specific version (e.g., `cetz_0_3_0`). A package without a version number will always refer to its latest version. 8 9```nix 10typst.withPackages ( 11 p: with p; [ 12 polylux_0_4_0 13 cetz_0_3_0 14 ] 15) 16``` 17 18### Handling Outdated Package Hashes {#typst-handling-outdated-package-hashes} 19 20Since **Typst Universe** does not provide a way to fetch a package with a specific hash, the package hashes in `nixpkgs` can sometimes be outdated. To resolve this issue, you can manually override the package source using the following approach: 21 22```nix 23typst.withPackages.override 24 (old: { 25 typstPackages = old.typstPackages.extend ( 26 _: previous: { 27 polylux_0_4_0 = previous.polylux_0_4_0.overrideAttrs (oldPolylux: { 28 src = oldPolylux.src.overrideAttrs { outputHash = YourUpToDatePolyluxHash; }; 29 }); 30 } 31 ); 32 }) 33 ( 34 p: with p; [ 35 polylux_0_4_0 36 cetz_0_3_0 37 ] 38 ) 39``` 40 41## Custom Packages {#typst-custom-packages} 42 43`Nixpkgs` provides a helper function, `buildTypstPackage`, to build custom Typst packages that can be used within the Typst environment. However, all dependencies of the custom package must be explicitly specified in `typstDeps`. 44 45Here's how to define a custom Typst package: 46 47```nix 48{ buildTypstPackage, typstPackages }: 49 50buildTypstPackage (finalAttrs: { 51 pname = "my-typst-package"; 52 version = "0.0.1"; 53 src = ./.; 54 typstDeps = with typstPackages; [ cetz_0_3_0 ]; 55}) 56``` 57 58### Package Scope and Usage {#typst-package-scope-and-usage} 59 60By default, every custom package is scoped under `@preview`, as shown below: 61 62```typst 63#import "@preview/my-typst-package:0.0.1": * 64``` 65 66Since `@preview` is intended for packages from **Typst Universe**, it is recommended to use this approach **only for temporary or experimental modifications over existing packages** from **Typst Universe**. 67 68On the other hand, **local packages**, packages scoped under `@local`, are **not** considered part of the Typst environment. This means that local packages must be manually linked to the Typst compiler if needed.