summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/phys-dim.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/phys-dim.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/phys-dim.lua58
1 files changed, 44 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/context/base/phys-dim.lua b/Master/texmf-dist/tex/context/base/phys-dim.lua
index 870cbd29b0e..7430b62d773 100644
--- a/Master/texmf-dist/tex/context/base/phys-dim.lua
+++ b/Master/texmf-dist/tex/context/base/phys-dim.lua
@@ -50,12 +50,11 @@ local utfchar = utf.char
physics = physics or { }
physics.units = physics.units or { }
-local variables = interfaces.variables
-local v_reverse = variables.reverse
local allocate = utilities.storage.allocate
local context = context
local commands = commands
+local implement = interfaces.implement
local trace_units = false
local report_units = logs.reporter("units")
@@ -173,8 +172,8 @@ local p_c = (ddigitspace^1 * dskipperiod)^0 -- ___.
local p_c_dparser = math_one + math_two + dleader * p_c * dtrailer * dfinal
local c_p_dparser = math_one + math_two + dleader * c_p * dtrailer * dfinal
-function commands.digits(str,p_c)
- if p_c == v_reverse then
+local function makedigits(str,reverse)
+ if reverse then
matchlpeg(p_c_dparser,str)
else
matchlpeg(c_p_dparser,str)
@@ -287,18 +286,29 @@ local long_units = {
-- synonyms
- ["Metric Ton"] = "tonne",
+ MetricTon = "tonne",
Litre = "liter",
+ ["Metric Ton"] = "tonne",
+
-- non-SI units whose values must be obtained experimentally (Table 7)
- ["Electron Volt"] = "electronvolt",
+ AtomicMassUnit = "atomicmassunit",
+ AstronomicalUnit = "astronomicalunit",
+ ElectronVolt = "electronvolt",
Dalton = "dalton",
+
["Atomic Mass Unit"] = "atomicmassunit",
["Astronomical Unit"] = "astronomicalunit",
+ ["Electron Volt"] = "electronvolt",
-- special cases (catch doubles, okay, a bit over the top)
+ DegreesCelsius = "celsius",
+ DegreesFahrenheit = "fahrenheit",
+ DegreeCelsius = "celsius",
+ DegreeFahrenheit = "fahrenheit",
+
["Degrees Celsius"] = "celsius",
["Degrees Fahrenheit"] = "fahrenheit",
["Degree Celsius"] = "celsius",
@@ -323,12 +333,14 @@ local long_units = {
Hg = "mercury",
-- ["Millimetre Of Mercury"] = [[mmHg]],
Angstrom = "angstrom", -- strictly Ångström
- ["Nautical Mile"] = "nauticalmile",
+ NauticalMile = "nauticalmile",
Barn = "barn",
Knot = "knot",
Neper = "neper",
Bel = "bel", -- in practice only decibel used
+ ["Nautical Mile"] = "nauticalmile",
+
-- other non-SI units from CGS system (Table 9)
Erg = "erg",
@@ -601,7 +613,7 @@ labels.units = allocate {
electronvolt = { labels = { en = [[eV]] } },
dalton = { labels = { en = [[Da]] } },
atomicmassunit = { labels = { en = [[u]] } },
- astronomicalunit = { labels = { en = [[ua]] } },
+ astronomicalunit = { labels = { en = [[au]] } },
bar = { labels = { en = [[bar]] } },
angstrom = { labels = { en = [[Å]] } }, -- strictly Ångström
nauticalmile = { labels = { en = [[M]] } },
@@ -799,6 +811,18 @@ local function update_parsers() -- todo: don't remap utf sequences
+ V("nothing") * V("shortunit")
+ V("longprefix") * V("shortunit") -- centi m
+ V("shortprefix") * V("longunit"), -- c meter
+
+-- combination = ( V("longprefix") -- centi meter
+-- + V("nothing")
+-- ) * V("longunit")
+-- + ( V("shortprefix") -- c m
+-- + V("nothing")
+-- + V("longprefix")
+-- ) * V("shortunit") -- centi m
+-- + ( V("shortprefix") -- c meter
+-- ) * V("longunit"),
+
+
dimension = V("somespace")
* (
V("packaged") / dimpre
@@ -812,9 +836,7 @@ local function update_parsers() -- todo: don't remap utf sequences
* V("somespace"),
snippet = V("dimension")
+ V("somesymbol"),
- unit = (
- V("snippet")
- * (V("operator") * V("snippet"))^0
+ unit = ( V("snippet") * (V("operator") * V("snippet"))^0
+ V("somepackaged")
)^1,
}
@@ -854,7 +876,7 @@ local p_c_parser = nil
local c_p_parser = nil
local dirty = true
-function commands.unit(str,p_c)
+local function makeunit(str,reverse)
if dirty then
if trace_units then
report_units("initializing parser")
@@ -863,7 +885,7 @@ function commands.unit(str,p_c)
dirty = false
end
local ok
- if p_c == v_reverse then
+ if reverse then
ok = matchlpeg(p_c_parser,str)
else
ok = matchlpeg(c_p_parser,str)
@@ -909,7 +931,7 @@ local mapping = {
packaged = "packaged",
}
-function commands.registerunit(category,list)
+local function registerunit(category,list)
if not list or list == "" then
list = category
category = "unit"
@@ -922,3 +944,11 @@ function commands.registerunit(category,list)
end
-- inspect(tables)
end
+
+physics.units.registerunit = registerunit
+
+implement { name = "digits_normal", actions = makedigits, arguments = "string" }
+implement { name = "digits_reverse", actions = makedigits, arguments = { "string", true } }
+implement { name = "unit_normal", actions = makeunit, arguments = "string"}
+implement { name = "unit_reverse", actions = makeunit, arguments = { "string", true } }
+implement { name = "registerunit", actions = registerunit, arguments = { "string", "string" } }