多页章节标题似乎与 htlatex 不兼容

多页章节标题似乎与 htlatex 不兼容

我希望每个章节都以图片开始,并在下一页显示文本。因此,我定义了替换,\chapter如下所示:

\newcommand{\MyChapter}[3]{%
    % #1 = image
    % #2 = title
    % #3 = author
    \chapter*{%
        \includegraphics[
            width=\linewidth,
            height=0.9\textheight,
            keepaspectratio
            ]{#1}%
        %% How do I insert a page break here compatible with htlatex???
        \pagebreak% TeX capacity exceeded, sorry [input stack size=5000]
        %\clearpage%  <----  Incomplete \iffalse 
        #2  \normalfont\newline by  \newline#3%
    }%
    \addcontentsline{toc}{chapter}{#2 -- #3}
}%

使用\pagebreak或都\clearpage可以很好地与 配合使用pdflatex。但是使用 时htlatex TeX-SE.tex xhtml我遇到了问题。

  1. 使用pagebreak收益:

    TeX 容量超出,抱歉 [输入堆栈大小=5000]。 \sch:ttl ->\includegraphics [ width=\linewidth , height=0.9\textheight , kee... l.85 ...le-image-a}{我的第一个故事}{第一个作者姓名}

  2. 使用\clearpage收益:

    不完整 \iffalse;行后的所有文本均被忽略...

那么,如何在那里放置与之兼容的分页符htlatex

可能相关的问题:

代码:

\documentclass{book}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{mwe}
\usepackage{lipsum}
%\usepackage{fancyhdr}
\usepackage{etoolbox}
%\usepackage[colorlinks=true]{hyperref}

\newcommand{\MyChapter}[3]{%
    % #1 = image
    % #2 = title
    % #3 = author
    \chapter*{%
        \includegraphics[
            width=\linewidth,
            height=0.9\textheight,
            keepaspectratio
            ]{#1}%
        %% How do I insert a page break here compatible with htlatex???
        \pagebreak% TeX capacity exceeded, sorry [input stack size=5000]
        %\clearpage%  <----  Incomplete \iffalse 
        #2  \normalfont\newline by  \newline#3%
    }%
    \addcontentsline{toc}{chapter}{#2 -- #3}
}%

\AfterEndPreamble{%
    \setcounter{page}{1}%
    \pagenumbering{roman}%
    %\pagestyle{plain}%
    \tableofcontents%
    \cleardoublepage%
    \pagenumbering{arabic}%
    %\pagestyle{fancy}%
}%


\begin{document}
\MyChapter{example-image-a}{My 1st Story}{1st Author Name}
\lipsum[1-5]
\MyChapter{example-image-a}{My 2nd Story}{2nd Author Name}
\lipsum[1-10]
\MyChapter{example-image-a}{My 3nd Story}{3nd Author Name}
\lipsum[1-2]
\end{document}

答案1

tex4ht对于写入的内容非常敏感toc(并且因为它使用自己的可配置机制来控制应该打印哪些分段命令toc,所以即使带星号的命令也会被保存),所以你需要小心使用。简单的解决方案是使用带有可选参数的普通章节:

\newcommand{\MyChapter}[3]{%
    % #1 = image
    % #2 = title
    % #3 = author
    \chapter[#2 -- #3]{%
        \includegraphics[
            width=\linewidth,
            height=0.9\textheight,
            keepaspectratio
            ]{#1}%
        %% How do I insert a page break here compatible with htlatex???
        %\pagebreak% TeX capacity exceeded, sorry [input stack size=5000]
        \clearpage%  <----  Incomplete \iffalse 
        #2  \normalfont\newline by  \newline#3%
    }%
    %\addcontentsline{toc}{chapter}{#2 -- #3}
    \par
}%

生成

 <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-20001"></a><img 
src="sample0x.png" alt="PIC" class="graphics" width="345.00964pt" height="258.75723pt"  /><!--tex4ht:graphics  
name="sample0x.png" src="example-image-a.eps"  
-->    

   My 1st Story <br 
class="newline" />by <br 
class="newline" />1st Author Name</h2> 
<p class="noindent">Lorem ipsum...

但是,由于您不想要章节标题,我也希望让事情变得更加可配置,因此您可以以不同的方式设置标题的特定部分。将定义移动\MyChapter到文件中.stymychapter.sty例如:

\usepackage{graphicx}


\newcommand{\MyChapter}[3]{%
    % #1 = image
    % #2 = title
    % #3 = author
    \chapter*{%
        \includegraphics[
            width=\linewidth,
            height=0.9\textheight,
            keepaspectratio
            ]{#1}%
        %% How do I insert a page break here compatible with htlatex???
        %\pagebreak% TeX capacity exceeded, sorry [input stack size=5000]
        \clearpage%  <----  Incomplete \iffalse 
                #2  \normalfont\newline by  \newline#3%
    }%
    \par
    \addcontentsline{toc}{chapter}{#2 -- #3}
}%

现在你可以为这个包创建配置文件mychapter.4ht了:

\renewcommand\MyChapter[3]{%
\a:MyChapter%
\includegraphics{#1}
\b:MyChapter%
\chapter[#2 -- #3]{#2}
\c:MyChapter%
#3%
\d:MyChapter%
\par%
}

\NewConfigure{MyChapter}{4}
\Configure{MyChapter}{}{}{\HCode{<div class="chap-author">}by\Tg<span class="author-name">}{\Tg</span>\Tg</div>}

\Css{.chap-author{font-weight:bold}}
\Css{.author-name{display:block;}}

您需要重新定义\MyChapter命令以插入可配置的钩子,稍后可以使用\Configure命令进行配置。这些钩子通过 引入\NewConfigure{MyChapter}{4}并命名\a:MyChapter等。您现在可以配置在参数之间插入的 html 标记,在此示例中,我们仅使用第三和第四个钩子来插入一些作者姓名的样式。

更新示例:

    <!--l. 22--><p class="indent" >   <img 
src="sample0x.png" alt="PIC" class="graphics" width="321.2pt" height="240.9pt"  /><!--tex4ht:graphics  
name="sample0x.png" src="example-image-a.eps"  
-->

</p>
   <h2 class="likechapterHead"><a 
 id="x1-2000"></a>My 1st Story</h2> <div class="chap-author">by<span class="author-name">1st Author Name</span></div>
<a 
 id="Q1-1-3"></a>
<!--l. 23--><p class="noindent" >Lorem ipsum

在此处输入图片描述

相关内容