Skip to content

Commit 7d9828c

Browse files
committed
Initialize MathJax directly in JSRootCore.js
While mathjax can be loaded from different places, do configuration centrally
1 parent c8abde3 commit 7d9828c

File tree

2 files changed

+58
-70
lines changed

2 files changed

+58
-70
lines changed

scripts/JSRootCore.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,15 @@
917917
if (jsroot.doing_assert.length > 1) return;
918918
}
919919

920+
function normal_callback() {
921+
var req = jsroot.doing_assert.shift();
922+
for (var n=0;n<req.modules.length;++n)
923+
jsroot.ready_modules.push(req.modules[n]);
924+
jsroot.CallBack(req._callback);
925+
jsroot.AssertPrerequisites('__next__');
926+
}
927+
928+
920929
jsroot.doing_assert[0].running = true;
921930

922931
if (kind[kind.length-1]!=";") kind+=";";
@@ -926,7 +935,8 @@
926935
use_bower = jsroot.bower_dir!==null,
927936
mainfiles = "",
928937
extrafiles = "", // scripts for direct loadin
929-
modules = []; // modules used for require.js
938+
modules = [], // modules used for require.js
939+
load_callback = normal_callback;
930940

931941
if ((kind.indexOf('io;')>=0) || (kind.indexOf('tree;')>=0))
932942
if (jsroot.sources.indexOf("io")<0) {
@@ -1015,6 +1025,24 @@
10151025
mainfiles += (use_bower ? "###MathJax/MathJax.js" : "https://root.cern/js/mathjax/latest/MathJax.js") +
10161026
"?config=TeX-AMS-MML_SVG&delayStartupUntil=configured";
10171027
modules.push('MathJax');
1028+
1029+
load_callback = function() {
1030+
MathJax.Hub.Config({ jax: ["input/TeX", "output/SVG"],
1031+
TeX: { extensions: ["color.js"] },
1032+
SVG: { mtextFontInherit: true, minScaleAdjust: 100, matchFontHeight: true, useFontCache: false } });
1033+
1034+
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
1035+
var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;
1036+
VARIANT["normal"].fonts.unshift("MathJax_SansSerif");
1037+
VARIANT["bold"].fonts.unshift("MathJax_SansSerif-bold");
1038+
VARIANT["italic"].fonts.unshift("MathJax_SansSerif");
1039+
VARIANT["-tex-mathit"].fonts.unshift("MathJax_SansSerif");
1040+
});
1041+
1042+
MathJax.Hub.Configured();
1043+
1044+
normal_callback();
1045+
}
10181046
}
10191047
if (jsroot.gStyle.MathJax == 0) jsroot.gStyle.MathJax = 1;
10201048
}
@@ -1052,14 +1080,6 @@
10521080
if (pos<0) pos = kind.indexOf("load:");
10531081
if (pos>=0) extrafiles += kind.slice(pos+5);
10541082

1055-
function load_callback() {
1056-
var req = jsroot.doing_assert.shift();
1057-
for (var n=0;n<req.modules.length;++n)
1058-
jsroot.ready_modules.push(req.modules[n]);
1059-
jsroot.CallBack(req._callback);
1060-
jsroot.AssertPrerequisites('__next__');
1061-
}
1062-
10631083
// check if modules already loaded
10641084
for (var n=modules.length-1;n>=0;--n)
10651085
if (jsroot.ready_modules.indexOf(modules[n])>=0)

scripts/JSRootPainter.js

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,25 +3315,6 @@
33153315

33163316
JSROOT.AssertPrerequisites('mathjax', function() {
33173317

3318-
if (!JSROOT.mathjax_configured) {
3319-
3320-
MathJax.Hub.Config({ jax: ["input/TeX", "output/SVG"],
3321-
TeX: { extensions: ["color.js"] },
3322-
SVG: { mtextFontInherit: true, minScaleAdjust: 100, matchFontHeight: true, useFontCache: false } });
3323-
3324-
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
3325-
var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;
3326-
VARIANT["normal"].fonts.unshift("MathJax_SansSerif");
3327-
VARIANT["bold"].fonts.unshift("MathJax_SansSerif-bold");
3328-
VARIANT["italic"].fonts.unshift("MathJax_SansSerif");
3329-
VARIANT["-tex-mathit"].fonts.unshift("MathJax_SansSerif");
3330-
});
3331-
3332-
MathJax.Hub.Configured();
3333-
3334-
JSROOT.mathjax_configured = true;
3335-
}
3336-
33373318
MathJax.Hub.Typeset(element, ["FinishMathjax", painter, draw_g, fo_g]);
33383319

