找回密码
 快速注册
搜索
查看: 68|回复: 8

TeX转换为HTML

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-5-9 04:40 |阅读模式
本帖最后由 hbghlyj 于 2022-8-31 10:12 编辑 利用HEVEA将tex转换为html
hevea.inria.fr/distri/hevea-2.35-manual.pdf
Assume that you have a file, a.tex, written in LaTeX, using the article, book or report style. Then, a translation is achieved by issuing the command:
     # hevea a.tex
Probably, you will get some warnings. If HEVEA does not crash, just ignore them for the moment (Section 4 explains how to correct errors).
If everything goes fine, this will produce a new file, a.html, which you can visualise through a HTML browser.



官网例子

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-9 04:44

利用TeX4ht将tex转换为html

本帖最后由 hbghlyj 于 2022-8-31 05:41 编辑 kodymirus.cz/tex4ht-doc/BasicTutorial.html#basic-tutorial
2.2 Basic Usage

Conversion is invoked using the make4ht command:

     $ make4ht filename.tex

Other conversions to and from (La)TeX

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-10 07:32

利用LaTeXMathJax将LaTeX转换为mathjax+html+css

math.chapman.edu/~jipsen/latexmathjax/index.html
<script src="http://math.chapman.edu/~jipsen/latexmathjax/latexmathjax.js"></script>

<link rel="stylesheet" type="text/css"
href="http://math.chapman.edu/~jipsen/latexmathjax/latexmathjax.css" />

LaTeXMathML: translating LaTeX math notation dynamically to Presentation MathML

maths.nottingham.ac.uk/plp/pmadw/lm.html

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-10 07:35
本帖最后由 hbghlyj 于 2022-8-30 22:36 编辑 对比一下:
$\overbrace{a+b+⋯+z}^{26}$
MathJax转换结果:
  1. <math xmlns="http://www.w3.org/1998/Math/MathML">
  2.   <mover>
  3.     <mrow data-mjx-texclass="OP">
  4.       <mover>
  5.         <mrow>
  6.           <mi>a</mi>
  7.           <mo>+</mo>
  8.           <mi>b</mi>
  9.           <mo>+</mo>
  10.           <mo>⋯</mo>
  11.           <mo>+</mo>
  12.           <mi>z</mi>
  13.         </mrow>
  14.         <mo>⏞</mo>
  15.       </mover>
  16.     </mrow>
  17.     <mrow data-mjx-texclass="ORD">
  18.       <mn>26</mn>
  19.     </mrow>
  20.   </mover>
  21. </math>
复制代码
LaTeXMathML转换结果:
ROctsEwT_o[1].png
  1. <math title="\overbrace{a+b+\cdots+z}^{26}">
  2.    <mstyle>
  3.       <mrow>
  4.          <mover>
  5.             <mover>
  6.                <mrow>
  7.                   <mi>a</mi>
  8.                   <mo>+</mo>
  9.                   <mi>b</mi>
  10.                   <mo>+</mo>
  11.                   <mo>⋯</mo>
  12.                   <mo>+</mo>
  13.                   <mi>z</mi>
  14.                </mrow>
  15.                <mo accent="true">⎴</mo>
  16.             </mover>
  17.             <mrow>
  18.                <mn>2</mn>
  19.                <mn>6</mn>
  20.             </mrow>
  21.          </mover>
  22.       </mrow>
  23.    </mstyle>
  24. </math>
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-5-10 07:50
TtM是一个C语言编写的TeX到MathML转换器。
TtM 将 Plain TeX 和 LaTeX 翻译成 HTML + MathML。
hutchinson.belmont.ma.us/tth/mml/
TtM 现在是免费的。

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-31 05:42
Making Compiler Design Relevant for Students who will (Most Likely) Never Design a Compiler
这篇文章讨论了《编译原理》除了设计编译器外的用途

《编译原理》是当今多数计算机本科课程的共同组成部分。然而,编译器设计已成为一个高度专业化的话题,很少的计算机专业的学生将来会从事编译器设计。本文认为,编译器设计课程中讨论的原则、技术和工具仍然适用于通常不被视为编译器设计的各种情况。应该强调编译器设计课程的内容的这种广泛的适用性,可以使它们与学生更相关。
Screenshot 2022-08-30 at 22-45-00 teaching_compilers.pdf.png
2.2 将 LaTeX 翻译成 HTML
LaTeX [2] 是一种排版系统,广泛用于文档格式化(至少在学术界); HTML 是一种标记语言,用于指定网页的外观。 虽然表面上相似,它们都描述了文档的外观,但两种语言具有非常不同的语法——各自语法的上下文无关语法片段如图 2 所示——并且它们的特征和优势有很大不同。
然而,使用 LaTeX 准备文档的作者可能希望通过将它们转换为 HTML 来创建网页。 为此,有几种工具可用于将 LaTeX 文档翻译成 HTML(例如,参见 [3, 5])。
此类翻译器通常按以下方式进行:
1. 使用上下文无关解析技术读入 LaTeX 文档。
2. 必要时构建文档部分的内部表示。
3. 处理 LaTeX 结构并输出相应的 HTML。

