-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback to the string printer if the latex printer raises an exception #65
Conversation
Currently it just prints an error and gives an empty png. However, there is a lot of LaTeX that matplotlib cannot parse, e.g., matrices. This gives a better user experience for SymPy, which has a text printer that it can fallback to. SymPy cannot just disable the LaTeX printer because it is desired for the notebook, and there is no way for it to enable LaTeX just in the notebook, or change the printer precedence order. I have left in the debug logging of the error (to the terminal). Fixes jupyter#63. This supersedes jupyter#57, although I don't know if it fixes the issue there.
@flying-sheep would love to hear if this fixes your issues or not. I didn't see any tests for latex, so didn't add any for this fix (because I'm not sure how). |
I'm unclear what exactly is happening in your case, then. |
@flying-sheep, please clarify. |
|
@flying-sheep is any error information printed to the terminal? Maybe the problem in your case is that the latex rendering "fails" but doesn't register as a failure (raise an exception) to the qtconsole. If it did, it would fallback to the text renderer in this PR. |
nothing. |
Oops, slipped through te cracks with all the repos. I'm fine with that. |
excuse me: what is it that you’re fine with? 😆 |
The PR in general if it helps. The QtConsole is in low maintnance mode and few of the core dev use it. Frankly the QtConsole. should be replaced by a QtWebkitView that actually support a local mathjax install + codemirror/Ace. |
FYI the QTConsole does have users, as evidenced by the multiple bug reports we've received from SymPy for this bug. Also, in case you missed it, this PR and #57 are mutually exclusive with one another. You guys need to pick one or the other (or suggest a third alternative). |
well, my problem as stated is that LaTeX → PNG isn’t a good solution to default to. you can’t select & copy parts of the output, and it’s more overhead than simple text→text transformations. if the explicit plan is to replace the QtConsole frontend with a QWebView based one, i’m all for merging this and moving on, but if this is going to stay for a longer time, it’s pretty ugly for IRKernel users. |
Yes I know. I'm just stating that it receives few patch from the core team. I would have no issues giving @flying-sheep , @asmeurer and @ccordoba12 commit rights if it makes things easier for you guys. (As long as a couple of other dev agrees also). You seem to be the one both using Qtconsole, receiving bugs report,and writing patches, so it seem fair to me. [edit] actually @ccordoba12 already have write access, (but not admin). [/edit]
Yes i though the incompatibility and why I commented on the other that |
I'm torn on this one. My current inclination is to go with this patch and allow explicit disable of latex via preferences. |
@Carreau, I already have commit rights (@minrk granted them to me :-) I'm +1 with @minrk proposal, I think it's a good compromise. I'll submit a PR with the option to disable Latex, if @flying-sheep and @asmeurer agree. Please let me test and merge this one, I promise to do it this weekend ;-) |
That sounds good to me too. (and btw I don't personally use the qtconsole; just fixing an issue for upstream SymPy) |
@ccordoba12 #63 has steps to reproduce the SymPy issue for when you test this. |
@ccordoba12 go ahead and merge when you are ready. |
well, disabling latex is already possible from the kernel, so two switches are probably confusing. another idea: maybe we should hardcode a list of which kernels interpret “text/latex” like IPython does. generally any MIME type means of course everything compliant to the language/format specified by that MIME type but IPython means with “text/latex”: “a math subset of LaTeX that is roughly equivalent to what MathJax can do” i don’t think we should accept all kernels to interpret the latex MIME type like IPython. it would be a hack but if IPython wants to keep doing that i think we should handle it in a special way. |
@flying-sheep, how latex can be deactivated from the kernel? |
options(jupyter.plot_mimetypes = c('text/plain', 'image/png', 'image/svg+xml')) i think that’s already the default by now… |
self._append_latex(data['text/latex'], True) | ||
except Exception as e: | ||
self.log.error("Failed to render latex: '%s'", data['text/latex'], exc_info=True) | ||
self.log.error("Failed to render latex: %s" % e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the second log call is redundant here - exc_info=True
in the first one should log the the error that was caught.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a fix for that.
exc_info=True already does this.
I just tested this, and it seems that the exception is printed in the qtconsole, which I believe wasn't the case when I originally made this. Any idea why that would be happening, and how to disable it? I only want the error to be logged to the terminal. |
@asmeurer are you sure the error isn't raised in the kernel? When I run the sample, sympy is computing the PNG kernel-side, so an error would logically be shown in the qtconsole. |
I have no idea what that even means, so ¯_(ツ)_/¯ |
When I run the code (sympy 0.7.6.1): from sympy import *
init_session()
Matrix([[1, 2], [3, 4]]) sympy computes a png and latex string and sends them in a display message. The QtConsole receives this and displays the png computed by sympy. If sympy encountered an error during that computation, the traceback would be normal kernel output, and rightly displayed in the qtconsole. |
OK, my bad. That means that this is an issue in SymPy, and it turns out it has already been fixed (I was testing against the release, but I checked master and it went away). |
self._append_latex(data['text/latex'], True) | ||
try: | ||
self._append_latex(data['text/latex'], True) | ||
self.log.error("Failed to render latex: '%s'", data['text/latex'], exc_info=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log call should be in the except
block, not the try
block, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably
Fallback to the string printer if the latex printer raises an exception closes #57
Currently it just prints an error and gives an empty png. However, there is a
lot of LaTeX that matplotlib cannot parse, e.g., matrices. This gives a better
user experience for SymPy, which has a text printer that it can fallback
to. SymPy cannot just disable the LaTeX printer because it is desired for the
notebook, and there is no way for it to enable LaTeX just in the notebook, or
change the printer precedence order.
I have left in the debug logging of the error (to the terminal).
Fixes #63. This supersedes #57, although I don't know if it fixes the issue
there.