nteract / markdown

A package for rendering Markdown within Jupyter notebooks
BSD 3-Clause "New" or "Revised" License
9 stars 8 forks source link

nteract doesnt interpret formulae #5

Open sonulohani opened 4 years ago

sonulohani commented 4 years ago

Application or Package Used VS code

Describe the bug The section $y^{pred}= \text{[0 if y_score < 0.5 else 1]}$ didn't get interpreted properly in VSCode however I can see this properly interpreted in the Jupyter notebook in the browser. Please visit this link for more info:- VSCode Python Extension bug

To Reproduce Steps to reproduce the behavior:

  1. Go to VSCode
  2. Create ipynb file
  3. Put this code in the markdown section
    
    <pre>
    <font color='red'><b>A.</b></font> Compute performance metrics for the given data <strong>5_a.csv</strong>
    <b>Note 1:</b> in this data you can see number of positive points >> number of negatives points
    <b>Note 2:</b> use pandas or numpy to read the data from <b>5_a.csv</b>
    <b>Note 3:</b> you need to derive the class labels from given score</pre> $y^{pred}= \text{[0 if y_score < 0.5 else 1]}$
  1. Compute Confusion Matrix
  2. Compute F1 Score
  3. Compute AUC Score, you need to compute different thresholds and for each threshold compute tpr,fpr and then use numpy.trapz(tpr_array, fpr_array) https://stackoverflow.com/q/53603376/4084039, https://stackoverflow.com/a/39678975/4084039 Note: it should be numpy.trapz(tpr_array, fpr_array) not numpy.trapz(fpr_array, tpr_array)
  4. Compute Accuracy Score

4. See formulae is printed as code instead of showing it as formulae.

**Expected behavior**
In the Jupyter notebook, I can see the formulae is interpreted properly.

**Screenshots**
VS Code Screenshot
![VS Code Screenshot](https://user-images.githubusercontent.com/2958681/77878484-055e6080-7276-11ea-830d-0f1a7a423f48.png)

Jupyter notebook Screenshot
![Jupyter notebook Screenshot](https://user-images.githubusercontent.com/2958681/77878528-2030d500-7276-11ea-804f-7940b05c286e.png)

**Desktop (please complete the following information):**

- OS: Windows
- Editor: VS Code 
- Version: 1.43.2
captainsafia commented 4 years ago

Thanks for opening this issue, @sonulohani!

Indeed, MathJax rendering has been a cumbersome bug for a few months now. My immediate notes on the problem:

Tagging this issue as new-contributor-friendly since it is localized enough to require a small change.

Do you mind sharing the notebook you used in the examples above for verification?

sonulohani commented 4 years ago

Here is the python notebook which you can use to check

bug.zip

sonulohani commented 4 years ago

@captainsafia Are you guys working on the fix. The bug nteract/nteract#2924 you closed was opened 2 years back.

captainsafia commented 4 years ago

The issue referenced above isn't an exact duplicate of this one but is kept as a reference.

To clarify, rendering of math works using the @nteract/mathjax package as seen below:

Screen Shot 2020-04-27 at 5 12 22 PM

The new seems to after LaTeX within markdown files or anywhere where the @nteract/mathjax library is used.

We did some work a couple of years ago to introduce the MathJax library. This regression is separate from the issues above (but perhaps related).

nteract is volunteer-based so there's not time to address everything on the backlog but we'll let you know once this makes it onto one of the monthly release milestones. Thanks for your patience!

willingc commented 4 years ago

@sonulohani I was able to get the formula in your example to render in a markdown cell by placing the formula on a new line.

Screen Shot 2020-05-09 at 3 16 07 AM

@captainsafia I think this may be more about how the markdown rendering works than a MathJax issue. Markdown is expecting a blank line in order to render the formula.

captainsafia commented 4 years ago

Migrating this issue to the markdown repo since the issue resides there.

Interesting observation, @willingc! Our markdown renderer is currently configured to support both inline and block math (ref).

This analysis might mean that there is a bug in the function that parses inline math blocks (ref).

sonulohani commented 4 years ago

@sonulohani I was able to get the formula in your example to render in a markdown cell by placing the formula on a new line.

Screen Shot 2020-05-09 at 3 16 07 AM

@captainsafia I think this may be more about how the markdown rendering works than a MathJax issue. Markdown is expecting a blank line in order to render the formula.

If the example works in Jupyter notebook regardless of adding new line or not, then it should work with nteract also. Anyway thanks for your findings. This will help devs to fix the issue more sooner.

sonulohani commented 4 years ago

Here is another ipynb markdown for testing:-

test.zip

ramantehlan commented 4 years ago

Thank you, @willingc, for the observation. After creating multiple use cases for how the formula can be used and testing it here, I found that the regex we are using is working.

However, It doesn't work when the formula is inside HTML tags and when it is in the new line with space at the beginning. The same is demonstrated below.

nteract

markldown-test

It works in the jupyter notebook and jupyter lab, but when it's in the new line with space at the beginning, it doesn't work for it either.

Jupyter notebook.

jupyter-test

I will look into over the weekend.