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 编写 Fortran 无格式文件 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
