4

To start with MWE:

\documentclass{article}

\def\pgfsysdriver{pgfsys-tex4ht.def}
\usepackage{tikz}

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

This works to some degree with htlatex. However, subcaption-package gives warnings and I must press enter several times to get this compiled. Also, this could generate something like <TD>Small . . . <TD COLSPAN=2>Circles..., but does not.

As a second and easier example, \subpdfbookmark gives error with htlatex.

Is it possible to modify htlatex and/or packages and get this working properly?

  • 1
    have you tried compatibility=false? – cmhughes Jul 03 '13 at 15:17
  • At least \usepackage[compatibility=false]{caption} removes the errors but IMHO the result is not very satisfying... But when using subfig and \subfloat the result seems to be the same. –  Jul 03 '13 at 19:27

1 Answers1

4

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

  1. second svg image fails to render, because there is a </p> tag
  2. subcaptions are enclosed in tspan elements, these are svg, not html elements and shouldn't be in the document
  3. 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>
michal.h21
  • 50,697
  • Very interesting. This gives me errors, but in any case compiles and works as you said. I have Fedora Linux with TeXlive, and subcation.sty is from tex-caption-3.2e.svn25657-1.noarch.rpm. What version are you using? – Jori Mäntysalo Jul 04 '13 at 09:10
  • @JoriMäntysalo with texlive 2010, it compiled correctly, with texlive 2012, there is error caused with subcaption inclusion. I think this is some bug in tex4ht – michal.h21 Jul 04 '13 at 09:58
  • Thanks! Next I will try to understand how this system works... – Jori Mäntysalo Jul 04 '13 at 10:40