texlive[62075] trunk: make4ht (18feb22)

commits+karl at tug.org commits+karl at tug.org
Fri Feb 18 23:12:03 CET 2022


Revision: 62075
          http://tug.org/svn/texlive?view=revision&revision=62075
Author:   karl
Date:     2022-02-18 23:12:02 +0100 (Fri, 18 Feb 2022)
Log Message:
-----------
make4ht (18feb22)

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/make4ht/make4ht
    trunk/Master/texmf-dist/doc/support/make4ht/README
    trunk/Master/texmf-dist/doc/support/make4ht/changelog.tex
    trunk/Master/texmf-dist/doc/support/make4ht/make4ht-doc.pdf
    trunk/Master/texmf-dist/doc/support/make4ht/readme.tex
    trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-fixinlines.lua
    trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-mathmlfixes.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_filters.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-join_colors.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mathjaxnode.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mjcli.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-odttemplate.lua
    trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-staticsite.lua
    trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua
    trunk/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua
    trunk/Master/texmf-dist/scripts/make4ht/make4ht
    trunk/Master/texmf-dist/scripts/make4ht/make4ht-logging.lua
    trunk/Master/texmf-dist/scripts/make4ht/make4ht-xtpipes.lua
    trunk/Master/texmf-dist/scripts/make4ht/mkparams.lua

Added Paths:
-----------
    trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua

Modified: trunk/Build/source/texk/texlive/linked_scripts/make4ht/make4ht
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/make4ht/make4ht	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Build/source/texk/texlive/linked_scripts/make4ht/make4ht	2022-02-18 22:12:02 UTC (rev 62075)
@@ -29,7 +29,7 @@
 
 -- set version number. the template should be replaced by the
 -- actual version number by the build script
-local version = "v0.3j"
+local version = "v0.3k"
 mkparams.version_number = version
 
 local args = mkparams.get_args()

Modified: trunk/Master/texmf-dist/doc/support/make4ht/README
===================================================================
--- trunk/Master/texmf-dist/doc/support/make4ht/README	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/doc/support/make4ht/README	2022-02-18 22:12:02 UTC (rev 62075)
@@ -657,6 +657,10 @@
    substantial growth of the CSS file. This filter replaces these rules with a
    common one for elements with the same color value.
 
+odtfonts
+
+:  fix styles for fonts that were wrongly converted by `Xtpipes` in the ODT format.
+
 odtimagesize
 
 :  set correct dimensions for images in the ODT format. It is no longer used, as the dimensions are set by TeX4ht itself.

Modified: trunk/Master/texmf-dist/doc/support/make4ht/changelog.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/make4ht/changelog.tex	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/doc/support/make4ht/changelog.tex	2022-02-18 22:12:02 UTC (rev 62075)
@@ -3,6 +3,120 @@
 
 \begin{itemize}
 \item
