RSC-005 [EPUB3 Error Code] if \caption before \includegraphics
Kuan-Lun opened this issue · 1 comments
The following is an example. I use tex4ebook --format epub3 "main.tex"
.
% main.tex
\documentclass{article}
\usepackage{graphicx}
\title{Test}
\author{Test}
\date{2023-08-12}
\begin{document}
\maketitle
\tableofcontents
\begin{figure}
\caption{123}
\includegraphics{test.png}
\end{figure}
%%%% The following is fine.
% \begin{figure}
% \includegraphics{test.png}
% \caption{123}
% \end{figure}
\end{document}
The mainli1.xhtml
in the output file main.epub
is incorrect by EPUBCheck.
Validating using EPUB version 3.2 rules.
ERROR(RSC-005): [path]/main.epub/OEBPS/mainli1.xhtml(19,33): Error while parsing file: element "img" not allowed here; expected the element end-tagCheck finished with errors
Messages: 0 fatals / 1 error / 0 warnings / 0 infosEPUBCheck completed
It should be fixed in the development version of make4ht
. Until it is available in TeX Live (I am not sure when I will release the new version), you can use this build file:
local domfilter = require "make4ht-domfilter"
local process = domfilter {
function(dom)
for _, el in ipairs(dom:query_selector("figure > a")) do
local id = el:get_attribute "id"
if id then
local parent = el:get_parent()
if not parent:get_attribute("id") then
parent:set_attribute("id", id)
el:remove_node()
end
end
end
return dom
end
}
Make:match("html$", process)
Compile using
$ tex4ebook -e build.lua --format epub3 "main.tex".