Module:Val/units: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Snaevar
m fix a script error (seen at "Template:Val/testcases" using the template sandbox extension).
meta>Johnuniq
try new procedure: define units in a big string (easier to edit and fast); use enhanced method of getting unit information from Module:Convert; include "long scale" units from Template:Val/units
Line 1: Line 1:
-- TODO: Need to see what units are missing and add them
-- Definitions for units known to val (short scale; see below for long scale).
-- There must be two spaces (not tab characters) after each unit code, and
-- two spaces or tabs between columns.
-- There must be a blank line before the first unit and a newline after the last.
-- Unit code      Symbol                                Link                                  Flags
local builtin_units = [=[


local units_tbl = {
"                  ″                                    second of arc                          NOSPACE
-- No space before unit
%                  %                                    percent                                NOSPACE
arcminute = { abbr='′', link='minute of arc', nospace=true },
'                                                     minute of arc                         NOSPACE
arcmin = { abbr='', link='minute of arc', nospace=true },
°                  °                                    degree (angle)                        NOSPACE
["'"] = { abbr='′', link='minute of arc', nospace=true },
‰                  ‰                                    per mil                                NOSPACE
['′'] = { abbr='′', link='minute of arc', nospace=true },
                ′                                    minute of arc                         NOSPACE
arcsecond = { abbr='', link='second of arc', nospace=true },
                ″                                    second of arc                         NOSPACE
arcsec = { abbr='″', link='second of arc', nospace=true },
µA                µA                                    microampere
['"'] = { abbr='″', link='second of arc', nospace=true },
µB                µ<sub>B</sub>                        Bohr magneton
['″'] = { abbr='″', link='second of arc', nospace=true },
µG                µG                                    microgauss
['deg'] = { abbr='°', link='degree (angle)', nospace=true },
µGal              µGal                                  Gal (unit)
['°'] = { abbr='°', link='degree (angle)', nospace=true },
µHz                µHz                                  hertz
percent = { abbr='%', link='percent', nospace=true },
µK                µK                                    microkelvin
['per cent'] = { abbr='%', link='percent', nospace=true },
µN                µ<sub>N</sub>                        nuclear magneton
['%'] = { abbr='%', link='percent', nospace=true },
µT                µT                                    microtesla
permil = { abbr='‰', link='per mil', nospace=true },
µV                µV                                    microvolt
permill = { abbr='‰', link='per mil', nospace=true },
μg/dL              μg/dL                                gram per litre
permille = { abbr='‰', link='per mil', nospace=true },
μg/dl              μg/dL                                gram per litre
['per mil'] = { abbr='‰', link='per mil', nospace=true },
μN                µ<sub>N</sub>                        nuclear magneton
['per mill'] = { abbr='‰', link='per mil', nospace=true },
A                  A                                    ampere
['per mille'] = { abbr='‰', link='per mil', nospace=true },
aA                aA                                    attoampere
['‰'] = { abbr='‰', link='per mil', nospace=true },
AD                AD                                    Anno Domini
-- Space before unit
aG                aG                                    attogauss
A = { abbr='A', link='ampere' },
ag                ag                                    attogram
aA = { abbr='aA', link='attoampere' },
aHz                aHz                                  attohertz
AD = { abbr='AD', link='Anno Domini' },
aK                aK                                    attokelvin
aG = { abbr='aG', link='attogauss' },
am                am                                    attometre
ag = { abbr='ag', link='attogram' },
arcmin            ′                                    minute of arc                          NOSPACE
aHz = { abbr='aHz', link='attohertz' },
arcminute          ′                                    minute of arc                          NOSPACE
aK = { abbr='aK', link='attokelvin' },
arcsec            ″                                    second of arc                          NOSPACE
am = { abbr='am', link='attometre' },
arcsecond          ″                                    second of arc                          NOSPACE
aT = { abbr='aT', link='attotesla' },
aT                aT                                    attotesla
BC = { abbr='BC', link='Before Christ' },
BC                BC                                    Before Christ
BCE = { abbr='BCE', link='Before the Common Era' },
BCE                BCE                                  Before the Common Era
['bit/s'] = { abbr='bit/s', link='bit per second' },
bit/s              bit/s                                bit per second
bps = { abbr='bit/s', link='bit per second' },
BP                BP                                    Before present
BP = { abbr='BP', link='Before present' },
bps                bit/s                                bit per second
bya = { abbr='bya', link='billion years ago' },
bya                bya                                  billion years ago
byr = { abbr='byr', link='billion years' },
byr                byr                                  billion years
C = { abbr='C', link='coulomb' },
c                  <i>c</i>                              speed of light
c = { abbr='<i>c</i>', link='speed of light' },
C                  C                                    coulomb
cA = { abbr='cA', link='centiampere' },
cA                cA                                    centiampere
CE = { abbr='CE', link='Common Era' },
CE                CE                                    Common Era
cG = { abbr='cG', link='centigauss' },
cG                cG                                    centigauss
cg = { abbr='cg', link='centigram' },
cg                cg                                    centigram
cHz = { abbr='cHz', link='centihertz' },
cHz                cHz                                  centihertz
cK = { abbr='cK', link='centikelvin' },
cK                cK                                    centikelvin
['cm-1'] = { abbr='cm<sup>&minus;1</sup>', link='wavenumber' },
cm-1              cm<sup>&minus;1</sup>                 wavenumber
cT = { abbr='cT', link='centitesla' },
cT                cT                                    centitesla
cV = { abbr='cV', link='volt' },
cV                cV                                    volt
dA = { abbr='dA', link='ampere' },
dA                dA                                    ampere
daA = { abbr='daA', link='decaampere' },
daA                daA                                  decaampere
daG = { abbr='daG', link='decagauss' },
daG                daG                                  decagauss
dag = { abbr='dag', link='decagram' },
dag                dag                                  decagram
daHz = { abbr='daHz', link='decahertz' },
daHz              daHz                                  decahertz
daK = { abbr='daK', link='decakelvin' },
daK                daK                                  decakelvin
daT = { abbr='daT', link='decatesla' },
daT                daT                                  decatesla
daV = { abbr='daV', link='volt' },
daV                daV                                  volt
degC = { abbr='°C', link='degree Celsius' },
deg                °                                    degree (angle)                        NOSPACE
degF = { abbr='°F', link='Fahrenheit' },
degC              °C                                    degree Celsius
degR = { abbr='°R', link='Rankine scale' },
degF              °F                                    Fahrenheit
dG = { abbr='dG', link='decigauss' },
degR              °R                                    Rankine scale
dg = { abbr='dg', link='decigram' },
dG                dG                                    decigauss
dHz = { abbr='dHz', link='hertz' },
dg                dg                                    decigram
dK = { abbr='dK', link='decikelvin' },
dHz                dHz                                  hertz
dT = { abbr='dT', link='decitesla' },
dK                dK                                    decikelvin
dV = { abbr='dV', link='volt' },
dT                dT                                    decitesla
e = { abbr='<i>e</i>', link='Elementary charge' },
dV                dV                                    volt
EA = { abbr='EA', link='ampere' },
e                  <i>e</i>                              Elementary charge
['Earth mass'] = { abbr='<i>M</i><sub>⊕</sub>', link='Earth mass' },
EA                EA                                    ampere
['Earth radius'] = { abbr='<i>R</i><sub>⊕</sub>', link='Earth radius' },
Earth mass        <i>M</i><sub>⊕</sub>                  Earth mass
EG = { abbr='EG', link='exagauss' },
Earth radius      <i>R</i><sub>⊕</sub>                  Earth radius
Eg = { abbr='Eg', link='exagram' },
EG                EG                                    exagauss
EHz = { abbr='EHz', link='exahertz' },
Eg                Eg                                    exagram
EK = { abbr='EK', link='exakelvin' },
EHz                EHz                                  exahertz
ET = { abbr='ET', link='exatesla' },
EK                EK                                    exakelvin
EV = { abbr='EV', link='volt' },
ET                ET                                    exatesla
['eV/c2'] = { abbr='eV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
EV                EV                                    volt
F = { abbr='F', link='farad' },
eV/c2              eV/<i>c</i><sup>2</sup>               electronvolt#Mass
fA = { abbr='fA', link='femtoampere' },
F                  F                                    farad
['fb-1'] = { abbr='fb<sup>&minus;1</sup>', link='Barn (unit)' },
fA                fA                                    femtoampere
fG = { abbr='fG', link='femtogauss' },
fb-1              fb<sup>&minus;1</sup>                 Barn (unit)
fg = { abbr='fg', link='femtogram' },
fG                fG                                    femtogauss
fHz = { abbr='fHz', link='femtohertz' },
fg                fg                                    femtogram
fK = { abbr='fK', link='femtokelvin' },
fHz                fHz                                  femtohertz
fT = { abbr='fT', link='femtotesla' },
fK                fK                                    femtokelvin
fV = { abbr='fV', link='femtovolt' },
fT                fT                                    femtotesla
gal = { abbr='gal', link='gallon' },
fV                fV                                    femtovolt
['g/cm3'] = { abbr='g/cm<sup>3</sup>', link='gram per cubic centimetre' },
g*mol-1            g&sdot;mol<sup>&minus;1</sup>         molar mass
['g/l'] = { abbr='g/l', link='gram per litre' },
g/cm3              g/cm<sup>3</sup>                     gram per cubic centimetre
['g/L'] = { abbr='g/L', link='gram per litre' },
g/l                g/l                                  gram per litre
['g*mol-1'] = { abbr='g&sdot;mol<sup>&minus;1</sup>', link='molar mass' },
g/L                g/L                                  gram per litre
['g/mol'] = { abbr='g&sdot;mol<sup>&minus;1</sup>', link='molar mass' },
g/mol              g&sdot;mol<sup>&minus;1</sup>         molar mass
GA = { abbr='GA', link='gigaampere' },
GA                GA                                    gigaampere
Ga = { abbr='Ga', link='gigaannum' },
Ga                Ga                                    gigaannum
['Gbit/s'] = { abbr='Gbit/s', link='gigabit per second' },
gal                gal                                  gallon
['GeV/c2'] = { abbr='GeV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
Gbit/s            Gbit/s                                gigabit per second
GG = { abbr='GG', link='gigagauss' },
GeV/c2            GeV/<i>c</i><sup>2</sup>              electronvolt#Mass
Gg = { abbr='Gg', link='gigagram' },
GG                GG                                    gigagauss
GHz = { abbr='GHz', link='gigahertz' },
Gg                Gg                                    gigagram
['GJ*mol-1'] = { abbr='GJ&sdot;mol<sup>&minus;1</sup>', link='joule per mole' },
GHz                GHz                                  gigahertz
['GJ/mol'] = { abbr='GJ/mol', link='joule per mole' },
GJ*mol-1          GJ&sdot;mol<sup>&minus;1</sup>       joule per mole
GK = { abbr='GK', link='gigakelvin' },
GJ/mol            GJ/mol                                joule per mole
GPa = { abbr='GPa', link='gigapascal' },
GK                GK                                    gigakelvin
Gpc = { abbr='Gpc', link='megaparsec#Megaparsecs_and_gigaparsecs' },
GPa                GPa                                  gigapascal
['Gpc2'] = { abbr='Gpc<sup>2</sup>', link='megaparsec#Megaparsecs_and_gigaparsecs' },
Gpc                Gpc                                  megaparsec#Megaparsecs and gigaparsecs
['Gpc3'] = { abbr='Gpc<sup>3</sup>', link='megaparsec#Megaparsecs_and_gigaparsecs' },
Gpc2              Gpc<sup>2</sup>                       megaparsec#Megaparsecs and gigaparsecs
GT = { abbr='GT', link='gigatesla' },
Gpc3              Gpc<sup>3</sup>                       megaparsec#Megaparsecs and gigaparsecs
GV = { abbr='GV', link='gigavolt' },
GT                GT                                    gigatesla
Gyr = { abbr='Ga', link='gigaannum' },
GV                GV                                    gigavolt
H = { abbr='H', link='Henry (unit)' },
Gyr                Ga                                   gigaannum
['H*m-1'] = { abbr='H', link='Henry (unit)' },
H                  H                                    Henry (unit)
hA = { abbr='hA', link='hectoampere' },
H*m-1              H                                    Henry (unit)
hG = { abbr='hG', link='hectogauss' },
hA                hA                                    hectoampere
hg = { abbr='hg', link='hectogram' },
hG                hG                                    hectogauss
hHz = { abbr='hHz', link='hectohertz' },
hg                hg                                    hectogram
hK = { abbr='hK', link='hectokelvin' },
hHz                hHz                                  hectohertz
hT = { abbr='hT', link='hectotesla' },
hK                hK                                    hectokelvin
hV = { abbr='hV', link='volt' },
hT                hT                                    hectotesla
Hz = { abbr='Hz', link='hertz' },
hV                hV                                    volt
['Jupiter mass'] = { abbr='<i>M</i><sub>J</sub>', link='Jupiter mass' },
Hz                Hz                                    hertz
['Jupiter radius'] = { abbr='<i>R</i><sub>J</sub>', link='Jupiter radius' },
J*mol-1            J&sdot;mol<sup>&minus;1</sup>         joule per mole
['J/kg'] = { abbr='J/kg', link='joule' },
J*s                J&sdot;s                              joule-second
['J*mol-1'] = { abbr='J&sdot;mol<sup>&minus;1</sup>', link='joule per mole' },
J/kg              J/kg                                  joule
['J/mol'] = { abbr='J/mol', link='joule per mole' },
J/mol             J/mol                                 joule per mole
Js = { abbr='J&sdot;s', link='joule-second' },
Js                J&sdot;s                              joule-second
['J*s'] = { abbr='J&sdot;s', link='joule-second' },
Jupiter mass      <i>M</i><sub>J</sub>                  Jupiter mass
kA = { abbr='kA', link='kiloampere' },
Jupiter radius    <i>R</i><sub>J</sub>                  Jupiter radius
ka = { abbr='ka', link='kiloannum' },
kA                kA                                    kiloampere
['kbit/s'] = { abbr='kbit/s', link='kilobit per second' },
ka                ka                                    kiloannum
['keV/c2'] = { abbr='keV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
kbit/s            kbit/s                                kilobit per second
kG = { abbr='kG', link='kilogauss' },
keV/c2            keV/<i>c</i><sup>2</sup>             electronvolt#Mass
['kg/cm3'] = { abbr='kg/cm<sup>3</sup>', link='density#Formula_and_common_units' },
kG                kG                                    kilogauss
['kg/m3'] = { abbr='kg/m<sup>3</sup>', link='kilogram per cubic metre' },
kg/cm3            kg/cm<sup>3</sup>                    density#Formula and common units
['kg/mol'] = { abbr='kg&sdot;mol<sup>&minus;1</sup>', link='molar mass' },
kg/m3              kg/m<sup>3</sup>                      kilogram per cubic metre
kHz = { abbr='kHz', link='Kilohertz' },
kg/mol            kg&sdot;mol<sup>&minus;1</sup>        molar mass
kpc = { abbr='kpc', link='kiloparsec' },
kHz                kHz                                  Kilohertz
['kpc2'] = { abbr='kpc<sup>2</sup>', link='kiloparsec' },
kJ*mol-1           kJ&sdot;mol<sup>&minus;1</sup>        joule per mole
['kpc3'] = { abbr='kpc<sup>3</sup>', link='kiloparsec' },
kJ/mol            kJ/mol                                joule per mole
['kJ*mol-1'] = { abbr='kJ&sdot;mol<sup>&minus;1</sup>', link='joule per mole' },
kK                kK                                    kilokelvin
['kJ/mol'] = { abbr='kJ/mol', link='joule per mole' },
KPa                kPa                                  pascal (unit)
kK = { abbr='kK', link='kilokelvin' },
kpc                kpc                                  kiloparsec
KPa = { abbr='kPa', link='pascal (unit)' },
kpc2              kpc<sup>2</sup>                      kiloparsec
kT = { abbr='kT', link='kilotesla' },
kpc3              kpc<sup>3</sup>                      kiloparsec
kV = { abbr='kV', link='kilovolt' },
kT                kT                                    kilotesla
['kW·h'] = { abbr='kW&sdot;h', link='kilowatt hour' },
kV                kV                                    kilovolt
['kW.h'] = { abbr='kW&sdot;h', link='kilowatt hour' },
kW.h              kW&sdot;h                            kilowatt hour
kWh = { abbr='kWh', link='kilowatt hour' },
kWh                kWh                                  kilowatt hour
kya = { abbr='kya', link='kyr' },
kW·h              kW&sdot;h                            kilowatt hour
kyr = { abbr='kyr', link='kyr' },
kya                kya                                  kyr
lbf = { abbr='{{lbf}}', link='Pound (force)' },
kyr                kyr                                  kyr
lbm = { abbr='{{lbm}}', link='Pound (mass)' },
L_solar            <i>L</i><sub>&#x2609;</sub>           solar luminosity
ly = { abbr='ly', link='light-year' },
lbf                {{lbf}}                               Pound (force)
['L_solar'] = { abbr='<i>L</i><sub>&#x2609;</sub>', link='solar luminosity' },
lbm                {{lbm}}                               Pound (mass)
['m-3'] = { abbr='m<sup>&minus;3</sup>', link='cubic metre' },
ly                ly                                    light-year
['m-2'] = { abbr='m<sup>&minus;2</sup>', link='square metre' },
m                  m                                    metre
['m-1'] = { abbr='m<sup>&minus;1</sup>', link='metre' },
m*s-1             m&sdot;s<sup>&minus;1</sup>           metre per second
m = { abbr='m', link='metre' },
m*s-2              m&sdot;s<sup>&minus;2</sup>          metre per second squared
['m2'] = { abbr='m<sup>2</sup>', link='Square metre' },
m-1                m<sup>&minus;1</sup>                  metre
['m3'] = { abbr='m<sup>3</sup>', link='Cubic metre' },
m-2                m<sup>&minus;2</sup>                  square metre
metre = { abbr='m', link='metre' },
m-3                m<sup>&minus;3</sup>                  cubic metre
meter = { abbr='m', link='metre' },
m2                m<sup>2</sup>                        Square metre
['m*s-1'] = { abbr='m&sdot;s<sup>&minus;1</sup>', link='metre per second' },
m3                m<sup>3</sup>                        Cubic metre
['m*s-2'] = { abbr='m&sdot;s<sup>&minus;2</sup>', link='metre per second squared' },
M_Earth            <i>M</i><sub></sub>                 Earth mass
['M_Earth'] = { abbr='<i>M</i><sub>⊕</sub>', link='Earth mass' },
M_Jupiter          <i>M</i><sub>J</sub>                 Jupiter mass
['M_Jupiter'] = { abbr='<i>M</i><sub>J</sub>', link='Jupiter mass' },
M_solar            <i>M</i><sub>&#x2609;</sub>           solar mass
['M_Solar'] = { abbr='<i>M</i><sub>&#x2609;</sub>', link='solar mass' },
M_Solar            <i>M</i><sub>&#x2609;</sub>           solar mass
['M_solar'] = { abbr='<i>M</i><sub>&#x2609;</sub>', link='solar mass' },
MA                MA                                    megaampere
mA = { abbr='mA', link='milliampere' },
Ma                Ma                                    megaannum
MA = { abbr='MA', link='megaampere' },
mA                mA                                    milliampere
Ma = { abbr='Ma', link='megaannum' },
Mbit/s            Mbit/s                                megabit per second
['Mbit/s'] = { abbr='Mbit/s', link='megabit per second' },
mcg                µg                                    microgram
mcg = { abbr='µg', link='microgram' },
mcg/dL            µg/dL                                gram per
['mcg/dL'] = { abbr='µg/dL', link='gram per' },
mcg/dl            µg/dl                                gram per
['mcg/dl'] = { abbr='µg/dl', link='gram per' },
meter              m                                    metre
['MeV/c2'] = { abbr='MeV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
metre              m                                    metre
MG = { abbr='MG', link='megagauss' },
MeV/c2            MeV/<i>c</i><sup>2</sup>              electronvolt#Mass
Mg = { abbr='Mg', link='megagram' },
MG                MG                                    megagauss
mG = { abbr='mG', link='milligauss' },
Mg                Mg                                    megagram
['mg/mL'] = { abbr='mg/mL', link='gram per litre' },
mG                mG                                    milligauss
['mg/ml'] = { abbr='mg/mL', link='gram per litre' },
mg/ml              mg/mL                                gram per litre
MHz = { abbr='MHz', link='megahertz' },
mg/mL              mg/mL                                gram per litre
mHz = { abbr='mHz', link='hertz' },
mHz                mHz                                  hertz
['MJ*mol-1'] = { abbr='MJ&sdot;mol<sup>&minus;1</sup>', link='joule per mole' },
MHz                MHz                                  megahertz
['MJ/mol'] = { abbr='MJ/mol', link='joule per mole' },
MJ*mol-1          MJ&sdot;mol<sup>&minus;1</sup>        joule per mole
MK = { abbr='MK', link='megakelvin' },
MJ/mol            MJ/mol                                joule per mole
mK = { abbr='mK', link='millikelvin' },
MK                MK                                    megakelvin
Mpc = { abbr='Mpc', link='parsec#Megaparsecs_and_gigaparsecs' },
mK                mK                                    millikelvin
['Mpc2'] = { abbr='Mpc<sup>2</sup>', link='parsec#Megaparsecs_and_gigaparsecs' },
Mpc                Mpc                                  parsec#Megaparsecs and gigaparsecs
['Mpc3'] = { abbr='Mpc<sup>3</sup>', link='parsec#Megaparsecs_and_gigaparsecs' },
Mpc2              Mpc<sup>2</sup>                      parsec#Megaparsecs and gigaparsecs
MT = { abbr='MT', link='megatesla' },
Mpc3              Mpc<sup>3</sup>                      parsec#Megaparsecs and gigaparsecs
mT = { abbr='mT', link='millitesla' },
MT                MT                                    megatesla
muA = { abbr='µA', link='ampere' },
mT                mT                                    millitesla
muG = { abbr='µG', link='microgauss' },
muA                µA                                    ampere
mug = { abbr='µg', link='microgram' },
muG                µG                                    microgauss
muGal = { abbr='µGal', link='Gal (unit)' },
mug                µg                                    microgram
muHz = { abbr='µHz', link='hertz' },
muGal              µGal                                  Gal (unit)
muJ = { abbr='µJ', link='joule' },
muHz              µHz                                  hertz
muK = { abbr='µK', link='microkelvin' },
muJ                µJ                                    joule
mum = { abbr='µm', link='micrometre' },
muK                µK                                    microkelvin
mus = { abbr='µs', link='microsecond' },
mum                µm                                    micrometre
muT = { abbr='µT', link='microtesla' },
mus                µs                                    microsecond
muV = { abbr='µV', link='volt' },
muT                µT                                    microtesla
MV = { abbr='MV', link='volt' },
muV                µV                                    volt
mV = { abbr='mV', link='volt' },
MV                MV                                    volt
mya = { abbr='mya', link='million years ago' },
mV                mV                                    volt
myr = { abbr='myr', link='million years' },
mya                mya                                  million years ago
nA = { abbr='nA', link='ampere' },
myr                myr                                  million years
['N*A-2'] = { abbr='N&sdot;A<sup>&minus;2</sup>', link='permeability (electromagnetism)' },
N*A-2              N&sdot;A<sup>&minus;2</sup>           permeability (electromagnetism)
nG = { abbr='nG', link='nanogauss' },
N*m-1              N&sdot;m<sup>&minus;1</sup>           joule (unit)
ng = { abbr='ng', link='nanogram' },
nA                nA                                    ampere
nHz = { abbr='nHz', link='hertz' },
nG                nG                                    nanogauss
nK = { abbr='nK', link='nanokelvin' },
ng                ng                                    nanogram
['N*m-1'] = { abbr='N&sdot;m<sup>&minus;1</sup>', link='joule (unit)' },
nHz                nHz                                  hertz
nT = { abbr='nT', link='nanotesla' },
nK                nK                                    nanokelvin
nV = { abbr='nV', link='volt' },
nT                nT                                    nanotesla
PA = { abbr='PA', link='ampere' },
nV                nV                                    volt
pA = { abbr='pA', link='ampere' },
pA                pA                                    ampere
['pc2'] = { abbr='pc<sup>2</sup>', link='Parsec' },
PA                PA                                    ampere
['pc3'] = { abbr='pc<sup>3</sup>', link='Parsec' },
pc2                pc<sup>2</sup>                       Parsec
PG = { abbr='PG', link='petagauss' },
pc3                pc<sup>3</sup>                       Parsec
Pg = { abbr='Pg', link='petagram' },
per cent          %                                    percent                                NOSPACE
pG = { abbr='pG', link='picogauss' },
per mil            ‰                                    per mil                                NOSPACE
pg = { abbr='pg', link='picogram' },
per mill          ‰                                    per mil                                NOSPACE
PHz = { abbr='PHz', link='petahertz' },
per mille          ‰                                    per mil                                NOSPACE
pHz = { abbr='pHz', link='hertz' },
percent            %                                    percent                                NOSPACE
PK = { abbr='PK', link='petakelvin' },
permil            ‰                                    per mil                                NOSPACE
pK = { abbr='pK', link='picokelvin' },
permill            ‰                                    per mil                                NOSPACE
ppb = { abbr='ppb', link='parts per billion' },
permille          ‰                                    per mil                                NOSPACE
ppm = { abbr='ppm', link='parts per million' },
PG                PG                                    petagauss
PT = { abbr='PT', link='petatesla' },
Pg                Pg                                    petagram
pT = { abbr='pT', link='picotesla' },
pG                pG                                    picogauss
PV = { abbr='PV', link='volt' },
pg                pg                                    picogram
pV = { abbr='pV', link='volt' },
pHz                pHz                                  hertz
R = { abbr='R', link='rayleigh (unit)' },
PHz                PHz                                  petahertz
['R_Earth'] = { abbr='<i>R</i><sub>⊕</sub>', link='Earth radius' },
PK                PK                                    petakelvin
['R_Jupiter'] = { abbr='<i>R</i><sub>J</sub>', link='Jupiter radius' },
pK                pK                                    picokelvin
['R_Solar'] = { abbr='<i>R</i><sub>&#x2609;</sub>', link='solar radius' },
ppb                ppb                                  parts per billion
['R_solar'] = { abbr='<i>R</i><sub>&#x2609;</sub>', link='solar radius' },
ppm                ppm                                  parts per million
s = { abbr='s', link='second' },
PT                PT                                    petatesla
second = { abbr='s', link='second' },
pT                pT                                    picotesla
seconds = { abbr='s', link='second' },
PV                PV                                    volt
['s-1'] = { abbr='s<sup>&minus;1</sup>', link='second' },
pV                pV                                    volt
['s-2'] = { abbr='s<sup>&minus;2</sup>', link='second' },
R                  R                                    rayleigh (unit)
['s2'] = { abbr='s<sup>2</sup>', link='second' },
R_Earth            <i>R</i><sub></sub>                 Earth radius
['Solar luminosity'] = { abbr='<i>L</i><sub>&#x2609;</sub>', link='solar luminosity' },
R_Jupiter          <i>R</i><sub>J</sub>                 Jupiter radius
['solar luminosity'] = { abbr='<i>L</i><sub>&#x2609;</sub>', link='solar luminosity' },
R_solar            <i>R</i><sub>&#x2609;</sub>           solar radius
['Solar mass'] = { abbr='<i>M</i><sub>&#x2609;</sub>', link='solar mass' },
R_Solar            <i>R</i><sub>&#x2609;</sub>          solar radius
['solar mass'] = { abbr='<i>M</i><sub>&#x2609;</sub>', link='solar mass' },
s                  s                                    second
['Solar radius'] = { abbr='<i>R</i><sub>&#x2609;</sub>', link='solar radius' },
s-1                s<sup>&minus;1</sup>                  second
['solar radius'] = { abbr='<i>R</i><sub>&#x2609;</sub>', link='solar radius' },
s-2                s<sup>&minus;2</sup>                  second
TA = { abbr='TA', link='ampere' },
s2                s<sup>2</sup>                        second
['Tbit/s'] = { abbr='Tbit/s', link='terabit per second' },
second            s                                     second
['TeV/c2'] = { abbr='TeV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
seconds            s                                    second
TG = { abbr='TG', link='teragauss' },
solar luminosity  <i>L</i><sub>&#x2609;</sub>          solar luminosity
Tg = { abbr='Tg', link='teragram' },
Solar luminosity  <i>L</i><sub>&#x2609;</sub>          solar luminosity
THz = { abbr='THz', link='terahertz' },
solar mass        <i>M</i><sub>&#x2609;</sub>          solar mass
['TJ*mol-1'] = { abbr='TJ&sdot;mol<sup>&minus;1</sup>', link='joule per mole' },
Solar mass        <i>M</i><sub>&#x2609;</sub>          solar mass
['TJ/mol'] = { abbr='TJ/mol', link='joule per mole' },
solar radius      <i>R</i><sub>&#x2609;</sub>          solar radius
TK = { abbr='TK', link='terakelvin' },
Solar radius      <i>R</i><sub>&#x2609;</sub>          solar radius
Torr = { abbr='Torr', link='Torr' },
TA                TA                                    ampere
torr = { abbr='Torr', link='Torr' },
Tbit/s            Tbit/s                                terabit per second
TT = { abbr='TT', link='teratesla' },
TeV/c2            TeV/<i>c</i><sup>2</sup>             electronvolt#Mass
TV = { abbr='TV', link='volt' },
TG                TG                                    teragauss
u = { abbr='u', link='atomic mass unit' },
Tg                Tg                                    teragram
uBP = { abbr='<sup>14</sup>C yr BP', link='Radiocarbon dating#Calibration' },
THz                THz                                  terahertz
USgal = { abbr='US gal', link='US gallon' },
TJ*mol-1          TJ&sdot;mol<sup>&minus;1</sup>        joule per mole
V = { abbr='V', link='volt' },
TJ/mol            TJ/mol                                joule per mole
VV = { abbr='VV', link='volt' },
TK                TK                                    terakelvin
['V/m'] = { abbr='V/m', link='electric field' },
torr              Torr                                  Torr
['Vm-1'] = { abbr='V&sdot;m<sup>&minus;1</sup>', link='electric field' },
Torr              Torr                                  Torr
['V*m-1'] = { abbr='V&sdot;m<sup>&minus;1</sup>', link='electric field' },
TT                TT                                    teratesla
W = { abbr='W', link='Watt' },
TV                TV                                    volt
Wb = { abbr='Wb', link='Weber (unit)' },
u                  u                                    atomic mass unit
y = { abbr='y', link='year' },
uBP                <sup>14</sup>C yr BP                  Radiocarbon dating#Calibration
yA = { abbr='yA', link='ampere' },
USgal              US gal                                US gallon
YA = { abbr='YA', link='ampere' },
V                  V                                    volt
year = { abbr='year', link='year' },
V*m-1              V&sdot;m<sup>&minus;1</sup>          electric field
years = { abbr='years', link='year' },
V/m                V/m                                  electric field
YG = { abbr='YG', link='yottagauss' },
Vm-1              V&sdot;m<sup>&minus;1</sup>          electric field
Yg = { abbr='Yg', link='yottagram' },
VV                VV                                    volt
yG = { abbr='yG', link='yoctogauss' },
W                  W                                    Watt
yg = { abbr='yg', link='yoctogram' },
Wb                Wb                                    Weber (unit)
YHz = { abbr='YHz', link='yottahertz' },
y                  y                                    year
yHz = { abbr='yHz', link='hertz' },
YA                YA                                    ampere
YK = { abbr='YK', link='yottakelvin' },
yA                yA                                    ampere
yK = { abbr='yK', link='yoctokelvin' },
year              year                                  year
ym = { abbr='ym', link='yoctometre' },
years              years                                year
yr = { abbr='yr', link='year#Symbols_y_and_yr' },
yG                yG                                    yoctogauss
YT = { abbr='YT', link='Yottatesla' },
yg                yg                                    yoctogram
yT = { abbr='yT', link='yoctotesla' },
YG                YG                                    yottagauss
YV = { abbr='YV', link='volt' },
Yg                Yg                                    yottagram
yV = { abbr='yV', link='volt' },
yHz                yHz                                  hertz
ZA = { abbr='ZA', link='ampere' },
YHz                YHz                                  yottahertz
zA = { abbr='zA', link='ampere' },
yK                yK                                    yoctokelvin
ZG = { abbr='ZG', link='zettagauss' },
YK                YK                                    yottakelvin
Zg = { abbr='Zg', link='zettagram' },
ym                ym                                    yoctometre
zG = { abbr='zG', link='zeptogauss' },
yr                yr                                    year#Symbols y and yr
zg = { abbr='zg', link='zeptogram' },
yT                yT                                    yoctotesla
ZHz = { abbr='ZHz', link='hertz' },
YT                YT                                    Yottatesla
zHz = { abbr='zHz', link='hertz' },
YV                YV                                    volt
ZK = { abbr='ZK', link='zettakelvin' },
yV                yV                                    volt
zK = { abbr='zK', link='zeptokelvin' },
ZA                ZA                                    ampere
zm = { abbr='zm', link='zeptometre' },
zA                zA                                    ampere
ZT = { abbr='ZT', link='zettatesla' },
zG                zG                                    zeptogauss
zT = { abbr='zT', link='zeptotesla' },
zg                zg                                    zeptogram
ZV = { abbr='ZV', link='volt' },
ZG                ZG                                    zettagauss
zV = { abbr='zV', link='volt' },
Zg                Zg                                    zettagram
['µA'] = { abbr='µA', link='microampere' },
zHz                zHz                                  hertz
['µB'] = { abbr='µ<sub>B</sub>', link='Bohr magneton' },
ZHz                ZHz                                  hertz
['µG'] = { abbr='µG', link='microgauss' },
zK                zK                                    zeptokelvin
['µGal'] = { abbr='µGal', link='Gal (unit)' },
ZK                ZK                                    zettakelvin
['μg/dl'] = { abbr='μg/dL', link='gram per litre' },
zm                zm                                    zeptometre
['μg/dL'] = { abbr='μg/dL', link='gram per litre' },
zT                zT                                    zeptotesla
['µHz'] = { abbr='µHz', link='hertz' },
ZT                ZT                                    zettatesla
['µK'] = { abbr='µK', link='microkelvin' },
zV                zV                                    volt
['µN'] = { abbr='µ<sub>N</sub>', link='nuclear magneton' },
ZV                ZV                                    volt
['μN'] = { abbr='µ<sub>N</sub>', link='nuclear magneton' },
['µT'] = { abbr='µT', link='microtesla' },
['µV'] = { abbr='µV', link='microvolt' }
}


return function (u, tbl)
billiard          billiard                              Orders of magnitude (numbers)#1015
if not tbl then
billion            billion                              1,000,000,000
tbl = {}
billionth          billionth                            1,000,000,000
end
billionths        billionths                            1,000,000,000
local per = tbl.per
decilliard        decilliard                            Orders of magnitude (numbers)#1063
local link = tbl.link
decillion          decillion                            Orders of magnitude (numbers)#1033
local perl = tbl.per_link
decillionth        decillionth                          Orders of magnitude (numbers)#1033
decillionths      decillionths                          Orders of magnitude (numbers)#1033
milliard          milliard                              1,000,000,000
nonilliard        nonilliard                            Orders of magnitude (numbers)#1057
nonillion          nonillion                            Orders of magnitude (numbers)#1030
nonillionth        nonillionth                          Orders of magnitude (numbers)#1030
nonillionths      nonillionths                          Orders of magnitude (numbers)#1030
octilliard        octilliard                            Orders of magnitude (numbers)#1051
octillion          octillion                            Orders of magnitude (numbers)#1027
octillionth        octillionth                          Orders of magnitude (numbers)#1027
octillionths      octillionths                          Orders of magnitude (numbers)#1027
quadrilliard      quadrilliard                          Orders of magnitude (numbers)#1027
quadrillion        quadrillion                          Orders of magnitude (numbers)#1015
quadrillionth      quadrillionth                        Orders of magnitude (numbers)#1015
quadrillionths    quadrillionths                        Orders of magnitude (numbers)#1015
quintilliard      quintilliard                          Orders of magnitude (numbers)#1033
quintillion        quintillion                          Orders of magnitude (numbers)#1018
quintillionth      quintillionth                        Orders of magnitude (numbers)#1018
quintillionths    quintillionths                        Orders of magnitude (numbers)#1018
septilliard        septilliard                          Orders of magnitude (numbers)#1045
septillion        septillion                            Orders of magnitude (numbers)#1024
septillionth      septillionth                          Orders of magnitude (numbers)#1024
septillionths      septillionths                        Orders of magnitude (numbers)#1024
sextilliard        sextilliard                          Orders of magnitude (numbers)#1039
sextillion        sextillion                            Orders of magnitude (numbers)#1021
sextillionth      sextillionth                          Orders of magnitude (numbers)#1021
sextillionths      sextillionths                        Orders of magnitude (numbers)#1021
trilliard          trilliard                            Orders of magnitude (numbers)#1021
trillion          trillion                              Orders of magnitude (numbers)#1012
trillionth        trillionth                            Orders of magnitude (numbers)#1012
trillionths        trillionths                          Orders of magnitude (numbers)#1012
 
]=]
 
-- If val has "|long scale=on" the following definitions are used
-- (if not found here, the normal definitions are used).
-- Unit code      Symbol                                Link                                  Flags
local builtin_units_long_scale = [=[
 
billion            billion                              Orders of magnitude (numbers)#1012
billionth          billionth                            Orders of magnitude (numbers)#1012
billionths        billionths                            Orders of magnitude (numbers)#1012
decillion          decillion                            Orders of magnitude (numbers)#1060
decillionth        decillionth                          Orders of magnitude (numbers)#1060
decillionths      decillionths                          Orders of magnitude (numbers)#1060
nonillion          nonillion                            Orders of magnitude (numbers)#1054
nonillionth        nonillionth                          Orders of magnitude (numbers)#1054
nonillionths      nonillionths                          Orders of magnitude (numbers)#1054
octillion          octillion                            Orders of magnitude (numbers)#1048
octillionth        octillionth                          Orders of magnitude (numbers)#1048
octillionths      octillionths                          Orders of magnitude (numbers)#1048
quadrillion        quadrillion                          Orders of magnitude (numbers)#1024
quadrillionth      quadrillionth                        Orders of magnitude (numbers)#1024
quadrillionths    quadrillionths                        Orders of magnitude (numbers)#1024
quintillion        quintillion                          Orders of magnitude (numbers)#1030
quintillionth      quintillionth                        Orders of magnitude (numbers)#1030
quintillionths    quintillionths                        Orders of magnitude (numbers)#1030
septillion        septillion                            Orders of magnitude (numbers)#1042
septillionth      septillionth                          Orders of magnitude (numbers)#1042
septillionths      septillionths                        Orders of magnitude (numbers)#1042
sextillion        sextillion                            Orders of magnitude (numbers)#1036
sextillionth      sextillionth                          Orders of magnitude (numbers)#1036
sextillionths      sextillionths                        Orders of magnitude (numbers)#1036
trillion          trillion                              Orders of magnitude (numbers)#1018
trillionth        trillionth                            Orders of magnitude (numbers)#1018
trillionths        trillionths                          Orders of magnitude (numbers)#1018
 
]=]


local function get_unit(_u)
local function get_builtin_unit(unitcode, definitions)
-- load convert module data
-- Return table of information for the specified built-in unit, or nil if not known.
local convert_data = mw.loadData('Module:Convert/data').all_units
-- Each defined unit code must be followed by two spaces (not tab characters).
local c_unit = convert_data[_u]
local _, pos = definitions:find('\n' .. unitcode .. '  ', 1, true)
if c_unit then
if pos then
if c_unit.target then
local endline = definitions:find('\n', pos, true)
c_unit = convert_data[c_unit.target]
if endline then
local result = {}
local n = 0
local text = definitions:sub(pos, endline - 1)
for item in (text .. '  '):gmatch('(%S[^\n]-)%s%s') do
if item == 'NOSPACE' then
result.nospace = true
else
n = n + 1
if n == 1 then
result.symbol = item
elseif n == 2 then
result.link = item
else
break
end
end
end
if n == 2 then
return result
end
end
return {abbr=c_unit.symbol or _u, link=c_unit.link or c_unit.name1 or _u, symlink=c_unit.symlink}
-- Ignore invalid definition.
else
return nil
end
end
end
end
end


local unit = units_tbl[u] or get_unit(u) or {abbr=u, link=u}
local function get_unit(ucode, value, want_link, want_longscale)
local nospace = unit.nospace
local result = want_longscale and
 
get_builtin_unit(ucode, builtin_units_long_scale) or
if link and unit.symlink then
get_builtin_unit(ucode, builtin_units)
unit = unit.symlink
local lookup = require('Module:Convert/sandbox')._unit
elseif link then
local convert_unit = lookup(ucode, { value = value, link = want_link })
unit = '[['..unit.link..'|'..unit.abbr..']]'
if result then
else
-- Have: result.symbol + result.link + result.nospace
unit = unit.abbr
if want_link then
end
result.text = '[[' .. result.link .. '|' .. result.symbol .. ']]'
if per then
-- Look for "*" "." or "/"
-- If found, add parentheses
if u:find('[%*%.%/]') then
unit = '('..unit..')'
end
local per_u = units_tbl[per] or get_unit(per) or {abbr=per, link=per}
if perl and per_u.symlink then
per_u = per_u.symlink
elseif perl then
per_u = '[['..per_u.link..'|'..per_u.abbr..']]'
else
else
per_u = per_u.abbr
result.text = result.symbol
end
end
-- Look for "*" "." or "/"
result.sortkey = convert_unit.sortkey
-- If found, add parentheses
else
if per:find('[%*%.%/]') then
result = {
per_u = '('..per_u..')'
text = convert_unit.text,
end
sortkey = convert_unit.sortkey,
unit = unit..'/'..per_u
}
end
end
return result
end


if not nospace then
local function bracketed(ucode, text)
unit = '&nbsp;'..unit
if ucode:find('[*./]') then
return '(' .. text .. ')'
end
end
return text
end


return unit
local function makeunit(ucode, options)
-- Return wikitext, sortkey for the requested unit and options.
-- LATER The sortkey does not account for any per unit.
options = options or {}
local unit = get_unit(ucode, options.value, options.link, options.longscale)
local text = unit.text
local percode = options.per
if percode then
local perunit = get_unit(percode, 0, options.per_link, options.longscale)
text = bracketed(ucode, text) .. '/' .. bracketed(percode, perunit.text)
end
if not unit.nospace then
text = '&nbsp;' .. text
end
return text, unit.sortkey
end
end
return makeunit

Revision as of 09:46, 7 July 2015

Documentation for this module may be created at Module:Val/units/doc

-- Definitions for units known to val (short scale; see below for long scale).
-- There must be two spaces (not tab characters) after each unit code, and
-- two spaces or tabs between columns.
-- There must be a blank line before the first unit and a newline after the last.
-- Unit code       Symbol                                Link                                   Flags
local builtin_units = [=[

"                  ″                                     second of arc                          NOSPACE
%                  %                                     percent                                NOSPACE
'                  ′                                     minute of arc                          NOSPACE
°                  °                                     degree (angle)                         NOSPACE
‰                  ‰                                     per mil                                NOSPACE
′                  ′                                     minute of arc                          NOSPACE
″                  ″                                     second of arc                          NOSPACE
µA                 µA                                    microampere
µB                 µ<sub>B</sub>                         Bohr magneton
µG                 µG                                    microgauss
µGal               µGal                                  Gal (unit)
µHz                µHz                                   hertz
µK                 µK                                    microkelvin
µN                 µ<sub>N</sub>                         nuclear magneton
µT                 µT                                    microtesla
µV                 µV                                    microvolt
μg/dL              μg/dL                                 gram per litre
μg/dl              μg/dL                                 gram per litre
μN                 µ<sub>N</sub>                         nuclear magneton
A                  A                                     ampere
aA                 aA                                    attoampere
AD                 AD                                    Anno Domini
aG                 aG                                    attogauss
ag                 ag                                    attogram
aHz                aHz                                   attohertz
aK                 aK                                    attokelvin
am                 am                                    attometre
arcmin             ′                                     minute of arc                          NOSPACE
arcminute          ′                                     minute of arc                          NOSPACE
arcsec             ″                                     second of arc                          NOSPACE
arcsecond          ″                                     second of arc                          NOSPACE
aT                 aT                                    attotesla
BC                 BC                                    Before Christ
BCE                BCE                                   Before the Common Era
bit/s              bit/s                                 bit per second
BP                 BP                                    Before present
bps                bit/s                                 bit per second
bya                bya                                   billion years ago
byr                byr                                   billion years
c                  <i>c</i>                              speed of light
C                  C                                     coulomb
cA                 cA                                    centiampere
CE                 CE                                    Common Era
cG                 cG                                    centigauss
cg                 cg                                    centigram
cHz                cHz                                   centihertz
cK                 cK                                    centikelvin
cm-1               cm<sup>&minus;1</sup>                 wavenumber
cT                 cT                                    centitesla
cV                 cV                                    volt
dA                 dA                                    ampere
daA                daA                                   decaampere
daG                daG                                   decagauss
dag                dag                                   decagram
daHz               daHz                                  decahertz
daK                daK                                   decakelvin
daT                daT                                   decatesla
daV                daV                                   volt
deg                °                                     degree (angle)                         NOSPACE
degC               °C                                    degree Celsius
degF               °F                                    Fahrenheit
degR               °R                                    Rankine scale
dG                 dG                                    decigauss
dg                 dg                                    decigram
dHz                dHz                                   hertz
dK                 dK                                    decikelvin
dT                 dT                                    decitesla
dV                 dV                                    volt
e                  <i>e</i>                              Elementary charge
EA                 EA                                    ampere
Earth mass         <i>M</i><sub>⊕</sub>                  Earth mass
Earth radius       <i>R</i><sub>⊕</sub>                  Earth radius
EG                 EG                                    exagauss
Eg                 Eg                                    exagram
EHz                EHz                                   exahertz
EK                 EK                                    exakelvin
ET                 ET                                    exatesla
EV                 EV                                    volt
eV/c2              eV/<i>c</i><sup>2</sup>               electronvolt#Mass
F                  F                                     farad
fA                 fA                                    femtoampere
fb-1               fb<sup>&minus;1</sup>                 Barn (unit)
fG                 fG                                    femtogauss
fg                 fg                                    femtogram
fHz                fHz                                   femtohertz
fK                 fK                                    femtokelvin
fT                 fT                                    femtotesla
fV                 fV                                    femtovolt
g*mol-1            g&sdot;mol<sup>&minus;1</sup>         molar mass
g/cm3              g/cm<sup>3</sup>                      gram per cubic centimetre
g/l                g/l                                   gram per litre
g/L                g/L                                   gram per litre
g/mol              g&sdot;mol<sup>&minus;1</sup>         molar mass
GA                 GA                                    gigaampere
Ga                 Ga                                    gigaannum
gal                gal                                   gallon
Gbit/s             Gbit/s                                gigabit per second
GeV/c2             GeV/<i>c</i><sup>2</sup>              electronvolt#Mass
GG                 GG                                    gigagauss
Gg                 Gg                                    gigagram
GHz                GHz                                   gigahertz
GJ*mol-1           GJ&sdot;mol<sup>&minus;1</sup>        joule per mole
GJ/mol             GJ/mol                                joule per mole
GK                 GK                                    gigakelvin
GPa                GPa                                   gigapascal
Gpc                Gpc                                   megaparsec#Megaparsecs and gigaparsecs
Gpc2               Gpc<sup>2</sup>                       megaparsec#Megaparsecs and gigaparsecs
Gpc3               Gpc<sup>3</sup>                       megaparsec#Megaparsecs and gigaparsecs
GT                 GT                                    gigatesla
GV                 GV                                    gigavolt
Gyr                Ga                                    gigaannum
H                  H                                     Henry (unit)
H*m-1              H                                     Henry (unit)
hA                 hA                                    hectoampere
hG                 hG                                    hectogauss
hg                 hg                                    hectogram
hHz                hHz                                   hectohertz
hK                 hK                                    hectokelvin
hT                 hT                                    hectotesla
hV                 hV                                    volt
Hz                 Hz                                    hertz
J*mol-1            J&sdot;mol<sup>&minus;1</sup>         joule per mole
J*s                J&sdot;s                              joule-second
J/kg               J/kg                                  joule
J/mol              J/mol                                 joule per mole
Js                 J&sdot;s                              joule-second
Jupiter mass       <i>M</i><sub>J</sub>                  Jupiter mass
Jupiter radius     <i>R</i><sub>J</sub>                  Jupiter radius
kA                 kA                                    kiloampere
ka                 ka                                    kiloannum
kbit/s             kbit/s                                kilobit per second
keV/c2             keV/<i>c</i><sup>2</sup>              electronvolt#Mass
kG                 kG                                    kilogauss
kg/cm3             kg/cm<sup>3</sup>                     density#Formula and common units
kg/m3              kg/m<sup>3</sup>                      kilogram per cubic metre
kg/mol             kg&sdot;mol<sup>&minus;1</sup>        molar mass
kHz                kHz                                   Kilohertz
kJ*mol-1           kJ&sdot;mol<sup>&minus;1</sup>        joule per mole
kJ/mol             kJ/mol                                joule per mole
kK                 kK                                    kilokelvin
KPa                kPa                                   pascal (unit)
kpc                kpc                                   kiloparsec
kpc2               kpc<sup>2</sup>                       kiloparsec
kpc3               kpc<sup>3</sup>                       kiloparsec
kT                 kT                                    kilotesla
kV                 kV                                    kilovolt
kW.h               kW&sdot;h                             kilowatt hour
kWh                kWh                                   kilowatt hour
kW·h               kW&sdot;h                             kilowatt hour
kya                kya                                   kyr
kyr                kyr                                   kyr
L_solar            <i>L</i><sub>&#x2609;</sub>           solar luminosity
lbf                {{lbf}}                               Pound (force)
lbm                {{lbm}}                               Pound (mass)
ly                 ly                                    light-year
m                  m                                     metre
m*s-1              m&sdot;s<sup>&minus;1</sup>           metre per second
m*s-2              m&sdot;s<sup>&minus;2</sup>           metre per second squared
m-1                m<sup>&minus;1</sup>                  metre
m-2                m<sup>&minus;2</sup>                  square metre
m-3                m<sup>&minus;3</sup>                  cubic metre
m2                 m<sup>2</sup>                         Square metre
m3                 m<sup>3</sup>                         Cubic metre
M_Earth            <i>M</i><sub>⊕</sub>                  Earth mass
M_Jupiter          <i>M</i><sub>J</sub>                  Jupiter mass
M_solar            <i>M</i><sub>&#x2609;</sub>           solar mass
M_Solar            <i>M</i><sub>&#x2609;</sub>           solar mass
MA                 MA                                    megaampere
Ma                 Ma                                    megaannum
mA                 mA                                    milliampere
Mbit/s             Mbit/s                                megabit per second
mcg                µg                                    microgram
mcg/dL             µg/dL                                 gram per
mcg/dl             µg/dl                                 gram per
meter              m                                     metre
metre              m                                     metre
MeV/c2             MeV/<i>c</i><sup>2</sup>              electronvolt#Mass
MG                 MG                                    megagauss
Mg                 Mg                                    megagram
mG                 mG                                    milligauss
mg/ml              mg/mL                                 gram per litre
mg/mL              mg/mL                                 gram per litre
mHz                mHz                                   hertz
MHz                MHz                                   megahertz
MJ*mol-1           MJ&sdot;mol<sup>&minus;1</sup>        joule per mole
MJ/mol             MJ/mol                                joule per mole
MK                 MK                                    megakelvin
mK                 mK                                    millikelvin
Mpc                Mpc                                   parsec#Megaparsecs and gigaparsecs
Mpc2               Mpc<sup>2</sup>                       parsec#Megaparsecs and gigaparsecs
Mpc3               Mpc<sup>3</sup>                       parsec#Megaparsecs and gigaparsecs
MT                 MT                                    megatesla
mT                 mT                                    millitesla
muA                µA                                    ampere
muG                µG                                    microgauss
mug                µg                                    microgram
muGal              µGal                                  Gal (unit)
muHz               µHz                                   hertz
muJ                µJ                                    joule
muK                µK                                    microkelvin
mum                µm                                    micrometre
mus                µs                                    microsecond
muT                µT                                    microtesla
muV                µV                                    volt
MV                 MV                                    volt
mV                 mV                                    volt
mya                mya                                   million years ago
myr                myr                                   million years
N*A-2              N&sdot;A<sup>&minus;2</sup>           permeability (electromagnetism)
N*m-1              N&sdot;m<sup>&minus;1</sup>           joule (unit)
nA                 nA                                    ampere
nG                 nG                                    nanogauss
ng                 ng                                    nanogram
nHz                nHz                                   hertz
nK                 nK                                    nanokelvin
nT                 nT                                    nanotesla
nV                 nV                                    volt
pA                 pA                                    ampere
PA                 PA                                    ampere
pc2                pc<sup>2</sup>                        Parsec
pc3                pc<sup>3</sup>                        Parsec
per cent           %                                     percent                                NOSPACE
per mil            ‰                                     per mil                                NOSPACE
per mill           ‰                                     per mil                                NOSPACE
per mille          ‰                                     per mil                                NOSPACE
percent            %                                     percent                                NOSPACE
permil             ‰                                     per mil                                NOSPACE
permill            ‰                                     per mil                                NOSPACE
permille           ‰                                     per mil                                NOSPACE
PG                 PG                                    petagauss
Pg                 Pg                                    petagram
pG                 pG                                    picogauss
pg                 pg                                    picogram
pHz                pHz                                   hertz
PHz                PHz                                   petahertz
PK                 PK                                    petakelvin
pK                 pK                                    picokelvin
ppb                ppb                                   parts per billion
ppm                ppm                                   parts per million
PT                 PT                                    petatesla
pT                 pT                                    picotesla
PV                 PV                                    volt
pV                 pV                                    volt
R                  R                                     rayleigh (unit)
R_Earth            <i>R</i><sub>⊕</sub>                  Earth radius
R_Jupiter          <i>R</i><sub>J</sub>                  Jupiter radius
R_solar            <i>R</i><sub>&#x2609;</sub>           solar radius
R_Solar            <i>R</i><sub>&#x2609;</sub>           solar radius
s                  s                                     second
s-1                s<sup>&minus;1</sup>                  second
s-2                s<sup>&minus;2</sup>                  second
s2                 s<sup>2</sup>                         second
second             s                                     second
seconds            s                                     second
solar luminosity   <i>L</i><sub>&#x2609;</sub>           solar luminosity
Solar luminosity   <i>L</i><sub>&#x2609;</sub>           solar luminosity
solar mass         <i>M</i><sub>&#x2609;</sub>           solar mass
Solar mass         <i>M</i><sub>&#x2609;</sub>           solar mass
solar radius       <i>R</i><sub>&#x2609;</sub>           solar radius
Solar radius       <i>R</i><sub>&#x2609;</sub>           solar radius
TA                 TA                                    ampere
Tbit/s             Tbit/s                                terabit per second
TeV/c2             TeV/<i>c</i><sup>2</sup>              electronvolt#Mass
TG                 TG                                    teragauss
Tg                 Tg                                    teragram
THz                THz                                   terahertz
TJ*mol-1           TJ&sdot;mol<sup>&minus;1</sup>        joule per mole
TJ/mol             TJ/mol                                joule per mole
TK                 TK                                    terakelvin
torr               Torr                                  Torr
Torr               Torr                                  Torr
TT                 TT                                    teratesla
TV                 TV                                    volt
u                  u                                     atomic mass unit
uBP                <sup>14</sup>C yr BP                  Radiocarbon dating#Calibration
USgal              US gal                                US gallon
V                  V                                     volt
V*m-1              V&sdot;m<sup>&minus;1</sup>           electric field
V/m                V/m                                   electric field
Vm-1               V&sdot;m<sup>&minus;1</sup>           electric field
VV                 VV                                    volt
W                  W                                     Watt
Wb                 Wb                                    Weber (unit)
y                  y                                     year
YA                 YA                                    ampere
yA                 yA                                    ampere
year               year                                  year
years              years                                 year
yG                 yG                                    yoctogauss
yg                 yg                                    yoctogram
YG                 YG                                    yottagauss
Yg                 Yg                                    yottagram
yHz                yHz                                   hertz
YHz                YHz                                   yottahertz
yK                 yK                                    yoctokelvin
YK                 YK                                    yottakelvin
ym                 ym                                    yoctometre
yr                 yr                                    year#Symbols y and yr
yT                 yT                                    yoctotesla
YT                 YT                                    Yottatesla
YV                 YV                                    volt
yV                 yV                                    volt
ZA                 ZA                                    ampere
zA                 zA                                    ampere
zG                 zG                                    zeptogauss
zg                 zg                                    zeptogram
ZG                 ZG                                    zettagauss
Zg                 Zg                                    zettagram
zHz                zHz                                   hertz
ZHz                ZHz                                   hertz
zK                 zK                                    zeptokelvin
ZK                 ZK                                    zettakelvin
zm                 zm                                    zeptometre
zT                 zT                                    zeptotesla
ZT                 ZT                                    zettatesla
zV                 zV                                    volt
ZV                 ZV                                    volt

billiard           billiard                              Orders of magnitude (numbers)#1015
billion            billion                               1,000,000,000
billionth          billionth                             1,000,000,000
billionths         billionths                            1,000,000,000
decilliard         decilliard                            Orders of magnitude (numbers)#1063
decillion          decillion                             Orders of magnitude (numbers)#1033
decillionth        decillionth                           Orders of magnitude (numbers)#1033
decillionths       decillionths                          Orders of magnitude (numbers)#1033
milliard           milliard                              1,000,000,000
nonilliard         nonilliard                            Orders of magnitude (numbers)#1057
nonillion          nonillion                             Orders of magnitude (numbers)#1030
nonillionth        nonillionth                           Orders of magnitude (numbers)#1030
nonillionths       nonillionths                          Orders of magnitude (numbers)#1030
octilliard         octilliard                            Orders of magnitude (numbers)#1051
octillion          octillion                             Orders of magnitude (numbers)#1027
octillionth        octillionth                           Orders of magnitude (numbers)#1027
octillionths       octillionths                          Orders of magnitude (numbers)#1027
quadrilliard       quadrilliard                          Orders of magnitude (numbers)#1027
quadrillion        quadrillion                           Orders of magnitude (numbers)#1015
quadrillionth      quadrillionth                         Orders of magnitude (numbers)#1015
quadrillionths     quadrillionths                        Orders of magnitude (numbers)#1015
quintilliard       quintilliard                          Orders of magnitude (numbers)#1033
quintillion        quintillion                           Orders of magnitude (numbers)#1018
quintillionth      quintillionth                         Orders of magnitude (numbers)#1018
quintillionths     quintillionths                        Orders of magnitude (numbers)#1018
septilliard        septilliard                           Orders of magnitude (numbers)#1045
septillion         septillion                            Orders of magnitude (numbers)#1024
septillionth       septillionth                          Orders of magnitude (numbers)#1024
septillionths      septillionths                         Orders of magnitude (numbers)#1024
sextilliard        sextilliard                           Orders of magnitude (numbers)#1039
sextillion         sextillion                            Orders of magnitude (numbers)#1021
sextillionth       sextillionth                          Orders of magnitude (numbers)#1021
sextillionths      sextillionths                         Orders of magnitude (numbers)#1021
trilliard          trilliard                             Orders of magnitude (numbers)#1021
trillion           trillion                              Orders of magnitude (numbers)#1012
trillionth         trillionth                            Orders of magnitude (numbers)#1012
trillionths        trillionths                           Orders of magnitude (numbers)#1012

]=]

-- If val has "|long scale=on" the following definitions are used
-- (if not found here, the normal definitions are used).
-- Unit code       Symbol                                Link                                   Flags
local builtin_units_long_scale = [=[

billion            billion                               Orders of magnitude (numbers)#1012
billionth          billionth                             Orders of magnitude (numbers)#1012
billionths         billionths                            Orders of magnitude (numbers)#1012
decillion          decillion                             Orders of magnitude (numbers)#1060
decillionth        decillionth                           Orders of magnitude (numbers)#1060
decillionths       decillionths                          Orders of magnitude (numbers)#1060
nonillion          nonillion                             Orders of magnitude (numbers)#1054
nonillionth        nonillionth                           Orders of magnitude (numbers)#1054
nonillionths       nonillionths                          Orders of magnitude (numbers)#1054
octillion          octillion                             Orders of magnitude (numbers)#1048
octillionth        octillionth                           Orders of magnitude (numbers)#1048
octillionths       octillionths                          Orders of magnitude (numbers)#1048
quadrillion        quadrillion                           Orders of magnitude (numbers)#1024
quadrillionth      quadrillionth                         Orders of magnitude (numbers)#1024
quadrillionths     quadrillionths                        Orders of magnitude (numbers)#1024
quintillion        quintillion                           Orders of magnitude (numbers)#1030
quintillionth      quintillionth                         Orders of magnitude (numbers)#1030
quintillionths     quintillionths                        Orders of magnitude (numbers)#1030
septillion         septillion                            Orders of magnitude (numbers)#1042
septillionth       septillionth                          Orders of magnitude (numbers)#1042
septillionths      septillionths                         Orders of magnitude (numbers)#1042
sextillion         sextillion                            Orders of magnitude (numbers)#1036
sextillionth       sextillionth                          Orders of magnitude (numbers)#1036
sextillionths      sextillionths                         Orders of magnitude (numbers)#1036
trillion           trillion                              Orders of magnitude (numbers)#1018
trillionth         trillionth                            Orders of magnitude (numbers)#1018
trillionths        trillionths                           Orders of magnitude (numbers)#1018

]=]

local function get_builtin_unit(unitcode, definitions)
	-- Return table of information for the specified built-in unit, or nil if not known.
	-- Each defined unit code must be followed by two spaces (not tab characters).
	local _, pos = definitions:find('\n' .. unitcode .. '  ', 1, true)
	if pos then
		local endline = definitions:find('\n', pos, true)
		if endline then
			local result = {}
			local n = 0
			local text = definitions:sub(pos, endline - 1)
			for item in (text .. '  '):gmatch('(%S[^\n]-)%s%s') do
				if item == 'NOSPACE' then
					result.nospace = true
				else
					n = n + 1
					if n == 1 then
						result.symbol = item
					elseif n == 2 then
						result.link = item
					else
						break
					end
				end
			end
			if n == 2 then
				return result
			end
			-- Ignore invalid definition.
		end
	end
end

local function get_unit(ucode, value, want_link, want_longscale)
	local result = want_longscale and
		get_builtin_unit(ucode, builtin_units_long_scale) or
		get_builtin_unit(ucode, builtin_units)
	local lookup = require('Module:Convert/sandbox')._unit
	local convert_unit = lookup(ucode, { value = value, link = want_link })
	if result then
		-- Have: result.symbol + result.link + result.nospace
		if want_link then
			result.text = '[[' .. result.link .. '|' .. result.symbol .. ']]'
		else
			result.text = result.symbol
		end
		result.sortkey = convert_unit.sortkey
	else
		result = {
			text = convert_unit.text,
			sortkey = convert_unit.sortkey,
		}
	end
	return result
end

local function bracketed(ucode, text)
	if ucode:find('[*./]') then
		return '(' .. text .. ')'
	end
	return text
end

local function makeunit(ucode, options)
	-- Return wikitext, sortkey for the requested unit and options.
	-- LATER The sortkey does not account for any per unit.
	options = options or {}
	local unit = get_unit(ucode, options.value, options.link, options.longscale)
	local text = unit.text
	local percode = options.per
	if percode then
		local perunit = get_unit(percode, 0, options.per_link, options.longscale)
		text = bracketed(ucode, text) .. '/' .. bracketed(percode, perunit.text)
	end
	if not unit.nospace then
		text = '&nbsp;' .. text
	end
	return text, unit.sortkey
end

return makeunit