+  2022/02/18
+
+  \begin{itemize}
+  \tightlist
+  \item
+    version \texttt{0.3k} released.
+  \end{itemize}
+\item
+  2022/02/07
+
+  \begin{itemize}
+  \tightlist
+  \item
+    fixed support for some fonts in the ODT format.
+  \item
+    added \texttt{odtfonts} DOM filter.
+  \end{itemize}
+\item
+  2022/01/30
+
+  \begin{itemize}
+  \tightlist
+  \item
+    fix \texttt{mathvariant} attribue of
+    \texttt{\textless{}mi\textgreater{}} elements if they are children
+    of \texttt{\textless{}mstyle\textgreater{}}.
+  \end{itemize}
+\item
+  2021/12/17
+
+  \begin{itemize}
+  \tightlist
+  \item
+    quote jobname in order to support filenames like \texttt{(xxx).tex}.
+  \end{itemize}
+\item
+  2021/12/13
+
+  \begin{itemize}
+  \tightlist
+  \item
+    fixed setting of properties in the \texttt{staticsite} filter.
+  \end{itemize}
+\item
+  2021/12/06
+
+  \begin{itemize}
+  \tightlist
+  \item
+    in the end, use \texttt{\textless{}mtext\textgreater{}} even for one
+    \texttt{\textless{}mo\textgreater{}} in the \texttt{fix\_operators}
+    function. LO had issues with \texttt{\textless{}mi\textgreater{}}.
+  \end{itemize}
+\item
+  2021/12/03
+
+  \begin{itemize}
+  \tightlist
+  \item
+    don't add additional \texttt{\textless{}mrow\textgreater{}} elements
+    in the \texttt{mathmlfixes} DOM filter. It caused various issues.
+  \end{itemize}
+\item
+  2021/12/01
+
+  \begin{itemize}
+  \tightlist
+  \item
+    transform
+    \texttt{\textless{}mn\textgreater{}x\textless{}/mn\textgreater{}\textless{}mo\textgreater{}.\textless{}/mo\textgreater{}\textless{}mn\textgreater{}x\textless{}/mn\textgreater{}}
+    to
+    \texttt{\textless{}mn\textgreater{}x.x\textless{}/mn\textgreater{}}
+    in MathML.
+  \item
+    transform \texttt{\textless{}mo\textgreater{}} elements that are
+    single childs to \texttt{\textless{}mi\textgreater{}} in MathML, and
+    list of consecutive \texttt{\textless{}mo\textgreater{}} elements to
+    \texttt{\textless{}mtext\textgreater{}}. This should fix rendering
+    issues of superscripts in LibreOffice.
+  \item
+    added filter names in extensions to prevent multiple execution of
+    filters.
+  \end{itemize}
+\item
+  2021/11/29
+
+  \begin{itemize}
+  \tightlist
+  \item
+    make current logging level available outside of the Logging module.
+  \item
+    print Xtpipes and Tidy output if these command fail in the Xtpipes
+    module.
+  \end{itemize}
+\item
+  2021/11/18
+
+  \begin{itemize}
+  \tightlist
+  \item
+    don't put \texttt{\textless{}mrow\textgreater{}} as children of
+    \texttt{\textless{}mrow\textgreater{}} in the \texttt{mathmlfixes}
+    DOM filter.
+  \end{itemize}
+\item
+  2021/11/04
+
+  \begin{itemize}
+  \tightlist
+  \item
+    more intelligent handling of text and inline elements outside of
+    paragraphs in the \texttt{fixinlines} DOM filter.
+  \end{itemize}
+\item
   2021/10/11
 
   \begin{itemize}

Modified: trunk/Master/texmf-dist/doc/support/make4ht/make4ht-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/support/make4ht/readme.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/make4ht/readme.tex	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/doc/support/make4ht/readme.tex	2022-02-18 22:12:02 UTC (rev 62075)
@@ -734,6 +734,9 @@
 the document. A CSS rule is added for each of these elements, which may
 result in substantial growth of the CSS file. This filter replaces these
 rules with a common one for elements with the same color value.
+\item[odtfonts]
+fix styles for fonts that were wrongly converted by \texttt{Xtpipes} in
+the ODT format.
 \item[odtimagesize]
 set correct dimensions for images in the ODT format. It is no longer
 used, as the dimensions are set by TeX4ht itself.

Modified: trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-fixinlines.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-fixinlines.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-fixinlines.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -41,15 +41,33 @@
   local settings = get_filter_settings "fixinlines"
   local inline_elements = settings.inline_elements or inline_elements
   local nodes = obj:get_path("html body")
+  local new = nil
   obj:traverse_node_list(nodes, function(jej) 
-    if jej._type == "ELEMENT" then
-      local name = string.lower(jej._name)
+    if jej._type == "ELEMENT" or jej._type == "TEXT" then
+      local name = string.lower(jej._name or "")
       -- local parent = jej:get_parent_node()
-      if inline_elements[name] then
-        local new = obj:create_element("p" )
-        new:add_child_node(obj:copy_node(jej))
-        jej:replace_node(new)
+      if inline_elements[name] or jej._type == "TEXT" then
+        if not new then
+          -- start new paragraph
+          if jej._type == "TEXT" and jej._text:match("^%s+$") then
+            -- ignore parts that contain only whitespace and are placed before 
+            -- paragraph start
+          else
+            new = obj:create_element("p" )
+            new:add_child_node(obj:copy_node(jej))
+            jej:replace_node(new)
+          end
+        else
+          -- paragraph already exists
+          new:add_child_node(obj:copy_node(jej))
+          jej:remove_node()
+        end
+      else
+        -- close the current paragraph before new block element
+        new = nil
       end
+    else
+      new = nil
     end
   end)
   return obj

