Converting latex code to Images (or other displayble format) with Python(使用 Python 将乳胶代码转换为图像(或其他可显示格式))
问题描述
我有一个正在使用的函数,它返回一串乳胶代码.我需要从中生成图像.我见过的大多数这样做的方法都建议通过 subprocess 模块调用外部应用程序,该模块将为我生成图像.
但是,管理层对此并不热衷,因为除了我们自己的软件之外,它还需要外部用户安装额外的软件,就我们的用户群而言,我们认为这不是一项简单的任务.
那么是否有任何 python 库可以完成将乳胶转换为可在 GUI 中显示的格式(例如图像文件)的任务?
SymPy 有一个内置的预览功能可以做到这一点.
expr = sin(sqrt(x**2 + 20)) + 1预览(expr,查看器='文件',文件名='output.png')
生成
有
I have a function I am consuming that returns a string of latex code. I need to generate an image from this. Most of the methods I have seen for doing so suggest calling an external application via say the subprocess module which will generate the image for me.
However, management is not keen on this as it will require external users to install additional software in addition to our own which, with our user base, is not something we can assume to be a simple task.
So are there any python libraries that will accomplish the task of taking latex into a format (such as an image file) which is displayable in a GUI?
SymPy has a builtin preview function that does this.
expr = sin(sqrt(x**2 + 20)) + 1
preview(expr, viewer='file', filename='output.png')
generates
There are lots of options to preview
to change the format of the output (for instance, if you don't like the Euler font you can set euler=False
).
preview
also accepts a LaTeX string instead of a SymPy expression if you have that
preview(r'$$int_0^1 e^x,dx$$', viewer='file', filename='test.png', euler=False)
这篇关于使用 Python 将乳胶代码转换为图像(或其他可显示格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Python 将乳胶代码转换为图像(或其他可显示格式)


基础教程推荐
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01