4

I want each chapter to start with an image and I want the text on the subsequent page. So, I defined my replacement for \chapter as follows:

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

Using either a \pagebreak or a \clearpage works just fine with pdflatex. But with htlatex TeX-SE.tex xhtml I run into problems.

  1. Using a pagebreak yields:

    TeX capacity exceeded, sorry [input stack size=5000]. \sch:ttl ->\includegraphics [ width=\linewidth , height=0.9\textheight , kee... l.85 ...le-image-a}{My 1st Story}{1st Author Name}

  2. Using a \clearpage yields:

    Incomplete \iffalse; all text was ignored after line ...

So, how do I put a page break there that is compatible with htlatex?

Possibly Related Question:

Code:

\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 Answer 1

3

tex4ht is quite sensitive on things which are written to toc (and because it uses own configurable mechanism for controlling which sectioning commands should be printed in toc, even starred commands are saved), so you need to be careful in what you use. easy solution is to use normal chapter with optional parameter:

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

generated

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

But, as you don't want chapter heading and I would also make things more configurable, so you could style particular parts of heading differently. move definition of \MyChapter to a .sty file, mychapter.sty for example:

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

and now you can make configuration file for this package, 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;}}

you need to redefine \MyChapter command to insert configurable hooks, which would be configurable with \Configure command later. These hooks are introduced with \NewConfigure{MyChapter}{4} and are named \a:MyChapter etc. You can now configure html tags inserted between arguments, in this example we use only third and fourth hooks to insert some styling for author names.

Updated example:

    <!--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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .