Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MathJax root to be configured. #1403 #1525

Merged
merged 1 commit into from
Jul 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions unpacked/MathJax.js
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,11 @@ MathJax.Hub.Startup = {
Config: function () {
this.queue.Push(["Post",this.signal,"Begin Config"]);
//
// Make sure root is set before loading any files
//
if (MathJax.AuthorConfig && MathJax.AuthorConfig.root)
MathJax.Ajax.config.root = MathJax.AuthorConfig.root;
//
// If a locale is given as a parameter,
// set the locale and the default menu value for the locale
//
Expand Down Expand Up @@ -2552,15 +2557,15 @@ MathJax.Hub.Startup = {
//
ConfigBlocks: function () {
var scripts = document.getElementsByTagName("script");
var last = null, queue = MathJax.Callback.Queue();
var queue = MathJax.Callback.Queue();
for (var i = 0, m = scripts.length; i < m; i++) {
var type = String(scripts[i].type).replace(/ /g,"");
if (type.match(/^text\/x-mathjax-config(;.*)?$/) && !type.match(/;executed=true/)) {
scripts[i].type += ";executed=true";
last = queue.Push(scripts[i].innerHTML+";\n1;");
queue.Push(scripts[i].innerHTML+";\n1;");
}
}
return last;
return queue.Push(function () {MathJax.Ajax.config.root = MathJax.Hub.config.root});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Push synchronous, i.e., will there be a return value?

Copy link
Member Author

@dpvc dpvc Jul 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the return value is the MathJax.Callback object created from the item pushed (Callbacks can be created from lots of possible data). The important point in returning the last callback pushed is that Callback objects are not only functions that can be called, but they also know how to work with MathJax.Callback.Queue objects; when a Callback is pushed on a Queue, the Queue will block until the Callback is called, and when it is, the next item in the Queue will start. But if a queued item returns another Callback, then the queue continues to pause until that callback is called, and so on.

So in this case, ConfigBlocks is itself pushed on a queue, and that queue will not continue until all the items that have been queued in queue in this routine are run, because the outer queue will have to wait for the Callback object returned by queue.Push(), and that only runs after everything else in queue has been run.

The MathJax.Callback was my attempt to do the job that now would be handled by promises, but that idea hadn't been developed (in javascript) at the time, and so the paradigm is a bit more awkward than it should be. It is one of the things that needs fixing in 3.0.

},

//
Expand Down