Custom Printing

15 views
Skip to first unread message

brombo

unread,
Dec 8, 2022, 9:43:11 AM12/8/22
to sympy
I understand how to create a custom latex printer for my classes using _latex().  My question is there an acceptable way for me to create a custom latex printer for sympy class objects?  For example a custom latex printer for sympy functions or derivatives that would override the sympy printer functions when printing my objects?

Aaron Meurer

unread,
Dec 8, 2022, 5:26:36 PM12/8/22
to sy...@googlegroups.com
Yes, you can do this by subclassing the LatexPrinter in
sympy.printing.latex, redefining the methods for the classes you want
to print, and using YourSubclass().doprint() instead of latex(). Or if
you are using init_printing, using
init_printing(latex_printer=YourSubclass().doprint). There's some
basic docs on how define a subclass of a printer here
https://docs.sympy.org/latest/modules/printing.html, but really the
best bet is to just look at the original source code for LatexPrinter
and go from there.

Aaron Meurer

On Thu, Dec 8, 2022 at 7:43 AM brombo <abrom...@gmail.com> wrote:
>
> I understand how to create a custom latex printer for my classes using _latex(). My question is there an acceptable way for me to create a custom latex printer for sympy class objects? For example a custom latex printer for sympy functions or derivatives that would override the sympy printer functions when printing my objects?
>
> --
> 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 sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/ff57da55-7311-4375-adfe-d61434fc5393n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages