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 withtex4ht
, using simple configurations. Save the following code asmycfg.cfg
: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}
requestsSVG
format for images, which is preferred format for textual pictures these days.tex4ht
doesn't know how to convert toSVG
by default, we must use build file formake4ht
(build system fortex4ht
). Save the following code asyourtexfilename.mk4
:this build file uses
dvisvgm
for conversion toSVG
. Compile with:the result: