Custom units without `@local`
lumpiluk opened this issue · 2 comments
I'm looking for a way to add custom units (e.g., "hours") while importing unify from @preview
.
According to the Readme:
The possible values of the three latter parts are loaded at runtime from prefixes.csv, units.csv, and postfixes.csv (in the library directory). There, you can also add your own units.
However, when importing from @preview
, these CSVs aren't available to me.
Would it make sense to either
- maintain the corresponding dictionaries like
units
,units-short
, etc., asstate
and add a function for easily adding a new unit, prefix, or postfix; or - add parameters of the same names as those dictionaries to
_format-unit
defaulting to the existing dictionaries, which should allow users to useset
rules to specify the extended dictionaries?
You're right, the current unit storage is not as flexible as I'd like.
Storing the units in a CSV instead of in the code was not a choice I felt was the most usable, but rather the one lying in my abilities. Keeping track of global variables in Typst is really hard because you have multiple passes over the file. I am always to pull requests, though.
Would the second idea work? I'd assume that the path is relative to the main file where the library is imported, such that you can't easily find the bundled CSVs.
I finally implemented it in 7c41b07!
Also thanks to @SergeyGorchakov for (unintentionally) introducing me to the state function that made this possible.