Beamer to HTML using make4ht

\documentclass{beamer}
\begin{document}
\begin{frame}
aaa
\end{frame}
\begin{frame}
bbb
\end{frame}
\end{document}


The above tex file is to be converted into html. I am using the following command

make4ht filename.tex


However it throws error. The basic question is "Is it possible to convert beamer presentation to html using make4ht?"

• An off-topic (but I think useful comment): pandoc is a powerful converter (at least for linux) that accepts tex files as input and output. It is not perfect ... But does a good job in many cases. – koleygr Mar 29 at 15:35

There is some support for Beamer in tex4ht, but it seems to be a little bit old - it is dated to 2003. It seems that it doesn't really work anymore, as Beamer changed substantially since that time. For example, it seems to support a slide environment instead of frame.

So it seems that we can just discard the current Beamer support and create a new one. Before it is added to the tex4ht sources, you can use the following beamer.4ht file:

\let\Hy@EveryPageAnchor\relax
\def\pgf@trimright@final{0pt}
\def\pgf@trimleft@final{0pt}
\let\origEndP\EndP
\AtBeginDocument{\def\EndP{\let\EndP\origEndP}\SaveEndP}
\endinput


It just fixes basic issues - spurious elements inserted for every page, some missing PGF commands and issues with paragraphs. This version will create just a plain document, without frames. If we want to keep the frames, we can configure them in a .cfg file:

\Preamble{xhtml}
\ConfigureEnv{beamer@frameslide}
{\ifvmode\IgnorePar\fi\EndP
\HCode{<section class="slide">}\RecallEndP\par\ShowPar
}
{\ifvmode\IgnorePar\fi\EndP \HCode{</section>}}
{} {}
\Css{section.slide {border:solid black 0.4pt;margin-bottom:1em;}}
\begin{document}
\EndPreamble


This will insert <section class="slide"> element for every frame.

Result:

<section class="slide">

<ul class="itemize1">
<li class="itemize">
first
</li>
<li class="itemize">
second</li></ul>
<!--l. 16--><p class="noindent" >aaa

</p>
</section>

<section class="slide">

<!--l. 19--><p class="noindent" >bbb

</p>
</section>