diff options
author | Karl Berry <karl@freefriends.org> | 2023-03-03 21:32:26 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-03-03 21:32:26 +0000 |
commit | 513808f5f9f5d4966d929007f07f7103ab0dfade (patch) | |
tree | 1f7dd8fbade04082ef23553227cea1d415c778c3 | |
parent | 27086b730dba4bb8a9f328d818fe67fa628560dd (diff) |
tex4ebook (3mar23) (branch)
git-svn-id: svn://tug.org/texlive/branches/branch2022.final@66333 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-x | Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook | 9 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/tex4ebook/README | 62 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/tex4ebook/changelog.tex | 89 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/tex4ebook/readme.tex | 89 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf | bin | 85759 -> 90419 bytes | |||
-rwxr-xr-x | Master/texmf-dist/scripts/tex4ebook/tex4ebook | 9 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub.lua | 49 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua | 4 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/tex4ebook/tex4ebook-epub3.4ht | 11 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht | 2 |
10 files changed, 277 insertions, 47 deletions
diff --git a/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook b/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook index 8f6c8aa3f73..0bde98c9e0c 100755 --- a/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook +++ b/Build/source/texk/texlive/linked_scripts/tex4ebook/tex4ebook @@ -43,7 +43,7 @@ tex4ebook [switches] filename ["tex4ht.sty op."] ["tex4ht op."] ["t4ht op"] ["la -j,--jobname (default nil) Set the jobname -l,--lua Use lualatex for document compilation -m,--mode (default default) Switch which can be used in the makefile - -r,--resolution (default 167) + -r,--resolution (default nil) This option is obsolete, use build files instead! -s,--shell-escape Enable shell escape in htlatex run -t,--tidy Run html tidy on html output. May result in wrong spacing! -x,--xetex Use xelatex for document compilation @@ -67,7 +67,7 @@ else end if args.version then - print "tex4ebook v0.3h" + print "tex4ebook v0.3i" return end @@ -150,6 +150,11 @@ local oldparams = { ,packages="\\RequirePackage{tex4ebook}" } +if oldparams.resolution~="nil" then + log:warning("The resolution parameter is deprecated. Please use a build file") + log:warning("See information about Make:image() command in Make4ht documenation") +end + -- extend params for k,v in pairs(oldparams) do params[k] = v diff --git a/Master/texmf-dist/doc/support/tex4ebook/README b/Master/texmf-dist/doc/support/tex4ebook/README index 8339341c51a..95c60088eeb 100644 --- a/Master/texmf-dist/doc/support/tex4ebook/README +++ b/Master/texmf-dist/doc/support/tex4ebook/README @@ -107,11 +107,6 @@ For example: values are `default` and `draft`. In `draft` mode, document is compiled only once, instead of three times. -`-r,--resolution` - -: Resolution of generated images, for example math. It should meet resolution - of target devices, which is usually about 167 ppi. - `-s,--shell-escape` : Enable shell escape in the `htlatex` run. This is necessary for the execution of the external @@ -119,7 +114,7 @@ For example: `-t,--tidy` -: process output html files with `HTML tidy` command^[It needs to be installed separately]. +: clean-up output HTML files using the `HTML tidy` command^[if it is available on your system]. `-x,--xetex` @@ -256,8 +251,26 @@ Remarks: equivalent HTML code needs to be inserted. `UTF8` is not recognized at that place. - `UTF8` characters may be used in the `OpfMetadata` sections. +## \TeX4ht options + +\TeX4ht supports lot of options, that change produced HTML code without need to +use configurations. Their list is available in the [\TeX4ht +documentation](https://www.kodymirus.cz/tex4ht-doc/texfourhtOptions.html). +You can pass options to `tex4ebook` in the argument that follows filename: + + tex4ebook filename.tex "option1,option2" + +Alternatively, they can be put in the `\Preamble` command in the config file: + + \Preamble{xhtml,option1,option2} + +### Options provided by `tex4ebook` +`no-cut` +: By default `tex4ebook` splits document to separate HTML pages on `\chapter` command when it is available. + Othervise, it splits on `\section`. This can be changed using the `\CutAt` command or numeric options, but + you need to use the `no-cut` option to prevent fatal error. ## Commands available in the config file @@ -279,13 +292,42 @@ Remarks: ## Build files `tex4ebook` uses `make4ht`^[https://github.com/michal-h21/make4ht] as a build -system. See `make4ht` documentation for details on build files. +system. It provides support for build files written in Lua. These build files +can be used to call additional commands, like Bib\TeX\ or Makeindex, post-process +generated HTML files, change the way how images are created, or to modify +parameters of the conversion. + +Sample build file can look like this: + + if mode=="draft" then + Make:htlatex {} + else + Make:htlatex {} + Make:htlatex {} + Make:htlatex {} + end + + Make:image("png$", + "dvipng -bg Transparent -T tight -o ${output} -D 170 -pp ${page} ${source}") + +The `mode` variable holds value of the `--mode` argument to `tex4ebook`. The `draft` +mode is used for faster compilation, it calls LaTeX only once. + +The `Make:image` function can configure handling of images created by extraction from the +DVI file. It can be complex math, TikZ or PSTricks pictures, and so on. The `${<name>}` +placeholders are filled by `tex4ebook` with parameters like current page number of +the image DVI file, or output image name. + +You can compile your document with a build file using the `-e` option: + + tex4ebook -m draft -e build.lua filename.tex + +See `make4ht` documentation for more details on configuration files. ## `.tex4ebook` configuration file -It is possible to globally modify the build settings using the configuration -file. New compilation commands can be added, extensions can be loaded or -disabled and settings can be set. +`tex4ebook` supports a default build file, which is loaded automatically +without need to use the `-e` option. ### Location diff --git a/Master/texmf-dist/doc/support/tex4ebook/changelog.tex b/Master/texmf-dist/doc/support/tex4ebook/changelog.tex index 7eaa4c85ec6..92ec689690e 100644 --- a/Master/texmf-dist/doc/support/tex4ebook/changelog.tex +++ b/Master/texmf-dist/doc/support/tex4ebook/changelog.tex @@ -3,6 +3,95 @@ \begin{itemize} \item + 2023/03/02 + + \begin{itemize} + \tightlist + \item + released verision \texttt{0.3i} + \item + check if file with TOC exists before processing. + \end{itemize} +\item + 2023/01/12 + + \begin{itemize} + \tightlist + \item + added all mimetypes supported in Epub. + \end{itemize} +\item + 2023/01/09 + + \begin{itemize} + \tightlist + \item + fixed handling of metadata for filenames with accented characters. + \end{itemize} +\item + 2022/12/15 + + \begin{itemize} + \tightlist + \item + use lower case file extensions for mimetype matching. + \end{itemize} +\item + 2022/12/01 + + \begin{itemize} + \tightlist + \item + set destinations for \texttt{\textbackslash{}label} used inside of + footnotes. + \item + fixed handling of multiple tables of contents in Epub 3. + \end{itemize} +\item + 2022/11/20 + + \begin{itemize} + \tightlist + \item + added support for the \texttt{fn-in} option in the Epub 3 output. + \end{itemize} +\item + 2022/03/29 + + \begin{itemize} + \tightlist + \item + fixed support for \TeX~filenames that contain dot. + \item + removed spurious comma that was introduced earlier. + \end{itemize} +\item + 2022/03/28 + + \begin{itemize} + \tightlist + \item + documented the \texttt{no-cut} option. + \end{itemize} +\item + 2022/02/23 + + \begin{itemize} + \tightlist + \item + extended the documentation about build files. + \item + deprecated the \texttt{-\/-resolution} CLI argument. + \end{itemize} +\item + 2022/02/22 + + \begin{itemize} + \tightlist + \item + print \texttt{\textbackslash{}subsubsection} in the Epub TOC. + \end{itemize} +\item 2022/02/18 \begin{itemize} diff --git a/Master/texmf-dist/doc/support/tex4ebook/readme.tex b/Master/texmf-dist/doc/support/tex4ebook/readme.tex index 52982d65c45..e144238178a 100644 --- a/Master/texmf-dist/doc/support/tex4ebook/readme.tex +++ b/Master/texmf-dist/doc/support/tex4ebook/readme.tex @@ -115,15 +115,12 @@ This set \texttt{mode} variable, accessible in the build file. Default supported values are \texttt{default} and \texttt{draft}. In \texttt{draft} mode, document is compiled only once, instead of three times. -\item[\texttt{-r,-\/-resolution}] -Resolution of generated images, for example math. It should meet -resolution of target devices, which is usually about 167 ppi. \item[\texttt{-s,-\/-shell-escape}] Enable shell escape in the \texttt{htlatex} run. This is necessary for the execution of the external commands from your source files. \item[\texttt{-t,-\/-tidy}] -process output html files with \texttt{HTML\ tidy} command\footnote{It - needs to be installed separately}. +clean-up output HTML files using the \texttt{HTML\ tidy} +command\footnote{if it is available on your system}. \item[\texttt{-x,-\/-xetex}] Use xelatex for document compilation \item[\texttt{-v,-\/-version}] @@ -304,6 +301,41 @@ Remarks: sections. \end{itemize} +\hypertarget{ht-options}{% +\subsection{\texorpdfstring{\TeX4ht +options}{4ht options}}\label{ht-options}} + +\TeX4ht supports lot of options, that change produced HTML code without +need to use configurations. Their list is available in the +\href{https://www.kodymirus.cz/tex4ht-doc/texfourhtOptions.html}{\TeX4ht +documentation}. You can pass options to \texttt{tex4ebook} in the +argument that follows filename: + +\begin{verbatim} +tex4ebook filename.tex "option1,option2" +\end{verbatim} + +Alternatively, they can be put in the \texttt{\textbackslash{}Preamble} +command in the config file: + +\begin{verbatim} +\Preamble{xhtml,option1,option2} +\end{verbatim} + +\hypertarget{options-provided-by-tex4ebook}{% +\subsubsection{\texorpdfstring{Options provided by +\texttt{tex4ebook}}{Options provided by tex4ebook}}\label{options-provided-by-tex4ebook}} + +\begin{description} +\item[\texttt{no-cut}] +By default \texttt{tex4ebook} splits document to separate HTML pages on +\texttt{\textbackslash{}chapter} command when it is available. +Othervise, it splits on \texttt{\textbackslash{}section}. This can be +changed using the \texttt{\textbackslash{}CutAt} command or numeric +options, but you need to use the \texttt{no-cut} option to prevent fatal +error. +\end{description} + \hypertarget{commands-available-in-the-config-file}{% \subsection{Commands available in the config file}\label{commands-available-in-the-config-file}} @@ -328,16 +360,53 @@ deprecated in \texttt{EPUB\ 3}. \subsection{Build files}\label{build-files}} \texttt{tex4ebook} uses \texttt{make4ht}\footnote{\url{https://github.com/michal-h21/make4ht}} -as a build system. See \texttt{make4ht} documentation for details on -build files. +as a build system. It provides support for build files written in Lua. +These build files can be used to call additional commands, like +Bib\TeX~or Makeindex, post-process generated HTML files, change the way +how images are created, or to modify parameters of the conversion. + +Sample build file can look like this: + +\begin{verbatim} +if mode=="draft" then + Make:htlatex {} +else + Make:htlatex {} + Make:htlatex {} + Make:htlatex {} +end + +Make:image("png$", +"dvipng -bg Transparent -T tight -o ${output} -D 170 -pp ${page} ${source}") +\end{verbatim} + +The \texttt{mode} variable holds value of the \texttt{-\/-mode} argument +to \texttt{tex4ebook}. The \texttt{draft} mode is used for faster +compilation, it calls LaTeX only once. + +The \texttt{Make:image} function can configure handling of images +created by extraction from the DVI file. It can be complex math, TikZ or +PSTricks pictures, and so on. The +\texttt{\$\{\textless{}name\textgreater{}\}} placeholders are filled by +\texttt{tex4ebook} with parameters like current page number of the image +DVI file, or output image name. + +You can compile your document with a build file using the \texttt{-e} +option: + +\begin{verbatim} +tex4ebook -m draft -e build.lua filename.tex +\end{verbatim} + +See \texttt{make4ht} documentation for more details on configuration +files. \hypertarget{tex4ebook-configuration-file}{% \subsection{\texorpdfstring{\texttt{.tex4ebook} configuration file}{.tex4ebook configuration file}}\label{tex4ebook-configuration-file}} -It is possible to globally modify the build settings using the -configuration file. New compilation commands can be added, extensions -can be loaded or disabled and settings can be set. +\texttt{tex4ebook} supports a default build file, which is loaded +automatically without need to use the \texttt{-e} option. \hypertarget{location}{% \subsubsection{Location}\label{location}} diff --git a/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf b/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf Binary files differindex 7e8386af7a7..bbc6b2da3fd 100644 --- a/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf +++ b/Master/texmf-dist/doc/support/tex4ebook/tex4ebook-doc.pdf diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook b/Master/texmf-dist/scripts/tex4ebook/tex4ebook index 8f6c8aa3f73..0bde98c9e0c 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook @@ -43,7 +43,7 @@ tex4ebook [switches] filename ["tex4ht.sty op."] ["tex4ht op."] ["t4ht op"] ["la -j,--jobname (default nil) Set the jobname -l,--lua Use lualatex for document compilation -m,--mode (default default) Switch which can be used in the makefile - -r,--resolution (default 167) + -r,--resolution (default nil) This option is obsolete, use build files instead! -s,--shell-escape Enable shell escape in htlatex run -t,--tidy Run html tidy on html output. May result in wrong spacing! -x,--xetex Use xelatex for document compilation @@ -67,7 +67,7 @@ else end if args.version then - print "tex4ebook v0.3h" + print "tex4ebook v0.3i" return end @@ -150,6 +150,11 @@ local oldparams = { ,packages="\\RequirePackage{tex4ebook}" } +if oldparams.resolution~="nil" then + log:warning("The resolution parameter is deprecated. Please use a build file") + log:warning("See information about Make:image() command in Make4ht documenation") +end + -- extend params for k,v in pairs(oldparams) do params[k] = v diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub.lua b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub.lua index 539cf930ab6..539e9b19ba9 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub.lua +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub.lua @@ -127,49 +127,63 @@ local mimetypes = { css = "text/css", png = "image/png", jpg = "image/jpeg", + jpeg = "image/jpeg", gif = "image/gif", svg = "image/svg+xml", html= "application/xhtml+xml", xhtml= "application/xhtml+xml", ncx = "application/x-dtbncx+xml", - otf = "application/opentype", - ttf = "application/truetype", + otf = "application/font-sfnt", + ttf = "application/font-sfnt", woff = "application/font-woff", + woff2 = "font/woff2", js = "text/javascript", mp3 = "audio/mpeg", - smil = "application/smil+xml" + mp4 = "audio/mp4", + avi = "video/x-msvideo", + mkv = "video/x-matroska", + smil = "application/smil+xml", + pls = "application/pls+xml" } function remove_empty_guide(content) return content:gsub("<guide>%s*</guide>","") end + + function make_opf() -- Join files content.opf and content-part2.opf -- make item record for every converted image local lg_item = function(item) -- Find mimetype and make item tag for each converted file in the lg file - local fname,ext = item:match("([%a%d%_%-]*)%p([%a%d]*)$") - local mimetype = mimetypes[ext] or "" - if mimetype == "" then log:info("Mimetype for "..ext.." is not registered"); return nil end + local fname,ext = item:match("([^%/^%.]*)%.([%a%d]*)$") + if not ext then return nil end + local lower_ext = string.lower(ext) + local mimetype = mimetypes[lower_ext] or "" + if mimetype == "" then log:info("Mimetype for the "..ext.." extension is not registered"); return nil end local dir_part = item:split("/") table.remove(dir_part,#dir_part) local id=table.concat(dir_part,"-")..fname.."_"..ext -- remove invalid characters from id start id = id:gsub("^[%.%-]*","") -- remove colons - id = id:gsub(":", "_") + id = id:gsub("[:%(%)]", "_") -- id cannot start by number, add trailing "x" character id = id:gsub("^([%d])", "x%1") return "<item id='"..id .. "' href='"..item.."' media-type='"..mimetype.."' />",id end local find_all_files= function(s,r) - local r = r or "([%a%d%_%-]*)%.([x]?html)" + -- find files that had been declared in the OPF file using \Configure{OpfMetadata} + local r = r or "(.*)%.([x]?html)" local files = {} - for i, ext in s:gmatch(r) do - --local i, ext = s:match(r)-- do - ext = ext or "true" - files[i] = ext + for item in s:gmatch("href=\"(.-)\"") do + local i, ext = item:match(r) + if i then + --local i, ext = s:match(r)-- do + ext = ext or "true" + files[item] = ext + end end return files end @@ -188,7 +202,8 @@ function make_opf() local h_second = io.open(opf_second_part,"r") local opf_complete = {} table.insert(opf_complete,h_first:read("*all")) - local used_html = find_all_files(opf_complete[1]) + -- we used to detect all declared HTML files, but this table wasn't used anymore, so I deprecate this use + -- local used_html = find_all_files(opf_complete[1]) -- local lg_file = ebookutils.parse_lg(outputfilename..".lg") -- The lg_file has been already loaded by make4ht, it doesn't make sense to load it again -- Furthermore, it is now possible to add new files from Lua build files @@ -196,12 +211,10 @@ function make_opf() local used_files = {} for _,filename in ipairs(lg_file["files"]) do -- we need to test the filenames in order to prevent duplicates - -- filenames are tested without paths, so there may be issues if - -- the same filename is used in different directories. Is that a problem? used_files[filename] = true end local outside_spine = {} - local all_used_files = find_all_files(opf_complete[1],"([%a%d%-%_]+%.[%a%d]+)") + local all_used_files = find_all_files(opf_complete[1],"(.+)%.(.+)") local used_paths = {} local used_ids = {} for _,k in ipairs(lg_file["files"]) do @@ -212,8 +225,6 @@ function make_opf() table.remove(parts,#parts) --table.insert(parts,1,"OEBPS") table.insert(parts,1,outputdir) - -- print("SSSSS "..fn.." ext .." .. ext) - --if string.find("jpg gif png", ext) and not all_used_files[k] then local item,id = lg_item(k) if item then local path = table.concat(parts) @@ -232,7 +243,7 @@ function make_opf() end if not used_ids[id] then ebookutils.copy(k, outputdir .. "/"..k) - if not all_used_files[fn] then + if not all_used_files[k] then table.insert(opf_complete,item) if allow_in_spine[ext] then table.insert(outside_spine,id) diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua index 328acaae375..bf66548e2cd 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook-exec_epub3.lua @@ -186,6 +186,10 @@ local function cleanTOC(content) if filename then filename = outputdir .. "/" .. filename local f = io.open(filename, "r") + if not f then + log:warning("Cannot open TOC file for clean-up: " .. filename) + return nil + end local t = f:read("*all") f:close() local tocdom = dom.parse(t) diff --git a/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook-epub3.4ht b/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook-epub3.4ht index 9d49b624e67..0e1bcd85db6 100644 --- a/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook-epub3.4ht +++ b/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook-epub3.4ht @@ -24,9 +24,10 @@ \Configure{toTocLink}{}{} }{\b:NavMap}{}{}{} %%%%%%%%%%% -\Configure{NavMap}{\ifvmode\IgnorePar\fi\EndP\boolfalse{tocnoempty}\HCode{<nav id="toc" epub:type="toc">\Hnewline<ol>}% +\newcount\:toccount +\Configure{NavMap}{\ifvmode\IgnorePar\fi\EndP\boolfalse{tocnoempty}\global\advance\:toccount by1\HCode{<nav id="toc\the\:toccount" \ifnum\:toccount<2 epub:type="toc"\fi>\Hnewline<ol>}% \opf:registerfilename{\FileName} -\opf:add:property{nav} +\ifnum\:toccount<2 \opf:add:property{nav}\fi }{\usetoclevels{part,appendix,chapter,section,subsection,subsubsection}% \ifbool{tocnoempty}{}{\HCode{<li><a href="\jobname.\:html">Document</a></li>}} \HCode{</ol></nav>}} @@ -76,6 +77,9 @@ % Structural elements +\:CheckOption{fn-in} +\if:Option +\else % Foootnote configuration for epub3 % Footnotes are printed directly after the paragraph they appeared in % footnotebox - configure box in which footnotes are printed @@ -91,7 +95,7 @@ \ifvoid\footnotebox\else\unvbox\footnotebox\fi% \IgnorePar% \bgroup% - \fnlink{}{fn\FNnum x\minipageNum}\Tg<p>% + \fnlink{}{fn\FNnum x\minipageNum}\Tg<p>\AnchorLabel% }{\EndNoFonts} {% \HCode{</p>\Hnewline} @@ -114,3 +118,4 @@ \Css{.footnote{font-size:small;}} \Css{.footnotes hr{width:30\%;margin:0 auto 0 0;}} +\fi diff --git a/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht b/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht index 8686c2932f5..ae550e9832c 100644 --- a/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht +++ b/Master/texmf-dist/tex/latex/tex4ebook/tex4ebook.4ht @@ -391,7 +391,7 @@ href="#1" media-type="\a:CoverMimeType" />}} \ncx:head% % Book title \ncx:title% -\tableofcontents[part,appendix,chapter,likechapter,appendixsec,section,likesection,appendixsubsec,subsection,likesubsection]% +\tableofcontents[part,appendix,chapter,likechapter,appendixsec,section,likesection,appendixsubsec,subsection,likesubsection,subsubsection,likesubsubsection]% %Hack to get close tag working \HCode{</ncx>}% \EndNoFonts |