cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
893 stars 36 forks source link

Move external dependencies to a single file #403

Closed johannes-wolf closed 10 months ago

johannes-wolf commented 10 months ago

We should group imports of external packages into one file to not mix up versions.

BTW, it's not great when you import the same published package multiple times. I had an issue (with cetz) where I thought I've changed the version, but actually I imported the same old version in different files. So I advise you to import external libraries somewhere once and then import that local file everywhere where you need external library API.

You can very easily forget to update all files that import the same package.

src/anchor.typ
1:#import "@preview/oxifmt:0.2.0": strfmt

src/draw/grouping.typ
1:#import "@preview/oxifmt:0.2.0": strfmt

src/coordinate.typ
3:#import "@preview/oxifmt:0.2.0": strfmt

src/util.typ
1:#import "@preview/oxifmt:0.2.0": strfmt

Originally posted by @Andrew15-5 in https://github.com/johannes-wolf/cetz/issues/402#issuecomment-1854839353

Andrew15-5 commented 10 months ago

In my last document, I put external packages that are used (one or) many times inside my /utils/utils.typ file. And then I can import that file and choose what exactly do I want to import.

A more readable approach is to make:

/src/preview/oxifmt.typ
/src/packages/oxifmt.typ
/src/external/oxifmt.typ
/src/dependencies/oxifmt.typ

This way you create 1 file per @preview package where you import everything that you need and then re-import from that local file into other files. This looks very well organized, and only the relative paths will be more ugly/longer, but since they are only created by a script automatically, this shouldn't be an issue.

#import "/src/dependencies/oxifmt.typ": strfmt

This ↑ should work flawlessly.

Inside /src/dependencies/oxifmt.typ:

#import "@preview/oxifmt:0.2.0": strfmt