from sympy import Symbol
from sympy.printing.latex import LatexPrinter
from sympy.core.function import UndefinedFunction
class MyLatexPrinter(LatexPrinter):
def _print_Derivative(self, expr):
# Only print the shortened way for functions of symbols
function, *vars = expr.args
if not isinstance(type(function), UndefinedFunction) or not all(isinstance(i, Symbol) for i in vars):
return super()._print_Derivative(expr)
return r'%s_{%s}' % (self._print(Symbol(function.func.__name__)), ' '.join([self._print(i) for i in vars]))
1 回答
您可以继承
LatexPrinter
并定义自己的_print_Derivative
. Here是当前的实现 .也许是这样的
哪个像
要在Jupyter笔记本中使用它,请使用