Skip to content

Embedding interactive Plotly.js plots in Sphinx disables LaTeX rendering via MathJax #2403

Closed
@kordian2k

Description

@kordian2k

First of all, thanks for the great set of Plotly libraries!

I would like to embed plots into a Sphinx documentation which makes use of LaTeX via its sphinx.ext.mathjax extension. I do not want to embed the plots as images like jpg in order to keep them interactive.

My strategy to achieve that is to

  • put plotly-latest.min.js into Sphinx' _static folder,
  • embed "ready to use" HTML div elements created in Python via plotly.offline.plot with the include_plotlyjs flag set to False using the .. raw:: html directive,
  • Add a script reference to Plotly.js into each HTML file's head element using the following code snipped in Sphinx' _templates folder:
{% extends "!layout.html" %}

{%- block extrahead %}
 <script type="text/javascript" src="_static/plotly-latest.min.js"></script>
{% endblock %}

With that strategy the generated html file include the following script tags:

  • <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7./MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>,
  • <script type="text/javascript" src="_static/plotly-latest.min.js"></script>.

While Plotly's plots are shown as expected, LaTeX embeddings using the :math: directive do not render anymore.

Is there any way to use the same MathJax profile in Plotly.js as in Sphinx?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions