Code Monkey home page Code Monkey logo

unify's People

Contributors

benjamin-voisin avatar chhecker avatar gkend avatar jarrod-angove avatar linuxrider avatar loewe1000 avatar mrlegohead0x45 avatar nycex avatar rungecc avatar scrouthtv avatar sergeygorchakov avatar szsdk avatar ydx-2147483647 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

unify's Issues

Degree and Day has same shorthand

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?

Result of `#unit("Hz")` is confusing

  • #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).

Workaround

Don't use units-short: #unit("hertz") works as expected.

Reason

  • h is a valid prefix (hecto or 100).
  • H is a valid unit (Henry).
  • z is a valid prefix (zepto or $10^{-21}$).

Therefore the checks pass, and we try to parse z and fail. However, we don't #panic and let it go…

Possible Fix

In #format-unit-short, remove the else if in the for loop…

unify/lib.typ

Lines 230 to 232 in d2ab4c3

} else if acc.len() == quantity.len() {
panic("invalid unit: " + quantity)
}

…and add the following immediately after the loop.

    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:

unify/lib.typ

Lines 223 to 225 in d2ab4c3

if acc in prefixes-short and prefix == none {
prefix = prefixes-short.at(acc)
acc = ""

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.

A Bigger Refactor?

I suggest a bigger refactor of the parsing logic in #format-unit-short

  1. If quantity in units-short, unit = units-short.at(quantity), ✓.
  2. If not, divide quantitiy into two parts, if the first part is a prefix and the second is a unit, ✓.
  3. If not, try to divide at other positions.
  4. If all division fail, panic.

How do you think so? If you agree but are busy, I can try to work out a PR.

Allow spaces as `num` thousand separators

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

Typo in units.csv and request for times multiplication symbol

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

Custom units without `@local`

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., as state 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 use set rules to specify the extended dictionaries?

Adding Imperial Units

(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!

Degree after percent causes error

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

[unify package] Set decimal separator manually

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)

Space before temperature units

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]).

Change font used in numbers

Good package, but need way to change the font used so that it may jibe well with the rest of the document.

Allow unicode exponents

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⁻¹")

Bug: can't have range of powers of ten without the awkward 1

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³

Addition of monetary unit

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.

Leading thin space

There is an additional thin space at the beginning when using uncertainties, that shouldn't be there:

#import "@preview/unify:0.4.2": qty, num

#qty("200+-5", "m") \
#num("200+-5")

$(200 plus.minus 5)$ // How it should look

image

(Using web app, 0.8.0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.