# Is there a LaTeX to HTML tool that supports the algorithm2e package?

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}

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Regarding your question, I really doubt there will be anything out there (though I would be glad to be proven wrong). It is very difficult for LaTeX to HTML converter to support packages other than by outright re-implementing that package entirely in the converter. There might be some tricks you can do with CSS and the HTML output, but that will depend on the converter. Alternatively, you could perhaps upload and embed the PDF. – JP-Ellis Feb 13 '16 at 11:10
• it would probably be useful if you provided a small test file then results of various possibilities are more likely to be tested. – David Carlisle Feb 13 '16 at 11:38
• Your code does not compile in pdflatex nor in lualatex? How did you compile it? – Nasser Feb 13 '16 at 12:02
• I'm using texstudio with TexLive. What error are you getting? – binarez Feb 13 '16 at 12:30
• I am using TL 2015. with lualatex, I get this error: !Mathematica graphics and with pdflatex, I get this error !Mathematica graphics I just copied what you have above. – Nasser Feb 13 '16 at 12:50

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: