summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/x-mathml.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/x-mathml.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/x-mathml.lua54
1 files changed, 26 insertions, 28 deletions
diff --git a/Master/texmf-dist/tex/context/base/x-mathml.lua b/Master/texmf-dist/tex/context/base/x-mathml.lua
index 30e77019028..31483bbeabf 100644
--- a/Master/texmf-dist/tex/context/base/x-mathml.lua
+++ b/Master/texmf-dist/tex/context/base/x-mathml.lua
@@ -9,13 +9,11 @@ if not modules then modules = { } end modules ['x-mathml'] = {
-- This needs an upgrade to the latest greatest mechanisms.
local type, next = type, next
-local utf = unicode.utf8
local format, lower, find, gsub = string.format, string.lower, string.find, string.gsub
local strip = string.strip
-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 getid = lxml.getid
-local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues
+local utfchar, utfcharacters, utfvalues = utf.char, utf.characters, utf.values
local lpegmatch = lpeg.match
local mathml = { }
@@ -87,6 +85,8 @@ local o_replacements = { -- in main table
}
+local simpleoperatorremapper = utf.remapper(o_replacements)
+
--~ languages.data.labels.functions
local i_replacements = {
@@ -104,6 +104,7 @@ local i_replacements = {
["identity"] = "\\mathopnolimits{id}",
["image"] = "\\mathopnolimits{image}",
["lcm"] = "\\mathopnolimits{lcm}",
+ ["lim"] = "\\mathopnolimits{lim}",
["max"] = "\\mathopnolimits{max}",
["median"] = "\\mathopnolimits{median}",
["min"] = "\\mathopnolimits{min}",
@@ -457,18 +458,13 @@ function xml.functions.remapopenmath(e)
end
function mathml.checked_operator(str)
- str = utfgsub(str,".",o_replacements)
- context(str)
+ context(simpleoperatorremapper(str))
end
function mathml.stripped(str)
context(strip(str))
end
-function characters.remapentity(chr,slot) -- Brrrrrr, this will be replaced!
- context("{\\catcode%s=13\\xdef%s{\\string%s}}",slot,utfchar(slot),chr)
-end
-
function mathml.mn(id,pattern)
-- maybe at some point we need to interpret the number, but
-- currently we assume an upright font
@@ -481,24 +477,29 @@ end
function mathml.mo(id)
local str = xmlcontent(getid(id)) or ""
- local rep = gsub(str,"&.-;","")
- local rep = utfgsub(rep,".",o_replacements)
- context(rep)
- -- context.mo(rep) -- fails with \left etc
+ local rep = gsub(str,"&.-;","") -- todo
+ context(simpleoperatorremapper(rep))
end
function mathml.mi(id)
+ -- we need to strip comments etc .. todo when reading in tree
local e = getid(id)
local str = e.dt
- if type(str) == "string" then -- we need a helper for this in the xml namespace ... xml.type(e)
- -- local str = xmlcontent(e) or ""
- local str = gsub(str,"&.-;","") -- needed?
- local rep = i_replacements[str]
- if not rep then
- rep = gsub(str,".",i_replacements)
+ if type(str) == "string" then
+ local n = #str
+ if n == 0 then
+ -- nothing to do
+ elseif n == 1 then
+ local str = gsub(str[1],"&.-;","") -- bah
+ local rep = i_replacements[str]
+ if not rep then
+ rep = gsub(str,".",i_replacements)
+ end
+ context(rep)
+ -- context.mi(rep)
+ else
+ context.xmlflush(id) -- xmlsprint or so
end
- context(rep)
- -- context.mi(rep)
else
context.xmlflush(id) -- xmlsprint or so
end
@@ -524,10 +525,7 @@ function mathml.mfenced(id) -- multiple separators
elseif n == 1 then
xmlsprint(collected[1]) -- to be checked
else
- local t = { }
- for s in utfgmatch(separators,"[^%s]") do
- t[#t+1] = s
- end
+ local t = utf.split(separators,true)
for i=1,n do
xmlsprint(collected[i]) -- to be checked
if i < n then
@@ -646,8 +644,8 @@ function mathml.mcolumn(root)
local tag = e.tg
if tag == "mi" or tag == "mn" or tag == "mo" or tag == "mtext" then
local str = xmltext(e)
-str = gsub(str,"&.-;","")
- for s in utfcharacters(str) do -- utf.gmatch(str,".") btw, the gmatch was bugged
+ str = gsub(str,"&.-;","")
+ for s in utfcharacters(str) do
m[#m+1] = { tag, s }
end
if tag == "mn" then
@@ -658,7 +656,7 @@ str = gsub(str,"&.-;","")
end
elseif tag == "mspace" or tag == "mline" then
local str = e.at.spacing or ""
- for s in utfcharacters(str) do -- utf.gmatch(str,".") btw, the gmatch was bugged
+ for s in utfcharacters(str) do
m[#m+1] = { tag, s }
end
-- elseif tag == "mline" then