texlive[60662] trunk: make4ht (30sep21)

commits+karl at tug.org commits+karl at tug.org
Thu Sep 30 22:13:53 CEST 2021


Revision: 60662
          http://tug.org/svn/texlive?view=revision&revision=60662
Author:   karl
Date:     2021-09-30 22:13:53 +0200 (Thu, 30 Sep 2021)
Log Message:
-----------
make4ht (30sep21)

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-sectionid.lua
    trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.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-htlatex.lua

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

Modified: trunk/Build/source/texk/texlive/linked_scripts/make4ht/make4ht
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/make4ht/make4ht	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Build/source/texk/texlive/linked_scripts/make4ht/make4ht	2021-09-30 20:13:53 UTC (rev 60662)
@@ -29,7 +29,7 @@
 
 -- set version number. the template should be replaced by the
 -- actual version number by the build script
-local version = "v0.3h"
+local version = "v0.3i"
 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	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/doc/support/make4ht/README	2021-09-30 20:13:53 UTC (rev 60662)
@@ -433,7 +433,8 @@
 
 :    This command removes all generated files, including images, HTML files and
      various auxilary files, from the current directory. It keeps files whose
-     file names don't match the input file name.
+     file names don't match the input file name. It is preferable to use `make4ht -m clean filename.tex`
+     to clean output files.
 
 `Make:httex`
 
@@ -658,8 +659,9 @@
 
 odtimagesize
 
-:  set correct dimensions for images in the ODT format. It is loaded by default for the ODT output.
+:  set correct dimensions for images in the ODT format. It is no longer used, as the dimensions are set by TeX4ht itself.
 
+
 odtpartable
 
 :  resolve tables nested inside paragraphs, which is invalid in the ODT format.

Modified: trunk/Master/texmf-dist/doc/support/make4ht/changelog.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/make4ht/changelog.tex	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/doc/support/make4ht/changelog.tex	2021-09-30 20:13:53 UTC (rev 60662)
@@ -3,6 +3,76 @@
 
 \begin{itemize}
 \item
+  2021/09/30
+
+  \begin{itemize}
+  \tightlist
+  \item
+    version \texttt{0.3i} released.
+  \end{itemize}
+\item
+  2021/09/21
+
+  \begin{itemize}
+  \tightlist
+  \item
+    run DOM parse in sandbox in the ODT format picture size function.
+  \end{itemize}
+\item
+  2021/09/20
+
+  \begin{itemize}
+  \tightlist
+  \item
+    remove LaTeX commands from TOC entries in \texttt{sectionid} DOM
+    filter.
+  \end{itemize}
+\item
+  2021/09/09
+
+  \begin{itemize}
+  \tightlist
+  \item
+    corrected SVG dimension setting in the ODT output. Dimensions are
+    set also for PNG and JPG pictures.
+  \end{itemize}
+\item
+  2021/09/05
+
+  \begin{itemize}
+  \tightlist
+  \item
+    corrected detection of closing brace in CSS style in \texttt{mjcli}
+    filter.
+  \end{itemize}
+\item
+  2021/08/13
+
+  \begin{itemize}
+  \tightlist
+  \item
+    use LaTeX new hook mechanism to load \texttt{tex4ht.sty} before
+    document class. It fixes some issues with packages required in
+    classes.
+  \end{itemize}
+\item
+  2021/08/12
+
+  \begin{itemize}
+  \tightlist
+  \item
+    correctly set dimensions for \texttt{SVG} images in the \texttt{ODT}
+    format.
+  \end{itemize}
+\item
+  2021/07/29
+
+  \begin{itemize}
+  \tightlist
+  \item
+    sort YAML header in the \texttt{staticsite} filter.
+  \end{itemize}
+\item
   2021/07/25
 
   \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	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/doc/support/make4ht/readme.tex	2021-09-30 20:13:53 UTC (rev 60662)
@@ -531,7 +531,8 @@
 \item[\texttt{Make:clean}]
 This command removes all generated files, including images, HTML files
 and various auxilary files, from the current directory. It keeps files
-whose file names don't match the input file name.
+whose file names don't match the input file name. It is preferable to
+use \texttt{make4ht\ -m\ clean\ filename.tex} to clean output files.
 \item[\texttt{Make:httex}]
 Variant of \texttt{Make:htlatex} suitable for Plain \TeX.
 \item[\texttt{Make:latexmk}]
@@ -734,8 +735,8 @@
 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[odtimagesize]
-set correct dimensions for images in the ODT format. It is loaded by
-default for the ODT output.
+set correct dimensions for images in the ODT format. It is no longer
+used, as the dimensions are set by TeX4ht itself.
 \item[odtpartable]
 resolve tables nested inside paragraphs, which is invalid in the ODT
 format.

