Changing the render programmatically

709 views
Skip to first unread message

free.thought

unread,
Mar 27, 2011, 1:44:40 PM3/27/11
to MathJax Users
Which commands can I call to switch between the HTML-CSS and MathML
renderers programmatically, without going through the right-click
menu? I don't think this is covered in the documentation.

The right-click menu is not showing up in some situations, so I need
to change the renderer directly. Is that easy enough?

Many thanks

Davide P.Cervone

unread,
Mar 28, 2011, 8:40:09 AM3/28/11
to mathja...@googlegroups.com
See the code example given in the discussion at

http://groups.google.com/group/mathjax-users/browse_thread/thread/653a992e67d34ee7/6a49b66fb6645f00?hl=ena49b66fb6645f00

Can you be more specific about the cases where the menu doesn't show
up? What browser, what version, and what OS? And what version of
MathJax?

Opera has a known bug that causes it not to properly handle the menu
in some cases (see https://github.com/mathjax/MathJax/issues#issue/
48), but I'm not aware of any other menu problems.

Davide

projetmbc

unread,
Mar 28, 2011, 9:48:59 AM3/28/11
to MathJax Users
Hello,
take a look at the source code of this page http://www.mathjax.org/demos/mathml-samples/
.

Christophe.

free.thought

unread,
Mar 28, 2011, 1:57:02 PM3/28/11
to MathJax Users
Davide and Christophe, Thank you for the pointers, I think I should be
able to figure it from there.

Davide: I don't think it is a bug, so nothing to be concerned about. I
am just doing something that is not an intended application of
MathJax. But here is what happens in my application (GmailTeX Firefox
addon):

If the renderer is initially set to MathML, everything works fine, as
expected. The Math Menu shows up and I am able to change the renderer
if I wish.

But if the renderer is HTML-CSS, and MathJax is served from a local
directory, and no fonts are provided (image fonts are too large to
include in the addon, and other fonts are not recognized by Firefox as
far as I can see) then I get the [Math Processing Error] error in
red.

Clicking on this error does not bring up the menu, unlike the in the
previous case. Perhaps this behavior could be changed?

By the way, am I correct that Chrome is able to use otf and svg fonts
(which are quite small so can be included with the addon) but Firefox
only the img fonts (which are too large for me to include)?

Davide P. Cervone

unread,
Mar 29, 2011, 1:55:30 PM3/29/11
to mathja...@googlegroups.com
If the renderer is initially set to MathML, everything works fine, as
expected. The Math Menu shows up and I am able to change the renderer
if I wish.

But if the renderer is HTML-CSS, and MathJax is served from a local
directory, and no fonts are provided (image fonts are too large to
include in the addon, and other fonts are not recognized by Firefox as
far as I can see) then I get the [Math Processing Error] error in
red.

Clicking on this error does not bring up the menu, unlike the in the
previous case.

Right, the error message doesn't have the menu associated with it.  It has been on my list of things to fix, but I haven't gotten to it.


Perhaps this behavior could be changed?

Yes, it would be good to have the menu accessible there as well, so that users can change things back if they make a change that causes a problem like this.  

Have you set the imageFont parameter to null in the HTML-CSS block of your configuration?  If not, you might want to do that if you are not providing the image fonts.  

By the way, am I correct that Chrome is able to use otf and svg fonts
(which are quite small so can be included with the addon) but Firefox
only the img fonts (which are too large for me to include)?

If you are loading MathJax from a file:// URL, then firefox will use the image fonts.  They have a pretty script same-origin policy and it doesn't allow loading web-based fonts from a directory that isn't the same as (or a subdirectory of) the one where the HTML page is taken from.  Not sure how this applies to plug-ins, so MathJax's logic may be off in your case.  Of course, if you install the fonts locally in your system fonts folder that will avoid the problem entirely.

Davide

albert...@gmail.com

unread,
Jan 20, 2013, 8:31:57 AM1/20/13
to mathja...@googlegroups.com
Dear All,

I'm posting to this message as I think it fits best to this.
I'm trying to set the SVG renderer programatically in the startup section of my code, but I cannot getting it to work, probably due to a lack of knowledge on my side.
In the HTML the following is present by default:
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/SVG"],
   });
</script>

I've tried to place code for changing the renderer behind this but I could not get it to work.
Can anybody give me a hand?

In advance thanks,

Albert

Frédéric WANG

unread,
Jan 31, 2013, 3:37:13 AM1/31/13
to mathja...@googlegroups.com
On 20/01/2013 14:31, albert...@gmail.com wrote:
> Dear All,
>
> I'm posting to this message as I think it fits best to this.
> I'm trying to set the SVG renderer programatically in the startup
> section of my code, but I cannot getting it to work, probably due to a
> lack of knowledge on my side.
> In the HTML the following is present by default:
> <script type="text/x-mathjax-config">
> MathJax.Hub.Config({
> extensions: ["tex2jax.js"],
> jax: ["input/TeX","output/SVG"],
> });
> </script>
>
> I've tried to place code for changing the renderer behind this but I
> could not get it to work.
> Can anybody give me a hand?
>
> In advance thanks,
>
> Albert
You have a comma at the end of your config options, old versions of
Internet Explorer may interpret this as an error. I have not tried, but
what about:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/SVG"]
});
MathJax.Hub.Queue(["setRenderer", MathJax.Hub, "SVG"]);
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
</script>

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