Modified: trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-mathmlfixes.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-mathmlfixes.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-mathmlfixes.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -1,3 +1,4 @@
+local log = logging.new("mathmlfixes")
 -- <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"}
@@ -37,20 +38,57 @@
   end
 end
 
--- if element contains 
--- wrap everything in <mrow>
+local function fix_mathvariant(el)
+  -- set mathvariant of <mi> that is child of <mstyle> to have the same value
+  local function find_mstyle(x)
+    -- find if element has <mstyle> parent, and its value of mathvariant
+    if not x:is_element() then
+      return nil
+    elseif x:get_element_name() == "mstyle" then 
+      return x:get_attribute("mathvariant")
+    else
+      return find_mstyle(x:get_parent())
+    end
+  end
+  if el:get_element_name() == "mi" then
+    -- process only <mi> that have mathvariant set
+    local oldmathvariant = el:get_attribute("mathvariant")
+    if oldmathvariant then
+      local mathvariant = find_mstyle(el:get_parent())
+      if mathvariant then
+        el:set_attribute("mathvariant", mathvariant)
+      end
+    end
+  end
+end
+
+-- put <mrow> as child of <math> if it already isn't here
+local allowed_top_mrow = {
+  math=true
+}
 local function top_mrow(math)
   local children = math:get_children()
   local put_mrow = false
   -- don't process elements with one or zero children
   -- don't process elements that already are mrow
-  if #children < 2 or  math:get_element_name() == "mrow" then return nil end
+  local parent = math:get_parent()
+  local parent_name
+  if parent then parent_name = parent:get_element_name() end
+  local current_name = math:get_element_name()
+  if #children < 2 or not allowed_top_mrow[current_name] or current_name == "mrow" or parent_name == "mrow" then return nil end
+  local mrow_count = 0
   for _,v in ipairs(children) do
     if v:is_element() and is_token_element(v) then
       put_mrow = true
-      break
+      -- break
+    elseif v:is_element() and v:get_element_name() == "mrow" then
+      mrow_count = mrow_count + 1
     end
   end
+  if not put_mrow and math:get_element_name() == "math" and mrow_count == 0 then
+    -- put at least one <mrow> to each <math>
+    put_mrow = true
+  end
   if put_mrow then
     local mrow = math:create_element("mrow")
     for _, el in ipairs(children) do
@@ -122,6 +160,86 @@
   end
 end
 
