Two changes are introduced:
Add dvipng backend to latex_to_png
Use dvipng to format sympy.Matrix to PNG display
This looks pretty nice. Though you mustn't use the dvipng backend unconditionally, as it may not be present.
Quite right. Is returning None delegate the work to other formatter?
returning None will delegate to other mimetypes, but if you want to fallback on the mpl backend, then you have to do that yourself.
latex_to_png returns None when the backend cannot be used
When matplotlib/dvipng is not present, other formatter will be used.
I think latex output of Matrix can't rendered by matplotlib. So I guess returning None when dvipng is not present is OK here.
That makes sense, can you add a comment to that effect? The function itself looks generic, so it's unclear why it would never be used with mpl.
And please don't do pep8 cleanup on code other than your own in the future.
Document print_png and print_display_png
Sorry about PEP8. I just removed it. I remember the discussion (I think it was about copyright year stuff) saying this kind of cleanup should be done when the code is touched. Now I guess it was only for core developers.
IPython doesn't enforce pep8, so not all changes it would make should be made just for the sake of it. The copyright discussion specifically referred to the copyright notice at the top of the file, which everyone is welcome to fix as they edit fies. Even (or especially) core devs don't do file-wide pep8 at any time.
I had impression that IPython devs try to follow pep8 as much as possible because devs try to apply pep8 even to JS. But anyway, lesson learned! Thanks for the explanation.
Copyright fix on sympyprinting.py and latextools.py
We have been more strict in the JS because it's unfamiliar territory for all of us, so it helps us all stay on the same page while learning a new language.
We are much more comfortable in Python, and thus more comfortable letting authors make personal style choices in Python code. pep8 is a great guideline, and "when in doubt: pep8", but that doesn't mean an 82 character line needs to be wrapped.
I don't have dvipng on my machine, so I'm just checking that it does the right thing. It appears to do the right thing at the Python level, but latex barfs a bunch of crap to the terminal. Can you squash that by capturing stdout/err on your subprocesses?
You might also want to use IPython.utils.process.find_cmd on dvipng before even trying, because then you can be fairly sure it's not worth it.
Suppress output from latex and dvipng command
Check if latex/dvipng exist before calling them
Sorry if it's a bit of a dumb question: why is this nicer than using mathjax? In general, mathjax renders more cleanly in the browser, zooms correctly, etc. Dvipng solutions tend to suffer from nasty resolution-dependent behavior (which are likely to get worse with systems like the upcoming macs with retina displays).
I'm just trying to understand and make sure this is really always an improvement (since it's activated unconditionally).
This is for the QtConsole, and not relevant to the notebook. The notebook will still display the math with mathjax, ignoring the png this produces.
I think it is an improvement because mathjax does not work in Qt console. My intention to add dvipng backend to latex_to_png function is to cover latex math expressions which are not covered by matplotlib (such as the one by sympy.Matrix). Besides, if you put latex mime-type notebook won't show png (Am I understanding it correctly?). So I think it is improvement (or at least zero improvement) for all frontends.
Ah, notebook server will send unused data to notebook client, so I guess it will slow down the response a bit.
But this is already true of all the other sympy latex, so no big deal to add Matrices to the list.
The long-term answer is to render latex client-side in the QtConsole, which I think is preferable for various reasons.
Ah, got it. Then it's good to go, I just wanted to clarify that. I'll explain in the merge commit.
@tkf, thanks for the contribution! Merging now, thanks Min for the careful review.