diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/math-tag.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/math-tag.lua | 186 |
1 files changed, 97 insertions, 89 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/math-tag.lua b/Master/texmf-dist/tex/context/base/mkiv/math-tag.lua index 13c8fffc76d..d1ed90d389b 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/math-tag.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/math-tag.lua @@ -33,6 +33,10 @@ local setattr = nuts.setattr local getcomponents = nuts.getcomponents local getwidth = nuts.getwidth +local getnucleus = nuts.getnucleus +local getsub = nuts.getsub +local getsup = nuts.getsup + local set_attributes = nuts.setattributes local traverse_nodes = nuts.traverse @@ -60,6 +64,7 @@ local math_fixed_both = accentcodes.fixedboth local kerncodes = nodes.kerncodes local fontkern_code = kerncodes.fontkern +local italickern_code = kerncodes.italickern local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist @@ -74,7 +79,6 @@ local processnoads = noads.process local a_tagged = attributes.private('tagged') local a_mathcategory = attributes.private('mathcategory') local a_mathmode = attributes.private('mathmode') -local a_fontkern = attributes.private('fontkern') local tags = structures.tags @@ -85,7 +89,7 @@ local taglist = tags.taglist local chardata = characters.data -local getmathcode = tex.getmathcode +local getmathcodes = tex.getmathcodes local mathcodes = mathematics.codes local ordinary_code = mathcodes.ordinary local variable_code = mathcodes.variable @@ -101,9 +105,9 @@ local function processsubsup(start) -- At some point we might need to add an attribute signaling the -- super- and subscripts because TeX and MathML use a different -- order. The mrows are needed to keep mn's separated. - local nucleus = getfield(start,"nucleus") - local sup = getfield(start,"sup") - local sub = getfield(start,"sub") + local nucleus = getnucleus(start) + local sup = getsup(start) + local sub = getsub(start) if sub then if sup then setattr(start,a_tagged,start_tagged("msubsup")) @@ -190,7 +194,7 @@ process = function(start) -- we cannot use the processor as we have no finalizer mtexttag = start_tagged("mtext") end setattr(start,a_tagged,mtexttag) - elseif mtexttag and id == kern_code and (getsubtype(start) == fontkern_code or getattr(start,a_fontkern)) then + elseif mtexttag and id == kern_code and (getsubtype(start) == fontkern_code or getsubtype(start) == italickern_code) then -- italickern setattr(start,a_tagged,mtexttag) else if mtexttag then @@ -199,10 +203,7 @@ process = function(start) -- we cannot use the processor as we have no finalizer end if id == math_char_code then local char = getchar(start) - local code = getmathcode(char) - if code then - code = code[1] - end + local code = getmathcodes(char) local tag if code == ordinary_code or code == variable_code then local ch = chardata[char] @@ -247,95 +248,102 @@ process = function(start) -- we cannot use the processor as we have no finalizer elseif id == math_box_code or id == hlist_code or id == vlist_code then -- keep an eye on math_box_code and see what ends up in there local attr = getattr(start,a_tagged) +if not attr then + -- just skip +else local specification = taglist[attr] - local tag = specification.tagname - if tag == "formulacaption" then - -- skip - elseif tag == "mstacker" then - local list = getlist(start) - if list then - process(list) - end - else - if tag ~= "mstackertop" and tag ~= "mstackermid" and tag ~= "mstackerbot" then - tag = "mtext" - end - local text = start_tagged(tag) - setattr(start,a_tagged,text) - local list = getlist(start) - if not list then - -- empty list - elseif not attr then - -- box comes from strange place - set_attributes(list,a_tagged,text) -- only the first node ? + if specification then + local tag = specification.tagname + if tag == "formulacaption" then + -- skip + elseif tag == "mstacker" then + local list = getlist(start) + if list then + process(list) + end else - -- Beware, the first node in list is the actual list so we definitely - -- need to nest. This approach is a hack, maybe I'll make a proper - -- nesting feature to deal with this at another level. Here we just - -- fake structure by enforcing the inner one. - -- - -- todo: have a local list with local tags that then get appended - -- - local tagdata = specification.taglist - local common = #tagdata + 1 - local function runner(list,depth) -- quite inefficient - local cache = { } -- we can have nested unboxed mess so best local to runner - local keep = nil - -- local keep = { } -- win case we might need to move keep outside - for n in traverse_nodes(list) do - local id = getid(n) - local mth = id == math_code and getsubtype(n) - if mth == 0 then - -- insert(keep,text) - keep = text - text = start_tagged("mrow") - common = common + 1 - end - local aa = getattr(n,a_tagged) - if aa then - local ac = cache[aa] - if not ac then - local tagdata = taglist[aa].taglist - local extra = #tagdata - if common <= extra then - for i=common,extra do - ac = restart_tagged(tagdata[i]) -- can be made faster - end - for i=common,extra do - stop_tagged() -- can be made faster + if tag ~= "mstackertop" and tag ~= "mstackermid" and tag ~= "mstackerbot" then + tag = "mtext" + end + local text = start_tagged(tag) + setattr(start,a_tagged,text) + local list = getlist(start) + if not list then + -- empty list + elseif not attr then + -- box comes from strange place + set_attributes(list,a_tagged,text) -- only the first node ? + else + -- Beware, the first node in list is the actual list so we definitely + -- need to nest. This approach is a hack, maybe I'll make a proper + -- nesting feature to deal with this at another level. Here we just + -- fake structure by enforcing the inner one. + -- + -- todo: have a local list with local tags that then get appended + -- + local tagdata = specification.taglist + local common = #tagdata + 1 + local function runner(list,depth) -- quite inefficient + local cache = { } -- we can have nested unboxed mess so best local to runner + local keep = nil + -- local keep = { } -- win case we might need to move keep outside + for n in traverse_nodes(list) do + local id = getid(n) + local mth = id == math_code and getsubtype(n) + if mth == 0 then + -- insert(keep,text) + keep = text + text = start_tagged("mrow") + common = common + 1 + end + local aa = getattr(n,a_tagged) + if aa then + local ac = cache[aa] + if not ac then + local tagdata = taglist[aa].taglist + local extra = #tagdata + if common <= extra then + for i=common,extra do + ac = restart_tagged(tagdata[i]) -- can be made faster + end + for i=common,extra do + stop_tagged() -- can be made faster + end + else + ac = text end - else - ac = text + cache[aa] = ac end - cache[aa] = ac + setattr(n,a_tagged,ac) + else + setattr(n,a_tagged,text) end - setattr(n,a_tagged,ac) - else - setattr(n,a_tagged,text) - end - if id == hlist_code or id == vlist_code then - runner(getlist(n),depth+1) - elseif id == glyph_code then - runner(getcomponents(n),depth+1) -- this should not be needed - elseif id == disc_code then - local pre, post, replace = getdisc(n) - runner(pre,depth+1) -- idem - runner(post,depth+1) -- idem - runner(replace,depth+1) -- idem - end - if mth == 1 then - stop_tagged() - -- text = remove(keep) - text = keep - common = common - 1 + if id == hlist_code or id == vlist_code then + runner(getlist(n),depth+1) + elseif id == glyph_code then + -- this should not be needed (todo: use tounicode info) + runner(getcomponents(n),depth+1) + elseif id == disc_code then + local pre, post, replace = getdisc(n) + runner(pre,depth+1) -- idem + runner(post,depth+1) -- idem + runner(replace,depth+1) -- idem + end + if mth == 1 then + stop_tagged() + -- text = remove(keep) + text = keep + common = common - 1 + end end end + runner(list,0) end - runner(list,0) + stop_tagged() end - stop_tagged() end +end elseif id == math_sub_code then -- normally a hbox local list = getlist(start) if list then @@ -420,7 +428,7 @@ process = function(start) -- we cannot use the processor as we have no finalizer -- left local properties = { } insert(fencesstack,properties) - setattr(start,a_tagged,start_tagged("mfenced",{ properties = properties })) -- needs checking + setattr(start,a_tagged,start_tagged("mfenced",properties)) -- needs checking if delim then start_tagged("ignore") local chr = getfield(delim,"small_char") |