MathJax minimal install

2,364 views
Skip to first unread message

Carlos Miguel Jenkins Pérez

unread,
Nov 8, 2011, 5:07:11 PM11/8/11
to MathJax Users
Hi!

We love MathJax, and at the college we want to start using it with a
software we are developing. The software produces local html files not
expected to be loaded to a web server, and that can be used without
internet connection.

So we are putting MathJax aside those html files and using it locally.
Everything works great. The problem is that the default download of
MathJax has 30 573 elements and is 18,2 MB. So, each project is huge,
of course (have you tried to copy 30 573 files? It's slow :P)

So we are trying to configure a minimal MathJax installation, removing
all the files that are not absolutely needed for our setup.

We just need these:

- To work on very recent Chrome/Chromium, very recent Firefox or
Internet Explorer 9.
- Always to use HTML+CSS output (removing MathML support).
- Input is always Tex/Latex.

This is our config:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
imageFont: null,
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
});
</script>

Until now, I removed everything except:

extensions/
fonts/ (eot, svg, otf)
jax/
MathJax.js

And is working so far so good: 498 elements, 3,3 MB total

However, I want to shrink the library further. In particular, I tried
to remove:

jax/element

But then the math stopped rendering in Firefox.

jax/output/NativeMML

Good. But as the option 'Right click -> Settings -> Math Renderer ->
MathML' still there and I don't how to remove it from the menu.

Do you have any advice on how to setup this in a better way, or what
files and configuration may I use to shrink it even more?

Thank you in advance.

leathrum

unread,
Nov 8, 2011, 6:27:29 PM11/8/11
to MathJax Users
Try "showRenderer: false" in the MathMenu config object to get rid of
the MathML/HTML-CSS menu option:

http://www.mathjax.org/docs/1.1/options/MathMenu.html

Otherwise, it looks like you are doing the right kinds of experiments
to find the right minimal custom install for your purposes. You may
be able to eliminate some of the font options, but you have already
gotten rid of the image files which give the font fallbacks, and which
are by far the biggest space hogs, so you may be nearing a practical
limit.

On Nov 8, 4:07 pm, Carlos Miguel Jenkins Pérez <car...@jenkins.co.cr>
wrote:

Sean Hogan

unread,
Nov 11, 2011, 4:20:35 PM11/11/11
to mathja...@googlegroups.com, Carlos Miguel Jenkins Pérez
You don't need the svg fonts for up-to-date Chrome.
You may be able to disable STIX font support and remove
jax/output/HTML-CSS/fonts/STIX

Sean

Davide P. Cervone

unread,
Nov 13, 2011, 11:39:42 AM11/13/11
to mathja...@googlegroups.com
> So we are trying to configure a minimal MathJax installation, removing
> all the files that are not absolutely needed for our setup.

So far you have done pretty well with removing what is not needed.

> This is our config:
>
> <script type="text/x-mathjax-config">
> MathJax.Hub.Config({
> imageFont: null,
> extensions: ["tex2jax.js"],
> jax: ["input/TeX","output/HTML-CSS"],
> tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
> });
> </script>
>
> Until now, I removed everything except:
>
> extensions/
> fonts/ (eot, svg, otf)
> jax/
> MathJax.js
>
> And is working so far so good: 498 elements, 3,3 MB total

As Sean suggested, the fonts/HTML-CSS/TeX/svg directory can also be
removed, as it is needed only for very old versions of Chrome, and
pretty old versions of iOS. This should save you about 1.1MB.

> However, I want to shrink the library further. In particular, I tried
> to remove:
>
> jax/element
>
> But then the math stopped rendering in Firefox.

The element jax is a core component (it implements the internal format
used by MathJax, and so nothing will work without it).

> jax/output/NativeMML
>
> Good. But as the option 'Right click -> Settings -> Math Renderer ->
> MathML' still there and I don't how to remove it from the menu.

I think someone already mentioned that you could add

MathMenu: { showRenderer: false }

to your configuration in order to remove the Renderer submenu.

> Do you have any advice on how to setup this in a better way, or what
> files and configuration may I use to shrink it even more?

There are still some files that can be removed. For example:

extensions/FontWarnings.js
extensions/jsMath2jax.js
extensions/mml2jax.js
extensions/v1.0-warnings

If you really want everything, you can also remove

extensions/TeX/autobold.js
extensions/TeX/noErrors.js
extensions/TeX/noUndefined.js
extensions/AMSsymbols.js

since you aren't using those and they don't get loaded automatically
when needed. (You might want to keep AMSsymbols, however, if that is
something you are likely to use later. The only other extension of
any size is AMSmath.js, but this one IS loaded automatically when
needed, so if you use AMS math environments, for example, you can't
get rid of that one.)

