summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts')
-rw-r--r--Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtsvg.lua42
-rw-r--r--Master/texmf-dist/scripts/make4ht/domfilters/make4ht-sectionid.lua5
-rw-r--r--Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.lua3
-rw-r--r--Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua8
-rw-r--r--Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua86
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/make4ht2
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/make4ht-htlatex.lua4
7 files changed, 144 insertions, 6 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtsvg.lua b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtsvg.lua
new file mode 100644
index 00000000000..453cf430f7f
--- /dev/null
+++ b/Master/texmf-dist/scripts/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/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-sectionid.lua b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-sectionid.lua
index c1629181bb0..4a1f522e6e8 100644
--- a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-sectionid.lua
+++ b/Master/texmf-dist/scripts/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/Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.lua b/Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.lua
index c7b3c46507a..f6102464392 100644
--- a/Master/texmf-dist/scripts/make4ht/filters/make4ht-mjcli.lua
+++ b/Master/texmf-dist/scripts/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/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua b/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua
index 969d47ecaaa..5620f9c8bb6 100644
--- a/Master/texmf-dist/scripts/make4ht/filters/make4ht-staticsite.lua
+++ b/Master/texmf-dist/scripts/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/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua b/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua
index 4d5d768ee75..257e597bb3a 100644
--- a/Master/texmf-dist/scripts/make4ht/formats/make4ht-odt.lua
+++ b/Master/texmf-dist/scripts/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/Master/texmf-dist/scripts/make4ht/make4ht b/Master/texmf-dist/scripts/make4ht/make4ht
index d2bf27194f6..1e7b0d73df0 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.3h"
+local version = "v0.3i"
mkparams.version_number = version
local args = mkparams.get_args()
diff --git a/Master/texmf-dist/scripts/make4ht/make4ht-htlatex.lua b/Master/texmf-dist/scripts/make4ht/make4ht-htlatex.lua
index f141070406b..033b25b6324 100755
--- a/Master/texmf-dist/scripts/make4ht/make4ht-htlatex.lua
+++ b/Master/texmf-dist/scripts/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}{"..