Is there a way to ignore/negate an in-line configuration?

29 views
Skip to first unread message

Rachael Verbruggen

unread,
Apr 12, 2016, 8:56:08 AM4/12/16
to MathJax Users

Hello,


I am working in a learning management system (LMS). They have their own call to MathJax as well as their own in-line configuration that loads on each page. However, many of their settings are not useful to me. I can counteract them by putting my own in-line configuration* that puts the settings back to what I want. The problem with this is that I have to do this on every page, and they sometimes change their configuration, so I have to go through every page and make updates.

 

*To give a little bit of information, if I use an in-line configuration without a call to MathJax, it uses the version of MathJax that is called by the LMS. If, however, I put in my own call to MathJax, it uses the version I chose instead. If I put my own in-line configuration in the head of my file, it works in IE, but nowhere else. If I put my own in-line configuration in the body of my file, it works in Chrome, FF, and Safari, but not IE. This means I have an in-line configuration in both the head and the body on every single page that I use MathJax on (perhaps not the best solution, but it works for whatever reason and I have't been able to find a different solution).

 

I’d think I'd like to keep my configuration outside of the individual pages so that I only have to change it in one place, instead of on each page. However, when I pull the configuration out into a local js file, it works outside of the LMS, but when I put it in the LMS, the in-line configuration for the LMS seems to overwrite my configuration (or it doesn’t work for some other reason). I have tried a couple of different options: I tried using a local config file with the CDN and giving the full URL(http://docs.mathjax.org/en/latest/configuration.html#using-a-local-configuration-file-with-the-cdn); and I tried a relative path to the config file as discussed recently on the user group (https://groups.google.com/forum/#!topic/mathjax-users/cbRwI58nqeg).  As I said, I got both of these working outside of the LMS, but as soon as I put them into the LMS, their in-line configuration takes over. Unfortunately, because I’m working in an LMS I can’t provide a useful “working” example.


Is there any thing different I can do so that the poor choices that the LMS is making don’t negatively affect me?


Thanks,

Rachael

Peter Krautzberger

unread,
Apr 15, 2016, 8:53:45 AM4/15/16
to mathja...@googlegroups.com
Hi Rachael,

If I understand you, there are two questions.

a) can you ignore other configurations
b) how to set up a configuration file 

For a), I think that depends on how much control you have. If your configuration enters the page before the LMS's configuration (i.e., is higher up in the document), then your configuration would be overwritten. I guess you could try to remove MathJax after it's loaded and then inject a new MathJax script (but that seems awful to me).

For b), it's difficult to say much without some code samples (html and js, e.g., mockups on codepen or jsbin).

It's a little odd that you are able to inject JavaScript but cannot modify the original JS. Maybe you can convince the LMS admins to work with you to make custom configurations easier.

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/d/optout.

Rachael Verbruggen

unread,
Apr 15, 2016, 3:34:03 PM4/15/16
to MathJax Users

Thanks for your response. I didn’t have high hopes.

 

I think my question was mostly a). I really don’t have a lot of control. I believe that my configuration comes after the LMS’s configuration. If I put my configuration in-line on my page, it overwrites the LMS’s configuration. However, if I pull my configuration out into a file, then it seems that the LMS’s configuration takes precedence.

 

I think I have b) figured out.

 

My workflow up to now has been to wait until the LMS changes their configuration and then go and undo the weird things they do (for example, make the math font 130%) in my inline configuration for each file. I was hoping to be proactive and either negate the LMS’s configuration so I don’t have to worry about changes , or keep my configuration in a separate file so I only have to change my configuration in one place, but it sounds like this isn’t possible – or at least not easy, so I will just continue  to do things the way I have been.


Rachael

Murray

unread,
Apr 16, 2016, 3:55:38 AM4/16/16
to MathJax Users
Rachael

What LMS is it?

I have mostly been required to work in Blackboard. Long ago I gave up trying to fight with it (and the admin's "enlightened" settings) and do all my development in a separate "Web Folder" (which is a space free of all of Blackboard's JS, CSS, frames and so on, but still on the Bb servers.) You can set up your own mini-site there and be quite independent.

I would just link to my Web Folder from the Blackboard course page. Students don't need separate authentication.

Is that a possibility in your LMS? Alternatively, can the admins give you a space on the server?

I'm guessing you also run quizzes involving math. That's rather trickier...

Regards
Murray

Davide P. Cervone

unread,
Apr 17, 2016, 3:07:59 PM4/17/16
to mathja...@googlegroups.com
It may be possible to disable the LMS configuration, but it depends on how and when MathJax is loaded in comparison to your own code.

