Is it possible to limit what MathJax should parse?

967 views
Skip to first unread message

Dmitry Shachnev

unread,
Sep 30, 2012, 7:49:49 AM9/30/12
to mathja...@googlegroups.com
Hi everybody!

I'm developer of ReText editor and we want all math to be wrapped in
<div class="math"> and all inline math — in <span class="math"> tags,
so that it had correct (and consistent) styling.

Is it possible to tell MathJax to parse *only* content withing
<div/span class="math"> blocks and not touch everything else?

Cheers,

--
Dmitry Shachnev

Frédéric WANG

unread,
Sep 30, 2012, 8:07:14 AM9/30/12
to mathja...@googlegroups.com
Hi Dmitry,

Here are links to the doc, with several options to control what is or is
not parsed:

See "elements" http://www.mathjax.org/docs/2.0/options/hub.html
See "skipTags", "ignoreClass", "processClass":
http://www.mathjax.org/docs/2.0/options/tex2jax.html

Hope that helps,
--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

Davide P. Cervone

unread,
Sep 30, 2012, 6:02:05 PM9/30/12
to mathja...@googlegroups.com
Fred has already pointed you to the documentation on this.

There are two approaches that would probably work for you. The first
is to use MathJax's ignoreClass and processClass values to control the
tex2jax processing (assuming your input is TeX). Set processClass to
include the "math" class, and add class="tex2jax_ignore" to the BODY
element in your document (or put a <div class="tex2jax_ignore"> around
the contents of the page). This will cause tex2jax to only look for
math in the containers that have class="math".

Alternatively, if you are able to recognize the mathematics yourself
already, you could decide not to use tex2jax at all, and mark the
mathematics directly using the <script> tags that MathJax uses for
storing the math on the page. Use <script type="math/tex">...</
script> for in-line math and <script type="math/tex;
mode=display">...</script> for display math. You can put these inside
your class="math" spans and divs if you want. You could also include
<span class="MathJax_Preview">...</span> just before the <script
type="math/tex"> script (with no intervening tags, text, or
whitespace) to include a preview for before MathJax processes the page
(MathJax will remove it as it goes). That could be just the original
TeX code, or something else that marks where your mathematics will
appear.

See

http://www.mathjax.org/docs/2.0/model.html

and in particular

http://www.mathjax.org/docs/2.0/model.html#how-mathematics-is-stored-in-the-page

for details.

Davide

Dmitry Shachnev

unread,
Oct 2, 2012, 3:40:01 AM10/2/12
to mathja...@googlegroups.com
Thank you all, ReText is now using <body class="tex2jax_ignore>.

By the way, if someone also wants to use MathJax within Markdown, the
code is available here:
http://bazaar.launchpad.net/~mitya57/python-markups/trunk/view/head:/markups/markdown.py

--
Dmitry Shachnev

On Mon, Oct 1, 2012 at 2:02 AM, Davide P. Cervone <dp...@union.edu> wrote:
> Fred has already pointed you to the documentation on this.
>
> There are two approaches that would probably work for you. The first is to
> use MathJax's ignoreClass and processClass values to control the tex2jax
> processing (assuming your input is TeX). Set processClass to include the
> "math" class, and add class="tex2jax_ignore" to the BODY element in your
> document (or put a <div class="tex2jax_ignore"> around the contents of the
> page). This will cause tex2jax to only look for math in the containers that
> have class="math".
>
> Alternatively, if you are able to recognize the mathematics yourself
> already, you could decide not to use tex2jax at all, and mark the
> mathematics directly using the <script> tags that MathJax uses for storing
> the math on the page. Use <script type="math/tex">...</script> for in-line

jmlop...@gmail.com

unread,
Mar 6, 2014, 6:48:32 PM3/6/14
to mathja...@googlegroups.com
Hi Davide, you pointed out that if we can use the script tags ourselves and not
use the preprocessor. I'm currently including mathjax as follows:

http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full

so that I can use all the macros included with AMS. The question is, how do I disable
tex2jax? My current solution is to configure it as follows:

    tex2jax: {
       inlineMath: []
       displayMath: []
       processEscapes: false,
       processEnvironments: false,
       balanceBraces: false,
       skipTags: ["body"],
    },

Is there something I just cannot see from the documentation?

Dmitry Shachnev

unread,
Mar 8, 2014, 3:51:04 AM3/8/14
to mathja...@googlegroups.com
Hi,

On Fri, Mar 7, 2014 at 3:48 AM, <jmlop...@gmail.com> wrote:
> Hi Davide, you pointed out that if we can use the script tags ourselves and
> not
> use the preprocessor. I'm currently including mathjax as follows:
>
> http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full
>
> so that I can use all the macros included with AMS. The question is, how do
> I disable
> tex2jax? My current solution is to configure it as follows:
>
> tex2jax: {
> inlineMath: []
> displayMath: []
> processEscapes: false,
> processEnvironments: false,
> balanceBraces: false,
> skipTags: ["body"],
> },

Provide your own set of extensions, i.e.:

extensions: ["MathMenu.js", "MathZoom.js"],

--
Dmitry Shachnev

Davide P. Cervone

unread,
Mar 17, 2014, 9:58:13 AM3/17/14
to mathja...@googlegroups.com
The combined configuration files that include the TeX input processor also include the tex2jax preprocessor, and so it will get installed as a preprocessor automatically when you load that file.  In order to really disable it, you would have to remove it from the preprocessor list.  In fact, in your case, you will get both the tex2jax and mml2jax preprocessors, since this configuration file processes both MathML and TeX.  So you might want to clear the entire preprocessor list.

To do that, you can use

<script type="text/x-mathjax-config">
while (MathJax.Hub.preProcessors.hooks.length) {
  MathJax.Hub.preProcessors.Remove(MathJax.Hub.preProcessors.hooks[0]);
}
</script>

This clears all the preprocessors.  So you don't need to include configuration for tex2jax in that case.

As for why your configuration didn't prevent the preprocessor, I think you also need to set

processRefs: false

in order to disable all its features.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages