chhecker / unify Goto Github PK
View Code? Open in Web Editor NEWFormat numbers, units, and ranges in Typst correctly.
License: MIT License
Format numbers, units, and ranges in Typst correctly.
License: MIT License
Both Degree and Day has shorthand "d". Degree seems to have priority, making volumetric flow units "m^3/d" unaccessible using shorthand. "meter cubed per day" works but is a hassle.
Maybe "deg" is suitable as shorthand for degree?
#unit("hz")
⇒ h
(hecto ?)#unit("Hz")
⇒ zH
(zepto Henry)Results of #qty
is similar.
I am using v0.4.2 and I've verified this issue on current main (d2ab4c3).
Don't use units-short: #unit("hertz")
works as expected.
h
is a valid prefix (hecto or 100).H
is a valid unit (Henry).z
is a valid prefix (zepto or Therefore the checks pass, and we try to parse z
and fail. However, we don't #panic
and let it go…
In #format-unit-short
, remove the else if
in the for
loop…
Lines 230 to 232 in d2ab4c3
if acc.len() > 0 {
panic("invalid unit: " + quantity)
}
This will make #unit("hz")
into error: panicked with: "invalid unit: hz"
.
In the same for
loop, add and unit == none
in this if, because the prefix must appear before the unit:
Lines 223 to 225 in d2ab4c3
This will make #unit("Hz")
into error: panicked with: "invalid unit: Hz"
.
Warning
This does NOT make #unit("Hz")
⇒ Hz
, because #format-unit-short
is eager — it consumes H
as Henry first.
I suggest a bigger refactor of the parsing logic in #format-unit-short
…
quantity in units-short
, unit = units-short.at(quantity)
, ✓.quantitiy
into two parts, if the first part is a prefix and the second is a unit, ✓.panic
.How do you think so? If you agree but are busy, I can try to work out a PR.
Currently, separators for num
are trimmed, meaning it is not possible to set e.g. " "
or sym.space.nobreak
or sym.space.nobreak.narrow
as the thousands separator, which is inconvenient for formatting a number like e.g. 4446536
as 4 446 536
Hi.
Sorry to disturb you.
When I tried to use the coulomb measurement ubit, it didn't work.
I realized, as in the attachement, that there was a typo in the unit.csv file, probabbly it is necessary to remove the character ".
By the way, in LaTeX SIunits, when you type the scientific notation the multiplication sign is a times and not a dot. Could it be possible to have the possibility tto choice between a dot or times symbol also in your package (I attach a file to be clearer).
Thank a lot and sorry for my bad English.
Best regards,
Roberto
units.csv.pdf
Generic.pdf
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
units
, units-short
, etc., as state
and add a function for easily adding a new unit, prefix, or postfix; or_format-unit
defaulting to the existing dictionaries, which should allow users to use set
rules to specify the extended dictionaries?(For context, I submitted an "add imperial units" PR a few weeks ago, and the maintainer asked if it could be used with the new language feature.)
Having looked at the new code, imperial units can be added. It would consist of adding an imperial entry to the existing lang-db
, and parsing a corresponding imperial.csv
file. Since there is currently no language referred to as imperial, there is no risk of a namespace clash when more languages are added.
This does not exactly copy siunitx's behavior (there, the "preferred solution" is to use \DeclareSIUnit
; here, that would require either downloading a local copy of the package or going through some complex state.update
maneuvers). However, it does not create any conflicts with existing code, and it is unlikely to create namespace collisions with future code.
If there is interest in adding imperial units, I can create a PR.
I am interested to read any thoughts on this. Please let me know if you need any additional information. Thanks!
both $qty("0.393", "% / d K")$
and $qty("0.393", "percent per degree kelvin")$
Cause the error unknown variable: percentdegree
in unify 0.6.0
It should be possible to set the default decimal separator. I tried doing
#set _format-float(decsep: ",")
$ num("2.0") $
as I prefer to leave the numbers in code with dots (yet want it to show up as 2,0), but it throws a syntax error. Any way to set that in another way?
(originally typst/packages#188)
The Dyne is used in astronomy in the cgs unit system.
There are 22 derived SI units with special name, of which three are not yet included in the units file.
Those are:
steradian, sr
weber, Wb
katal, kat
Typically, the only units you don't use spaces before are a lone-standing degree symbol and primes. This means there should be one if the unit is "°C", "°F" etc., since the "°" has a "suffix" (see e.g. [https://german.stackexchange.com/a/322]).
Good package, but need way to change the font used so that it may jibe well with the rest of the document.
It would be nice if unicode exponents could be used to write units.
normal:
#qty("2.5", "J mol^-1 K^-1")
unicode:
#qty("2.5", "J mol⁻¹ K⁻¹")
This:
#import "@preview/unify:0.5.0": numrange
$numrange("e2", "e3")$
which i would expect to render as 10² - 10³ raises an error.
Instead i have to use
#import "@preview/unify:0.5.0": numrange
$numrange("1e2", "1e3")$
which renders the a little awkward 1 * 10² - 1 * 10³
I'm not sure if this fits the intended use of this package, but I think having monetary unit it can be usefull (I found this package while writing a financial document, and wanted to unify the typesetting of the numbers I was writing). If that is not in the scope of this package, fine. Else, I can do the PR.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.