Skip to content

Commit 4f5c3a6

Browse files
authored
Merge pull request #402 from mathjax/401
[main] extensions options: support names containing "s"
2 parents 1dad5e5 + 8844326 commit 4f5c3a6

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

lib/main.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ var document, window, content, html; // the DOM elements
9292
var queue = []; // queue of typesetting requests of the form [data,callback]
9393
var data, callback, originalData; // the current queue item
9494
var errors = []; // errors collected durring the typesetting
95+
var sErrors = []; // errors collected durring MathJax startup
9596
var ID = 0; // id for this SVG element
9697

9798
//
@@ -523,7 +524,10 @@ function ConfigureMathJax() {
523524
setTimeout(RestartMathJax, 100);
524525
} else {
525526
serverState = STATE.READY;
526-
MathJax.Hub.Queue(StartQueue);
527+
MathJax.Hub.Queue(
528+
function () {sErrors = errors},
529+
StartQueue
530+
);
527531
}
528532
});
529533
}
@@ -533,7 +537,7 @@ function ConfigureMathJax() {
533537
//
534538
// Parse added extensions list and add to standard ones
535539
//
536-
var extensionList = extensions.split(/s*,\s*/);
540+
var extensionList = extensions.split(/\s*,\s*/);
537541
for (var i = 0; i < extensionList.length; i++) {
538542
var matches = extensionList[i].match(/^(.*?)(\.js)?$/);
539543
window.MathJax.extensions.push(matches[1] + '.js');
@@ -735,7 +739,7 @@ function GetSVG(result) {
735739
//
736740
function StartQueue() {
737741
data = callback = originalData = null; // clear existing equation, if any
738-
errors = []; // clear any errors
742+
errors = sErrors; sErrors = []; // clear any errors
739743
if (!queue.length) return; // return if nothing to do
740744

741745
serverState = STATE.BUSY;

test/base-config-extensions.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var tape = require('tape');
2+
var mjAPI = require('../lib/main.js');
3+
4+
tape('Options "extension": multiple extensions', function(t) {
5+
t.plan(1);
6+
mjAPI.config({
7+
extensions: 'TeX/autoload-all.js, TeX/color.js'
8+
});
9+
mjAPI.typeset(
10+
{
11+
math: 'E = mc^2',
12+
format: 'TeX',
13+
mml: true
14+
},
15+
function(data) {
16+
t.notOk(
17+
data.errors,
18+
'Config block with multiple extensions throws no error'
19+
);
20+
}
21+
);
22+
});

test/base-errors-startup.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var tape = require('tape');
2+
var mjAPI = require('../lib/main.js');
3+
4+
tape('Catch errors during startup phase', function(t) {
5+
t.plan(1);
6+
mjAPI.config({
7+
extensions: 'blargh'
8+
});
9+
mjAPI.start();
10+
mjAPI.typeset(
11+
{
12+
math: 'x',
13+
format: 'TeX',
14+
mml: true
15+
},
16+
function(data) {
17+
t.ok(
18+
data.errors,
19+
'Error (loading non-existent extension) is caught in output'
20+
);
21+
// reset configuration
22+
mjAPI.config({
23+
extensions: ''
24+
});
25+
mjAPI.start();
26+
}
27+
);
28+
});

0 commit comments

Comments
 (0)