这里的步骤顺序与绘图工具或编译器的顺序有些不同,主要是因为在这种情况下源语言和目标语言在语义上更接近,从而大大简化了翻译过程。
尽管如此,还是有许多相似之处,主要是在最初的词法分析和解析阶段(上面的步骤(1))和最终的 HTML 生成(上面的步骤(3)),这实际上是通过递归树遍历来执行的.然而,翻译并非完全是微不足道的,因为我们必须处理处理 HTML 不支持的 LaTeX 特征的问题,例如数学符号、图片等。这通常通过使用相应结构的 GIF 或 JPEG 图像来完成。这需要为 LaTeX 构造构建适当的内部表示,然后将其转换为图像(上面的步骤(2));相应的编译器类比是语言特性的代码生成——例如面向对象语言中的继承和虚函数调用——目标体系结构不直接支持。
在亚利桑那大学的本科编译器设计课程中,第 0 项编程作业让学生使用 lex 和 yacc 在大约 1.5 周内实现从 LaTeX(一个子集)到 HTML(一个子集)的翻译器。
那时,大多数学生对 LaTeX 知之甚少,许多学生对 HTML 知之甚少,对 lex 和 yacc 也一无所知。作业的目标是双重的:首先,让学生熟悉 lex 和 yacc,为更传统的项目实现 C 子集的编译器做准备;其次,说明这些工具对其他翻译问题的适用性。
我们使用讨论会和在线教程让他们对 LaTeX 和 HTML 有足够的了解,以便学生知道他们在做什么。我们在学期末的课堂讨论中重新审视这个问题,因为他们更精通这些工具(lex 和 yacc);学生们常常似乎很惊讶和高兴地意识到,他们现在已经具备了为 LaTeX 的重要片段实现一个重要且实用的软件的能力,而且相当快速且无需大量努力。
2.2 Translating LaTeX to HTML
LaTeX [2] is a typesetting system that is widely used for document formatting (at least in academia); HTML is a markup language used for specifying the appearance of web pages on the Internet. While superficially similar in that they both describe the appearance of documents, the two languages have very different syntax—fragments of context-free grammars for the respective syntaxes are shown in Figure 2—and are considerably different in their features and strengths.
Nevertheless, authors who prepare documents using LaTeX may then want to create web pages from them by translating them to HTML. To this end, several tools are available for translating Latex documents to HTML (e.g., see [3, 5]).
Such translators typically proceed as follows:
1. Read in the LaTeX document using context-free parsing techniques.
2. Construct internal representations of portions of the document, as necessary.
3. Process the LaTeX constructs and output the corresponding HTML.

The sequence of steps here is somewhat different from that of a graph-drawing tool or a compiler, primarily because the source and target languages are semantically much closer in this case, simplifying the translation process considerably.
Nevertheless there are a number of similarities, primarily in the initial lexical analysis and parsing phase (step (1) above) and the final HTML generation (step (3) above), which is carried out by what is in effect a recursive tree walk. However, the translation is not entirely trivial, since we have to deal with the problem of handling LaTeX features, such as mathematical symbols, pictures, etc., that are not supported by HTML. This is typically done by resorting to GIF or JPEG images of the corresponding constructs. This requires the construction of an appropriate internal representation for the LaTeX construct and then transforming this to an image (step (2) above); the corresponding compiler analog is that of code generation for language features—such as inheritance and virtual function calls in an object-oriented language—that are not directly supported by the target architecture.
In the undergraduate compiler design course at the University of Arizona, the 0th programming assignment has the students use lex and yacc to implement, in roughly 1.5 weeks, a translator from (a subset of) LaTeX to (a subset of) HTML.
At that point, most students know very little about LaTeX, many don’t know a lot about HTML, and none of them know anything about lex and yacc. The goals of the assignment are twofold: first, to get the students acquainted with lex and yacc, in preparation for a more traditional project implementing a compiler for a subset of C; and second, to illustrate the applicability of these tools to other translation problems.
We use discussion sessions and on-line tutorials to give them just enough acquaintance with LaTeX and HTML so that the students know what they are doing. We revisit the problem in classroom discussions at the end of the term, when they are much better versed with these tools (lex and yacc); students often seem quite surprised and pleased to realize that they are now equipped to implement a nontrivial and practically useful piece of software, for a significant fragment of LaTeX, reasonably quickly and without a great deal of effort.

CS2121: The Implementation and Power of Programming Languages
How To Use TFPExpressionParser

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-31 06:02
itex2MML
itex Commands
itex2mml中的解析器将itex翻译成tex,然后使用程序“tth”将tex翻译成MathML。(twiki.org/cgi-bin/view/Support/SID-00428)
itex是WebTeX的扩充.

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-31 06:16
TUGboat, Volume 16 (1995), No. 2
From TeX to HTML and back,  Michel Goossens and Janne Saarela
ntg.nl/maps/15a/07.pdf
Abstract
Both LATEX and HTML are languages that can express the structure of a document, and similarities between these two systems are shown. A detailed study is made of the LaTeX2HTML program, written by Nikos Drakos, that is today the most complete utility for translating LATEX code into HTML, providing a quasi-automatic translation for most elements. A discussion of a few other tools for translating between HTML and LATEX concludes the article.

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-31 17:14

Lex and Yacc



Lex and yacc (now flex and bison) can be used to write a lexer and parser for such things as configuration files, trees in newick format, and so on. A basic tutorial is available here. There are also detailed manuals for flex and bison.

rajnitish / Latex-to-Html-Lex-Yacc (这个支持的指令多, 比较成熟)
mrazvan21 / latex-to-html-compiler-lex-yacc (这个支持的指令比较少)
StackOverflow上有一个相关的问题: https://stackoverflow.com/questions/68821393

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:21

Powered by Discuz!

× 快速回复 返回顶部 返回列表