python - 在 sympy 中设置 Latex 打印的全局设置

标签 python latex settings sympy

我想在我的代码中大量使用 sympy 中的 Latex() 命令。 不过,我希望每个乘法都用点打印,并且我通过在我想要 latex 形式的变量后面添加 mul_symbol= "dot"来实现这一点。

我可以将这些设置设为全局,这样我就不必每次都添加它吗? 这是文档:http://docs.sympy.org/dev/modules/printing.html#sympy.printing.latex.latex

最佳答案

默认设置位于类LatexPrinter的内部变量_default_settings中。您可以使用自己的设置创建 LatexPrinter 的新实例:

from sympy import *
from sympy.printing.latex import LatexPrinter
my_printer = LatexPrinter(settings={"mul_symbol": "dot"})
var('x y z')
print(my_printer.doprint(x*y+y*z)) 

但是编写一行函数要容易得多:

def my_latex(expr):
    return latex(expr, mul_symbol="dot")

print(my_latex(x*y+y*z))

关于python - 在 sympy 中设置 Latex 打印的全局设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42905515/

相关文章:

r - knitr+booktabs 包中不需要的空白

ios - iOS应用中的多个Settings.bundle

python - (初学者 Python)根据用户输入创建 if/else 语句?

python - 在 Linux 程序中嵌入 Python

latex - 对于 Sphinx,我需要对 "register" 'latexpdf' 做什么?

R 文档,如何在数学模式下,在院长方程中以粗体设置字符?

python - 修改中间件中的 Django 设置变量

c# - 在 Settings.setting 文件中添加新设置

python - 如何使用 boto3 将自定义 EC2 指标发送到 CloudWatch 仪表板?

Python:如何为 64 位 python 导入 32 位模块