You can also remove jax/input/MathML if you haven't already (you
didn't list it as something you removed).

There are some pieces of the HTML-CSS output jax that can also go.
For example

jax/output/HTML-CSS/autoload/annotation-xml.js
jax/output/HTML-CSS/autoload/maction.js
jax/output/HTML-CSS/autoload/mglyph.js
jax/output/HTML-CSS/autoload/mmultiscripts.js
jax/output/HTML-CSS/autoload/ms.js

and probably

jax/output/HTML-CSS/autoload/menclose.js

though if you have added the \cancel command, the implementation I
suggested for that did use menclose, so you would need to keep that.

You can also get rid of

jax/output/HTML-CSS/imageFonts.js

since you are not going to use that.

The other big chunk of space is taken up by the HTML-CSS font metric
data. MathJax includes data for the STIX fonts, as well as its own
web-based fonts. If you are not using the \unicode{} macro, then you
can get away with using just the MathJax web fonts, and so you can
remove the (large) directory

jax/output/HTML-CSS/fonts/STIX

which will save you about 840KB. If you do, however, you will have to
add

"HTML-CSS": {
availableFonts: ["TeX"],
preferredFont: "TeX",
imageFont: null
}

to your configuration (note that the imageFont value must be in the
"HTML-CSS" section, not the main section, in any case). The one
caveat about doing this, however, is that you may have trouble with
Firefox's same-origin policy, which may prevent it from accessing the
web-based fonts. If you can put the MathJax directory in the same
directory as the HTML files that use it, then you should be OK, but
otherwise, MathJax will try to use the image fonts when you load a
file:// URL, and they won't be available. The alternative would be to
have your users install the MathJax fonts as system fonts, avoiding
the need to use web-based fonts.

Finally, you can remove

jax/output/HTML-CSS/fonts/TeX/Caligraphic/Regular/Main.js
jax/output/HTML-CSS/fonts/TeX/Greek/Bold/Main.js
jax/output/HTML-CSS/fonts/TeX/Greek/Italic/Main.js
jax/output/HTML-CSS/fonts/TeX/Greek/Regular/Main.js
jax/output/HTML-CSS/fonts/TeX/Main/Bold/Main.js
jax/output/HTML-CSS/fonts/TeX/Main/Italic/Main.js
jax/output/HTML-CSS/fonts/TeX/Main/Regular/Main.js
jax/output/HTML-CSS/fonts/TeX/Math/Italic/Main.js
jax/output/HTML-CSS/fonts/TeX/Size1/Regular/Main.js
jax/output/HTML-CSS/fonts/TeX/Size2/Regular/Main.js
jax/output/HTML-CSS/fonts/TeX/Size3/Regular/Main.js
jax/output/HTML-CSS/fonts/TeX/Size4/Regular/Main.js
jax/output/HTML-CSS/fonts/TeX/WinChrome/Regular/Main.js

(about 31KB) as well, as this data is already included in the jax/
output/HTML-CSS/fonts/TeX/fontdata.js file.

I think that is pretty much all that can be removed while still
allowing MathJax to function.

Davide

Carlos Jenkins

unread,
Nov 13, 2011, 2:37:49 PM11/13/11
to mathja...@googlegroups.com
Hi everyone,

Thank you very much for your help. Davide, that's was a awesome post and it helped me very much. I've implemented your recommendations and everything works perfectly in just 202 elements, 1,5 MB total, which is just great.

From all of them, I just didn't remove:

extensions/AMSsymbols.js
jax/output/HTML-CSS/autoload/menclose.js

I also removed:

jax/output/HTML-CSS/fonts/TeX/WinIE6

I assumed it was for IE6. It's ok? Math still rendering on Firefox, Chromium and IE9.

And attaching the current a layout of my installation tree. Also, this is the current config:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
    menuSettings: {zoom: "Double-Click", zscale: "300%"},
    tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]},
    MathMenu: {showRenderer: false},
    "HTML-CSS": {
        availableFonts: ["TeX"],
        preferredFont: "TeX",
        imageFont: null
    }
  });
</script>

Again, thank you very much.
tree.txt

Davide P. Cervone

unread,
Nov 13, 2011, 7:47:33 PM11/13/11
to mathja...@googlegroups.com
Glad you are pleased with the results.  Yes, you should also be able to remove the WinIE6 data, (and also the .eot and .otf versions of the font).  That should save you a little more, and should get you to 200 elements, a nice round number.

If you are going to use the AMSsymbols and AMSmath extensions, you might want to add them to the configuration using

TeX: { extensions: ["AMSmath.js","AMSsymbols.js"] },

so they are loaded and available when you need them.

Davide


<tree.txt>

bkra...@gmail.com