Added: trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtsvg.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtsvg.lua	                        (rev 0)
+++ trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtsvg.lua	2021-09-30 20:13:53 UTC (rev 60662)
@@ -0,0 +1,42 @@
+-- we need to set dimensions for SVG images produced by \Picture commands
+local log = logging.new "odtsvg"
+local function get_svg_dimensions(filename) 
+  local width, height
+  log:debug("file exists", filename, mkutils.file_exists(filename))
+  if mkutils.file_exists(filename) then 
+    for line in io.lines(filename) do
+      width = line:match("width%s*=%s*[\"'](.-)[\"']") or width
+      height = line:match("height%s*=%s*[\"'](.-)[\"']") or height
+      -- stop parsing once we get both width and height
+      if width and height then break end
+    end
+  end
+  return width, height
+end
+
+
+-- process 
+return function(dom)
+  for _, pic in ipairs(dom:query_selector("draw|image")) do
+    local imagename = pic:get_attribute("xlink:href")
+    -- update SVG images dimensions
+    log:debug("image", imagename)
+    local parent = pic:get_parent()
+    local width =  parent:get_attribute("svg:width")
+    local height = parent:get_attribute("svg:height")
+    -- if width == "0.0pt" then width = nil end
+    -- if height == "0.0pt" then height = nil end
+    if not width or not height then
+      if imagename:match("svg$") then
+        width, height = get_svg_dimensions(imagename) --  or width, height
+      elseif imagename:match("png$") or imagename:match("jpe?g$") then
+      end
+    end
+    log:debug("dimensions", width, height)
+    parent:set_attribute("svg:width", width)
+    parent:set_attribute("svg:height", height)
+    -- if 
+  end
+  return dom
+end
+


Property changes on: trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtsvg.lua
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-sectionid.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-sectionid.lua	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-sectionid.lua	2021-09-30 20:13:53 UTC (rev 60662)
@@ -44,6 +44,9 @@
 
 local escape_name = function(name)
   local result = {}
+  -- remove LaTeX commands
+  name = name:gsub("\\[%a]+", "")
+  name = name:gsub("^%s+", ""):gsub("%s+$", "")
   for _,char in utf8.codes(name) do
     local info = chardata[char] or {}
     if is_space(info) then
@@ -62,7 +65,7 @@
   -- the section ids and titles are saved in the following format:
   -- \csname a:TocLink\endcsname{1}{x1-20001}{QQ2-1-2}{Nazdar světe}
   -- ............................... id ................. title ...
-  local id, name = line:match("a:TocLink.-{.-}{(.-)}{.-}{(.-)}")
+  local id, name = line:match("a:TocLink.-{.-}{(.-)}{.-}(%b{})")
   if id then
     return id, escape_name(name)
   end

Modified: trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.lua	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.lua	2021-09-30 20:13:53 UTC (rev 60662)
@@ -62,7 +62,8 @@
         status = "record"
       end
     elseif status == "record" then
-      if line:match("%}") then
+      -- find end of the CSS rule
+      if line:match("}%s*$") then
         status = "init"
         if not used_styles[current_selector] then
           table.insert(saved_styles, {selector = current_selector, content = current})

Modified: trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua	2021-09-30 20:13:53 UTC (rev 60662)
@@ -7,7 +7,13 @@
   local indent = string.rep("  ", level)
   -- indentation for multilen strings
   local str_indent = string.rep("  ", level + 1)
