1

This is a follow-up of my questions from here and here. The setup files have been provided by @Michal.h21.

I am getting errors when using tex4ebook and generating epub and mobi outputs.

The input file (sample.tex) is:

\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}

The config file is:

\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

The build file is:

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)

When I check the epub with epubcheck, the log shows errors:

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.'.

Using Kindlegen also gives errors:

*************************************************************
 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 can display both versions without problems.

Is there a way to fix these errors or can I just ignore them?

Thank you.

3

There are two main sources of problems - first is that chesboard package uses Tikz to draw some stuff to the chess board and it produces broken SVG images, the second issue is that \usestorebox and probably some other configurations produces wrong paragraphs in the HTML.

It is easy to disable the SVG images, we just need to use different Tikz backend to produce drawings. Add the following code before \usepackage{xskak}, which loads chessboard package:

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

To handle the wrong paragraph tags, try this modified .cfg file:

\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

The main differences are:

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

I've added \HtmlParOff and \HtmlParOn commands to disable inclusion of any paragraphs in the chess board. You would get the following invalid HTML code otherwise:

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

   </p>

We need to disable wrong </p> tags also after \usestorebox:

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

The wild code at the end: \HtmlParOn\ifvmode\IgnorePar\fi\par\EndP\HCode{ } requests inclusion of new paragraph after the stored box. I realize that it is a little bit cryptic :)

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

This disables inclusion of paragraphs after </html> tag, using \HtmlParOff again.

epubcheck should be happy now:

$ 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
  • Thank you very much for your updated files. They work for me too. I now only get a W28003 warning from kindlegen but I assume that this doesn't matter. Thanks again for all your work. – user41974 Feb 2 '17 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.