diff options
author | Marius <mariausol@gmail.com> | 2011-11-25 12:20:14 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2011-11-25 12:20:14 +0200 |
commit | 8a9434e331825735e636700d6a509cf770d5ec41 (patch) | |
tree | 6ebe026b4865fa3d197c121d9f1d5d135016c52a | |
parent | b0b3f63745dbcd338e4ce549c2f8c4427998ffcf (diff) | |
download | context-8a9434e331825735e636700d6a509cf770d5ec41.tar.gz |
beta 2011.11.25 10:34
-rw-r--r-- | tex/context/base/cont-new.mkii | 2 | ||||
-rw-r--r-- | tex/context/base/cont-new.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/context-version.pdf | bin | 4069 -> 4071 bytes | |||
-rw-r--r-- | tex/context/base/context-version.png | bin | 106436 -> 106083 bytes | |||
-rw-r--r-- | tex/context/base/context.mkii | 2 | ||||
-rw-r--r-- | tex/context/base/context.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/math-ali.mkiv | 66 | ||||
-rw-r--r-- | tex/context/base/phys-dim.lua | 415 | ||||
-rw-r--r-- | tex/context/base/phys-dim.mkiv | 53 | ||||
-rw-r--r-- | tex/context/base/s-fnt-31.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/s-phy-01.mkiv | 101 | ||||
-rw-r--r-- | tex/context/base/status-files.pdf | bin | 24020 -> 24028 bytes | |||
-rw-r--r-- | tex/context/base/status-lua.pdf | bin | 167927 -> 168821 bytes | |||
-rw-r--r-- | tex/context/base/supp-box.mkiv | 4 | ||||
-rw-r--r-- | tex/context/base/tabl-xtb.mkvi | 46 | ||||
-rw-r--r-- | tex/generic/context/luatex/luatex-fonts-merged.lua | 2 |
16 files changed, 506 insertions, 191 deletions
diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 197d60d3d..9c10f4dec 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2011.11.24 15:52} +\newcontextversion{2011.11.25 10:34} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 15f20a3ad..af464bf37 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2011.11.24 15:52} +\newcontextversion{2011.11.25 10:34} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 5a97ce700..e46b9b8df 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png Binary files differindex c66071a58..fa6beba00 100644 --- a/tex/context/base/context-version.png +++ b/tex/context/base/context-version.png diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index 4e70f3769..b99fa4181 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2011.11.24 15:52} +\edef\contextversion{2011.11.25 10:34} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 32be1327a..3d01d57bf 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2011.11.24 15:52} +\edef\contextversion{2011.11.25 10:34} %D For those who want to use this: diff --git a/tex/context/base/math-ali.mkiv b/tex/context/base/math-ali.mkiv index b33838737..b0399d9d1 100644 --- a/tex/context/base/math-ali.mkiv +++ b/tex/context/base/math-ali.mkiv @@ -15,6 +15,9 @@ \unprotect +% todo: \aligntab +% todo: less code (more efficient) + %D The code here has been moved from other files. Beware: the \MKII\ and %D \MKIV\ code is not gathered in files with the same name. @@ -162,14 +165,10 @@ \noalign{\glet\math_alignment_NC\math_alignment_NC_first}} % noalign used for change state, conditional does not work here \def\math_alignment_NC_first - {\dostarttagged\t!mathtablerow\empty - \dostarttagged\t!mathtablecell\empty - \let\NC\math_alignment_NC_rest} + {\glet\math_alignment_NC\math_alignment_NC_rest} \def\math_alignment_NC_rest - {\aligntab - \dostoptagged % finish cell - \dostarttagged\t!mathtablecell\empty} + {\aligntab} \def\math_alignment_EQ {\NC=} @@ -196,7 +195,7 @@ \setupmathalignment[\currentmathalignment][#1]% \fi \the\everymathalignment - \eqaligncolumn\zerocount % LOCAL HERE? + \eqaligncolumn\zerocount \processcommacommand [\mathalignmentparameter\c!align] {\advance\eqaligncolumn\plusone\doseteqaligncolumn}% takes argument @@ -241,18 +240,45 @@ \newcount\eqaligncolumn -\def\firstineqalign{\global\eqaligncolumn\plusone} -\def\nextineqalign {\global\advance\eqaligncolumn\plusone} -\def\leftofeqalign {\getvalue{\??eq:\v!left :\number\eqaligncolumn}} -\def\rightofeqalign{\getvalue{\??eq:\v!right:\number\eqaligncolumn}} +\def\firstineqalign + {\global\eqaligncolumn\plusone + \dostarttagged\t!mathtablerow \empty + \dostarttagged\t!mathtablecell\empty} + +\def\nextineqalign + {\global\advance\eqaligncolumn\plusone + \dostoptagged % finish cell + \dostarttagged\t!mathtablecell\empty} + +% \def\leftofeqalign {\getvalue{\??eq:\v!left :\number\eqaligncolumn}} +% \def\rightofeqalign{\getvalue{\??eq:\v!right:\number\eqaligncolumn}} + +% \def\doseteqaligncolumn#1% we could just add to the preamble (as with other alignments) +% {\letvalueempty{\??eq:\v!left :\number\eqaligncolumn}% +% \letvalueempty{\??eq:\v!right:\number\eqaligncolumn}% +% \doif{#1}\v!left {\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfill}% +% \doif{#1}\v!right {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfill}% +% \doif{#1}\v!middle{\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfill +% \letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfill}} + +\def\leftofeqalign + {\ifcase\csname\??eq::a::\number\eqaligncolumn\endcsname\or + \relax \or \hfill \or \hfill + \fi} + +\def\rightofeqalign + {\ifcase\csname\??eq::a::\number\eqaligncolumn\endcsname\or + \hfill \or \relax \or \hfill + \fi} + +\def\doseteqaligncolumn#1% we could just add to the preamble (as with other alignments) + {\expandafter\let\csname\??eq::a::\number\eqaligncolumn\expandafter\endcsname + \csname\??eq::a::\ifcsname\??eq::a::#1\endcsname#1\else\v!normal\fi\endcsname} -\def\doseteqaligncolumn#1% - {\letvalueempty{\??eq:\v!left :\number\eqaligncolumn}% - \letvalueempty{\??eq:\v!right:\number\eqaligncolumn}% - \doif{#1}\v!left {\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfill}% - \doif{#1}\v!right {\letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfill}% - \doif{#1}\v!middle{\letvalue{\??eq:\v!right:\number\eqaligncolumn}\hfill - \letvalue{\??eq:\v!left :\number\eqaligncolumn}\hfill}} +\letvalue{\??eq::a::\v!normal}\zerocount +\letvalue{\??eq::a::\v!left }\plusone +\letvalue{\??eq::a::\v!right }\plustwo +\letvalue{\??eq::a::\v!middle}\plusthree \def\dodoalignNC {\gdef\doalignNC##1{&##1}} @@ -548,7 +574,7 @@ \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksa}}% \dorecurse{\numexpr\scratchcounter-\plusone\relax} {\normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksb}}}% - \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksc }}} + \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksc}}} \def\preparemathmatrix {\!!toksa{\strut \firstineqalign\leftofeqalign \span @@ -666,7 +692,7 @@ \mathsurround\zeropoint \everycr\emptytoks \tabskip\zeropoint - \eqaligncolumn\zerocount % could be \scratchcounter LOCAL HERE? + \eqaligncolumn\zerocount \processcommacommand[\mathmatrixparameter\c!align]{\advance\eqaligncolumn\plusone\dosetmatrixcolumn}% \scratchcounter=\ifnum\eqaligncolumn>\zerocount \eqaligncolumn \else \plusone \fi \global\eqaligncolumn\plusone diff --git a/tex/context/base/phys-dim.lua b/tex/context/base/phys-dim.lua index 0a271852d..9d1176b78 100644 --- a/tex/context/base/phys-dim.lua +++ b/tex/context/base/phys-dim.lua @@ -12,14 +12,18 @@ if not modules then modules = { } end modules ['phys-dim'] = { -- -- todo: maybe also an sciunit command that converts to si units (1 inch -> 0.0254 m) -- etc .. typical something to do when listening to a news whow or b-movie +-- +-- todo: collect used units for logging (and list of units, but then we need +-- associations too). local V, P, S, R, C, Cc, Cs, matchlpeg, Carg = lpeg.V, lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.match, lpeg.Carg local format, lower = string.format, string.lower local appendlpeg = lpeg.append local mergetable, mergedtable, keys, loweredkeys = table.merge, table.merged, table.keys, table.loweredkeys +local setmetatablenewindex = table.setmetatablenewindex physics = physics or { } -physics.patterns = physics.patterns or { } +physics.units = physics.units or { } local variables = interfaces.variables local v_reverse = variables.reverse @@ -111,7 +115,7 @@ function commands.digits(str,p_c) end end --- units parser +-- tables: local long_prefixes = { Yocto = [[y]], -- 10^{-24} @@ -151,72 +155,76 @@ local long_prefixes = { Zebi = [[Zi]], -- binary Yobi = [[Yi]], -- binary - Degrees = [[°]], - Degree = [[°]], - Deg = [[°]], - ["°"] = [[°]], + Micro = [[µ]], -- 0x00B5 \textmu + Root = [[√]], -- 0x221A } local long_units = { - Meter = [[m]], - Hertz = [[hz]], - Second = [[s]], - Hour = [[h]], - Liter = [[l]], --- Litre = [[l]], - Gram = [[g]], - Newton = [[N]], - Pascal = [[Pa]], - Atom = [[u]], - Joule = [[J]], - Watt = [[W]], - Celsius = [[C]], -- no SI - Kelvin = [[K]], - Fahrenheit = [[F]], -- no SI - Mol = [[mol]], - Mole = [[mol]], - Equivalent = [[eql]], - Farad = [[F]], - Ohm = [[\Omega]], - Siemens = [[S]], - Ampere = [[A]], - Coulomb = [[C]], - Volt = [[V]], - eVolt = [[eV]], - Tesla = [[T]], - VoltAC = [[V\unitsbackspace\unitslower{ac}]], - VoltDC = [[V\unitsbackspace\unitslower{dc}]], - AC = [[V\unitsbackspace\unitslower{ac}]], - DC = [[V\unitsbackspace\unitslower{dc}]], - Bit = [[bit]], - Baud = [[Bd]], - Byte = [[B]], - Erlang = [[E]], - Bequerel = [[Bq]], - Sievert = [[Sv]], - Candela = [[cd]], - Bell = [[B]], - At = [[at]], - Atm = [[atm]], - Bar = [[bar]], - Foot = [[ft]], - Inch = [[inch]], - Cal = [[cal]], - Force = [[f]], - Lux = [[lux]], - Gray = [[Gr]], - Weber = [[Wb]], - Henry = [[H]], - Sterant = [[sr]], - Angstrom = [[Å]], - Gauss = [[G]], - Rad = [[rad]], - RPS = [[RPS]], - RPM = [[RPM]], - RevPerSec = [[RPS]], - RevPerMin = [[RPM]], - Percent = [[\percent]], - Promille = [[\promille]], + Meter = [[m]], + Hertz = [[Hz]], + Second = [[s]], + Hour = [[h]], + Liter = [[l]], +-- Litre = [[l]], + Gram = [[g]], + Newton = [[N]], + Pascal = [[Pa]], + Atom = [[u]], + Bell = [[B]], + Katal = [[kat]], + Dalton = [[Da]], + Joule = [[J]], + Watt = [[W]], + Celsius = [[C]], -- no SI + Kelvin = [[K]], + Fahrenheit = [[F]], -- no SI + Mol = [[mol]], + Mole = [[mol]], + Equivalent = [[eql]], + Farad = [[F]], + Ohm = [[\Omega]], + Siemens = [[S]], + Ampere = [[A]], + Coulomb = [[C]], + Volt = [[V]], + eVolt = [[eV]], + eV = [[eV]], + Tesla = [[T]], + VoltAC = [[V\unitsbackspace\unitslower{ac}]], + VoltDC = [[V\unitsbackspace\unitslower{dc}]], + AC = [[V\unitsbackspace\unitslower{ac}]], + DC = [[V\unitsbackspace\unitslower{dc}]], + Bit = [[bit]], + Baud = [[Bd]], + Byte = [[B]], + Erlang = [[E]], + Bequerel = [[Bq]], + Sievert = [[Sv]], + Candela = [[cd]], + Bel = [[B]], + At = [[at]], + Atm = [[atm]], + Bar = [[bar]], + Foot = [[ft]], + Inch = [[inch]], + Cal = [[cal]], + Force = [[f]], + Lux = [[lx]], + Gray = [[Gr]], + Weber = [[Wb]], + Henry = [[H]], + Sterant = [[sr]], + Tonne = [[t]], + Angstrom = [[Å]], + Gauss = [[G]], + Rad = [[rad]], + RPS = [[RPS]], + RPM = [[RPM]], + RevPerSec = [[RPS]], + RevPerMin = [[RPM]], + Ohm = [[Ω]], -- 0x2126 \textohm + ["Metric Ton"] = [[t]], + ["Electron Volt"] = [[eV]], } local long_operators = { @@ -236,15 +244,6 @@ local long_suffixes = { ICubic = [[-3]], } -long_prefixes.Micro = [[\textmu]] -long_units .Ohm = [[\textohm]] - -mergetable(long_suffixes,loweredkeys(long_suffixes)) - -local long_prefixes_to_long = { } for k, v in next, long_prefixes do long_prefixes_to_long [lower(k)] = k end -local long_units_to_long = { } for k, v in next, long_units do long_units_to_long [lower(k)] = k end -local long_operators_to_long = { } for k, v in next, long_operators do long_operators_to_long[lower(k)] = k end - local short_prefixes_to_long = { y = "Yocto", z = "Zetto", @@ -272,12 +271,17 @@ local short_units_to_long = { -- I'm not sure about casing m = "Meter", Hz = "Hertz", hz = "Hertz", + B = "Bel", + b = "Bel", + lx = "Lux", + -- da = "Dalton", u = "Hour", h = "Hour", s = "Second", g = "Gram", n = "Newton", v = "Volt", + t = "Tonne", l = "Liter", -- w = "Watt", @@ -296,14 +300,6 @@ local short_operators_to_long = { [":"] = "OutOf", } --- local connected = table.tohash { --- "Degrees", --- } - -short_prefixes = { } for k, v in next, short_prefixes_to_long do short_prefixes [k] = long_prefixes [v] end -short_units = { } for k, v in next, short_units_to_long do short_units [k] = long_units [v] end -short_operators = { } for k, v in next, short_operators_to_long do short_operators[k] = long_operators[v] end - local short_suffixes = { -- maybe just raw digit match ["1"] = long_suffixes.Linear, ["2"] = long_suffixes.Square, @@ -327,51 +323,23 @@ local short_suffixes = { -- maybe just raw digit match ["^-3"] = long_suffixes.ICubic, } -local prefixes = long_prefixes -local units = long_units -local operators = long_operators -local suffixes = long_suffixes - -local somespace = P(" ")^0/"" - -local l_prefix = appendlpeg(keys(long_prefixes)) -local l_unit = appendlpeg(keys(long_units)) -local l_operator = appendlpeg(keys(long_operators)) -local l_suffix = appendlpeg(keys(long_suffixes)) - -local l_prefix = appendlpeg(long_prefixes_to_long,l_prefix) -local l_unit = appendlpeg(long_units_to_long,l_unit) -local l_operator = appendlpeg(long_operators_to_long,l_operator) - -local s_prefix = appendlpeg(short_prefixes_to_long) -local s_unit = appendlpeg(short_units_to_long) -local s_operator = appendlpeg(short_operators_to_long) - -local s_suffix = appendlpeg(keys(short_suffixes)) - --- space inside Cs else funny captures and args to function - --- square centi meter per square kilo seconds +local symbol_units = { + Degrees = [[°]], + Degree = [[°]], + Deg = [[°]], + ["°"] = [[°]], + ArcMinute = [[\checkedtextprime]], -- ′ 0x2032 + ArcSecond = [[\checkedtextdoubleprime]], -- ″ 0x2033 + Percent = [[\percent]], + Promille = [[\promille]], + Permille = [[\promille]], +} -local l_suffix = Cs(somespace * l_suffix) -local s_suffix = Cs(somespace * s_suffix) + Cc("") -local l_operator = Cs(somespace * l_operator) - -local combination = P { "start", - l_prefix = Cs(somespace * l_prefix) + Cc(""), - s_prefix = Cs(somespace * s_prefix) + Cc(""), - l_unit = Cs(somespace * l_unit), - s_unit = Cs(somespace * s_unit), - start = V("l_prefix") * V("l_unit") - + V("s_prefix") * V("s_unit") - + V("l_prefix") * V("s_unit") - + V("s_prefix") * V("l_unit"), +local packaged_units = { + Micron = [[\textmu m]], } --- inspect(s_prefix) --- inspect(s_unit) --- square kilo meter --- square km +-- rendering: local unitsPUS = context.unitsPUS local unitsPU = context.unitsPU @@ -400,6 +368,11 @@ l_prefixes .test = { Kilo = "kilo" } l_units .test = { Meter = "meter", Second = "second" } l_operators.test = { Solidus = " per " } +local prefixes = { } +local units = { } +local operators = { } +local suffixes = { } + local function dimpus(p,u,s,wherefrom) if trace_units then report_units("w: [%s], p: [%s], u: [%s], s: [%s]",wherefrom or "?",p or "?",u or "?",s or "?") @@ -411,8 +384,8 @@ local function dimpus(p,u,s,wherefrom) else local lp = l_prefixes[wherefrom] local lu = l_units [wherefrom] - p = lp and lp[p] or p - u = lu and lu[u] or u + p = lp and lp[p] or prefixes[p] or p + u = lu and lu[u] or units [u] or u end s = suffixes[s] or s -- @@ -457,41 +430,187 @@ local function dimop(o,wherefrom) o = operators[o] or o else local lo = l_operators[wherefrom] - o = lo and lo[o] or o + o = lo and lo[o] or operators[o] or o end if o then unitsO(o) end end --- todo 0x -> rm --- pretty large lpeg (maybe do dimension lookup otherwise) --- not ok yet ... we have this p n s problem - -local dimension = ((l_suffix * combination) * Carg(1)) / dimspu - + ((combination * s_suffix) * Carg(1)) / dimpus -local number = lpeg.patterns.number / unitsN -local operator = C((l_operator + s_operator) * Carg(1)) / dimop -- weird, why is the extra C needed here -local whatever = (P(1)^0) / unitsU - -local number = (1-R("az","AZ")-P(" "))^1 / unitsN -- todo: catch { } +local function dimsym(s,wherefrom) -- Do we need to support wherefrom here? + if trace_units then + report_units("w: [%s], s: [%s]",wherefrom,s or "?") + end + s = symbol_units[s] or s + if s then + unitsC(s) + end +end -dimension = somespace * dimension * somespace -number = somespace * number * somespace -operator = somespace * operator * somespace +local function dimpre(p,wherefrom) -- Do we need to support wherefrom here? + if trace_units then + report_units("w: [%s], p: [%s]",wherefrom,p or "?") + end + p = packaged_units[p] or p + if p then + unitsU(p) + end +end -local unitparser = dimension^1 * (operator * dimension^1)^-1 + whatever + P(-1) +-- patterns: +-- +-- space inside Cs else funny captures and args to function +-- +-- square centi meter per square kilo seconds -local p_c_unitdigitparser = (Cc(nil)/unitsNstart) * p_c_dparser * (Cc(nil)/unitsNstop) -- -local c_p_unitdigitparser = (Cc(nil)/unitsNstart) * c_p_dparser * (Cc(nil)/unitsNstop) -- +local function update_parsers() + + local long_prefixes_to_long = { } for k, v in next, long_prefixes do long_prefixes_to_long [lower(k)] = k end + local long_units_to_long = { } for k, v in next, long_units do long_units_to_long [lower(k)] = k end + local long_operators_to_long = { } for k, v in next, long_operators do long_operators_to_long[lower(k)] = k end + local short_prefixes = { } for k, v in next, short_prefixes_to_long do short_prefixes [k] = long_prefixes [v] end + local short_units = { } for k, v in next, short_units_to_long do short_units [k] = long_units [v] end + local short_operators = { } for k, v in next, short_operators_to_long do short_operators [k] = long_operators[v] end + + mergetable(long_suffixes, loweredkeys(long_suffixes)) + mergetable(symbol_units, loweredkeys(symbol_units)) + mergetable(packaged_units,loweredkeys(packaged_units)) + + prefixes = long_prefixes -- used in above functions + units = long_units -- used in above functions + operators = long_operators -- used in above functions + suffixes = long_suffixes -- used in above functions + + local somespace = P(" ")^0/"" + + local l_prefix = appendlpeg(keys(long_prefixes)) + local l_unit = appendlpeg(keys(long_units)) + local l_operator = appendlpeg(keys(long_operators)) + local l_suffix = appendlpeg(keys(long_suffixes)) + + local l_prefix = appendlpeg(long_prefixes_to_long,l_prefix) + local l_unit = appendlpeg(long_units_to_long,l_unit) + local l_operator = appendlpeg(long_operators_to_long,l_operator) + + local s_prefix = appendlpeg(short_prefixes_to_long) + local s_unit = appendlpeg(short_units_to_long) + local s_operator = appendlpeg(short_operators_to_long) + + local s_suffix = appendlpeg(keys(short_suffixes)) + + local c_symbol = appendlpeg(keys(symbol_units)) + local p_unit = appendlpeg(keys(packaged_units)) + + local combination = P { "start", + l_prefix = Cs(somespace * l_prefix) + Cc(""), + s_prefix = Cs(somespace * s_prefix) + Cc(""), + l_unit = Cs(somespace * l_unit), + s_unit = Cs(somespace * s_unit), + start = V("l_prefix") * V("l_unit") -- centi meter + + V("s_prefix") * V("s_unit") -- c m + + V("l_prefix") * V("s_unit") -- centi m + + V("s_prefix") * V("l_unit"), -- c meter + } + + local l_suffix = Cs(somespace * l_suffix) + local s_suffix = Cs(somespace * s_suffix) + Cc("") + local l_operator = Cs(somespace * l_operator) + local p_unit = Cs(somespace * p_unit) + + -- todo 0x -> rm + -- pretty large lpeg (maybe do dimension lookup otherwise) + -- not ok yet ... we have this p n s problem + + local dimension = (p_unit * Carg(1)) / dimpre + + ((l_suffix * combination) * Carg(1)) / dimspu + + ((combination * s_suffix) * Carg(1)) / dimpus + local number = lpeg.patterns.number / unitsN + local operator = ((l_operator + s_operator) * Carg(1)) / dimop -- weird, why is the extra C needed here + local whatever = (P(1)^0) / unitsU + local symbol = c_symbol / dimsym + local packaged = p_unit / dimpre + + local number = (1-R("az","AZ")-P(" "))^1 / unitsN -- todo: catch { } + + symbol = somespace * symbol * somespace + packaged = somespace * packaged * somespace + dimension = somespace * dimension * somespace + number = somespace * number * somespace + operator = somespace * operator * somespace + + dimension = symbol * dimension + dimension + symbol -- too many space tests + + local unitparser = dimension^1 * (operator * dimension^1)^-1 -- dimension^-1 ? + + symbol + + packaged + + whatever + + P(-1) + + local p_c_unitdigitparser = (Cc(nil)/unitsNstart) * p_c_dparser * (Cc(nil)/unitsNstop) -- + local c_p_unitdigitparser = (Cc(nil)/unitsNstart) * c_p_dparser * (Cc(nil)/unitsNstop) -- + + local p_c_combinedparser = dleader * (p_c_unitdigitparser + number)^-1 * unitparser + local c_p_combinedparser = dleader * (c_p_unitdigitparser + number)^-1 * unitparser + + return p_c_combinedparser, c_p_combinedparser +end -local p_c_combinedparser = dleader * (p_c_unitdigitparser + number)^-1 * unitparser -local c_p_combinedparser = dleader * (c_p_unitdigitparser + number)^-1 * unitparser +local p_c_parser = nil +local c_p_parser = nil +local dirty = true function commands.unit(str,wherefrom,p_c) + if dirty then + if trace_units then + report_units("initializing parser") + end + p_c_parser, c_p_parser = update_parsers() + dirty = false + end if p_c == v_reverse then - matchlpeg(p_c_combinedparser,str,1,wherefrom or "") + matchlpeg(p_c_parser,str,1,wherefrom or "") else - matchlpeg(c_p_combinedparser,str,1,wherefrom or "") + matchlpeg(c_p_parser,str,1,wherefrom or "") + end +end + +local function trigger(t,k,v) + rawset(t,k,v) + dirty = true +end + +local t_units = { + prefixes = setmetatablenewindex(long_prefixes,trigger), + units = setmetatablenewindex(long_units,trigger), + operators = setmetatablenewindex(long_operators,trigger), + suffixes = setmetatablenewindex(long_suffixes,trigger), + symbols = setmetatablenewindex(symbol_units,trigger), + packaged = setmetatablenewindex(packaged_units,trigger), +} + +local t_shortcuts = { + prefixes = setmetatablenewindex(short_prefixes_to_long,trigger), + units = setmetatablenewindex(short_units_to_long,trigger), + operators = setmetatablenewindex(short_operators_to_long,trigger), + suffixes = setmetatablenewindex(short_suffixes,trigger), +} + +physics.units.tables = { + units = t_units, + shortcuts = t_shortcuts, +} + +function commands.registerunit(category,list) + if not list or list == "" then + list = category + category = "units" end + local t = t_units[category] + if t then + for k, v in next, utilities.parsers.settings_to_hash(list or "") do + t[k] = v + end + end + inspect(tables) end + diff --git a/tex/context/base/phys-dim.mkiv b/tex/context/base/phys-dim.mkiv index a093466d0..eaac72bb6 100644 --- a/tex/context/base/phys-dim.mkiv +++ b/tex/context/base/phys-dim.mkiv @@ -13,6 +13,8 @@ \registerctxluafile{phys-dim}{} +% todo: optional space between 'connected' symbols + \unprotect %D \macros @@ -474,7 +476,10 @@ \unexpanded\def\unitsS #1{\units_start{}\unitsraise{#1}\c_units_state \plusone} % suffix \unexpanded\def\unitsO #1{\units_start#1\c_units_state \plustwo} % operator \unexpanded\def\unitsN #1{\units_start#1\c_units_state \plusfive} % number -\unexpanded\def\unitsC #1{\units_next#1\c_units_state \plussix} % connected +\unexpanded\def\unitsC #1{\removeunwantedspaces#1\c_units_state \plussix} % connected + +\unexpanded\def\checkedtextprime {\iffontchar\font"2032′\else\textacute\fi} +\unexpanded\def\checkedtextdoubleprime{\iffontchar\font"2033″\else\textacute\kern-.25em\textacute\fi} \setelementnature[unit] [mixed] \setelementnature[quantity][mixed] @@ -588,6 +593,35 @@ {/}% }%\unitsbackspace} +%D You can define additional units: +%D +%D \starttyping +%D \registerunit +%D [units] +%D [point=pt, +%D basepoint=bp, +%D scaledpoint=sp, +%D didot=dd, +%D cicero=cc] +%D \stoptyping +%D +%D Possible categories are: \type {prefixes}, \type {units}, \type {operators}, +%D \type {suffixes}, \type {symbols},\type {packaged}. + +\unexpanded\def\registerunit + {\dodoubleempty\register_unit} + +\def\register_unit[#1][#2]% + {\ctxcommand{registerunit(\!!bs#1\!!es,\!!bs#2\!!es)}} + +%D You can generate a list as follows: +%D +%D \starttyping +%D \usemodule[phy-01] +%D +%D \ShowUnitsTable % [prefixes] +%D \stoptyping + %D Now we define the standard units command: \defineunits @@ -633,5 +667,22 @@ %D \stopbuffer %D %D \typebuffer \getbuffer +%D +%D Another example: +%D +%D \starttyping +%D \startluacode +%D languages.data.labels.units.foo = { +%D Liter = "l" +%D } +%D languages.data.labels.units.bar = { +%D Liter = "L" +%D } +%D \stopluacode +%D +%D \defineunits[lunit] \lunit{10 l/s}\par +%D \defineunits[funit][label=foo] \funit{10 l/s}\par +%D \defineunits[bunit][label=bar] \bunit{10 l/s}\par +%D \stoptyping \protect \endinput diff --git a/tex/context/base/s-fnt-31.mkiv b/tex/context/base/s-fnt-31.mkiv index 4ce3b42c0..171f991db 100644 --- a/tex/context/base/s-fnt-31.mkiv +++ b/tex/context/base/s-fnt-31.mkiv @@ -98,7 +98,7 @@ end \stopluacode -\continueifinputfile{s-fnt-31.mkiv} % \doifnotmode{demo}{\endinput} +\continueifinputfile{s-fnt-31.mkiv} \setupbodyfont[10pt] diff --git a/tex/context/base/s-phy-01.mkiv b/tex/context/base/s-phy-01.mkiv new file mode 100644 index 000000000..789aeb187 --- /dev/null +++ b/tex/context/base/s-phy-01.mkiv @@ -0,0 +1,101 @@ +%D \module +%D [ file=s-phy-01, +%D version=2011-11-24, +%D title=\CONTEXT\ Modules, +%D subtitle=Units Tables, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\unprotect + +% todo: better breaks of head line + +\startluacode +moduledata.units = moduledata.units or { } + +local tables = physics.units.tables + +local HL = context.HL +local NC = context.NC +local NR = context.NR + +local function typeset(category,name,list,followup) + if followup then + context.TB() + end + HL() + NC() + context.rlap(category .. ":" .. name) + NC() + NC() + NR() + HL() + for k, v in table.sortedhash(list) do + NC() + context(k) + NC() + if isunit then + context(v) + else + context.type(v) + end + NC() + NR() + end + HL() +end + +function moduledata.units.show_table(name) + context.starttabulate { "|lT|l|" } + if name and name ~= "" then + local first, second = string.match("(.-):(.-)") + if first then + local t = tables[first] + if t then + t = t[second] + end + if t then + typeset(first,second,t,false) + end + else + local t = tables.entries[name] + if t then + typeset("entries",name,t,false) + end + end + else + local done = false + for what, list in table.sortedhash(tables.units) do + typeset("units",what,list,done) + done = true + end + for what, list in table.sortedhash(tables.shortcuts) do + typeset("shortcuts",what,list,done) + done = true + end + end + context.stoptabulate() +end + +\stopluacode + +\unexpanded\def\ShowUnitsTable + {\dosingleempty\Show_Units_Table} + +\def\Show_Units_Table[#1]% + {\ctxlua{moduledata.units.show_table("#1")}} + +\protect + +\continueifinputfile{s-phy-01.mkiv} + +\usemodule[art-01] + +\starttext + \ShowUnitsTable +\stoptext diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 14972afff..4065f2c48 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 129f122ed..022b8f526 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/supp-box.mkiv b/tex/context/base/supp-box.mkiv index 53c4b3b1a..a874ae43b 100644 --- a/tex/context/base/supp-box.mkiv +++ b/tex/context/base/supp-box.mkiv @@ -646,8 +646,8 @@ \def\dodotlap{\normalvbox to \zeropoint{\normalvss\flushnextbox}\endgroup} \def\dodoblap{\normalvbox to \zeropoint{\flushnextbox\normalvss}\endgroup} -\def\tlap{\begingroup\dowithnextboxcs\dodotlap\normalvbox} -\def\blap{\begingroup\dowithnextboxcs\dodoblap\normalvbox} +\unexpanded\def\tlap{\begingroup\dowithnextboxcs\dodotlap\normalvbox} +\unexpanded\def\blap{\begingroup\dowithnextboxcs\dodoblap\normalvbox} %D \macros %D {beginofshapebox, diff --git a/tex/context/base/tabl-xtb.mkvi b/tex/context/base/tabl-xtb.mkvi index e9cd87368..58f980844 100644 --- a/tex/context/base/tabl-xtb.mkvi +++ b/tex/context/base/tabl-xtb.mkvi @@ -157,15 +157,40 @@ \let\normal_start_x_table\start_x_table +% These direct buffers can be somewhat faster but it's probably neglectable. +% Anyway, no nesting is supported as we then need to catch (e.g.) rows and +% keep track of nesting and have a more complex redefinition of nested +% instanced \unknown\ it's not worth the trouble. + \def\process_x_table_buffer[#name]% {\bgroup \let\start_x_table\start_process_x_table_buffer \edef\x_table_current_buffer{#name}% + \x_table_get_buffer % pickup settings \x_table_process} +\def\ignore_start_x_table[#settings]% + {} + \def\start_process_x_table_buffer[#settings]% {\x_table_prepare{#settings}% - \let\start_x_table\normal_start_x_table} + \let\start_x_table\ignore_start_x_table + \gobbleuntil\stopxtable} + +%D A bonus: you can use the following construct inside a macro. + +\unexpanded\def\startembeddedxtable + {\dosingleempty\start_embedded_x_table} + +\def\start_embedded_x_table[#settings]#content\stopembeddedxtable + {\x_table_prepare{#settings}% + \ctxcommand{assignbuffer("embedded_x_table",\!!bs\detokenize{#content}\!!es)}% + \bgroup + \let\start_x_table\start_process_x_table_buffer + \edef\x_table_current_buffer{embedded_x_table}% + \x_table_process} + +\let\stopembeddedxtable\relax %D We can also define xtables. @@ -206,10 +231,11 @@ {\ctxcommand{gettexbuffer("\x_table_current_buffer")}} \unexpanded\def\x_table_process - {\begingroup -\doifsomething{\xtableparameter\c!bodyfont} - {\setupbodyfont[\xtableparameter\c!bodyfont]}% - \setbox\scratchbox\vbox{\xtableparameter\c!spaceinbetween}% + {\begingroup % * + \doifsomething{\xtableparameter\c!bodyfont} + {\setupbodyfont[\xtableparameter\c!bodyfont]}% + \setbox\scratchbox\vbox + {\xtableparameter\c!spaceinbetween}% \ctxcommand{x_table_create { option = "\xtableparameter\c!option", textwidth = \number\dimexpr\xtableparameter\c!textwidth, @@ -257,7 +283,7 @@ \x_table_get_buffer \ctxcommand{x_table_construct()}\relax \endgroup -\endgroup + \endgroup % * \ifinsidesplitfloat \x_table_flush_float_split \else\ifinsidefloat @@ -540,14 +566,6 @@ \let\stopxtablenext\stop_x_table_partition \let\stopxtablebody\stop_x_table_partition -%D A bonus: you can use the following construct inside a macro. - -\unexpanded\def\startembeddedxtable#1\stopembeddedxtable - {\ctxcommand{assignbuffer("embedded_x_table",\!!bs\detokenize{#1}\!!es)}% - \processxtablebuffer[embedded_x_table]} - -\let\stopembeddedxtable\relax - %D This is an experiment! Beware: you can create loops by using nested %D references to already chained settings. %D diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 78855b32b..4cedab23e 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 11/24/11 15:52:09 +-- merge date : 11/25/11 10:34:08 do -- begin closure to overcome local limits and interference |