-  for k,v in pairs(tbl) do
+  local sorted = {}
+  for k, _ in pairs(tbl) do
+    sorted[#sorted+1] = k
+  end
+  table.sort(sorted)
+  for _,k in ipairs(sorted) do
+    local v = tbl[k]
     if type(v)=="string" then
       -- detect multiline strings
       if v:match("\n") then

Modified: trunk/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua	2021-09-30 20:13:53 UTC (rev 60662)
@@ -5,6 +5,7 @@
 local kpse    = require "kpse"
 local filter  = require "make4ht-filter"
 local domfilter  = require "make4ht-domfilter"
+local domobject  = require "luaxml-domobject"
 local xtpipeslib = require "make4ht-xtpipes"
 local log = logging.new "odt"
 
@@ -81,6 +82,88 @@
   mkutils.delete_dir(self.archivelocation)
 end
 
+--- *************************
+--  *** fix picture sizes ***
+--  *************************
+--
+local function add_points(dimen)
+  if type(dimen) ~= "string" then return dimen end
+  -- convert SVG dimensions to points if only number is provided
+  if dimen:match("[0-9]$") then return dimen .. "pt" end
+  return dimen
+end
+
+local function get_svg_dimensions(filename) 
+  local width, height
+  if mkutils.file_exists(filename) then 
+    for line in io.lines(filename) do
+      width = line:match("width%s*=%s*[\"'](.-)[\"']") or width
+      height = line:match("height%s*=%s*[\"'](.-)[\"']") or height
+      -- stop parsing once we get both width and height
+      if width and height then break end
+    end
+  end
+  width = add_points(width)
+  height = add_points(height)
+  return width, height
+end
+
+local function get_xbb_dimensions(filename)
+  local f = io.popen("ebb -x -O " .. filename)
+  if f then
+    local content = f:read("*all")
+    local width, height = content:match("%%BoundingBox: %d+ %d+ (%d+) (%d+)")
+    return add_points(width), add_points(height)
+  end
+  return nil
+end
+--
+local function fix_picture_sizes(tmpdir)
+  local filename = tmpdir .. "/content.xml"
+  local f = io.open(filename, "r")
+  if not f then 
+    log:warning("Cannot open ", filename, "for picture size fixes")
+    return nil
+  end
+  local content = f:read("*all") or ""
+  f:close()
+  local status, domobject = pcall(function()
+    return domobject.parse(content)
+  end)
+  if not status then 
+    log:warning("Cannot parse DOM, the resulting ODT file will be most likely corrupted")
+    return nil
+  end
+  for _, pic in ipairs(dom:query_selector("draw|image")) do
+    local imagename = pic:get_attribute("xlink:href")
+    -- update SVG images dimensions
+    log:debug("image", imagename)
+    local parent = pic:get_parent()
+    local width =  parent:get_attribute("svg:width")
+    local height = parent:get_attribute("svg:height")
+    -- if width == "0.0pt" then width = nil end
+    -- if height == "0.0pt" then height = nil end
+    if not width or not height then
+      local imgfilename = tmpdir .. "/" .. imagename
+      if imagename:match("svg$") then
+        width, height = get_svg_dimensions(imgfilename) --  or width, height
+      elseif imagename:match("png$") or imagename:match("jpe?g$") then
+        width, height = get_xbb_dimensions(imgfilename)
+      end
+    end
+    log:debug("new dimensions", width, height)
+    parent:set_attribute("svg:width", width)
+    parent:set_attribute("svg:height", height)
+    -- if 
+  end
+  -- save the modified DOM again
+  log:debug("Fixed picture sizes")
+  local content = dom:serialize()
+  local f = io.open(filename, "w")
+  f:write(content)
+  f:close()
+end
+
 -- escape string to be used in the gsub search
 local function escape_file(filename)
   local quotepattern = '(['..("%^$().[]*+-?"):gsub("(.)", "%%%1")..'])'
@@ -219,6 +302,9 @@
           odt:copy("${basename}" % par, "Pictures")
         end)
 
+        -- fix picture sizes in the content file
+        fix_picture_sizes(odt.archivelocation)
+
         -- remove some spurious file
         exec_group(groups, "4od", function(par)
           os.remove(par.filename)

Modified: trunk/Master/texmf-dist/scripts/make4ht/make4ht
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/make4ht	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/scripts/make4ht/make4ht	2021-09-30 20:13:53 UTC (rev 60662)
@@ -29,7 +29,7 @@
 
 -- set version number. the template should be replaced by the
 -- actual version number by the build script
-local version = "v0.3h"
+local version = "v0.3i"
 mkparams.version_number = version
 
 local args = mkparams.get_args()

Modified: trunk/Master/texmf-dist/scripts/make4ht/make4ht-htlatex.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/make4ht/make4ht-htlatex.lua	2021-09-30 20:13:28 UTC (rev 60661)
+++ trunk/Master/texmf-dist/scripts/make4ht/make4ht-htlatex.lua	2021-09-30 20:13:53 UTC (rev 60662)
@@ -43,8 +43,8 @@
 Make.latex_command = "${htlatex} --interaction=${interaction} ${latex_par} '\\makeatletter"..
 "\\def\\HCode{\\futurelet\\HCode\\HChar}\\def\\HChar{\\ifx\"\\HCode"..
 "\\def\\HCode\"##1\"{\\Link##1}\\expandafter\\HCode\\else"..
-"\\expandafter\\Link\\fi}\\def\\Link#1.a.b.c.{\\g at addto@macro"..
-"\\@documentclasshook{\\RequirePackage[#1,html]{tex4ht}${packages}}"..
+"\\expandafter\\Link\\fi}\\def\\Link#1.a.b.c.{\\AddToHook"..
+"{class/before}{\\RequirePackage[#1,html]{tex4ht}${packages}}"..
 "\\let\\HCode\\documentstyle\\def\\documentstyle{\\let\\documentstyle"..
 "\\HCode\\expandafter\\def\\csname tex4ht\\endcsname{#1,html}\\def"..
 "\\HCode####1{\\documentstyle[tex4ht,}\\@ifnextchar[{\\HCode}{"..



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