Merge branch 'CHTML-preview' into develop
This commit is contained in:
commit
3f5730a59f
|
@ -2544,6 +2544,8 @@ MathJax.Hub.Startup = {
|
|||
}
|
||||
jax.unshift(name);
|
||||
}
|
||||
if (config.menuSettings.CHTMLpreview && !MathJax.Extension["CHTML-preview"])
|
||||
{MathJax.Hub.config.extensions.push("CHTML-preview.js")}
|
||||
},MathJax.Hub.config],
|
||||
["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");
|
||||
|
|
@ -964,7 +964,7 @@
|
|||
"The MathJax contextual menu will be disabled, but you can " +
|
||||
"Alt-Click on an expression to obtain the MathJax menu instead."]
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************/
|
||||
/*************************************************************/
|
||||
|
||||
|
@ -1090,15 +1090,18 @@
|
|||
ITEM.RULE(),
|
||||
ITEM.SUBMENU(["Renderer","Math Renderer"], {hidden:!CONFIG.showRenderer},
|
||||
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("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,
|
||||
disabled:!HUB.Browser.hasMathPlayer},
|
||||
ITEM.LABEL(["MPHandles","Let MathPlayer Handle:"]),
|
||||
ITEM.CHECKBOX(["MenuEvents","Menu Events"], "mpContext", {action: MENU.MPEvents, hidden:!isIE9}),
|
||||
ITEM.CHECKBOX(["MouseEvents","Mouse Events"], "mpMouse", {action: MENU.MPEvents, hidden:!isIE9}),
|
||||
ITEM.CHECKBOX(["MenuAndMouse","Mouse and Menu Events"], "mpMouse", {action: MENU.MPEvents, hidden:isIE9})
|
||||
ITEM.CHECKBOX(["MenuAndMouse","Mouse and Menu Events"], "mpMouse", {action: MENU.MPEvents, hidden:isIE9})
|
||||
),
|
||||
ITEM.SUBMENU(["FontPrefs","Font Preference"], {hidden:!CONFIG.showFontMenu},
|
||||
ITEM.LABEL(["ForHTMLCSS","For HTML-CSS:"]),
|
||||
|
|
|
@ -965,49 +965,58 @@ MathJax.ElementJax.mml.Augment({
|
|||
close: ')',
|
||||
separators: ','
|
||||
},
|
||||
texClass: MML.TEXCLASS.OPEN,
|
||||
setTeXclass: function (prev) {
|
||||
this.getPrevClass(prev);
|
||||
addFakeNodes: function () {
|
||||
var values = this.getValues("open","close","separators");
|
||||
values.open = values.open.replace(/[ \t\n\r]/g,"");
|
||||
values.close = values.close.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 !== "") {
|
||||
this.SetData("open",MML.mo(values.open).With({
|
||||
fence:true, form:MML.FORM.PREFIX, texClass:MML.TEXCLASS.OPEN
|
||||
}));
|
||||
//
|
||||
// Clear flag for using MML spacing even though form is specified
|
||||
//
|
||||
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 !== "") {
|
||||
while (values.separators.length < this.data.length)
|
||||
{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++) {
|
||||
if (this.data[i]) {
|
||||
if (values.separators !== "") {
|
||||
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);
|
||||
for (var i = 1, m = this.data.length; i < m; i++) {
|
||||
if (this.data[i])
|
||||
{this.SetData("sep"+i,MML.mo(values.separators.charAt(i-1)).With({separator:true}))}
|
||||
}
|
||||
}
|
||||
// create fake node for the close item
|
||||
//
|
||||
// Create fake node for the close item
|
||||
//
|
||||
if (values.close !== "") {
|
||||
this.SetData("close",MML.mo(values.close).With({
|
||||
fence:true, form:MML.FORM.POSTFIX, texClass:MML.TEXCLASS.CLOSE
|
||||
}));
|
||||
//
|
||||
// Clear flag for using MML spacing even though form is specified
|
||||
//
|
||||
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.texClass = MML.TEXCLASS.INNER;
|
||||
return prev;
|
||||
|
|
|
@ -1284,15 +1284,16 @@ junk = null;
|
|||
Translate: function (script) {
|
||||
var mml, math = MathJax.HTML.getScript(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 {
|
||||
mml = this.AM.parseMath(math);
|
||||
} catch(err) {
|
||||
if (!err.asciimathError) {throw err}
|
||||
mml = this.formatError(err,math);
|
||||
}
|
||||
data.math = MML(mml); this.postfilterHooks.Execute(data);
|
||||
return data.math;
|
||||
data.math = MML(mml);
|
||||
return this.postfilterHooks.Execute(data) || data.math;
|
||||
},
|
||||
formatError: function (err,math,script) {
|
||||
var message = err.message.replace(/\n.*/,"");
|
||||
|
|
|
@ -255,20 +255,21 @@
|
|||
if (script.firstChild &&
|
||||
script.firstChild.nodeName.toLowerCase().replace(/^[a-z]+:/,"") === "math") {
|
||||
data.math = script.firstChild;
|
||||
this.prefilterHooks.Execute(data); math = data.math;
|
||||
} else {
|
||||
math = MathJax.HTML.getScript(script);
|
||||
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 {
|
||||
mml = MATHML.Parse(math,script).mml;
|
||||
} catch(err) {
|
||||
if (!err.mathmlError) {throw err}
|
||||
mml = this.formatError(err,math,script);
|
||||
}
|
||||
data.math = MML(mml); this.postfilterHooks.Execute(data);
|
||||
return data.math;
|
||||
data.math = MML(mml);
|
||||
return this.postfilterHooks.Execute(data) || data.math;
|
||||
},
|
||||
prefilterMath: 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 display = (script.type.replace(/\n/g," ").match(/(;|\s|\n)mode\s*=\s*display(;|\s|\n|$)/) != null);
|
||||
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 {
|
||||
mml = TEX.Parse(math).mml();
|
||||
} catch(err) {
|
||||
|
@ -2144,8 +2145,8 @@
|
|||
if (mml.inferred) {mml = MML.apply(MathJax.ElementJax,mml.data)} else {mml = MML(mml)}
|
||||
if (display) {mml.root.display = "block"}
|
||||
if (isError) {mml.texError = true}
|
||||
data.math = mml; this.postfilterHooks.Execute(data);
|
||||
return data.math;
|
||||
data.math = mml;
|
||||
return this.postfilterHooks.Execute(data) || data.math;
|
||||
},
|
||||
prefilterMath: function (math,displaystyle,script) {
|
||||
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