Sympy/Ipython 什么时候自动下标系数显示?

When is Sympy/Ipython Automatically subscripting coefficients for display?

下面我展示了Sympy/IPython在显示a0的乳胶之前添加下标。我试图查看源代码,但我找不到这是在哪里完成的? 理想情况下,我想访问这个乳胶字符串变量来修改或至少停止这种行为,这样我就可以手动处理所有下标。

相比之下,变量 ana1 的行为很直接。 an的latex只是字符串而a1维护了我手动给它的下标

from sympy import *
a0, an, a1 = symbols('a0 an a_1')

from IPython.core.interactiveshell import InteractiveShell
display(InteractiveShell.instance().display_formatter.format(a0))
display(InteractiveShell.instance().display_formatter.format(an))
display(InteractiveShell.instance().display_formatter.format(a1))

print(latex(a0))
print(latex(an))
print(latex(a1),"\n")

print(str(a0))
print(str(an))
print(str(a1))

display(a0)
display(an)
display(a1)

示例表明我对此行为感到困惑

我可以创建一个变量 xh 其中 print(xh) 给出 'xh' 但 latex(xh) 给出 x_{h} (因此显示将产生一个下标)就像a1 以上。或者,我怎样才能阻止这种行为?如果我想要 a1latex(a1) 给出 a1 而不是 a_1 怎么办?

其他信息

IPython 7.20.0,SymPy 1.7.1,Python 3.8.8

我的上下文正在以编程方式处理大量 sympy 变量的左右下标,而这种自动行为正在阻碍。但是,我认为单独讨论上述行为是合理的。

编辑: 添加了 str()latex() 变量。添加了额外的部分,用一个例子来解释我的理解不足。

回答我自己的问题,我认为这种行为来自 split_super_sub()。该文档指出以下内容是“所有打印机通用的一些实用约定”的一部分。

在:

from sympy.printing.conventions import split_super_sub
print(split_super_sub("a0"))
print(split_super_sub("an"))

输出:

('a', [], ['0'])
('an', [], [])

编辑的额外注释: 就我而言,现在我可以在 init_printing(latex_printer= 旁边编写自定义 split_super_sub 和自定义 LatexPrinter 来更改代码中的打印行为