/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ /************************************************************* * * MathJax/extensions/TeX/mhchem.js * * Implements the \ce command for handling chemical formulas * from the mhchem LaTeX package. * * --------------------------------------------------------------------- * * Copyright (c) 2011-2013 The MathJax Consortium * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */MathJax.Extension["TeX/mhchem"]={version:"2.2"};MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var c=MathJax.InputJax.TeX,d=MathJax.Object.Subclass({string:"",i:0,tex:"",atom:!1,sup:"",sub:"",Init:function(a){this.string=a},ParseTable:{"-":"Minus","+":"Plus","(":"Open",")":"Close","[":"Open","]":"Close","\x3c":"Less","^":"Superscript",_:"Subscript","*":"Dot",".":"Dot","\x3d":"Equal","#":"Pound",$:"Math","\\":"Macro"," ":"Space"},Arrows:{"-\x3e":"rightarrow","\x3c-":"leftarrow","\x3c-\x3e":"leftrightarrow","\x3c\x3d\x3e":"rightleftharpoons","\x3c\x3d\x3e\x3e":"Rightleftharpoons","\x3c\x3c\x3d\x3e":"Leftrightharpoons","^":"uparrow",v:"downarrow"},Bonds:{"-":"-","\x3d":"\x3d","#":"\\equiv","~":"\\tripledash","~-":"\\begin{CEstack}{}\\tripledash\\\\-\\end{CEstack}","~\x3d":"\\raise2mu{\\begin{CEstack}{}\\tripledash\\\\-\\\\-\\end{CEstack}}","~--":"\\raise2mu{\\begin{CEstack}{}\\tripledash\\\\-\\\\-\\end{CEstack}}","-~-":"\\raise2mu{\\begin{CEstack}{}-\\\\\\tripledash\\\\-\\end{CEstack}}","...":"{\\cdot}{\\cdot}{\\cdot}","....":"{\\cdot}{\\cdot}{\\cdot}{\\cdot}","-\x3e":"\\rightarrow","\x3c-":"\\leftarrow","??":"\\text{??}"},Parse:function(){this.tex="";for(this.atom=!1;this.i?|<=>>?|<<=>)/);b?this.AddArrow(b):(this.tex+=a,this.i++)},ParseSuperscript:function(a){a=this.string.charAt(++this.i);if("{"===a)this.i++,a=this.Find("}"),"-."===a?this.sup+="{-}{\\cdot}":a&&(this.sup+=d(a).Parse().replace(/^\{-\}/,"-"));else if(" "===a||""===a)this.tex+="{\\"+this.Arrows["^"]+"}",this.i++;else if(a=this.Match(/^(\d+|-\.)/))this.sup+=a},ParseSubscript:function(a){if("{"==this.string.charAt(++this.i))this.i++,this.sub+=d(this.Find("}")).Parse().replace(/^\{-\}/,"-");else if(a=this.Match(/^\d+/))this.sub+=a},ParseMath:function(a){this.FinishAtom();this.i++;this.tex+=this.Find(a)},ParseMacro:function(a){this.FinishAtom();this.i++;var b=this.Match(/^([a-z]+|.)/i)||" ";"sbond"===b?this.tex+="{-}":"dbond"===b?this.tex+="{\x3d}":"tbond"===b?this.tex+="{\\equiv}":"bond"===b?(a=this.Match(/^\{.*?\}/)||"",a=a.substr(1,a.length-2),this.tex+="{"+(this.Bonds[a]||"\\text{??}")+"}"):"{"===b?this.tex+="{\\{":"}"===b?(this.tex+="\\}}",this.atom=!0):this.tex+=a+b},ParseSpace:function(a){this.FinishAtom();this.i++},ParseOther:function(a){this.FinishAtom();this.tex+=a;this.i++},AddArrow:function(a){var b=this.Match(/^[CT]\[/);b&&(this.i--,b=b.charAt(0));var c=this.GetBracket(b),b=this.GetBracket(b);a=this.Arrows[a];c||b?(b&&(a+="["+b+"]"),a="\\mathrel{\\x"+(a+("{"+c+"}"))+"}"):a="\\long"+a+" ";this.tex+=a},FinishAtom:function(){if(this.sup||this.sub){if(this.sup&&this.sub&&!this.atom){var a=this.sup,b=this.sub;a.match(/\d/)||(a+="\\vphantom{0}");b.match(/\d/)||(b+="\\vphantom{0}");this.tex+="\\raise 1pt{\\scriptstyle\\begin{CEscriptstack}"+a+"\\\\"+b+"\\end{CEscriptstack}}\\kern-.125em "}else this.sup||(this.sup="\\Space{0pt}{0pt}{.2em}"),this.tex+="^{"+this.sup+"}_{"+this.sub+"}";this.sup=this.sub=""}this.atom=!1},GetBracket:function(a){if("["!==this.string.charAt(this.i))return"";this.i++;var b=this.Find("]");"C"===a?b="\\ce{"+b+"}":"T"===a&&(b.match(/^\{.*\}$/)||(b="{"+b+"}"),b="\\text"+b);return b},Match:function(a){if(a=a.exec(this.string.substr(this.i)))a=a[0],this.i+=a.length;return a},Find:function(a){for(var b=this.string.length,d=this.i,e=0;this.i