michal-h21 / tex4ebook

Converter from LaTeX to ebook formats (epub, mobi). Using tex4ht and texlua scripts.
314 stars 33 forks source link

floating figures not supported #58

Open DavidGriffith opened 5 years ago

DavidGriffith commented 5 years ago

I started using \begin{figure}[tp] to ensure that a page in the pdf is filled as much as possible before beginning a new page and displaying a full-page graphic. In the epub output, this text shuffling doesn't happen and horizontal lines are added right after the last line of text before \begin{figure}[tp] and after \end{figure}.

Also, \thisfloatpagestyle to do the equivalent of \thispagestyle within a floating figure causes tex4ebook to abort:

! Undefined control sequence.
\thisfloatpagestyle ... \csname \number \@currbox 
                                                  @float\endcsname {\thispag...
l.125 \thisfloatpagestyle{empty}
michal-h21 commented 5 years ago

There is not similar mechanism to LaTeX floats in HTML, so they are always placed where they appeared in the LaTeX source. But the appearance can be configured, see for example this answer.

Regarding the compilation error, try to save the following code as floatpag.4ht:

% this command doesn't make sense in HTML anyway
\renewcommand\thisfloatpagestyle[1]{}
\Hinput{floatpag}
\endinput
DavidGriffith commented 5 years ago

Those horizontal lines still appear when I use a figure environment.


\documentclass[11pt]{article}%
\usepackage{float}
\begin{document}

This is my table

\begin{table}[H]
\centering
Foobar!
%\begin{tabular}[c]{|c|c|}\hline
%A & B \\\hline
%853.075 (sec) & 43.711 (sec)\\\hline
%14.218 (minutes) & 0.729 (minutes)\\\hline
%\end{tabular}
\end{table}

\begin{figure}[tp]
\centering
Hello World!
\end{figure}

my table is done    
\end{document}
michal-h21 commented 5 years ago

What about the following configuration:

\Preamble{xhtml}
\Css{div.caption{text-align:center;}}
\Configure{float}{\csname par\endcsname\ShowPar}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="float">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar}
\ConfigureEnv{figure}
{\IgnorePar\EndP\HCode{<div class="figure">\Hnewline}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup\IgnorePar\EndP\HCode{</div>}\par}
{}{}

\Css{div.float, div.figure{margin-left:auto;margin-right:auto;}}
\begin{document}
\EndPreamble

You will probably need to change the CSS for figures and floats for your needs.