我可以将MathJax集成到Python程序中吗? [英] Can I integrate MathJax into a Python program?
问题描述
这可能是一个愚蠢的问题,但是有可能将MathJax合并到Python代码中吗?很多时候,我希望程序输出看起来更整洁,老实说MathJax看起来很棒.
This might be a silly question, but is it possible to merge MathJax into Python code? Many times I've wished the program output would look more neat, and honestly MathJax looks awesome.
我知道MathJax运行在Javascript上,但我没有放弃希望.如果答案是否定的,是否可以使用一些简单的模块代替?
I know MathJax runs on Javascript, yet I have not given up hope. If the answer is no, are there some simple modules to use instead?
例如,如果:
1.234 / e^23 [and] (I^-)_(aq) +I _(2(s)) -> (I^-)_3(aq)
可以设置为:
,
那将是理想的.
推荐答案
我只能假定您可能想将某些内容输出到显示器以进行打印.因此,Python中的常见用法可能是Matplotlib(尽管Gnuplot是与python兼容的一个很好的选择). 如果使用Matplotlib创建空白图,则可以输入普通的普通LaTeX数学指令(与MathJax几乎相同):
I can only presume that maybe you want to output something to the display for printing. Hence the common usage in Python is probably Matplotlib (albeit Gnuplot is a good alternative that is python compatible). If you create a blank plot using Matplotlib then you can input normal plain LaTeX maths instructions (near identical to MathJax):
一个小例子:
import matplotlib
matplotlib.use('TkAgg')
import pylab
import matplotlib.pyplot as plt
from matplotlib import rc
plt.clf()
plt.rc('text', usetex=True)
plt.rcParams["figure.figsize"] = (8, 5)
plt.rc('font', **{'family':'serif', 'serif':['Computer Modern Roman'], 'size': 16})
plt.axis("off")
plt.text(0.5, 0.5, "Maths $e = mc^2$")
给出以下输出
可以简单地另存为.pdf,然后删除了屏幕快照的明显颗粒感.
which can trivially be saved, as a .pdf, and then the apparent graininess of my screenshot is removed.
这篇关于我可以将MathJax集成到Python程序中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!