summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-10-01 03:01:47 +0000
committerNorbert Preining <norbert@preining.info>2021-10-01 03:01:47 +0000
commit569e4d488d3398f8ed12807dd67e2b301b7447d5 (patch)
treeb0649aad82d5811ce9251e770edd9a1c94b71f0f /support
parentc0e66330261a0098e8041d4cc1428666ef598c30 (diff)
CTAN sync 202110010301
Diffstat (limited to 'support')
-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
-rw-r--r--support/tex4ebook/README7
-rw-r--r--support/tex4ebook/changelog.tex29
-rw-r--r--support/tex4ebook/readme.tex8
-rwxr-xr-xsupport/tex4ebook/tex4ebook2
-rw-r--r--support/tex4ebook/tex4ebook-doc.pdfbin83506 -> 84685 bytes
-rw-r--r--support/tex4ebook/tex4ebook-exec_azw.lua17
-rw-r--r--support/tex4ebook/tex4ebook-exec_azw3.lua20
-rw-r--r--support/tex4ebook/tex4ebook-exec_mobi.lua38
-rw-r--r--support/tex4ebook/tex4ebook.4ht29
20 files changed, 348 insertions, 35 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.
diff --git a/support/tex4ebook/README b/support/tex4ebook/README
index f87bd02f42..d19ca44e1b 100644
--- a/support/tex4ebook/README
+++ b/support/tex4ebook/README
@@ -297,6 +297,13 @@ See the `make4ht` documentation for an example and more information.
# Troubleshooting
+## Kindle formats
+
+`tex4ebook` uses `kindlegen` command for the conversion to Kindle formats (`mobi`,
+`azw` and `azw3`). Unfortunatelly, Amazon discontinued this command, so we use
+also `ebook-convert` provided by Calibre if `kindlegen` fails.
+
+
## Fixed layout EPUB
The basic support for the Fixed layout EPUB 3 can be enabled using the following configurations:
diff --git a/support/tex4ebook/changelog.tex b/support/tex4ebook/changelog.tex
index f415f81c8c..8c9445b910 100644
--- a/support/tex4ebook/changelog.tex
+++ b/support/tex4ebook/changelog.tex
@@ -3,6 +3,35 @@
\begin{itemize}
\item
+ 2021/09/30
+
+ \begin{itemize}
+ \tightlist
+ \item
+ released version \texttt{0.3e}
+ \item
+ better detection if \texttt{kindlegen} was found.
+ \end{itemize}
+\item
+ 2021/09/23
+
+ \begin{itemize}
+ \tightlist
+ \item
+ use \texttt{ebook-convert} for convertsion to Kindle formats if
+ \texttt{kindlegen} fails.
+ \end{itemize}
+\item
+ 2021/08/22
+
+ \begin{itemize}
+ \tightlist
+ \item
+ fixed
+ \href{https://tex.stackexchange.com/a/611611/2891}{cross-referencing
+ issue} related to unnumbered equations.
+ \end{itemize}
+\item
2021/07/26
\begin{itemize}
diff --git a/support/tex4ebook/readme.tex b/support/tex4ebook/readme.tex
index 428ac6c68c..99853b4d39 100644
--- a/support/tex4ebook/readme.tex
+++ b/support/tex4ebook/readme.tex
@@ -352,6 +352,14 @@ information.
\hypertarget{troubleshooting}{%
\section{Troubleshooting}\label{troubleshooting}}
+\hypertarget{kindle-formats}{%
+\subsection{Kindle formats}\label{kindle-formats}}
+
+\texttt{tex4ebook} uses \texttt{kindlegen} command for the conversion to
+Kindle formats (\texttt{mobi}, \texttt{azw} and \texttt{azw3}).
+Unfortunatelly, Amazon discontinued this command, so we use also
+\texttt{ebook-convert} provided by Calibre if \texttt{kindlegen} fails.
+
\hypertarget{fixed-layout-epub}{%
\subsection{Fixed layout EPUB}\label{fixed-layout-epub}}
diff --git a/support/tex4ebook/tex4ebook b/support/tex4ebook/tex4ebook
index 2b2b38b113..5c6aca5546 100755
--- a/support/tex4ebook/tex4ebook
+++ b/support/tex4ebook/tex4ebook
@@ -67,7 +67,7 @@ else
end
if args.version then
- print "tex4ebook v0.3d"
+ print "tex4ebook v0.3e"
return
end
diff --git a/support/tex4ebook/tex4ebook-doc.pdf b/support/tex4ebook/tex4ebook-doc.pdf
index 170a8fc4f1..62a87cd250 100644
--- a/support/tex4ebook/tex4ebook-doc.pdf
+++ b/support/tex4ebook/tex4ebook-doc.pdf
Binary files differ
diff --git a/support/tex4ebook/tex4ebook-exec_azw.lua b/support/tex4ebook/tex4ebook-exec_azw.lua
index 397292b648..ebf8d34144 100644
--- a/support/tex4ebook/tex4ebook-exec_azw.lua
+++ b/support/tex4ebook/tex4ebook-exec_azw.lua
@@ -1,5 +1,6 @@
module(...,package.seeall)
local eb = require("tex4ebook-exec_epub")
+local mobi = require("tex4ebook-exec_mobi")
local ebookutils = require("mkutils")
local log = logging.new "exec_azw"
@@ -19,13 +20,15 @@ function writeContainer()
-- find the azw filename
local azwfile = eb.outputfile:gsub("epub$", "azw")
local azwdist = eb.destdir .. azwfile
- local command = "kindlegen " .. epubpath .. " -o " .. azwfile
- log:info("Pack azw ".. command)
- local status, output = ebookutils.execute(command)
- -- copy the azw file to the destination directory
- -- the destination directory will be created by the epub writer, so it is possible to use
- -- the cp function which doesn't try to create directory
- ebookutils.cp(eb.basedir .. "/" .. azwfile, azwdist)
+ local status = mobi.kindlegen(epubpath, azwfile)
+ if status then
+ -- copy the azw file to the destination directory
+ -- the destination directory will be created by the epub writer, so it is possible to use
+ -- the cp function which doesn't try to create directory
+ if azwfile ~= azwdist then
+ ebookutils.cp(azwfile, azwdist)
+ end
+ end
return ret
end
diff --git a/support/tex4ebook/tex4ebook-exec_azw3.lua b/support/tex4ebook/tex4ebook-exec_azw3.lua
index 33e8a1182c..36c537f7ee 100644
--- a/support/tex4ebook/tex4ebook-exec_azw3.lua
+++ b/support/tex4ebook/tex4ebook-exec_azw3.lua
@@ -1,5 +1,6 @@
module(...,package.seeall)
local eb = require("tex4ebook-exec_epub")
+local mobi = require("tex4ebook-exec_mobi")
local ebookutils = require("mkutils")
local log = logging.new "exec_azw"
@@ -19,13 +20,18 @@ function writeContainer()
-- find the azw filename
local azwfile = eb.outputfile:gsub("epub$", "azw3")
local azwdist = eb.destdir .. azwfile
- local command = "kindlegen " .. epubpath .. " -o " .. azwfile
- log:info("Pack azw ".. command)
- local status, output = ebookutils.execute(command)
- -- copy the azw file to the destination directory
- -- the destination directory will be created by the epub writer, so it is possible to use
- -- the cp function which doesn't try to create directory
- ebookutils.cp(eb.basedir .. "/" .. azwfile, azwdist)
+ -- local command = "kindlegen " .. epubpath .. " -o " .. azwfile
+ -- log:info("Pack azw ".. command)
+ -- local status, output = ebookutils.execute(command)
+ local status = mobi.kindlegen(epubpath, azwfile)
+ if status then
+ -- copy the azw file to the destination directory
+ -- the destination directory will be created by the epub writer, so it is possible to use
+ -- the cp function which doesn't try to create directory
+ if azwfile ~= azwdist then
+ ebookutils.cp(azwfile, azwdist)
+ end
+ end
return ret
end
diff --git a/support/tex4ebook/tex4ebook-exec_mobi.lua b/support/tex4ebook/tex4ebook-exec_mobi.lua
index 92b70af71c..828baeba4a 100644
--- a/support/tex4ebook/tex4ebook-exec_mobi.lua
+++ b/support/tex4ebook/tex4ebook-exec_mobi.lua
@@ -11,22 +11,46 @@ function run(out,params)
return eb.run(out, params)
end
+function kindlegen(source, outputfile)
+ -- try to run kindlegen first
+ local command = "kindlegen " .. source .. " -o " .. outputfile
+ local status, output = ebookutils.execute(command)
+ log:debug("running kindlegen: " .. command, status)
+ -- if we cannot find kindlegen, try ebook-convert
+ if not output:match("Amazon") then
+ log:debug("kindlegen failed, trying epub-convert")
+ local ebookcmd = "ebook-convert " .. source .. " " .. outputfile
+ status, output = ebookutils.execute(ebookcmd)
+ if status > 0 then
+ log:error("Conversion to the output format failed")
+ log:error("Do you have either kindlegen or ebook-convert installed?")
+ return false
+ end
+ end
+ return true
+end
+
function writeContainer()
local ret = eb.writeContainer()
-- convert the epub file to mobi
local epubpath = eb.basedir .. "/" .. eb.outputfile
- log:info("Pack mobi "..os.execute("kindlegen " .. epubpath))
-- find the mobi filename
- local mobifile = epubpath:gsub("epub$", "mobi")
+ local mobifile = eb.outputfile:gsub("epub$", "mobi")
local mobidist = eb.destdir .. eb.outputfile:gsub("epub$", "mobi")
- -- copy the mobi file to the destination directory
- -- the destination directory will be created by the epub writer, so it is possible to use
- -- the cp function which doesn't try to create directory
- ebookutils.cp(mobifile, mobidist)
-
+ log:info("Convert Epub to mobi")
+ local status = kindlegen(epubpath, mobifile)
+ if status then
+ -- copy the mobi file to the destination directory
+ -- the destination directory will be created by the epub writer, so it is possible to use
+ -- the cp function which doesn't try to create directory
+ if mobifile ~= mobidist then
+ ebookutils.cp(mobifile, mobidist)
+ end
+ end
return ret
end
function clean()
return eb.clean()
end
+
diff --git a/support/tex4ebook/tex4ebook.4ht b/support/tex4ebook/tex4ebook.4ht
index 0132463917..7cd6ca39fe 100644
--- a/support/tex4ebook/tex4ebook.4ht
+++ b/support/tex4ebook/tex4ebook.4ht
@@ -318,7 +318,27 @@ href="#1" media-type="\a:CoverMimeType" />}}
}
% Get filename from tableofcontents anchor
-\def\ncx:hfile#1{\Ref{)F\Ref{)Q#1}F-}}
+\def\ncx:hfile#1{\LikeRef{)F\LikeRef{)Q#1}F-}}
+
+\ExplSyntaxOn
+% get filename for the section label
+% sometimes, TeX4ht returns list of file numbers for label. we must use just
+% the first number. we use the LaTeX 3 sequence list to get it.
+\tl_new:N\ncx:hfilename
+\def\ncx:newhfile#1{
+ \cs_if_exist_use:cTF{cw:)Q#1}{%
+ % cw:)Q#1 is csname of tag from the xref file. we convert it to sequence
+ \seq_set_from_clist:Nc\l_tmpa_seq{cw:)Q#1}
+ % get first item and put it to a token list
+ \seq_get_left:NN \l_tmpa_seq \l_tmpa_tl
+ % \RefFileNumber returns file name for the given file number
+ % \ncx:hfilename contains the filename for later use
+ \tl_set:Nx \ncx:hfilename {\RefFileNumber{\l_tmpa_tl}}
+ }{%
+ \tl_set:Nn \ncx:hfilename {nic}
+ }
+}
+\ExplSyntaxOff
% define toc levels which should be included in the NCX file
\NewConfigure{resettoclevels}{1}
@@ -349,7 +369,12 @@ href="#1" media-type="\a:CoverMimeType" />}}
% We need to configure TocLink
% in navmapsrc is link to the file and anchor, where chapter or section is located
\def\navmapsrc{}
- \Configure{TocLink}{\def\navmapsrc{\ncx:hfile{##2}\:sharp ##2}\opf:registerfilename{\ncx:hfile{##2}}##4}
+ \Configure{TocLink}{%
+ \ncx:newhfile{##2}
+ \def\navmapsrc{\ncx:hfilename\:sharp ##2}
+ \opf:registerfilename{\ncx:hfilename}
+ ##4
+ }
% Configuraion of entries
\expandafter\resettoclevels\expandafter{\a:resettoclevels}%
\confnavsections%