我在复制其他人的工作以正确呈现 epub 格式的 LaTeX 文档时遇到了麻烦。具体来说,我在段落间距、居中和换页/清页方面遇到了麻烦。
.tex
文件
\documentclass{book}
\usepackage{lipsum}
\begin{document}
\parindent=7pt
\parskip=7pt
\title{\Huge\textbf{Latin Gibberish\normalsize}}
\author{Ralph}
\date{1440}
\maketitle
\begin{center}This stuff should be centered\end{center}
\lipsum[1]
\lipsum[1]
\newpage
\lipsum[1]
\clearpage
\end{document}
.cfg
文件
% 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>}}}
\Preamble{xhtml}
% define it for \newpage
\mypagebreak
\Css{.newpage{page-break-before:always;}}
% modify \Configure{BODY} so our confiurations work on all extracted pages
\catcode`\:=11
\append:def\a:BODY{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}}
\append:def\b:BODY{\gdef\clearpage{\relax}}
\catcode`\:=12
\begin{document}
\EndPreamble
以下是我尝试后得到的结果tex4ebook -c config.cfg test.tex
:
zip 错误:无需执行任何操作!(尝试:zip -qXr9D test.epub . -i OEBPS)打包 outputdir 3072 复制生成的 epub 复制:cp “test-epub/test.epub” “test.epub”
答案1
该问题是由.cfg
文件中的此行引起的:
\append:def\b:BODY{\gdef\clearpage{\relax}}
它\clearpage
在页面末尾重新定义HTML
(tex4ebook
为章节、部分等编写单独的页面),因为 spurious<div class="newpage"></div>
放在了后面</html>
。这会导致 HTML 文件无效。
问题在于,tex4ebook
在 LaTeX 钩子中调用特殊例程来写入元数据文件\AtEndDocument
。似乎此配置禁用了该钩子的执行,并且不会依次写入元数据文件。
更好的配置是重新定义\clearpage
回其原始含义并配置newpage
为不产生任何内容。更正后的.cfg
文件:
% 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>}}}
\Preamble{xhtml}
% define it for \newpage
\mypagebreak
\Css{.newpage{page-break-before:always;}}
% modify \Configure{BODY} so our confiurations work on all extracted pages
\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}}
\Configure{@/BODY}{\global\let\clearpage\oldclrearpage\Configure{newpage}{}}
\begin{document}
\EndPreamble
我发现\Configure{@BODY}
和\Configure{@/BODY}
可以用来在页面的开头和结尾插入材料,所以我们可以稍微简化配置。
生成的 HTML 文件:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"
>
<head> <title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<!-- charset=utf-8,epub,html,xhtml -->
<meta name="src" content="test.tex" />
<link rel="stylesheet" type="text/css" href="test.css" />
</head><body
>
<!--l. 4--><p class="noindent" >Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum
ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem.
Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet
tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra
ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,
accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
</p>
<div class="newpage"></div>
<!--l. 6--><p class="indent" > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris.
Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula
augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem.
Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet
tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra
ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,
accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
</p>
<div class="newpage"></div>
<!--l. 8--><p class="indent" > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris.
Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula
augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem.
Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet
tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra
ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,
accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
</p>
<div class="newpage"></div>
</body></html>
Calibre 中显示的更新示例: