-
I have spent a little time investigating, but think I should ask before I dig in too deep. I have situations where I would like to pre-process objects so additional information is displayed when they are pretty printed in IPython/Jupyter. There are a number of scenarios, but the simplest is to generate an easily turned on or off display of the code version of the expression in addition to the typeset version. When writing code on the fly you can just insert a
However, I have cases where I want to programmatically inject the 2nd to last line when pretty printing is triggered by the last line of a cell. I can make this work by extending the call to latex in sympy.printing.latex to accept what I call a pre_latex_hook function that does the things I want. However, that requires modifying sympy. Is there another way of doing this? I have tried using some of the IPython printing modules such as IPython.lib.pretty.for_type(typ, func) to register my functions as overrides in IPython, but with no success. It appears the way sympy registers its pretty printers cannot be overriden at the IPython level. Does anybody have suggestions along those lines? A related question is if there is any interest in having a "show code" option as part of sympy? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Another alternative that has occurred to me is to hook into the IPython pre-parser and actually insert the |
Beta Was this translation helpful? Give feedback.
-
A partial solution for IPython that allows injection of a process before the pretty printing, but does not readily allow for modification of what is pretty printed by sympy uses the following pattern to hook into the IPython display formatter.
This could also be used to hook into any of the other display types: ['text/plain', 'text/html', 'text/markdown', 'image/svg+xml', 'image/png', 'application/pdf', 'image/jpeg', 'text/latex', 'application/json', 'application/javascript']. It easily works to print something before the fancy display. It is not clear to me how to modify the fancy display itself using this. |
Beta Was this translation helpful? Give feedback.
A partial solution for IPython that allows injection of a process before the pretty printing, but does not readily allow for modification of what is pretty printed by sympy uses the following pattern to hook into the IPython display formatter.
This could also be used to hook into any of the other display types: ['text/plain', 'text/html', 'text/markdown', 'image/svg+xml', 'image/png', 'application/pdf', 'image/jpeg', 'text/latex', 'application/json', 'application/j…