Davide P. Cervone

unread,
Jan 31, 2013, 8:48:38 AM1/31/13
to mathja...@googlegroups.com
You also don't say whether you have used config=... on the script tag that loads MathJax.js.  If you do, that will be processed first, and the output set by it will take precedence over the jax you have here (though the SVG output jax will be loaded).

Since you are using TeX input and SVG output, why not just use


which will load the TeX (and MathML) input jax and use the SVG output?

Fred's suggestion will also work, if you change "Typeset" to "Rerender".  As it currently stands, the renderer will be changed after the initial typesetting is done, and then the Typeset call will be made again, but it only affects NEW math (not math already processed), so noting will seem to happen.  Even with "Rerender", this is not very efficient, as the math will be rendered twice.  Finally, it prevents users from using the MathJax contextual menu to select the renderer they prefer, as you explicitly override that with setRenderer.

So I'd recommend loading the proper predefined configuration file in the first place.

Davide

albert...@gmail.com

unread,
Feb 6, 2013, 2:36:31 PM2/6/13
to mathja...@googlegroups.com
Dear Fred and Davide,

Many thanks for your responses, brought me much closer to where I want to be. Reducing the MathJax directory and only offer the SVG output option.
I now have:

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

  }
  });
    MathJax.Hub.Queue(["setRenderer", MathJax.Hub, "SVG"]);
    MathJax.Hub.Queue(["Rerender", MathJax.Hub]);
</script>

From the MathJax directory I removed:
LICENSE
README-branch.txt
README.md
docs
fonts
test
unpacked

giving me quite a bit of reduction of required disk space. The loading goes OK only I still see the message: "Can't find a valid font using [STIX, TeX]"

Any hints on this one ?

In advance thanks,

Albert

Frédéric WANG

unread,
Feb 6, 2013, 2:51:23 PM2/6/13
to mathja...@googlegroups.com

> giving me quite a bit of reduction of required disk space. The loading
> goes OK only I still see the message: "Can't find a valid font using
> [STIX, TeX]"
>
> Any hints on this one ?
>
> In advance thanks,
>
> Albert

This looks an error message from the HTML-CSS output. If you really only
want to use only the SVG ouput, you'd better set the configuration
option to the SVG output in the config line, as Davide suggested. What
is the javascript line you used to load MathJax.js?

--
Fr�d�ric Wang
maths-informatique-jeux.com/blog/frederic

albert...@gmail.com

unread,
Feb 6, 2013, 2:53:14 PM2/6/13
to mathja...@googlegroups.com
Dear Fred,

Thank you for the quick reply.

I'm using:
</script><script src="../../MathJax/MathJax.js"></script>
changing it to:
</script><script src="../../MathJax/MathJax.js?config=TeX-AMS-MML_SVG"></script>
gives still the same message.

Best Regards,

Albert


On Wednesday, February 6, 2013 8:51:23 PM UTC+1, fred wrote:

> giving me quite a bit of reduction of required disk space. The loading
> goes OK only I still see the message: "Can't find a valid font using
> [STIX, TeX]"
>
> Any hints on this one ?
>
> In advance thanks,
>
> Albert

This looks an error message from the HTML-CSS output. If you really only
want to use only the SVG ouput, you'd better set the configuration
option to the SVG output in the config line, as Davide suggested. What
is the javascript line you used to load MathJax.js?

--
Fr�d�ric Wang
maths-informatique-jeux.com/blog/frederic

Davide P. Cervone

unread,
Feb 6, 2013, 3:01:50 PM2/6/13
to mathja...@googlegroups.com
Perhaps you have a MathJax cookie that sets the render to HTML-CSS (if you used the MathJax contextual menu to set the renderer in the past, that may still be in effect).  Try removing cookies (or look for the one whose name begins with "mjx").

PS, you can combine all your configuration blocks into one:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/SVG"],
    menuSettings: {
      showRenderer: false
    }
    "HTML-CSS": {
      imageFont: null
    }
  });
  MathJax.Hub.Queue(["setRenderer", MathJax.Hub, "SVG"]);
  MathJax.Hub.Queue(["Rerender", MathJax.Hub]);
</script> 

