Skip to content
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

Merged
merged 3 commits into from
Jan 21, 2016

Conversation

asmeurer
Copy link
Contributor

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.

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.
@asmeurer
Copy link
Contributor Author

@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).

@flying-sheep
Copy link
Contributor

hmm, no

@minrk minrk added this to the 4.2 milestone Oct 25, 2015
@asmeurer
Copy link
Contributor Author

I'm unclear what exactly is happening in your case, then.

@ccordoba12
Copy link
Collaborator

@flying-sheep, please clarify.

@flying-sheep
Copy link
Contributor

  1. i installed the qtconsole dependencies in an almost clean venv (i symlinked my system pyqt)
  2. i installed this branch of qtconsole
  3. i started jupyter qtconsole --kernel=ir
  4. i see what i show you in the screenshot

@asmeurer
Copy link
Contributor Author

asmeurer commented Dec 7, 2015

@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.

@flying-sheep
Copy link
Contributor

nothing.

@Carreau
Copy link
Member

Carreau commented Jan 6, 2016

Oops, slipped through te cracks with all the repos.

I'm fine with that.

@flying-sheep
Copy link
Contributor

excuse me: what is it that you’re fine with? 😆

@Carreau
Copy link
Member

Carreau commented Jan 7, 2016

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.
So most PR should be merge accepted quickly.

Frankly the QtConsole. should be replaced by a QtWebkitView that actually support a local mathjax install + codemirror/Ace.

@asmeurer
Copy link
Contributor Author

asmeurer commented Jan 7, 2016

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).

@flying-sheep
Copy link
Contributor

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.

@Carreau
Copy link
Member

Carreau commented Jan 7, 2016

FYI the QTConsole does have users, as evidenced by the multiple bug reports we've received from SymPy for this bug.

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]

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).

Yes i though the incompatibility and why I commented on the other that I think that even partial support is better than none.

@minrk
Copy link
Member

minrk commented Jan 7, 2016

I'm torn on this one. My current inclination is to go with this patch and allow explicit disable of latex via preferences.

@ccordoba12
Copy link
Collaborator

@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 ;-)

@asmeurer
Copy link
Contributor Author

asmeurer commented Jan 7, 2016

That sounds good to me too.

(and btw I don't personally use the qtconsole; just fixing an issue for upstream SymPy)

@asmeurer
Copy link
Contributor Author

asmeurer commented Jan 7, 2016

@ccordoba12 #63 has steps to reproduce the SymPy issue for when you test this.

@minrk
Copy link
Member

minrk commented Jan 7, 2016

@ccordoba12 go ahead and merge when you are ready.

@flying-sheep
Copy link
Contributor

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.

@ccordoba12
Copy link
Collaborator

@flying-sheep, how latex can be deactivated from the kernel?

@flying-sheep
Copy link
Contributor

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)
Copy link
Member

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.

Copy link
Contributor Author

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.
@asmeurer
Copy link
Contributor Author

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.

@minrk
Copy link
Member

minrk commented Jan 13, 2016

@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.

@asmeurer
Copy link
Contributor Author

I have no idea what that even means, so ¯_(ツ)_/¯

@minrk
Copy link
Member

minrk commented Jan 13, 2016

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.

@asmeurer
Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably

minrk added a commit that referenced this pull request Jan 21, 2016
Fallback to the string printer if the latex printer raises an exception

closes #57
@minrk minrk merged commit d78756a into jupyter:master Jan 21, 2016
@asmeurer asmeurer mentioned this pull request Jan 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LaTeX that matplotlib fails on should fallback to the next renderer
6 participants