Tex标记,如何使用Python在HTML中呈现? [英] Tex markup, how to render it in Html with Python?

查看:124
本文介绍了Tex标记,如何使用Python在HTML中呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tex标记支持最近已添加到以下Stack Exchange网站:

The Tex markup support has been recently added to the following Stack Exchange sites:

  • Mathematics
  • Statistical Analysis
  • Theoretical Computer Science

这些网站正在使用客户端 Mathjax 库来正确格式化提交的格式给用户的公式.

These sites are using the client side Mathjax library to correctly format the submitted formulas to the user.

由于添加了此新功能, StackExchange API 返回JSON问题/答案文本其公式以$ char Tex标记( StackPrinter 仅使用

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.

我正在寻找一个服务器端Python库,该库可以解析和转换JSON数据以正确地在HTML中呈现Tex标记.
你知道有什么解决办法吗?

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?

应用程序详细信息:
平台:
Google App Engine
框架: webpy

Application details:
Platform: Google App Engine
Framework: webpy

推荐答案

您可以尝试结合使用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.

这篇关于Tex标记,如何使用Python在HTML中呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