Note, however, that the HTML-CSS block should not be necessary (since you are loading only the SVG output jax, and disabling the user's ability to change renderers.  Also, the setRenderer and Rerender commands should not be necessary, since SVG should be what is selected automatically but this configuration.  I suspect the cookie is the culprit for you.

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

albert...@gmail.com

unread,
Feb 6, 2013, 3:18:58 PM2/6/13
to mathja...@googlegroups.com
Dear Davide,

Thank you for the answer, yes the cookie is the culprit. When I remove the cookie it works indeed without error message, but I don't have control over other computers to remove the cookie beforehand and I don't see a way to change the cookie.
When having HTML-CSS in the cookie and not the HTML-CSS imageFont:null stetting the loading takes 'incredibly' long. around 15 seconds and it is just a small page with 2 formulas.

Best Regards,

Albert

albert...@gmail.com

unread,
Feb 6, 2013, 3:49:04 PM2/6/13
to mathja...@googlegroups.com, albert...@gmail.com
Dear Davide, Fred,

Looks like I solved the cookie problem, placed the line:
MathJax.HTML.Cookie.Set("menu",{renderer:"SVG"});

albert...@gmail.com

unread,
Feb 6, 2013, 3:52:29 PM2/6/13
to mathja...@googlegroups.com, albert...@gmail.com
Dear Davide, Fred,

Something went wrong with the previous post, sorry.

Looks like I solved the cookie problem, placed the line:
  MathJax.HTML.Cookie.Set("menu",{renderer:"SVG"});
so this sets SVG in the cookie and thus removes the error message. I still have to experiment a bit with the Cookie.Get so I can retain the other settings from the user.

Albert

Davide P. Cervone

unread,
Feb 6, 2013, 4:03:36 PM2/6/13
to mathja...@googlegroups.com
> Thank you for the answer, yes the cookie is the culprit. When I remove the cookie it works indeed without error message, but I don't have control over other computers to remove the cookie beforehand and I don't see a way to change the cookie.

If they haven't visited your site before, they will not have a cookie for it. So if this is a new site, you should not have any problem. If it is an existing one that has been using MathJax in the past, then you might have an issue, but it is unlikely that anyone would have set the renderer themselves (unlike you, who were testing the site for different renderings).

> When having HTML-CSS in the cookie and not the HTML-CSS imageFont:null stetting the loading takes 'incredibly' long. around 15 seconds and it is just a small page with 2 formulas.

This is because MathJax has tried to load one of the files you removed, and it is waiting for it to arrive. It has a 15 second timeout, which accounts for the 15 second delay you are seeing. leaving the HTML-CSS block in place is fine. It won't hurt anything, just takes up a little space.

Davide

Davide P. Cervone

unread,
Feb 6, 2013, 4:10:33 PM2/6/13
to mathja...@googlegroups.com
I considered suggesting that, but I really don't think it is going to be an issue for you, as I mentioned in my previous message.

If you really want to do that, you should first get the menu cookie, check if the renderer is not SVG, and if so, set the renderer in the returned structure and set the cookie to the modified structure.

Davide

albert...@gmail.com

unread,
Feb 6, 2013, 4:11:02 PM2/6/13
to mathja...@googlegroups.com
Dear Davide,

Well the site is not new so the cookie might have been set already. It is also possible that it is set by another site that uses MathJax. So I'd like to be on the safe side.

Still struggling a bit with the cookie business (and leaving the rest in place). Any suggestion? (it is a bit off topic as it is in fact a lack my knowledge)

Albert

Davide P. Cervone

unread,
Feb 6, 2013, 4:13:00 PM2/6/13
to mathja...@googlegroups.com
Since cookies are site-specific (actually server-specific), setting the cookie on another site will not affect yours (unless there are other sites on your server).  So you only have to worry about people having set it on your site.

I sent you some hints in my previous message (written while you were replying to mine).

Davide


albert...@gmail.com

unread,
Feb 6, 2013, 4:19:39 PM2/6/13
to mathja...@googlegroups.com
Dear Davide,

Thanks for the answer.
I saw your answer:

> If you really want to do that, you should first get the menu cookie, check if the renderer is not SVG, and if so, set the renderer in the returned structure and set the cookie to the modified structure.
but like I wrote I have to figure this out, so actually dive into js and see how to do it.

Albert

Davide P. Cervone

unread,
Feb 6, 2013, 4:41:32 PM2/6/13
to mathja...@googlegroups.com
Try 

<script type="text/x-mathjax-config">
(function () {
  cookie = MathJax.HTML.Cookie.Get("menu");
  if (cookie.renderer && cookie.renderer !== "SVG") {
    cookie.renderer = "SVG";
    MathJax.HTML.Cookie.Set("menu",cookie);
  }
})();
</script>

This gets the menu cookie, checks if the renderer is already set, and if so, sets it to SVG if it isn't already.

Davide

albert...@gmail.com

unread,
Feb 6, 2013, 4:49:41 PM2/6/13
to mathja...@googlegroups.com
Dear Davide,

Thank you very very much, works like a charm.

Albert
Reply all
Reply to author
Forward
0 new messages