!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(t){"use strict";t.defineMode("stex",function(t,e){function a(t,e){t.cmdState.push(e)}function c(t){return 0<t.cmdState.length?t.cmdState[t.cmdState.length-1]:null}function n(t,e,n){return function(){this.name=t,this.bracketNo=0,this.style=e,this.styles=n,this.argument=null,this.styleIdentifier=function(){return this.styles[this.bracketNo-1]||null},this.openBracket=function(){return this.bracketNo++,"bracket"},this.closeBracket=function(){}}}var o={};function u(t,e){t.f=e}function i(t,e){var n;if(t.match(/^\\[a-zA-Z@]+/)){var r=t.current().slice(1);return a(e,n=new(n=o[r]||o.DEFAULT)),u(e,m),n.style}if(t.match(/^\\[$&%#{}_]/))return"tag";if(t.match(/^\\[,;!\/\\]/))return"tag";if(t.match("\\["))return u(e,function(t,e){return f(t,e,"\\]")}),"keyword";if(t.match("\\("))return u(e,function(t,e){return f(t,e,"\\)")}),"keyword";if(t.match("$$"))return u(e,function(t,e){return f(t,e,"$$")}),"keyword";if(t.match("$"))return u(e,function(t,e){return f(t,e,"$")}),"keyword";var i=t.next();return"%"==i?(t.skipToEnd(),"comment"):"}"==i||"]"==i?(n=c(e))?(n.closeBracket(i),u(e,m),"bracket"):"error":"{"==i||"["==i?(a(e,n=new(n=o.DEFAULT)),"bracket"):/\d/.test(i)?(t.eatWhile(/[\w.%]/),"atom"):(t.eatWhile(/[\w\-_]/),"begin"==(n=function(t){for(var e=t.cmdState,n=e.length-1;0<=n;n--){var r=e[n];if("DEFAULT"!=r.name)return r}return{styleIdentifier:function(){return null}}}(e)).name&&(n.argument=t.current()),n.styleIdentifier())}function f(t,e,n){if(t.eatSpace())return null;if(n&&t.match(n))return u(e,i),"keyword";if(t.match(/^\\[a-zA-Z@]+/))return"tag";if(t.match(/^[a-zA-Z]+/))return"variable-2";if(t.match(/^\\[$&%#{}_]/))return"tag";if(t.match(/^\\[,;!\/]/))return"tag";if(t.match(/^[\^_&]/))return"tag";if(t.match(/^[+\-<>|=,\/@!*:;'"`~#?]/))return null;if(t.match(/^(\d+\.\d*|\d*\.\d+|\d+)/))return"number";var r=t.next();return"{"==r||"}"==r||"["==r||"]"==r||"("==r||")"==r?"bracket":"%"==r?(t.skipToEnd(),"comment"):"error"}function m(t,e){var n=t.peek();return"{"==n||"["==n?(c(e).openBracket(n),t.eat(n),u(e,i),"bracket"):/[ \t\r]/.test(n)?(t.eat(n),null):(u(e,i),function(t){var e=t.cmdState.pop();e&&e.closeBracket()}(e),i(t,e))}return o.importmodule=n("importmodule","tag",["string","builtin"]),o.documentclass=n("documentclass","tag",["","atom"]),o.usepackage=n("usepackage","tag",["atom"]),o.begin=n("begin","tag",["atom"]),o.end=n("end","tag",["atom"]),o.label=n("label","tag",["atom"]),o.ref=n("ref","tag",["atom"]),o.eqref=n("eqref","tag",["atom"]),o.cite=n("cite","tag",["atom"]),o.bibitem=n("bibitem","tag",["atom"]),o.Bibitem=n("Bibitem","tag",["atom"]),o.RBibitem=n("RBibitem","tag",["atom"]),o.DEFAULT=function(){this.name="DEFAULT",this.style="tag",this.styleIdentifier=this.openBracket=this.closeBracket=function(){}},{startState:function(){return{cmdState:[],f:e.inMathMode?function(t,e){return f(t,e)}:i}},copyState:function(t){return{cmdState:t.cmdState.slice(),f:t.f}},token:function(t,e){return e.f(t,e)},blankLine:function(t){t.f=i,t.cmdState.length=0},lineComment:"%"}}),t.defineMIME("text/x-stex","stex"),t.defineMIME("text/x-latex","stex")});