tex4ebook で epub および mobi 形式を生成するときにエラーが発生する

tex4ebook で epub および mobi 形式を生成するときにエラーが発生する

これは私が質問した内容の続きですここそしてここセットアップ ファイルは @Michal.h21 によって提供されています。

tex4ebook を使用して epub および mobi 出力を生成するときにエラーが発生します。

入力ファイル (sample.tex) は次のとおりです。

\documentclass[ebook,12pt,oneside,openany]{memoir}

\begin{filecontents}{\jobname.bib}
@book{Hiemenz,
author={Hiemenz},
title={Polymer Chemistry}
}
\end{filecontents}

\usepackage{lipsum}

\usepackage{storebox}
\newstorebox{\mybox}

\usepackage{xskak}
\usepackage{chess-workshop-symbols}
\newcommand\mychessboard[1][]{\chessboard[#1]}

\usepackage[backend=biber,hyperref=auto,backref=true]{biblatex}
\addbibresource{\jobname.bib}

\usepackage{imakeidx}

\makeindex[intoc=true,columns=1,noautomatic]

\usepackage[hyperindex=true]{hyperref}

\title{Book}
\author{Author}
\date{}

\begin{document}

\maketitle

\frontmatter

\tableofcontents \newpage

\mainmatter

\chapter{C1}

aword\index{aword}

\newchessgame

This is a chessboard.

\mychessboard

\storebox{\mybox}{\mychessboard}

This is a chessboard from storebox.

\usestorebox{\mybox}

Here comes a quotation \cite{Hiemenz}.

This is a chessboard from storebox.

\usestorebox{\mybox}

\newpage

\lipsum[1]

bword\index{bword}

\backmatter

\printbibliography \newpage
\printindex

\end{document}

設定ファイルは次のとおりです:

\RequirePackage{addfont4ht} % needed for skaknew font
%
% save the clearpage before it is redefined by tex4ht
%
\let\oldclrearpage\clearpage
%
% define macro for newpage insertion
%
\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}}
%
% new chessboard command
%
\renewcommand\mychessboard[1][]{\HCode{<div class="chessboard">}\Picture*{}\chessboard[#1]\EndPicture\HCode{</div>}}
%
\Preamble{xhtml}
%
% italic and bold
%
\Configure{textit}{\HCode{<span class="italic">}\NoFonts}{\EndNoFonts\HCode{</span>}}
\Configure{textbf}{\HCode{<span class="bold">}\NoFonts}{\EndNoFonts\HCode{</span>}}
\Css{.bold{font-weight:bold;}}
\Css{.italic{font-style:italic;}}
%
\catcode`\:=12
%
% enforce newpage
%
% define it for \newpage
%
\mypagebreak
\Css{.newpage{page-break-before:always;}}
%
% modify \Configure{BODY} so our configurations work on all extracted pages
%
\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}}
\Configure{@/BODY}{\global\let\clearpage\oldclrearpage\Configure{newpage}{}}
%
% skak fonts
%
\AddFontFace{SkakNewFigurine}{SkakNew-Figurine}{SkakNew-Figurine.woff}{}
\Css{.SkakNew-Figurine-{font-family:"SkakNewFigurine",sans-serif;}}
%\Css{.SkakNew-Figurine-{font-family:"SkakNewFigurine",serif;}}
%
\begin{document}
%
\EndPreamble

ビルド ファイルは次のとおりです。

local filter    = require "make4ht-filter"

local process = filter{"cleanspan", "fixligatures"}

local used_images = {}
Make:image("png$", function(par)
  local output = par.output
  if not used_images[output] then
    local command = "dvipng -bg Transparent -T tight -D 167 -o ${output}  -pp ${page} ${source}" % par
    print(command)
    used_images[output] = true
    os.execute(command)
  end
  return true
end)

Make:add("biber","biber ${input}")

Make:add("xindy", function(par)
  -- par.encoding  = par.encoding or "utf8"
  -- par.language = par.language or "english"
  par.idxfile = par.idxfile or par.input .. ".idx"
  local modules = par.modules or {}
  local t = {}
  for k,v in ipairs(modules) do
    t[#t+1] = "-M ".. v
  end
  par.moduleopt = table.concat(t, " ")
  local xindy_call = "xindy -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par
  print(xindy_call)
  return os.execute("xindy -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par)
end, {modules = {"texindy"}, language = "english", encoding = "utf8"})

if mode=="draft" then
  Make:htlatex {}
else
  Make:htlatex {}
  Make:biber {}
  -- xindymodule = Make.params["input"]
  Make:xindy {modules = {"sample"}}
  Make:htlatex {}
  Make:htlatex {}
  Make:htlatex {}
end

Make:match("html$",process)

epubcheck で epub をチェックすると、ログにエラーが表示されます。

Validating using EPUB version 2.0.1 rules.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(19,63): Error while parsing file 'element "div" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(36,32): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(37,32): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(41,36): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(41,63): Error while parsing file 'element "div" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(57,36): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(59,36): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(63,36): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(63,63): Error while parsing file 'element "div" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(80,25): Error while parsing file 'element "div" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(84,32): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(100,36): Error while parsing file 'element "p" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(103,25): Error while parsing file 'element "div" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(107,25): Error while parsing file 'element "div" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(111,40): Error while parsing file 'element "div" not allowed here; expected the element end-tag, text or element "a", "abbr", "acronym", "applet", "b", "bdo", "big", "br", "cite", "code", "del", "dfn", "em", "i", "iframe", "img", "ins", "kbd", "map", "noscript", "ns:svg", "object", "q", "samp", "script", "small", "span", "strong", "sub", "sup", "tt" or "var" (with xmlns:ns="http://www.w3.org/2000/svg")'.
FATAL(RSC-016): sample.epub/OEBPS/samplech1.html(113,3): Fatal Error while parsing file 'The element type "p" must be terminated by the matching end-tag "</p>".'.
ERROR(RSC-005): sample.epub/OEBPS/samplech1.html(-1,-1): Error while parsing file 'The element type "p" must be terminated by the matching end-tag "</p>".'.
FATAL(RSC-016): sample.epub/OEBPS/sample-1.svg(1,1): Fatal Error while parsing file 'Premature end of file.'.
ERROR(RSC-005): sample.epub/OEBPS/sample-1.svg(-1,-1): Error while parsing file 'Premature end of file.'.
FATAL(RSC-016): sample.epub/OEBPS/sample-2.svg(1,1): Fatal Error while parsing file 'Premature end of file.'.
ERROR(RSC-005): sample.epub/OEBPS/sample-2.svg(-1,-1): Error while parsing file 'Premature end of file.'.
FATAL(RSC-016): sample.epub/OEBPS/sample-3.svg(1,1): Fatal Error while parsing file 'Premature end of file.'.
ERROR(RSC-005): sample.epub/OEBPS/sample-3.svg(-1,-1): Error while parsing file 'Premature end of file.'.
FATAL(RSC-016): sample.epub/OEBPS/sample-4.svg(1,1): Fatal Error while parsing file 'Premature end of file.'.
ERROR(RSC-005): sample.epub/OEBPS/sample-4.svg(-1,-1): Error while parsing file 'Premature end of file.'.
FATAL(RSC-016): sample.epub/OEBPS/sample-5.svg(1,1): Fatal Error while parsing file 'Premature end of file.'.
ERROR(RSC-005): sample.epub/OEBPS/sample-5.svg(-1,-1): Error while parsing file 'Premature end of file.'.
FATAL(RSC-016): sample.epub/OEBPS/sample-6.svg(1,1): Fatal Error while parsing file 'Premature end of file.'.
ERROR(RSC-005): sample.epub/OEBPS/sample-6.svg(-1,-1): Error while parsing file 'Premature end of file.'.

Kindlegen を使用するとエラーも発生します:

*************************************************************
 Amazon kindlegen(Windows) V2.9 build 1029-0897292
 A command line e-book compiler
 Copyright Amazon.com and its Affiliates 2014
*************************************************************

Info(prcgen):I1047: Added metadata dc:Title        "Book"
Info(prcgen):I1047: Added metadata dc:Date         "2017-02-01T14:26:00Z"
Info(prcgen):I1047: Added metadata dc:Creator      "Author"
Info(prcgen):I1002: Parsing files  0000005
Warning(htmlprocessor):W28003: Value specified for CSS property in content is not supported by Kindle readers. Please refer Kindle Publishing Guidelines about usage of property: 'position: relative' in file: C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample.css
Warning(inputpreprocessor):W29004: Forcefully closed opened Tag: <p class="indent">
      in file: C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\samplech1.html     line: 0000035
Warning(inputpreprocessor):W29004: Forcefully closed opened Tag: <p class="indent">
      in file: C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\samplech1.html     line: 0000041
Warning(inputpreprocessor):W29004: Forcefully closed opened Tag: <p class="indent">
      in file: C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\samplech1.html     line: 0000056
Warning(inputpreprocessor):W29004: Forcefully closed opened Tag: <p class="indent">
      in file: C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\samplech1.html     line: 0000078
Warning(prcgen):W14010: media file not found  C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample-1.svg
Warning(prcgen):W14010: media file not found  C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample-2.svg
Warning(prcgen):W14010: media file not found  C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample-3.svg
Warning(prcgen):W14010: media file not found  C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample-4.svg
Warning(prcgen):W14010: media file not found  C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample-5.svg
Warning(prcgen):W14010: media file not found  C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample-6.svg
Info(prcgen):I1015: Building PRC file
Info(prcgen):I1006: Resolving hyperlinks
Info(prcgen):I1049: Building table of content     URL: C:\Users\User\AppData\Local\Temp\mbp_7E1_2_1_E_2A_3A_EF_2114_B00_1\OEBPS\sample.ncx
Warning(prcgen):W14016: Cover not specified
Info(pagemap):I8000: No Page map found in the book
Info(prcgen):I1045: Computing UNICODE ranges used in the book
Info(prcgen):I1046: Found UNICODE range: Basic Latin [20..7E]
Info(prcgen):I1017: Building PRC file, record count:   0000002
Info(prcgen):I1039: Final stats - text compressed to (in % of original size):  41.83%
Info(prcgen):I1040: The document identifier is: "Book"
Info(prcgen):I1041: The file format version is V6
Info(prcgen):I1031: Saving PRC file
Info(prcgen):I1033: PRC built with WARNINGS!
Info(prcgen):I1016: Building enhanced PRC file
Info(prcgen):I1007: Resolving mediaidlinks
Info(prcgen):I1011: Writing mediaidlinks
Info(prcgen):I1009: Resolving guide items
Info(prcgen):I1017: Building PRC file, record count:   0000006
Info(prcgen):I1039: Final stats - text compressed to (in % of original size):  36.92%
Info(prcgen):I1041: The file format version is V8
Info(prcgen):I1032: PRC built successfully
Info(prcgen):I15000:  Approximate Standard Mobi Deliverable file size :   0000125KB
Info(prcgen):I15001:  Approximate KF8 Deliverable file size :   0000139KB
Info(prcgen):I1037: Mobi file built with WARNINGS!

Calibre は両方のバージョンを問題なく表示できます。

これらのエラーを修正する方法はありますか、それとも無視してもいいのでしょうか?

ありがとう。

答え1

問題には主に 2 つの原因があります。1 つ目は、chesboardパッケージが Tikz を使用してチェス ボードに何かを描画し、壊れた SVG 画像を生成することです。2 つ目は、\usestorebox おそらく他のいくつかの構成によって HTML に間違った段落が生成されることです。

SVG 画像を無効にするのは簡単です。図面を生成するために別の Tikz バックエンドを使用するだけです。パッケージ\usepackage{xskak}をロードする次のコードを の前に追加します。chessboard

\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvips.def}
\fi

間違った段落タグを処理するには、次の変更された.cfgファイルを試してください。

\RequirePackage{addfont4ht} % needed for skaknew font
%
% save the clearpage before it is redefined by tex4ht
%
\let\oldclrearpage\clearpage
%
% define macro for newpage insertion
%
\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}}
%
% new chessboard command
%
\renewcommand\mychessboard[1][]{\ifvmode\IgnorePar\fi\EndP\HtmlParOff\HCode{<div class="chessboard">}\Picture*{}\chessboard[#1]\EndPicture\HCode{</div>}\HtmlParOn}
\let\tmpusavebox\usestorebox
\renewcommand\usestorebox[1]{\ifvmode\IgnorePar\fi\EndP\HtmlParOff\tmpusavebox{#1}\HtmlParOn\ifvmode\IgnorePar\fi\par\EndP\HCode{ }}

%
\Preamble{xhtml}
%
% italic and bold
%
\Configure{textit}{\HCode{<span class="italic">}\NoFonts}{\EndNoFonts\HCode{</span>}}
\Configure{textbf}{\HCode{<span class="bold">}\NoFonts}{\EndNoFonts\HCode{</span>}}
\Css{.bold{font-weight:bold;}}
\Css{.italic{font-style:italic;}}
%
\catcode`\:=12
%
% enforce newpage
%
% define it for \newpage
%
\mypagebreak
\Css{.newpage{page-break-before:always;}}
%
% modify \Configure{BODY} so our configurations work on all extracted pages
%
\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}\HtmlParOn}
\Configure{@/BODY}{\global\let\clearpage\oldclrearpage\Configure{newpage}{}\HtmlParOff}
%
% skak fonts
%
\AddFontFace{SkakNewFigurine}{SkakNew-Figurine}{SkakNew-Figurine.woff}{}
\Css{.SkakNew-Figurine-{font-family:"SkakNewFigurine",sans-serif;}}
%\Css{.SkakNew-Figurine-{font-family:"SkakNewFigurine",serif;}}
%
\begin{document}
%
\EndPreamble

