Add support for automatic line numbers, and the \label and \ref macros (resolves issue #71)
This commit is contained in:
parent
c23c21443e
commit
7e2ed03750
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -262,6 +262,13 @@ MathJax.Hub.Config({
|
|||
//
|
||||
processEnvironments: true,
|
||||
|
||||
//
|
||||
// Conteols whether tex2jax processes \ref{...} commands outside
|
||||
// of math mode. Set to "false" to prevent processing of \ref
|
||||
// except within math mode.
|
||||
//
|
||||
processRefs: true,
|
||||
|
||||
//
|
||||
// Controls whether tex2jax inserts MathJax_Preview spans to make a
|
||||
// preview available, and what preview to use, when it locates in-line
|
||||
|
@ -368,7 +375,19 @@ MathJax.Hub.Config({
|
|||
// bold: ['{\\bf #1}', 1]
|
||||
// }
|
||||
//
|
||||
Macros: {}
|
||||
Macros: {},
|
||||
|
||||
//
|
||||
// Equation numbering parameters
|
||||
//
|
||||
equationNumbers: {
|
||||
autoNumber: "none", // "AMS" for standard AMS environment numbering,
|
||||
// or "all" to number all displayed equations
|
||||
// formatNumber: function (n) {return n}, // format for equation number n
|
||||
// formatTag: function (n) {return '('+n+')'}, // format for \tag and \eqref
|
||||
// formatID: function (n) {return 'mjx-eqn-'+n}, // element ID to use for reference
|
||||
// formatURL: function (n) {return '#mjx-eqn-'+escape(n)}, // URL to use for references
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -12,5 +12,5 @@
|
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
MathJax.InputJax.TeX=MathJax.InputJax({id:"TeX",version:"1.1.2",directory:MathJax.InputJax.directory+"/TeX",extensionDir:MathJax.InputJax.extensionDir+"/TeX",config:{TagSide:"right",TagIndent:"0.8em",MultLineWidth:"85%"}});MathJax.InputJax.TeX.Register("math/tex");MathJax.InputJax.TeX.loadComplete("config.js");
|
||||
MathJax.InputJax.TeX=MathJax.InputJax({id:"TeX",version:"1.1.3",directory:MathJax.InputJax.directory+"/TeX",extensionDir:MathJax.InputJax.extensionDir+"/TeX",config:{TagSide:"right",TagIndent:"0.8em",MultLineWidth:"85%",equationNumbers:{autoNumber:"none",formatNumber:function(a){return a},formatTag:function(a){return"("+a+")"},formatID:function(a){return"mjx-eqn-"+a},formatURL:function(a){return"#mjx-eqn-"+escape(a)}}}});MathJax.InputJax.TeX.Register("math/tex");MathJax.InputJax.TeX.loadComplete("config.js");
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -262,6 +262,13 @@ MathJax.Hub.Config({
|
|||
//
|
||||
processEnvironments: true,
|
||||
|
||||
//
|
||||
// Conteols whether tex2jax processes \ref{...} commands outside
|
||||
// of math mode. Set to "false" to prevent processing of \ref
|
||||
// except within math mode.
|
||||
//
|
||||
processRefs: true,
|
||||
|
||||
//
|
||||
// Controls whether tex2jax inserts MathJax_Preview spans to make a
|
||||
// preview available, and what preview to use, when it locates in-line
|
||||
|
@ -368,7 +375,19 @@ MathJax.Hub.Config({
|
|||
// bold: ['{\\bf #1}', 1]
|
||||
// }
|
||||
//
|
||||
Macros: {}
|
||||
Macros: {},
|
||||
|
||||
//
|
||||
// Equation numbering parameters
|
||||
//
|
||||
equationNumbers: {
|
||||
autoNumber: "none", // "AMS" for standard AMS environment numbering,
|
||||
// or "all" to number all displayed equations
|
||||
// formatNumber: function (n) {return n}, // format for equation number n
|
||||
// formatTag: function (n) {return '('+n+')'}, // format for \tag and \eqref
|
||||
// formatID: function (n) {return 'mjx-eqn-'+n}, // element ID to use for reference
|
||||
// formatURL: function (n) {return '#mjx-eqn-'+escape(n)}, // URL to use for references
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*
|
||||
* ---------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2009 Design Science, Inc.
|
||||
* Copyright (c) 2009-2011 Design Science, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -21,16 +21,30 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
MathJax.Extension["TeX/AMSmath"] = {
|
||||
version: "1.1.1",
|
||||
|
||||
number: 0, // current equation number
|
||||
startNumber: 0, // current starting equation number (for when equation is restarted)
|
||||
labels: {}, // the set of labels
|
||||
eqlabels: {}, // labels in the current equation
|
||||
refs: [] // array of jax with unresolved references
|
||||
};
|
||||
|
||||
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
||||
var VERSION = "1.1";
|
||||
|
||||
var MML = MathJax.ElementJax.mml;
|
||||
var TEX = MathJax.InputJax.TeX;
|
||||
var TEXDEF = TEX.Definitions;
|
||||
var STACKITEM = TEX.Stack.Item;
|
||||
|
||||
var MML = MathJax.ElementJax.mml,
|
||||
TEX = MathJax.InputJax.TeX,
|
||||
AMS = MathJax.Extension["TeX/AMSmath"];
|
||||
|
||||
var TEXDEF = TEX.Definitions,
|
||||
STACKITEM = TEX.Stack.Item,
|
||||
CONFIG = TEX.config.equationNumbers;
|
||||
|
||||
var COLS = function (W) {return W.join("em ") + "em"};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
MathJax.Hub.Insert(TEXDEF,{
|
||||
macros: {
|
||||
mathring: ['Accent','2DA'], // or 0x30A
|
||||
|
@ -54,6 +68,9 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
|
||||
tag: 'HandleTag',
|
||||
notag: 'HandleNoTag',
|
||||
label: 'HandleLabel',
|
||||
ref: 'HandleRef',
|
||||
eqref: ['HandleRef',true],
|
||||
|
||||
substack: ['Macro','\\begin{subarray}{c}#1\\end{subarray}',1],
|
||||
|
||||
|
@ -101,7 +118,10 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
gathered: ['Array',null,null,null,'c',null,".5em",'D'],
|
||||
|
||||
subarray: ['Array',null,null,null,null,COLS([0,0,0,0]),"0.1em",'S',1],
|
||||
smallmatrix: ['Array',null,null,null,'c',COLS([1/3]),".2em",'S',1]
|
||||
smallmatrix: ['Array',null,null,null,'c',COLS([1/3]),".2em",'S',1],
|
||||
|
||||
'equation': ['EquationBegin','Equation',true],
|
||||
'equation*': ['EquationBegin','EquationStar',false]
|
||||
},
|
||||
|
||||
delimiter: {
|
||||
|
@ -113,21 +133,50 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
});
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
TEX.Parse.Augment({
|
||||
|
||||
/*
|
||||
* Add the tag to the environment to be added to the table row later
|
||||
* Add the tag to the environment (to be added to the table row later)
|
||||
*/
|
||||
HandleTag: function (name) {
|
||||
var arg = this.trimSpaces(this.GetArgument(name));
|
||||
if (arg === "*") {arg = this.GetArgument(name)} else {arg = "("+arg+")"}
|
||||
if (this.stack.global.notag)
|
||||
{TEX.Error(name+" not allowed in "+this.stack.global.notag+" environment")}
|
||||
if (this.stack.global.tag) {TEX.Error("Multiple "+name)}
|
||||
this.stack.global.tag = MML.mtd.apply(MML,this.InternalMath(arg));
|
||||
var arg = this.trimSpaces(this.GetArgument(name)), tag = arg;
|
||||
if (arg === "*") {tag = arg = this.GetArgument(name)} else {arg = CONFIG.formatTag(arg)}
|
||||
var global = this.stack.global; global.tagID = tag;
|
||||
if (global.notags) {TEX.Error(name+" not allowed in "+global.notags+" environment")}
|
||||
if (global.tag) {TEX.Error("Multiple "+name)}
|
||||
global.tag = MML.mtd.apply(MML,this.InternalMath(arg)).With({id:CONFIG.formatID(tag)});
|
||||
},
|
||||
HandleNoTag: function (name) {
|
||||
if (this.stack.global.tag) {delete this.stack.global.tag}
|
||||
this.stack.global.notag = true; // prevent auto-tagging
|
||||
},
|
||||
|
||||
/*
|
||||
* Record a label name for a tag
|
||||
*/
|
||||
HandleLabel: function (name) {
|
||||
var global = this.stack.global, label = this.GetArgument(name);
|
||||
if (!AMS.refUpdate) {
|
||||
if (global.label) {TEX.Error("Multiple "+name+"'s")}
|
||||
global.label = label;
|
||||
if (AMS.labels[label] || AMS.eqlabels[label]) {TEX.Error("Label '"+label+"' mutiply defined")}
|
||||
AMS.eqlabels[label] = "???"; // will be replaced by tag value later
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Handle a label reference
|
||||
*/
|
||||
HandleRef: function (name,eqref) {
|
||||
var label = this.GetArgument(name);
|
||||
var ref = AMS.labels[label] || AMS.eqlabels[label];
|
||||
if (!ref) {ref = "??"; AMS.badref = !AMS.refUpdate}
|
||||
var tag = ref; if (eqref) {tag = CONFIG.formatTag(tag)}
|
||||
this.Push(MML.mrow.apply(MML,this.InternalMath(tag)).With({
|
||||
href:CONFIG.formatURL(ref), "class":"MathJax_ref"
|
||||
}));
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -202,7 +251,6 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
if (STYLE === "D") {frac.displaystyle = true; frac.scriptlevel = 0}
|
||||
else {frac.displaystyle = false; frac.scriptlevel = style - 1}
|
||||
}
|
||||
|
||||
this.Push(frac);
|
||||
},
|
||||
|
||||
|
@ -210,8 +258,8 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
* Implements multline environment (mostly handled through STACKITEM below)
|
||||
*/
|
||||
Multline: function (begin,numbered) {
|
||||
this.Push(begin);
|
||||
return STACKITEM.multline().With({
|
||||
this.Push(begin); this.checkEqnEnv();
|
||||
return STACKITEM.multline(numbered,this.stack).With({
|
||||
arraydef: {
|
||||
displaystyle: true,
|
||||
rowspacing: ".5em",
|
||||
|
@ -226,7 +274,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
* Handle AMS aligned environments
|
||||
*/
|
||||
AMSarray: function (begin,numbered,taggable,align,spacing) {
|
||||
this.Push(begin);
|
||||
this.Push(begin); if (taggable) {this.checkEqnEnv()}
|
||||
align = align.replace(/[^clr]/g,'').split('').join(' ');
|
||||
align = align.replace(/l/g,'left').replace(/r/g,'right').replace(/c/g,'center');
|
||||
return STACKITEM.AMSarray(begin.name,numbered,taggable,this.stack).With({
|
||||
|
@ -242,6 +290,9 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* Handle alignat environments
|
||||
*/
|
||||
AlignAt: function (begin,numbered,taggable) {
|
||||
var n = this.GetArgument("\\begin{"+begin.name+"}");
|
||||
if (n.match(/[^0-9]/)) {TEX.Error("Argument to \\begin{"+begin.name+"} must me a positive integer")}
|
||||
|
@ -252,6 +303,27 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
return this.Array(begin,null,null,align,spacing,".5em",'D');
|
||||
},
|
||||
|
||||
/*
|
||||
* Handle equation environment
|
||||
*/
|
||||
EquationBegin: function (begin,force) {
|
||||
this.checkEqnEnv();
|
||||
this.stack.global.forcetag = (force && CONFIG.autoNumber !== "none");
|
||||
return begin;
|
||||
},
|
||||
EquationStar: function (begin,row) {
|
||||
this.stack.global.tagged = true; // prevent automatic tagging
|
||||
return row;
|
||||
},
|
||||
|
||||
/*
|
||||
* Check for bad nesting of equation environments
|
||||
*/
|
||||
checkEqnEnv: function () {
|
||||
if (this.stack.global.eqnenv) {TEX.Error("Erroneous nesting of equation structures")}
|
||||
this.stack.global.eqnenv = true;
|
||||
},
|
||||
|
||||
/*
|
||||
* Handle multiple integrals (make a mathop if followed by limits)
|
||||
*/
|
||||
|
@ -268,6 +340,9 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
this.i = 0;
|
||||
},
|
||||
|
||||
/*
|
||||
* Handle stretchable arrows
|
||||
*/
|
||||
xArrow: function (name,chr,l,r) {
|
||||
var def = {width: "+"+(l+r)+"mu", lspace: l+"mu"};
|
||||
var bot = this.GetBrackets(name),
|
||||
|
@ -295,11 +370,43 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
}
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
STACKITEM.Augment({
|
||||
/*
|
||||
* Increment equation number and form tag mtd element
|
||||
*/
|
||||
autoTag: function () {
|
||||
var global = this.global;
|
||||
if (!global.notag) {
|
||||
AMS.number++; global.tagID = CONFIG.formatNumber(AMS.number.toString());
|
||||
var mml = TEX.Parse("\\text{"+CONFIG.formatTag(global.tagID)+"}",{}).mml();
|
||||
global.tag = MML.mtd(mml.With({id:CONFIG.formatID(global.tagID)}));
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Get the tag and record the label, if any
|
||||
*/
|
||||
getTag: function () {
|
||||
var global = this.global, tag = global.tag; global.tagged = true;
|
||||
if (global.label) {AMS.eqlabels[global.label] = global.tagID}
|
||||
delete global.tag; delete global.tagID; delete global.label;
|
||||
return tag;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Implement multline environment via a STACKITEM
|
||||
*/
|
||||
STACKITEM.multline = STACKITEM.array.Subclass({
|
||||
type: "multline",
|
||||
Init: function (numbered,stack) {
|
||||
this.SUPER(arguments).Init.apply(this);
|
||||
this.numbered = (numbered && CONFIG.autoNumber !== "none");
|
||||
this.save = {notag: stack.global.notag};
|
||||
stack.global.tagged = !numbered && !stack.global.forcetag; // prevent automatic tagging in starred environments
|
||||
},
|
||||
EndEntry: function () {
|
||||
var mtd = MML.mtd.apply(MML,this.data);
|
||||
if (this.data.shove) {mtd.columnalign = this.data.shove}
|
||||
|
@ -317,37 +424,46 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
if (!this.table[0][0].columnalign) {this.table[0][0].columnalign = MML.ALIGN.LEFT}
|
||||
if (!this.table[m][0].columnalign) {this.table[m][0].columnalign = MML.ALIGN.RIGHT}
|
||||
var mtr = MML.mtr;
|
||||
if (this.global.tag) {
|
||||
this.table[0] = [this.global.tag].concat(this.table[0]);
|
||||
delete this.global.tag; mtr = MML.mlabeledtr;
|
||||
if (!this.global.tag && this.numbered) {this.autoTag()}
|
||||
if (this.global.tag && !this.global.notags) {
|
||||
this.table[0] = [this.getTag()].concat(this.table[0]);
|
||||
mtr = MML.mlabeledtr;
|
||||
}
|
||||
this.table[0] = mtr.apply(MML,this.table[0]);
|
||||
for (i = 1, m = this.table.length; i < m; i++)
|
||||
{this.table[i] = MML.mtr.apply(MML,this.table[i])}
|
||||
}
|
||||
this.global.notag = this.save.notag;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Save data about numbering and taging equations, and add
|
||||
* tags at the ends of rows.
|
||||
*/
|
||||
STACKITEM.AMSarray = STACKITEM.array.Subclass({
|
||||
type: "AMSarray",
|
||||
Init: function (name,numbered,taggable,stack) {
|
||||
this.SUPER(arguments).Init.apply(this);
|
||||
this.numbered = numbered;
|
||||
this.save_notag = stack.global.notag;
|
||||
stack.global.notag = (taggable ? null : name);
|
||||
this.numbered = (numbered && CONFIG.autoNumber !== "none");
|
||||
this.save = {notags: stack.global.notags, notag: stack.global.notag};
|
||||
stack.global.notags = (taggable ? null : name);
|
||||
stack.global.tagged = !numbered && !stack.global.forcetag; // prevent automatic tagging in starred environments
|
||||
},
|
||||
EndRow: function () {
|
||||
var mtr = MML.mtr;
|
||||
if (this.global.tag) {
|
||||
this.row = [this.global.tag].concat(this.row);
|
||||
if (!this.global.tag && this.numbered) {this.autoTag()}
|
||||
if (this.global.tag &&! this.global.notags) {
|
||||
this.row = [this.getTag()].concat(this.row);
|
||||
mtr = MML.mlabeledtr;
|
||||
delete this.global.tag;
|
||||
}
|
||||
if (this.numbered) {delete this.global.notag}
|
||||
this.table.push(mtr.apply(MML,this.row)); this.row = [];
|
||||
},
|
||||
EndTable: function () {
|
||||
this.SUPER(arguments).EndTable.call(this);
|
||||
this.global.notag = this.save_notag;
|
||||
this.global.notags = this.save.notags;
|
||||
this.global.notag = this.save.notag;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -358,9 +474,11 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
oldCheckItem: STACKITEM.start.prototype.checkItem,
|
||||
checkItem: function (item) {
|
||||
if (item.type === "stop") {
|
||||
var mml = this.mmlData();
|
||||
if (this.global.tag) {
|
||||
var row = [this.global.tag,MML.mtd(mml)]; delete this.global.tag;
|
||||
var mml = this.mmlData(), global = this.global;
|
||||
if (AMS.display && !global.tag && !global.tagged && !global.isInner &&
|
||||
(CONFIG.autoNumber === "all" || global.forcetag)) {this.autoTag()}
|
||||
if (global.tag) {
|
||||
var row = [this.getTag(),MML.mtd(mml)];
|
||||
var def = {
|
||||
side: TEX.config.TagSide,
|
||||
minlabelspacing: TEX.config.TagIndent,
|
||||
|
@ -383,10 +501,44 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
|||
}
|
||||
return STACKITEM.mml(mml);
|
||||
}
|
||||
return this.SUPER(arguments).checkItem.call(this,item);
|
||||
return this.oldCheckItem.call(this,item);
|
||||
}
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/*
|
||||
* Add pre- and post-filters to handle the equation number maintainance.
|
||||
*/
|
||||
TEX.prefilterHooks.Add(function (data) {
|
||||
AMS.display = data.display;
|
||||
AMS.number = AMS.startNumber; // reset equation numbers (in case the equation restarted)
|
||||
AMS.eqlabels = {}; AMS.badref = false;
|
||||
if (AMS.refUpdate) {AMS.number = data.script.MathJax.startNumber}
|
||||
});
|
||||
TEX.postfilterHooks.Add(function (data) {
|
||||
data.script.MathJax.startNumber = AMS.startNumber;
|
||||
AMS.startNumber = AMS.number; // equation numbers for next equation
|
||||
MathJax.Hub.Insert(AMS.labels,AMS.eqlabels); // save labels from this equation
|
||||
if (AMS.badref && !data.math.isError) {AMS.refs.push(data.script)} // reprocess later
|
||||
});
|
||||
|
||||
MathJax.Hub.Register.MessageHook("Begin Math Input",function () {
|
||||
AMS.refs = []; // array of jax with bad references
|
||||
AMS.refUpdate = false;
|
||||
});
|
||||
MathJax.Hub.Register.MessageHook("End Math Input",function (message) {
|
||||
if (AMS.refs.length) {
|
||||
AMS.refUpdate = true;
|
||||
for (var i = 0, m = AMS.refs.length; i < m; i++)
|
||||
{AMS.refs[i].MathJax.state = MathJax.ElementJax.STATE.UPDATE}
|
||||
return MathJax.Hub.processInput(AMS.refs);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
MathJax.Hub.Startup.signal.Post("TeX AMSmath Ready");
|
||||
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
MathJax.Extension.tex2jax = {
|
||||
version: "1.1.2",
|
||||
version: "1.1.3",
|
||||
config: {
|
||||
inlineMath: [ // The start/stop pairs for in-line math
|
||||
// ['$','$'], // (comment out any you don't want, or add your own, but
|
||||
|
@ -56,6 +56,8 @@ MathJax.Extension.tex2jax = {
|
|||
processEnvironments: true, // set to true to process \begin{xxx}...\end{xxx} outside
|
||||
// of math mode, false to prevent that
|
||||
|
||||
processRefs: true, // set to true to process \ref{...} outside of math mode
|
||||
|
||||
preview: "TeX" // set to "none" to not insert MathJax_Preview spans
|
||||
// or set to an array specifying an HTML snippet
|
||||
// to use the same preview for every equation.
|
||||
|
@ -96,9 +98,10 @@ MathJax.Extension.tex2jax = {
|
|||
};
|
||||
}
|
||||
this.start = new RegExp(
|
||||
starts.sort(this.sortLength).join("|") +
|
||||
(config.processEnvironments ? "|\\\\begin\\{([^}]*)\\}" : "") +
|
||||
(config.processEscapes ? "|\\\\*\\\\\\\$" : ""), "g"
|
||||
starts.sort(this.sortLength).join("|") +
|
||||
(config.processEnvironments ? "|\\\\begin\\{([^}]*)\\}" : "") +
|
||||
(config.processEscapes ? "|\\\\*\\\\\\\$" : "") +
|
||||
(config.processRefs ? "|\\\\(eq)?ref\\{[^}]*\\}" : ""), "g"
|
||||
);
|
||||
this.skipTags = new RegExp("^("+config.skipTags.join("|")+")$","i");
|
||||
this.ignoreClass = new RegExp("(^| )("+config.ignoreClass+")( |$)");
|
||||
|
@ -172,6 +175,12 @@ MathJax.Extension.tex2jax = {
|
|||
isBeginEnd: true
|
||||
};
|
||||
this.switchPattern(this.endPattern(this.search.end));
|
||||
} else if (match[0].substr(0,4) === "\\ref" || match[0].substr(0,6) === "\\eqref") {
|
||||
this.search = {
|
||||
mode: "", end: "", open: element,
|
||||
olen: 0, opos: this.pattern.lastIndex - match[0].length,
|
||||
}
|
||||
return this.endMatch([""],element);
|
||||
} else { // escaped dollar signs
|
||||
var dollar = match[0].replace(/\\(.)/g,'$1');
|
||||
element.nodeValue = element.nodeValue.substr(0,match.index) + dollar +
|
||||
|
|
|
@ -24,14 +24,23 @@
|
|||
|
||||
MathJax.InputJax.TeX = MathJax.InputJax({
|
||||
id: "TeX",
|
||||
version: "1.1.2",
|
||||
version: "1.1.3",
|
||||
directory: MathJax.InputJax.directory + "/TeX",
|
||||
extensionDir: MathJax.InputJax.extensionDir + "/TeX",
|
||||
|
||||
config: {
|
||||
TagSide: "right",
|
||||
TagIndent: "0.8em",
|
||||
MultLineWidth: "85%"
|
||||
MultLineWidth: "85%",
|
||||
|
||||
equationNumbers: {
|
||||
autoNumber: "none", // "AMS" for standard AMS numbering,
|
||||
// or "all" for all displayed equations
|
||||
formatNumber: function (n) {return n},
|
||||
formatTag: function (n) {return '('+n+')'},
|
||||
formatID: function (n) {return 'mjx-eqn-'+n},
|
||||
formatURL: function (n) {return '#mjx-eqn-'+escape(n)}
|
||||
}
|
||||
}
|
||||
});
|
||||
MathJax.InputJax.TeX.Register("math/tex");
|
||||
|
|
|
@ -850,8 +850,10 @@
|
|||
|
||||
tag: ['Extension','AMSmath'],
|
||||
notag: ['Extension','AMSmath'],
|
||||
label: ['Macro','',1], // not implemented yet
|
||||
nonumber: ['Macro',''], // not implemented yet
|
||||
label: ['Extension','AMSmath'],
|
||||
ref: ['Extension','AMSmath'],
|
||||
eqref: ['Extension','AMSmath'],
|
||||
nonumber: ['Macro','\\notag'],
|
||||
|
||||
// Extensions to TeX
|
||||
unicode: ['Extension','unicode'],
|
||||
|
@ -1627,7 +1629,7 @@
|
|||
InternalMath: function (text,level) {
|
||||
var def = {displaystyle: FALSE}; if (level != null) {def.scriptlevel = level}
|
||||
if (this.stack.env.font) {def.mathvariant = this.stack.env.font}
|
||||
if (!text.match(/\$|\\\(/)) {return [this.InternalText(text,def)]}
|
||||
if (!text.match(/\$|\\\(|\\(eq)?ref\s*\{/)) {return [this.InternalText(text,def)]}
|
||||
var i = 0, k = 0, c, match = '';
|
||||
var mml = [];
|
||||
while (i < text.length) {
|
||||
|
@ -1640,14 +1642,22 @@
|
|||
if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))}
|
||||
match = '$'; k = i;
|
||||
}
|
||||
} else if (c === '}' && match === '}') {
|
||||
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i),{}).mml().With(def)));
|
||||
match = ''; k = i+1;
|
||||
} else if (c === '\\') {
|
||||
c = text.charAt(i++);
|
||||
if (c === '(' && match === '') {
|
||||
if (k < i-2) {mml.push(this.InternalText(text.slice(k,i-2),def))}
|
||||
match = ')'; k = i;
|
||||
} else if (c === ')' && match === ')') {
|
||||
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml().With(def)));
|
||||
match = ''; k = i;
|
||||
if (match === '' && text.substr(i).match(/^(eq)?ref\s*\{/)) {
|
||||
if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))}
|
||||
match = '}'; k = i-1;
|
||||
} else {
|
||||
c = text.charAt(i++);
|
||||
if (c === '(' && match === '') {
|
||||
if (k < i-2) {mml.push(this.InternalText(text.slice(k,i-2),def))}
|
||||
match = ')'; k = i;
|
||||
} else if (c === ')' && match === ')') {
|
||||
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml().With(def)));
|
||||
match = ''; k = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user