Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/accessibility.typ
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@
V: "volt",
W: "watt",
Wb: "weber",
"$": "dollar",
"€": "euro",
"¥": "yen",
"£": "pound",
"Fr.": "franc",
"₹": "rupee",
"₩": "won",
"kr": "krona",
"R": "rand",
"zł": "rand",
"₺": "lira",
"฿": "baht",
"₪": "shekel",
"Ft": "forint",
"Kč": "koruna",
"₱": "peso",
"RM": "ringgit",
"Dhs": "dirham",
"⃁": "riyal",
"₿": "bitcoin",
"Ξ": "ethereum",
),
de: (
// identical/similar units are inherited from English
Expand Down Expand Up @@ -465,7 +486,7 @@
#let pluralize = (
en: (unit, count, is-in-denom) => {
let singular = units.en.at(unit)
if unit in ("lx", "Hz", "S") {
if unit in ("lx", "Hz", "S", "¥", "₩", "kr", "zł", "฿", "Ft", "Kč", "RM", "Dhs", "₿", "Ξ") {
return singular
}
if unit == sym.degree + "C" {
Expand Down
24 changes: 18 additions & 6 deletions src/units.typ
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
value,
unit,
alt: auto,
prefixed: false,
..args,
) = context {
let unit = unit
Expand Down Expand Up @@ -357,12 +358,7 @@
}
let breakable = utility.process-breakable(num-state.breakable)

let result = {
num(value, state: num-state, force-parentheses-around-uncertainty: true)
sym.wj
separator
if not breakable.unit { sym.wj }
show-unit(
let unit-content = show-unit(
unit.numerator,
unit.denominator,
fraction: num-state.unit.fraction,
Expand All @@ -376,6 +372,22 @@
float(info.int + "." + info.frac)
},
)
let result = {
if prefixed {
unit-content
sym.wj
separator
if not breakable.unit { sym.wj }
}

num(value, state: num-state, force-parentheses-around-uncertainty: true)

if not prefixed {
sym.wj
separator
if not breakable.unit { sym.wj }
unit-content
}
}

result
Expand Down
43 changes: 35 additions & 8 deletions src/zi.typ
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#import "units.typ"

#let declare(alt: auto, ..unit) = {
#let declare(alt: auto, prefixed:false, ..unit) = {
assert(unit.named().len() == 0, )

(..value) => if value.pos().len() == 0 {
units.unit(units.parse-unit(..unit.pos()), ..value, alt: alt)
units.unit(units.parse-unit(..unit.pos()), ..value, alt: alt, prefixed: prefixed)
} else {
units.qty(..value, units.parse-unit(..unit.pos()), alt: alt)
units.qty(..value, units.parse-unit(..unit.pos()), alt: alt, prefixed: prefixed)
}
}

Expand Down Expand Up @@ -45,6 +45,9 @@
#let ohm = declare(sym.Omega)
#let pascal = declare("Pa")
#let radian = declare("rad")
#let degree = declare(sym.degree)
#let percent = declare("%")
#let promille = declare("‰")
#let siemens = declare("S")
#let sievert = declare("Sv")
#let steradian = declare("sr")
Expand Down Expand Up @@ -81,14 +84,13 @@
#let dalton = declare("Da")
#let day = declare("d")
#let decibel = declare("dB")
#let degree = declare(sym.degree)
#let electronvolt = declare("eV")
#let hectare = declare("ha")
#let hour = declare("h")
#let liter = declare("L")
#let arcminute = declare(sym.prime)
#let minute = declare("min")
#let arcsecond = declare(sym.prime.double)
#let hour = declare("h")
#let minute = declare("min")
#let neper = declare("Np")
#let tonne = declare("t")
#let gram = declare("g")
Expand Down Expand Up @@ -117,7 +119,7 @@
#let µH = declare("µH")
#let uH = µH
#let nH = declare("nH")
#let pH = declare("pH")
#let pH = declare("pH", prefixed: true)
#let mC = declare("mC")
#let nC = declare("nC")
#let µC = declare("µC")
Expand Down Expand Up @@ -199,5 +201,30 @@
#let F-m = declare("F/m")
#let kWh = declare("kW h")

// the order and if it's included at all is based on https://en.wikipedia.org/wiki/Template:Most_traded_currencies with duplicates removed
#let dollar = declare("$", prefixed: true, alt:"")
#let euro = declare("€")
#let yen = declare("¥", prefixed: true)
#let pound-sterling = declare("£", prefixed: true)
#let francs = declare("Fr.")
#let rupee = declare("₹", prefixed: true)
#let won = declare("₩", prefixed: true)
#let krona = declare("kr")
#let rand = declare("R", prefixed: true)
#let zloty = declare("zł")
#let lira = declare("₺")
#let baht = declare("฿", prefixed: true)
#let shekel = declare("₪", prefixed: true)
#let forint = declare("Ft")
#let koruna = declare("Kč")
#let philipine-peso = declare("₱", prefixed: true)
#let ringgit = declare("RM", prefixed: true)
// unicode symbol for dirham will be added in September 2026
#let dirham = declare("Dhs", prefixed: true)
#let riyal = declare("⃁")
#let sol = declare([S/], prefixed: true, alt:"sol")


#kWh()
// two commonly used crypto currencies
#let BTC = declare("₿", prefixed: true)
#let ETH = declare("Ξ", prefixed: true)
4 changes: 4 additions & 0 deletions tests/currency/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# generated by tytanic, do not edit

/diff/
/out/
Binary file added tests/currency/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions tests/currency/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#set page(width: auto, height: auto, margin: .5em)
#import "/src/zero.typ": set-unit, zi


#zi.dollar(12.34)\
#zi.euro(12.34)\
#zi.yen(12.34)\
#zi.pound-sterling(12.34)\
#zi.francs(12.34)\
#zi.rupee(12.34)\
#zi.won(12.34)\
#zi.krona(12.34)\
#zi.rand(12.34)\
#zi.zloty(12.34)\
#zi.lira(12.34)\
#zi.baht(12.34)\
#zi.shekel(12.34)\
#zi.forint(12.34)\
#zi.koruna(12.34)\
#zi.philipine-peso(12.34)\
#zi.ringgit(12.34)\
#zi.dirham(12.34)\
#zi.riyal(12.34)\
#zi.sol(12.34)\
#zi.BTC(12.34)\
#zi.ETH(12.34)\