diff options
author | Karl Berry <karl@freefriends.org> | 2019-11-27 22:06:50 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-11-27 22:06:50 +0000 |
commit | 5ddfa0bd3428ac6c5b0a4a564b2b1b78a468d129 (patch) | |
tree | 5a95803333995618d7870de20959b7dc9bd1589b /Master/texmf-dist/scripts/make4ht | |
parent | 80cb9c50ef0c7af421240024db2804123753d73b (diff) |
make4ht (27nov19)
git-svn-id: svn://tug.org/texlive/trunk@52950 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht')
8 files changed, 74 insertions, 10 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincharacters.lua b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincharacters.lua index 30ed6e1382a..5830eae78e6 100644 --- a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincharacters.lua +++ b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincharacters.lua @@ -1,8 +1,23 @@ +local log = logging.new("joincharacters") + local charclasses = { span=true, mn = true, + mi = true } +local has_matching_attributes = function (el, next_el) + local el_attr = el._attr or {} + local next_attr = next_el._attr or {} + -- if the number of attributes doesn't match, elements don't match + if #next_attr ~= #el_attr then return false end + for k, v in pairs(el_attr) do + -- if any attribute doesn't match, elements don't match + if v~=next_attr[k] then return false end + end + return true +end + local function join_characters(obj,par) -- join adjanced span and similar elements inserted by -- tex4ht to just one object. @@ -10,12 +25,13 @@ local function join_characters(obj,par) local options = get_filter_settings "joincharacters" local charclasses = options.charclasses or par.charclasses or charclasses + obj:traverse_elements(function(el) local get_name = function(curr) return string.lower(curr:get_element_name()) end local get_class = function(next_el) - return next_el:get_attribute("class") + return next_el:get_attribute("class") or next_el:get_attribute("mathvariant") end local is_span = function(next_el) return charclasses[get_name(next_el)] @@ -41,7 +57,7 @@ local function join_characters(obj,par) while next_el do -- save the next element because we will remove it later local real_next = get_next(next_el) - if get_name(el) == get_name(next_el) and get_class(el) == get_class(next_el) and not el:get_attribute("id") then + if get_name(el) == get_name(next_el) and has_matching_attributes(el,next_el) and not el:get_attribute("id") then -- it the following element match, copy it's children to the current element for _, child in ipairs(next_el:get_children()) do el:add_child_node(child) diff --git a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-mathmlfixes.lua b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-mathmlfixes.lua new file mode 100644 index 00000000000..a52b0e5d6b1 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-mathmlfixes.lua @@ -0,0 +1,46 @@ +-- <mglyph> should be inside <mi>, so we don't process it +-- even though it is a token element +local token = {"mi", "mn", "mo", "mtext", "mspace", "ms"} +local token_elements = {} +for _, tok in ipairs(token) do token_elements[tok] = true end + +local function is_token_element(el) + return token_elements[el:get_element_name()] +end + +local function fix_token_elements(el) + -- find token elements that are children of other token elements + if is_token_element(el) then + local parent = el:get_parent() + if is_token_element(parent) then + -- change top element in nested token elements to mstyle + parent._name = "mstyle" + end + end +end + +local function fix_nested_mstyle(el) + -- the <mstyle> element can be child of token elements + -- we must exterminate it + if el:get_element_name() == "mstyle" then + local parent = el:get_parent() + if is_token_element(parent) then + -- if parent doesn't have the mathvariant attribute copy it from <mstyle> + if not parent:get_attribute("mathvariant") then + local mathvariant = el:get_attribute("mathvariant") + parent:set_attribute("mathvariant", mathvariant) + end + -- copy the contents of <mstyle> to the parent element + parent._children = el._children + end + end +end + +return function(dom) + dom:traverse_elements(function(el) + fix_token_elements(el) + fix_nested_mstyle(el) + end) + return dom +end + diff --git a/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua b/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua index 9399492d907..ec687cd042d 100644 --- a/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua +++ b/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua @@ -19,14 +19,14 @@ function M.modify_build(make) local count = 0 if current_format == "odt" then -- some formats doesn't make sense in the ODT format - local process = filter {"joincharacters"} - local charclasses = {mn = true, ["text:span"] = true} + local process = filter {"joincharacters", "mathmlfixes"} + local charclasses = {mn = true, ["text:span"] = true, mi=true} make:match("4oo$", process, {charclasses= charclasses}) -- match math documents make:match("4om$", process, {charclasses= charclasses}) count = 2 else - local process = filter {"fixinlines", "idcolons", "joincharacters", "tablerows"} + local process = filter {"fixinlines", "idcolons", "joincharacters", "mathmlfixes", "tablerows"} make:match("html$", process) count = 1 end diff --git a/Master/texmf-dist/scripts/make4ht/formats/make4ht-html5.lua b/Master/texmf-dist/scripts/make4ht/formats/make4ht-html5.lua index 633a45e7f34..a70309fa7ae 100644 --- a/Master/texmf-dist/scripts/make4ht/formats/make4ht-html5.lua +++ b/Master/texmf-dist/scripts/make4ht/formats/make4ht-html5.lua @@ -3,8 +3,7 @@ local M = {} local mkutils = require "mkutils" function M.prepare_extensions(extensions) - -- return mkutils.add_extensions("+common_domfilters", extensions) - return extensions --mkutils.add_extensions("+tidy", extensions) + return mkutils.add_extensions("+common_domfilters", extensions) end function M.prepare_parameters(parameters,extensions) diff --git a/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua b/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua index c515a154a1b..30fdc0744da 100644 --- a/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua +++ b/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua @@ -136,6 +136,9 @@ function M.modify_build(make) -- fix the image dimensions wrongly set by xtpipes local domfilters = domfilter {"t4htlinks", "odtpartable"} make:match("4oo$", domfilters) + -- fixes for mathml + local mathmldomfilters = domfilter {"joincharacters","mathmlfixes"} + make:match("4om$", mathmldomfilters) -- execute it before xtpipes, because we don't want xtpipes to mess with t4htlink elements move_matches(make) -- convert XML entities for Unicode characters produced by Xtpipes to characters diff --git a/Master/texmf-dist/scripts/make4ht/formats/make4ht-xhtml.lua b/Master/texmf-dist/scripts/make4ht/formats/make4ht-xhtml.lua index 4a4ac6689ca..25fb339c0f8 100644 --- a/Master/texmf-dist/scripts/make4ht/formats/make4ht-xhtml.lua +++ b/Master/texmf-dist/scripts/make4ht/formats/make4ht-xhtml.lua @@ -3,8 +3,7 @@ local M = {} local mkutils = require "mkutils" function M.prepare_extensions(extensions) - -- return mkutils.add_extensions("+common_domfilters", extensions) - return extensions + return mkutils.add_extensions("+common_domfilters", extensions) end function M.prepare_parameters(parameters,extensions) diff --git a/Master/texmf-dist/scripts/make4ht/make4ht b/Master/texmf-dist/scripts/make4ht/make4ht index fd153164cd7..10311088d78 100755 --- a/Master/texmf-dist/scripts/make4ht/make4ht +++ b/Master/texmf-dist/scripts/make4ht/make4ht @@ -29,7 +29,7 @@ make4ht [options] filename ["tex4ht.sty op." "tex4ht op." "t4ht op" "latex op"] -- set version number. the template should be replaced by the -- actual version number by the build script -local version = "v0.3b" +local version = "v0.3c" mkparams.version_number = version local args = mkparams.get_args() diff --git a/Master/texmf-dist/scripts/make4ht/mkutils.lua b/Master/texmf-dist/scripts/make4ht/mkutils.lua index 0ea85c7b56b..944ab99cc74 100755 --- a/Master/texmf-dist/scripts/make4ht/mkutils.lua +++ b/Master/texmf-dist/scripts/make4ht/mkutils.lua @@ -440,6 +440,7 @@ end -- for the BibLaTeX support env.Make:add("biber", "biber ${input}") env.Make:add("bibtex", "bibtex ${input}") +env.Make:add("pythontex", "pythontex ${input}") --- load the output format plugins function load_output_format(format_name) |