I'm using tex4ebook to generate an epub. I want subfigures to be placed side-by-side with subcaptions below the subfigures. I came across a couple of issues and I'd appreciate any hints for how to resolve them.
How do I get side-by-side subfigures?
I used recommendations in the answers to these questions to configure and provide css for figures and subfigures: htlatex and subfigures
htlatex and subfigures Using subfigure with tex4ht
This is part of the result I got. The other part is a pair of subfigures that are identical except for the captions.
mwe.cfg
\Preamble{xhtml}
\ConfigureEnv{figure}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="figure">}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup
\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar
\par}
{}{}
\Css{div.caption{text-align:center;font-size:83\%;text-indent:0em;margin-left:2em;margin-right:2em;}}
\Css{div.figure{text-align:center;clear:both;overflow:auto;width:100\%;margin-bottom:1em;}}
\ConfigureEnv{subfigure}
{\ifvmode\IgnorePar\fi\EndP\HCode
{<div class="subfigure"\Hnewline>}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
{}{}
\Css{div.subfigure {text-align:center;display:inline-block; max-width:45\%;}}
\Css{.subfigure img{display:block; margin-left:auto;margin-right:auto;}}
\ConfigureEnv{subfigurecaption}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="subfigurecaption">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
{}{}
\Css{.subfigcaption {margin-top:1em;margin-left:1em;}}
\makeatletter
\DeclareGraphicsExtensions{.svg,.png}
\ExplSyntaxOn
\Configure{Gin-dim}
{style="width:\fp_eval:n{round(\Gin@req@width/\textwidth*100,2)}\%;max-height:\fp_eval:n{round(\Gin@req@height/\textwidth*100,2)}\%;"}
\ExplSyntaxOff
\makeatother
\begin{document}
\EndPreamble
mwe.tex
\documentclass{book}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\include{included}
\begin{figure}[htbp]
\caption{A pair of frogs}
\centering
\begin{subfigure}[b]{0.45\textwidth}
\caption{Third Frog}
\label{fig:frogone}
\includegraphics[width=0.36\textwidth, keepaspectratio]{./images/simplefrog.png}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\caption{Fourth Frog}
\label{fig:frogtwo}
\includegraphics[width=0.36\textwidth, keepaspectratio]{./images/simplefrog.png}
\end{subfigure}
\end{figure}
included.tex
\begin{figure}[htbp]
\caption{Included frogs}
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[height=0.36\textwidth, keepaspectratio]{./images/simplefrog.svg}
\caption{First Frog}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[height=0.36\textwidth, keepaspectratio]{./images/simplefrog.svg}
\caption{Second Frog}
\end{subfigure}
\end{figure}
When I commented out \Css{.subfigure img{display:block; margin-left:auto;margin-right:auto;}}
the figures are scaled correctly, but the styling when the subfigures are inserted in the top-level .tex file is different from the styling when they're inserted with \include (the subcaption is beside the subfigure instead of being under it).
That leads me to my second question:
What can I do ensure the styling of subfigures doesn't change when they're inserted with \include?
Here's what the .epub looks like when I comment out the line I mentioned (css for subfigure img) in the .cfg:
mwe.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 (https://tug.org/tex4ht/)' />
<meta name='originator' content='TeX4ht (https://tug.org/tex4ht/)' />
<!-- charset=utf-8,epub,uni-html4,html,xhtml -->
<meta name='src' content='mwe.tex' />
<link type='text/css' rel='stylesheet' href='mwe.css' />
</head><body>
<div class='figure'>
<a id='x1-2r1'></a>
<a id='x1-3'></a>
<br /> <div class='caption'><span class='id'>
Figure 1: </span><span class='content'>Included frogs
</span></div><!-- tex4ht:label?: x1-2r -->
<div class='subfigure'><!-- l. 7 --><p class='noindent'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' /> <a id='x1-4r1'></a>
<span class='cmr-9'>(a) First Frog</span>
</p></div> <div class='subfigure'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' /> <a id='x1-5r2'></a>
<span class='cmr-9'>(b) Second Frog</span>
</div>
</div>
<div class='figure'>
<a id='x1-6r2'></a>
<a id='x1-7'></a>
<br /> <div class='caption'><span class='id'>
Figure 2: </span><span class='content'>A pair of frogs
</span></div><!-- tex4ht:label?: x1-6r -->
<div class='subfigure'><a id='x1-8r1'></a>
<!-- l. 14 --><p class='noindent'><span class='cmr-9'>(a) Third Frog</span>
</p><!-- l. 16 --><p class='noindent'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' />
</p></div> <div class='subfigure'><a id='x1-9r2'></a>
<span class='cmr-9'>(b) Fourth Frog</span>
<!-- l. 21 --><p class='noindent'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' />
</p></div>
</div>
</body></html>