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

errors loading plotly graphs with latex #572

Closed
atharva-2001 opened this issue May 27, 2021 · 10 comments
Closed

errors loading plotly graphs with latex #572

atharva-2001 opened this issue May 27, 2021 · 10 comments

Comments

@atharva-2001
Copy link

I am trying to plot Plotly graphs inside sphinx documentation, but it seems MathJax is causing some issues.
In the documentation, MathJax v3 is being loaded, which causes errors because MathJax.hub doesn't exist anymore.

image

MathJax v3 should work with plotly because

window.PlotlyConfig = {MathJaxConfig: 'local'};

is also present in the documentation
(see here as well please)

However, if I set nbsphinx_assume_equations = False in conf.py and remove Latex in cells, I am able to see the figure, because MathJax is no longer loaded.

image

Could someone please tell me how to solve this?

@mgeier
Copy link
Member

mgeier commented May 27, 2021

Can you please provide a minimal reproducible example?

@atharva-2001
Copy link
Author

Sure, with nbsphinx_assume_equations = False in conf.py:
latex in labels and cells
latex only in labels
no latex at all
see the conf.py file used to make these here

Without any changes in conf.py (nbsphinx_assume_equations = True, default value)
latex in labels and cells
labels only in latex
no latex at all
see the conf.py file used to make these here

@mgeier
Copy link
Member

mgeier commented May 28, 2021

Thanks for the examples. The aren't really minimal, though.

@atharva-2001
Copy link
Author

Any updates on this? @mgeier

@mgeier
Copy link
Member

mgeier commented Jun 1, 2021

Not from my side. I'm waiting for a minimal example for me to reproduce and investigate the problem.

@atharva-2001
Copy link
Author

atharva-2001 commented Jun 2, 2021

Could you please check if this works?
html file with links to files built with nbsphinx_assume_equations = False in conf.py
html file with links to files built with nbsphinx_assume_equations = True in conf.py
link to the repository
I was not sure what was needed, please let me know if I can do anything more.

@mgeier
Copy link
Member

mgeier commented Jun 2, 2021

Thanks, this is still more complicated than necessary, but I can work with it!

IMHO, this should just work regardless of the value of nbsphinx_assume_equations.

The problem (or rather one of the problems) seems to be that plotly inserts this code into the HTML page:

        if (window.MathJax) {MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}

... and Sphinx defines window.MathJax because nbsphinx sets some default values for mathjax3_config.
Anyone who uses mathjax3_config will have the same problem, even if they don't use nbsphinx.

You should make another minimal example without nbsphinx that uses mathjax3_config, for example

mathjax3_config = {'tex': {'processEscapes': True}}

(EDIT: fixed dict syntax)

If this causes the same error (which I think it does), you can create an issue at the plotly issue tracker.
Once that is fixed, you can try it with nbsphinx again and we can continue here.

@mgeier
Copy link
Member

mgeier commented Jun 2, 2021

In the meantime, you can work around this problem by either downgrading Sphinx to below version 4 or by manually switching to MathJax 2 like this:

mathjax_path = 'https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
mathjax2_config = {
    'tex2jax': {
        'inlineMath': [['$', '$'], ['\\(', '\\)']],
        'processEscapes': True,
        'ignoreClass': 'document',
        'processClass': 'math|output_area',
    }
}

@atharva-2001
Copy link
Author

Thank you very much! I will make an issue in plotly soon.

@mgeier
Copy link
Member

mgeier commented Apr 3, 2022

In the meantime, plotly/plotly.js#6073 has been merged.

Maybe it works now with MathJax 3?

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

No branches or pull requests

2 participants