instiki/public/MathJax/jax/input/TeX/jax.js

17 lines
38 KiB
JavaScript
Raw Normal View History

/*
2011-01-28 02:12:00 +01:00
* /MathJax/jax/input/TeX/jax.js
*
* Copyright (c) 2010 Design Science, Inc.
*
* Part of the MathJax library.
* See http://www.mathjax.org for details.
*
* Licensed under the Apache License, Version 2.0;
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
2011-01-28 02:12:00 +01:00
(function(d){var c=true,f=false,i,h=String.fromCharCode(160);var e=MathJax.Object.Subclass({Init:function(k){this.global={};this.data=[b.start().With({global:this.global})];if(k){this.data[0].env=k}this.env=this.data[0].env},Push:function(){var l,k,n,o;for(l=0,k=arguments.length;l<k;l++){n=arguments[l];if(n instanceof i.mbase){n=b.mml(n)}n.global=this.global;o=(this.data.length?this.Top().checkItem(n):c);if(o instanceof Array){this.Pop();this.Push.apply(this,o)}else{if(o instanceof b){this.Pop();this.Push(o)}else{if(o){this.data.push(n);if(n.env){for(var p in this.env){if(this.env.hasOwnProperty(p)){n.env[p]=this.env[p]}}this.env=n.env}else{n.env=this.env}}}}}},Pop:function(){var k=this.data.pop();if(!k.isOpen){delete k.env}this.env=(this.data.length?this.Top().env:{});return k},Top:function(k){if(k==null){k=1}if(this.data.length<k){return null}return this.data[this.data.length-k]},Prev:function(k){var l=this.Top();if(k){return l.data[l.data.length-1]}else{return l.Pop()}},toString:function(){return"stack[\n "+this.data.join("\n ")+"\n]"}});var b=e.Item=MathJax.Object.Subclass({type:"base",closeError:"Extra close brace or missing open brace",rightError:"Missing \\left or extra \\right",Init:function(){if(this.isOpen){this.env={}}this.data=[];this.Push.apply(this,arguments)},Push:function(){this.data.push.apply(this.data,arguments)},Pop:function(){return this.data.pop()},mmlData:function(k,l){if(k==null){k=c}if(this.data.length===1&&!l){return this.data[0]}return i.mrow.apply(i,this.data).With((k?{inferred:c}:{}))},checkItem:function(k){if(k.type==="over"&&this.isOpen){k.num=this.mmlData(f);this.data=[]}if(k.type==="cell"&&this.isOpen){d.Error("Misplaced "+k.name)}if(k.isClose&&this[k.type+"Error"]){d.Error(this[k.type+"Error"])}if(!k.isNotStack){return c}this.Push(k.data[0]);return f},With:function(k){for(var l in k){if(k.hasOwnProperty(l)){this[l]=k[l]}}return this},toString:function(){return this.type+"["+this.data.join("; ")+"]"}});b.start=b.Subclass({type:"start",isOpen:c,checkItem:function(k){if(k.type==="stop"){return b.mml(this.mmlData())}return this.SUPER(arguments).checkItem.call(this,k)}});b.stop=b.Subclass({type:"stop",isClose:c});b.open=b.Subclass({type:"open",isOpen:c,stopError:"Extra open brace or missing close brace",checkItem:function(l){if(l.type==="close"){var k=this.mmlData();return b.mml(i.TeXAtom(k))}return this.SUPER(arguments).checkItem.call(this,l)}});b.close=b.Subclass({type:"close",isClose:c});b.subsup=b.Subclass({type:"subsup",stopError:"Missing superscript or subscript argument",checkItem:function(l){var k=["","subscript","superscript"][this.position];if(l.type==="open"||l.type==="left"){return c}if(l.type==="mml"){this.data[0].SetData(this.position,l.data[0]);return b.mml(this.data[0])}if(this.SUPER(arguments).checkItem.call(this,l)){d.Error("Missing open brace for "+k)}},Pop:function(){}});b.over=b.Subclass({type:"over",isClose:c,name:"\\over",checkItem:function(m,k){if(m.type==="over"){d.Error("Ambiguous use of "+m.name)}if(m.isClose){var l=i.mfrac(this.num,this.mmlData(f));if(this.thickness!=null){l.linethickness=this.thickness}if(this.open||this.close){l.texClass=i.TEXCLASS.INNER;l.texWithDelims=c;l=i.mfenced(l).With({open:this.open,close:this.close})}return[b.mml(l),m]}return this.SUPER(arguments).checkItem.call(this,m)},toString:function(){return"over["+this.num+" / "+this.data.join("; ")+"]"}});b.left=b.Subclass({type:"left",isOpen:c,delim:"(",stopError:"Extra \\left or missing \\right",checkItem:function(l){if(l.type==="right"){var k=i.mfenced(this.data.length===1?this.data[0]:i.mrow.apply(i,this.data));return b.mml(k.With({open:this.delim,close:l.delim}))}return this.SUPER(arguments).checkItem.call(this,l)}});b.right=b.Subclass({type:"right",isClose:c,delim:")"});b.begin=b.Subclass({type:"begin",isOpen:c,checkItem:function(k){if(k.type==="end"){if(k.name!==this.name){d.Error("\\begin{"+this.name+"} ended with \\end{"+k.name+"}")}if(!this.end){return b.mml(this.mmlData())}return this.parse[this.end].call(this.parse,this,this.data)}if(k.type==="stop"){d.Error("Missing \\end{"+this.n