+local function fix_numbers(el)
+  -- convert <mn>1</mn><mo>.</mo><mn>3</mn> to <mn>1.3</mn>
+  if el:get_element_name() == "mn" then
+    local n = el:get_sibling_node(1)
+    -- test if next  element is <mo class="MathClass-punc">.</mo>
+    if n and n:is_element() 
+         and n:get_element_name() == "mo" 
+         and n:get_attribute("class") == "MathClass-punc" 
+         and n:get_text() == "." 
+    then
+      -- get next element and test if it is <mn>
+      local x = el:get_sibling_node(2)
+      if x and x:is_element() 
+           and x:get_element_name() == "mn" 
+      then
+        -- join numbers and set it as text content of the current element
+        local newnumber = el:get_text() .. "." .. x:get_text()
+        log:debug("Joining numbers: " .. newnumber)
+        el._children = {}
+        local newchild = el:create_text_node(newnumber)
+        el:add_child_node(newchild)
+        -- remove elements that hold dot and decimal part
+        n:remove_node()
+        x:remove_node()
+      end
+    end
+  end
+end
+
+
+local function just_operators(list)
+  -- count <mo> and return true if list contains just them
+  local mo = 0
+  for _, x in ipairs(list) do
+    if x:get_element_name() == "mo" then mo = mo + 1 end
+  end
+  return mo
+end
+
+
+local function fix_operators(x)
+  -- change <mo> elements that are only children of any element to <mi>
+  -- this fixes issues in LibreOffice with a^{*}
+  -- I hope it doesn't introduce different issues
+  -- process only <mo>
+  if x:get_element_name() ~= "mo" then return nil end
+	local siblings = x:get_siblings()
+	-- test if current element list contains only <mo>
+	if just_operators(siblings) == #siblings then
+		if #siblings == 1 then
+			-- one <mo> translates to <mtext>
+			x._name = "mtext"
+      log:debug("changing one <mo> to <mtext>: " .. x:get_text())
+      -- I think we should use <mi>, but LO incorrectly renders it in <msubsup>,
+      -- even if we use the mathvariant="normal" attribute. <mtext> works, so
+      -- we use that instead.
+			-- x:set_attribute("mathvariant", "normal")
+		else
+			-- multiple <mo> translate to <mtext>
+			local text = {}
+			for _, el in ipairs(siblings) do
+				text[#text+1] = el:get_text()
+			end
+			-- replace first <mo> text with concetanated text content
+			-- of all <mo> elements
+			x._children = {}
+      local newtext = table.concat(text)
+			local text_el = x:create_text_node(newtext)
+      log:debug("changing <mo> to <mtext>: " .. newtext)
+      x:add_child_node(text_el)
+      -- change <mo> to <mtext>
+      x._name = "mtext"
+      -- remove subsequent <mo>
+      for i = 2, #siblings do
+        siblings[i]:remove_node()
+      end
+    end
+  end
+end
+
 return function(dom)
   dom:traverse_elements(function(el)
     if settings.output_format ~= "odt" then
@@ -132,6 +250,9 @@
     end
     fix_token_elements(el)
     fix_nested_mstyle(el)
+    fix_numbers(el)
+    fix_operators(el)
+    fix_mathvariant(el)
     top_mrow(el)
   end)
   return dom

Added: trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua	                        (rev 0)
+++ trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -0,0 +1,26 @@
+return function(dom, params)
+  -- fix ODT style for fonts 
+  -- sometimes, fonts have missing size, we need to patch styles
+  local properties = get_filter_settings "odtfonts" or {}
+  local fix_lgfile_fonts = params.patched_lg_fonts or properties.patched_lg_fonts or {}
+  for _, style in ipairs(dom:query_selector "style|style") do
+    local typ  = style:get_attribute("style:family")
+    if typ == "text" then
+      -- detect if the style is for font
+      local style_name = style:get_attribute("style:name")
+      local name, size, size2, size3 = style_name:match("(.-)%-(%d*)x%-(%d*)x%-(%d+)")
+      if name then
+        -- find if the style corresponds to a problematic font (it is set in formats/make4ht-odt.lua)
+        local used_name = name .. "-" .. size
+        if fix_lgfile_fonts[used_name] then
+          -- copy current style and fix the name
+          local new = style:copy_node()
+          new:set_attribute("style:name", string.format("%s-x-%sx-%s", name, size2, size3))
+          local parent = style:get_parent()
+          parent:add_child_node(new)
+        end
+      end
+    end
+  end
+  return dom
+end


Property changes on: trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_domfilters.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -19,7 +19,7 @@
   local count = 0
   if current_format == "odt" then
     -- some formats doesn't make sense in the ODT format
-    local process = filter {"joincharacters", "mathmlfixes"}
+    local process = filter ({"joincharacters", "mathmlfixes"}, "commondomfilters")
     local charclasses = {mn = true, ["text:span"] = true, mi=true}
     make:match("4oo$", process, {charclasses= charclasses})
     -- match math documents
@@ -26,7 +26,7 @@
     make:match("4om$", process, {charclasses= charclasses})
     count = 2
   else
-    local process = filter {"fixinlines", "idcolons", "joincharacters", "mathmlfixes", "tablerows","booktabs", "sectionid", "itemparagraphs"}
+    local process = filter({"fixinlines", "idcolons", "joincharacters", "mathmlfixes", "tablerows","booktabs", "sectionid", "itemparagraphs"}, "commondomfilters")
     make:match("html?$", process)
     count = 1
   end

Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_filters.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_filters.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-common_filters.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -2,7 +2,7 @@
 
 
 local filter = require "make4ht-filter"
-local process = filter {"cleanspan-nat", "fixligatures", "hruletohr", "entities", "fix-links"}
+local process = filter({"cleanspan-nat", "fixligatures", "hruletohr", "entities", "fix-links"}, "commonfilters")
 
 -- filters support only html formats
 function M.test(format)

Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-dvisvgm_hashes.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -243,7 +243,7 @@
   end)
 
   -- fix src attributes
