summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/x-mathml.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
committerTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
commitd7ccb42582f85acf30568913610ccf4d602023fb (patch)
tree7292e3545a420676878e7451b68892d360c62cb6 /Master/texmf-dist/tex/context/base/x-mathml.lua
parent2d62a6fe9b80def59c392268022f1f9a2d6e358f (diff)
commit context 2011.05.18
git-svn-id: svn://tug.org/texlive/trunk@22719 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/x-mathml.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/x-mathml.lua520
1 files changed, 257 insertions, 263 deletions
diff --git a/Master/texmf-dist/tex/context/base/x-mathml.lua b/Master/texmf-dist/tex/context/base/x-mathml.lua
index 2ee3cd09093..434aefc553a 100644
--- a/Master/texmf-dist/tex/context/base/x-mathml.lua
+++ b/Master/texmf-dist/tex/context/base/x-mathml.lua
@@ -12,11 +12,13 @@ local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes
local format, lower, find, gsub = string.format, string.lower, string.find, string.gsub
local utfchar, utffind, utfgmatch, utfgsub = utf.char, utf.find, utf.gmatch, utf.gsub
local xmlsprint, xmlcprint, xmltext, xmlcontent = xml.sprint, xml.cprint, xml.text, xml.content
-local lxmltext, get_id = lxml.text, lxml.get_id
+local lxmltext, getid = lxml.text, lxml.getid
local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues
local lpegmatch = lpeg.match
-lxml.mml = lxml.mml or { }
+local mathml = { }
+moduledata.mathml = mathml
+lxml.mathml = mathml -- for the moment
-- an alternative is to remap to private codes, where we can have
-- different properties .. to be done; this will move and become
@@ -27,55 +29,55 @@ lxml.mml = lxml.mml or { }
local doublebar = utfchar(0x2016)
local n_replacements = {
--- [" "] = utfchar(0x2002), -- "&textspace;" -> tricky, no &; in mkiv
- ["."] = "{.}",
- [","] = "{,}",
- [" "] = "",
+-- [" "] = utfchar(0x2002), -- "&textspace;" -> tricky, no &; in mkiv
+ ["."] = "{.}",
+ [","] = "{,}",
+ [" "] = "",
}
local l_replacements = { -- in main table
- ["|"] = "\\mmlleftdelimiter\\vert",
- ["{"] = "\\mmlleftdelimiter\\lbrace",
- ["("] = "\\mmlleftdelimiter(",
- ["["] = "\\mmlleftdelimiter[",
- ["<"] = "\\mmlleftdelimiter<",
- [doublebar] = "\\mmlleftdelimiter\\Vert",
+ ["|"] = "\\mmlleftdelimiter\\vert",
+ ["{"] = "\\mmlleftdelimiter\\lbrace",
+ ["("] = "\\mmlleftdelimiter(",
+ ["["] = "\\mmlleftdelimiter[",
+ ["<"] = "\\mmlleftdelimiter<",
+ [doublebar] = "\\mmlleftdelimiter\\Vert",
}
local r_replacements = { -- in main table
- ["|"] = "\\mmlrightdelimiter\\vert",
- ["}"] = "\\mmlrightdelimiter\\rbrace",
- [")"] = "\\mmlrightdelimiter)",
- ["]"] = "\\mmlrightdelimiter]",
- [">"] = "\\mmlrightdelimiter>",
- [doublebar] = "\\mmlrightdelimiter\\Vert",
+ ["|"] = "\\mmlrightdelimiter\\vert",
+ ["}"] = "\\mmlrightdelimiter\\rbrace",
+ [")"] = "\\mmlrightdelimiter)",
+ ["]"] = "\\mmlrightdelimiter]",
+ [">"] = "\\mmlrightdelimiter>",
+ [doublebar] = "\\mmlrightdelimiter\\Vert",
}
local o_replacements = { -- in main table
- ["@l"] = "\\mmlleftdelimiter.",
- ["@r"] = "\\mmlrightdelimiter.",
- ["{"] = "\\mmlleftdelimiter\\lbrace",
- ["}"] = "\\mmlrightdelimiter\\rbrace",
- ["|"] = "\\mmlleftorrightdelimiter\\vert",
- [doublebar] = "\\mmlleftorrightdelimiter\\Vert",
- ["("] = "\\mmlleftdelimiter(",
- [")"] = "\\mmlrightdelimiter)",
- ["["] = "\\mmlleftdelimiter[",
- ["]"] = "\\mmlrightdelimiter]",
- ["<"] = "\\mmlleftdelimiter<",
- [">"] = "\\mmlrightdelimiter>",
- ["#"] = "\\mmlchar{35}",
- ["$"] = "\\mmlchar{36}", -- $
- ["%"] = "\\mmlchar{37}",
- ["&"] = "\\mmlchar{38}",
- ["^"] = "\\mmlchar{94}{}", -- strange, sometimes luatex math sees the char instead of \char
- ["_"] = "\\mmlchar{95}{}", -- so we need the {}
- ["~"] = "\\mmlchar{126}",
- [" "] = "",
- ["°"] = "^\\circ", -- hack
-
- [utfchar(0xF103C)] = "\\mmlleftdelimiter<",
+ ["@l"] = "\\mmlleftdelimiter.",
+ ["@r"] = "\\mmlrightdelimiter.",
+ ["{"] = "\\mmlleftdelimiter \\lbrace",
+ ["}"] = "\\mmlrightdelimiter\\rbrace",
+ ["|"] = "\\mmlleftorrightdelimiter\\vert",
+ [doublebar] = "\\mmlleftorrightdelimiter\\Vert",
+ ["("] = "\\mmlleftdelimiter(",
+ [")"] = "\\mmlrightdelimiter)",
+ ["["] = "\\mmlleftdelimiter[",
+ ["]"] = "\\mmlrightdelimiter]",
+ -- ["<"] = "\\mmlleftdelimiter<",
+ -- [">"] = "\\mmlrightdelimiter>",
+ ["#"] = "\\mmlchar{35}",
+ ["$"] = "\\mmlchar{36}", -- $
+ ["%"] = "\\mmlchar{37}",
+ ["&"] = "\\mmlchar{38}",
+ ["^"] = "\\mmlchar{94}{}", -- strange, sometimes luatex math sees the char instead of \char
+ ["_"] = "\\mmlchar{95}{}", -- so we need the {}
+ ["~"] = "\\mmlchar{126}",
+ [" "] = "",
+ ["°"] = "^\\circ", -- hack
+
+ -- [utfchar(0xF103C)] = "\\mmlleftdelimiter<",
[utfchar(0xF1026)] = "\\mmlchar{38}",
- [utfchar(0xF103E)] = "\\mmlleftdelimiter>",
+ -- [utfchar(0xF103E)] = "\\mmlleftdelimiter>",
}
@@ -137,250 +139,253 @@ local i_replacements = {
["as"] = "{\\mr as}",
}
+-- we could use a metatable or when accessing fallback on the
+-- key but at least we now have an overview
+
local csymbols = {
arith1 = {
- lcm = "lcm",
- big_lcm = "lcm",
- gcd = "gcd",
- big_gcd = "big_gcd",
- plus = "plus",
- unary_minus = "minus",
- minus = "minus",
- times = "times",
- divide = "divide",
- power = "power",
- abs = "abs",
- root = "root",
- sum = "sum",
- product ="product",
+ lcm = "lcm",
+ big_lcm = "lcm",
+ gcd = "gcd",
+ big_gcd = "big_gcd",
+ plus = "plus",
+ unary_minus = "minus",
+ minus = "minus",
+ times = "times",
+ divide = "divide",
+ power = "power",
+ abs = "abs",
+ root = "root",
+ sum = "sum",
+ product = "product",
},
fns = {
- domain = "domain",
- range = "codomain",
- image = "image",
- identity = "ident",
---~ left_inverse = "",
---~ right_inverse = "",
- inverse = "inverse",
- left_compose = "compose",
- lambda = "labmda",
+ domain = "domain",
+ range = "codomain",
+ image = "image",
+ identity = "ident",
+ -- left_inverse = "",
+ -- right_inverse = "",
+ inverse = "inverse",
+ left_compose = "compose",
+ lambda = "labmda",
},
linalg1 = {
- vectorproduct = "vectorproduct",
- scalarproduct = "scalarproduct",
- outerproduct = "outerproduct",
- transpose = "transpose",
- determinant = "determinant",
- vector_selector = "selector",
---~ matrix_selector = "matrix_selector",
+ vectorproduct = "vectorproduct",
+ scalarproduct = "scalarproduct",
+ outerproduct = "outerproduct",
+ transpose = "transpose",
+ determinant = "determinant",
+ vector_selector = "selector",
+ -- matrix_selector = "matrix_selector",
},
logic1 = {
- equivalent = "equivalent",
- ["not"] = "not",
- ["and"] = "and",
---~ big_and = "",
- ["xor"] = "xor",
---~ big_xor = "",
- ["or"] = "or",
---~ big-or= "",
- implies = "implies",
- ["true"] = "true",
- ["false"] = "false",
+ equivalent = "equivalent",
+ ["not"] = "not",
+ ["and"] = "and",
+ -- big_and = "",
+ ["xor"] = "xor",
+ -- big_xor = "",
+ ["or"] = "or",
+ -- big-or = "",
+ implies = "implies",
+ ["true"] = "true",
+ ["false"] = "false",
},
nums1 = {
---~ based_integer = "based_integer"
- rational = "rational",
- inifinity = "infinity",
- e = "expenonentiale",
- i ="imaginaryi",
- pi = "pi",
- gamma = "gamma",
- NaN, "NaN",
+ -- based_integer = "based_integer"
+ rational = "rational",
+ inifinity = "infinity",
+ e = "expenonentiale",
+ i = "imaginaryi",
+ pi = "pi",
+ gamma = "gamma",
+ NaN = "NaN",
},
relation1 = {
- eq = "eq",
- lt = "lt",
- gt = "gt",
- neq = "neq",
- leq = "leq",
- geq = "geq",
- approx = "approx",
+ eq = "eq",
+ lt = "lt",
+ gt = "gt",
+ neq = "neq",
+ leq = "leq",
+ geq = "geq",
+ approx = "approx",
},
set1 = {
- cartesian_product = "cartesianproduct",
- empty_set = "emptyset",
- map = "map",
- size = "card",
---~ suchthat = "suchthat",
- set = "set",
- intersect = "intersect",
---~ big_intersect = "",
- union = "union",
---~ big_union = "",
- setdiff = "setdiff",
- subset = "subset",
- ["in"] = "in",
- notin = "notin",
- prsubset = "prsubset",
- notsubset = "notsubset",
- notprsubset = "notprsubset",
+ cartesian_product = "cartesianproduct",
+ empty_set = "emptyset",
+ map = "map",
+ size = "card",
+ -- suchthat = "suchthat",
+ set = "set",
+ intersect = "intersect",
+ -- big_intersect = "",
+ union = "union",
+ -- big_union = "",
+ setdiff = "setdiff",
+ subset = "subset",
+ ["in"] = "in",
+ notin = "notin",
+ prsubset = "prsubset",
+ notsubset = "notsubset",
+ notprsubset = "notprsubset",
},
veccalc1 = {
- divergence = "divergence",
- grad = "grad",
- curl = "curl",
- Laplacian = "laplacian",
+ divergence = "divergence",
+ grad = "grad",
+ curl = "curl",
+ Laplacian = "laplacian",
},
calculus1 = {
- diff = "diff",
---~ nthdiff = "",
- partialdiff = "partialdiff",
- int = "int",
---~ defint = "defint",
+ diff = "diff",
+ -- nthdiff = "",
+ partialdiff = "partialdiff",
+ int = "int",
+ -- defint = "defint",
},
integer1 = {
- factorof = "factorof",
- factorial = "factorial",
- quotient = "quotient",
- remainder = "rem",
+ factorof = "factorof",
+ factorial = "factorial",
+ quotient = "quotient",
+ remainder = "rem",
},
linalg2 = {
- vector = "vector",
- matrix = "matrix",
- matrixrow = "matrixrow",
+ vector = "vector",
+ matrix = "matrix",
+ matrixrow = "matrixrow",
},
mathmkeys = {
---~ equiv = "",
---~ contentequiv = "",
---~ contentequiv_strict = "",
+ -- equiv = "",
+ -- contentequiv = "",
+ -- contentequiv_strict = "",
},
rounding1 = {
- ceiling = "ceiling",
- floor = "floor",
---~ trunc = "trunc",
---~ round = "round",
+ ceiling = "ceiling",
+ floor = "floor",
+ -- trunc = "trunc",
+ -- round = "round",
},
setname1 = {
- P = "primes",
- N = "naturalnumbers",
- Z = "integers",
- rationals = "rationals",
- R = "reals",
- complexes = "complexes",
+ P = "primes",
+ N = "naturalnumbers",
+ Z = "integers",
+ rationals = "rationals",
+ R = "reals",
+ complexes = "complexes",
},
complex1 = {
---~ complex_cartesian = "complex_cartesian", -- ci ?
- real = "real",
- imaginary = "imaginary",
---~ complex_polar = "complex_polar", -- ci ?
- argument = "arg",
- conjugate = "conjugate",
+ -- complex_cartesian = "complex_cartesian", -- ci ?
+ real = "real",
+ imaginary = "imaginary",
+ -- complex_polar = "complex_polar", -- ci ?
+ argument = "arg",
+ conjugate = "conjugate",
},
interval1 = { -- not an apply
---~ "integer_interval" = "integer_interval",
- interval = "interval",
- interval_oo = { tag = "interval", closure = "open" },
- interval_cc = { tag = "interval", closure = "closed" },
- interval_oc = { tag = "interval", closure = "open-closed" },
- interval_co = { tag = "interval", closure = "closed-open" },
+ -- integer_interval = "integer_interval",
+ interval = "interval",
+ interval_oo = { tag = "interval", closure = "open" },
+ interval_cc = { tag = "interval", closure = "closed" },
+ interval_oc = { tag = "interval", closure = "open-closed" },
+ interval_co = { tag = "interval", closure = "closed-open" },
},
linalg3 = {
---~ vector = "vector.column",
---~ matrixcolumn = "matrixcolumn",
---~ matrix = "matrix.column",
+ -- vector = "vector.column",
+ -- matrixcolumn = "matrixcolumn",
+ -- matrix = "matrix.column",
},
minmax1 = {
- min = "min",
---~ big_min = "",
- max = "max",
---~ big_max = "",
+ min = "min",
+ -- big_min = "",
+ max = "max",
+ -- big_max = "",
},
piece1 = {
- piecewise = "piecewise",
- piece = "piece",
- otherwise = "otherwise",
+ piecewise = "piecewise",
+ piece = "piece",
+ otherwise = "otherwise",
},
error1 = {
---~ unhandled_symbol = "",
---~ unexpected_symbol = "",
---~ unsupported_CD = "",
+ -- unhandled_symbol = "",
+ -- unexpected_symbol = "",
+ -- unsupported_CD = "",
},
limit1 = {
---~ limit = "limit",
---~ both_sides = "both_sides",
---~ above = "above",
---~ below = "below",
---~ null = "null",
- tendsto = "tendsto",
+ -- limit = "limit",
+ -- both_sides = "both_sides",
+ -- above = "above",
+ -- below = "below",
+ -- null = "null",
+ tendsto = "tendsto",
},
list1 = {
---~ map = "",
---~ suchthat = "",
---~ list = "list",
+ -- map = "",
+ -- suchthat = "",
+ -- list = "list",
},
multiset1 = {
- size = { tag = "card", type="multiset" },
- cartesian_product = { tag = "cartesianproduct", type="multiset" },
- empty_set = { tag = "emptyset", type="multiset" },
---~ multi_set = { tag = "multiset", type="multiset" },
- intersect = { tag = "intersect", type="multiset" },
---~ big_intersect = "",
- union = { tag = "union", type="multiset" },
---~ big_union = "",
- setdiff = { tag = "setdiff", type="multiset" },
- subset = { tag = "subset", type="multiset" },
- ["in"] = { tag = "in", type="multiset" },
- notin = { tag = "notin", type="multiset" },
- prsubset = { tag = "prsubset", type="multiset" },
- notsubset = { tag = "notsubset", type="multiset" },
- notprsubset = { tag = "notprsubset", type="multiset" },
+ size = { tag = "card", type = "multiset" },
+ cartesian_product = { tag = "cartesianproduct", type = "multiset" },
+ empty_set = { tag = "emptyset", type = "multiset" },
+ -- multi_set = { tag = "multiset", type = "multiset" },
+ intersect = { tag = "intersect", type = "multiset" },
+ -- big_intersect = "",
+ union = { tag = "union", type = "multiset" },
+ -- big_union = "",
+ setdiff = { tag = "setdiff", type = "multiset" },
+ subset = { tag = "subset", type = "multiset" },
+ ["in"] = { tag = "in", type = "multiset" },
+ notin = { tag = "notin", type = "multiset" },
+ prsubset = { tag = "prsubset", type = "multiset" },
+ notsubset = { tag = "notsubset", type = "multiset" },
+ notprsubset = { tag = "notprsubset", type = "multiset" },
},
quant1 = {
- forall = "forall",
- exists = "exists",
+ forall = "forall",
+ exists = "exists",
},
s_dist = {
---~ mean = "mean.dist",
---~ sdev = "sdev.dist",
---~ variance = "variance.dist",
---~ moment = "moment.dist",
+ -- mean = "mean.dist",
+ -- sdev = "sdev.dist",
+ -- variance = "variance.dist",
+ -- moment = "moment.dist",
},
s_data = {
- mean = "mean",
- sdev = "sdev",
- variance = "vriance",
- mode = "mode",
- median = "median",
- moment = "moment",
+ mean = "mean",
+ sdev = "sdev",
+ variance = "vriance",
+ mode = "mode",
+ median = "median",
+ moment = "moment",
},
transc1 = {
- log = "log",
- ln = "ln",
- exp = "exp",
- sin = "sin",
- cos = "cos",
- tan = "tan",
- sec = "sec",
- csc = "csc",
- cot = "cot",
- sinh = "sinh",
- cosh = "cosh",
- tanh = "tanh",
- sech = "sech",
- csch = "cscs",
- coth = "coth",
- arcsin = "arcsin",
- arccos = "arccos",
- arctan = "arctan",
- arcsec = "arcsec",
- arcscs = "arccsc",
- arccot = "arccot",
- arcsinh = "arcsinh",
- arccosh = "arccosh",
- arctanh = "arstanh",
- arcsech = "arcsech",
- arccsch = "arccsch",
- arccoth = "arccoth",
+ log = "log",
+ ln = "ln",
+ exp = "exp",
+ sin = "sin",
+ cos = "cos",
+ tan = "tan",
+ sec = "sec",
+ csc = "csc",
+ cot = "cot",
+ sinh = "sinh",
+ cosh = "cosh",
+ tanh = "tanh",
+ sech = "sech",
+ csch = "cscs",
+ coth = "coth",
+ arcsin = "arcsin",
+ arccos = "arccos",
+ arctan = "arctan",
+ arcsec = "arcsec",
+ arcscs = "arccsc",
+ arccot = "arccot",
+ arcsinh = "arcsinh",
+ arccosh = "arccosh",
+ arctanh = "arstanh",
+ arcsech = "arcsech",
+ arccsch = "arccsch",
+ arccoth = "arccoth",
},
}
@@ -442,44 +447,33 @@ function xml.functions.remapopenmath(e)
e.rn = "mml"
end
-function lxml.mml.checked_operator(str)
+function mathml.checked_operator(str)
texsprint(ctxcatcodes,(utfgsub(str,".",o_replacements)))
end
-function lxml.mml.stripped(str)
+function mathml.stripped(str)
tex.sprint(ctxcatcodes,str:strip())
end
-function table.keys_as_string(t)
- local k = { }
- for k,_ in next, t do
- k[#k+1] = k
- end
- return concat(k,"")
-end
-
---~ local leftdelimiters = "[" .. table.keys_as_string(l_replacements) .. "]"
---~ local rightdelimiters = "[" .. table.keys_as_string(r_replacements) .. "]"
-
-function characters.remapentity(chr,slot)
+function characters.remapentity(chr,slot) -- brrrrrr
texsprint(format("{\\catcode%s=13\\xdef%s{\\string%s}}",slot,utfchar(slot),chr))
end
-function lxml.mml.mn(id,pattern)
+function mathml.mn(id,pattern)
-- maybe at some point we need to interpret the number, but
-- currently we assume an upright font
- local str = xmlcontent(get_id(id)) or ""
+ local str = xmlcontent(getid(id)) or ""
str = gsub(str,"(%s+)",utfchar(0x205F)) -- medspace e.g.: twenty one (nbsp is not seen)
texsprint(ctxcatcodes,(gsub(str,".",n_replacements)))
end
-function lxml.mml.mo(id)
- local str = xmlcontent(get_id(id)) or ""
+function mathml.mo(id)
+ local str = xmlcontent(getid(id)) or ""
texsprint(ctxcatcodes,(utfgsub(str,".",o_replacements)))
end
-function lxml.mml.mi(id)
- local str = xmlcontent(get_id(id)) or ""
+function mathml.mi(id)
+ local str = xmlcontent(getid(id)) or ""
-- str = gsub(str,"^%s*(.-)%s*$","%1")
local rep = i_replacements[str]
if rep then
@@ -489,8 +483,8 @@ function lxml.mml.mi(id)
end
end
-function lxml.mml.mfenced(id) -- multiple separators
- id = get_id(id)
+function mathml.mfenced(id) -- multiple separators
+ id = getid(id)
local left, right, separators = id.at.open or "(", id.at.close or ")", id.at.separators or ","
local l, r = l_replacements[left], r_replacements[right]
texsprint(ctxcatcodes,"\\enabledelimiter")
@@ -562,7 +556,7 @@ local function flush(e,tag,toggle)
return not toggle
end
-function lxml.mml.mmultiscripts(id)
+function mathml.mmultiscripts(id)
local done, toggle = false, false
for e in lxml.collected(id,"/*") do
local tag = e.tg
@@ -609,8 +603,8 @@ local frametypes = {
-- crazy element ... should be a proper structure instead of such a mess
-function lxml.mml.mcolumn(root)
- root = get_id(root)
+function mathml.mcolumn(root)
+ root = getid(root)
local matrix, numbers = { }, 0
local function collect(m,e)
local tag = e.tg
@@ -705,9 +699,9 @@ end
local spacesplitter = lpeg.Ct(lpeg.splitat(" "))
-function lxml.mml.mtable(root)
+function mathml.mtable(root)
-- todo: align, rowspacing, columnspacing, rowlines, columnlines
- root = get_id(root)
+ root = getid(root)
local at = root.at
local rowalign = at.rowalign
local columnalign = at.columnalign
@@ -763,8 +757,8 @@ function lxml.mml.mtable(root)
--~ context.eTABLE()
end
-function lxml.mml.csymbol(root)
- root = get_id(root)
+function mathml.csymbol(root)
+ root = getid(root)
local at = root.at
local encoding = at.encoding or ""
local hash = url.hashed(lower(at.definitionUrl or ""))
@@ -775,8 +769,8 @@ function lxml.mml.csymbol(root)
texsprint(ctxcatcodes,"\\mmlapplycsymbol{",full,"}{",base,"}{",encoding,"}{",text,"}")
end
-function lxml.mml.menclosepattern(root)
- root = get_id(root)
+function mathml.menclosepattern(root)
+ root = getid(root)
local a = root.at.notation
if a and a ~= "" then
texsprint("mml:enclose:",gsub(a," +",",mml:enclose:"))