Tex markup, how to render it in Html with Python?

你。 提交于 2019-12-21 18:34:48

问题


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

  • Mathematics
  • Statistical Analysis
  • Theoretical Computer Science

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


回答1:


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.



来源:https://stackoverflow.com/questions/4592501/tex-markup-how-to-render-it-in-html-with-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!