-  local process = filter {
+  local process = filter({
     function(str, filename)
       return str:gsub('src=["\'](.-)(["\'])', function(filename, endquote)
         local newname = output_map[filename] or filename
@@ -251,7 +251,7 @@
         return 'src=' .. endquote .. newname  .. endquote
       end)
     end
-  }
+  }, "dvisvgmhashes")
 
   make:match("htm.?$", process)
 

Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-join_colors.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-join_colors.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-join_colors.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -9,7 +9,7 @@
 end
 
 function M.modify_build(make)
-  local process = filter {"joincolors"}
+  local process = filter({"joincolors"}, "joincolors")
   make:match("html?$", process)
   return make
 end

Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mathjaxnode.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mathjaxnode.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mathjaxnode.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -13,7 +13,7 @@
 
 end
 function M.modify_build(make)
-  local mathjax = filter { "mathjaxnode"}
+  local mathjax = filter({ "mathjaxnode"}, "mathjaxnode")
   -- this extension needs mathml enabled
   make:match("html?$",mathjax)
   return make

Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mjcli.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mjcli.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-mjcli.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -24,7 +24,7 @@
 
 end
 function M.modify_build(make)
-  local mathjax = filter { "mjcli"}
+  local mathjax = filter({ "mjcli"}, "mjcli")
   local params = {}
   if detected_latex then
     params.latex = true

Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-odttemplate.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-odttemplate.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-odttemplate.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -8,7 +8,7 @@
 end
 
 M.modify_build = function(make)
-  local process = filter {"odttemplate"}
+  local process = filter({"odttemplate"}, "odttemplate")
   make:match("4oy$", process)
   return make
 end

Modified: trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-staticsite.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-staticsite.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/extensions/make4ht-ext-staticsite.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -22,6 +22,7 @@
     -- escape 
     -- slug must contain the unescaped input name
     local f = io.open(published_name, "w")
+    log:info("Publishing article", os.date("%Y-%m-%d %H:%M", time))
     f:write(time)
     f:close()
   end
@@ -79,7 +80,7 @@
 local function remove_maketitle(make)
   -- use DOM filter to remove \maketitle block
   local domfilter = require "make4ht-domfilter"
-  local process = domfilter {
+  local process = domfilter({
     function(dom)
       local maketitles = dom:query_selector(".maketitle")
       for _, el in ipairs(maketitles) do
@@ -88,7 +89,7 @@
       end
       return dom
     end
-  }
+  }, "staticsite")
   make:match("html$", process)
 end
 
@@ -120,9 +121,9 @@
   -- we use an bogus match which will be executed only once as the very first one to insert
   -- the filters
   -- I should make filter from this
-  local process = filter {
+  local process = filter({
     "staticsite"
-  }
+  }, "staticsite")
 
   -- detect if we should remove maketitle
   local site_settings = get_filter_settings "staticsite"

Modified: trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -58,13 +58,17 @@
   -- enable properties update from the config or build file
   local settings = get_filter_settings "staticsite" or {}
   local header = settings.header or {}
+  -- set non-function properties first
   for field, rule in pairs(header) do
+    if type(rule) ~="function" then
+      properties[field] = rule
+    end
+  end
+  -- then execute functions. it ensures that all propeties set in header are available
+  for field, rule in pairs(header) do
     -- it is possible to pass function as a rule, it will be executed with properties as a parameter
     if type(rule) == "function" then
       properties[field] = rule(properties, dom)
-    else
-      -- otherwise set properties
-      properties[field] = rule
     end
   end
   return properties