33393320
MathJax.Hub.Queue(["FinishMathjax", painter, draw_g, fo_g]); // repeat once again, while Typeset not always invoke callback
@@ -9554,59 +9535,46 @@
95549535

95559536
// ================= painter of raw text ========================================
95569537

9557-
JSROOT.RawTextPainter = function(txt) {
9558-
JSROOT.TBasePainter.call(this);
9559-
this.txt = txt;
9560-
return this;
9561-
}
9562-
9563-
JSROOT.RawTextPainter.prototype = Object.create( JSROOT.TBasePainter.prototype );
9564-
9565-
JSROOT.RawTextPainter.prototype.RedrawObject = function(obj) {
9566-
this.txt = obj;
9567-
this.Draw();
9568-
return true;
9569-
}
95709538

9571-
JSROOT.RawTextPainter.prototype.Draw = function() {
9572-
var txt = this.txt.value;
9573-
if (txt==null) txt = "<undefined>";
9539+
JSROOT.Painter.drawRawText = function(divid, txt, opt) {
95749540

9575-
var mathjax = 'mathjax' in this.txt;
9541+
var painter = new JSROOT.TBasePainter();
9542+
painter.txt = txt;
9543+
painter.SetDivId(divid);
95769544

9577-
if (!mathjax && !('as_is' in this.txt)) {
9578-
var arr = txt.split("\n"); txt = "";
9579-
for (var i = 0; i < arr.length; ++i)
9580-
txt += "<pre>" + arr[i] + "</pre>";
9545+
painter.RedrawObject = function(obj) {
9546+
this.txt = obj;
9547+
this.Draw();
9548+
return true;
95819549
}
95829550

9583-
var frame = this.select_main();
9584-
var main = frame.select("div");
9585-
if (main.empty())
9586-
main = frame.append("div").style('max-width','100%').style('max-height','100%').style('overflow','auto');
9551+
painter.Draw = function() {
9552+
var txt = this.txt.value;
9553+
if (typeof txt != 'string') txt = "<undefined>";
95879554

9588-
main.html(txt);
9555+
var mathjax = this.txt.mathjax || (JSROOT.gStyle.MathJax>1);
95899556

9590-
// (re) set painter to first child element
9591-
this.SetDivId(this.divid);
9557+
if (!mathjax && !('as_is' in this.txt)) {
9558+
var arr = txt.split("\n"); txt = "";
9559+
for (var i = 0; i < arr.length; ++i)
9560+
txt += "<pre>" + arr[i] + "</pre>";
9561+
}
95929562

9593-
if (!mathjax) return;
9563+
var frame = this.select_main(),
9564+
main = frame.select("div");
9565+
if (main.empty())
9566+
main = frame.append("div").style('max-width','100%').style('max-height','100%').style('overflow','auto');
9567+
main.html(txt);
95949568

9595-
var painter = this;
9596-
if (painter.loading_mathjax) return;
9569+
// (re) set painter to first child element
9570+
this.SetDivId(this.divid);
95979571

9598-
painter.loading_mathjax = true;
9599-
JSROOT.AssertPrerequisites('mathjax', function() {
9600-
delete painter.loading_mathjax;
9601-
if (typeof MathJax == 'object') {
9602-
MathJax.Hub.Queue(["Typeset", MathJax.Hub, frame.node()]);
9603-
}
9604-
});
9605-
}
9572+
if (mathjax)
9573+
JSROOT.AssertPrerequisites('mathjax', function() {
9574+
MathJax.Hub.Typeset(frame.node());
9575+
});
9576+
}
96069577

9607-
JSROOT.Painter.drawRawText = function(divid, txt, opt) {
9608-
var painter = new JSROOT.RawTextPainter(txt);
9609-
painter.SetDivId(divid);
96109578
painter.Draw();
96119579
return painter.DrawingReady();
96129580
}

0 commit comments

Comments
 (0)