主な違いは次のとおりです。

\renewcommand\mychessboard[1][]{\ifvmode\IgnorePar\fi\EndP\HtmlParOff\HCode{<div class="chessboard">}\Picture*{}\chessboard[#1]\EndPicture\HCode{</div>}\HtmlParOn}

チェス ボードに段落が含まれないようにするコマンドを\HtmlParOff追加しました。そうしないと、次の無効な HTML コードが表示されます。\HtmlParOn

<!--l. 56--><p class="indent" >
<!--l. 58--><p class="indent" >   This is a chessboard from storebox.
</p>

   </p>

</p>以下の後も間違ったタグを無効にする必要があります\usestorebox:

\let\tmpusavebox\usestorebox
\renewcommand\usestorebox[1]{\ifvmode\IgnorePar\fi\EndP\HtmlParOff\tmpusavebox{#1}\HtmlParOn\ifvmode\IgnorePar\fi\par\EndP\HCode{ }}

最後のワイルドコード:\HtmlParOn\ifvmode\IgnorePar\fi\par\EndP\HCode{ }保存されたボックスの後に新しい段落を含めることを要求します。少しわかりにくいことには気づきました :)

\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}\HtmlParOn}
\Configure{@/BODY}{\global\let\clearpage\oldclrearpage\Configure{newpage}{}\HtmlParOff}

これにより、タグの後の段落の組み込みが無効になり</html>\HtmlParOff再度使用できなくなります。

epubcheck今は幸せであるべき:

$ epubcheck sample.epub 
Validating against EPUB version 2.0 - custom validation
Validating using EPUB version 2.0 rules.
No errors or warnings detected.
epubcheck completed

関連情報