I have old version of subcaption, but your example fails even with pdflatex for me, saying you need to load package caption first. So fixed code looks this way:
\documentclass{article}
\def\pgfsysdriver{pgfsys-tex4ht.def}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\subcaptionbox{Small} { \tikz \draw (0cm,0cm) circle(5mm); }
\subcaptionbox{Big} { \tikz \draw (0cm,0cm) circle(20mm); }
\caption{Circles}
\end{figure}
\end{document}
Edit:
this compiles without error for me with0 texlive 2010, but with texlive 2012 using subcaption package with htlatex gives error, saying it is needed to include caption package with compatibility=false option. So you need to change your preamble to include this option with tex4ht run:
\documentclass{article}
\ifdefined\HCode
\usepackage[compatibility=false]{caption}
\def\pgfsysdriver{pgfsys-tex4ht.def}
\else
\usepackage[]{caption}
\fi
\usepackage{tikz}
\usepackage{subcaption}
note that also pgfsys-tex4ht.def is used only with tex4ht now.
Now there are three problems
- second svg image fails to render, because there is a
</p> tag
- subcaptions are enclosed in
tspan elements, these are svg, not html elements and shouldn't be in the document
- there is a lack of logical markup which could be styled using
css
so we need to configure tex4ht to output logical markup and as a consequence solve issues 1 and 2.
Standard way to configure a package for tex4ht is to provide file named packagename.4ht. So subcaption.4ht in our case:
\NewConfigure{subcaptionbox}{3}
\renewcommand\subcaptionbox[2]{%
\a:subcaptionbox#2\b:subcaptionbox#1\c:subcaptionbox
}
\Configure{subcaptionbox}
{\ifvmode \IgnorePar\fi \EndP\HCode{<div class="subcaptionbox">\Hnewline<div class="image">}}
{\HCode{</div>\Hnewline<div class="subcaption">}}
{\HCode{</div>\Hnewline</div>\Hnewline}}
\Css{.subcaptionbox{display:inline-block;}}
\Css{.subcaption{text-align:center;}}
we declared three hooks which are used for inserting html tags with \NewConfigure, then redefined \subcaptionbox to use these hooks and with \Configure{subcaptionbox} we insert the html tags. Construct
\ifvmode \IgnorePar\fi \EndP
is there to solve problem with </p> tags on wrong positions. see this answer for more details.
You can play with \Css commands and add some more fancy formatting.
Code generated with this configuration:
<div class="subcaptionbox">
<div class="image"> <object data="subcap-1.svg" width="39.47014 " height="39.47014 " type="image/svg+xml"><p>SVG-Viewer needed.</p></object> </div>
<div class="subcaption">Small</div>
</div>
<div class="subcaptionbox">
<div class="image"> <object data="subcap-2.svg" width="153.28075 " height="153.28075 " type="image/svg+xml"><p>SVG-Viewer needed.</p></object> </div>
<div class="subcaption">Big</div>
</div>
compatibility=false? – cmhughes Jul 03 '13 at 15:17\usepackage[compatibility=false]{caption}removes the errors but IMHO the result is not very satisfying... But when usingsubfigand\subfloatthe result seems to be the same. – Jul 03 '13 at 19:27