diff --git a/src/accessibility.typ b/src/accessibility.typ index 25bb391..8c77cee 100644 --- a/src/accessibility.typ +++ b/src/accessibility.typ @@ -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 @@ -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" { diff --git a/src/units.typ b/src/units.typ index aad02fe..c53cfc2 100644 --- a/src/units.typ +++ b/src/units.typ @@ -308,6 +308,7 @@ value, unit, alt: auto, + prefixed: false, ..args, ) = context { let unit = unit @@ -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, @@ -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 diff --git a/src/zi.typ b/src/zi.typ index cb331c4..408c835 100644 --- a/src/zi.typ +++ b/src/zi.typ @@ -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) } } @@ -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") @@ -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") @@ -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") @@ -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() \ No newline at end of file +// two commonly used crypto currencies +#let BTC = declare("₿", prefixed: true) +#let ETH = declare("Ξ", prefixed: true) \ No newline at end of file diff --git a/tests/currency/.gitignore b/tests/currency/.gitignore new file mode 100644 index 0000000..8e21a98 --- /dev/null +++ b/tests/currency/.gitignore @@ -0,0 +1,4 @@ +# generated by tytanic, do not edit + +/diff/ +/out/ diff --git a/tests/currency/ref/1.png b/tests/currency/ref/1.png new file mode 100644 index 0000000..1e162c7 Binary files /dev/null and b/tests/currency/ref/1.png differ diff --git a/tests/currency/test.typ b/tests/currency/test.typ new file mode 100644 index 0000000..e3ef9d2 --- /dev/null +++ b/tests/currency/test.typ @@ -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)\ \ No newline at end of file