gpt4 book ai didi

python - 如何要求 sympy 不要将 bm 翻译成 boldsymbol?

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:23 26 4
gpt4 key购买 nike

我处于最终用户可以自己定义变量名的情况。

例如:名为“tbm_al”的变量是正确的。

为了将变量 pprint 为 latex ,我正在使用 sympy.latex 并期望有类似“tbm”和“al”作为索引的东西,但 bm 被翻译成粗体符号。

enter image description here

有没有办法让“tbm”和索引“al”都没有,t(粗体)和索引 al 也没有 tbm_al 作为字符串?

喜欢:

\begin{equation*}\begin{equation}{tbm}_{al}\end{equation}\end{equation*}

最佳答案

bm 的自动翻译由 Sympy latex printer 执行(sympy.printing.latex),特别是 bm 是在 sympy.printing 中声明的变量修饰符字典 modifier_dict 中的一个条目。 latex 。我在源代码中看不到在调用 latex(expr, **settings) 时禁用修饰符 dict 的方法;据我所知,在与 modifier_dict 字典相同的上下文中的任何地方都没有使用设置。

看看例如源代码中的函数 translate(s):

def translate(s):

Check for a modifier ending the string. If present, convert the modifier to latex and translate the rest recursively.

...

从这个函数的源代码来看,很明显修饰符字典检查(递归地)参数表达式中的所有条目。


剩下的选择是在您自己的 sympy.printing.latex 自定义源副本中手动修改名称修饰符 (modifier_dict)(或者,在原始的),通过简单地删除关键字 bm 的字典条目。当然,除非您想在其他地方使用 bm

另见:

关于python - 如何要求 sympy 不要将 bm 翻译成 boldsymbol?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34651710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com