Add support for automatic line numbers, and the \label and \ref macros (resolves issue #71)

This commit is contained in:
Davide P. Cervone 2011-05-01 19:05:02 -04:00
parent c23c21443e
commit 7e2ed03750
15 changed files with 290 additions and 72 deletions

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

View File

@ -262,6 +262,13 @@ MathJax.Hub.Config({
// //
processEnvironments: true, 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 // Controls whether tex2jax inserts MathJax_Preview spans to make a
// preview available, and what preview to use, when it locates in-line // preview available, and what preview to use, when it locates in-line
@ -368,7 +375,19 @@ MathJax.Hub.Config({
// bold: ['{\\bf #1}', 1] // 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

View File

@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0 * 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

View File

@ -262,6 +262,13 @@ MathJax.Hub.Config({
// //
processEnvironments: true, 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 // Controls whether tex2jax inserts MathJax_Preview spans to make a
// preview available, and what preview to use, when it locates in-line // preview available, and what preview to use, when it locates in-line
@ -368,7 +375,19 @@ MathJax.Hub.Config({
// bold: ['{\\bf #1}', 1] // 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
}
}, },

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,16 +21,30 @@
* limitations under the License. * limitations under the License.
*/ */
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { MathJax.Extension["TeX/AMSmath"] = {
var VERSION = "1.1"; version: "1.1.1",
var MML = MathJax.ElementJax.mml; number: 0, // current equation number
var TEX = MathJax.InputJax.TeX; startNumber: 0, // current starting equation number (for when equation is restarted)
var TEXDEF = TEX.Definitions; labels: {}, // the set of labels
var STACKITEM = TEX.Stack.Item; eqlabels: {}, // labels in the current equation
refs: [] // array of jax with unresolved references
};
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
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"}; var COLS = function (W) {return W.join("em ") + "em"};
/******************************************************************************/
MathJax.Hub.Insert(TEXDEF,{ MathJax.Hub.Insert(TEXDEF,{
macros: { macros: {
mathring: ['Accent','2DA'], // or 0x30A mathring: ['Accent','2DA'], // or 0x30A
@ -54,6 +68,9 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
tag: 'HandleTag', tag: 'HandleTag',
notag: 'HandleNoTag', notag: 'HandleNoTag',
label: 'HandleLabel',
ref: 'HandleRef',
eqref: ['HandleRef',true],
substack: ['Macro','\\begin{subarray}{c}#1\\end{subarray}',1], 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'], gathered: ['Array',null,null,null,'c',null,".5em",'D'],
subarray: ['Array',null,null,null,null,COLS([0,0,0,0]),"0.1em",'S',1], 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: { delimiter: {
@ -113,21 +133,50 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
}); });
/******************************************************************************/
TEX.Parse.Augment({ 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) { HandleTag: function (name) {
var arg = this.trimSpaces(this.GetArgument(name)); var arg = this.trimSpaces(this.GetArgument(name)), tag = arg;
if (arg === "*") {arg = this.GetArgument(name)} else {arg = "("+arg+")"} if (arg === "*") {tag = arg = this.GetArgument(name)} else {arg = CONFIG.formatTag(arg)}
if (this.stack.global.notag) var global = this.stack.global; global.tagID = tag;
{TEX.Error(name+" not allowed in "+this.stack.global.notag+" environment")} if (global.notags) {TEX.Error(name+" not allowed in "+global.notags+" environment")}
if (this.stack.global.tag) {TEX.Error("Multiple "+name)} if (global.tag) {TEX.Error("Multiple "+name)}
this.stack.global.tag = MML.mtd.apply(MML,this.InternalMath(arg)); global.tag = MML.mtd.apply(MML,this.InternalMath(arg)).With({id:CONFIG.formatID(tag)});
}, },
HandleNoTag: function (name) { HandleNoTag: function (name) {
if (this.stack.global.tag) {delete this.stack.global.tag} 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} if (STYLE === "D") {frac.displaystyle = true; frac.scriptlevel = 0}
else {frac.displaystyle = false; frac.scriptlevel = style - 1} else {frac.displaystyle = false; frac.scriptlevel = style - 1}
} }
this.Push(frac); this.Push(frac);
}, },
@ -210,8 +258,8 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
* Implements multline environment (mostly handled through STACKITEM below) * Implements multline environment (mostly handled through STACKITEM below)
*/ */
Multline: function (begin,numbered) { Multline: function (begin,numbered) {
this.Push(begin); this.Push(begin); this.checkEqnEnv();
return STACKITEM.multline().With({ return STACKITEM.multline(numbered,this.stack).With({
arraydef: { arraydef: {
displaystyle: true, displaystyle: true,
rowspacing: ".5em", rowspacing: ".5em",
@ -226,7 +274,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
* Handle AMS aligned environments * Handle AMS aligned environments
*/ */
AMSarray: function (begin,numbered,taggable,align,spacing) { 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(/[^clr]/g,'').split('').join(' ');
align = align.replace(/l/g,'left').replace(/r/g,'right').replace(/c/g,'center'); align = align.replace(/l/g,'left').replace(/r/g,'right').replace(/c/g,'center');
return STACKITEM.AMSarray(begin.name,numbered,taggable,this.stack).With({ 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) { AlignAt: function (begin,numbered,taggable) {
var n = this.GetArgument("\\begin{"+begin.name+"}"); var n = this.GetArgument("\\begin{"+begin.name+"}");
if (n.match(/[^0-9]/)) {TEX.Error("Argument to \\begin{"+begin.name+"} must me a positive integer")} 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'); 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) * 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; this.i = 0;
}, },
/*
* Handle stretchable arrows
*/
xArrow: function (name,chr,l,r) { xArrow: function (name,chr,l,r) {
var def = {width: "+"+(l+r)+"mu", lspace: l+"mu"}; var def = {width: "+"+(l+r)+"mu", lspace: l+"mu"};
var bot = this.GetBrackets(name), 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 * Implement multline environment via a STACKITEM
*/ */
STACKITEM.multline = STACKITEM.array.Subclass({ STACKITEM.multline = STACKITEM.array.Subclass({
type: "multline", 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 () { EndEntry: function () {
var mtd = MML.mtd.apply(MML,this.data); var mtd = MML.mtd.apply(MML,this.data);
if (this.data.shove) {mtd.columnalign = this.data.shove} 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[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} if (!this.table[m][0].columnalign) {this.table[m][0].columnalign = MML.ALIGN.RIGHT}
var mtr = MML.mtr; var mtr = MML.mtr;
if (this.global.tag) { if (!this.global.tag && this.numbered) {this.autoTag()}
this.table[0] = [this.global.tag].concat(this.table[0]); if (this.global.tag && !this.global.notags) {
delete this.global.tag; mtr = MML.mlabeledtr; this.table[0] = [this.getTag()].concat(this.table[0]);
mtr = MML.mlabeledtr;
} }
this.table[0] = mtr.apply(MML,this.table[0]); this.table[0] = mtr.apply(MML,this.table[0]);
for (i = 1, m = this.table.length; i < m; i++) for (i = 1, m = this.table.length; i < m; i++)
{this.table[i] = MML.mtr.apply(MML,this.table[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({ STACKITEM.AMSarray = STACKITEM.array.Subclass({
type: "AMSarray", type: "AMSarray",
Init: function (name,numbered,taggable,stack) { Init: function (name,numbered,taggable,stack) {
this.SUPER(arguments).Init.apply(this); this.SUPER(arguments).Init.apply(this);
this.numbered = numbered; this.numbered = (numbered && CONFIG.autoNumber !== "none");
this.save_notag = stack.global.notag; this.save = {notags: stack.global.notags, notag: stack.global.notag};
stack.global.notag = (taggable ? null : name); stack.global.notags = (taggable ? null : name);
stack.global.tagged = !numbered && !stack.global.forcetag; // prevent automatic tagging in starred environments
}, },
EndRow: function () { EndRow: function () {
var mtr = MML.mtr; var mtr = MML.mtr;
if (this.global.tag) { if (!this.global.tag && this.numbered) {this.autoTag()}
this.row = [this.global.tag].concat(this.row); if (this.global.tag &&! this.global.notags) {
this.row = [this.getTag()].concat(this.row);
mtr = MML.mlabeledtr; mtr = MML.mlabeledtr;
delete this.global.tag;
} }
if (this.numbered) {delete this.global.notag}
this.table.push(mtr.apply(MML,this.row)); this.row = []; this.table.push(mtr.apply(MML,this.row)); this.row = [];
}, },
EndTable: function () { EndTable: function () {
this.SUPER(arguments).EndTable.call(this); 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, oldCheckItem: STACKITEM.start.prototype.checkItem,
checkItem: function (item) { checkItem: function (item) {
if (item.type === "stop") { if (item.type === "stop") {
var mml = this.mmlData(); var mml = this.mmlData(), global = this.global;
if (this.global.tag) { if (AMS.display && !global.tag && !global.tagged && !global.isInner &&
var row = [this.global.tag,MML.mtd(mml)]; delete this.global.tag; (CONFIG.autoNumber === "all" || global.forcetag)) {this.autoTag()}
if (global.tag) {
var row = [this.getTag(),MML.mtd(mml)];
var def = { var def = {
side: TEX.config.TagSide, side: TEX.config.TagSide,
minlabelspacing: TEX.config.TagIndent, minlabelspacing: TEX.config.TagIndent,
@ -383,10 +501,44 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
} }
return STACKITEM.mml(mml); 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"); MathJax.Hub.Startup.signal.Post("TeX AMSmath Ready");
}); });

View File

@ -24,7 +24,7 @@
*/ */
MathJax.Extension.tex2jax = { MathJax.Extension.tex2jax = {
version: "1.1.2", version: "1.1.3",
config: { config: {
inlineMath: [ // The start/stop pairs for in-line math inlineMath: [ // The start/stop pairs for in-line math
// ['$','$'], // (comment out any you don't want, or add your own, but // ['$','$'], // (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 processEnvironments: true, // set to true to process \begin{xxx}...\end{xxx} outside
// of math mode, false to prevent that // 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 preview: "TeX" // set to "none" to not insert MathJax_Preview spans
// or set to an array specifying an HTML snippet // or set to an array specifying an HTML snippet
// to use the same preview for every equation. // to use the same preview for every equation.
@ -98,7 +100,8 @@ MathJax.Extension.tex2jax = {
this.start = new RegExp( this.start = new RegExp(
starts.sort(this.sortLength).join("|") + starts.sort(this.sortLength).join("|") +
(config.processEnvironments ? "|\\\\begin\\{([^}]*)\\}" : "") + (config.processEnvironments ? "|\\\\begin\\{([^}]*)\\}" : "") +
(config.processEscapes ? "|\\\\*\\\\\\\$" : ""), "g" (config.processEscapes ? "|\\\\*\\\\\\\$" : "") +
(config.processRefs ? "|\\\\(eq)?ref\\{[^}]*\\}" : ""), "g"
); );
this.skipTags = new RegExp("^("+config.skipTags.join("|")+")$","i"); this.skipTags = new RegExp("^("+config.skipTags.join("|")+")$","i");
this.ignoreClass = new RegExp("(^| )("+config.ignoreClass+")( |$)"); this.ignoreClass = new RegExp("(^| )("+config.ignoreClass+")( |$)");
@ -172,6 +175,12 @@ MathJax.Extension.tex2jax = {
isBeginEnd: true isBeginEnd: true
}; };
this.switchPattern(this.endPattern(this.search.end)); 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 } else { // escaped dollar signs
var dollar = match[0].replace(/\\(.)/g,'$1'); var dollar = match[0].replace(/\\(.)/g,'$1');
element.nodeValue = element.nodeValue.substr(0,match.index) + dollar + element.nodeValue = element.nodeValue.substr(0,match.index) + dollar +

View File

@ -24,14 +24,23 @@
MathJax.InputJax.TeX = MathJax.InputJax({ MathJax.InputJax.TeX = MathJax.InputJax({
id: "TeX", id: "TeX",
version: "1.1.2", version: "1.1.3",
directory: MathJax.InputJax.directory + "/TeX", directory: MathJax.InputJax.directory + "/TeX",
extensionDir: MathJax.InputJax.extensionDir + "/TeX", extensionDir: MathJax.InputJax.extensionDir + "/TeX",
config: { config: {
TagSide: "right", TagSide: "right",
TagIndent: "0.8em", 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"); MathJax.InputJax.TeX.Register("math/tex");

View File

@ -850,8 +850,10 @@
tag: ['Extension','AMSmath'], tag: ['Extension','AMSmath'],
notag: ['Extension','AMSmath'], notag: ['Extension','AMSmath'],
label: ['Macro','',1], // not implemented yet label: ['Extension','AMSmath'],
nonumber: ['Macro',''], // not implemented yet ref: ['Extension','AMSmath'],
eqref: ['Extension','AMSmath'],
nonumber: ['Macro','\\notag'],
// Extensions to TeX // Extensions to TeX
unicode: ['Extension','unicode'], unicode: ['Extension','unicode'],
@ -1627,7 +1629,7 @@
InternalMath: function (text,level) { InternalMath: function (text,level) {
var def = {displaystyle: FALSE}; if (level != null) {def.scriptlevel = level} var def = {displaystyle: FALSE}; if (level != null) {def.scriptlevel = level}
if (this.stack.env.font) {def.mathvariant = this.stack.env.font} 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 i = 0, k = 0, c, match = '';
var mml = []; var mml = [];
while (i < text.length) { while (i < text.length) {
@ -1640,7 +1642,14 @@
if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))} if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))}
match = '$'; k = i; 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 === '\\') { } else if (c === '\\') {
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++); c = text.charAt(i++);
if (c === '(' && match === '') { if (c === '(' && match === '') {
if (k < i-2) {mml.push(this.InternalText(text.slice(k,i-2),def))} if (k < i-2) {mml.push(this.InternalText(text.slice(k,i-2),def))}
@ -1651,6 +1660,7 @@
} }
} }
} }
}
if (match !== '') {TEX.Error("Math not terminated in text box")} if (match !== '') {TEX.Error("Math not terminated in text box")}
if (k < text.length) {mml.push(this.InternalText(text.slice(k),def))} if (k < text.length) {mml.push(this.InternalText(text.slice(k),def))}
return mml; return mml;