texlive[60663] trunk: tex4ebook (30sep21)

commits+karl at tug.org commits+karl at tug.org
Thu Sep 30 22:14:09 CEST 2021


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

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook
    trunk/Master/texmf-dist/doc/support/tex4ebook/README
    trunk/Master/texmf-dist/doc/support/tex4ebook/changelog.tex
    trunk/Master/texmf-dist/doc/support/tex4ebook/readme.tex
    trunk/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf
    trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook
    trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua
    trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua
    trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_mobi.lua
    trunk/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht

Modified: trunk/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook	2021-09-30 20:14:09 UTC (rev 60663)
@@ -67,7 +67,7 @@
 end
 
 if args.version then
-  print "tex4ebook v0.3d"
+  print "tex4ebook v0.3e"
   return 
 end
 

Modified: trunk/Master/texmf-dist/doc/support/tex4ebook/README
===================================================================
--- trunk/Master/texmf-dist/doc/support/tex4ebook/README	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/doc/support/tex4ebook/README	2021-09-30 20:14:09 UTC (rev 60663)
@@ -297,6 +297,13 @@
 
 # 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:

Modified: trunk/Master/texmf-dist/doc/support/tex4ebook/changelog.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/tex4ebook/changelog.tex	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/doc/support/tex4ebook/changelog.tex	2021-09-30 20:14:09 UTC (rev 60663)
@@ -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}

Modified: trunk/Master/texmf-dist/doc/support/tex4ebook/readme.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/tex4ebook/readme.tex	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/doc/support/tex4ebook/readme.tex	2021-09-30 20:14:09 UTC (rev 60663)
@@ -352,6 +352,14 @@
 \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}}
 

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

Modified: trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook
===================================================================
--- trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook	2021-09-30 20:14:09 UTC (rev 60663)
@@ -67,7 +67,7 @@
 end
 
 if args.version then
-  print "tex4ebook v0.3d"
+  print "tex4ebook v0.3e"
   return 
 end
 

Modified: trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw.lua	2021-09-30 20:14:09 UTC (rev 60663)
@@ -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 @@
   -- 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

Modified: trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_azw3.lua	2021-09-30 20:14:09 UTC (rev 60663)
@@ -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 @@
   -- 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

Modified: trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_mobi.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_mobi.lua	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_mobi.lua	2021-09-30 20:14:09 UTC (rev 60663)
@@ -11,19 +11,42 @@
 	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
 
@@ -30,3 +53,4 @@
 function clean()
 	return eb.clean()
 end
+

Modified: trunk/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht
===================================================================
--- trunk/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht	2021-09-30 20:13:53 UTC (rev 60662)
+++ trunk/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht	2021-09-30 20:14:09 UTC (rev 60663)
@@ -318,8 +318,28 @@
 }
 
 % 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}
 \Configure{resettoclevels}{part,chapter,section,subsection,subsubsection,paragraph}
@@ -349,7 +369,12 @@
  % 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%



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