unread,
Dec 6, 2012, 3:14:51 PM12/6/12
to mathja...@googlegroups.com, car...@jenkins.co.cr
Carlos,

It looks like you have been doing what I am hoping to do with MathJax.  I followed your installation tree but I can't seem to get the MathML to display correctly.  Did you also delete the config folder and config files from the root?  If so, what script block did you put in the site to "import" the MathJax.js file and what config file are you pointing to?

I followed everything else to the T but I must be missing something in the script tag for my site to use the MathJax in the first place.


Thanks,
Brian

bkra...@gmail.com

unread,
Dec 6, 2012, 3:31:48 PM12/6/12
to mathja...@googlegroups.com, car...@jenkins.co.cr, bkra...@gmail.com
For Example, I tried to import like so:

<script type="text/javascript" src="/Scripts/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

And I kept the default config folder in with the mathjax project.  It looked like, in your project, you removed the config folder...if that is the case, how are you importing?

Carlos Jenkins

unread,
Dec 7, 2012, 4:47:55 AM12/7/12
to bkra...@gmail.com, MathJax Users
Hi Brian,

The modified MathJax tree is here:


Please keep in mind that is an old tree and would worth the update, but as is it work perfectly for my requirements.

Please check the tree, in particular the file include.html which is the way I include MathJax. If you have other questions they are welcome.

Kind regards

bkra...@gmail.com

unread,
Dec 7, 2012, 10:32:16 AM12/7/12
to mathja...@googlegroups.com, bkra...@gmail.com, car...@jenkins.co.cr
Carlos thanks for posting this!  I am still struggling to get this to work and I can't figure out why.  I'm wondering if my input is different.  Here is an example of the MathML mark up I'm using:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
              <mrow>
                <mover accent="true">
                  <mrow>
                    <mo>&#x2207;</mo>
                  </mrow>
                  <mrow>
                    <mo>&#x2192;</mo>
                  </mrow>
                </mover>
                <mo>&#xD7;</mo>
                <mover accent="true">
                  <mrow>
                    <mi>F</mi>
                  </mrow>
                  <mrow>
                    <mo>&#x2192;</mo>
                  </mrow>
                </mover>
                <mo>=</mo>
                <mrow>
                  <mo>(</mo>
                  <mfrac>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <msub>
                        <mrow>
                          <mi>F</mi>
                        </mrow>
                        <mrow>
                          <mi>z</mi>
                        </mrow>
                      </msub>
                    </mrow>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <mi>y</mi>
                    </mrow>
                  </mfrac>
                  <mo>&#x2212;</mo>
                  <mfrac>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <msub>
                        <mrow>
                          <mi>F</mi>
                        </mrow>
                        <mrow>
                          <mi>y</mi>
                        </mrow>
                      </msub>
                    </mrow>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <mi>z</mi>
                    </mrow>
                  </mfrac>
                  <mo>)</mo>
                </mrow>
                <mstyle mathvariant="bold" mathsize="normal">
                  <mrow>
                    <mi>i</mi>
                  </mrow>
                </mstyle>
                <mo>+</mo>
                <mrow>
                  <mo>(</mo>
                  <mfrac>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <msub>
                        <mrow>
                          <mi>F</mi>
                        </mrow>
                        <mrow>
                          <mi>x</mi>
                        </mrow>
                      </msub>
                    </mrow>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <mi>z</mi>
                    </mrow>
                  </mfrac>
                  <mo>&#x2212;</mo>
                  <mfrac>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <msub>
                        <mrow>
                          <mi>F</mi>
                        </mrow>
                        <mrow>
                          <mi>z</mi>
                        </mrow>
                      </msub>
                    </mrow>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <mi>x</mi>
                    </mrow>
                  </mfrac>
                  <mo>)</mo>
                </mrow>
                <mstyle mathvariant="bold" mathsize="normal">
                  <mrow>
                    <mi>j</mi>
                  </mrow>
                </mstyle>
                <mo>+</mo>
                <mrow>
                  <mo>(</mo>
                  <mfrac>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <msub>
                        <mrow>
                          <mi>F</mi>
                        </mrow>
                        <mrow>
                          <mi>y</mi>
                        </mrow>
                      </msub>
                    </mrow>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <mi>x</mi>
                    </mrow>
                  </mfrac>
                  <mo>&#x2212;</mo>
                  <mfrac>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <msub>
                        <mrow>
                          <mi>F</mi>
                        </mrow>
                        <mrow>
                          <mi>x</mi>
                        </mrow>
                      </msub>
                    </mrow>
                    <mrow>
                      <mo>&#x2202;</mo>
                      <mi>y</mi>
                    </mrow>
                  </mfrac>
                  <mo>)</mo>
                </mrow>
                <mstyle mathvariant="bold" mathsize="normal">
                  <mrow>
                    <mi>k</mi>
                  </mrow>
                </mstyle>
              </mrow>
            </math>

