简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM