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?
  • 3
    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
  • 2
    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
  • 1
    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.





\section{Font support}

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


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


  hello & world\\
  hello & again\\

we need also small config file, hej.cfg:


\Configure{textsc}{\HCode{<span class="sc">}}{\HCode{</span>}}
\Configure{$}{\HCode{<span class="inline-math">}}{\HCode{</span>}}{}
\Css{.sc{font-variant: small-caps;}}

compile with:

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

and the result:

enter image description here

  <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" 
cellspacing="0" cellpadding="0"  
><colgroup id="TBL-1-1g"><col 
id="TBL-1-1" /><col 
id="TBL-1-2" /></colgroup><tr  
 style="vertical-align:baseline;" id="TBL-1-1-"><td  style="white-space:nowrap; text-align:left;" id="TBL-1-1-1"  
class="td11">  hello  </td><td  style="white-space:nowrap; text-align:left;" id="TBL-1-1-2"  
class="td11">  world  </td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-2-"><td  style="white-space:nowrap; text-align:left;" id="TBL-1-2-1"  
class="td11">  hello  </td><td  style="white-space:nowrap; text-align:left;" id="TBL-1-2-2"  
class="td11">  again  </td></tr><tr  
 style="vertical-align:baseline;" id="TBL-1-3-"><td  style="white-space:nowrap; text-align:left;" id="TBL-1-3-1"  
class="td11">   </td></tr></table> </div>  
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.