goulu / Goulib

library of useful Python code for scientific + technical applications
GNU Lesser General Public License v3.0
42 stars 6 forks source link

_repr_latex_ method not working anymore in Jupyter / IPython notebook #3

Closed goulu closed 8 years ago

goulu commented 9 years ago

(posted on http://stackoverflow.com/questions/33150125/repr-latex-method-not-working-anymore-in-jupyter-ipython-notebook ) I have an Expr class to represent mathematical expressions in which I defined

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())

as you can see on http://nbviewer.ipython.org/github/Goulu/Goulib/blob/master/notebook.ipynb at cell [42], latex is correctly rendered when explicitly specified by the property but fails next cell when called though _reprlatex with a UnicodeDecodeError.

e2(e1)._latex() returns '\sin(3x+2)' with no unicode, so what's wrong here ? Thanks !

goulu commented 8 years ago

solved : well... it was partly my mistake : my Expr class inherits from my Plot class which has a _reprsvg method and Jupyter called this one by default instead of _reprlatex ...

Ok But:

the error message in Jupyter/IPython doesn't mention this I still don't know how to select the default _reprxxx method of a class