summaryrefslogtreecommitdiff
path: root/support/make4ht
diff options
context:
space:
mode:
Diffstat (limited to 'support/make4ht')
-rw-r--r--support/make4ht/README6
-rw-r--r--support/make4ht/changelog.tex70
-rw-r--r--support/make4ht/domfilters/make4ht-odtsvg.lua42
-rw-r--r--support/make4ht/domfilters/make4ht-sectionid.lua5
-rw-r--r--support/make4ht/filters/make4ht-mjcli.lua3
-rw-r--r--support/make4ht/filters/make4ht-staticsite.lua8
-rw-r--r--support/make4ht/formats/make4ht-odt.lua86
-rwxr-xr-xsupport/make4ht/make4ht2
-rw-r--r--support/make4ht/make4ht-doc.pdfbin144186 -> 152568 bytes
-rw-r--r--support/make4ht/make4ht-htlatex.lua4
-rw-r--r--support/make4ht/readme.tex7
11 files changed, 222 insertions, 11 deletions
diff --git a/support/make4ht/README b/support/make4ht/README
index 89cfac9141..51af04a3fc 100644
--- a/support/make4ht/README
+++ b/support/make4ht/README
@@ -433,7 +433,8 @@ detect compilation errors in the TeX log file.
: 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,7 +659,8 @@ joincolors
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
diff --git a/support/make4ht/changelog.tex b/support/make4ht/changelog.tex
index 61dbcdaa3b..d1b9b22219 100644
--- a/support/make4ht/changelog.tex
+++ b/support/make4ht/changelog.tex
@@ -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}
diff --git a/support/make4ht/domfilters/make4ht-odtsvg.lua b/support/make4ht/domfilters/make4ht-odtsvg.lua
new file mode 100644
index 0000000000..453cf430f7
--- /dev/null
+++ b/support/make4ht/domfilters/make4ht-odtsvg.lua
@@ -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
+
diff --git a/support/make4ht/domfilters/make4ht-sectionid.lua b/support/make4ht/domfilters/make4ht-sectionid.lua
index c1629181bb..4a1f522e6e 100644
--- a/support/make4ht/domfilters/make4ht-sectionid.lua
+++ b/support/make4ht/domfilters/make4ht-sectionid.lua
@@ -44,6 +44,9 @@ end
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 @@ local function parse_toc_line(line)
-- 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
diff --git a/support/make4ht/filters/make4ht-mjcli.lua b/support/make4ht/filters/make4ht-mjcli.lua
index c7b3c46507..f610246439 100644
--- a/support/make4ht/filters/make4ht-mjcli.lua
+++ b/support/make4ht/filters/make4ht-mjcli.lua
@@ -62,7 +62,8 @@ local function parse_css(css, file_class)
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})
diff --git a/support/make4ht/filters/make4ht-staticsite.lua b/support/make4ht/filters/make4ht-staticsite.lua
index 969d47ecaa..5620f9c8bb 100644
--- a/support/make4ht/filters/make4ht-staticsite.lua
+++ b/support/make4ht/filters/make4ht-staticsite.lua
@@ -7,7 +7,13 @@ local function make_yaml(tbl, level)
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
diff --git a/support/make4ht/formats/make4ht-odt.lua b/support/make4ht/formats/make4ht-odt.lua
index 4d5d768ee7..257e597bb3 100644
--- a/support/make4ht/formats/make4ht-odt.lua
+++ b/support/make4ht/formats/make4ht-odt.lua
@@ -5,6 +5,7 @@ local os = require "os"
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 @@ function Odtfile:pack()
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 @@ function M.modify_build(make)
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)
diff --git a/support/make4ht/make4ht b/support/make4ht/make4ht
index d2bf27194f..1e7b0d73df 100755
--- a/support/make4ht/make4ht
+++ b/support/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.3h"
+local version = "v0.3i"
mkparams.version_number = version
local args = mkparams.get_args()
diff --git a/support/make4ht/make4ht-doc.pdf b/support/make4ht/make4ht-doc.pdf
index cc0d7d1b50..0b6b155444 100644
--- a/support/make4ht/make4ht-doc.pdf
+++ b/support/make4ht/make4ht-doc.pdf
Binary files differ
diff --git a/support/make4ht/make4ht-htlatex.lua b/support/make4ht/make4ht-htlatex.lua
index f141070406..033b25b632 100644
--- a/support/make4ht/make4ht-htlatex.lua
+++ b/support/make4ht/make4ht-htlatex.lua
@@ -43,8 +43,8 @@ Make.testlogfile = testlogfile
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@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}{"..
diff --git a/support/make4ht/readme.tex b/support/make4ht/readme.tex
index 1938c98a0a..caf5e05966 100644
--- a/support/make4ht/readme.tex
+++ b/support/make4ht/readme.tex
@@ -531,7 +531,8 @@ One call to the TeX engine with special configuration for loading of the
\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 @@ 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[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.