question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MathJax not loaded in plotly offline

See original GitHub issue

plotly.offline.plot fails (shows an unstyled plot after bailing out early due to errors) if latex is used since MathJax is not loaded in the default html. Short of getting fancy, it seems like plotly.offline.plot might need a manual option to inject MathJax from a cdn into the head tag.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

13reactions
jjaraalmcommented, Nov 27, 2016

EDIT: Actually, this might not be the right place for this since the original issue did not explicitly specify Jupyter notebooks, might be more closely related to #105 or #444

This is not really an issue with plotly.py per-se, but is the result of issues upstream at plotly.js.

plotly.js does not encapsulate mathjax but instead relies on it being loaded globally and configured in a specific way. The problem is that there are multiple different output renderers for mathjax. Juypter globally loads mathjax with HTML output, but plotly.js requires SVG output. A quick and easy fix is just to change the output renderer for mathjax globally as this does not affect Juypter’s markdown rendering.

In order to address #445, mathjax should also be configured to set displayAlign = center since plotly.js explicitly sets this to left align. As far as I can tell in simple testing, the display alignment actually has no bearing on the output rendered by plotly.

Right now the code block I’m using to fix all these issues is:


# Startup plotly
init_notebook_mode(connected=True)

# The polling here is to ensure that plotly.js has already been loaded before
# setting display alignment in order to avoid a race condition.
display(HTML(
    '<script>'
        'var waitForPlotly = setInterval( function() {'
            'if( typeof(window.Plotly) !== "undefined" ){'
                'MathJax.Hub.Config({ SVG: { font: "STIX-Web" }, displayAlign: "center" });'
                'MathJax.Hub.Queue(["setRenderer", MathJax.Hub, "SVG"]);'
                'clearInterval(waitForPlotly);'
            '}}, 250 );'
    '</script>'
))
10reactions
mmlangercommented, Sep 7, 2016

This is actually the only reason that stops me using plotly for my publication graphics. No LaTeX in offline plotly is a serious issue, is there any news on this? #444 and #445 also addresses latex problems with plotly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotly library interferes with MathJax - Plotly Community Forum
I noticed, when included the plotly library in my HTML header, MathJax stopped working. All my LaTeX formulas appeared in raw source form ......
Read more >
LaTeX-text does not work at all in plotly.offline?
I am using mac os x 10.14, python 3.7 and plotly 3.4.2 . Unfortunately plotly.offline.iplot doesn't display latex text on the chrome browser:...
Read more >
Mathjax & LaTeX in dash - Plotly Community Forum
i need to ask how can i render latex using mathjax on callbacks. LaTeX doesn't work in Dash. LaTeX in dash not functioning....
Read more >
LaTeX not functioning - plotly.js
In the offline subpackage, on init_notebook_mode() plotly.min.js is loaded using get_plotlyjs(). How do I edit the HTML created by ...
Read more >
Latex does not work - 📊 Plotly Python
I installed Plotly 5.6.0 and Mathjax 3.2.0. I use a clean environment, with a Jupyter Notebook, with Visual Studio Code. What am I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found