[Tex/LaTex] LaTeX to HTML tool that supports the algorithm2e package

algorithm2ehtlatexhtmlpandoc

I'm a LaTeX beginner and I'm writing computer science documents. I carefully choose my algorithmic package considering the features I needed and that led me to pick algorithm2e (vlined and noend options, pretty much the only package capable of providing this unique combination). My algorithms will be using French keywords, but I doubt that is relevant to this question.

I will also need to publish my documents on the web. I have started looking around for tools to convert from LaTeX to HTML, but none of them seem to support the algorithm2e package properly (tried htlatex, pandoc and LaTeXML).

Is there a conversion tool that will convert LaTeX properly (found out that pandoc doesn't that good of a job with regular LaTeX) AND support algorithm2e?

EDIT: An example tex file of what I am trying to convert to HTML:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[letterpaper]{geometry}
\usepackage[francais]{babel}

\usepackage[linesnumbered,ruled,vlined,french,onelanguage]{algorithm2e}

\begin{document}

\section{Titre de section}

\subsection{Titre de sous-section}

This section provides a demo algorithm.

\begin{algorithm}
\DontPrintSemicolon
$max \gets a_1$\;
\For{$i \gets 2$ \textbf{to} $n$} {
  \If{$a_i > max$} {
    $max \gets a_i$\;
  }
}
\Return{$max$}\;
\caption{Test}
\label{algo:max}
\end{algorithm}

\end{document}

Best Answer

The structure created by algorithm would be quite hard to represent in HTML, it seems that more sensible approach is to convert it as image. Fortunately, we can convert any piece of code to image with tex4ht, using simple configurations. Save the following code as mycfg.cfg:

\Preamble{xhtml}

\ConfigureEnv{algorithm}{\Picture*{}}{\EndPicture}{}{}
\Configure{Picture}{.svg}
\begin{document}

\EndPreamble

this is configutation file for tex4ht. Important commands are \ConfigureEnv, which inserts code before and after configured environment, algorithm, in our case. Command \Picture*{} ... \EndPicture converts enclosed content to a picture. \Configure{Picture}{.svg} requests SVG format for images, which is preferred format for textual pictures these days.

tex4ht doesn't know how to convert to SVG by default, we must use build file for make4ht (build system for tex4ht). Save the following code as yourtexfilename.mk4:

if mode=="draft" then
  Make:htlatex{}
else
  Make:htlatex{}
  Make:htlatex{}
  Make:htlatex{}
end

Make:image("svg$","dvisvgm -n -p ${page} -c 1.4,1.4 -s ${source} > ${output}")

this build file uses dvisvgm for conversion to SVG. Compile with:

 make4ht -uc mycfg.cfg yourtexfilename.tex

the result:

enter image description here

Related Question