Merge branch 'CHTML-preview' into develop
This commit is contained in:
commit
3f5730a59f
|
@ -2544,6 +2544,8 @@ MathJax.Hub.Startup = {
|
||||||
}
|
}
|
||||||
jax.unshift(name);
|
jax.unshift(name);
|
||||||
}
|
}
|
||||||
|
if (config.menuSettings.CHTMLpreview && !MathJax.Extension["CHTML-preview"])
|
||||||
|
{MathJax.Hub.config.extensions.push("CHTML-preview.js")}
|
||||||
},MathJax.Hub.config],
|
},MathJax.Hub.config],
|
||||||
["Post",this.signal,"End Cookie"]
|
["Post",this.signal,"End Cookie"]
|
||||||
);
|
);
|
||||||
|
|
142
unpacked/extensions/CHTML-preview.js
Normal file
142
unpacked/extensions/CHTML-preview.js
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
|
||||||
|
/* vim: set ts=2 et sw=2 tw=80: */
|
||||||
|
|
||||||
|
/*************************************************************
|
||||||
|
*
|
||||||
|
* MathJax/extensions/CHTML-preview.js
|
||||||
|
*
|
||||||
|
* Implements a fast preview using the Common-HTML output jax
|
||||||
|
* and then a slower update to the more accurate HTML-CSS output
|
||||||
|
* (or whatever the user has selected).
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 The MathJax Consortium
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function (HUB,HTML) {
|
||||||
|
|
||||||
|
var SETTINGS = HUB.config.menuSettings;
|
||||||
|
|
||||||
|
var CHTMLpreview = MathJax.Extension["CHTML-preview"] = {
|
||||||
|
version: "1.0",
|
||||||
|
|
||||||
|
//
|
||||||
|
// Configuration for the chunking of the main output
|
||||||
|
// after the previews have been created, and other configuration.
|
||||||
|
//
|
||||||
|
config: HUB.CombineConfig("CHTML-preview",{
|
||||||
|
Chunks: {EqnChunk: 10000, EqnChunkFactor: 1, EqnChunkDelay: 0},
|
||||||
|
color: "inherit!important",
|
||||||
|
updateTime: 10, updateDelay: 10,
|
||||||
|
messageStyle: "none",
|
||||||
|
disabled: false
|
||||||
|
}),
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ajust the chunking of the output jax
|
||||||
|
//
|
||||||
|
Config: function () {
|
||||||
|
HUB.Config({
|
||||||
|
"HTML-CSS": this.config.Chunks,
|
||||||
|
SVG: this.config.Chunks,
|
||||||
|
});
|
||||||
|
MathJax.Ajax.Styles({".MathJax_Preview .MJXc-math":{color:this.config.color}});
|
||||||
|
var update, delay, style, done, saved;
|
||||||
|
var config = this.config;
|
||||||
|
|
||||||
|
if (!config.disabled && SETTINGS.CHTMLpreview == null)
|
||||||
|
HUB.Config({menuSettings:{CHTMLpreview:true}});
|
||||||
|
HUB.Register.MessageHook("Begin Math Output",function () {
|
||||||
|
if (!done && SETTINGS.CHTMLpreview && SETTINGS.renderer !== "CommonHTML") {
|
||||||
|
update = HUB.processUpdateTime; delay = HUB.processUpdateDelay;
|
||||||
|
style = HUB.config.messageStyle;
|
||||||
|
HUB.processUpdateTime = config.updateTime;
|
||||||
|
HUB.processUpdateDelay = config.updateDelay;
|
||||||
|
HUB.Config({messageStyle: config.messageStyle});
|
||||||
|
MathJax.Message.Clear(0,0);
|
||||||
|
saved = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
HUB.Register.MessageHook("End Math Output",function () {
|
||||||
|
if (!done && saved) {
|
||||||
|
HUB.processUpdateTime = update;
|
||||||
|
HUB.processUpdateDelay = delay;
|
||||||
|
HUB.Config({messageStyle: style});
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Insert a preview span, if there isn't one already,
|
||||||
|
// and call the CommonHTML output jax to create the preview
|
||||||
|
//
|
||||||
|
Preview: function (data) {
|
||||||
|
if (!SETTINGS.CHTMLpreview || SETTINGS.renderer === "CommonHTML") return;
|
||||||
|
var preview = data.script.MathJax.preview || data.script.previousSibling;
|
||||||
|
if (!preview || preview.className !== MathJax.Hub.config.preRemoveClass) {
|
||||||
|
preview = HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass});
|
||||||
|
data.script.parentNode.insertBefore(preview,data.script);
|
||||||
|
data.script.MathJax.preview = preview;
|
||||||
|
}
|
||||||
|
preview.innerHTML = ""; preview.style.color = "inherit";
|
||||||
|
return this.postFilter(preview,data);
|
||||||
|
},
|
||||||
|
postFilter: function (preview,data) {
|
||||||
|
try {
|
||||||
|
data.math.root.toCommonHTML(preview);
|
||||||
|
} catch (err) {
|
||||||
|
//
|
||||||
|
// Load the CommonHTML jax if it is not already loaded
|
||||||
|
//
|
||||||
|
if (!data.math.root.toCommonHTML) {
|
||||||
|
var queue = MathJax.Callback.Queue();
|
||||||
|
queue.Push(
|
||||||
|
["Require",MathJax.Ajax,"[MathJax]/jax/output/CommonHTML/config.js"],
|
||||||
|
["Require",MathJax.Ajax,"[MathJax]/jax/output/CommonHTML/jax.js"]
|
||||||
|
);
|
||||||
|
HUB.RestartAfter(queue.Push({}));
|
||||||
|
}
|
||||||
|
if (!err.restart) {throw err} // an actual error
|
||||||
|
return MathJax.Callback.After(["postFilter",this,preview,data],err.restart);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hook into the input jax postFilter to create the previews as
|
||||||
|
// the input jax are processed.
|
||||||
|
//
|
||||||
|
Register: function (name) {
|
||||||
|
HUB.Register.StartupHook(name+" Jax Require",function () {
|
||||||
|
var jax = MathJax.InputJax[name];
|
||||||
|
jax.postfilterHooks.Add(["Preview",MathJax.Extension["CHTML-preview"]],50);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hook into each input jax
|
||||||
|
//
|
||||||
|
CHTMLpreview.Register("TeX");
|
||||||
|
CHTMLpreview.Register("MathML");
|
||||||
|
CHTMLpreview.Register("AsciiMath");
|
||||||
|
|
||||||
|
HUB.Register.StartupHook("End Config",["Config",CHTMLpreview]);
|
||||||
|
|
||||||
|
})(MathJax.Hub,MathJax.HTML);
|
||||||
|
|
||||||
|
MathJax.Ajax.loadComplete("[MathJax]/extensions/CHTML-preview.js");
|
||||||
|
|
|
@ -1090,8 +1090,11 @@
|
||||||
ITEM.RULE(),
|
ITEM.RULE(),
|
||||||
ITEM.SUBMENU(["Renderer","Math Renderer"], {hidden:!CONFIG.showRenderer},
|
ITEM.SUBMENU(["Renderer","Math Renderer"], {hidden:!CONFIG.showRenderer},
|
||||||
ITEM.RADIO("HTML-CSS", "renderer", {action: MENU.Renderer}),
|
ITEM.RADIO("HTML-CSS", "renderer", {action: MENU.Renderer}),
|
||||||
|
ITEM.RADIO("Fast HTML", "renderer", {action: MENU.Renderer, value:"CommonHTML"}),
|
||||||
ITEM.RADIO("MathML", "renderer", {action: MENU.Renderer, value:"NativeMML"}),
|
ITEM.RADIO("MathML", "renderer", {action: MENU.Renderer, value:"NativeMML"}),
|
||||||
ITEM.RADIO("SVG", "renderer", {action: MENU.Renderer})
|
ITEM.RADIO("SVG", "renderer", {action: MENU.Renderer}),
|
||||||
|
ITEM.RULE(),
|
||||||
|
ITEM.CHECKBOX("Fast Preview", "CHTMLpreview")
|
||||||
),
|
),
|
||||||
ITEM.SUBMENU("MathPlayer", {hidden:!HUB.Browser.isMSIE || !CONFIG.showMathPlayer,
|
ITEM.SUBMENU("MathPlayer", {hidden:!HUB.Browser.isMSIE || !CONFIG.showMathPlayer,
|
||||||
disabled:!HUB.Browser.hasMathPlayer},
|
disabled:!HUB.Browser.hasMathPlayer},
|
||||||
|
|
|
@ -965,49 +965,58 @@ MathJax.ElementJax.mml.Augment({
|
||||||
close: ')',
|
close: ')',
|
||||||
separators: ','
|
separators: ','
|
||||||
},
|
},
|
||||||
texClass: MML.TEXCLASS.OPEN,
|
addFakeNodes: function () {
|
||||||
setTeXclass: function (prev) {
|
|
||||||
this.getPrevClass(prev);
|
|
||||||
var values = this.getValues("open","close","separators");
|
var values = this.getValues("open","close","separators");
|
||||||
values.open = values.open.replace(/[ \t\n\r]/g,"");
|
values.open = values.open.replace(/[ \t\n\r]/g,"");
|
||||||
values.close = values.close.replace(/[ \t\n\r]/g,"");
|
values.close = values.close.replace(/[ \t\n\r]/g,"");
|
||||||
values.separators = values.separators.replace(/[ \t\n\r]/g,"");
|
values.separators = values.separators.replace(/[ \t\n\r]/g,"");
|
||||||
// create a fake node for the open item
|
//
|
||||||
|
// Create a fake node for the open item
|
||||||
|
//
|
||||||
if (values.open !== "") {
|
if (values.open !== "") {
|
||||||
this.SetData("open",MML.mo(values.open).With({
|
this.SetData("open",MML.mo(values.open).With({
|
||||||
fence:true, form:MML.FORM.PREFIX, texClass:MML.TEXCLASS.OPEN
|
fence:true, form:MML.FORM.PREFIX, texClass:MML.TEXCLASS.OPEN
|
||||||
}));
|
}));
|
||||||
|
//
|
||||||
// Clear flag for using MML spacing even though form is specified
|
// Clear flag for using MML spacing even though form is specified
|
||||||
|
//
|
||||||
this.data.open.useMMLspacing &= ~this.data.open.SPACE_ATTR.form;
|
this.data.open.useMMLspacing &= ~this.data.open.SPACE_ATTR.form;
|
||||||
prev = this.data.open.setTeXclass(prev);
|
|
||||||
}
|
}
|
||||||
// get the separators
|
//
|
||||||
|
// Create fake nodes for the separators
|
||||||
|
//
|
||||||
if (values.separators !== "") {
|
if (values.separators !== "") {
|
||||||
while (values.separators.length < this.data.length)
|
while (values.separators.length < this.data.length)
|
||||||
{values.separators += values.separators.charAt(values.separators.length-1)}
|
{values.separators += values.separators.charAt(values.separators.length-1)}
|
||||||
}
|
|
||||||
// handle the first item, if any
|
|
||||||
if (this.data[0]) {prev = this.data[0].setTeXclass(prev)}
|
|
||||||
// add fake nodes for separators and handle the following item
|
|
||||||
for (var i = 1, m = this.data.length; i < m; i++) {
|
for (var i = 1, m = this.data.length; i < m; i++) {
|
||||||
if (this.data[i]) {
|
if (this.data[i])
|
||||||
if (values.separators !== "") {
|
{this.SetData("sep"+i,MML.mo(values.separators.charAt(i-1)).With({separator:true}))}
|
||||||
this.SetData("sep"+i,MML.mo(values.separators.charAt(i-1)).With({separator:true}));
|
|
||||||
prev = this.data["sep"+i].setTeXclass(prev);
|
|
||||||
}
|
|
||||||
prev = this.data[i].setTeXclass(prev);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create fake node for the close item
|
//
|
||||||
|
// Create fake node for the close item
|
||||||
|
//
|
||||||
if (values.close !== "") {
|
if (values.close !== "") {
|
||||||
this.SetData("close",MML.mo(values.close).With({
|
this.SetData("close",MML.mo(values.close).With({
|
||||||
fence:true, form:MML.FORM.POSTFIX, texClass:MML.TEXCLASS.CLOSE
|
fence:true, form:MML.FORM.POSTFIX, texClass:MML.TEXCLASS.CLOSE
|
||||||
}));
|
}));
|
||||||
|
//
|
||||||
// Clear flag for using MML spacing even though form is specified
|
// Clear flag for using MML spacing even though form is specified
|
||||||
|
//
|
||||||
this.data.close.useMMLspacing &= ~this.data.close.SPACE_ATTR.form;
|
this.data.close.useMMLspacing &= ~this.data.close.SPACE_ATTR.form;
|
||||||
prev = this.data.close.setTeXclass(prev);
|
|
||||||
}
|
}
|
||||||
// get the data from the open item
|
},
|
||||||
|
texClass: MML.TEXCLASS.OPEN,
|
||||||
|
setTeXclass: function (prev) {
|
||||||
|
this.addFakeNodes();
|
||||||
|
this.getPrevClass(prev);
|
||||||
|
if (this.data.open) {prev = this.data.open.setTeXclass(prev)}
|
||||||
|
if (this.data[0]) {prev = this.data[0].setTeXclass(prev)}
|
||||||
|
for (var i = 1, m = this.data.length; i < m; i++) {
|
||||||
|
if (this.data["sep"+i]) {prev = this.data["sep"+i].setTeXclass(prev)}
|
||||||
|
if (this.data[i]) {prev = this.data[i].setTeXclass(prev)}
|
||||||
|
}
|
||||||
|
if (this.data.close) {prev = this.data.close.setTeXclass(prev)}
|
||||||
this.updateTeXclass(this.data.open);
|
this.updateTeXclass(this.data.open);
|
||||||
this.texClass = MML.TEXCLASS.INNER;
|
this.texClass = MML.TEXCLASS.INNER;
|
||||||
return prev;
|
return prev;
|
||||||
|
|
|
@ -1284,15 +1284,16 @@ junk = null;
|
||||||
Translate: function (script) {
|
Translate: function (script) {
|
||||||
var mml, math = MathJax.HTML.getScript(script);
|
var mml, math = MathJax.HTML.getScript(script);
|
||||||
var data = {math:math, script:script};
|
var data = {math:math, script:script};
|
||||||
this.prefilterHooks.Execute(data); math = data.math;
|
var callback = this.prefilterHooks.Execute(data); if (callback) return callback;
|
||||||
|
math = data.math;
|
||||||
try {
|
try {
|
||||||
mml = this.AM.parseMath(math);
|
mml = this.AM.parseMath(math);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if (!err.asciimathError) {throw err}
|
if (!err.asciimathError) {throw err}
|
||||||
mml = this.formatError(err,math);
|
mml = this.formatError(err,math);
|
||||||
}
|
}
|
||||||
data.math = MML(mml); this.postfilterHooks.Execute(data);
|
data.math = MML(mml);
|
||||||
return data.math;
|
return this.postfilterHooks.Execute(data) || data.math;
|
||||||
},
|
},
|
||||||
formatError: function (err,math,script) {
|
formatError: function (err,math,script) {
|
||||||
var message = err.message.replace(/\n.*/,"");
|
var message = err.message.replace(/\n.*/,"");
|
||||||
|
|
|
@ -255,20 +255,21 @@
|
||||||
if (script.firstChild &&
|
if (script.firstChild &&
|
||||||
script.firstChild.nodeName.toLowerCase().replace(/^[a-z]+:/,"") === "math") {
|
script.firstChild.nodeName.toLowerCase().replace(/^[a-z]+:/,"") === "math") {
|
||||||
data.math = script.firstChild;
|
data.math = script.firstChild;
|
||||||
this.prefilterHooks.Execute(data); math = data.math;
|
|
||||||
} else {
|
} else {
|
||||||
math = MathJax.HTML.getScript(script);
|
math = MathJax.HTML.getScript(script);
|
||||||
if (BROWSER.isMSIE) {math = math.replace(/( )+$/,"")}
|
if (BROWSER.isMSIE) {math = math.replace(/( )+$/,"")}
|
||||||
data.math = math; this.prefilterHooks.Execute(data); math = data.math;
|
data.math = math;
|
||||||
}
|
}
|
||||||
|
var callback = this.prefilterHooks.Execute(data); if (callback) return callback;
|
||||||
|
math = data.math;
|
||||||
try {
|
try {
|
||||||
mml = MATHML.Parse(math,script).mml;
|
mml = MATHML.Parse(math,script).mml;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if (!err.mathmlError) {throw err}
|
if (!err.mathmlError) {throw err}
|
||||||
mml = this.formatError(err,math,script);
|
mml = this.formatError(err,math,script);
|
||||||
}
|
}
|
||||||
data.math = MML(mml); this.postfilterHooks.Execute(data);
|
data.math = MML(mml);
|
||||||
return data.math;
|
return this.postfilterHooks.Execute(data) || data.math;
|
||||||
},
|
},
|
||||||
prefilterMath: function (math,script) {return math},
|
prefilterMath: function (math,script) {return math},
|
||||||
prefilterMathML: function (math,script) {return math},
|
prefilterMathML: function (math,script) {return math},
|
||||||
|
|
|
@ -2133,7 +2133,8 @@
|
||||||
var mml, isError = false, math = MathJax.HTML.getScript(script);
|
var mml, isError = false, math = MathJax.HTML.getScript(script);
|
||||||
var display = (script.type.replace(/\n/g," ").match(/(;|\s|\n)mode\s*=\s*display(;|\s|\n|$)/) != null);
|
var display = (script.type.replace(/\n/g," ").match(/(;|\s|\n)mode\s*=\s*display(;|\s|\n|$)/) != null);
|
||||||
var data = {math:math, display:display, script:script};
|
var data = {math:math, display:display, script:script};
|
||||||
this.prefilterHooks.Execute(data); math = data.math;
|
var callback = this.prefilterHooks.Execute(data); if (callback) return callback;
|
||||||
|
math = data.math;
|
||||||
try {
|
try {
|
||||||
mml = TEX.Parse(math).mml();
|
mml = TEX.Parse(math).mml();
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
@ -2144,8 +2145,8 @@
|
||||||
if (mml.inferred) {mml = MML.apply(MathJax.ElementJax,mml.data)} else {mml = MML(mml)}
|
if (mml.inferred) {mml = MML.apply(MathJax.ElementJax,mml.data)} else {mml = MML(mml)}
|
||||||
if (display) {mml.root.display = "block"}
|
if (display) {mml.root.display = "block"}
|
||||||
if (isError) {mml.texError = true}
|
if (isError) {mml.texError = true}
|
||||||
data.math = mml; this.postfilterHooks.Execute(data);
|
data.math = mml;
|
||||||
return data.math;
|
return this.postfilterHooks.Execute(data) || data.math;
|
||||||
},
|
},
|
||||||
prefilterMath: function (math,displaystyle,script) {
|
prefilterMath: function (math,displaystyle,script) {
|
||||||
return math;
|
return math;
|
||||||
|
|
53
unpacked/jax/output/CommonHTML/config.js
Normal file
53
unpacked/jax/output/CommonHTML/config.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
|
||||||
|
/* vim: set ts=2 et sw=2 tw=80: */
|
||||||
|
|
||||||
|
/*************************************************************
|
||||||
|
*
|
||||||
|
* MathJax/jax/output/HTML2/config.js
|
||||||
|
*
|
||||||
|
* Initializes the HTML2 OutputJax (the main definition is in
|
||||||
|
* MathJax/jax/input/HTML2/jax.js, which is loaded when needed).
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2014 The MathJax Consortium
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
MathJax.OutputJax.CommonHTML = MathJax.OutputJax({
|
||||||
|
id: "CommonHTML",
|
||||||
|
version: "2.4.0",
|
||||||
|
directory: MathJax.OutputJax.directory + "/CommonHTML",
|
||||||
|
extensionDir: MathJax.OutputJax.extensionDir + "/CommonHTML",
|
||||||
|
|
||||||
|
config: {
|
||||||
|
scale: 100, minScaleAdjust: 50, // global math scaling factor, and minimum adjusted scale factor
|
||||||
|
mtextFontInherit: false, // to make <mtext> be in page font rather than MathJax font
|
||||||
|
|
||||||
|
linebreaks: {
|
||||||
|
automatic: false, // when false, only process linebreak="newline",
|
||||||
|
// when true, insert line breaks automatically in long expressions.
|
||||||
|
|
||||||
|
width: "container" // maximum width of a line for automatic line breaks (e.g. "30em").
|
||||||
|
// use "container" to compute size from containing element,
|
||||||
|
// use "nn% container" for a portion of the container,
|
||||||
|
// use "nn%" for a portion of the window size
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!MathJax.Hub.config.delayJaxRegistration) {MathJax.OutputJax.CommonHTML.Register("jax/mml")}
|
||||||
|
|
||||||
|
MathJax.OutputJax.CommonHTML.loadComplete("config.js");
|
1156
unpacked/jax/output/CommonHTML/jax.js
Normal file
1156
unpacked/jax/output/CommonHTML/jax.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user