_repr_latex_ 方法在 Jupyter / IPython notebook 中不再有效

_repr_latex_ method not working anymore in Jupyter / IPython notebook

我有一个 Expr class 来表示我定义的数学表达式

def _latex(self):
    """:return: string LaTex formula"""
    (...)
    return res

def _repr_latex_(self):
    return r'$%s$'%self._latex() #tried several variations of this...

@property
def latex(self):
    from IPython.display import Math
    return Math(self._latex())

正如您在 http://nbviewer.ipython.org/github/Goulu/Goulib/blob/master/notebook.ipynb 单元格 [42] 中看到的那样,当 属性 明确指定时,latex 会正确呈现 但是当通过 _repr_latex_ 调用时下一个单元格失败并出现 UnicodeDecodeError.

e2(e1)._latex() returns '\sin(3x+2)' 没有 unicode,所以这里出了什么问题? 谢谢!

嗯...这部分是我的错误:my Expr class inherits from my Plot class 有一个 _repr_svg_ 方法,Jupyter 默认调用这个方法而不是 _repr_latex_ ...

好的但是:

  1. Jupyter/IPython 中的错误消息没有提到这个
  2. 我仍然不知道如何 select class
  3. 的默认 _repr_xxx_ 方法