且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Tex标记,如何使用Python在HTML中呈现?

更新时间:2023-12-05 21:19:04

您可以尝试结合使用TeX-to-DVI工具(例如 tex.latex2dvi pytex ),带有DVI图像工具(例如 dvipng ).要在服务器端实现此功能,您需要一个API端点,该端点必须以TeX代码作为输入并以图像作为输出.这样,您可以通过将数学公式的源指向具有相应参数的URL来将数学公式呈现为图像.这很复杂,但是好消息是 Google图表用于数学公式的API 已经提供了此类服务.

You could try combining a TeX-to-DVI tool (such as tex.latex2dvi or pytex) with a DVI-to-image tool (such as dvipng). To implement this on the server side, you would need an API endpoint that takes TeX code as input and serves an image as output. This way, you can render math formulas as images by pointing their source to that URL, with the corresponding parameters. This is quite complex, but the good news is that Google Chart API for math formulas already provides such service.

无论如何,我会考虑使用 MathML 在客户端呈现数学符号,因为所有主要的网络浏览器(Internet Explorer除外)都支持符合HTML5标准的此功能.或者仅包括MathStack,例如StackExchange(这也是客户端标记渲染).这似乎是最简单和跨平台的选择.

Anyway, I would consider using MathML to render math notation on the client side, since all major web browsers (except Internet Explorer) support this feature in compliance with HTML5 standards. Or just including Mathjax like StackExchange (this is client-side markup rendering too). This seems the most simple and cross-platform alternative.