# Can LuaTeX create HTML?

I heard that LuaTeX provides access to the internals of TeX. So, I have two questions in this regard:

• Is it possible to modify the output routine with LuaTeX so that HTML is produced instead of DVI or PDF?
• If possible, are there any projects aiming at this?
• The answers to your questions are: yes and yes. To be precise: ConTeXt MkIV (which is built on top of LuaTeX) can produce (X)HTML natively from ConTeXt source. I'm not aware of any LaTeX package to do such a thing, though. – mbork Feb 21 '14 at 15:19
• ConTeXt outputs XML. Most browswers display this XML, which can be styled using CSS, without problems. See Converting ConTeXt document to HTML for a demonstration. – Marco Feb 21 '14 at 15:24
• To add to what @Marco and @ mbork pointed out in their comments: Context does indeed produce XML out of the box, but it does not actuall need to “modify the output routine”. (That’s actually pretty obvious since HTML doesn’t have the concept of a page like TeX does.) Instead, the relevant structural commands are extended to tag regions of text by means of Luatex attributes, which doesn’t even require much effort since most user-level commands are derived from generic ones. – Philipp Gesang Feb 21 '14 at 18:04

As it is possible to access nodes created by \special commands, we can access tags inserted by tex4ht. Small proof of concept is lua4ht package.

Advantage is that it supports fontspec and unicode-math packages, which tex4ht doesn't support otherwise, the downside is that mathml production is broken, so it is produced as normal italic text in the sample. In theory, we can produce mathml directly from LuaTeX's math nodes, I've tried some exercises in this direction and it seemed doable.

Sample:

\documentclass{article}

\usepackage{fontspec}
\usepackage{unicode-math}

\begin{document}

\section{Font support}

Příliš \textit{žluťoučký kůň} úpěl \textsc{ďábelské ódy}. A \textbf{další text}

\section{Math}

$\forall x \in X, \quad \exists y \leq \epsilon$

\section{Tables}

\begin{tabular}{ll}
hello & world\\
hello & again\\
\end{tabular}
\end{document}

we need also small config file, hej.cfg:

\Preamble{xhtml}

\Configure{textit}{\HCode{<em>}}{\HCode{</em>}}
\Configure{textbf}{\HCode{<strong>}}{\HCode{</strong>}}
\Configure{textsc}{\HCode{<span class="sc">}}{\HCode{</span>}}
\Configure{\$}{\HCode{<span class="inline-math">}}{\HCode{</span>}}{}
\begin{document}
\Css{.sc{font-variant: small-caps;}}
\Css{.inline-math{font-style:italic;}}
\EndPreamble

compile with:

make4ht -b lua4ht -um draft -c hej.cfg  sample.tex  "new-accents"

and the result:

<h3 class="sectionHead"><span class="titlemark">1 </span> <a
id="x1-10001"></a>Font support</h3> <!--l. 10--><p class="noindent" >Příliš <em>žluťoučký kůň</em> úpěl <span class="sc">ďábelské ódy</span>. A <strong>další text</strong>  </p><!--l. 12--><p class="noindent" > </p><h3 class="sectionHead"><span class="titlemark">2 </span> <a
id="x1-20002"></a>Math</h3> <!--l. 14--><p class="noindent" ><span class="inline-math">∀𝑥∈𝑋, ∃𝑦≤𝜖</span>  </p><!--l. 16--><p class="noindent" > </p><h3 class="sectionHead"><span class="titlemark">3 </span> <a
id="x1-30003"></a>Tables</h3><div class="tabular"> <table id="TBL-1" class="tabular"