Skip to content

MathJax too keen to convert TeX markup in Sphinx generated HTML #332

jonathanfine opened this Issue Oct 9, 2012 · 7 comments

4 participants


As subject, with this input and ouput.



MathJax processes the {problematic} environment, but I don't want it to (and according to the Sphinx docs, it should not, I believe).

I've tried changing setting, and have changed behaviour, but not to give what I want.

This might also be regarded as a Sphinx bug.

MathJax member
dpvc commented Oct 10, 2012

In the output file you link to, MathJax should process the \begin{problematic}...\end{problematic} block as the default for tex2jax is to process \begin...end pairs (and assume they produce display math equations). You can turn that off my setting the processEnvironments option to false in the tex2jax section of your configuration. That could be included in the file itself as in-line configuration if you wanted (but I don't know how to do that in Sphinx).

Note that this will disable all processing of \begin..\end pairs that aren't explicitly inside math delimiters, so if you use this approach, you might need to put $$ around some environments that would otherwise have been handled by MathJax directly.

Alternatively, you could put the environment inside <pre> or <code> tags, in which case MathJax will ignore it (not sure how this is handled in Sphinx, but I suspect that its verbatim modes use such tags). Or you could put it inside <div class="tex2jax_ignore">...</div> (again, you would have to know how to make that happen in Sphinx). You may also be able to define your own classes, and you could add them to the ignoreClass pattern in the tex2jax section of your configuration.

See the tex2jax options documentation for details of controlling that, and the configuration documentation for how to do in-line configuration.


I would like Sphinx and MathJax to be set up so that they work with each other. Sphinx puts its math into HTML elements with a math class, as I recall. I'd like there to be a MathJax configuration option that recognizes as math exactly the things that Sphinx intends to be MathJax math. It's clearly an interface issue between Sphinx and MathJax.

Is it possible to configure MathJax by supplying a JavaScript function that returns the nodes that MathJax should be processing? This would be good, because then the Sphinx configuration for MathJax needs only to add this this function to its MathJax configuration.

I've added a Sphinx issue, with the same title:


Oops - did not mean to close the issue.

@jonathanfine jonathanfine reopened this Oct 22, 2012
mitya57 commented Oct 27, 2012

@jonathanfine I had the same problem and was told how to do that in this discussion.

The easiest way is adding class="tex2jax_ignore" to your <body> and add this to MathJax config:

tex2jax: {
  processClass: "math"
MathJax member
pkra commented Oct 30, 2012

@jonathanfine you could combine what @dpvc and @mitya57 wrote: set processEnvironments to false and specify the processClass. That should do the trick, giving you a Sphinx specific base configuration.

MathJax member
dpvc commented Oct 31, 2012

I don't think you need to set processEnvironments to false if you use @mitya57's suggestions.

On the other hand, if inline math is in <span class="math">...</span> and display math is in <div class="math">...</div>, then you could use the jsMath2jax preprocessor rather than the tex2jax preprocessor and it would only convert the math contained within those elements.


In the URL below Georg Brandl writes: So if I understand correctly, first MathJax needs to provide an API that we could use?

I suggest that a suitable expert in this list supplies the API that Georg asks for. I think this can be done without my being involved. If you have specific questions related to Sphinx please use the URL below.

@dpvc dpvc closed this Dec 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.