shn*_*shn 6 python svg parsing latex mathml
是否有任何python代码允许采用乳胶代码(方程式)并将其解析为mathml或svg代码?将字符串(乳胶代码)作为参数并输出字符串(svg或mathml代码)的简单函数将是完美的.
PS.我发现这个http://svgkit.sourceforge.net/SVGLaTeX.html但它是一个基于Web的项目,不知道如何使用它.
编辑:或任何语言(非强制python),或至少一个exe文件,可以通过命令行简单地执行(不安装其他东西).
您可以在不安装任何东西的情况下执行此操作:
import urllib
import urllib2
def latex2svg(latexcode):
"""
Turn LaTeX string to an SVG formatted string using the online SVGKit
found at: http://svgkit.sourceforge.net/tests/latex_tests.html
"""
txdata = urllib.urlencode({"latex": latexcode})
url = "http://svgkit.sourceforge.net/cgi-bin/latex2svg.py"
req = urllib2.Request(url, txdata)
return urllib2.urlopen(req).read()
print latex2svg("2+2=4")
print latex2svg("\\frac{1}{2\\pi}")
Run Code Online (Sandbox Code Playgroud)
该脚本调用您提到的 SVGKit 服务器,该服务器负责将 LaTeX 转换为 SVG 的工作。它返回 SVG 文本(尝试一下)。
请注意,与任何依赖第三方 Web 应用程序的解决方案一样,
这假设您有可靠的互联网连接
它的性能取决于您的连接速度和服务器的速度
这依赖于第三方网站保持一致(如果他们将其删除,或者格式发生显着变化,则无需调整,这将不再有效)