-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
ENH: added StackExchange-style MathJax filtering #2349
Conversation
This is great! First, I'm testing the problem blocks listed in #2289. The following in a cell:
produces this image: while master gives: So this is obviously major progress! Thanks a lot @ahmadia, I'll have a look now at the code. Pinging @minrk in case he's OK considering this for a 0.13.1 backport, as I think this is super high value. |
deTilde; | ||
if (hasCodeSpans) { | ||
text = text.replace(/~/g, "~T").replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, function (wholematch) { | ||
return wholematch.replace(/\$/g, "~D"); |
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.
It seems to me these nested function declarations would be more readable if they were broken up across lines. Right now these lines (above and below this comment) are really hard to read.
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.
Yes, I'm getting used to a new editor, and one thing that it doesn't do automatically is hard line breaks. Does the javascript follow an 80 character line break?
The code is very non-trivial, with a ton of regex logic, but it looks clean and well-comented. I wish dearly we had some unit test machinery in place for the JS code so this could also get tested, as it's a bit too monolithic for my taste (and hitting it with a test harness would likely lead to some refactoring into more digestible pieces). But given the current state of our JS testing (aka none), the importance of this fix and the fact that at least running it over many notebooks I have seems to always do the right thing, I'm +1 on merging it (once the very minor comments above are addressed). I will however wait a couple of days in case others have a different opinion. @ellisonbg, @Carreau, @minrk: you guys have looked the most at the JS code; any dissenting views here or other concerns? Thanks for the contribution! |
I will try to have a look at it Sent from my iPad On Sep 5, 2012, at 8:17 PM, Fernando Perez notifications@github.com wrote:
|
Given the untested nature of our js, I would be a bit squeamish putting this in 0.13.1, with only a couple of days of testing. |
I'm a little less squeamish about this code for the reason that I'm Fernando, if you're really interested in seeing this is 0.13.1, we could The biggest most-dangerous change I'm introducing is overriding the I'll wait for you to guys to come to a decision about what you want and A On Thu, Sep 6, 2012 at 6:08 AM, Min RK notifications@github.com wrote:
|
Here is my proposal about where the code should go:
|
*On Fri, Sep 7, 2012 at 9:03 PM, Brian E. Granger notifications@github.com
I agree with Brian's proposal. I will perform the suggested modifications I am waiting on the dev team to decide whether they want this backported to Regards, —
|
On Sun, Sep 9, 2012 at 5:51 AM, ahmadia notifications@github.com wrote:
Great, thanks!!
Min was -1 on it, and since he's done all the work on making 0.13.1 If we had a solid unittest infrastructure for the JS code I think this Cheers, f |
I would put it closer to -0.75 :) There are really two considerations:
|
I filed a preapproval of the 0.13.1 diff with the debian release team a while back but no answer yet (bug 686604), so I can't say much about the current chances of the branch with or without this change. |
ahmadia: what is the status of this, do you have more work to do to address the comments or are you waiting for further review? |
@ellisonbg - the status is that @ahmadia needs to reimplement this properly following your suggestions, and has not found the time to do so, but at least has been feeling guilty about it. I'll try to have the updated in by Thursday, thanks for the nudge :) |
@ahmadia please don't feel guilty - I was just making sure you weren't On Tue, Oct 2, 2012 at 1:33 PM, ahmadia notifications@github.com wrote:
Brian E. Granger |
Okay, I've got @ellisonbg 's suggested refactor in, but now I'm wrestling with getting MathJaX to properly process environments. All of the basic stuff is enabled here: https://github.com/ahmadia/ipython/tree/mathjax_refactor What I'd like to do is get some of the cooler equation numbering and such going, but this is going to take some debugging (which is new to me): http://cdn.mathjax.org/mathjax/latest/test/sample-eqrefs.html |
@ellisonbg @fperez @minrk - This pull request is once more ready for review. I've changed the default mathjax configuration so it accepts LaTeX environments, added AMS-style equation references and numbering, and significantly cleaned up the code module. You no longer need
Using |
Can you create a notebook in docs/examples/notebooks that shows how to use Cheers, Brian On Tue, Oct 9, 2012 at 9:40 AM, ahmadia notifications@github.com wrote:
Brian E. Granger |
@ellisonbg - I added a sample notebook. Note that nbviewer won't typeset it properly until we've correctly patched it. |
// Some magic for deferring mathematical expressions to MathJaX | ||
// Some of the code here is adapted with permission from Stack Exchange Inc. | ||
|
||
var inline = "$"; // the inline math delimiter |
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.
Don't know how I feel about top level attributes. You have protected them using the JS module pattern though. The alternative would be to create a class that has all of this logic. @Carreau what do you think about this?
So this is looking pretty good now. A few comments:
|
// Don't allow math to pass through a double linebreak | ||
// (which will be a paragraph). | ||
// | ||
function removeMath(text) { |
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.
We are trying to use the var foo = function ()
style of function defs, please convert to this.
I just tried this branch and it is completely broken with the version of MathJax I am using. @Carreau @minrk @fperez how should we handle MathJax versioning issues? Sort of difficult.. Minimally, we should make sure that the |
I just updated to v2.0 of MathJax and it is still broken. I see a JS console error:
The notebook doesn't even finish loading. |
Got it, you have to clear your browser cache when updating MathJax. The example notebook looks spectacular! |
The majority of the logic for stripping TeX/LaTeX before sending text to PageDown then replacing it after PageDown has rendered the Markdown-formatted text to HTML-formatted text comes from the StackExchange javascript source. Unfortunately, the javascript is no longer available from the URL I originally accessed it at, but was linked to from this question. I improved the source code by incorporating a more robust regular expression parser with explicit licensing. The StackExchange code is not copyright, but it is also not released in any way. I was given permission by the moderator team in a StackExchange logged and hosted chat session to reuse the code. As pointed out on the discussion list, it would be great if we had a better Markdown parser than Pagedown, but until the competing projects are more mature, I think we are better off piggy-backing larger projects like StackExchange. Are there any other concerns beside the naming issues? |
thisStyle --> this_style. function foo() --> var foo = function() StackExchange improperly attributed for Davide Cervone's Markdown+MathJax handling. This has been fixed. Ref: http://stackoverflow.com/a/11231030/122022 http://www.math.union.edu/~dpvc/transfer/mathjax/mathjax-editing.js
@ellisonbg - ready for review. |
OK I think this looks good, merging. |
ENH: added StackExchange-style MathJax filtering
Am I the only one to get a totally broken notebook after this merge ? With |
FYI, it break when user have old mathjax version installed locally, they then need to upgrade to 2.0, check that the old version is removed (new version is installed in profile) and clear cache. |
Brian pointed that out in the PR, and I didn't properly fix it :( A On Sun, Oct 21, 2012 at 4:20 PM, Bussonnier Matthias <
|
@Carreau @ellisonbg - I'm not familiar with the bit of code responsible for local MathJax installs. Is this something that some attention from me can help, or should I leave it to one of you to fix? |
@Carreau - One thing I think I can do is try and detect if the MathJax library is out of date and issue an alert to the user. Would this be useful? |
Yes, I would put this information in the mathjaxinit function. There is a On Sun, Oct 21, 2012 at 9:20 AM, ahmadia notifications@github.com wrote:
Brian E. Granger |
I am seeing two problems related to this branch:
|
For me only sometimes. |
Yes, it is inconsistent for me too - probably a timing issue or something. On Wed, Oct 24, 2012 at 10:05 AM, Bussonnier Matthias <
Brian E. Granger |
After installing this, I also see very slow math rendering or (often, not always) the notebook doesn't seem to load at all; I just get a single cell that says "Type Markdown and LaTeX: α2". I see both effects in both Safari and Chrome. I would love to have this functionality, though. It's very annoying that with 0.13 I can't cut/paste valid laTeX in ipython notebooks. But for now this has forced me to roll back to the release version. |
I see the same things. On Thu, Oct 25, 2012 at 5:23 AM, David Ketcheson
Brian E. Granger |
Thanks for feedback and apologies for the bug. I'm improving the logic A On Thu, Oct 25, 2012 at 5:47 PM, Brian E. Granger
|
Thanks! On Thu, Oct 25, 2012 at 11:21 AM, ahmadia notifications@github.com wrote:
Brian E. Granger |
Addresses the javascript errors resulting in a blank notebook pointed out in #2349 as well as significant performance degradations that were introduced by that merge. It also disables equation numbering/references, fixes broken offline access and re-typesets individual Notebook Cells instead of the entire document on edit. Closes #2289.
ENH: added StackExchange-style MathJax filtering
Addresses the javascript errors resulting in a blank notebook pointed out in ipython#2349 as well as significant performance degradations that were introduced by that merge. It also disables equation numbering/references, fixes broken offline access and re-typesets individual Notebook Cells instead of the entire document on edit. Closes ipython#2289.
Attempts to fix Issue #2289
Resubmission of accidentally merged Pull Request #2337