Is it possible to force inclusion of MathJax?

93 views
Skip to first unread message

Moritz Beber

unread,
Jan 1, 2020, 7:32:11 AM1/1/20
to sphinx-users
This is somewhat related to issue https://github.com/sphinx-doc/sphinx/issues/5497. I have a plotly figure that includes some math and only renders correctly when MathJax is present. You can see what I mean in this nbsphinx issue (https://github.com/spatialaudio/nbsphinx/issues/369). This is not detected by Sphinx and thus MathJax is not automatically included.

So I'm wondering if there is a way for me to force the inclusion of MathJax or, alternatively, for Sphinx to detect math in plotly objects?

Stefano David

unread,
Jan 2, 2020, 8:49:18 AM1/2/20
to sphinx-users
Hi,


On Wednesday, 1 January 2020 13:32:11 UTC+1, Moritz Beber wrote:
This is somewhat related to issue https://github.com/sphinx-doc/sphinx/issues/5497. I have a plotly figure that includes some math and only renders correctly when MathJax is present. You can see what I mean in this nbsphinx issue (https://github.com/spatialaudio/nbsphinx/issues/369). This is not detected by Sphinx and thus MathJax is not automatically included.

So I'm wondering if there is a way for me to force the inclusion of MathJax or, alternatively, for Sphinx to detect math in plotly objects?

Add 'sphinx.ext.mathjax' to the extensions listed in conf.py, like

extensions = [ 'sphinx.ext.mathjax' ]

HTH,
Stefano

Komiya Takeshi

unread,
Jan 2, 2020, 9:04:40 AM1/2/20
to sphinx...@googlegroups.com
Hi,

mathjax will be loaded only when document contains any math elements.
How about make plotly objects subclasses of math node? Then mathjax
extension will recognize them as math elements.

As a workaround, you can modify "has_equations" attribute of math
domain. But I don't think not a good way because it is internal
attribute.

Thanks,
Takeshi KOMIYA

2020年1月1日(水) 21:32 Moritz Beber <moritz...@gmail.com>:
>
> This is somewhat related to issue https://github.com/sphinx-doc/sphinx/issues/5497. I have a plotly figure that includes some math and only renders correctly when MathJax is present. You can see what I mean in this nbsphinx issue (https://github.com/spatialaudio/nbsphinx/issues/369). This is not detected by Sphinx and thus MathJax is not automatically included.
>
> So I'm wondering if there is a way for me to force the inclusion of MathJax or, alternatively, for Sphinx to detect math in plotly objects?
>
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/83b41c7f-c527-426a-9f5d-ff168182589e%40googlegroups.com.

moritz...@gmail.com

unread,
Jan 2, 2020, 9:06:13 AM1/2/20
to sphinx...@googlegroups.com
Hi Stefano,

That's already the case but MathJax is not loaded unless there is a math object somewhere in the documents.

Cheers,
Moritz
--
You received this message because you are subscribed to a topic in the Google Groups "sphinx-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sphinx-users/0cDKO35c5IQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/a93d58ee-f390-48fe-ba4e-1d3f66833f84%40googlegroups.com.

moritz...@gmail.com

unread,
Jan 2, 2020, 9:08:46 AM1/2/20
to sphinx...@googlegroups.com
Hello,

On Thu, 2020-01-02 at 23:04 +0900, Komiya Takeshi wrote:
mathjax will be loaded only when document contains any math elements.
How about make plotly objects subclasses of math node? Then mathjax
extension will recognize them as math elements.

Do you have any pointers (documentation links) as to how I could do that? I'm not a plotly author and I have never really looked at Sphinx internals either.

Thanks,
Moritz

Komiya Takeshi

unread,
Jan 2, 2020, 9:36:53 AM1/2/20
to sphinx...@googlegroups.com
Do you want to know how to make a subclass of math nodes? It's simple
knowledge of python.
You can do it like following:

from docutils.nodes import math

class plotly_elements(math):
pass


That's all.

If you'd like to know about that behavior, unfortunately there are no
document for that.
It only described in CHANGES and its code:
https://github.com/sphinx-doc/sphinx/blob/0319faf8f1503453b6ce19020819a8cf44e39f13/sphinx/domains/math.py#L80-L85

Thanks,
Takeshi KOMIYA

2020年1月2日(木) 23:08 <moritz...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/0a2462c47569aba75e80727e17069e5f440247e8.camel%40gmail.com.

Stefano David

unread,
Jan 3, 2020, 4:24:21 AM1/3/20
to sphinx-users
Hi Moritz,


On Thursday, 2 January 2020 15:06:13 UTC+1, morit...@gmail.com wrote:
Hi Stefano,

That's already the case but MathJax is not loaded unless there is a math object somewhere in the documents.
Ouch, sorry for the misunderstanding.
Stefano

Reply all
Reply to author
Forward
0 new messages