Allow \newcommand to take a default parameter, and adjust GetBrackets to distinguish between no brackets and empty brackets

This commit is contained in:
Davide P. Cervone 2012-01-07 18:55:52 -05:00
parent 51a65e5b52
commit 3131d09d06
18 changed files with 53 additions and 42 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

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
*/
MathJax.Extension["TeX/bbox"]={version:"1.1"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var b=MathJax.InputJax.TeX,a=MathJax.ElementJax.mml;b.Definitions.macros.bbox="BBox";b.Parse.Augment({BBox:function(e){var n=this.GetBrackets(e),m=this.ParseArg(e);var j=n.split(/,/),g,d,c;for(var k in j){var f=j[k].replace(/^\s+/,"").replace(/\s+$/,"");var l=f.match(/^(\.\d+|\d+(\.\d*)?)(pt|em|ex|mu|px|in|cm|mm)$/);if(l){var h=l[1]+l[3];if(g){b.Error("Padding specified twice in "+e)}g={height:"+"+h,depth:"+"+h,lspace:h,width:"+"+(2*l[1])+l[3]}}else{if(f.match(/^([a-z0-9]+|\#[0-9a-f]{6}|\#[0-9a-f]{3})$/i)){if(d){b.Error("Background specified twice in "+e)}d=f}else{if(f.match(/^[-a-z]+:/i)){if(c){b.Error("Style specified twice in "+e)}c=f}else{if(f!==""){b.Error("'"+f+"' doesn't look like a color, a padding dimension, or a style")}}}}}if(g){m=a.mpadded(m).With(g)}if(d||c){m=a.mstyle(m).With({mathbackground:d,style:c})}this.Push(m)}});MathJax.Hub.Startup.signal.Post("TeX bbox Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/bbox.js");
MathJax.Extension["TeX/bbox"]={version:"1.1"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var b=MathJax.InputJax.TeX,a=MathJax.ElementJax.mml;b.Definitions.macros.bbox="BBox";b.Parse.Augment({BBox:function(e){var n=this.GetBrackets(e,""),m=this.ParseArg(e);var j=n.split(/,/),g,d,c;for(var k in j){var f=j[k].replace(/^\s+/,"").replace(/\s+$/,"");var l=f.match(/^(\.\d+|\d+(\.\d*)?)(pt|em|ex|mu|px|in|cm|mm)$/);if(l){var h=l[1]+l[3];if(g){b.Error("Padding specified twice in "+e)}g={height:"+"+h,depth:"+"+h,lspace:h,width:"+"+(2*l[1])+l[3]}}else{if(f.match(/^([a-z0-9]+|\#[0-9a-f]{6}|\#[0-9a-f]{3})$/i)){if(d){b.Error("Background specified twice in "+e)}d=f}else{if(f.match(/^[-a-z]+:/i)){if(c){b.Error("Style specified twice in "+e)}c=f}else{if(f!==""){b.Error("'"+f+"' doesn't look like a color, a padding dimension, or a style")}}}}}if(g){m=a.mpadded(m).With(g)}if(d||c){m=a.mstyle(m).With({mathbackground:d,style:c})}this.Push(m)}});MathJax.Hub.Startup.signal.Post("TeX bbox Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/bbox.js");

View File

@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Extension["TeX/cancel"]={version:"1.1",ALLOWED:{arrow:1,color:1,mathcolor:1,background:1,mathbackground:1,padding:1,thickness:1}};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var d=MathJax.InputJax.TeX,c=d.Definitions.macros,a=MathJax.ElementJax.mml,b=MathJax.Extension["TeX/cancel"];b.setAttributes=function(j,f){if(f!==""){f=f.replace(/ /g,"").split(/,/);for(var h=0,e=f.length;h<e;h++){var g=f[h].split(/[:=]/);if(b.ALLOWED[g[0]]){if(g[1]==="true"){g[1]=true}if(g[1]==="false"){g[1]=false}j[g[0]]=g[1]}}}return j};c.cancel=["Cancel",a.NOTATION.UPDIAGONALSTRIKE];c.bcancel=["Cancel",a.NOTATION.DOWNDIAGONALSTRIKE];c.xcancel=["Cancel",a.NOTATION.UPDIAGONALSTRIKE+" "+a.NOTATION.DOWNDIAGONALSTRIKE];c.cancelto="CancelTo";d.Parse.Augment({Cancel:function(f,h){var e=this.GetBrackets(f),g=this.ParseArg(f);var i=b.setAttributes({notation:h},e);this.Push(a.menclose(g).With(i))},CancelTo:function(f,h){var j=this.ParseArg(f),e=this.GetBrackets(f),g=this.ParseArg(f);var i=b.setAttributes({notation:a.NOTATION.UPDIAGONALSTRIKE,arrow:true},e);j=a.mpadded(j).With({depth:"-.1em",height:"+.1em",voffset:".1em"});this.Push(a.msup(a.menclose(g).With(i),j))}});MathJax.Hub.Startup.signal.Post("TeX cancel Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/cancel.js");
MathJax.Extension["TeX/cancel"]={version:"1.1",ALLOWED:{arrow:1,color:1,mathcolor:1,background:1,mathbackground:1,padding:1,thickness:1}};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var d=MathJax.InputJax.TeX,c=d.Definitions.macros,a=MathJax.ElementJax.mml,b=MathJax.Extension["TeX/cancel"];b.setAttributes=function(j,f){if(f!==""){f=f.replace(/ /g,"").split(/,/);for(var h=0,e=f.length;h<e;h++){var g=f[h].split(/[:=]/);if(b.ALLOWED[g[0]]){if(g[1]==="true"){g[1]=true}if(g[1]==="false"){g[1]=false}j[g[0]]=g[1]}}}return j};c.cancel=["Cancel",a.NOTATION.UPDIAGONALSTRIKE];c.bcancel=["Cancel",a.NOTATION.DOWNDIAGONALSTRIKE];c.xcancel=["Cancel",a.NOTATION.UPDIAGONALSTRIKE+" "+a.NOTATION.DOWNDIAGONALSTRIKE];c.cancelto="CancelTo";d.Parse.Augment({Cancel:function(f,h){var e=this.GetBrackets(f,""),g=this.ParseArg(f);var i=b.setAttributes({notation:h},e);this.Push(a.menclose(g).With(i))},CancelTo:function(f,h){var j=this.ParseArg(f),e=this.GetBrackets(f,""),g=this.ParseArg(f);var i=b.setAttributes({notation:a.NOTATION.UPDIAGONALSTRIKE,arrow:true},e);j=a.mpadded(j).With({depth:"-.1em",height:"+.1em",voffset:".1em"});this.Push(a.msup(a.menclose(g).With(i),j))}});MathJax.Hub.Startup.signal.Post("TeX cancel Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/cancel.js");

View File

@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Extension["TeX/enclose"]={version:"1.1",ALLOWED:{arrow:1,color:1,mathcolor:1,background:1,mathbackground:1,padding:1,thickness:1}};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var c=MathJax.InputJax.TeX,a=MathJax.ElementJax.mml,b=MathJax.Extension["TeX/enclose"].ALLOWED;c.Definitions.macros.enclose="Enclose";c.Parse.Augment({Enclose:function(g){var k=this.GetArgument(g),e=this.GetBrackets(g),j=this.ParseArg(g);var l={notation:k.replace(/,/g," ")};if(e!==""){e=e.replace(/ /g,"").split(/,/);for(var h=0,d=e.length;h<d;h++){var f=e[h].split(/[:=]/);if(b[f[0]]){if(f[1]==="true"){f[1]=true}if(f[1]==="false"){f[1]=false}l[f[0]]=f[1]}}}this.Push(a.menclose(j).With(l))}});MathJax.Hub.Startup.signal.Post("TeX enclose Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/enclose.js");
MathJax.Extension["TeX/enclose"]={version:"1.1",ALLOWED:{arrow:1,color:1,mathcolor:1,background:1,mathbackground:1,padding:1,thickness:1}};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var c=MathJax.InputJax.TeX,a=MathJax.ElementJax.mml,b=MathJax.Extension["TeX/enclose"].ALLOWED;c.Definitions.macros.enclose="Enclose";c.Parse.Augment({Enclose:function(g){var k=this.GetArgument(g),e=this.GetBrackets(g),j=this.ParseArg(g);var l={notation:k.replace(/,/g," ")};if(e){e=e.replace(/ /g,"").split(/,/);for(var h=0,d=e.length;h<d;h++){var f=e[h].split(/[:=]/);if(b[f[0]]){if(f[1]==="true"){f[1]=true}if(f[1]==="false"){f[1]=false}l[f[0]]=f[1]}}}this.Push(a.menclose(j).With(l))}});MathJax.Hub.Startup.signal.Post("TeX enclose Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/enclose.js");

View File

@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Extension["TeX/newcommand"]={version:"1.1.2"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var b=MathJax.InputJax.TeX;var a=b.Definitions;a.Add({macros:{newcommand:"NewCommand",renewcommand:"NewCommand",newenvironment:"NewEnvironment",renewenvironment:"NewEnvironment",def:"MacroDef",let:"Let"}},null,true);b.Parse.Augment({NewCommand:function(c){var d=this.trimSpaces(this.GetArgument(c)),f=this.trimSpaces(this.GetBrackets(c)),e=this.GetArgument(c);if(f===""){f=null}if(d.charAt(0)==="\\"){d=d.substr(1)}if(!d.match(/^(.|[a-z]+)$/i)){b.Error("Illegal control sequence name for "+c)}if(f!=null&&!f.match(/^[0-9]+$/)){b.Error("Illegal number of parameters specified in "+c)}this.setDef(d,["Macro",e,f])},NewEnvironment:function(d){var e=this.trimSpaces(this.GetArgument(d)),g=this.trimSpaces(this.GetBrackets(d)),f=this.GetArgument(d),c=this.GetArgument(d);if(g===""){g=null}if(g!=null&&!g.match(/^[0-9]+$/)){b.Error("Illegal number of parameters specified in "+d)}this.setEnv(e,["BeginEnv","EndEnv",f,c,g])},MacroDef:function(c){var d=this.GetCSname(c),f=this.GetTemplate(c,"\\"+d),e=this.GetArgument(c);if(!(f instanceof Array)){this.setDef(d,["Macro",e,f])}else{this.setDef(d,["MacroWithTemplate",e].concat(f))}},Let:function(d){var e=this.GetCSname(d),f;var g=this.GetNext();if(g==="="){this.i++;g=this.GetNext()}if(g==="\\"){d=this.GetCSname(d);f=this.csFindMacro(d);if(!f){if(a.mathchar0mi[d]){f=["csMathchar0mi",a.mathchar0mi[d]]}else{if(a.mathchar0mo[d]){f=["csMathchar0mo",a.mathchar0mo[d]]}else{if(a.mathchar7[d]){f=["csMathchar7",a.mathchar7[d]]}else{if(a.delimiter["\\"+d]!=null){f=["csDelimiter",a.delimiter["\\"+d]]}}}}}}else{f=["Macro",g];this.i++}this.setDef(e,f)},setDef:function(c,d){d.isUser=true;a.macros[c]=d},setEnv:function(c,d){d.isUser=true;a.environment[c]=d},GetCSname:function(e){var f=this.GetNext();if(f!=="\\"){b.Error("\\ must be followed by a control sequence")}var d=this.trimSpaces(this.GetArgument(e));return d.substr(1)},GetTemplate:function(f,e){var j,g=[],h=0;j=this.GetNext();var d=this.i;while(this.i<this.string.length){j=this.GetNext();if(j==="#"){if(d!==this.i){g[h]=this.string.substr(d,this.i-d)}j=this.string.charAt(++this.i);if(!j.match(/^[1-9]$/)){b.Error("Illegal use of # in template for "+e)}if(parseInt(j)!=++h){b.Error("Parameters for "+e+" must be numbered sequentially")}d=this.i+1}else{if(j==="{"){if(d!==this.i){g[h]=this.string.substr(d,this.i-d)}if(g.length>0){return[h,g]}else{return h}}}this.i++}b.Error("Missing replacement string for definition of "+f)},MacroWithTemplate:function(d,g,h,f){if(h){var c=[];this.GetNext();if(f[0]&&!this.MatchParam(f[0])){b.Error("Use of "+d+" doesn't match its definition")}for(var e=0;e<h;e++){c.push(this.GetParameter(d,f[e+1]))}g=this.SubstituteArgs(c,g)}this.string=this.AddArgs(g,this.string.slice(this.i));this.i=0;if(++this.macroCount>b.config.MAXMACROS){b.Error("MathJax maximum macro substitution count exceeded; is there a recursive macro call?")}},BeginEnv:function(f,h,c,g){if(g){var d=[];for(var e=0;e<g;e++){d.push(this.GetArgument("\\begin{"+name+"}"))}h=this.SubstituteArgs(d,h);c=this.SubstituteArgs(d,c)}f.edef=c;this.string=this.AddArgs(h,this.string.slice(this.i));this.i=0;return f},EndEnv:function(c,d){this.string=this.AddArgs(c.edef,this.string.slice(this.i));this.i=0;return d},GetParameter:function(d,g){if(g==null){return this.GetArgument(d)}var f=this.i,c=0,e=0;while(this.i<this.string.length){if(this.string.charAt(this.i)==="{"){if(this.i===f){e=1}this.GetArgument(d);c=this.i-f}else{if(this.MatchParam(g)){if(e){f++;c-=2}return this.string.substr(f,c)}else{this.i++;c++;e=0}}}b.Error("Runaway argument for "+d+"?")},MatchParam:function(c){if(this.string.substr(this.i,c.length)!==c){return 0}this.i+=c.length;return 1}});b.Environment=function(c){a.environment[c]=["BeginEnv","EndEnv"].concat([].slice.call(arguments,1));a.environment[c].isUser=true};MathJax.Hub.Startup.signal.Post("TeX newcommand Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/newcommand.js");
MathJax.Extension["TeX/newcommand"]={version:"1.1.2"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var b=MathJax.InputJax.TeX;var a=b.Definitions;a.Add({macros:{newcommand:"NewCommand",renewcommand:"NewCommand",newenvironment:"NewEnvironment",renewenvironment:"NewEnvironment",def:"MacroDef",let:"Let"}},null,true);b.Parse.Augment({NewCommand:function(c){var e=this.trimSpaces(this.GetArgument(c)),g=this.GetBrackets(c),d=this.GetBrackets(c),f=this.GetArgument(c);if(e.charAt(0)==="\\"){e=e.substr(1)}if(!e.match(/^(.|[a-z]+)$/i)){b.Error("Illegal control sequence name for "+c)}if(g){g=this.trimSpaces(g);if(!g.match(/^[0-9]+$/)){b.Error("Illegal number of parameters specified in "+c)}}this.setDef(e,["Macro",f,g,d])},NewEnvironment:function(d){var e=this.trimSpaces(this.GetArgument(d)),g=this.GetBrackets(d),f=this.GetArgument(d),c=this.GetArgument(d);if(g){g=this.trimSpaces(g);if(!g.match(/^[0-9]+$/)){b.Error("Illegal number of parameters specified in "+d)}}this.setEnv(e,["BeginEnv","EndEnv",f,c,g])},MacroDef:function(c){var d=this.GetCSname(c),f=this.GetTemplate(c,"\\"+d),e=this.GetArgument(c);if(!(f instanceof Array)){this.setDef(d,["Macro",e,f])}else{this.setDef(d,["MacroWithTemplate",e].concat(f))}},Let:function(d){var e=this.GetCSname(d),f;var g=this.GetNext();if(g==="="){this.i++;g=this.GetNext()}if(g==="\\"){d=this.GetCSname(d);f=this.csFindMacro(d);if(!f){if(a.mathchar0mi[d]){f=["csMathchar0mi",a.mathchar0mi[d]]}else{if(a.mathchar0mo[d]){f=["csMathchar0mo",a.mathchar0mo[d]]}else{if(a.mathchar7[d]){f=["csMathchar7",a.mathchar7[d]]}else{if(a.delimiter["\\"+d]!=null){f=["csDelimiter",a.delimiter["\\"+d]]}}}}}}else{f=["Macro",g];this.i++}this.setDef(e,f)},setDef:function(c,d){d.isUser=true;a.macros[c]=d},setEnv:function(c,d){d.isUser=true;a.environment[c]=d},GetCSname:function(e){var f=this.GetNext();if(f!=="\\"){b.Error("\\ must be followed by a control sequence")}var d=this.trimSpaces(this.GetArgument(e));return d.substr(1)},GetTemplate:function(f,e){var j,g=[],h=0;j=this.GetNext();var d=this.i;while(this.i<this.string.length){j=this.GetNext();if(j==="#"){if(d!==this.i){g[h]=this.string.substr(d,this.i-d)}j=this.string.charAt(++this.i);if(!j.match(/^[1-9]$/)){b.Error("Illegal use of # in template for "+e)}if(parseInt(j)!=++h){b.Error("Parameters for "+e+" must be numbered sequentially")}d=this.i+1}else{if(j==="{"){if(d!==this.i){g[h]=this.string.substr(d,this.i-d)}if(g.length>0){return[h,g]}else{return h}}}this.i++}b.Error("Missing replacement string for definition of "+f)},MacroWithTemplate:function(d,g,h,f){if(h){var c=[];this.GetNext();if(f[0]&&!this.MatchParam(f[0])){b.Error("Use of "+d+" doesn't match its definition")}for(var e=0;e<h;e++){c.push(this.GetParameter(d,f[e+1]))}g=this.SubstituteArgs(c,g)}this.string=this.AddArgs(g,this.string.slice(this.i));this.i=0;if(++this.macroCount>b.config.MAXMACROS){b.Error("MathJax maximum macro substitution count exceeded; is there a recursive macro call?")}},BeginEnv:function(f,h,c,g){if(g){var d=[];for(var e=0;e<g;e++){d.push(this.GetArgument("\\begin{"+name+"}"))}h=this.SubstituteArgs(d,h);c=this.SubstituteArgs(d,c)}f.edef=c;this.string=this.AddArgs(h,this.string.slice(this.i));this.i=0;return f},EndEnv:function(c,d){this.string=this.AddArgs(c.edef,this.string.slice(this.i));this.i=0;return d},GetParameter:function(d,g){if(g==null){return this.GetArgument(d)}var f=this.i,c=0,e=0;while(this.i<this.string.length){if(this.string.charAt(this.i)==="{"){if(this.i===f){e=1}this.GetArgument(d);c=this.i-f}else{if(this.MatchParam(g)){if(e){f++;c-=2}return this.string.substr(f,c)}else{this.i++;c++;e=0}}}b.Error("Runaway argument for "+d+"?")},MatchParam:function(c){if(this.string.substr(this.i,c.length)!==c){return 0}this.i+=c.length;return 1}});b.Environment=function(c){a.environment[c]=["BeginEnv","EndEnv"].concat([].slice.call(arguments,1));a.environment[c].isUser=true};MathJax.Hub.Startup.signal.Post("TeX newcommand Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/newcommand.js");

File diff suppressed because one or more lines are too long

View File

@ -213,7 +213,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
* Handle \cfrac
*/
CFrac: function (name) {
var lr = this.trimSpaces(this.GetBrackets(name)),
var lr = this.trimSpaces(this.GetBrackets(name,"")),
num = this.GetArgument(name),
den = this.GetArgument(name);
var frac = MML.mfrac(TEX.Parse('\\strut\\textstyle{'+num+'}',this.stack.env).mml(),

View File

@ -55,7 +55,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
TEX.Parse.Augment({
BBox: function (name) {
var bbox = this.GetBrackets(name),
var bbox = this.GetBrackets(name,""),
math = this.ParseArg(name);
var parts = bbox.split(/,/), def, background, style;
for (var i in parts) {

View File

@ -79,7 +79,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
// \xcancel[attributes]{math}
//
Cancel: function(name,notation) {
var attr = this.GetBrackets(name), math = this.ParseArg(name);
var attr = this.GetBrackets(name,""), math = this.ParseArg(name);
var def = CANCEL.setAttributes({notation: notation},attr);
this.Push(MML.menclose(math).With(def));
},
@ -89,7 +89,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
//
CancelTo: function(name,notation) {
var value = this.ParseArg(name),
attr = this.GetBrackets(name),
attr = this.GetBrackets(name,""),
math = this.ParseArg(name);
var def = CANCEL.setAttributes({notation: MML.NOTATION.UPDIAGONALSTRIKE, arrow:true},attr);
value = MML.mpadded(value).With({depth:"-.1em",height:"+.1em",voffset:".1em"});

View File

@ -63,7 +63,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
attr = this.GetBrackets(name),
math = this.ParseArg(name);
var def = {notation: notation.replace(/,/g," ")};
if (attr !== "") {
if (attr) {
attr = attr.replace(/ /g,"").split(/,/);
for (var i = 0, m = attr.length; i < m; i++) {
var keyvalue = attr[i].split(/[:=]/);

View File

@ -49,25 +49,30 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
*/
NewCommand: function (name) {
var cs = this.trimSpaces(this.GetArgument(name)),
n = this.trimSpaces(this.GetBrackets(name)),
n = this.GetBrackets(name),
opt = this.GetBrackets(name),
def = this.GetArgument(name);
if (n === '') {n = null}
if (cs.charAt(0) === "\\") {cs = cs.substr(1)}
if (!cs.match(/^(.|[a-z]+)$/i)) {TEX.Error("Illegal control sequence name for "+name)}
if (n != null && !n.match(/^[0-9]+$/)) {TEX.Error("Illegal number of parameters specified in "+name)}
this.setDef(cs,['Macro',def,n]);
if (n) {
n = this.trimSpaces(n);
if (!n.match(/^[0-9]+$/)) {TEX.Error("Illegal number of parameters specified in "+name)}
}
this.setDef(cs,['Macro',def,n,opt]);
},
/*
* Implement \newenvironment{name}[n]{begincmd}{endcmd}
* Implement \newenvironment{name}[n][default]{begincmd}{endcmd}
*/
NewEnvironment: function (name) {
var env = this.trimSpaces(this.GetArgument(name)),
n = this.trimSpaces(this.GetBrackets(name)),
n = this.GetBrackets(name),
bdef = this.GetArgument(name),
edef = this.GetArgument(name);
if (n === '') {n = null}
if (n != null && !n.match(/^[0-9]+$/)) {TEX.Error("Illegal number of parameters specified in "+name)}
if (n) {
n = this.trimSpaces(n);
if (!n.match(/^[0-9]+$/)) {TEX.Error("Illegal number of parameters specified in "+name)}
}
this.setEnv(env,['BeginEnv','EndEnv',bdef,edef,n]);
},

View File

@ -1239,8 +1239,8 @@
var n = this.GetBrackets(name), arg = this.GetArgument(name);
if (arg === "\\frac") {arg += "{"+this.GetArgument(arg)+"}{"+this.GetArgument(arg)+"}"}
var mml = TEX.Parse(arg,this.stack.env).mml();
if (n == "") {mml = MML.msqrt.apply(MML,mml.array())}
else {mml = MML.mroot(mml,this.parseRoot(n))}
if (!n) {mml = MML.msqrt.apply(MML,mml.array())}
else {mml = MML.mroot(mml,this.parseRoot(n))}
this.Push(mml);
},
Root: function (name) {
@ -1315,15 +1315,16 @@
MmlToken: function (name) {
var type = this.GetArgument(name),
attr = this.GetBrackets(name).replace(/^\s+/,""),
attr = this.GetBrackets(name,"").replace(/^\s+/,""),
data = this.GetArgument(name),
def = {}, match;
def = {mmlAttributes:[]}, match;
if (!MML[type] || !MML[type].prototype.isToken) {TEX.Error(type+" is not a token element")}
while (attr !== "") {
match = attr.match(/^([a-z]+)\s*=\s*('[^']*'|"[^"]*"|[^ ]*)\s*/i);
if (!match) {TEX.Error("Invalid MathML attribute: "+attr)}
if (!MML[type].prototype.defaults[match[1]]) {TEX.Error(match[1]+" is not a recognized attribute for "+type)}
def[match[1]] = match[2].replace(/^(['"])(.*)\1$/,"$2");
def.mmlAttributes.push(match[1]);
attr = attr.substr(match[0].length);
}
this.Push(this.mmlToken(MML[type](data).With(def)));
@ -1344,7 +1345,7 @@
},
Smash: function (name) {
var bt = this.trimSpaces(this.GetBrackets(name));
var bt = this.trimSpaces(this.GetBrackets(name,""));
var smash = MML.mpadded(this.ParseArg(name));
switch (bt) {
case "b": smash.depth = 0; break;
@ -1437,10 +1438,14 @@
}
},
Macro: function (name,macro,argcount) {
Macro: function (name,macro,argcount,def) {
if (argcount) {
var args = [];
for (var i = 0; i < argcount; i++) {args.push(this.GetArgument(name))}
if (def != null) {
var optional = this.GetBrackets(name);
args.push(optional == null ? def : optional);
}
for (var i = args.length; i < argcount; i++) {args.push(this.GetArgument(name))}
macro = this.SubstituteArgs(args,macro);
}
this.string = this.AddArgs(macro,this.string.slice(this.i));
@ -1493,7 +1498,7 @@
},
CrLaTeX: function (name) {
var n = this.GetBrackets(name).replace(/ /g,"");
var n = this.GetBrackets(name,"").replace(/ /g,"");
if (n && !n.match(/^(((\.\d+|\d+(\.\d*)?))(pt|em|ex|mu|mm|cm|in|pc))$/))
{TEX.Error("Bracket argument to "+name+" must be a dimension")}
this.Push(STACKITEM.cell().With({isCR: TRUE, name: name, linebreak: TRUE}));
@ -1598,10 +1603,11 @@
return this.setArrayAlign(this.Array.apply(this,arguments),align);
},
setArrayAlign: function (array,align) {
align = this.trimSpaces(align||"");
if (align === "t") {array.arraydef.align = "baseline 1"}
else if (align === "b") {array.arraydef.align = "baseline -1"}
else if (align === "c") {array.arraydef.align = "center"}
else if (align !== "") {array.arraydef.align = align} // FIXME: should be an error?
else if (align) {array.arraydef.align = align} // FIXME: should be an error?
return array;
},
@ -1687,8 +1693,8 @@
/*
* Get an optional LaTeX argument in brackets
*/
GetBrackets: function (name) {
if (this.GetNext() != '[') {return ''};
GetBrackets: function (name,def) {
if (this.GetNext() != '[') {return def};
var j = ++this.i, parens = 0;
while (this.i < this.string.length) {
switch (this.string.charAt(this.i++)) {