David Carlisle

unread,
Dec 7, 2012, 11:26:55 AM12/7/12
to mathja...@googlegroups.com, bkra...@gmail.com, car...@jenkins.co.cr
On 7 December 2012 15:32, <bkra...@gmail.com> wrote:
> Carlos thanks for posting this! I am still struggling to get this to work
> and I can't figure out why. I'm wondering if my input is different.


the test.html example that you were replying to shows a cut down
mathjax config that has

MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],


so it only accepts tex-like input and only uses html/css for output.
Your input is mathml so doesn't need the tex input jax but does need
the mml2jax something more like

jax: ["input/MathML","output/HTML-CSS"],
extensions: ["mml2jax.js","MathZoom.js"],


David




--
http://dpcarlisle.blogspot.com/

bkra...@gmail.com

unread,
Dec 9, 2012, 11:09:14 PM12/9/12
to mathja...@googlegroups.com, bkra...@gmail.com, car...@jenkins.co.cr
Thanks David,

I feel like I'm sooooo close but I must be missing something.  I've tweaked my config statement to include what I need for both input and output, but for some reason MathJax is now bombing on its attempt to load MathMenu and MathZoom js files.  They are both in the appropriate location, but I get a 404 not found.  As I looked through the "unpacked" code that comes with the MathJax framework it looks like its attempting to look for these files at [MathJax]/extensions/MathMenu.js etc and I have them in the extensions folder.  I just don't know how this [MathML] paramenter is being created within the framework, because it finds my mml2jax.js which is in the same exact directory.

Any ideas with how to solve the Menu and Zoom problem?

Also as a side note, I did attempt to bypass this by setting up my config a little differently and I don't get the 404, however nothing seems to happen either in terms of re-rendering the MathML via MathJax so at this point I'm pretty stumped.

<script type="text/x-mathjax-config">
    
    MathJax.Hub.Config({
      extensions: ["mml2jax.js"],
      jax: ["input/MathML","output/HTML-CSS"],
      showMathMenu: false,
      "HTML-CSS": {
        availableFonts: ["TeX"],
        preferredFont: "TeX",
        imageFont: null
      }
    });
 
    MathJax.Hub.Startup.MenuZoom = function () {};
 
</script>
<script type="text/javascript" src="../../Scripts/mathjax/MathJax.js"></script>


Any hints/tips/pointers etc would be greatly appreciated since I feel like I've been battling this for a few days now. I just wanna get this working and move on!


Humbly,
Brian

bkra...@gmail.com

unread,
Dec 10, 2012, 1:30:22 PM12/10/12
to mathja...@googlegroups.com, bkra...@gmail.com, car...@jenkins.co.cr
FINALLY got it to work.  In the event someone else out there is attempting to used the slimmed down version of the MathJax framework w/ MML as an input here is my config.  I was getting 404's on the MathEvents, MathMenu, MathZoom js files so I had to override the root property.  Once I did that, everything started working.

Hope this helps someone out there.

<script type="text/x-mathjax-config">
    
    MathJax.Hub.Config({
      root: "/Scripts/mathjax",
      extensions: ["mml2jax.js"],
      jax: ["input/MathML","output/HTML-CSS"],
      menuSettings: {zoom: "Double-Click", zscale: "300%"},
      MathMenu: {showRenderer: false},
      "HTML-CSS": {
        availableFonts: ["TeX"],
        preferredFont: "TeX",
        imageFont: null
      }
    });
 
</script>
<script type="text/javascript" src=""../../Scripts/mathjax/MathJax.js"></script>

Davide Cervone

unread,
Dec 18, 2012, 9:09:09 PM12/18/12
to mathja...@googlegroups.com
Sorry I wasn't able to get back to you on this in a timely fashion, but glad you got it to work.  Relative URL's do sometimes cause MathJax trouble in finding the correct root directory, and setting the root property as you did can overcome that.  Not sure why SOME files could be loaded, though, and not others.  That is weird.  Anyway, thanks for sharing your solution.

Davide

kids...@gmail.com

unread,
Feb 25, 2014, 3:27:55 PM2/25/14
to mathja...@googlegroups.com, car...@jenkins.co.cr
When I kept only the files mention on the tree.txt, on google chrome it showed an error "can't load tex/math/italic". Took slightly a long time to show the math formula

Peter Krautzberger

unread,
Feb 25, 2014, 3:37:25 PM2/25/14
to mathja...@googlegroups.com, car...@jenkins.co.cr
Hi,

This is a bug in Chrome 32. There will be a workaround in the next release. See https://github.com/mathjax/MathJax/issues/735

Regards,
Peter


--
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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages