在Mac OS X和TeX Live中使用matplotlib的TeX

13 投票
1 回答
12784 浏览
提问于 2025-04-16 18:05

我在我的Mac上尝试用matplotlib来渲染TeX,所以写了一个简单的Hello World代码。

import matplotlib.pyplot as plt
from matplotlib import rc

rc('text', usetex=True)
rc('font', family='serif')

plt.text(2,2,r"Hello World!")
plt.show()

运行这段代码后,我遇到了以下错误:

sh: latex: command not found
Exception in Tkinter callback
<... a long Traceback here ...>
RuntimeError: LaTeX was not able to process the following string:
'lp'
Here is the full report generated by LaTeX:

在最后一行之后,我没有看到任何完整的错误报告。总之,我觉得这可能是路径的问题。有没有什么建议可以帮我解决这个问题?我使用的是TeX Live 2010。

我尝试把/Library/TeX/Root/bin/universal-darwin添加到项目属性的全局Python路径中,但还是出现了同样的错误。

enter image description here

1 个回答

13

将来你可能想提一下你是在NetBeans这个软件里运行代码的。Python的路径不是$PATH,而是sys.path,这是Python加载代码的路径。你需要在你的Python代码里设置os.environ['PATH'];如果你在使用TeX Live,推荐的方式是用/usr/texbin来指向当前的TeX安装位置。

撰写回答