Modified: trunk/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -73,10 +73,10 @@
   lfs.chdir(self.archivelocation)
   -- make temporary mime type file
   self:make_mimetype()
-  mkutils.execute(zip_command .. " -q0X " .. self.name .. " " .. self.mimetypename)
+  mkutils.execute(zip_command .. " -q0X '" .. self.name .. "' " .. self.mimetypename)
   -- remove it, so the next command doesn't overwrite it
   self:remove_mimetype()
-  mkutils.execute(zip_command .." -r " .. self.name .. " *")
+  mkutils.execute(zip_command .." -r '" .. self.name .. "' *")
   lfs.chdir(currentdir)
   mkutils.cp(self.archivelocation .. "/" .. self.name, self.name)
   mkutils.delete_dir(self.archivelocation)
@@ -164,6 +164,58 @@
   f:close()
 end
 
+-- fix font records in the lg file that don't correct Font_Size record
+local lg_fonts_processed=false
+local patched_lg_fonts = {}
+local function fix_lgfile_fonts(ignored_name, params)
+  -- this function is called from file match. we must use the name of the .lg file
+  local filename = params.input .. ".lg"
+  if not lg_fonts_processed then
+    local lines = {}
+    -- default font_size
+    local font_size = "10"
+    if mkutils.file_exists(filename) then 
+      -- 
+      for line in io.lines(filename) do
+        -- default font_size can be set in the .lg file
+        if line:match("Font_Size") then
+          font_size = line:match("Font_Size:%s*(%d+)")
+        elseif line:match("Font%(") then
+          -- match Font record
+          local name, size, size2, size3 = line:match('Font%("([^"]+)","([%d]*)","([%d]+)","([%d]+)"')
+          -- find if the first size is not set, and add the default font_size then
+          if size == "" then
+            line = string.format('Font("%s","%s","%s","%s")', name, font_size, size2, size3)
+            -- we must also save the font name and size for later post-processing, because 
+            -- we will need to fix styles in content.xml too
+            patched_lg_fonts[name .. "-" .. font_size] = true
+          end
+        end
+        lines[#lines+1] = line
+      end
+      -- save changed lines to the lg file
+      local f = io.open(filename, "w")
+      for _,line in ipairs(lines) do
+        f:write(line .. "\n")
+      end
+      f:close()
+    end
+    filter_settings "odtfonts" {patched_lg_fonts = patched_lg_fonts}
+  end
+  lg_fonts_processed=true
+  return true
+end
+
+local move_matches = xtpipeslib.move_matches
+
+local function insert_lgfile_fonts(make)
+  local first_file = make.params.input .. ".4oo"
+  -- find the last file and escape it so it can be used 
+  -- in filename match
+  make:match(first_file, fix_lgfile_fonts)
+  move_matches(make)
+end
+
 -- escape string to be used in the gsub search
 local function escape_file(filename)
   local quotepattern = '(['..("%^$().[]*+-?"):gsub("(.)", "%%%1")..'])'
@@ -170,7 +222,6 @@
   return filename:gsub(quotepattern, "%%%1")
 end
 
-local move_matches = xtpipeslib.move_matches
 
 -- call xtpipes from Lua
 local function call_xtpipes(make)
@@ -185,6 +236,8 @@
     -- we need to move last two matches, for 4oo and 4om files
     move_matches(make)
     move_matches(make)
+    -- fix font records in the lg file
+    insert_lgfile_fonts(make)
   else
     log:warning "Cannot locate xtpipes. Try to set TEXMFROOT variable to a root directory of your TeX distribution"
   end
@@ -231,6 +284,9 @@
   -- fixes for mathml
   local mathmldomfilters = domfilter({"joincharacters","mathmlfixes"}, "mathmlfilters")
   make:match("4om$", mathmldomfilters)
+  -- DOM filters that should be executed after xtpipes
+  local latedom = domfilter({"odtfonts"}, "lateodtfilters")
+  make:match("4oo$", latedom)
   -- convert XML entities for Unicode characters produced by Xtpipes to characters
   local fixentities = filter {"entities-to-unicode", remove_xtpipes}
   make:match("4oo", fixentities)

Modified: trunk/Master/texmf-dist/scripts/make4ht/make4ht
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/make4ht	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/make4ht	2022-02-18 22:12:02 UTC (rev 62075)
@@ -29,7 +29,7 @@
 
 -- set version number. the template should be replaced by the
 -- actual version number by the build script
-local version = "v0.3j"
+local version = "v0.3k"
 mkparams.version_number = version
 
 local args = mkparams.get_args()

Modified: trunk/Master/texmf-dist/scripts/make4ht/make4ht-logging.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/make4ht-logging.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/make4ht-logging.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -4,7 +4,8 @@
 
 local levels = {}
 -- level of bugs that should be shown
-local show_level = 1
+-- enable querying of current log level
+logging.show_level = 1
 local max_width = 0
 local max_status = 0
 
@@ -34,7 +35,7 @@
 -- the logging level is set once
 function logging.set_level(name)
   local level = levels[name] or 1
-  show_level = level
+  logging.show_level = level
 end
 
 function logging.print_msg(header, message, color)
@@ -53,7 +54,7 @@
     module = module,
     output = function(self, output)
       -- used for printing of output of commands
-      if show_level <= (levels[debug] or 1) then
+      if logging.show_level <= (levels["debug"] or 1) then
         print(output)
       end
     end
@@ -68,7 +69,7 @@
       -- set make4ht exit status
       max_status = math.max(status, max_status)
       -- max width is saved in logging.prepare_levels
-      if mode.level >= show_level then
+      if mode.level >= logging.show_level then
         -- support variable number of parameters
         local table_with_holes = table.pack(...) 
         local table_without_holes = {}
@@ -106,6 +107,7 @@
 -- logging.set_level("error")
 -- cls:info("level set")
 -- cls:error("just print the error")
+--
 
 
 return logging

Modified: trunk/Master/texmf-dist/scripts/make4ht/make4ht-xtpipes.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/make4ht-xtpipes.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/make4ht-xtpipes.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -48,18 +48,27 @@
     mkutils.mv(filename, tmpfile)
     local command = pattern % {filename = tmpfile, outputfile = filename}
     log:info("execute: " ..command)
-    local status = mkutils.execute(command)
+    local status, output = mkutils.execute(command)
     if status > 0 then
       -- if xtpipes failed to process the file, it may mean that it was bad-formed xml
       -- we can try to make it well-formed using Tidy
       local tidy_command = 'tidy -utf8 -xml -asxml -q -o "${filename}" "${tmpfile}"' % {tmpfile = tmpfile, filename = filename}
-      log:warning("xtpipes failed trying tidy")
+      log:warning("Xtpipes failed")
+      -- show_level 1 is debug mode, which prints command output as well
+      -- we need this condition to prevent multiple instances of the output
+      if logging.show_level > 1 then
+        print(output)
+      end
+      log:warning("Trying HTML tidy")
       log:debug(tidy_command)
-      local status = os.execute(tidy_command)
+      local status, output = os.execute(tidy_command)
       if status > 0 then
         -- if tidy failed as well, just use the original file
         -- it will probably produce corrupted ODT file though
         log:warning("Tidy failed as well")
+        if logging.show_level > 1 then
+          print(output)
+        end
         mkutils.mv(tmpfile, filename)
       end
     end

Modified: trunk/Master/texmf-dist/scripts/make4ht/mkparams.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/mkparams.lua	2022-02-18 22:11:00 UTC (rev 62074)
+++ trunk/Master/texmf-dist/scripts/make4ht/mkparams.lua	2022-02-18 22:12:02 UTC (rev 62075)
@@ -108,7 +108,7 @@
     input = input:match("([^%/^%\\]+)$")
     -- input also cannot contain spaces, replace them with underscores
     input = input:gsub("%s", "_")
-    table.insert(latex_params,"-jobname="..input)
+    table.insert(latex_params,"-jobname='"..input.. "'")
   else
     -- when user specifies -jobname, we must change name of the input file,
     -- in order to be able to process correct dvi file with tex4ht and t4ht



More information about the tex-live-commits mailing list.