LuaTeX 可以创建 HTML 吗?

LuaTeX 可以创建 HTML 吗?

我听说 LuaTeX 提供了对 TeX 内部结构的访问。因此,我在这方面有两个问题:

  • 是否可以使用 LuaTeX 修改输出例程以便生成 HTML 而不是 DVI 或 PDF?
  • 如果可能的话,有没有什么项目针对这一目标?

答案1

由于可以访问由\special命令创建的节点,因此我们可以访问由插入的标签tex4ht。小概念验证是lua4ht包裹。

优点是支持fontspecunicode-math打包,tex4ht其他方面都不支持,缺点是mathml制作不方便,所以在示例中制作成普通斜体文本。理论上,我们可以mathml直接从 LuaTeX 的数学节点制作,我尝试过这个方向的一些练习,似乎可行。

样本:

\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}

我们还需要小型配置文件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

编译:

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

结果:

在此处输入图片描述

  <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">∀

相关内容