It would help if you could post a portion of the HTML for an example page that includes the configuration used by the LMS, the script call that loads MathJax.js, and your own configuration when you put it in line and externally.

I'm assuming the LMS has a <script type="text/x-mathjax-config"> element in the document <head>.  Is that correct?

I'm assuming that you use a similar x-mathjax-config script when you put your configuration in-line.  Is that also in the document <head>?  And where is it in relation to the LMS configuration and the script that loads MathJax.js (before, in between, or after them)?

When you put your configuration into a file, how are you loading the file?  Do you have control of the script that loads MathJax.js and are adding it as an additional configuration file via config=...?  Or are you using a raw <script src="..."></script> tag?  If the latter, where does this fall in relation to the LMS configuration script and the loading of MathJax?

When you say you have b) figured out, what did you do (if you haven't already explained that in answering the questions above)?

What I'm after is really whether your code runs before MathJax.js is loaded or not.  If you can get some javascript to run before that, then you can probably disable the LMS configuration before it is processed.  If your code runs after MathJax.js is loaded, then the LMS configuration is probably already processed, and you will have to "undo" their changes in your own configuration.  It really all depends on where your code comes in relation to the LMS code.  But we really need more details in order to advise you further.

Davide

Rachael Verbruggen

unread,
Apr 21, 2016, 1:51:56 PM4/21/16
to MathJax Users, dp...@union.edu, mark.s...@uwaterloo.ca
I took a bit of a closer look at what was happening in the LMS, and there are 2 circumstances when our content is in the LMS. One is that it is in an iframe within the LMS, so the LMS has it's own MathJax config and call in their head, and then my config/call comes in the head within the iframe. The other is that the page opens on it's own and it is (mostly) just my head and body that are there. However, in both cases the LMS injects it's MathJax stuff into my head underneath my mathjax stuff.
I have put what I think it the relevant code into a pastebin for you to take a look at: http://pastebin.com/hz6Ubj4k. I have included what's in the LMS head, my head and body after they have been put in the LMS and my original file before uploading it.  It is from a page that is within an iframe, but the same injection happens in my head even when it is not in an iframe (it's just that the code from the LMS head isn't included in my stand alone page). This is what I have to do currently to get my page to show up properly within the LMS.

If I leave out the call to MathJax it uses the version provided by the LMS. However, I choose to include my own call so I can control the version, etc.
I have tried adding a config file in the LMS and including it (with the full URL) in the call to MathJax (<script type="text/javascript src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML,http://myserver.com/MathJax/config/local/local.js"></script>) and I have also tried pulling out just the inline config I use and putting it in a js file (with window.MathJax) and using <script type="text/javascript" src="config_file.js">.

Thanks,
Rachael

Davide P. Cervone

unread,
Apr 29, 2016, 3:44:31 PM4/29/16
to Rachael Verbruggen, MathJax Users, mark.s...@uwaterloo.ca
OK, since your code appears in the document before the LMS code for loading MathJax, that gives you some leeway to avoid the LMS configuration.  One approach is the following.  Use

<script>
var MathJax = {
  tex2jax: {
    inlineMath: [['$','$'], ['\\(','\\)']],
    displayMath: [ [ '$$', '$$'], [ '\\[', '\\]'] ],
    processEnvironments: true,
    processEscapes: true
  }, 
  "HTML-CSS": {
    scale: 100
  },
  AuthorInit: function () {
    MathJax.Hub.Startup.ConfigBlocks = function () {}
  }
};
</script>

in place of your configuration block.  This uses MathJax's alternative means of configuration, by setting the MathJax variable to the configuration first.  The key piece here is the AuthorInit function, which gets run by MathJax before any of its startup functions (including processing configurations).  The definition included here simply replaces the code that locates and runs configuration blocks by an empty function, so MathJax will not process any <script type="text/x-mathjax-config"> configurations.  That will disable the configuration supplied by the LMS.

The only remaining issue is that the LMS does load MathJax version 2.5.3.  Fortunately, MathJax checks to see if it is already loaded and if it is loaded a second time, it does nothing (in particular, it doesn't override the MathJax that you already loaded).  But it does mean the people will have to wait for a second copy of MathJax.js to load.  There is no easy way to prevent that that I see, but there are some more complicated hacks that could be used if you really want to prevent the second copy from loading.  In any case, it will not cause a problem, just a delay during the initial page load.

Hope that works for you.

Davide
Reply all
Reply to author
Forward
0 new messages