Giter VIP home page Giter VIP logo

unify's Introduction

Unify

unify is a Typst package simplifying the typesetting of number, (physical) units, and ranges. It is the equivalent to LaTeX's siunitx, though not as mature.

Overview

unify allows flexible numbers and units, and still mostly gets well typeset results.

#import "@preview/unify:0.4.3": num,qty,numrange,qtyrange

$ num("-1.32865+-0.50273e-6") $
$ qty("1.3+1.2-0.3e3", "erg/cm^2/s", space: "#h(2mm)") $
$ numrange("1,1238e-2", "3,0868e5", thousandsep: "'") $
$ qtyrange("1e3", "2e3", "meter per second squared", per: "/", delimiter: "\"to\"") $

num

num uses string parsing in order to typeset numbers, including separators between the thousands. They can have the following form:

  • float or integer number
  • either ({} stands for a number)
    • symmetric uncertainties with +-{}
    • asymmetric uncertainties with +{}-{}
  • exponential notation e{}

Parentheses are automatically set as necessary. Use thousandsep to change the separator between the thousands.

unit

unit takes the unit in words or in symbolic notation as its first argument. The value of space will be inserted between units if necessary. Setting per to symbol will format the number with exponents (i.e. ^(-1)), and fraction or / using fraction.
Units in words have four possible parts:

  • per forms the inverse of the following unit.
  • A written-out prefix in the sense of SI (e.g. centi). This is added before the unit.
  • The unit itself written out (e.g. gram).
  • A postfix like squared. This is added after the unit and takes per into account.

The shorthand notation also has four parts:

  • / forms the inverse of the following unit.
  • A short prefix in the sense of SI (e.g. c). This is added before the unit.
  • The short unit itself (e.g. g).
  • An exponent like ^2. This is added after the unit and takes / into account.

Note: Use u for micro.

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. The formats for the pre- and postfixes are:

pre-/postfix shorthand symbol
milli m upright("m")

and for units:

unit shorthand symbol space
meter m upright("m") true

The first column specifies the written-out word, the second one the shorthand. These should be unique. The third column represents the string that will be inserted as the unit symbol. For units, the last column describes whether there should be space before the unit (possible values: true/false, 1,0). This is mostly the cases for degrees and other angle units (e.g. arcseconds).
If you think there are units not included that are of interest for other users, you can create an issue or PR.

qty

qty allows a num as the first argument following the same rules. The second argument is a unit. If rawunit is set to true, its value will be passed on to the result (note that the string passed on will be passed to eval, so add escaped quotes \" if necessary). Otherwise, it follows the rules of unit. The value of space will be inserted between units if necessary, thousandsep between the thousands, and per switches between exponents and fractions.

numrange

numrange takes two nums as the first two arguments. If they have the same exponent, it is automatically factorized. The range symbol can be changed with delimiter, and the space between the numbers and symbols with space.

qtyrange

qtyrange is just a combination of unit and range.

unify's People

Contributors

chhecker avatar loewe1000 avatar scrouthtv avatar ydx-2147483647 avatar

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.