fsprojects / IfSharp

F# for Jupyter Notebooks
Other
442 stars 71 forks source link

MathJax not displayed on Print Preview and Download as HTML when used with XPlot.Plotly #195

Closed cannorin closed 5 years ago

cannorin commented 5 years ago

Description

LaTeX equations $..$ inside Markdown blocks are rendered in the notebook with MathJax, but not in the print preview and the downloaded HTML.

When used with XPlot.Plotly.fsx, LaTeX equations $..$ inside Markdown blocks are rendered in the notebook with MathJax, but not in the print preview and the downloaded HTML.

Repro steps

  1. Change the cell to Markdown

  2. Enter any LaTeX equation such as $1+2$

3. Execute File>Print Preview

  1. Use #load "XPlot.Plotly.fsx

  2. Execute File>Print Preview

Expected behavior

The equation will get rendered.

Actual behavior

$1+2$ is shown as-is.

Known workarounds

Not known.

Print the notebook directly to a PDF with the browser.

Related information

cgravill commented 5 years ago

I've tried this in a couple of places and print preview seems to be working for me:

image

It's behaving right on Edge / Windows 10 and Safari / macOS.

Does LaTeX work correctly for you in a Python notebook when you download the html?

cannorin commented 5 years ago

@cgravill It seems not to be the simplest repro. screenshot from 2019-01-18 19-58-26 screenshot from 2019-01-18 20-00-52

It turned out that the XPlot.Plotly.fsx is actually causing the problem: screenshot from 2019-01-18 20-09-28

Sorry for confusing you.

cannorin commented 5 years ago

I've updated the issue accordingly.

cgravill commented 5 years ago

Ah it's probably this then: https://github.com/plotly/plotly.py/issues/515

cannorin commented 5 years ago

Ahh so is it not related to IFSharp? Sorry if so...

cgravill commented 5 years ago

It's in-between. The way we, and others, load XPlot/Plotly looks like it's causing the issue. It looks like they have a new flag that might help us. Needs investigating.

cgravill commented 5 years ago

I found a potential workaround for this of hiding MathJax (used for LaTeX) from Plotly so it won't mangle it. It follows on from what I did with @npmurphy who originally integrated XPlot into IFSharp. It works in the notebook and on print preview for me:

image

@cannorin if you get a chance could you confirm if works for you? It's on pull request #196

I also updated XPlot.Plotly and Plotly JavaScript to their latest stable version so will need to do a bit more testing elsewhere too.

cannorin commented 5 years ago

@cgravill Thanks! I'll try later today.

cannorin commented 5 years ago

@cgravill It worked very nicely! :+1:

cannorin commented 5 years ago

btw I noticed F# highlighting is not working on the print preview. Am I missing something?

cannorin commented 5 years ago

@cgravill It worked very nicely! +1

It also worked on my real notebooks which heavily use LaTeX and Plotly.

cgravill commented 5 years ago

Great, thanks for testing. It looked good on my other tests too so I'll go ahead and merge.

On the F# highlighting, I don't think F# highlighting on print preview has ever worked. It's probably falling back on styling it as Python. Last time I looked into this sort of thing on #105 while I easily adjusted export the templates needed configuring inside the Python distribution. That seemed messy so it's been on hold until changes are made upstream or someone comes up with a good approach.

cannorin commented 5 years ago

Thank you! Now I'll close this issue as solved.

Hmm... It looks really complicated. I think I might be able to override it with something like highlight.js. It's just an idea and will be a dirty workaround, though. Anyway, thanks for fixing this!