Tex标记,如何用Python将其渲染为Html?
Tex 标记 支持最近已添加到以下内容Stack Exchange 站点:
这些站点使用客户端Mathjax 库以正确格式化向用户提交的公式。
添加此新功能后,StackExchange API 返回带有公式分隔的 JSON 问题/答案文本通过 $
char Tex 标记 (这里是一个例子)。
StackPrinter,基于此 API 构建,仅打印返回的文本,其中包含 可怕的结果。
我正在寻找一个服务器端 Python 库,它可以解析和转换 JSON 数据,以正确呈现 Html 中的 Tex 标记。
你知道有什么解决办法吗?
申请详情:
平台:Google App Engine
框架: webpy
The Tex markup support has been recently added to the following Stack Exchange sites:
These sites are using the client side Mathjax library to correctly format the submitted formulas to the user.
Since this new feature was added, the StackExchange API returns the JSON question/answers text with formulas delimited by the $
char Tex Markup (here an example).
StackPrinter, built on this API, merely prints the returned text full of $ with an orrible result.
I'm searching for a server side Python library that can parse and trasform the JSON Data to properly render the Tex Markup in Html.
Do you know any solution?
Application details:
Platform: Google App Engine
Framework: webpy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试结合 TeX 到 DVI 工具(例如 tex.latex2dvi 或 pytex)与 DVI 转图像工具(例如 dvipng)。要在服务器端实现此功能,您需要一个 API 端点,该端点将 TeX 代码作为输入并提供图像作为输出。这样,您可以通过将数学公式的源指向该 URL 并使用相应的参数,将数学公式呈现为图像。这相当复杂,但好消息是 Google 图表数学公式API已经提供了这样的服务。
无论如何,我会考虑使用 MathML 在客户端呈现数学符号,因为所有主要Web 浏览器(Internet Explorer 除外)支持此功能,符合 HTML5 标准。或者只是包括像 StackExchange 这样的 Mathjax(这也是客户端标记渲染)。这似乎是最简单且跨平台的替代方案。
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.
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.