Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?
share|improve this question
2  
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. –  phg Feb 21 '14 at 18:04
    
@phg Thanks. Could you turn your comment into an answer so that I can accept it? I'm also interested in the strategy. –  krnk Feb 23 '14 at 2:48

1 Answer 1

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:

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>  
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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