The method should have the signature _latex(self, printer), and you should use printer._print() to recursively print things. See https://docs.sympy.org/latest/guides/custom-functions.html#printing
Aaron Meurer On Fri, Sep 9, 2022 at 9:20 AM brombo <[email protected]> wrote: > > I have written the custom class PieceWiseFunction. One of the class members > is: > > def _latex(self): > s = r'\left \{\begin{array}{c}'+'\n' > s += r'x < '+latex(self.x[0])+': '+latex(self.f[0])+r' \\ '+'\n' > for i in range(1,len(self.x)): > xlo = latex(self.x[i-1]) > xhi = latex(self.x[i]) > f = latex(self.f[i]) > s += xlo+r' \le x < '+xhi+r': '+f+r' \\ '+'\n' > s += r' x \ge '+latex(self.x[-1])+': '+latex(self.f[-1])+'\n' > s += r' \end{array}\right \}' > return s > > I am trying to use the sympy "latex" function to access my _latex and get the > following error message: > > File > "/home/brombo/.local/lib/python3.8/site-packages/sympy/printing/printer.py", > line 309, in _print > return getattr(expr, self.printmethod)(self, **kwargs) > TypeError: _latex() takes 1 positional argument but 2 were given > > What am I doing wrong in my definition of _latex? > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/c0821032-a469-4506-afc9-880d0ea0d952n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BZKNOSaeAQ87ERR%2BAS2CsdC6AO0B9%3DpSSTq-3963_Xgw%40mail.gmail.com.
