ASCIIMathML.js 228 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892
  1. /*
  2. ASCIIMathML2wMnGFallback.js
  3. ==============
  4. ver 0.1 - RegEx errors in Opera need to be fixed (apparently OK in 9.5)
  5. This version of ASCIIMathML has been modified with TeX conversion for
  6. IMG fallback June 11, 2008 (c) David Lippman http://www.pierce.ctc.edu/dlippman
  7. This this version, if browser supports MathML, it is used. Otherwise, image-
  8. based math rendering is used (set AMTcgiloc for renderer). Also provides
  9. IMG fallback for editor-produced graphs (does not attempt img fallback for
  10. other graphs)
  11. This file contains JavaScript functions to convert ASCII math notation
  12. and LaTeX to Presentation MathML. Simple graphics commands are also
  13. translated to SVG images. The conversion is done while the (X)HTML
  14. page loads, and should work with Firefox/Mozilla/Netscape 7+ and Internet
  15. Explorer 6/7 + MathPlayer (http://www.dessci.com/en/products/mathplayer/) +
  16. Adobe SVGview 3.03 (http://www.adobe.com/svg/viewer/install/).
  17. Just add the next line to your (X)HTML page with this file in the same folder:
  18. <script type="text/javascript" src="ASCIIMathML.js"></script>
  19. (using the graphics in IE also requires the file "d.svg" in the same folder).
  20. This is a convenient and inexpensive solution for authoring MathML and SVG.
  21. Version 2.1 Oct 8, 2008, (c) Peter Jipsen http://www.chapman.edu/~jipsen
  22. This version extends ASCIIMathML.js with LaTeXMathML.js and ASCIIsvg.js.
  23. Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
  24. If you use it on a webpage, please send the URL to jipsen@chapman.edu
  25. The LaTeXMathML modifications were made by Douglas Woodall, June 2006.
  26. (for details see header on the LaTeXMathML part in middle of file)
  27. Extensive clean-up and improvements by Paulo Soares, Oct 2007.
  28. Some modifications from AM.js, version 2.X.X.4 November 2009
  29. by Mauno Korpelainen (http://korpelainen.net) have been transfered here.
  30. This script has been "assembled" for Chamilo 1.8.7.1 LMS
  31. by Ivan Tcholakov, July 2010, using some information from
  32. http://groups.google.com/group/asciimath
  33. This program is free software; you can redistribute it and/or modify
  34. it under the terms of the GNU Lesser General Public License as published by
  35. the Free Software Foundation; either version 2.1 of the License, or (at
  36. your option) any later version.
  37. This program is distributed in the hope that it will be useful, but WITHOUT
  38. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  39. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  40. (at http://www.gnu.org/licences/lgpl.html) for more details.
  41. */
  42. // Modified by Ivan Tcholakov, 02-JUL-2010.
  43. //var AMTcgiloc = "http://www.imathas.com/cgi-bin/mimetex.cgi"; //path to CGI script that
  44. // //can render a TeX string
  45. //
  46. // You should pick up and install on your server software for TeX rendering, such as:
  47. //
  48. // mimeTeX - http://www.forkosh.dreamhost.com/source_mimetex.html
  49. // mathTeX - http://www.forkosh.com/mathtex.html
  50. //
  51. // or you may try to use some public services as:
  52. //
  53. // MathTran - http://www.mathtran.org/
  54. // Google Chart Tools - http://code.google.com/apis/charttools/
  55. //
  56. // You have to set here the path to the script for TeX rendering
  57. // and specific query parameters, if any.
  58. //
  59. // Some examples for testing purposes:
  60. //
  61. //var AMTcgiloc = "http://www.imathas.com/cgi-bin/mimetex.cgi";
  62. //var AMTcgiloc = "http://schmoodle.alaskapolicy.net/cgi-bin/mimetex.cgi";
  63. //
  64. //var AMTcgiloc = "http://korpelainen.net/cgi-bin/mathtex.cgi";
  65. //
  66. //var AMTcgiloc = "http://www.mathtran.org/cgi-bin/mathtran?tex=";
  67. //var AMTcgiloc = "http://www.mathtran.org/cgi-bin/mathtran?D=1;tex=";
  68. //var AMTcgiloc = "http://www.mathtran.org/cgi-bin/mathtran?D=2;tex=";
  69. //
  70. //var AMTcgiloc = "http://chart.googleapis.com/chart?cht=tx&chl=";
  71. //var AMTcgiloc = "http://chart.googleapis.com/chart?cht=tx&chs=1x0&chl=";
  72. //
  73. //var AMTcgiloc = "http://codecogs.izyba.com/gif.latex";
  74. //var AMTcgiloc = "http://codecogs.izyba.com/png.latex";
  75. //
  76. var AMTcgiloc = "//chart.googleapis.com/chart?cht=tx&chs=1x0&chl=";
  77. var AScgiloc = '//www.imathas.com/imathas/filter/graph/svgimg.php'; //path to CGI script
  78. //for editor graphs IMG fallback
  79. var mathcolor = "blue"; // change it to "" (to inherit) or another color
  80. // Modified by Ivan Tcholakov, 01-JUL-2010.
  81. //var mathfontsize = "1em"; // change to e.g. 1.2em for larger math
  82. var mathfontsize = "1.2em";
  83. //
  84. // Modified by Ivan Tcholakov, 05-JUL-2010.
  85. //var mathfontfamily = "serif"; // change to "" to inherit (works in IE)
  86. // // or another family (e.g. "arial")
  87. var mathfontfamily = 'STIXGeneral,Arial Unicode MS,Lucida Sans Unicode,Lucida Grande,Garuda,sans-serif,serif';
  88. //
  89. var automathrecognize = false; // writing "amath" on page makes this true
  90. var checkForMathML = true; // check if browser can display MathML
  91. var notifyIfNoMathML = false; // display note at top if no MathML capability
  92. var alertIfNoMathML = false; // show alert box if no MathML capability
  93. var translateOnLoad = true; // set to false to do call translators from js
  94. // Originally modified by Ivan Tcholakov, 19-OCT-2010.
  95. //var translateLaTeX = true;
  96. // See #6355
  97. var translateLaTeX = false; // false to preserve $..$, $$..$$
  98. var translateLaTeXformatting = true; // false to preserve \emph,\begin{},\end{}
  99. var translateASCIIMath = true; // false to preserve `..`
  100. var translateASCIIsvg = true; // false to preserve agraph.., \begin{graph}..
  101. var avoidinnerHTML = false; // set true if assigning to innerHTML gives error
  102. var displaystyle = true; // puts limits above and below large operators
  103. var showasciiformulaonhover = true; // helps students learn ASCIIMath
  104. var decimalsign = "."; // change to "," if you like, beware of `(1,2)`!
  105. var AMdelimiter1 = "`", AMescape1 = "\\\\`"; // can use other characters
  106. var AMdocumentId = "wikitext" // PmWiki element containing math (default=body)
  107. var checkforprocessasciimathinmoodle = false; // true for systems like Moodle
  108. var dsvglocation = ""; // path to d.svg (blank if same as ASCIIMathML.js loc)
  109. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  110. // Modified by Ivan Tcholakov, 06-JUL-2010.
  111. //var isIE = document.createElementNS==null;
  112. var isIE = (/msie/).test(navigator.userAgent.toLowerCase());
  113. //
  114. var noMathML = false;
  115. var translated = false;
  116. // Returns true if MathPlayer add-on has been installed and enabled.
  117. function checkMathPlayer() {
  118. if (isIE && window.ActiveXObject) {
  119. try {
  120. var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
  121. return true;
  122. } catch(e) { };
  123. }
  124. return false;
  125. }
  126. var isMathPlayerAvailable = checkMathPlayer();
  127. if (isMathPlayerAvailable) { // Avoid adding MathPlayer info explicitly to each webpage.
  128. document.write("<object id=\"mathplayer\"\
  129. classid=\"clsid:32F66A20-7614-11D4-BD11-00104BD3F987\"></object>");
  130. document.write("<?import namespace=\"m\" implementation=\"#mathplayer\"?>");
  131. }
  132. // Add a stylesheet, replacing any previous custom stylesheet (adapted from TW)
  133. function setStylesheet(s) {
  134. var id = "AMMLcustomStyleSheet";
  135. var n = document.getElementById(id);
  136. if(document.createStyleSheet) {
  137. // Test for IE's non-standard createStyleSheet method
  138. if(n)
  139. n.parentNode.removeChild(n);
  140. // This failed without the &nbsp;
  141. document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd","&nbsp;<style id='" + id + "'>" + s + "</style>");
  142. } else {
  143. if(n) {
  144. n.replaceChild(document.createTextNode(s),n.firstChild);
  145. } else {
  146. n = document.createElement("style");
  147. n.type = "text/css";
  148. n.id = id;
  149. n.appendChild(document.createTextNode(s));
  150. document.getElementsByTagName("head")[0].appendChild(n);
  151. }
  152. }
  153. }
  154. // Disabled by Ivan Tcholakov, 11-JUL-2010.
  155. // On Internet Explorer the inserted &nbsp; character breaks visual appearance of the online editor.
  156. //setStylesheet("#AMMLcloseDiv \{font-size:0.8em; padding-top:1em; color:#014\}\n#AMMLwarningBox \{position:absolute; width:100%; top:0; left:0; z-index:200; text-align:center; font-size:1em; font-weight:bold; padding:0.5em 0 0.5em 0; color:#ffc; background:#c30\}");
  157. //
  158. // Added by Ivan Tcholakov, 08-JUL-2010.
  159. // Prevention from multiple calls of the initialization function.
  160. var AMinitialized = false;
  161. //
  162. function init(){
  163. // Added by Ivan Tcholakov, 08-JUL-2010.
  164. if (AMinitialized) { return true; }
  165. //
  166. var msg, warnings = new Array();
  167. if (document.getElementById==null){
  168. alert("This webpage requires a recent browser such as Mozilla Firefox/Netscape 7+ or Internet Explorer 6+ with MathPlayer and Adobe SVGviewer");
  169. return null;
  170. }
  171. if (checkForMathML && (msg = checkMathML())) warnings.push(msg);
  172. if (checkIfSVGavailable && (msg = checkSVG())) warnings.push(msg);
  173. if (warnings.length>0) displayWarnings(warnings);
  174. initSymbols();
  175. // Added by Ivan Tcholakov, 08-JUL-2010.
  176. AMinitialized = true;
  177. //
  178. return true;
  179. }
  180. function checkMathML(){
  181. if (navigator.product && navigator.product=='Gecko') {
  182. var rv = navigator.userAgent.toLowerCase().match(/rv:\s*([\d\.]+)/);
  183. if (rv!=null) {
  184. rv = rv[1].split('.');
  185. if (rv.length<3) { rv[2] = 0;}
  186. if (rv.length<2) { rv[1] = 0;}
  187. }
  188. if (rv!=null && 10000*rv[0]+100*rv[1]+1*rv[2]>=10100) {
  189. noMathML = null;
  190. } else {
  191. noMathML = true;
  192. }
  193. }
  194. else if (isIE) {
  195. noMathML = isMathPlayerAvailable ? null : true;
  196. }
  197. else if (navigator.appName.slice(0,5)=="Opera") {
  198. noMathML = (navigator.appVersion.slice(0,3)>="9.5") ? null : true;
  199. }
  200. else noMathML = true;
  201. //noMathML = true; //uncomment to check
  202. if (noMathML && notifyIfNoMathML) {
  203. var msg = "To view the ASCIIMathML notation use Internet Explorer + MathPlayer or Mozilla Firefox 2.0 or later.";
  204. if (alertIfNoMathML)
  205. alert(msg);
  206. else return msg;
  207. }
  208. }
  209. function hideWarning(){
  210. var body = document.getElementsByTagName("body")[0];
  211. body.removeChild(document.getElementById('AMMLwarningBox'));
  212. body.onclick = null;
  213. }
  214. function displayWarnings(warnings) {
  215. var i, frag, nd = createElementXHTML("div");
  216. var body = document.getElementsByTagName("body")[0];
  217. body.onclick=hideWarning;
  218. nd.id = 'AMMLwarningBox';
  219. for (i=0; i<warnings.length; i++) {
  220. frag = createElementXHTML("div");
  221. frag.appendChild(document.createTextNode(warnings[i]));
  222. frag.style.paddingBottom = "1.0em";
  223. nd.appendChild(frag);
  224. }
  225. nd.appendChild(createElementXHTML("p"));
  226. nd.appendChild(document.createTextNode("For instructions see the "));
  227. var an = createElementXHTML("a");
  228. an.appendChild(document.createTextNode("ASCIIMathML"));
  229. an.setAttribute("href","http://www.chapman.edu/~jipsen/asciimath.html");
  230. nd.appendChild(an);
  231. nd.appendChild(document.createTextNode(" homepage"));
  232. an = createElementXHTML("div");
  233. an.id = 'AMMLcloseDiv';
  234. an.appendChild(document.createTextNode('(click anywhere to close this warning)'));
  235. nd.appendChild(an);
  236. var body = document.getElementsByTagName("body")[0];
  237. body.insertBefore(nd,body.childNodes[0]);
  238. }
  239. function translate(spanclassAM) {
  240. if (!translated) { // run this only once
  241. translated = true;
  242. var body = document.getElementsByTagName("body")[0];
  243. var processN = document.getElementById(AMdocumentId);
  244. if (translateLaTeX) LMprocessNode((processN!=null?processN:body));
  245. if (translateASCIIMath) AMprocessNode((processN!=null?processN:body), false, spanclassAM);
  246. }
  247. }
  248. function createElementXHTML(t) {
  249. if (isIE) return document.createElement(t);
  250. else return document.createElementNS("http://www.w3.org/1999/xhtml",t);
  251. }
  252. function createMmlNode(t,frag) {
  253. if (isIE) var node = document.createElement("m:"+t);
  254. else var node = document.createElementNS("http://www.w3.org/1998/Math/MathML",t);
  255. if (frag) node.appendChild(frag);
  256. return node;
  257. }
  258. // character lists for Mozilla/Netscape fonts
  259. var AMcal = [
  260. '\uD835\uDC9C', '\u212C', '\uD835\uDC9E', //abc
  261. '\uD835\uDC9F', '\u2130', '\u2131', //def
  262. '\uD835\uDCA2', '\u210B', '\u2110', //ghi
  263. '\uD835\uDCA5', '\uD835\uDCA6', '\u2112', //jkl
  264. '\u2133', '\uD835\uDCA9', '\uD835\uDCAA', //mno
  265. '\uD835\uDCAB', '\uD835\uDCAC', '\u211B', //pqr
  266. '\uD835\uDCAE', '\uD835\uDCAF', '\uD835\uDCB0', //stu
  267. '\uD835\uDCB1', '\uD835\uDCB2', '\uD835\uDCB3', //vwx
  268. '\uD835\uDCB4', '\uD835\uDCB5' ]; //yz
  269. var AMfrk = [
  270. '\uD835\uDD04', '\uD835\uDD05', '\u212D', //abc
  271. '\uD835\uDD07', '\uD835\uDD08', '\uD835\uDD09', //def
  272. '\uD835\uDD0A', '\u210C', '\u2111', //ghi
  273. '\uD835\uDD0D', '\uD835\uDD0E', '\uD835\uDD0F', //jkl
  274. '\uD835\uDD10', '\uD835\uDD11', '\uD835\uDD12', //mno
  275. '\uD835\uDD13', '\uD835\uDD14', '\u211C', //pqr
  276. '\uD835\uDD16', '\uD835\uDD17', '\uD835\uDD18', //stu
  277. '\uD835\uDD19', '\uD835\uDD1A', '\uD835\uDD1B', //vwx
  278. '\uD835\uDD1C', '\u2128' ]; //yz
  279. var AMbbb = [
  280. '\uD835\uDD38', '\uD835\uDD39', '\u2102', //abc
  281. '\uD835\uDD3B', '\uD835\uDD3C', '\uD835\uDD3D', //def
  282. '\uD835\uDD3E', '\u210D', '\uD835\uDD40', //ghi
  283. '\uD835\uDD41', '\uD835\uDD42', '\uD835\uDD43', //jkl
  284. '\uD835\uDD44', '\u2115', '\uD835\uDD46', //mno
  285. '\u2119', '\u211A', '\u211D', //pqr
  286. '\uD835\uDD4A', '\uD835\uDD4B', '\uD835\uDD4C', //stu
  287. '\uD835\uDD4D', '\uD835\uDD4E', '\uD835\uDD4F', //vwx
  288. '\uD835\uDD50', '\u2124', ];
  289. var CONST = 0, UNARY = 1, BINARY = 2, INFIX = 3, LEFTBRACKET = 4,
  290. RIGHTBRACKET = 5, SPACE = 6, UNDEROVER = 7, DEFINITION = 8,
  291. LEFTRIGHT = 9, TEXT = 10, BIG = 11, LONG = 12, STRETCHY = 13,
  292. MATRIX = 14; // token types
  293. var AMquote = {input:"\"", tag:"mtext", output:"mbox", tex:null, ttype:TEXT};
  294. var AMsymbols = [
  295. //some greek symbols
  296. {input:"alpha", tag:"mi", output:"\u03B1", tex:null, ttype:CONST},
  297. {input:"beta", tag:"mi", output:"\u03B2", tex:null, ttype:CONST},
  298. {input:"chi", tag:"mi", output:"\u03C7", tex:null, ttype:CONST},
  299. {input:"delta", tag:"mi", output:"\u03B4", tex:null, ttype:CONST},
  300. {input:"Delta", tag:"mo", output:"\u0394", tex:null, ttype:CONST},
  301. {input:"epsi", tag:"mi", output:"\u03B5", tex:"epsilon", ttype:CONST},
  302. {input:"varepsilon", tag:"mi", output:"\u025B", tex:null, ttype:CONST},
  303. {input:"eta", tag:"mi", output:"\u03B7", tex:null, ttype:CONST},
  304. {input:"gamma", tag:"mi", output:"\u03B3", tex:null, ttype:CONST},
  305. {input:"Gamma", tag:"mo", output:"\u0393", tex:null, ttype:CONST},
  306. {input:"iota", tag:"mi", output:"\u03B9", tex:null, ttype:CONST},
  307. {input:"kappa", tag:"mi", output:"\u03BA", tex:null, ttype:CONST},
  308. {input:"lambda", tag:"mi", output:"\u03BB", tex:null, ttype:CONST},
  309. {input:"Lambda", tag:"mo", output:"\u039B", tex:null, ttype:CONST},
  310. {input:"mu", tag:"mi", output:"\u03BC", tex:null, ttype:CONST},
  311. {input:"nu", tag:"mi", output:"\u03BD", tex:null, ttype:CONST},
  312. {input:"omega", tag:"mi", output:"\u03C9", tex:null, ttype:CONST},
  313. {input:"Omega", tag:"mo", output:"\u03A9", tex:null, ttype:CONST},
  314. {input:"phi", tag:"mi", output:"\u03C6", tex:null, ttype:CONST},
  315. {input:"varphi", tag:"mi", output:"\u03D5", tex:null, ttype:CONST},
  316. {input:"Phi", tag:"mo", output:"\u03A6", tex:null, ttype:CONST},
  317. {input:"pi", tag:"mi", output:"\u03C0", tex:null, ttype:CONST},
  318. {input:"Pi", tag:"mo", output:"\u03A0", tex:null, ttype:CONST},
  319. {input:"psi", tag:"mi", output:"\u03C8", tex:null, ttype:CONST},
  320. {input:"Psi", tag:"mi", output:"\u03A8", tex:null, ttype:CONST},
  321. {input:"rho", tag:"mi", output:"\u03C1", tex:null, ttype:CONST},
  322. {input:"sigma", tag:"mi", output:"\u03C3", tex:null, ttype:CONST},
  323. {input:"Sigma", tag:"mo", output:"\u03A3", tex:null, ttype:CONST},
  324. {input:"tau", tag:"mi", output:"\u03C4", tex:null, ttype:CONST},
  325. {input:"theta", tag:"mi", output:"\u03B8", tex:null, ttype:CONST},
  326. {input:"vartheta", tag:"mi", output:"\u03D1", tex:null, ttype:CONST},
  327. {input:"Theta", tag:"mo", output:"\u0398", tex:null, ttype:CONST},
  328. {input:"upsilon", tag:"mi", output:"\u03C5", tex:null, ttype:CONST},
  329. {input:"xi", tag:"mi", output:"\u03BE", tex:null, ttype:CONST},
  330. {input:"Xi", tag:"mo", output:"\u039E", tex:null, ttype:CONST},
  331. {input:"zeta", tag:"mi", output:"\u03B6", tex:null, ttype:CONST},
  332. //binary operation symbols
  333. //{input:"-", tag:"mo", output:"\u0096", tex:null, ttype:CONST},
  334. {input:"*", tag:"mo", output:"\u22C5", tex:"cdot", ttype:CONST},
  335. {input:"**", tag:"mo", output:"\u22C6", tex:"star", ttype:CONST},
  336. {input:"//", tag:"mo", output:"/", tex:null, ttype:CONST},
  337. {input:"\\\\", tag:"mo", output:"\\", tex:"backslash", ttype:CONST},
  338. {input:"setminus", tag:"mo", output:"\\", tex:null, ttype:CONST},
  339. {input:"xx", tag:"mo", output:"\u00D7", tex:"times", ttype:CONST},
  340. {input:"-:", tag:"mo", output:"\u00F7", tex:"divide", ttype:CONST},
  341. {input:"@", tag:"mo", output:"\u26AC", tex:"circ", ttype:CONST},
  342. {input:"o+", tag:"mo", output:"\u2295", tex:"oplus", ttype:CONST},
  343. {input:"ox", tag:"mo", output:"\u2297", tex:"otimes", ttype:CONST},
  344. {input:"o.", tag:"mo", output:"\u2299", tex:"odot", ttype:CONST},
  345. {input:"sum", tag:"mo", output:"\u2211", tex:null, ttype:UNDEROVER},
  346. {input:"prod", tag:"mo", output:"\u220F", tex:null, ttype:UNDEROVER},
  347. {input:"^^", tag:"mo", output:"\u2227", tex:"wedge", ttype:CONST},
  348. {input:"^^^", tag:"mo", output:"\u22C0", tex:"bigwedge", ttype:UNDEROVER},
  349. {input:"vv", tag:"mo", output:"\u2228", tex:"vee", ttype:CONST},
  350. {input:"vvv", tag:"mo", output:"\u22C1", tex:"bigvee", ttype:UNDEROVER},
  351. {input:"nn", tag:"mo", output:"\u2229", tex:"cap", ttype:CONST},
  352. {input:"nnn", tag:"mo", output:"\u22C2", tex:"bigcap", ttype:UNDEROVER},
  353. {input:"uu", tag:"mo", output:"\u222A", tex:"cup", ttype:CONST},
  354. {input:"uuu", tag:"mo", output:"\u22C3", tex:"bigcup", ttype:UNDEROVER},
  355. //binary relation symbols
  356. {input:"!=", tag:"mo", output:"\u2260", tex:"ne", ttype:CONST},
  357. {input:":=", tag:"mo", output:":=", tex:"text{:=}", ttype:CONST},
  358. {input:"lt", tag:"mo", output:"<", tex:null, ttype:CONST},
  359. {input:"<=", tag:"mo", output:"\u2264", tex:"le", ttype:CONST},
  360. {input:"lt=", tag:"mo", output:"\u2264", tex:"leq", ttype:CONST},
  361. {input:">=", tag:"mo", output:"\u2265", tex:"ge", ttype:CONST},
  362. {input:"geq", tag:"mo", output:"\u2265", tex:null, ttype:CONST},
  363. {input:"-<", tag:"mo", output:"\u227A", tex:"prec", ttype:CONST},
  364. {input:"-lt", tag:"mo", output:"\u227A", tex:null, ttype:CONST},
  365. {input:">-", tag:"mo", output:"\u227B", tex:"succ", ttype:CONST},
  366. {input:"-<=", tag:"mo", output:"\u2AAF", tex:"preceq", ttype:CONST},
  367. {input:">-=", tag:"mo", output:"\u2AB0", tex:"succeq", ttype:CONST},
  368. {input:"in", tag:"mo", output:"\u2208", tex:null, ttype:CONST},
  369. {input:"!in", tag:"mo", output:"\u2209", tex:"notin", ttype:CONST},
  370. {input:"sub", tag:"mo", output:"\u2282", tex:"subset", ttype:CONST},
  371. {input:"sup", tag:"mo", output:"\u2283", tex:"supset", ttype:CONST},
  372. {input:"sube", tag:"mo", output:"\u2286", tex:"subseteq", ttype:CONST},
  373. {input:"supe", tag:"mo", output:"\u2287", tex:"supseteq", ttype:CONST},
  374. {input:"-=", tag:"mo", output:"\u2261", tex:"equiv", ttype:CONST},
  375. {input:"~=", tag:"mo", output:"\u2245", tex:"cong", ttype:CONST},
  376. {input:"~~", tag:"mo", output:"\u2248", tex:"approx", ttype:CONST},
  377. {input:"prop", tag:"mo", output:"\u221D", tex:"propto", ttype:CONST},
  378. //logical symbols
  379. {input:"and", tag:"mtext", output:"and", tex:null, ttype:SPACE},
  380. {input:"or", tag:"mtext", output:"or", tex:null, ttype:SPACE},
  381. {input:"not", tag:"mo", output:"\u00AC", tex:"neg", ttype:CONST},
  382. {input:"=>", tag:"mo", output:"\u21D2", tex:"Rightarrow", ttype:CONST},
  383. {input:"if", tag:"mo", output:"if", tex:null, ttype:SPACE},
  384. {input:"<=>", tag:"mo", output:"\u21D4", tex:"Leftrightarrow", ttype:CONST},
  385. {input:"AA", tag:"mo", output:"\u2200", tex:"forall", ttype:CONST},
  386. {input:"EE", tag:"mo", output:"\u2203", tex:"exists", ttype:CONST},
  387. {input:"_|_", tag:"mo", output:"\u22A5", tex:"bot", ttype:CONST},
  388. {input:"TT", tag:"mo", output:"\u22A4", tex:"top", ttype:CONST},
  389. {input:"|--", tag:"mo", output:"\u22A2", tex:"vdash", ttype:CONST},
  390. {input:"|==", tag:"mo", output:"\u22A8", tex:"models", ttype:CONST},
  391. //grouping brackets
  392. {input:"(", tag:"mo", output:"(", tex:null, ttype:LEFTBRACKET},
  393. {input:")", tag:"mo", output:")", tex:null, ttype:RIGHTBRACKET},
  394. {input:"[", tag:"mo", output:"[", tex:null, ttype:LEFTBRACKET},
  395. {input:"]", tag:"mo", output:"]", tex:null, ttype:RIGHTBRACKET},
  396. {input:"{", tag:"mo", output:"{", tex:"lbrace", ttype:LEFTBRACKET},
  397. {input:"}", tag:"mo", output:"}", tex:"rbrace", ttype:RIGHTBRACKET},
  398. {input:"|", tag:"mo", output:"|", tex:null, ttype:LEFTRIGHT},
  399. //{input:"||", tag:"mo", output:"||", tex:null, ttype:LEFTRIGHT},
  400. {input:"(:", tag:"mo", output:"\u2329", tex:"langle", ttype:LEFTBRACKET},
  401. {input:":)", tag:"mo", output:"\u232A", tex:"rangle", ttype:RIGHTBRACKET},
  402. {input:"<<", tag:"mo", output:"\u2329", tex:"langle", ttype:LEFTBRACKET},
  403. {input:">>", tag:"mo", output:"\u232A", tex:"rangle", ttype:RIGHTBRACKET},
  404. {input:"{:", tag:"mo", output:"{:", tex:null, ttype:LEFTBRACKET, invisible:true},
  405. {input:":}", tag:"mo", output:":}", tex:null, ttype:RIGHTBRACKET, invisible:true},
  406. //miscellaneous symbols
  407. {input:"int", tag:"mo", output:"\u222B", tex:null, ttype:CONST},
  408. {input:"dx", tag:"mi", output:"{:d x:}", tex:null, ttype:DEFINITION},
  409. {input:"dy", tag:"mi", output:"{:d y:}", tex:null, ttype:DEFINITION},
  410. {input:"dz", tag:"mi", output:"{:d z:}", tex:null, ttype:DEFINITION},
  411. {input:"dt", tag:"mi", output:"{:d t:}", tex:null, ttype:DEFINITION},
  412. {input:"oint", tag:"mo", output:"\u222E", tex:null, ttype:CONST},
  413. {input:"del", tag:"mo", output:"\u2202", tex:"partial", ttype:CONST},
  414. {input:"grad", tag:"mo", output:"\u2207", tex:"nabla", ttype:CONST},
  415. {input:"+-", tag:"mo", output:"\u00B1", tex:"pm", ttype:CONST},
  416. {input:"O/", tag:"mo", output:"\u2205", tex:"emptyset", ttype:CONST},
  417. {input:"oo", tag:"mo", output:"\u221E", tex:"infty", ttype:CONST},
  418. {input:"aleph", tag:"mo", output:"\u2135", tex:null, ttype:CONST},
  419. {input:"...", tag:"mo", output:"...", tex:"ldots", ttype:CONST},
  420. {input:":.", tag:"mo", output:"\u2234", tex:"therefore", ttype:CONST},
  421. {input:"/_", tag:"mo", output:"\u2220", tex:"angle", ttype:CONST},
  422. {input:"\\ ", tag:"mo", output:"\u00A0", tex:null, ttype:CONST, val:true},
  423. {input:"quad", tag:"mo", output:"\u00A0\u00A0", tex:null, ttype:CONST},
  424. {input:"qquad", tag:"mo", output:"\u00A0\u00A0\u00A0\u00A0", tex:null, ttype:CONST},
  425. {input:"cdots", tag:"mo", output:"\u22EF", tex:null, ttype:CONST},
  426. {input:"vdots", tag:"mo", output:"\u22EE", tex:null, ttype:CONST},
  427. {input:"ddots", tag:"mo", output:"\u22F1", tex:null, ttype:CONST},
  428. {input:"diamond", tag:"mo", output:"\u22C4", tex:null, ttype:CONST},
  429. {input:"square", tag:"mo", output:"\u25A1", tex:null, ttype:CONST},
  430. {input:"|__", tag:"mo", output:"\u230A", tex:"lfloor", ttype:CONST},
  431. {input:"__|", tag:"mo", output:"\u230B", tex:"rfloor", ttype:CONST},
  432. {input:"|~", tag:"mo", output:"\u2308", tex:"lceil", ttype:CONST},
  433. {input:"~|", tag:"mo", output:"\u2309", tex:"rceil", ttype:CONST},
  434. {input:"CC", tag:"mo", output:"\u2102", tex:"mathbb{C}", ttype:CONST, notexcopy:true},
  435. {input:"NN", tag:"mo", output:"\u2115", tex:"mathbb{N}", ttype:CONST, notexcopy:true},
  436. {input:"QQ", tag:"mo", output:"\u211A", tex:"mathbb{Q}", ttype:CONST, notexcopy:true},
  437. {input:"RR", tag:"mo", output:"\u211D", tex:"mathbb{R}", ttype:CONST, notexcopy:true},
  438. {input:"ZZ", tag:"mo", output:"\u2124", tex:"mathbb{Z}", ttype:CONST, notexcopy:true},
  439. //{input:"f", tag:"mi", output:"f", tex:null, ttype:UNARY, func:true, val:true},
  440. //{input:"g", tag:"mi", output:"g", tex:null, ttype:UNARY, func:true, val:true},
  441. //standard functions
  442. {input:"lim", tag:"mo", output:"lim", tex:null, ttype:UNDEROVER},
  443. {input:"Lim", tag:"mo", output:"Lim", tex:null, ttype:UNDEROVER},
  444. {input:"sin", tag:"mo", output:"sin", tex:null, ttype:UNARY, func:true},
  445. {input:"cos", tag:"mo", output:"cos", tex:null, ttype:UNARY, func:true},
  446. {input:"tan", tag:"mo", output:"tan", tex:null, ttype:UNARY, func:true},
  447. {input:"sinh", tag:"mo", output:"sinh", tex:null, ttype:UNARY, func:true},
  448. {input:"cosh", tag:"mo", output:"cosh", tex:null, ttype:UNARY, func:true},
  449. {input:"tanh", tag:"mo", output:"tanh", tex:null, ttype:UNARY, func:true},
  450. {input:"cot", tag:"mo", output:"cot", tex:null, ttype:UNARY, func:true},
  451. {input:"sec", tag:"mo", output:"sec", tex:null, ttype:UNARY, func:true},
  452. {input:"csc", tag:"mo", output:"csc", tex:null, ttype:UNARY, func:true},
  453. {input:"log", tag:"mo", output:"log", tex:null, ttype:UNARY, func:true},
  454. {input:"ln", tag:"mo", output:"ln", tex:null, ttype:UNARY, func:true},
  455. {input:"det", tag:"mo", output:"det", tex:null, ttype:UNARY, func:true},
  456. {input:"dim", tag:"mo", output:"dim", tex:null, ttype:CONST},
  457. {input:"mod", tag:"mo", output:"mod", tex:null, ttype:CONST},
  458. {input:"gcd", tag:"mo", output:"gcd", tex:null, ttype:UNARY, func:true},
  459. {input:"lcm", tag:"mo", output:"lcm", tex:null, ttype:UNARY, func:true},
  460. {input:"lub", tag:"mo", output:"lub", tex:null, ttype:CONST},
  461. {input:"glb", tag:"mo", output:"glb", tex:null, ttype:CONST},
  462. {input:"min", tag:"mo", output:"min", tex:null, ttype:UNDEROVER},
  463. {input:"max", tag:"mo", output:"max", tex:null, ttype:UNDEROVER},
  464. //arrows
  465. {input:"uarr", tag:"mo", output:"\u2191", tex:"uparrow", ttype:CONST},
  466. {input:"darr", tag:"mo", output:"\u2193", tex:"downarrow", ttype:CONST},
  467. {input:"rarr", tag:"mo", output:"\u2192", tex:"rightarrow", ttype:CONST},
  468. {input:"->", tag:"mo", output:"\u2192", tex:"to", ttype:CONST},
  469. {input:">->", tag:"mo", output:"\u21A3", tex:"rightarrowtail", ttype:CONST},
  470. {input:"->>", tag:"mo", output:"\u21A0", tex:"twoheadrightarrow", ttype:CONST},
  471. {input:">->>", tag:"mo", output:"\u2916", tex:"twoheadrightarrowtail", ttype:CONST},
  472. {input:"|->", tag:"mo", output:"\u21A6", tex:"mapsto", ttype:CONST},
  473. {input:"larr", tag:"mo", output:"\u2190", tex:"leftarrow", ttype:CONST},
  474. {input:"harr", tag:"mo", output:"\u2194", tex:"leftrightarrow", ttype:CONST},
  475. {input:"rArr", tag:"mo", output:"\u21D2", tex:"Rightarrow", ttype:CONST},
  476. {input:"lArr", tag:"mo", output:"\u21D0", tex:"Leftarrow", ttype:CONST},
  477. {input:"hArr", tag:"mo", output:"\u21D4", tex:"Leftrightarrow", ttype:CONST},
  478. //commands with argument
  479. {input:"sqrt", tag:"msqrt", output:"sqrt", tex:null, ttype:UNARY},
  480. {input:"root", tag:"mroot", output:"root", tex:null, ttype:BINARY},
  481. {input:"frac", tag:"mfrac", output:"/", tex:null, ttype:BINARY},
  482. {input:"/", tag:"mfrac", output:"/", tex:null, ttype:INFIX},
  483. {input:"stackrel", tag:"mover", output:"stackrel", tex:null, ttype:BINARY},
  484. {input:"_", tag:"msub", output:"_", tex:null, ttype:INFIX},
  485. {input:"^", tag:"msup", output:"^", tex:null, ttype:INFIX},
  486. {input:"hat", tag:"mover", output:"\u005E", tex:null, ttype:UNARY, acc:true},
  487. {input:"bar", tag:"mover", output:"\u00AF", tex:"overline", ttype:UNARY, acc:true},
  488. {input:"vec", tag:"mover", output:"\u2192", tex:null, ttype:UNARY, acc:true},
  489. {input:"dot", tag:"mover", output:".", tex:null, ttype:UNARY, acc:true},
  490. {input:"ddot", tag:"mover", output:"..", tex:null, ttype:UNARY, acc:true},
  491. {input:"ul", tag:"munder", output:"\u0332", tex:"underline", ttype:UNARY, acc:true},
  492. {input:"text", tag:"mtext", output:"text", tex:null, ttype:TEXT},
  493. {input:"mbox", tag:"mtext", output:"mbox", tex:null, ttype:TEXT},
  494. AMquote,
  495. {input:"bb", tag:"mstyle", atname:"fontweight", atval:"bold", output:"bb", tex:null, ttype:UNARY},
  496. {input:"mathbf", tag:"mstyle", atname:"fontweight", atval:"bold", output:"mathbf", tex:null, ttype:UNARY},
  497. {input:"sf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"sf", tex:null, ttype:UNARY},
  498. {input:"mathsf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"mathsf", tex:null, ttype:UNARY},
  499. {input:"bbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"bbb", tex:null, ttype:UNARY, codes:AMbbb},
  500. {input:"mathbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"mathbb", tex:null, ttype:UNARY, codes:AMbbb},
  501. {input:"cc", tag:"mstyle", atname:"mathvariant", atval:"script", output:"cc", tex:null, ttype:UNARY, codes:AMcal},
  502. {input:"mathcal", tag:"mstyle", atname:"mathvariant", atval:"script", output:"mathcal", tex:null, ttype:UNARY, codes:AMcal},
  503. {input:"tt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"tt", tex:null, ttype:UNARY},
  504. {input:"mathtt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"mathtt", tex:null, ttype:UNARY},
  505. {input:"fr", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"fr", tex:null, ttype:UNARY, codes:AMfrk},
  506. {input:"mathfrak", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"mathfrak", tex:null, ttype:UNARY, codes:AMfrk},
  507. // Symbols added by Mauno Korpelainen, November 2009.
  508. {input:"density",tag:"mstyle",atname:"mathvariant", atval:"mathsize", tex:null, ttype:BINARY},
  509. {input:"varkappa", tag:"mi", output:"\u03F0", tex:null, ttype:CONST},
  510. {input:"digamma", tag:"mi", output:"\u03DC", tex:null, ttype:CONST},
  511. {input:"'", tag:"mo", output:"\u02B9", tex:"hspace{0}{'}", ttype:CONST},
  512. {input:"''", tag:"mo", output:"\u02BA", tex:"hspace{0}{''}", ttype:CONST},
  513. {input:"'''", tag:"mo", output:"\u2034", tex:"hspace{0}{'''}", ttype:CONST},
  514. {input:"''''", tag:"mo", output:"\u2057", tex:"hspace{0}{''''}", ttype:CONST},
  515. {input:"#", tag:"mo", output:"#", tex:null, ttype:CONST},
  516. {input:"%", tag:"mo", output:"\u0025", tex:null, ttype:CONST},
  517. {input:"&", tag:"mo", output:"\u0026", tex:null, ttype:CONST},
  518. {input:"^", tag:"msup", output:"^", tex:null, ttype:INFIX},
  519. {input:"~=", tag:"mo", output:"\u2245", tex:"cong", ttype:CONST},
  520. {input:"abs", tag:"mo", output:"abs", tex:null, ttype:UNARY, func:true},
  521. {input:"acute", tag:"mover", output:"\u00B4", tex:null, ttype:UNARY, acc:true},
  522. {input:"AE", tag:"mo", output:"\u00C6", tex:null, ttype:CONST},
  523. {input:"ae", tag:"mo", output:"\u00E6", tex:null, ttype:CONST},
  524. {input:"amalg", tag:"mo", output:"\u2210", tex:null, ttype:CONST},
  525. {input:"angle", tag:"mo", output:"\u2222", tex:null, ttype:CONST},
  526. {input:"approx", tag:"mo", output:"\u2248", tex:null, ttype:CONST},
  527. {input:"approxeq", tag:"mo", output:"\u224A", tex:null, ttype:CONST},
  528. {input:"arccos", tag:"mo", output:"arccos", tex:null, ttype:UNARY, func:true},
  529. {input:"arcsin", tag:"mo", output:"arcsin", tex:null, ttype:UNARY, func:true},
  530. {input:"arctan", tag:"mo", output:"arctan", tex:null, ttype:UNARY, func:true},
  531. {input:"arg", tag:"mi", output:"arg", tex:null, ttype:UNARY, func:true},
  532. {input:"ast", tag:"mo", output:"\u002A", tex:null, ttype:CONST},
  533. {input:"asymp", tag:"mo", output:"\u224D", tex:null, ttype:CONST},
  534. {input:"atop", tag:"mfrac", output:"", tex:null, ttype:INFIX},
  535. {input:"backprime", tag:"mo", output:"\u2035", tex:null, ttype:CONST},
  536. {input:"backsim", tag:"mo", output:"\u223D", tex:null, ttype:CONST},
  537. {input:"backsimeq", tag:"mo", output:"\u22CD", tex:null, ttype:CONST},
  538. {input:"backslash", tag:"mo", output:"\u2216", atval:"1", tex:null, ttype:STRETCHY},
  539. {input:"barwedge", tag:"mo", output:"\u22BC", tex:null, ttype:CONST},
  540. {input:"Bbb{A}", tag:"mo", output:"\uD835\uDD38", tex:"Bbb{A}", ttype:CONST},
  541. {input:"because", tag:"mo", output:"\u2235", tex:null, ttype:CONST},
  542. {input:"beth", tag:"mo", output:"\u2136", tex:null, ttype:CONST},
  543. {input:"between", tag:"mo", output:"\u226C", tex:null, ttype:CONST},
  544. {input:"bigcap", tag:"mo", output:"\u22C2", tex:null, ttype:UNDEROVER},
  545. {input:"bigcirc", tag:"mo", output:"\u25CB", tex:null, ttype:CONST},
  546. {input:"bigcup", tag:"mo", output:"\u22C3", tex:null, ttype:UNDEROVER},
  547. {input:"bigodot", tag:"mo", output:"\u2A00", tex:null, ttype:UNDEROVER},
  548. {input:"bigoplus", tag:"mo", output:"\u2A01", tex:null, ttype:UNDEROVER},
  549. {input:"bigotimes", tag:"mo", output:"\u2A02", tex:null, ttype:UNDEROVER},
  550. {input:"bigsqcap", tag:"mo", output:"\u2A05", tex:null, ttype:UNDEROVER},
  551. {input:"bigsqcup", tag:"mo", output:"\u2A06", tex:null, ttype:UNDEROVER},
  552. {input:"bigstar", tag:"mo", output:"\u2605", tex:null, ttype:CONST},
  553. {input:"bigtriangledown",tag:"mo",output:"\u25BD", tex:null, ttype:CONST},
  554. {input:"bigtriangleup",tag:"mo",output:"\u25B3", tex:null, ttype:CONST},
  555. {input:"biguplus", tag:"mo", output:"\u2A04", tex:null, ttype:UNDEROVER},
  556. {input:"bigwedge", tag:"mo", output:"\u22C0", tex:null, ttype:UNDEROVER},
  557. {input:"bigwedge", tag:"mo", output:"\u22C0", tex:null, ttype:UNDEROVER},
  558. {input:"bigvee", tag:"mo", output:"\u22C1", tex:null, ttype:UNDEROVER},
  559. {input:"blacktriangle", tag:"mo", output:"\u25B4", tex:null, ttype:CONST},
  560. {input:"blacktriangledown", tag:"mo", output:"\u25BE", tex:null, ttype:CONST},
  561. {input:"blacktriangleleft", tag:"mo", output:"\u25C0", tex:null, ttype:CONST},
  562. {input:"blacktriangleright", tag:"mo", output:"\u25B6", tex:null, ttype:CONST},
  563. {input:"bot", tag:"mo", output:"\u22A5", tex:null, ttype:CONST},
  564. {input:"bowtie", tag:"mo", output:"\u22C8", tex:null, ttype:CONST},
  565. {input:"Box", tag:"mo", output:"\u25A1", tex:null, ttype:CONST},
  566. {input:"boxdot", tag:"mo", output:"\u22A1", tex:null, ttype:CONST},
  567. {input:"boxminus", tag:"mo", output:"\u229F", tex:null, ttype:CONST},
  568. {input:"boxplus", tag:"mo", output:"\u229E", tex:null, ttype:CONST},
  569. {input:"boxtimes", tag:"mo", output:"\u22A0", tex:null, ttype:CONST},
  570. {input:"breve", tag:"mover", output:"\u02D8", tex:null, ttype:UNARY, acc:true},
  571. {input:"bullet", tag:"mo", output:"\u2022", tex:null, ttype:CONST},
  572. {input:"Bumpeq", tag:"mo", output:"\u224E", tex:null, ttype:CONST},
  573. {input:"bumpeq", tag:"mo", output:"\u224F", tex:null, ttype:CONST},
  574. {input:"cap", tag:"mo", output:"\u2229", tex:null, ttype:CONST},
  575. {input:"Cap", tag:"mo", output:"\u22D2", tex:null, ttype:CONST},
  576. {input:"cdot", tag:"mo", output:"\u22C5", tex:null, ttype:CONST},
  577. {input:"cdotp", tag:"mo", output:"\u00B7", tex:null, ttype:CONST},
  578. {input:"check", tag:"mover", output:"\u02C7", tex:null, ttype:UNARY, acc:true},
  579. {input:"checkmark", tag:"mo", output:"\u2713", tex:null, ttype:CONST},
  580. {input:"choose", tag:"mfrac", output:"", tex:null, ttype:INFIX},
  581. {input:"circ", tag:"mo", output:"\u2218", tex:null, ttype:CONST},
  582. {input:"circeq", tag:"mo", output:"\u2257", tex:null, ttype:CONST},
  583. {input:"circledast", tag:"mo", output:"\u229B", tex:null, ttype:CONST},
  584. {input:"circledcirc", tag:"mo", output:"\u229A", tex:null, ttype:CONST},
  585. {input:"circleddash", tag:"mo", output:"\u229D", tex:null, ttype:CONST},
  586. {input:"circledR", tag:"mo", output:"\u24C7", tex:null, ttype:CONST},
  587. {input:"circledS", tag:"mo", output:"\u24C8", tex:null, ttype:CONST},
  588. {input:"clubsuit", tag:"mo", output:"\u2663", tex:null, ttype:CONST},
  589. {input:"colon", tag:"mo", output:"\u003A", tex:null, ttype:CONST},
  590. {input:"complement", tag:"mo", output:"\u2201", tex:null, ttype:CONST},
  591. {input:"cong", tag:"mo", output:"\u2245", tex:null, ttype:CONST},
  592. {input:"coprod", tag:"mo", output:"\u2210", tex:null, ttype:UNDEROVER},
  593. {input:"coth", tag:"mo", output:"coth", tex:null, ttype:UNARY, func:true},
  594. {input:"cup", tag:"mo", output:"\u222A", tex:null, ttype:CONST},
  595. {input:"Cup", tag:"mo", output:"\u22D3", tex:null, ttype:CONST},
  596. {input:"curlyeqprec", tag:"mo", output:"\u22DE", tex:null, ttype:CONST},
  597. {input:"curlyeqsucc", tag:"mo", output:"\u22DF", tex:null, ttype:CONST},
  598. {input:"curlywedge", tag:"mo", output:"\u22CF", tex:null, ttype:CONST},
  599. {input:"curlyvee", tag:"mo", output:"\u22CE", tex:null, ttype:CONST},
  600. {input:"curvearrowleft", tag:"mo", output:"\u21B6", tex:null, ttype:CONST},
  601. {input:"curvearrowright", tag:"mo", output:"\u21B7", tex:null, ttype:CONST},
  602. {input:"dag", tag:"mo", output:"\u2020", tex:null, ttype:CONST},
  603. {input:"dagger", tag:"mo", output:"\u2020", tex:null, ttype:CONST},
  604. {input:"daleth", tag:"mo", output:"\u2138", tex:null, ttype:CONST},
  605. {input:"dashv", tag:"mo", output:"\u22A3", tex:null, ttype:CONST},
  606. {input:"ddag", tag:"mo", output:"\u2021", tex:null, ttype:CONST},
  607. {input:"ddagger", tag:"mo", output:"\u2021", tex:null, ttype:CONST},
  608. {input:"ddots", tag:"mo", output:"\u22F1", tex:null, ttype:CONST},
  609. {input:"deg", tag:"mi", output:"deg", tex:null, ttype:UNARY, func:true},
  610. {input:"Diamond", tag:"mo", output:"\u2662", tex:null, ttype:CONST},
  611. {input:"diamondsuit", tag:"mo", output:"\u2662", tex:null, ttype:CONST},
  612. {input:"displaystyle",tag:"mstyle",atname:"displaystyle",atval:"true", tex:null, ttype:UNARY},
  613. {input:"div", tag:"mo", output:"\u00F7", tex:null, ttype:CONST},
  614. {input:"divide", tag:"mo", output:"-:", tex:null, ttype:DEFINITION},
  615. {input:"divideontimes", tag:"mo", output:"\u22C7", tex:null, ttype:CONST},
  616. {input:"doteq", tag:"mo", output:"\u2250", tex:null, ttype:CONST},
  617. {input:"Doteq", tag:"mo", output:"\u2251", tex:null, ttype:CONST},
  618. {input:"dotplus", tag:"mo", output:"\u2214", tex:null, ttype:CONST},
  619. {input:"dots", tag:"mo", output:"\u2026", tex:null, ttype:CONST},
  620. {input:"doublebarwedge", tag:"mo", output:"\u2A5E", tex:null, ttype:CONST},
  621. {input:"downarrow", tag:"mo", output:"\u2193", tex:null, ttype:CONST},
  622. {input:"Downarrow", tag:"mo", output:"\u21D3", tex:null, ttype:CONST},
  623. {input:"downdownarrows", tag:"mo", output:"\u21CA", tex:null, ttype:CONST},
  624. {input:"downharpoonleft", tag:"mo", output:"\u21C3", tex:null, ttype:CONST},
  625. {input:"downharpoonright", tag:"mo", output:"\u21C2", tex:null, ttype:CONST},
  626. {input:"ell", tag:"mo", output:"\u2113", tex:null, ttype:CONST},
  627. {input:"emptyset", tag:"mo", output:"\u2205", tex:null, ttype:CONST},
  628. {input:"eqcirc", tag:"mo", output:"\u2256", tex:null, ttype:CONST},
  629. {input:"eqsim", tag:"mo", output:"\u2242", tex:null, ttype:CONST},
  630. {input:"eqslantgtr", tag:"mo", output:"\u2A96", tex:null, ttype:CONST},
  631. {input:"eqslantless", tag:"mo", output:"\u2A95", tex:null, ttype:CONST},
  632. {input:"equiv", tag:"mo", output:"\u2261", tex:null, ttype:CONST},
  633. {input:"exists", tag:"mo", output:"\u2203", tex:null, ttype:CONST},
  634. {input:"exp", tag:"mi", output:"exp", tex:null, ttype:UNARY, func:true},
  635. {input:"fallingdotseq", tag:"mo", output:"\u2252", tex:null, ttype:CONST},
  636. {input:"Finv", tag:"mo", output:"\u2132", tex:null, ttype:CONST},
  637. {input:"flat", tag:"mo", output:"\u266D", tex:null, ttype:CONST},
  638. {input:"forall", tag:"mo", output:"\u2200", tex:null, ttype:CONST},
  639. {input:"frac", tag:"mfrac", output:"/", tex:null, ttype:BINARY},
  640. {input:"frac12", tag:"mo", output:"\u00BD", tex:null, ttype:CONST},
  641. {input:"frac13", tag:"mo", output:"\u2153", tex:null, ttype:CONST},
  642. {input:"frac14", tag:"mo", output:"\u00BC", tex:null, ttype:CONST},
  643. {input:"frac15", tag:"mo", output:"\u2155", tex:null, ttype:CONST},
  644. {input:"frac16", tag:"mo", output:"\u2159", tex:null, ttype:CONST},
  645. {input:"frac18", tag:"mo", output:"\u215B", tex:null, ttype:CONST},
  646. {input:"frac23", tag:"mo", output:"\u2154", tex:null, ttype:CONST},
  647. {input:"frac25", tag:"mo", output:"\u2156", tex:null, ttype:CONST},
  648. {input:"frac34", tag:"mo", output:"\u00BE", tex:null, ttype:CONST},
  649. {input:"frac35", tag:"mo", output:"\u2157", tex:null, ttype:CONST},
  650. {input:"frac38", tag:"mo", output:"\u215C", tex:null, ttype:CONST},
  651. {input:"frac45", tag:"mo", output:"\u2158", tex:null, ttype:CONST},
  652. {input:"frac56", tag:"mo", output:"\u215A", tex:null, ttype:CONST},
  653. {input:"frac58", tag:"mo", output:"\u215D", tex:null, ttype:CONST},
  654. {input:"frac78", tag:"mo", output:"\u215E", tex:null, ttype:CONST},
  655. {input:"frown", tag:"mo", output:"\u2322", tex:null, ttype:CONST},
  656. {input:"Game", tag:"mo", output:"\u2141", tex:null, ttype:CONST},
  657. {input:"ge", tag:"mo", output:"\u2265", tex:null, ttype:CONST},
  658. {input:"geqq", tag:"mo", output:"\u2267", tex:null, ttype:CONST},
  659. {input:"geqslant", tag:"mo", output:"\u2265", tex:null, ttype:CONST},
  660. {input:"gets", tag:"mo", output:"\u2190", tex:null, ttype:CONST},
  661. {input:"gg", tag:"mo", output:"\u226B", tex:null, ttype:CONST},
  662. {input:"ggg", tag:"mo", output:"\u22D9", tex:null, ttype:CONST},
  663. {input:"gimel", tag:"mo", output:"\u2137", tex:null, ttype:CONST},
  664. {input:"gnapprox", tag:"mo", output:"\u2A8A", tex:null, ttype:CONST},
  665. {input:"gneq", tag:"mo", output:"\u2A88", tex:null, ttype:CONST},
  666. {input:"gneqq", tag:"mo", output:"\u2269", tex:null, ttype:CONST},
  667. {input:"gnsim", tag:"mo", output:"\u22E7", tex:null, ttype:CONST},
  668. {input:"grave", tag:"mover", output:"\u0060", tex:null, ttype:UNARY, acc:true},
  669. {input:"gt", tag:"mo", output:"\u003E", tex:null, ttype:CONST},
  670. {input:"gt=", tag:"mo", output:"\u2265", tex:"geq", ttype:CONST},
  671. {input:"gtrapprox", tag:"mo", output:"\u2A86", tex:null, ttype:CONST},
  672. {input:"gtrdot", tag:"mo", output:"\u22D7", tex:null, ttype:CONST},
  673. {input:"gtreqless", tag:"mo", output:"\u22DB", tex:null, ttype:CONST},
  674. {input:"gtreqqless", tag:"mo", output:"\u2A8C", tex:null, ttype:CONST},
  675. {input:"gtrless", tag:"mo", output:"\u2277", tex:null, ttype:CONST},
  676. {input:"gtrsim", tag:"mo", output:"\u2273", tex:null, ttype:CONST},
  677. {input:"hbar", tag:"mo", output:"\u210F", tex:null, ttype:CONST},
  678. {input:"Heart", tag:"mo", output:"\u2661", tex:"heartsuit", ttype:CONST},
  679. {input:"heartsuit", tag:"mo", output:"\u2661", tex:null, ttype:CONST},
  680. {input:"hom", tag:"mi", output:"hom", tex:null, ttype:UNARY, func:true},
  681. {input:"hookleftarrow", tag:"mo", output:"\u21A9", tex:null, ttype:CONST},
  682. {input:"hookrightarrow", tag:"mo", output:"\u21AA", tex:null, ttype:CONST},
  683. {input:"hslash", tag:"mo", output:"\u210F", tex:null, ttype:CONST},
  684. //{input:"i", tag:"mo", output:"\u0131", tex:null, ttype:CONST},
  685. {input:"iff", tag:"mo", output:"~\\Longleftrightarrow~", tex:null, ttype:DEFINITION},
  686. {input:"iff", tag:"mo", output:"<=>", tex:null, ttype:DEFINITION},
  687. {input:"iiiint", tag:"mo", output:"\u2A0C", tex:null, ttype:CONST},
  688. {input:"iiint", tag:"mo", output:"\u222D", tex:null, ttype:CONST},
  689. {input:"iint", tag:"mo", output:"\u222C", tex:null, ttype:CONST},
  690. {input:"Im", tag:"mo", output:"\u2111", tex:null, ttype:CONST},
  691. {input:"imath", tag:"mo", output:"\uD835\uDEA4", tex:null, ttype:CONST},
  692. {input:"implies", tag:"mo", output:"\u21D2", tex:null, ttype:LONG},
  693. {input:"inf", tag:"mo", output:"inf", tex:null, ttype:UNDEROVER},
  694. {input:"infty", tag:"mo", output:"\u221E", tex:null, ttype:CONST},
  695. {input:"intercal", tag:"mo", output:"\u22BA", tex:null, ttype:CONST},
  696. {input:"jmath", tag:"mo", output:"\uD835\uDEA5", tex:null, ttype:CONST},
  697. {input:"Join", tag:"mo", output:"\u22C8", tex:null, ttype:CONST},
  698. {input:"ker", tag:"mi", output:"ker", tex:null, ttype:UNARY, func:true},
  699. //{input:"L", tag:"mo", output:"\u0141", tex:null, ttype:CONST},
  700. //{input:"l", tag:"mo", output:"\u0142", tex:null, ttype:CONST},
  701. {input:"land", tag:"mo", output:"\u2227", tex:null, ttype:CONST},
  702. {input:"langle", tag:"mo", output:"\u2329", atval:"1", tex:null, ttype:STRETCHY},
  703. {input:"lbrace", tag:"mo", output:"{", atval:"1", tex:null, ttype:STRETCHY},
  704. {input:"lbrack", tag:"mo", output:"[", tex:"[", ttype:LEFTBRACKET},
  705. {input:"lceil", tag:"mo", output:"\u2308", atval:"1", tex:null, ttype:STRETCHY},
  706. {input:"lceiling", tag:"mo", output:"|~", tex:null, ttype:DEFINITION},
  707. {input:"ldots", tag:"mo", output:"\u2026", tex:null, ttype:CONST},
  708. {input:"le", tag:"mo", output:"\u2264", tex:null, ttype:CONST},
  709. {input:"left", tag:"mo", output:"\left", tex:null, ttype:LEFTBRACKET},
  710. {input:"leftarrow", tag:"mo", output:"\u2190", tex:null, ttype:CONST},
  711. {input:"Leftarrow", tag:"mo", output:"\u21D0", tex:null, ttype:CONST},
  712. {input:"leftarrowtail", tag:"mo", output:"\u21A2", tex:null, ttype:CONST},
  713. {input:"leftharpoondown", tag:"mo", output:"\u21BD", tex:null, ttype:CONST},
  714. {input:"leftharpoonup", tag:"mo", output:"\u21BC", tex:null, ttype:CONST},
  715. {input:"leftleftarrows", tag:"mo", output:"\u21C7", tex:null, ttype:CONST},
  716. {input:"leftrightarrow", tag:"mo", output:"\u2194", tex:null, ttype:CONST},
  717. {input:"Leftrightarrow", tag:"mo", output:"\u21D4", tex:null, ttype:CONST},
  718. {input:"leftrightarrows", tag:"mo", output:"\u21C6", tex:null, ttype:CONST},
  719. {input:"leftrightharpoons", tag:"mo", output:"\u21CB", tex:null, ttype:CONST},
  720. {input:"leftrightsquigarrow", tag:"mo", output:"\u21AD", tex:null, ttype:CONST},
  721. {input:"leftthreetimes", tag:"mo", output:"\u22CB", tex:null, ttype:CONST},
  722. {input:"leq", tag:"mo", output:"\u2264", tex:null, ttype:CONST},
  723. {input:"leqq", tag:"mo", output:"\u2266", tex:null, ttype:CONST},
  724. {input:"leqslant", tag:"mo", output:"\u2264", tex:null, ttype:CONST},
  725. {input:"lessapprox", tag:"mo", output:"\u2A85", tex:null, ttype:CONST},
  726. {input:"lessdot", tag:"mo", output:"\u22D6", tex:null, ttype:CONST},
  727. {input:"lesseqgtr", tag:"mo", output:"\u22DA", tex:null, ttype:CONST},
  728. {input:"lesseqqgtr", tag:"mo", output:"\u2A8B", tex:null, ttype:CONST},
  729. {input:"lessgtr", tag:"mo", output:"\u2276", tex:null, ttype:CONST},
  730. {input:"lesssim", tag:"mo", output:"\u2272", tex:null, ttype:CONST},
  731. {input:"lfloor", tag:"mo", output:"\u230A", atval:"1", tex:null, ttype:STRETCHY},
  732. {input:"lg", tag:"mi", output:"lg", tex:null, ttype:UNARY, func:true},
  733. {input:"lhd", tag:"mo", output:"\u22B2", tex:null, ttype:CONST},
  734. {input:"liminf", tag:"mo", output:"liminf", tex:null, ttype:UNDEROVER},
  735. {input:"limsup", tag:"mo", output:"limsup", tex:null, ttype:UNDEROVER},
  736. {input:"ll", tag:"mo", output:"\u226A", tex:null, ttype:CONST},
  737. {input:"llcorner", tag:"mo", output:"\u231E", tex:null, ttype:CONST},
  738. {input:"Lleftarrow", tag:"mo", output:"\u21DA", tex:null, ttype:CONST},
  739. {input:"lll", tag:"mo", output:"\u22D8", tex:null, ttype:CONST},
  740. {input:"lmoustache", tag:"mo", output:"\u23B0", tex:null, ttype:CONST},
  741. {input:"lnapprox", tag:"mo", output:"\u2A89", tex:null, ttype:CONST},
  742. {input:"lneq", tag:"mo", output:"\u2A87", tex:null, ttype:CONST},
  743. {input:"lneqq", tag:"mo", output:"\u2268", tex:null, ttype:CONST},
  744. {input:"lnot", tag:"mo", output:"\u00AC", tex:null, ttype:CONST},
  745. {input:"lnsim", tag:"mo", output:"\u22E6", tex:null, ttype:CONST},
  746. {input:"longleftarrow", tag:"mo", output:"\u2190", tex:null, ttype:LONG},
  747. {input:"Longleftarrow", tag:"mo", output:"\u21D0", tex:null, ttype:LONG},
  748. {input:"longleftrightarrow", tag:"mo", output:"\u2194", tex:null, ttype:LONG},
  749. {input:"Longleftrightarrow", tag:"mo", output:"\u21D4", tex:null, ttype:LONG},
  750. {input:"longmapsto", tag:"mo", output:"\u21A6", tex:null, ttype:CONST},
  751. {input:"longrightarrow", tag:"mo", output:"\u2192", tex:null, ttype:LONG},
  752. {input:"Longrightarrow", tag:"mo", output:"\u21D2", tex:null, ttype:LONG},
  753. {input:"looparrowleft", tag:"mo", output:"\u21AB", tex:null, ttype:CONST},
  754. {input:"looparrowright", tag:"mo", output:"\u21AC", tex:null, ttype:CONST},
  755. {input:"lor", tag:"mo", output:"\u2228", tex:null, ttype:CONST},
  756. {input:"lozenge", tag:"mo", output:"\u25CA", tex:null, ttype:CONST},
  757. {input:"lrcorner", tag:"mo", output:"\u231F", tex:null, ttype:CONST},
  758. {input:"Lsh", tag:"mo", output:"\u21B0", tex:null, ttype:CONST},
  759. {input:"-lt", tag:"mo", output:"\u227A", tex:null, ttype:CONST},
  760. {input:"ltimes", tag:"mo", output:"\u22C9", tex:null, ttype:CONST},
  761. {input:"maltese", tag:"mo", output:"\u2720", tex:null, ttype:CONST},
  762. {input:"mapsto", tag:"mo", output:"\u21A6", tex:null, ttype:CONST},
  763. {input:"mathit", tag:"mstyle", atname:"mathvariant", atval:"italic", tex:null, ttype:UNARY},
  764. {input:"mathrm", tag:"mtext", output:"text", tex:null, ttype:TEXT},
  765. {input:"mathsf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"mathsf", tex:null, ttype:UNARY},
  766. {input:"measuredangle", tag:"mo", output:"\u2221", tex:null, ttype:CONST},
  767. {input:"mho", tag:"mo", output:"\u2127", tex:null, ttype:CONST},
  768. {input:"mid", tag:"mo", output:"\u2223", atval:"1", tex:null, ttype:STRETCHY},
  769. {input:"models", tag:"mo", output:"\u22A8", tex:null, ttype:CONST},
  770. {input:"mp", tag:"mo", output:"\u2213", tex:null, ttype:CONST},
  771. {input:"multimap", tag:"mo", output:"\u22B8", tex:null, ttype:CONST},
  772. {input:"nabla", tag:"mo", output:"\u2207", tex:null, ttype:CONST},
  773. {input:"natural", tag:"mo", output:"\u266E", tex:null, ttype:CONST},
  774. {input:"ncong", tag:"mo", output:"\u2247", tex:null, ttype:CONST},
  775. {input:"ne", tag:"mo", output:"\u2260", tex:null, ttype:CONST},
  776. {input:"nearrow", tag:"mo", output:"\u2197", tex:null, ttype:CONST},
  777. {input:"neg", tag:"mo", output:"\u00AC", tex:null, ttype:CONST},
  778. {input:"neq", tag:"mo", output:"\u2260", tex:null, ttype:CONST},
  779. {input:"nexists", tag:"mo", output:"\u2204", tex:null, ttype:CONST},
  780. {input:"ngeq", tag:"mo", output:"\u2271", tex:null, ttype:CONST},
  781. {input:"ngtr", tag:"mo", output:"\u226F", tex:null, ttype:CONST},
  782. {input:"ni", tag:"mo", output:"\u220B", tex:null, ttype:CONST},
  783. {input:"nleftarrow", tag:"mo", output:"\u219A", tex:null, ttype:CONST},
  784. {input:"nLeftarrow", tag:"mo", output:"\u21CD", tex:null, ttype:CONST},
  785. {input:"nleftrightarrow", tag:"mo", output:"\u21AE", tex:null, ttype:CONST},
  786. {input:"nLeftrightarrow", tag:"mo", output:"\u21CE", tex:null, ttype:CONST},
  787. {input:"nleq", tag:"mo", output:"\u2270", tex:null, ttype:CONST},
  788. {input:"nless", tag:"mo", output:"\u226E", tex:null, ttype:CONST},
  789. {input:"nmid", tag:"mo", output:"\u2224", tex:null, ttype:CONST},
  790. {input:"not\\leq", tag:"mo", output:"\u2270", tex:null, ttype:CONST},
  791. {input:"not<", tag:"mo", output:"\u226E", tex:"not<", ttype:CONST},
  792. {input:"not=", tag:"mo", output:"\u2260", tex:"not=", ttype:CONST},
  793. {input:"not>", tag:"mo", output:"\u226F", tex:"not>", ttype:CONST},
  794. {input:"notexist", tag:"mo", output:"\u2204", tex:"not\\exists", ttype:CONST},
  795. {input:"notgeq", tag:"mo", output:"\u2271", tex:"not\\geq", ttype:CONST},
  796. {input:"notin", tag:"mo", output:"\u2209", tex:null, ttype:CONST},
  797. {input:"notleq", tag:"mo", output:"\u2270", tex:"not\\leq", ttype:CONST},
  798. {input:"notni", tag:"mo", output:"\u220C", tex:"not\\ni", ttype:CONST},
  799. {input:"notsubset", tag:"mo", output:"\u2284", tex:"not\\subset", ttype:CONST},
  800. {input:"notsubseteq", tag:"mo", output:"\u2288", tex:"not\\subseteq", ttype:CONST},
  801. {input:"notsupset", tag:"mo", output:"\u2285", tex:"not\\supset", ttype:CONST},
  802. {input:"notsupseteq", tag:"mo", output:"\u2289", tex:"not\\supseteq", ttype:CONST},
  803. {input:"nparallel", tag:"mo", output:"\u2226", tex:null, ttype:CONST},
  804. {input:"nprec", tag:"mo", output:"\u2280", tex:null, ttype:CONST},
  805. {input:"nrightarrow", tag:"mo", output:"\u219B", tex:null, ttype:CONST},
  806. {input:"nRightarrow", tag:"mo", output:"\u21CF", tex:null, ttype:CONST},
  807. {input:"nsim", tag:"mo", output:"\u2241", tex:null, ttype:CONST},
  808. {input:"nsubseteq", tag:"mo", output:"\u2288", tex:null, ttype:CONST},
  809. {input:"nsucc", tag:"mo", output:"\u2281", tex:null, ttype:CONST},
  810. {input:"nsupseteq", tag:"mo", output:"\u2289", tex:null, ttype:CONST},
  811. {input:"ntriangleleft", tag:"mo", output:"\u22EA", tex:null, ttype:CONST},
  812. {input:"ntrianglelefteq", tag:"mo", output:"\u22EC", tex:null, ttype:CONST},
  813. {input:"ntriangleright", tag:"mo", output:"\u22EB", tex:null, ttype:CONST},
  814. {input:"ntrianglerighteq", tag:"mo", output:"\u22ED", tex:null, ttype:CONST},
  815. {input:"nwarrow", tag:"mo", output:"\u2196", tex:null, ttype:CONST},
  816. {input:"nvdash", tag:"mo", output:"\u22AC", tex:null, ttype:CONST},
  817. {input:"nvDash", tag:"mo", output:"\u22AD", tex:null, ttype:CONST},
  818. {input:"nVdash", tag:"mo", output:"\u22AE", tex:null, ttype:CONST},
  819. {input:"nVDash", tag:"mo", output:"\u22AF", tex:null, ttype:CONST},
  820. //{input:"O", tag:"mo", output:"\u00D8", tex:null, ttype:CONST},
  821. //{input:"o", tag:"mo", output:"\u00F8", tex:null, ttype:CONST},
  822. {input:"odot", tag:"mo", output:"\u2299", tex:null, ttype:CONST},
  823. {input:"OE", tag:"mo", output:"\u0152", tex:null, ttype:CONST},
  824. {input:"oe", tag:"mo", output:"\u0153", tex:null, ttype:CONST},
  825. {input:"ominus", tag:"mo", output:"\u2296", tex:null, ttype:CONST},
  826. {input:"oplus", tag:"mo", output:"\u2295", tex:null, ttype:CONST},
  827. {input:"oslash", tag:"mo", output:"\u2298", tex:null, ttype:CONST},
  828. {input:"otimes", tag:"mo", output:"\u2297", tex:null, ttype:CONST},
  829. {input:"overbrace", tag:"mover", output:"\u23B4", tex:null, ttype:UNARY, acc:true},
  830. {input:"overleftarrow",tag:"mover", output:"\u20D6", tex:null, ttype:UNARY, acc:true},
  831. {input:"overleftrightarrow", tag:"mo", output:"\u20E1", tex:null, ttype:CONST},
  832. {input:"overline", tag:"mover", output:"\u00AF", tex:null, ttype:UNARY, acc:true},
  833. {input:"owns", tag:"mo", output:"\u220B", tex:"ni", ttype:CONST},
  834. {input:"parallel", tag:"mo", output:"\u2225", atval:"1", tex:null, ttype:STRETCHY},
  835. {input:"partial", tag:"mo", output:"\u2202", tex:null, ttype:CONST},
  836. {input:"perp", tag:"mo", output:"\u22A5", tex:null, ttype:CONST},
  837. {input:"pitchfork", tag:"mo", output:"\u22D4", tex:null, ttype:CONST},
  838. {input:"pm", tag:"mo", output:"\u00B1", tex:null, ttype:CONST},
  839. {input:"Pr", tag:"mi", output:"Pr", tex:null, ttype:UNARY, func:true},
  840. {input:"prec", tag:"mo", output:"\u227A", tex:null, ttype:CONST},
  841. {input:"precapprox", tag:"mo", output:"\u2AB7", tex:null, ttype:CONST},
  842. {input:"preccurlyeq", tag:"mo", output:"\u227C", tex:null, ttype:CONST},
  843. {input:"preceq", tag:"mo", output:"\u227C", tex:null, ttype:CONST},
  844. {input:"precnapprox", tag:"mo", output:"\u2AB9", tex:null, ttype:CONST},
  845. {input:"precneqq", tag:"mo", output:"\u2AB5", tex:null, ttype:CONST},
  846. {input:"precnsim", tag:"mo", output:"\u22E8", tex:null, ttype:CONST},
  847. {input:"precsim", tag:"mo", output:"\u227E", tex:null, ttype:CONST},
  848. {input:"prime", tag:"mo", output:"\u2032", tex:null, ttype:CONST},
  849. {input:"prod", tag:"mo", output:"\u220F", tex:null, ttype:UNDEROVER},
  850. {input:"prop", tag:"mo", output:"\u221D", tex:"propto", ttype:CONST},
  851. {input:"propto", tag:"mo", output:"\u221D", tex:null, ttype:CONST},
  852. {input:"rangle",tag:"mo",output:"\u232A", rtag:"mi",atval:"1", tex:"rangle", ttype:STRETCHY},
  853. {input:"rbrace",tag:"mo",output:"}", rtag:"mi",atval:"1", tex:"rbrace", ttype:STRETCHY},
  854. {input:"rbrack",tag:"mo",output:"]", tex:"]", ttype:RIGHTBRACKET},
  855. {input:"rceil", tag:"mo",output:"\u2309", rtag:"mi",atval:"1", tex:"rceil", ttype:STRETCHY},
  856. {input:"rceiling", tag:"mo", output:"~|", tex:null, ttype:DEFINITION},
  857. {input:"Re", tag:"mo", output:"\u211C", tex:null, ttype:CONST},
  858. {input:"rfloor",tag:"mo",output:"\u230B", rtag:"mi",atval:"1", tex:"rfloor", ttype:STRETCHY},
  859. {input:"rhd", tag:"mo", output:"\u22B3", tex:null, ttype:CONST},
  860. {input:"right", tag:"mo", output:"\right", tex:null, ttype:RIGHTBRACKET},
  861. {input:"rightarrow", tag:"mo", output:"\u2192", tex:null, ttype:CONST},
  862. {input:"Rightarrow", tag:"mo", output:"\u21D2", tex:null, ttype:CONST},
  863. {input:"rightarrowtail", tag:"mo", output:"\u21A3", tex:null, ttype:CONST},
  864. {input:"rightharpoondown", tag:"mo", output:"\u21C1", tex:null, ttype:CONST},
  865. {input:"rightharpoonup", tag:"mo", output:"\u21C0", tex:null, ttype:CONST},
  866. {input:"rightleftarrows", tag:"mo", output:"\u21C4", tex:null, ttype:CONST},
  867. {input:"rightleftharpoons", tag:"mo", output:"\u21CC", tex:null, ttype:CONST},
  868. {input:"rightrightarrows", tag:"mo", output:"\u21C9", tex:null, ttype:CONST},
  869. {input:"rightsquigarrow", tag:"mo", output:"\u21DD", tex:null, ttype:CONST},
  870. {input:"rightthreetimes", tag:"mo", output:"\u22CC", tex:null, ttype:CONST},
  871. {input:"risingdotseq", tag:"mo", output:"\u2253", tex:null, ttype:CONST},
  872. {input:"rmoustache", tag:"mo", output:"\u23B1", tex:null, ttype:CONST},
  873. {input:"Rrightarrow", tag:"mo", output:"\u21DB", tex:null, ttype:CONST},
  874. {input:"Rsh", tag:"mo", output:"\u21B1", tex:null, ttype:CONST},
  875. {input:"rtimes", tag:"mo", output:"\u22CA", tex:null, ttype:CONST},
  876. //{input:"S", tag:"mo", output:"\u00A7", tex:null, ttype:CONST},
  877. {input:"s0s", tag:"mo", output:"\u200B", tex:"!", ttype:CONST},
  878. {input:"s1s", tag:"mo", output:"\u200A", tex:"hspace{1}", ttype:CONST},
  879. {input:"s2s", tag:"mo", output:"\u2009", tex:"hspace{2}", ttype:CONST},
  880. {input:"s3s", tag:"mo", output:"\u2002", tex:"hspace{5}", ttype:CONST},
  881. {input:"s4s", tag:"mo", output:"\u2003", tex:"hspace{10}", ttype:CONST},
  882. {input:"scriptscriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"2", tex:null, ttype:UNARY},
  883. {input:"scriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"1", tex:null, ttype:UNARY},
  884. {input:"searrow", tag:"mo", output:"\u2198", tex:null, ttype:CONST},
  885. {input:"setminus", tag:"mo", output:"\\", tex:null, ttype:CONST},
  886. {input:"sharp", tag:"mo", output:"\u266F", tex:null, ttype:CONST},
  887. {input:"sim", tag:"mo", output:"\u223C", tex:null, ttype:CONST},
  888. {input:"simeq", tag:"mo", output:"\u2243", tex:null, ttype:CONST},
  889. {input:"sinh", tag:"mo", output:"sinh", tex:null, ttype:UNARY, func:true},
  890. {input:"slash", tag:"mo", output:"\u2215", tex:null, ttype:CONST},
  891. {input:"smallint", tag:"mo", output:"\u222B", tex:null, ttype:CONST},
  892. {input:"smallsetminus", tag:"mo", output:"\u2216", tex:null, ttype:CONST},
  893. {input:"smile", tag:"mo", output:"\u2323", tex:null, ttype:CONST},
  894. {input:"spadesuit", tag:"mo", output:"\u2660", tex:null, ttype:CONST},
  895. {input:"sphericalangle", tag:"mo", output:"\u2222", tex:null, ttype:CONST},
  896. {input:"sqcap", tag:"mo", output:"\u2293", tex:null, ttype:CONST},
  897. {input:"sqcup", tag:"mo", output:"\u2294", tex:null, ttype:CONST},
  898. {input:"sqsubset", tag:"mo", output:"\u228F", tex:null, ttype:CONST},//MimeTex bug
  899. {input:"sqsubseteq", tag:"mo", output:"\u2291", tex:null, ttype:CONST},
  900. {input:"sqsupset", tag:"mo", output:"\u2290", tex:null, ttype:CONST},//MimeTex bug
  901. {input:"sqsupseteq", tag:"mo", output:"\u2292", tex:null, ttype:CONST},
  902. {input:"ss", tag:"mo", output:"\u00DF", tex:null, ttype:CONST},
  903. {input:"stackrel", tag:"mover", output:"stackrel", tex:null, ttype:BINARY},
  904. {input:"star", tag:"mo", output:"\u22C6", tex:null, ttype:CONST},
  905. {input:"subset", tag:"mo", output:"\u2282", tex:null, ttype:CONST},
  906. {input:"Subset", tag:"mo", output:"\u22D0", tex:null, ttype:CONST},
  907. {input:"subseteq", tag:"mo", output:"\u2286", tex:null, ttype:CONST},
  908. {input:"subseteqq", tag:"mo", output:"\u2AC5", tex:null, ttype:CONST},
  909. {input:"subsetneq", tag:"mo", output:"\u228A", tex:null, ttype:CONST},
  910. {input:"subsetneqq", tag:"mo", output:"\u2ACB", tex:null, ttype:CONST},
  911. {input:"succ", tag:"mo", output:"\u227B", tex:null, ttype:CONST},
  912. {input:"succapprox", tag:"mo", output:"\u2AB8", tex:null, ttype:CONST},
  913. {input:"succcurlyeq", tag:"mo", output:"\u227D", tex:null, ttype:CONST},
  914. {input:"succeq", tag:"mo", output:"\u227D", tex:null, ttype:CONST},
  915. {input:"succnapprox", tag:"mo", output:"\u2ABA", tex:null, ttype:CONST},
  916. {input:"succneqq", tag:"mo", output:"\u2AB6", tex:null, ttype:CONST},
  917. {input:"succnsim", tag:"mo", output:"\u22E9", tex:null, ttype:CONST},
  918. {input:"succsim", tag:"mo", output:"\u227F", tex:null, ttype:CONST},
  919. {input:"supset", tag:"mo", output:"\u2283", tex:null, ttype:CONST},
  920. {input:"Supset", tag:"mo", output:"\u22D1", tex:null, ttype:CONST},
  921. {input:"supseteq", tag:"mo", output:"\u2287", tex:null, ttype:CONST},
  922. {input:"supseteqq", tag:"mo", output:"\u2AC6", tex:null, ttype:CONST},
  923. {input:"supsetneq", tag:"mo", output:"\u228B", tex:null, ttype:CONST},
  924. {input:"supsetneqq", tag:"mo", output:"\u2ACC", tex:null, ttype:CONST},
  925. {input:"surd", tag:"mo", output:"sqrt", tex:null, ttype:DEFINITION},
  926. {input:"swarrow", tag:"mo", output:"\u2199", tex:null, ttype:CONST},
  927. {input:"textasciicircum", tag:"mo", output:"\u005E", tex:null, ttype:CONST},
  928. {input:"textasciitilde", tag:"mo", output:"\u007E", tex:null, ttype:CONST},
  929. {input:"textbf", tag:"mstyle", atname:"mathvariant", atval:"bold", tex:null, ttype:UNARY},
  930. {input:"textcopyright", tag:"mo", output:"\u00A9", tex:null, ttype:CONST},
  931. {input:"textdegree", tag:"mo", output:"\u00B0", tex:null, ttype:CONST},
  932. {input:"textdollar", tag:"mo", output:"\u0024", tex:null, ttype:CONST},
  933. {input:"textit", tag:"mstyle", atname:"mathvariant", atval:"italic", tex:null, ttype:UNARY},
  934. {input:"textonehalf", tag:"mo", output:"\u00BD", tex:null, ttype:CONST},
  935. {input:"textonequarter", tag:"mo", output:"\u00BC", tex:null, ttype:CONST},
  936. {input:"textordfeminine", tag:"mo", output:"\u00AA", tex:null, ttype:CONST},
  937. {input:"textordmasculine", tag:"mo", output:"\u00BA", tex:null, ttype:CONST},
  938. {input:"textregistered", tag:"mo", output:"\u00AE", tex:null, ttype:CONST},
  939. {input:"textrm", tag:"mstyle", output:"\\mathrm", tex:null, ttype: DEFINITION},
  940. {input:"textstyle",tag:"mstyle",atname:"displaystyle",atval:"false", tex:null, ttype:UNARY},
  941. {input:"textthreequarters", tag:"mo", output:"\u00BE", tex:null, ttype:CONST},
  942. {input:"texttrademark", tag:"mo", output:"\u2122", tex:null, ttype:CONST},
  943. {input:"texttt", tag:"mstyle", atname:"mathvariant", atval:"monospace", tex:null, ttype:UNARY},
  944. {input:"therefore", tag:"mo", output:"\u2234", tex:null, ttype:CONST},
  945. {input:"thickapprox", tag:"mo", output:"\u2248", tex:null, ttype:CONST},
  946. {input:"thicksim", tag:"mo", output:"\u223C", tex:null, ttype:CONST},
  947. {input:"tilde", tag:"mover", output:"~", tex:null, ttype:UNARY, acc:true},
  948. {input:"times", tag:"mo", output:"\u00D7", tex:null, ttype:CONST},
  949. {input:"to", tag:"mo", output:"\u2192", tex:null, ttype:CONST},
  950. {input:"top", tag:"mo", output:"\u22A4", tex:null, ttype:CONST},
  951. {input:"triangle", tag:"mo", output:"\u25B3", tex:null, ttype:CONST},
  952. {input:"triangledown", tag:"mo", output:"\u25BF", tex:null, ttype:CONST},
  953. {input:"triangleleft",tag:"mo", output:"\u22B2", tex:null, ttype:CONST},
  954. {input:"trianglelefteq", tag:"mo", output:"\u22B4", tex:null, ttype:CONST},
  955. {input:"triangleq", tag:"mo", output:"\u225C", tex:null, ttype:CONST},
  956. {input:"triangleright",tag:"mo",output:"\u22B3", tex:null, ttype:CONST},
  957. {input:"trianglerighteq", tag:"mo", output:"\u22B5", tex:null, ttype:CONST},
  958. {input:"twoheadleftarrow", tag:"mo", output:"\u219E", tex:null, ttype:CONST},
  959. {input:"twoheadrightarrow", tag:"mo", output:"\u21A0", tex:null, ttype:CONST},
  960. {input:"ulcorner", tag:"mo", output:"\u231C", tex:null, ttype:CONST},
  961. {input:"underbrace", tag:"munder", output:"\u23B5", tex:null, ttype:UNARY, acc:true},
  962. {input:"underleftarrow", tag:"mo", output:"\u20EE", tex:null, ttype:CONST},
  963. {input:"underline", tag:"munder", output:"\u00AF", tex:null, ttype:UNARY, acc:true},
  964. {input:"underrightarrow", tag:"mo", output:"\u20EF", tex:null, ttype:CONST},
  965. {input:"unlhd", tag:"mo", output:"\u22B4", tex:null, ttype:CONST},
  966. {input:"unrhd", tag:"mo", output:"\u22B5", tex:null, ttype:CONST},
  967. {input:"uparrow", tag:"mo", output:"\u2191", tex:null, ttype:CONST},
  968. {input:"Uparrow", tag:"mo", output:"\u21D1", tex:null, ttype:CONST},
  969. {input:"updownarrow", tag:"mo", output:"\u2195", tex:null, ttype:CONST},
  970. {input:"Updownarrow", tag:"mo", output:"\u21D5", tex:null, ttype:CONST},
  971. {input:"upharpoonleft", tag:"mo", output:"\u21BF", tex:null, ttype:CONST},
  972. {input:"upharpoonright", tag:"mo", output:"\u21BE", tex:null, ttype:CONST},
  973. {input:"uplus", tag:"mo", output:"\u228E", tex:null, ttype:CONST},
  974. {input:"Upsilon", tag:"mo", output:"\u03A5", tex:null, ttype:CONST},
  975. {input:"upuparrows", tag:"mo", output:"\u21C8", tex:null, ttype:CONST},
  976. {input:"urcorner", tag:"mo", output:"\u231D", tex:null, ttype:CONST},
  977. {input:"varnothing", tag:"mo", output:"\u2205", tex:null, ttype:CONST},
  978. {input:"varpi", tag:"mi", output:"\u03D6", tex:null, ttype:CONST},
  979. {input:"varpropto", tag:"mo", output:"\u221D", tex:null, ttype:CONST},
  980. {input:"varrho", tag:"mi", output:"\u03F1", tex:null, ttype:CONST},
  981. {input:"varsigma", tag:"mi", output:"\u03C2", tex:null, ttype:CONST},
  982. {input:"vartriangle", tag:"mo", output:"\u22B5", tex:null, ttype:CONST},
  983. {input:"vartriangleleft", tag:"mo", output:"\u22B2", tex:null, ttype:CONST},
  984. {input:"vartriangleright", tag:"mo", output:"\u22B3", tex:null, ttype:CONST},
  985. {input:"vdash", tag:"mo", output:"\u22A2", tex:null, ttype:CONST},
  986. {input:"vDash", tag:"mo", output:"\u22A8", tex:null, ttype:CONST},
  987. {input:"Vdash", tag:"mo", output:"\u22A9", tex:null, ttype:CONST},
  988. {input:"wedge", tag:"mo", output:"\u2227", tex:null, ttype:CONST},
  989. {input:"vee", tag:"mo", output:"\u2228", tex:null, ttype:CONST},
  990. {input:"veebar", tag:"mo", output:"\u22BB", text:null, ttype:CONST},
  991. {input:"vert", tag:"mo", output:"\u007C", atval:"1", tex:null, ttype:STRETCHY},
  992. {input:"Vert", tag:"mo", output:"\u2016", atval:"1", tex:null, ttype:STRETCHY},
  993. {input:"widehat", tag:"mover", output:"\u0302", tex:null, ttype:UNARY, acc:true},
  994. {input:"widetilde", tag:"mover", output:"\u02DC", tex:null, ttype:UNARY, acc:true},
  995. {input:"wp", tag:"mo", output:"\u2118", tex:null, ttype:CONST},
  996. {input:"wr", tag:"mo", output:"\u2240", tex:null, ttype:CONST},
  997. {input:"Vvdash", tag:"mo", output:"\u22AA", tex:null, ttype:CONST},
  998. {input:"yen", tag:"mo", output:"\u00A5", tex:null, ttype:CONST},
  999. {input:"zeta", tag:"mi", output:"\u03B6", tex:null, ttype:CONST}
  1000. ];
  1001. function compareNames(s1,s2) {
  1002. if (s1.input > s2.input) return 1
  1003. else return -1;
  1004. }
  1005. var AMnames = []; //list of input symbols
  1006. function initSymbols() {
  1007. var texsymbols = [], i;
  1008. for (i=0; i<AMsymbols.length; i++)
  1009. if (AMsymbols[i].tex && !(typeof AMsymbols[i].notexcopy == "boolean" && AMsymbols[i].notexcopy))
  1010. texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
  1011. tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype};
  1012. AMsymbols = AMsymbols.concat(texsymbols);
  1013. refreshSymbols();
  1014. }
  1015. function refreshSymbols(){
  1016. var i;
  1017. AMsymbols.sort(compareNames);
  1018. for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
  1019. LMsymbols.sort(compareNames);
  1020. for (i=0; i<LMsymbols.length; i++) LMnames[i] = LMsymbols[i].input;
  1021. }
  1022. function define(oldstr,newstr) {
  1023. if(oldstr.substr(0,1)=="\\")
  1024. LMsymbols = LMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
  1025. ttype:DEFINITION}]);
  1026. else
  1027. AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
  1028. tex:null, ttype:DEFINITION}]);
  1029. refreshSymbols(); // this may be a problem if many symbols are defined!
  1030. }
  1031. function AMremoveCharsAndBlanks(str,n) {
  1032. //remove n characters and any following blanks
  1033. var st;
  1034. if (str.charAt(n)=="\\" && str.charAt(n+1)!="\\" && str.charAt(n+1)!=" ")
  1035. st = str.slice(n+1);
  1036. else st = str.slice(n);
  1037. for (var i=0; i<st.length && st.charCodeAt(i)<=32; i=i+1);
  1038. return st.slice(i);
  1039. }
  1040. function position(arr, str, n) {
  1041. // return position >=n where str appears or would be inserted
  1042. // assumes arr is sorted
  1043. if (n==0) {
  1044. var h,m;
  1045. n = -1;
  1046. h = arr.length;
  1047. while (n+1<h) {
  1048. m = (n+h) >> 1;
  1049. if (arr[m]<str) n = m; else h = m;
  1050. }
  1051. return h;
  1052. } else
  1053. for (var i=n; i<arr.length && arr[i]<str; i++);
  1054. return i; // i=arr.length || arr[i]>=str
  1055. }
  1056. function AMgetSymbol(str) {
  1057. //return maximal initial substring of str that appears in names
  1058. //return null if there is none
  1059. var k = 0; //new pos
  1060. var j = 0; //old pos
  1061. var mk; //match pos
  1062. var st;
  1063. var tagst;
  1064. var match = "";
  1065. var more = true;
  1066. for (var i=1; i<=str.length && more; i++) {
  1067. st = str.slice(0,i); //initial substring of length i
  1068. j = k;
  1069. k = position(AMnames, st, j);
  1070. if (k<AMnames.length && str.slice(0,AMnames[k].length)==AMnames[k]){
  1071. match = AMnames[k];
  1072. mk = k;
  1073. i = match.length;
  1074. }
  1075. more = k<AMnames.length && str.slice(0,AMnames[k].length)>=AMnames[k];
  1076. }
  1077. AMpreviousSymbol=AMcurrentSymbol;
  1078. if (match!=""){
  1079. AMcurrentSymbol=AMsymbols[mk].ttype;
  1080. return AMsymbols[mk];
  1081. }
  1082. // if str[0] is a digit or - return maxsubstring of digits.digits
  1083. AMcurrentSymbol=CONST;
  1084. k = 1;
  1085. st = str.slice(0,1);
  1086. var integ = true;
  1087. while ("0"<=st && st<="9" && k<=str.length) {
  1088. st = str.slice(k,k+1);
  1089. k++;
  1090. }
  1091. if (st == decimalsign) {
  1092. st = str.slice(k,k+1);
  1093. if ("0"<=st && st<="9") {
  1094. integ = false;
  1095. k++;
  1096. while ("0"<=st && st<="9" && k<=str.length) {
  1097. st = str.slice(k,k+1);
  1098. k++;
  1099. }
  1100. }
  1101. }
  1102. if ((integ && k>1) || k>2) {
  1103. st = str.slice(0,k-1);
  1104. tagst = "mn";
  1105. } else {
  1106. k = 2;
  1107. st = str.slice(0,1); //take 1 character
  1108. tagst = (("A">st || st>"Z") && ("a">st || st>"z")?"mo":"mi");
  1109. }
  1110. if (st=="-" && AMpreviousSymbol==INFIX) {
  1111. AMcurrentSymbol = INFIX; //trick "/" into recognizing "-" on second parse
  1112. return {input:st, tag:tagst, output:st, ttype:UNARY, func:true, val:true};
  1113. }
  1114. return {input:st, tag:tagst, output:st, ttype:CONST, val:true};
  1115. }
  1116. function AMremoveBrackets(node) {
  1117. var st;
  1118. if (node.nodeName=="mrow") {
  1119. st = node.firstChild.firstChild.nodeValue;
  1120. if (st=="(" || st=="[" || st=="{") node.removeChild(node.firstChild);
  1121. }
  1122. if (node.nodeName=="mrow") {
  1123. st = node.lastChild.firstChild.nodeValue;
  1124. if (st==")" || st=="]" || st=="}") node.removeChild(node.lastChild);
  1125. }
  1126. }
  1127. //TeX conversion version
  1128. function AMTremoveBrackets(node) {
  1129. var st;
  1130. if (node.charAt(0)=='{' && node.charAt(node.length-1)=='}') {
  1131. st = node.charAt(1);
  1132. if (st=="(" || st=="[") node = '{'+node.substr(2);
  1133. st = node.substr(1,6);
  1134. if (st=="\\left(" || st=="\\left[" || st=="\\left{") node = '{'+node.substr(7);
  1135. st = node.substr(1,12);
  1136. if (st=="\\left\\lbrace" || st=="\\left\\langle") node = '{'+node.substr(13);
  1137. st = node.charAt(node.length-2);
  1138. if (st==")" || st=="]") node = node.substr(0,node.length-8)+'}';
  1139. st = node.substr(node.length-8,7)
  1140. if (st=="\\rbrace" || st=="\\rangle") node = node.substr(0,node.length-14) + '}';
  1141. }
  1142. return node;
  1143. }
  1144. /*Parsing ASCII math expressions with the following grammar
  1145. v ::= [A-Za-z] | greek letters | numbers | other constant symbols
  1146. u ::= sqrt | text | bb | other unary symbols for font commands
  1147. b ::= frac | root | stackrel binary symbols
  1148. l ::= ( | [ | { | (: | {: left brackets
  1149. r ::= ) | ] | } | :) | :} right brackets
  1150. S ::= v | lEr | uS | bSS Simple expression
  1151. I ::= S_S | S^S | S_S^S | S Intermediate expression
  1152. E ::= IE | I/I Expression
  1153. Each terminal symbol is translated into a corresponding mathml node.*/
  1154. var AMnestingDepth,AMpreviousSymbol,AMcurrentSymbol;
  1155. function AMTgetTeXsymbol(symb) {
  1156. if (typeof symb.val == "boolean" && symb.val) {
  1157. pre = '';
  1158. } else {
  1159. pre = '\\';
  1160. }
  1161. if (symb.tex==null) {
  1162. return (pre+symb.input);
  1163. } else {
  1164. return (pre+symb.tex);
  1165. }
  1166. }
  1167. function AMTgetTeXbracket(symb) {
  1168. if (symb.tex==null) {
  1169. return (symb.input);
  1170. } else {
  1171. return ('\\'+symb.tex);
  1172. }
  1173. }
  1174. function AMTparseSexpr(str) { //parses str and returns [node,tailstr]
  1175. var symbol, node, result, i, st,// rightvert = false,
  1176. newFrag = '';
  1177. str = AMremoveCharsAndBlanks(str,0);
  1178. symbol = AMgetSymbol(str); //either a token or a bracket or empty
  1179. if (symbol == null || symbol.ttype == RIGHTBRACKET && AMnestingDepth > 0) {
  1180. return [null,str];
  1181. }
  1182. if (symbol.ttype == DEFINITION) {
  1183. str = symbol.output+AMremoveCharsAndBlanks(str,symbol.input.length);
  1184. symbol = AMgetSymbol(str);
  1185. }
  1186. switch (symbol.ttype) {
  1187. case UNDEROVER:
  1188. case CONST:
  1189. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1190. var texsymbol = AMTgetTeXsymbol(symbol);
  1191. if (texsymbol.charAt(0)=="\\" || symbol.tag=="mo") return [texsymbol,str];
  1192. else return ['{'+texsymbol+'}',str];
  1193. case LEFTBRACKET: //read (expr+)
  1194. AMnestingDepth++;
  1195. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1196. result = AMTparseExpr(str,true);
  1197. AMnestingDepth--;
  1198. if (typeof symbol.invisible == "boolean" && symbol.invisible)
  1199. node = '{\\left.'+result[0]+'}';
  1200. else {
  1201. node = '{\\left'+AMTgetTeXbracket(symbol) + result[0]+'}';
  1202. }
  1203. return [node,result[1]];
  1204. case TEXT:
  1205. if (symbol!=AMquote) str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1206. if (str.charAt(0)=="{") i=str.indexOf("}");
  1207. else if (str.charAt(0)=="(") i=str.indexOf(")");
  1208. else if (str.charAt(0)=="[") i=str.indexOf("]");
  1209. else if (symbol==AMquote) i=str.slice(1).indexOf("\"")+1;
  1210. else i = 0;
  1211. if (i==-1) i = str.length;
  1212. st = str.slice(1,i);
  1213. if (st.charAt(0) == " ") {
  1214. newFrag = '\\ ';
  1215. }
  1216. newFrag += '\\text{'+st+'}';
  1217. if (st.charAt(st.length-1) == " ") {
  1218. newFrag += '\\ ';
  1219. }
  1220. str = AMremoveCharsAndBlanks(str,i+1);
  1221. return [newFrag,str];
  1222. case UNARY:
  1223. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1224. result = AMTparseSexpr(str);
  1225. if (result[0]==null) return ['{'+AMTgetTeXsymbol(symbol)+'}',str];
  1226. if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
  1227. st = str.charAt(0);
  1228. if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
  1229. return ['{'+AMTgetTeXsymbol(symbol)+'}',str];
  1230. } else {
  1231. node = '{'+AMTgetTeXsymbol(symbol)+'{'+result[0]+'}}';
  1232. return [node,result[1]];
  1233. }
  1234. }
  1235. result[0] = AMTremoveBrackets(result[0]);
  1236. if (symbol.input == "sqrt") { // sqrt
  1237. return ['\\sqrt{'+result[0]+'}',result[1]];
  1238. } else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
  1239. return ['{'+AMTgetTeXsymbol(symbol)+'{'+result[0]+'}}',result[1]];
  1240. } else { // font change command
  1241. return ['{'+AMTgetTeXsymbol(symbol)+'{'+result[0]+'}}',result[1]];
  1242. }
  1243. case BINARY:
  1244. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1245. result = AMTparseSexpr(str);
  1246. if (result[0]==null) return ['{'+AMTgetTeXsymbol(symbol)+'}',str];
  1247. result[0] = AMTremoveBrackets(result[0]);
  1248. var result2 = AMTparseSexpr(result[1]);
  1249. if (result2[0]==null) return ['{'+AMTgetTeXsymbol(symbol)+'}',str];
  1250. result2[0] = AMTremoveBrackets(result2[0]);
  1251. if (symbol.input=="density") {
  1252. newFrag = '{\\density{'+result[0]+'}{'+result2[0]+'}}';
  1253. newFrag = newFrag.replace(/{{{/g,"{");
  1254. newFrag = newFrag.replace(/}}}/g,"}");
  1255. }
  1256. if (symbol.input=="root") {
  1257. newFrag = '{\\sqrt['+result[0]+']{'+result2[0]+'}}';
  1258. }
  1259. if (symbol.input=="stackrel") {
  1260. newFrag = '{'+AMTgetTeXsymbol(symbol)+'{'+result[0]+'}{'+result2[0]+'}}';
  1261. }
  1262. if (symbol.input=="frac") {
  1263. newFrag = '{\\frac{'+result[0]+'}{'+result2[0]+'}}';
  1264. }
  1265. return [newFrag,result2[1]];
  1266. case INFIX:
  1267. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1268. return [symbol.output,str];
  1269. case SPACE:
  1270. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1271. return ['{\\quad\\text{'+symbol.input+'}\\quad}',str];
  1272. case LEFTRIGHT:
  1273. // if (rightvert) return [null,str]; else rightvert = true;
  1274. AMnestingDepth++;
  1275. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1276. result = AMTparseExpr(str,false);
  1277. AMnestingDepth--;
  1278. var st = "";
  1279. st = result[0].charAt(result[0].length -1);
  1280. //alert(result[0].lastChild+"***"+st);
  1281. if (st == "|") { // its an absolute value subterm
  1282. node = '{\\left|'+result[0]+'}';
  1283. return [node,result[1]];
  1284. } else { // the "|" is a \mid
  1285. node = '{\\mid}';
  1286. return [node,str];
  1287. }
  1288. default:
  1289. //alert("default");
  1290. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1291. return ['{'+AMTgetTeXsymbol(symbol)+'}',str];
  1292. }
  1293. }
  1294. function AMTparseIexpr(str) {
  1295. var symbol, sym1, sym2, node, result, underover;
  1296. str = AMremoveCharsAndBlanks(str,0);
  1297. sym1 = AMgetSymbol(str);
  1298. result = AMTparseSexpr(str);
  1299. node = result[0];
  1300. str = result[1];
  1301. symbol = AMgetSymbol(str);
  1302. if (symbol.ttype == INFIX && symbol.input != "/") {
  1303. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1304. // if (symbol.input == "/") result = AMTparseIexpr(str); else
  1305. result = AMTparseSexpr(str);
  1306. if (result[0] == null) // show box in place of missing argument
  1307. result[0] = '{}';
  1308. else result[0] = AMTremoveBrackets(result[0]);
  1309. str = result[1];
  1310. // if (symbol.input == "/") AMTremoveBrackets(node);
  1311. if (symbol.input == "_") {
  1312. sym2 = AMgetSymbol(str);
  1313. underover = (sym1.ttype == UNDEROVER);
  1314. if (sym2.input == "^") {
  1315. str = AMremoveCharsAndBlanks(str,sym2.input.length);
  1316. var res2 = AMTparseSexpr(str);
  1317. res2[0] = AMTremoveBrackets(res2[0]);
  1318. str = res2[1];
  1319. node = '{' + node;
  1320. node += '_{'+result[0]+'}';
  1321. node += '^{'+res2[0]+'}';
  1322. node += '}';
  1323. } else {
  1324. node += '_{'+result[0]+'}';
  1325. }
  1326. } else { //must be ^
  1327. node = '{'+node+'}^{'+result[0]+'}';
  1328. }
  1329. }
  1330. return [node,str];
  1331. }
  1332. function AMTparseExpr(str,rightbracket) {
  1333. var symbol, node, result, i, nodeList = [],
  1334. newFrag = '';
  1335. var addedright = false;
  1336. do {
  1337. str = AMremoveCharsAndBlanks(str,0);
  1338. result = AMTparseIexpr(str);
  1339. node = result[0];
  1340. str = result[1];
  1341. symbol = AMgetSymbol(str);
  1342. if (symbol.ttype == INFIX && symbol.input == "/") {
  1343. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1344. result = AMTparseIexpr(str);
  1345. if (result[0] == null) // show box in place of missing argument
  1346. result[0] = '{}';
  1347. else result[0] = AMTremoveBrackets(result[0]);
  1348. str = result[1];
  1349. node = AMTremoveBrackets(node);
  1350. node = '\\frac' + '{'+ node + '}';
  1351. node += '{'+result[0]+'}';
  1352. newFrag += node;
  1353. symbol = AMgetSymbol(str);
  1354. } else if (node!=undefined) newFrag += node;
  1355. } while ((symbol.ttype != RIGHTBRACKET &&
  1356. (symbol.ttype != LEFTRIGHT || rightbracket)
  1357. || AMnestingDepth == 0) && symbol!=null && symbol.output!="");
  1358. if (symbol.ttype == RIGHTBRACKET || symbol.ttype == LEFTRIGHT) {
  1359. // if (AMnestingDepth > 0) AMnestingDepth--;
  1360. var len = newFrag.length;
  1361. if (len>2 && newFrag.charAt(0)=='{' && newFrag.indexOf(',')>0) { //could be matrix (total rewrite from .js)
  1362. var right = newFrag.charAt(len - 2);
  1363. if (right==')' || right==']') {
  1364. var left = newFrag.charAt(6);
  1365. if ((left=='(' && right==')' && symbol.output != '}') || (left=='[' && right==']')) {
  1366. //var mxout = '\\matrix{';
  1367. var mxout = '\\begin{array}{cc}';
  1368. var pos = new Array(); //position of commas
  1369. pos.push(0);
  1370. var matrix = true;
  1371. var mxnestingd = 0;
  1372. for (i=1; i<len-1; i++) {
  1373. if (newFrag.charAt(i)==left) mxnestingd++;
  1374. if (newFrag.charAt(i)==right) {
  1375. mxnestingd--;
  1376. if (mxnestingd==0 && newFrag.charAt(i+2)==',' && newFrag.charAt(i+3)=='{') pos.push(i+2);
  1377. }
  1378. }
  1379. pos.push(len);
  1380. var lastmxsubcnt = -1;
  1381. if (mxnestingd==0 && pos.length>0) {
  1382. for (i=0;i<pos.length-1;i++) {
  1383. if (i>0) mxout += '\\\\';
  1384. if (i==0) {
  1385. var subarr = newFrag.substr(pos[i]+7,pos[i+1]-pos[i]-15).split(',');
  1386. } else {
  1387. var subarr = newFrag.substr(pos[i]+8,pos[i+1]-pos[i]-16).split(',');
  1388. }
  1389. if (lastmxsubcnt>0 && subarr.length!=lastmxsubcnt) {
  1390. matrix = false;
  1391. } else if (lastmxsubcnt==-1) {
  1392. lastmxsubcnt=subarr.length;
  1393. }
  1394. mxout += subarr.join('&');
  1395. }
  1396. }
  1397. //mxout += '}';
  1398. mxout += '\\end{array}';
  1399. if (matrix) { newFrag = mxout;}
  1400. }
  1401. }
  1402. }
  1403. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1404. if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
  1405. node = '\\right'+AMTgetTeXbracket(symbol); //createMmlNode("mo",document.createTextNode(symbol.output));
  1406. newFrag += node;
  1407. addedright = true;
  1408. } else {
  1409. newFrag += '\\right.';
  1410. addedright = true;
  1411. }
  1412. }
  1413. if(AMnestingDepth>0 && !addedright) {
  1414. newFrag += '\\right.'; //adjust for non-matching left brackets
  1415. //todo: adjust for non-matching right brackets
  1416. }
  1417. return [newFrag,str];
  1418. }
  1419. function AMTparseAMtoTeX(str) {
  1420. //DLMOD to remove &nbsp;, which editor adds on multiple spaces
  1421. AMnestingDepth = 0;
  1422. str = str.replace(/&nbsp;/g,"");
  1423. str = str.replace(/&gt;/g,">");
  1424. str = str.replace(/&lt;/g,"<");
  1425. str = str.replace(/ /g," ");
  1426. return AMTparseExpr(str.replace(/^\s+/g,""),false)[0];
  1427. }
  1428. function AMTparseMath(str,istex) {
  1429. if (istex) {
  1430. var texstring = str;
  1431. } else {
  1432. var texstring = AMTparseAMtoTeX(str);
  1433. }
  1434. //alert(texstring);
  1435. if (mathcolor!="") {
  1436. if (AMTcgiloc.match(/mathtex/)) {
  1437. texstring = "\\gammacorrection{1.4}\\usepackage{color}\\color\{" + mathcolor + "\}" + texstring;
  1438. } else if (AMTcgiloc.match(/mimetex/)) {
  1439. texstring = "\\" + mathcolor + texstring;
  1440. } else if (AMTcgiloc.match(/.latex/)) {
  1441. texstring = texstring = "\\color\{" + mathcolor + "\}" + texstring;
  1442. }
  1443. }
  1444. if (displaystyle) {
  1445. texstring = "\\displaystyle" + texstring;
  1446. } else {
  1447. texstring = "\\textstyle" + texstring;
  1448. }
  1449. if (AMTcgiloc.match(/google/)) {
  1450. var tclr = mathcolor;
  1451. if (tclr!="") {
  1452. if(IsColorName.test(tclr.toLowerCase())) {
  1453. tclr=LaTeXColor[tclr.toLowerCase()];
  1454. }
  1455. } else {
  1456. tclr = "000000";
  1457. }
  1458. var bclr = "FFFFFF00";
  1459. if (texstring.match(/colorbox/)) {
  1460. bclr = texstring.match(/\{\s*([#\w]+)\s*\}/); //get's color from beginning of str
  1461. texstring = texstring.replace(/\{\s*[#\w]+\s*\}/,"");
  1462. texstring = texstring.replace(/\\colorbox/g,"");
  1463. if(bclr!=null) {
  1464. if(IsColorName.test(bclr[1].toLowerCase())) {
  1465. bclr=LaTeXColor[bclr[1].toLowerCase()];
  1466. bclr=bclr.replace(/\#/,"");
  1467. } else {
  1468. bclr=bclr[1]; // no checking for valid color!!
  1469. bclr=bclr.replace(/\#/,"");
  1470. }
  1471. }
  1472. }
  1473. if (texstring.match(/textcolor/)) {
  1474. tclr = texstring.match(/\{\s*([#\w]+)\s*\}/); //get's color from beginning of str
  1475. texstring = texstring.replace(/\{\s*[#\w]+\s*\}/,"");
  1476. texstring = texstring.replace(/\\textcolor/g,"");
  1477. if(tclr!=null) {
  1478. if(IsColorName.test(tclr[1].toLowerCase())) {
  1479. tclr=LaTeXColor[tclr[1].toLowerCase()];
  1480. } else {
  1481. tclr=tclr[1]; // no checking for valid color!!
  1482. }
  1483. }
  1484. }
  1485. tclr=tclr.replace(/\#/,"");
  1486. }
  1487. var node = createElementXHTML("img");
  1488. if (typeof encodeURIComponent == "function") {
  1489. texstring = encodeURIComponent(texstring);
  1490. } else {
  1491. texstring = escape(texstring);
  1492. }
  1493. if (AMTcgiloc.match(/google/)) {
  1494. texstring = texstring + "&chf=bg,s," + bclr + "&chco=" + tclr;
  1495. }
  1496. if (AMTcgiloc.indexOf('?') == -1) {
  1497. AMTcgiloc = AMTcgiloc + '?';
  1498. }
  1499. node.src = AMTcgiloc + texstring;
  1500. node.style.verticalAlign = "middle";
  1501. if (showasciiformulaonhover) //fixed by djhsu so newline
  1502. node.setAttribute("title",str.replace(/\s+/g," "));//does not show in Gecko
  1503. return node;
  1504. }
  1505. function AMparseSexpr(str) { //parses str and returns [node,tailstr]
  1506. var symbol, node, result, i, st,// rightvert = false,
  1507. newFrag = document.createDocumentFragment();
  1508. str = AMremoveCharsAndBlanks(str,0);
  1509. symbol = AMgetSymbol(str); //either a token or a bracket or empty
  1510. if (symbol == null || symbol.ttype == RIGHTBRACKET && AMnestingDepth > 0) {
  1511. return [null,str];
  1512. }
  1513. if (symbol.ttype == DEFINITION) {
  1514. str = symbol.output+AMremoveCharsAndBlanks(str,symbol.input.length);
  1515. symbol = AMgetSymbol(str);
  1516. }
  1517. switch (symbol.ttype) { case UNDEROVER:
  1518. case CONST:
  1519. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1520. return [createMmlNode(symbol.tag, //its a constant
  1521. document.createTextNode(symbol.output)),str];
  1522. case LEFTBRACKET: //read (expr+)
  1523. AMnestingDepth++;
  1524. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1525. result = AMparseExpr(str,true);
  1526. AMnestingDepth--;
  1527. if (typeof symbol.invisible == "boolean" && symbol.invisible)
  1528. node = createMmlNode("mrow",result[0]);
  1529. else {
  1530. node = createMmlNode("mo",document.createTextNode(symbol.output));
  1531. node = createMmlNode("mrow",node);
  1532. node.appendChild(result[0]);
  1533. }
  1534. return [node,result[1]];
  1535. case TEXT:
  1536. if (symbol!=AMquote) str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1537. if (str.charAt(0)=="{") i=str.indexOf("}");
  1538. else if (str.charAt(0)=="(") i=str.indexOf(")");
  1539. else if (str.charAt(0)=="[") i=str.indexOf("]");
  1540. else if (symbol==AMquote) i=str.slice(1).indexOf("\"")+1;
  1541. else i = 0;
  1542. if (i==-1) i = str.length;
  1543. st = str.slice(1,i);
  1544. if (st.charAt(0) == " ") {
  1545. node = createMmlNode("mspace");
  1546. node.setAttribute("width","1ex");
  1547. newFrag.appendChild(node);
  1548. }
  1549. newFrag.appendChild(
  1550. createMmlNode(symbol.tag,document.createTextNode(st)));
  1551. if (st.charAt(st.length-1) == " ") {
  1552. node = createMmlNode("mspace");
  1553. node.setAttribute("width","1ex");
  1554. newFrag.appendChild(node);
  1555. }
  1556. str = AMremoveCharsAndBlanks(str,i+1);
  1557. return [createMmlNode("mrow",newFrag),str];
  1558. case UNARY:
  1559. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1560. result = AMparseSexpr(str);
  1561. if (result[0]==null) return [createMmlNode(symbol.tag,
  1562. document.createTextNode(symbol.output)),str];
  1563. if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
  1564. st = str.charAt(0);
  1565. if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
  1566. return [createMmlNode(symbol.tag,
  1567. document.createTextNode(symbol.output)),str];
  1568. } else {
  1569. node = createMmlNode("mrow",
  1570. createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
  1571. node.appendChild(result[0]);
  1572. return [node,result[1]];
  1573. }
  1574. }
  1575. AMremoveBrackets(result[0]);
  1576. if (symbol.input == "sqrt") { // sqrt
  1577. return [createMmlNode(symbol.tag,result[0]),result[1]];
  1578. } else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
  1579. node = createMmlNode(symbol.tag,result[0]);
  1580. node.appendChild(createMmlNode("mo",document.createTextNode(symbol.output)));
  1581. return [node,result[1]];
  1582. } else { // font change command
  1583. if (!isIE && typeof symbol.codes != "undefined") {
  1584. for (i=0; i<result[0].childNodes.length; i++)
  1585. if (result[0].childNodes[i].nodeName=="mi" || result[0].nodeName=="mi") {
  1586. st = (result[0].nodeName=="mi"?result[0].firstChild.nodeValue:
  1587. result[0].childNodes[i].firstChild.nodeValue);
  1588. var newst = [];
  1589. for (var j=0; j<st.length; j++)
  1590. if (st.charCodeAt(j)>64 && st.charCodeAt(j)<91) newst = newst +
  1591. symbol.codes[st.charCodeAt(j)-65];
  1592. else newst = newst + st.charAt(j);
  1593. if (result[0].nodeName=="mi")
  1594. result[0]=createMmlNode("mo").
  1595. appendChild(document.createTextNode(newst));
  1596. else result[0].replaceChild(createMmlNode("mo").
  1597. appendChild(document.createTextNode(newst)),
  1598. result[0].childNodes[i]);
  1599. }
  1600. }
  1601. node = createMmlNode(symbol.tag,result[0]);
  1602. node.setAttribute(symbol.atname,symbol.atval);
  1603. return [node,result[1]];
  1604. }
  1605. case BINARY:
  1606. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1607. result = AMparseSexpr(str);
  1608. if (result[0]==null) return [createMmlNode("mo",
  1609. document.createTextNode(symbol.input)),str];
  1610. AMremoveBrackets(result[0]);
  1611. var result2 = AMparseSexpr(result[1]);
  1612. if (result2[0]==null) return [createMmlNode("mo",
  1613. document.createTextNode(symbol.input)),str];
  1614. AMremoveBrackets(result2[0]);
  1615. if (symbol.input=="density") {
  1616. var tclrf = str.match(/\{\s*([#\w]+)\s*\}/); //get's size from beginning of str
  1617. str = str.replace(/\{\s*[#\w]+\s*\}/,"");
  1618. if(tclrf!=null) {
  1619. if(tclrf[1]>1000) {
  1620. tclrf=1000+'%';
  1621. } else {
  1622. tclrf=tclrf[1]+'%';
  1623. }
  1624. node = createMmlNode("mstyle");
  1625. node.setAttribute(symbol.atval,tclrf);
  1626. node.appendChild(result2[0]);
  1627. return [node,result2[1],symbol.tag];
  1628. }
  1629. }
  1630. if (symbol.input=="root" || symbol.input=="stackrel")
  1631. newFrag.appendChild(result2[0]);
  1632. newFrag.appendChild(result[0]);
  1633. if (symbol.input=="frac") newFrag.appendChild(result2[0]);
  1634. return [createMmlNode(symbol.tag,newFrag),result2[1]];
  1635. case INFIX:
  1636. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1637. return [createMmlNode("mo",document.createTextNode(symbol.output)),str];
  1638. case SPACE:
  1639. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1640. node = createMmlNode("mspace");
  1641. node.setAttribute("width","1ex");
  1642. newFrag.appendChild(node);
  1643. newFrag.appendChild(
  1644. createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
  1645. node = createMmlNode("mspace");
  1646. node.setAttribute("width","1ex");
  1647. newFrag.appendChild(node);
  1648. return [createMmlNode("mrow",newFrag),str];
  1649. case LEFTRIGHT:
  1650. // if (rightvert) return [null,str]; else rightvert = true;
  1651. AMnestingDepth++;
  1652. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1653. result = AMparseExpr(str,false);
  1654. AMnestingDepth--;
  1655. var st = "";
  1656. if (result[0].lastChild!=null)
  1657. st = result[0].lastChild.firstChild.nodeValue;
  1658. if (st == "|") { // its an absolute value subterm
  1659. node = createMmlNode("mo",document.createTextNode(symbol.output));
  1660. node = createMmlNode("mrow",node);
  1661. node.appendChild(result[0]);
  1662. return [node,result[1]];
  1663. } else { // the "|" is a \mid so use unicode 2223 (divides) for spacing
  1664. node = createMmlNode("mo",document.createTextNode("\u2223"));
  1665. node = createMmlNode("mrow",node);
  1666. return [node,str];
  1667. }
  1668. default:
  1669. //alert("default");
  1670. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1671. return [createMmlNode(symbol.tag, //its a constant
  1672. document.createTextNode(symbol.output)),str];
  1673. }
  1674. }
  1675. function AMparseIexpr(str) {
  1676. var symbol, sym1, sym2, node, result, underover;
  1677. str = AMremoveCharsAndBlanks(str,0);
  1678. sym1 = AMgetSymbol(str);
  1679. result = AMparseSexpr(str);
  1680. node = result[0];
  1681. str = result[1];
  1682. symbol = AMgetSymbol(str);
  1683. if (symbol.ttype == INFIX && symbol.input != "/") {
  1684. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1685. // if (symbol.input == "/") result = AMparseIexpr(str); else ...
  1686. result = AMparseSexpr(str);
  1687. if (result[0] == null) // show box in place of missing argument
  1688. result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
  1689. else AMremoveBrackets(result[0]);
  1690. str = result[1];
  1691. // if (symbol.input == "/") AMremoveBrackets(node);
  1692. if (symbol.input == "_") {
  1693. sym2 = AMgetSymbol(str);
  1694. underover = (sym1.ttype == UNDEROVER);
  1695. if (sym2.input == "^") {
  1696. str = AMremoveCharsAndBlanks(str,sym2.input.length);
  1697. var res2 = AMparseSexpr(str);
  1698. AMremoveBrackets(res2[0]);
  1699. str = res2[1];
  1700. node = createMmlNode((underover?"munderover":"msubsup"),node);
  1701. node.appendChild(result[0]);
  1702. node.appendChild(res2[0]);
  1703. node = createMmlNode("mrow",node); // so sum does not stretch
  1704. } else {
  1705. node = createMmlNode((underover?"munder":"msub"),node);
  1706. node.appendChild(result[0]);
  1707. }
  1708. } else {
  1709. node = createMmlNode(symbol.tag,node);
  1710. node.appendChild(result[0]);
  1711. }
  1712. }
  1713. return [node,str];
  1714. }
  1715. function AMparseExpr(str,rightbracket) {
  1716. var symbol, node, result, i, nodeList = [],
  1717. newFrag = document.createDocumentFragment();
  1718. do {
  1719. str = AMremoveCharsAndBlanks(str,0);
  1720. result = AMparseIexpr(str);
  1721. node = result[0];
  1722. str = result[1];
  1723. symbol = AMgetSymbol(str);
  1724. if (symbol.ttype == INFIX && symbol.input == "/") {
  1725. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1726. result = AMparseIexpr(str);
  1727. if (result[0] == null) // show box in place of missing argument
  1728. result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
  1729. else AMremoveBrackets(result[0]);
  1730. str = result[1];
  1731. AMremoveBrackets(node);
  1732. node = createMmlNode(symbol.tag,node);
  1733. node.appendChild(result[0]);
  1734. newFrag.appendChild(node);
  1735. symbol = AMgetSymbol(str);
  1736. }
  1737. else if (node!=undefined) newFrag.appendChild(node);
  1738. } while ((symbol.ttype != RIGHTBRACKET &&
  1739. (symbol.ttype != LEFTRIGHT || rightbracket)
  1740. || AMnestingDepth == 0) && symbol!=null && symbol.output!="");
  1741. if (symbol.ttype == RIGHTBRACKET || symbol.ttype == LEFTRIGHT) {
  1742. // if (AMnestingDepth > 0) AMnestingDepth--;
  1743. var len = newFrag.childNodes.length;
  1744. if (len>0 && newFrag.childNodes[len-1].nodeName == "mrow" && len>1 &&
  1745. newFrag.childNodes[len-2].nodeName == "mo" &&
  1746. newFrag.childNodes[len-2].firstChild.nodeValue == ",") { //matrix
  1747. var right = newFrag.childNodes[len-1].lastChild.firstChild.nodeValue;
  1748. if (right==")" || right=="]") {
  1749. var left = newFrag.childNodes[len-1].firstChild.firstChild.nodeValue;
  1750. if (left=="(" && right==")" && symbol.output != "}" ||
  1751. left=="[" && right=="]") {
  1752. var pos = []; // positions of commas
  1753. var matrix = true;
  1754. var m = newFrag.childNodes.length;
  1755. for (i=0; matrix && i<m; i=i+2) {
  1756. pos[i] = [];
  1757. node = newFrag.childNodes[i];
  1758. if (matrix) matrix = node.nodeName=="mrow" &&
  1759. (i==m-1 || node.nextSibling.nodeName=="mo" &&
  1760. node.nextSibling.firstChild.nodeValue==",")&&
  1761. node.firstChild.firstChild.nodeValue==left &&
  1762. node.lastChild.firstChild.nodeValue==right;
  1763. if (matrix)
  1764. for (var j=0; j<node.childNodes.length; j++)
  1765. if (node.childNodes[j].firstChild.nodeValue==",")
  1766. pos[i][pos[i].length]=j;
  1767. if (matrix && i>1) matrix = pos[i].length == pos[i-2].length;
  1768. }
  1769. if (matrix) {
  1770. var row, frag, n, k, table = document.createDocumentFragment();
  1771. for (i=0; i<m; i=i+2) {
  1772. row = document.createDocumentFragment();
  1773. frag = document.createDocumentFragment();
  1774. node = newFrag.firstChild; // <mrow>(-,-,...,-,-)</mrow>
  1775. n = node.childNodes.length;
  1776. k = 0;
  1777. node.removeChild(node.firstChild); //remove (
  1778. for (j=1; j<n-1; j++) {
  1779. if (typeof pos[i][k] != "undefined" && j==pos[i][k]){
  1780. node.removeChild(node.firstChild); //remove ,
  1781. row.appendChild(createMmlNode("mtd",frag));
  1782. k++;
  1783. } else frag.appendChild(node.firstChild);
  1784. }
  1785. row.appendChild(createMmlNode("mtd",frag));
  1786. if (newFrag.childNodes.length>2) {
  1787. newFrag.removeChild(newFrag.firstChild); //remove <mrow>)</mrow>
  1788. newFrag.removeChild(newFrag.firstChild); //remove <mo>,</mo>
  1789. }
  1790. table.appendChild(createMmlNode("mtr",row));
  1791. }
  1792. node = createMmlNode("mtable",table);
  1793. if (typeof symbol.invisible == "boolean" && symbol.invisible) node.setAttribute("columnalign","left");
  1794. newFrag.replaceChild(node,newFrag.firstChild);
  1795. }
  1796. }
  1797. }
  1798. }
  1799. str = AMremoveCharsAndBlanks(str,symbol.input.length);
  1800. if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
  1801. node = createMmlNode("mo",document.createTextNode(symbol.output));
  1802. newFrag.appendChild(node);
  1803. }
  1804. }
  1805. return [newFrag,str];
  1806. }
  1807. function parseMath(str,latex) {
  1808. var frag, node;
  1809. AMnestingDepth = 0;
  1810. frag = latex ? LMparseExpr(str.replace(/^\s+/g,""),false,false)[0] : AMparseExpr(str.replace(/^\s+/g,""),false)[0];
  1811. node = createMmlNode("mstyle",frag);
  1812. node.setAttribute("mathcolor",mathcolor);
  1813. node.setAttribute("fontfamily",mathfontfamily);
  1814. node.setAttribute("mathsize",mathfontsize);
  1815. if (displaystyle) node.setAttribute("displaystyle","true");
  1816. node = createMmlNode("math",node);
  1817. if (showasciiformulaonhover) //fixed by djhsu so newline
  1818. node.setAttribute("title",str.replace(/\s+/g," "));//does not show in Gecko
  1819. return node;
  1820. }
  1821. function strarr2docFrag(arr, linebreaks, latex) {
  1822. var newFrag=document.createDocumentFragment();
  1823. var expr = false;
  1824. for (var i=0; i<arr.length; i++) {
  1825. if (expr && noMathML) newFrag.appendChild(AMTparseMath(arr[i],latex));
  1826. else if (expr && !noMathML) newFrag.appendChild(parseMath(arr[i],latex));
  1827. else {
  1828. var arri = (linebreaks ? arr[i].split("\n\n") : [arr[i]]);
  1829. newFrag.appendChild(createElementXHTML("span").
  1830. appendChild(document.createTextNode(arri[0])));
  1831. for (var j=1; j<arri.length; j++) {
  1832. newFrag.appendChild(createElementXHTML("p"));
  1833. newFrag.appendChild(createElementXHTML("span").
  1834. appendChild(document.createTextNode(arri[j])));
  1835. }
  1836. }
  1837. expr = !expr;
  1838. }
  1839. return newFrag;
  1840. }
  1841. function AMautomathrec(str) {
  1842. //formula is a space (or start of str) followed by a maximal sequence of *two* or more tokens, possibly separated by runs of digits and/or space.
  1843. //tokens are single letters (except a, A, I) and ASCIIMathML tokens
  1844. var texcommand = "\\\\[a-zA-Z]+|\\\\\\s|";
  1845. var ambigAMtoken = "\\b(?:oo|lim|ln|int|oint|del|grad|aleph|prod|prop|sinh|cosh|tanh|cos|sec|pi|tt|fr|sf|sube|supe|sub|sup|det|mod|gcd|lcm|min|max|vec|ddot|ul|chi|eta|nu|mu)(?![a-z])|";
  1846. var englishAMtoken = "\\b(?:sum|ox|log|sin|tan|dim|hat|bar|dot)(?![a-z])|";
  1847. var secondenglishAMtoken = "|\\bI\\b|\\bin\\b|\\btext\\b"; // took if and or not out
  1848. var simpleAMtoken = "NN|ZZ|QQ|RR|CC|TT|AA|EE|sqrt|dx|dy|dz|dt|xx|vv|uu|nn|bb|cc|csc|cot|alpha|beta|delta|Delta|epsilon|gamma|Gamma|kappa|lambda|Lambda|omega|phi|Phi|Pi|psi|Psi|rho|sigma|Sigma|tau|theta|Theta|xi|Xi|zeta"; // uuu nnn?
  1849. var letter = "[a-zA-HJ-Z](?=(?:[^a-zA-Z]|$|"+ambigAMtoken+englishAMtoken+simpleAMtoken+"))|";
  1850. var token = letter+texcommand+"\\d+|[-()[\\]{}+=*&^_%\\\@/<>,\\|!:;'~]|\\.(?!(?:\x20|$))|"+ambigAMtoken+englishAMtoken+simpleAMtoken;
  1851. var re = new RegExp("(^|\\s)((("+token+")\\s?)(("+token+secondenglishAMtoken+")\\s?)+)([,.?]?(?=\\s|$))","g");
  1852. str = str.replace(re," `$2`$7");
  1853. var arr = str.split(AMdelimiter1);
  1854. var re1 = new RegExp("(^|\\s)([b-zB-HJ-Z+*<>]|"+texcommand+ambigAMtoken+simpleAMtoken+")(\\s|\\n|$)","g");
  1855. var re2 = new RegExp("(^|\\s)([a-z]|"+texcommand+ambigAMtoken+simpleAMtoken+")([,.])","g"); // removed |\d+ for now
  1856. for (i=0; i<arr.length; i++) //single nonenglish tokens
  1857. if (i%2==0) {
  1858. arr[i] = arr[i].replace(re1," `$2`$3");
  1859. arr[i] = arr[i].replace(re2," `$2`$3");
  1860. arr[i] = arr[i].replace(/([{}[\]])/,"`$1`");
  1861. }
  1862. str = arr.join(AMdelimiter1);
  1863. str = str.replace(/((^|\s)\([a-zA-Z]{2,}.*?)\)`/g,"$1`)"); //fix parentheses
  1864. str = str.replace(/`(\((a\s|in\s))(.*?[a-zA-Z]{2,}\))/g,"$1`$3"); //fix parentheses
  1865. str = str.replace(/\sin`/g,"` in");
  1866. str = str.replace(/`(\(\w\)[,.]?(\s|\n|$))/g,"$1`");
  1867. str = str.replace(/`([0-9.]+|e.g|i.e)`(\.?)/gi,"$1$2");
  1868. str = str.replace(/`([0-9.]+:)`/g,"$1");
  1869. return str;
  1870. }
  1871. function processNodeR(n, linebreaks,latex) {
  1872. var mtch, str, arr, frg, i;
  1873. if (n.childNodes.length == 0) {
  1874. if ((n.nodeType!=8 || linebreaks) && n.parentNode &&
  1875. n.parentNode.nodeName!="form" && n.parentNode.nodeName!="FORM" &&
  1876. n.parentNode.nodeName!="textarea" && n.parentNode.nodeName!="TEXTAREA" /*&&
  1877. n.parentNode.nodeName!="pre" && n.parentNode.nodeName!="PRE"*/) {
  1878. str = n.nodeValue;
  1879. if (!(str == null)) {
  1880. str = str.replace(/\r\n\r\n/g,"\n\n");
  1881. str = str.replace(/\x20+/g," ");
  1882. str = str.replace(/\s*\r\n/g," ");
  1883. if(latex) {
  1884. // DELIMITERS:
  1885. mtch = (str.indexOf("\$")==-1 ? false : true);
  1886. str = str.replace(/([^\\])\$/g,"$1 \$");
  1887. str = str.replace(/^\$/," \$"); // in case \$ at start of string
  1888. arr = str.split(" \$");
  1889. for (i=0; i<arr.length; i++)
  1890. arr[i]=arr[i].replace(/\\\$/g,"\$");
  1891. } else {
  1892. mtch = false;
  1893. str = str.replace(new RegExp(AMescape1, "g"),
  1894. function(){mtch = true; return "AMescape1"});
  1895. str = str.replace(/\\?end{?a?math}?/i,
  1896. function(){automathrecognize = false; mtch = true; return ""});
  1897. str = str.replace(/amath\b|\\begin{a?math}/i,
  1898. function(){automathrecognize = true; mtch = true; return ""});
  1899. arr = str.split(AMdelimiter1);
  1900. if (automathrecognize)
  1901. for (i=0; i<arr.length; i++)
  1902. if (i%2==0) arr[i] = AMautomathrec(arr[i]);
  1903. str = arr.join(AMdelimiter1);
  1904. arr = str.split(AMdelimiter1);
  1905. for (i=0; i<arr.length; i++) // this is a problem ************
  1906. arr[i]=arr[i].replace(/AMescape1/g,AMdelimiter1);
  1907. }
  1908. if (arr.length>1 || mtch) {
  1909. //if (!noMathML) {
  1910. frg = strarr2docFrag(arr,n.nodeType==8,latex);
  1911. var len = frg.childNodes.length;
  1912. n.parentNode.replaceChild(frg,n);
  1913. return len-1;
  1914. //} else return 0;
  1915. }
  1916. }
  1917. } else return 0;
  1918. } else if (n.nodeName!="math") {
  1919. for (i=0; i<n.childNodes.length; i++)
  1920. i += processNodeR(n.childNodes[i], linebreaks,latex);
  1921. }
  1922. return 0;
  1923. }
  1924. function AMprocessNode(n, linebreaks, spanclassAM) {
  1925. var frag,st;
  1926. if (spanclassAM!=null) {
  1927. frag = document.getElementsByTagName("span")
  1928. for (var i=0;i<frag.length;i++)
  1929. if (frag[i].className == "AM")
  1930. processNodeR(frag[i],linebreaks,false);
  1931. } else {
  1932. try {
  1933. st = n.innerHTML; // look for AMdelimiter on page
  1934. } catch(err) {}
  1935. //alert(st)
  1936. // Corrected by Ivan Tcholakov, 01-JUL-2010.
  1937. //if (st==null || /amath\b|\\begin{a?math}/i.test(st) ||
  1938. if (st!=null || /amath\b|\\begin{a?math}/i.test(st) ||
  1939. st.indexOf(AMdelimiter1+" ")!=-1 || st.slice(-1)==AMdelimiter1 ||
  1940. st.indexOf(AMdelimiter1+"<")!=-1 || st.indexOf(AMdelimiter1+"\n")!=-1) {
  1941. processNodeR(n,linebreaks,false);
  1942. }
  1943. }
  1944. /* if (isIE) { //needed to match size and font of formula to surrounding text
  1945. frag = document.getElementsByTagName('math');
  1946. for (var i=0;i<frag.length;i++) frag[i].update() //What is this?
  1947. }*/
  1948. }
  1949. /*
  1950. LaTeXMathML.js
  1951. ==============
  1952. Version 1.1, July 20, 2007 (c) modifications by Peter Jipsen
  1953. (changes: renamed global variables from AM... to LM... so that
  1954. LaTeXMathML and ASCIIMathML can be used simultaneously)
  1955. Previous header notice:
  1956. This file (Version 1.0), is due to Douglas Woodall, June 2006.
  1957. It contains JavaScript functions to convert (most simple) LaTeX
  1958. math notation to Presentation MathML. It was obtained by
  1959. downloading the file ASCIIMathML.js from
  1960. http://www1.chapman.edu/~jipsen/mathml/asciimathdownload/
  1961. and modifying it so that it carries out ONLY those conversions
  1962. that would be carried out in LaTeX. A description of the original
  1963. file, with examples, can be found at
  1964. www1.chapman.edu/~jipsen/mathml/asciimath.html
  1965. ASCIIMathML: Math on the web for everyone
  1966. Here is the header notice from the original file:
  1967. ASCIIMathML.js
  1968. ==============
  1969. This file contains JavaScript functions to convert ASCII math notation
  1970. to Presentation MathML. The conversion is done while the (X)HTML page
  1971. loads, and should work with Firefox/Mozilla/Netscape 7+ and Internet
  1972. Explorer 6+MathPlayer (http://www.dessci.com/en/products/mathplayer/).
  1973. Just add the next line to your (X)HTML page with this file in the same folder:
  1974. <script type="text/javascript" src="ASCIIMathML.js"></script>
  1975. This is a convenient and inexpensive solution for authoring MathML.
  1976. Version 1.4.7 Dec 15, 2005, (c) Peter Jipsen http://www.chapman.edu/~jipsen
  1977. Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
  1978. For changes see http://www.chapman.edu/~jipsen/mathml/asciimathchanges.txt
  1979. If you use it on a webpage, please send the URL to jipsen@chapman.edu
  1980. This program is free software; you can redistribute it and/or modify
  1981. it under the terms of the GNU Lesser General Public License as published by
  1982. the Free Software Foundation; either version 2.1 of the License, or (at
  1983. your option) any later version.
  1984. This program is distributed in the hope that it will be useful,
  1985. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1986. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  1987. General Public License (at http://www.gnu.org/license/lgpl.html)
  1988. for more details.
  1989. LaTeXMathML.js (ctd)
  1990. ==============
  1991. Content between $...$ and $$...$$ is converted by this part of the file
  1992. */
  1993. // all further global variables start with "LM"
  1994. // Commented out by DRW to prevent 1/2 turning into a 2-line fraction
  1995. // LMdiv = {input:"/", tag:"mfrac", output:"/", ttype:INFIX},
  1996. // Commented out by DRW so that " prints literally in equations
  1997. // LMquote = {input:"\"", tag:"mtext", output:"mbox", ttype:TEXT};
  1998. var LMcal = AMcal;
  1999. var LMfrk = AMfrk;
  2000. var LMbbb = AMbbb;
  2001. var LMsymbols = [
  2002. //Greek letters
  2003. {input:"\\alpha", tag:"mi", output:"\u03B1", ttype:CONST},
  2004. {input:"\\beta", tag:"mi", output:"\u03B2", ttype:CONST},
  2005. {input:"\\gamma", tag:"mi", output:"\u03B3", ttype:CONST},
  2006. {input:"\\delta", tag:"mi", output:"\u03B4", ttype:CONST},
  2007. {input:"\\epsilon", tag:"mi", output:"\u03B5", ttype:CONST},
  2008. {input:"\\varepsilon", tag:"mi", output:"\u025B", ttype:CONST},
  2009. {input:"\\zeta", tag:"mi", output:"\u03B6", ttype:CONST},
  2010. {input:"\\eta", tag:"mi", output:"\u03B7", ttype:CONST},
  2011. {input:"\\theta", tag:"mi", output:"\u03B8", ttype:CONST},
  2012. {input:"\\vartheta", tag:"mi", output:"\u03D1", ttype:CONST},
  2013. {input:"\\iota", tag:"mi", output:"\u03B9", ttype:CONST},
  2014. {input:"\\kappa", tag:"mi", output:"\u03BA", ttype:CONST},
  2015. {input:"\\lambda", tag:"mi", output:"\u03BB", ttype:CONST},
  2016. {input:"\\mu", tag:"mi", output:"\u03BC", ttype:CONST},
  2017. {input:"\\nu", tag:"mi", output:"\u03BD", ttype:CONST},
  2018. {input:"\\xi", tag:"mi", output:"\u03BE", ttype:CONST},
  2019. {input:"\\pi", tag:"mi", output:"\u03C0", ttype:CONST},
  2020. {input:"\\varpi", tag:"mi", output:"\u03D6", ttype:CONST},
  2021. {input:"\\rho", tag:"mi", output:"\u03C1", ttype:CONST},
  2022. {input:"\\varrho", tag:"mi", output:"\u03F1", ttype:CONST},
  2023. {input:"\\varsigma", tag:"mi", output:"\u03C2", ttype:CONST},
  2024. {input:"\\sigma", tag:"mi", output:"\u03C3", ttype:CONST},
  2025. {input:"\\tau", tag:"mi", output:"\u03C4", ttype:CONST},
  2026. {input:"\\upsilon", tag:"mi", output:"\u03C5", ttype:CONST},
  2027. {input:"\\phi", tag:"mi", output:"\u03C6", ttype:CONST},
  2028. {input:"\\varphi", tag:"mi", output:"\u03D5", ttype:CONST},
  2029. {input:"\\chi", tag:"mi", output:"\u03C7", ttype:CONST},
  2030. {input:"\\psi", tag:"mi", output:"\u03C8", ttype:CONST},
  2031. {input:"\\omega", tag:"mi", output:"\u03C9", ttype:CONST},
  2032. {input:"\\Gamma", tag:"mo", output:"\u0393", ttype:CONST},
  2033. {input:"\\Delta", tag:"mo", output:"\u0394", ttype:CONST},
  2034. {input:"\\Theta", tag:"mo", output:"\u0398", ttype:CONST},
  2035. {input:"\\Lambda", tag:"mo", output:"\u039B", ttype:CONST},
  2036. {input:"\\Xi", tag:"mo", output:"\u039E", ttype:CONST},
  2037. {input:"\\Pi", tag:"mo", output:"\u03A0", ttype:CONST},
  2038. {input:"\\Sigma", tag:"mo", output:"\u03A3", ttype:CONST},
  2039. {input:"\\Upsilon", tag:"mo", output:"\u03A5", ttype:CONST},
  2040. {input:"\\Phi", tag:"mo", output:"\u03A6", ttype:CONST},
  2041. {input:"\\Psi", tag:"mo", output:"\u03A8", ttype:CONST},
  2042. {input:"\\Omega", tag:"mo", output:"\u03A9", ttype:CONST},
  2043. //fractions
  2044. {input:"\\frac12", tag:"mo", output:"\u00BD", ttype:CONST},
  2045. {input:"\\frac14", tag:"mo", output:"\u00BC", ttype:CONST},
  2046. {input:"\\frac34", tag:"mo", output:"\u00BE", ttype:CONST},
  2047. {input:"\\frac13", tag:"mo", output:"\u2153", ttype:CONST},
  2048. {input:"\\frac23", tag:"mo", output:"\u2154", ttype:CONST},
  2049. {input:"\\frac15", tag:"mo", output:"\u2155", ttype:CONST},
  2050. {input:"\\frac25", tag:"mo", output:"\u2156", ttype:CONST},
  2051. {input:"\\frac35", tag:"mo", output:"\u2157", ttype:CONST},
  2052. {input:"\\frac45", tag:"mo", output:"\u2158", ttype:CONST},
  2053. {input:"\\frac16", tag:"mo", output:"\u2159", ttype:CONST},
  2054. {input:"\\frac56", tag:"mo", output:"\u215A", ttype:CONST},
  2055. {input:"\\frac18", tag:"mo", output:"\u215B", ttype:CONST},
  2056. {input:"\\frac38", tag:"mo", output:"\u215C", ttype:CONST},
  2057. {input:"\\frac58", tag:"mo", output:"\u215D", ttype:CONST},
  2058. {input:"\\frac78", tag:"mo", output:"\u215E", ttype:CONST},
  2059. //binary operation symbols
  2060. {input:"\\pm", tag:"mo", output:"\u00B1", ttype:CONST},
  2061. {input:"\\mp", tag:"mo", output:"\u2213", ttype:CONST},
  2062. {input:"\\triangleleft",tag:"mo", output:"\u22B2", ttype:CONST},
  2063. {input:"\\triangleright",tag:"mo",output:"\u22B3", ttype:CONST},
  2064. {input:"\\cdot", tag:"mo", output:"\u22C5", ttype:CONST},
  2065. {input:"\\star", tag:"mo", output:"\u22C6", ttype:CONST},
  2066. {input:"\\ast", tag:"mo", output:"\u002A", ttype:CONST},
  2067. {input:"\\times", tag:"mo", output:"\u00D7", ttype:CONST},
  2068. {input:"\\div", tag:"mo", output:"\u00F7", ttype:CONST},
  2069. {input:"\\circ", tag:"mo", output:"\u2218", ttype:CONST},
  2070. //{input:"\\bullet", tag:"mo", output:"\u2219", ttype:CONST},
  2071. {input:"\\bullet", tag:"mo", output:"\u2022", ttype:CONST},
  2072. {input:"\\oplus", tag:"mo", output:"\u2295", ttype:CONST},
  2073. {input:"\\ominus", tag:"mo", output:"\u2296", ttype:CONST},
  2074. {input:"\\otimes", tag:"mo", output:"\u2297", ttype:CONST},
  2075. {input:"\\bigcirc", tag:"mo", output:"\u25CB", ttype:CONST},
  2076. {input:"\\oslash", tag:"mo", output:"\u2298", ttype:CONST},
  2077. {input:"\\odot", tag:"mo", output:"\u2299", ttype:CONST},
  2078. {input:"\\land", tag:"mo", output:"\u2227", ttype:CONST},
  2079. {input:"\\wedge", tag:"mo", output:"\u2227", ttype:CONST},
  2080. {input:"\\lor", tag:"mo", output:"\u2228", ttype:CONST},
  2081. {input:"\\vee", tag:"mo", output:"\u2228", ttype:CONST},
  2082. {input:"\\cap", tag:"mo", output:"\u2229", ttype:CONST},
  2083. {input:"\\cup", tag:"mo", output:"\u222A", ttype:CONST},
  2084. {input:"\\sqcap", tag:"mo", output:"\u2293", ttype:CONST},
  2085. {input:"\\sqcup", tag:"mo", output:"\u2294", ttype:CONST},
  2086. {input:"\\uplus", tag:"mo", output:"\u228E", ttype:CONST},
  2087. {input:"\\amalg", tag:"mo", output:"\u2210", ttype:CONST},
  2088. {input:"\\bigtriangleup",tag:"mo",output:"\u25B3", ttype:CONST},
  2089. {input:"\\bigtriangledown",tag:"mo",output:"\u25BD", ttype:CONST},
  2090. {input:"\\dag", tag:"mo", output:"\u2020", ttype:CONST},
  2091. {input:"\\dagger", tag:"mo", output:"\u2020", ttype:CONST},
  2092. {input:"\\ddag", tag:"mo", output:"\u2021", ttype:CONST},
  2093. {input:"\\ddagger", tag:"mo", output:"\u2021", ttype:CONST},
  2094. {input:"\\lhd", tag:"mo", output:"\u22B2", ttype:CONST},
  2095. {input:"\\rhd", tag:"mo", output:"\u22B3", ttype:CONST},
  2096. {input:"\\unlhd", tag:"mo", output:"\u22B4", ttype:CONST},
  2097. {input:"\\unrhd", tag:"mo", output:"\u22B5", ttype:CONST},
  2098. //BIG Operators
  2099. {input:"\\sum", tag:"mo", output:"\u2211", ttype:UNDEROVER},
  2100. {input:"\\prod", tag:"mo", output:"\u220F", ttype:UNDEROVER},
  2101. {input:"\\bigcap", tag:"mo", output:"\u22C2", ttype:UNDEROVER},
  2102. {input:"\\bigcup", tag:"mo", output:"\u22C3", ttype:UNDEROVER},
  2103. {input:"\\bigwedge", tag:"mo", output:"\u22C0", ttype:UNDEROVER},
  2104. {input:"\\bigvee", tag:"mo", output:"\u22C1", ttype:UNDEROVER},
  2105. {input:"\\bigsqcap", tag:"mo", output:"\u2A05", ttype:UNDEROVER},
  2106. {input:"\\bigsqcup", tag:"mo", output:"\u2A06", ttype:UNDEROVER},
  2107. {input:"\\coprod", tag:"mo", output:"\u2210", ttype:UNDEROVER},
  2108. {input:"\\bigoplus", tag:"mo", output:"\u2A01", ttype:UNDEROVER},
  2109. {input:"\\bigotimes", tag:"mo", output:"\u2A02", ttype:UNDEROVER},
  2110. {input:"\\bigodot", tag:"mo", output:"\u2A00", ttype:UNDEROVER},
  2111. {input:"\\biguplus", tag:"mo", output:"\u2A04", ttype:UNDEROVER},
  2112. {input:"\\int", tag:"mo", output:"\u222B", ttype:CONST},
  2113. {input:"\\oint", tag:"mo", output:"\u222E", ttype:CONST},
  2114. //binary relation symbols
  2115. {input:":=", tag:"mo", output:":=", ttype:CONST},
  2116. {input:"\\lt", tag:"mo", output:"<", ttype:CONST},
  2117. {input:"\\gt", tag:"mo", output:">", ttype:CONST},
  2118. {input:"\\ne", tag:"mo", output:"\u2260", ttype:CONST},
  2119. {input:"\\neq", tag:"mo", output:"\u2260", ttype:CONST},
  2120. {input:"\\le", tag:"mo", output:"\u2264", ttype:CONST},
  2121. {input:"\\leq", tag:"mo", output:"\u2264", ttype:CONST},
  2122. {input:"\\leqslant", tag:"mo", output:"\u2264", ttype:CONST},
  2123. {input:"\\ge", tag:"mo", output:"\u2265", ttype:CONST},
  2124. {input:"\\geq", tag:"mo", output:"\u2265", ttype:CONST},
  2125. {input:"\\geqslant", tag:"mo", output:"\u2265", ttype:CONST},
  2126. {input:"\\equiv", tag:"mo", output:"\u2261", ttype:CONST},
  2127. {input:"\\ll", tag:"mo", output:"\u226A", ttype:CONST},
  2128. {input:"\\gg", tag:"mo", output:"\u226B", ttype:CONST},
  2129. {input:"\\doteq", tag:"mo", output:"\u2250", ttype:CONST},
  2130. {input:"\\prec", tag:"mo", output:"\u227A", ttype:CONST},
  2131. {input:"\\succ", tag:"mo", output:"\u227B", ttype:CONST},
  2132. {input:"\\preceq", tag:"mo", output:"\u227C", ttype:CONST},
  2133. {input:"\\succeq", tag:"mo", output:"\u227D", ttype:CONST},
  2134. {input:"\\subset", tag:"mo", output:"\u2282", ttype:CONST},
  2135. {input:"\\supset", tag:"mo", output:"\u2283", ttype:CONST},
  2136. {input:"\\subseteq", tag:"mo", output:"\u2286", ttype:CONST},
  2137. {input:"\\supseteq", tag:"mo", output:"\u2287", ttype:CONST},
  2138. {input:"\\sqsubset", tag:"mo", output:"\u228F", ttype:CONST},
  2139. {input:"\\sqsupset", tag:"mo", output:"\u2290", ttype:CONST},
  2140. {input:"\\sqsubseteq", tag:"mo", output:"\u2291", ttype:CONST},
  2141. {input:"\\sqsupseteq", tag:"mo", output:"\u2292", ttype:CONST},
  2142. {input:"\\sim", tag:"mo", output:"\u223C", ttype:CONST},
  2143. {input:"\\simeq", tag:"mo", output:"\u2243", ttype:CONST},
  2144. {input:"\\approx", tag:"mo", output:"\u2248", ttype:CONST},
  2145. {input:"\\cong", tag:"mo", output:"\u2245", ttype:CONST},
  2146. {input:"\\Join", tag:"mo", output:"\u22C8", ttype:CONST},
  2147. {input:"\\bowtie", tag:"mo", output:"\u22C8", ttype:CONST},
  2148. {input:"\\in", tag:"mo", output:"\u2208", ttype:CONST},
  2149. {input:"\\ni", tag:"mo", output:"\u220B", ttype:CONST},
  2150. {input:"\\owns", tag:"mo", output:"\u220B", ttype:CONST},
  2151. {input:"\\propto", tag:"mo", output:"\u221D", ttype:CONST},
  2152. {input:"\\vdash", tag:"mo", output:"\u22A2", ttype:CONST},
  2153. {input:"\\dashv", tag:"mo", output:"\u22A3", ttype:CONST},
  2154. {input:"\\models", tag:"mo", output:"\u22A8", ttype:CONST},
  2155. {input:"\\perp", tag:"mo", output:"\u22A5", ttype:CONST},
  2156. {input:"\\smile", tag:"mo", output:"\u2323", ttype:CONST},
  2157. {input:"\\frown", tag:"mo", output:"\u2322", ttype:CONST},
  2158. {input:"\\asymp", tag:"mo", output:"\u224D", ttype:CONST},
  2159. {input:"\\notin", tag:"mo", output:"\u2209", ttype:CONST},
  2160. //matrices
  2161. {input:"\\begin{eqnarray}", output:"X", ttype:MATRIX, invisible:true},
  2162. {input:"\\begin{array}", output:"X", ttype:MATRIX, invisible:true},
  2163. {input:"\\\\", output:"}&{", ttype:DEFINITION},
  2164. {input:"\\end{eqnarray}", output:"}}", ttype:DEFINITION},
  2165. {input:"\\end{array}", output:"}}", ttype:DEFINITION},
  2166. //grouping and literal brackets -- ieval is for IE
  2167. {input:"\\big", tag:"mo", output:"X", atval:"1.2", ieval:"2.2", ttype:BIG},
  2168. {input:"\\Big", tag:"mo", output:"X", atval:"1.6", ieval:"2.6", ttype:BIG},
  2169. {input:"\\bigg", tag:"mo", output:"X", atval:"2.2", ieval:"3.2", ttype:BIG},
  2170. {input:"\\Bigg", tag:"mo", output:"X", atval:"2.9", ieval:"3.9", ttype:BIG},
  2171. {input:"\\left", tag:"mo", output:"X", ttype:LEFTBRACKET},
  2172. {input:"\\right", tag:"mo", output:"X", ttype:RIGHTBRACKET},
  2173. {input:"{", output:"{", ttype:LEFTBRACKET, invisible:true},
  2174. {input:"}", output:"}", ttype:RIGHTBRACKET, invisible:true},
  2175. {input:"(", tag:"mo", output:"(", atval:"1", ttype:STRETCHY},
  2176. {input:"[", tag:"mo", output:"[", atval:"1", ttype:STRETCHY},
  2177. {input:"\\lbrack", tag:"mo", output:"[", atval:"1", ttype:STRETCHY},
  2178. {input:"\\{", tag:"mo", output:"{", atval:"1", ttype:STRETCHY},
  2179. {input:"\\lbrace", tag:"mo", output:"{", atval:"1", ttype:STRETCHY},
  2180. {input:"\\langle", tag:"mo", output:"\u2329", atval:"1", ttype:STRETCHY},
  2181. {input:"\\lfloor", tag:"mo", output:"\u230A", atval:"1", ttype:STRETCHY},
  2182. {input:"\\lceil", tag:"mo", output:"\u2308", atval:"1", ttype:STRETCHY},
  2183. // rtag:"mi" causes space to be inserted before a following sin, cos, etc.
  2184. // (see function LMparseExpr() )
  2185. {input:")", tag:"mo",output:")", rtag:"mi",atval:"1",ttype:STRETCHY},
  2186. {input:"]", tag:"mo",output:"]", rtag:"mi",atval:"1",ttype:STRETCHY},
  2187. {input:"\\rbrack",tag:"mo",output:"]", rtag:"mi",atval:"1",ttype:STRETCHY},
  2188. {input:"\\}", tag:"mo",output:"}", rtag:"mi",atval:"1",ttype:STRETCHY},
  2189. {input:"\\rbrace",tag:"mo",output:"}", rtag:"mi",atval:"1",ttype:STRETCHY},
  2190. {input:"\\rangle",tag:"mo",output:"\u232A", rtag:"mi",atval:"1",ttype:STRETCHY},
  2191. {input:"\\rfloor",tag:"mo",output:"\u230B", rtag:"mi",atval:"1",ttype:STRETCHY},
  2192. {input:"\\rceil", tag:"mo",output:"\u2309", rtag:"mi",atval:"1",ttype:STRETCHY},
  2193. // "|", "\\|", "\\vert" and "\\Vert" modified later: lspace = rspace = 0em
  2194. {input:"|", tag:"mo", output:"\u2223", atval:"1", ttype:STRETCHY},
  2195. {input:"\\|", tag:"mo", output:"\u2225", atval:"1", ttype:STRETCHY},
  2196. {input:"\\vert", tag:"mo", output:"\u2223", atval:"1", ttype:STRETCHY},
  2197. {input:"\\Vert", tag:"mo", output:"\u2225", atval:"1", ttype:STRETCHY},
  2198. {input:"\\mid", tag:"mo", output:"\u2223", atval:"1", ttype:STRETCHY},
  2199. {input:"\\parallel", tag:"mo", output:"\u2225", atval:"1", ttype:STRETCHY},
  2200. {input:"/", tag:"mo", output:"/", atval:"1.01", ttype:STRETCHY},
  2201. {input:"\\backslash", tag:"mo", output:"\u2216", atval:"1", ttype:STRETCHY},
  2202. {input:"\\setminus", tag:"mo", output:"\\", ttype:CONST},
  2203. //miscellaneous symbols
  2204. {input:"\\!", tag:"mspace", atname:"width", atval:"-0.167em", ttype:SPACE},
  2205. {input:"\\,", tag:"mspace", atname:"width", atval:"0.167em", ttype:SPACE},
  2206. {input:"\\>", tag:"mspace", atname:"width", atval:"0.222em", ttype:SPACE},
  2207. {input:"\\:", tag:"mspace", atname:"width", atval:"0.222em", ttype:SPACE},
  2208. {input:"\\;", tag:"mspace", atname:"width", atval:"0.278em", ttype:SPACE},
  2209. {input:"~", tag:"mspace", atname:"width", atval:"0.333em", ttype:SPACE},
  2210. {input:"\\quad", tag:"mspace", atname:"width", atval:"1em", ttype:SPACE},
  2211. {input:"\\qquad", tag:"mspace", atname:"width", atval:"2em", ttype:SPACE},
  2212. //{input:"{}", tag:"mo", output:"\u200B", ttype:CONST}, // zero-width
  2213. {input:"\\prime", tag:"mo", output:"\u2032", ttype:CONST},
  2214. {input:"'", tag:"mo", output:"\u02B9", ttype:CONST},
  2215. {input:"''", tag:"mo", output:"\u02BA", ttype:CONST},
  2216. {input:"'''", tag:"mo", output:"\u2034", ttype:CONST},
  2217. {input:"''''", tag:"mo", output:"\u2057", ttype:CONST},
  2218. {input:"\\ldots", tag:"mo", output:"\u2026", ttype:CONST},
  2219. {input:"\\cdots", tag:"mo", output:"\u22EF", ttype:CONST},
  2220. {input:"\\vdots", tag:"mo", output:"\u22EE", ttype:CONST},
  2221. {input:"\\ddots", tag:"mo", output:"\u22F1", ttype:CONST},
  2222. {input:"\\forall", tag:"mo", output:"\u2200", ttype:CONST},
  2223. {input:"\\exists", tag:"mo", output:"\u2203", ttype:CONST},
  2224. {input:"\\Re", tag:"mo", output:"\u211C", ttype:CONST},
  2225. {input:"\\Im", tag:"mo", output:"\u2111", ttype:CONST},
  2226. {input:"\\aleph", tag:"mo", output:"\u2135", ttype:CONST},
  2227. {input:"\\hbar", tag:"mo", output:"\u210F", ttype:CONST},
  2228. {input:"\\ell", tag:"mo", output:"\u2113", ttype:CONST},
  2229. {input:"\\wp", tag:"mo", output:"\u2118", ttype:CONST},
  2230. {input:"\\emptyset", tag:"mo", output:"\u2205", ttype:CONST},
  2231. {input:"\\infty", tag:"mo", output:"\u221E", ttype:CONST},
  2232. {input:"\\surd", tag:"mo", output:"\\sqrt{}", ttype:DEFINITION},
  2233. {input:"\\partial", tag:"mo", output:"\u2202", ttype:CONST},
  2234. {input:"\\nabla", tag:"mo", output:"\u2207", ttype:CONST},
  2235. {input:"\\triangle", tag:"mo", output:"\u25B3", ttype:CONST},
  2236. {input:"\\therefore", tag:"mo", output:"\u2234", ttype:CONST},
  2237. {input:"\\angle", tag:"mo", output:"\u2220", ttype:CONST},
  2238. //{input:"\\\\ ", tag:"mo", output:"\u00A0", ttype:CONST},
  2239. {input:"\\diamond", tag:"mo", output:"\u22C4", ttype:CONST},
  2240. //{input:"\\Diamond", tag:"mo", output:"\u25CA", ttype:CONST},
  2241. {input:"\\Diamond", tag:"mo", output:"\u25C7", ttype:CONST},
  2242. {input:"\\neg", tag:"mo", output:"\u00AC", ttype:CONST},
  2243. {input:"\\lnot", tag:"mo", output:"\u00AC", ttype:CONST},
  2244. {input:"\\bot", tag:"mo", output:"\u22A5", ttype:CONST},
  2245. {input:"\\top", tag:"mo", output:"\u22A4", ttype:CONST},
  2246. {input:"\\square", tag:"mo", output:"\u25AB", ttype:CONST},
  2247. {input:"\\Box", tag:"mo", output:"\u25A1", ttype:CONST},
  2248. {input:"\\wr", tag:"mo", output:"\u2240", ttype:CONST},
  2249. //standard functions
  2250. //Note UNDEROVER *must* have tag:"mo" to work properly
  2251. {input:"\\arccos", tag:"mi", output:"arccos", ttype:UNARY, func:true},
  2252. {input:"\\arcsin", tag:"mi", output:"arcsin", ttype:UNARY, func:true},
  2253. {input:"\\arctan", tag:"mi", output:"arctan", ttype:UNARY, func:true},
  2254. {input:"\\arg", tag:"mi", output:"arg", ttype:UNARY, func:true},
  2255. {input:"\\cos", tag:"mi", output:"cos", ttype:UNARY, func:true},
  2256. {input:"\\cosh", tag:"mi", output:"cosh", ttype:UNARY, func:true},
  2257. {input:"\\cot", tag:"mi", output:"cot", ttype:UNARY, func:true},
  2258. {input:"\\coth", tag:"mi", output:"coth", ttype:UNARY, func:true},
  2259. {input:"\\csc", tag:"mi", output:"csc", ttype:UNARY, func:true},
  2260. {input:"\\deg", tag:"mi", output:"deg", ttype:UNARY, func:true},
  2261. {input:"\\det", tag:"mi", output:"det", ttype:UNARY, func:true},
  2262. {input:"\\dim", tag:"mi", output:"dim", ttype:UNARY, func:true}, //CONST?
  2263. {input:"\\exp", tag:"mi", output:"exp", ttype:UNARY, func:true},
  2264. {input:"\\gcd", tag:"mi", output:"gcd", ttype:UNARY, func:true}, //CONST?
  2265. {input:"\\hom", tag:"mi", output:"hom", ttype:UNARY, func:true},
  2266. {input:"\\inf", tag:"mo", output:"inf", ttype:UNDEROVER},
  2267. {input:"\\ker", tag:"mi", output:"ker", ttype:UNARY, func:true},
  2268. {input:"\\lg", tag:"mi", output:"lg", ttype:UNARY, func:true},
  2269. {input:"\\lim", tag:"mo", output:"lim", ttype:UNDEROVER},
  2270. {input:"\\liminf", tag:"mo", output:"liminf", ttype:UNDEROVER},
  2271. {input:"\\limsup", tag:"mo", output:"limsup", ttype:UNDEROVER},
  2272. {input:"\\ln", tag:"mi", output:"ln", ttype:UNARY, func:true},
  2273. {input:"\\log", tag:"mi", output:"log", ttype:UNARY, func:true},
  2274. {input:"\\max", tag:"mo", output:"max", ttype:UNDEROVER},
  2275. {input:"\\min", tag:"mo", output:"min", ttype:UNDEROVER},
  2276. {input:"\\Pr", tag:"mi", output:"Pr", ttype:UNARY, func:true},
  2277. {input:"\\sec", tag:"mi", output:"sec", ttype:UNARY, func:true},
  2278. {input:"\\sin", tag:"mi", output:"sin", ttype:UNARY, func:true},
  2279. {input:"\\sinh", tag:"mi", output:"sinh", ttype:UNARY, func:true},
  2280. {input:"\\sup", tag:"mo", output:"sup", ttype:UNDEROVER},
  2281. {input:"\\tan", tag:"mi", output:"tan", ttype:UNARY, func:true},
  2282. {input:"\\tanh", tag:"mi", output:"tanh", ttype:UNARY, func:true},
  2283. //arrows
  2284. {input:"\\gets", tag:"mo", output:"\u2190", ttype:CONST},
  2285. {input:"\\leftarrow", tag:"mo", output:"\u2190", ttype:CONST},
  2286. {input:"\\to", tag:"mo", output:"\u2192", ttype:CONST},
  2287. {input:"\\rightarrow", tag:"mo", output:"\u2192", ttype:CONST},
  2288. {input:"\\leftrightarrow", tag:"mo", output:"\u2194", ttype:CONST},
  2289. {input:"\\uparrow", tag:"mo", output:"\u2191", ttype:CONST},
  2290. {input:"\\downarrow", tag:"mo", output:"\u2193", ttype:CONST},
  2291. {input:"\\updownarrow", tag:"mo", output:"\u2195", ttype:CONST},
  2292. {input:"\\Leftarrow", tag:"mo", output:"\u21D0", ttype:CONST},
  2293. {input:"\\Rightarrow", tag:"mo", output:"\u21D2", ttype:CONST},
  2294. {input:"\\Leftrightarrow", tag:"mo", output:"\u21D4", ttype:CONST},
  2295. {input:"\\iff", tag:"mo", output:"~\\Longleftrightarrow~", ttype:DEFINITION},
  2296. {input:"\\Uparrow", tag:"mo", output:"\u21D1", ttype:CONST},
  2297. {input:"\\Downarrow", tag:"mo", output:"\u21D3", ttype:CONST},
  2298. {input:"\\Updownarrow", tag:"mo", output:"\u21D5", ttype:CONST},
  2299. {input:"\\mapsto", tag:"mo", output:"\u21A6", ttype:CONST},
  2300. {input:"\\longleftarrow", tag:"mo", output:"\u2190", ttype:LONG},
  2301. {input:"\\longrightarrow", tag:"mo", output:"\u2192", ttype:LONG},
  2302. {input:"\\longleftrightarrow", tag:"mo", output:"\u2194", ttype:LONG},
  2303. {input:"\\Longleftarrow", tag:"mo", output:"\u21D0", ttype:LONG},
  2304. {input:"\\Longrightarrow", tag:"mo", output:"\u21D2", ttype:LONG},
  2305. {input:"\\implies", tag:"mo", output:"\u21D2", ttype:LONG},
  2306. {input:"\\Longleftrightarrow", tag:"mo", output:"\u21D4", ttype:LONG},
  2307. {input:"\\longmapsto", tag:"mo", output:"\u21A6", ttype:CONST},
  2308. // disaster if LONG
  2309. //commands with argument
  2310. {input:"\\sqrt", tag:"msqrt", output:"sqrt", ttype:UNARY},
  2311. {input:"\\root", tag:"mroot", output:"root", ttype:BINARY},
  2312. {input:"\\frac", tag:"mfrac", output:"/", ttype:BINARY},
  2313. {input:"\\stackrel", tag:"mover", output:"stackrel", ttype:BINARY},
  2314. {input:"\\atop", tag:"mfrac", output:"", ttype:INFIX},
  2315. {input:"\\choose", tag:"mfrac", output:"", ttype:INFIX},
  2316. {input:"_", tag:"msub", output:"_", ttype:INFIX},
  2317. {input:"^", tag:"msup", output:"^", ttype:INFIX},
  2318. {input:"\\mathrm", tag:"mtext", output:"text", ttype:TEXT},
  2319. {input:"\\mbox", tag:"mtext", output:"mbox", ttype:TEXT},
  2320. //diacritical marks
  2321. {input:"\\acute", tag:"mover", output:"\u00B4", ttype:UNARY, acc:true},
  2322. //{input:"\\acute", tag:"mover", output:"\u0317", ttype:UNARY, acc:true},
  2323. //{input:"\\acute", tag:"mover", output:"\u0301", ttype:UNARY, acc:true},
  2324. //{input:"\\grave", tag:"mover", output:"\u0300", ttype:UNARY, acc:true},
  2325. //{input:"\\grave", tag:"mover", output:"\u0316", ttype:UNARY, acc:true},
  2326. {input:"\\grave", tag:"mover", output:"\u0060", ttype:UNARY, acc:true},
  2327. {input:"\\breve", tag:"mover", output:"\u02D8", ttype:UNARY, acc:true},
  2328. {input:"\\check", tag:"mover", output:"\u02C7", ttype:UNARY, acc:true},
  2329. {input:"\\dot", tag:"mover", output:".", ttype:UNARY, acc:true},
  2330. {input:"\\ddot", tag:"mover", output:"..", ttype:UNARY, acc:true},
  2331. //{input:"\\ddot", tag:"mover", output:"\u00A8", ttype:UNARY, acc:true},
  2332. {input:"\\mathring", tag:"mover", output:"\u00B0", ttype:UNARY, acc:true},
  2333. {input:"\\vec", tag:"mover", output:"\u20D7", ttype:UNARY, acc:true},
  2334. {input:"\\overrightarrow",tag:"mover",output:"\u20D7", ttype:UNARY, acc:true},
  2335. {input:"\\overleftarrow",tag:"mover", output:"\u20D6", ttype:UNARY, acc:true},
  2336. {input:"\\hat", tag:"mover", output:"\u005E", ttype:UNARY, acc:true},
  2337. {input:"\\widehat", tag:"mover", output:"\u0302", ttype:UNARY, acc:true},
  2338. {input:"\\tilde", tag:"mover", output:"~", ttype:UNARY, acc:true},
  2339. //{input:"\\tilde", tag:"mover", output:"\u0303", ttype:UNARY, acc:true},
  2340. {input:"\\widetilde", tag:"mover", output:"\u02DC", ttype:UNARY, acc:true},
  2341. {input:"\\bar", tag:"mover", output:"\u203E", ttype:UNARY, acc:true},
  2342. {input:"\\overbrace", tag:"mover", output:"\u23B4", ttype:UNARY, acc:true},
  2343. {input:"\\overline", tag:"mover", output:"\u00AF", ttype:UNARY, acc:true},
  2344. {input:"\\underbrace", tag:"munder", output:"\u23B5", ttype:UNARY, acc:true},
  2345. {input:"\\underline", tag:"munder", output:"\u00AF", ttype:UNARY, acc:true},
  2346. //{input:"underline", tag:"munder", output:"\u0332", ttype:UNARY, acc:true},
  2347. //typestyles and fonts
  2348. {input:"\\displaystyle",tag:"mstyle",atname:"displaystyle",atval:"true", ttype:UNARY},
  2349. {input:"\\textstyle",tag:"mstyle",atname:"displaystyle",atval:"false", ttype:UNARY},
  2350. {input:"\\scriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"1", ttype:UNARY},
  2351. {input:"\\scriptscriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"2", ttype:UNARY},
  2352. {input:"\\textrm", tag:"mstyle", output:"\\mathrm", ttype: DEFINITION},
  2353. {input:"\\mathbf", tag:"mstyle", atname:"mathvariant", atval:"bold", ttype:UNARY},
  2354. {input:"\\textbf", tag:"mstyle", atname:"mathvariant", atval:"bold", ttype:UNARY},
  2355. {input:"\\mathit", tag:"mstyle", atname:"mathvariant", atval:"italic", ttype:UNARY},
  2356. {input:"\\textit", tag:"mstyle", atname:"mathvariant", atval:"italic", ttype:UNARY},
  2357. {input:"\\mathtt", tag:"mstyle", atname:"mathvariant", atval:"monospace", ttype:UNARY},
  2358. {input:"\\texttt", tag:"mstyle", atname:"mathvariant", atval:"monospace", ttype:UNARY},
  2359. {input:"\\mathsf", tag:"mstyle", atname:"mathvariant", atval:"sans-serif", ttype:UNARY},
  2360. {input:"\\mathbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", ttype:UNARY, codes:LMbbb},
  2361. {input:"\\mathcal",tag:"mstyle", atname:"mathvariant", atval:"script", ttype:UNARY, codes:LMcal},
  2362. {input:"\\mathfrak",tag:"mstyle",atname:"mathvariant", atval:"fraktur",ttype:UNARY, codes:LMfrk},
  2363. // Symbols added by Mauno Korpelainen, November 2009.
  2364. {input:"\\density",tag:"mstyle",atname:"mathvariant", atval:"mathsize", ttype:BINARY},
  2365. {input:"\\#", tag:"mo", output:"\u0023", ttype:CONST},
  2366. {input:"\\%", tag:"mo", output:"\u0025", ttype:CONST},
  2367. {input:"\\&", tag:"mo", output:"\u0026", ttype:CONST},
  2368. {input:"\\AE", tag:"mo", output:"\u00C6", ttype:CONST},
  2369. {input:"\\ae", tag:"mo", output:"\u00E6", ttype:CONST},
  2370. {input:"\\approxeq", tag:"mo", output:"\u224A", ttype:CONST},
  2371. {input:"\\backprime", tag:"mo", output:"\u2035", ttype:CONST},
  2372. {input:"\\backsim", tag:"mo", output:"\u223D", ttype:CONST},
  2373. {input:"\\backsimeq", tag:"mo", output:"\u22CD", ttype:CONST},
  2374. {input:"\\barwedge", tag:"mo", output:"\u22BC", ttype:CONST},
  2375. {input:"\\Bbb{A}", tag:"mo", output:"\uD835\uDD38", ttype:CONST},
  2376. {input:"\\because", tag:"mo", output:"\u2235", ttype:CONST},
  2377. {input:"\\beth", tag:"mo", output:"\u2136", ttype:CONST},
  2378. {input:"\\between", tag:"mo", output:"\u226C", ttype:CONST},
  2379. {input:"\\bigcup", tag:"mo", output:"\u22C3", ttype:UNDEROVER},
  2380. {input:"\\bigodot", tag:"mo", output:"\u2A00", ttype:UNDEROVER},
  2381. {input:"\\bigstar", tag:"mo", output:"\u2605", ttype:CONST},
  2382. {input:"\\blacktriangle", tag:"mo", output:"\u25B4", ttype:CONST},
  2383. {input:"\\blacktriangledown", tag:"mo", output:"\u25BE", ttype:CONST},
  2384. {input:"\\blacktriangleleft", tag:"mo", output:"\u25C0", ttype:CONST},
  2385. {input:"\\blacktriangleright", tag:"mo", output:"\u25B6", ttype:CONST},
  2386. {input:"\\boxdot", tag:"mo", output:"\u22A1", ttype:CONST},
  2387. {input:"\\boxminus", tag:"mo", output:"\u229F", ttype:CONST},
  2388. {input:"\\boxplus", tag:"mo", output:"\u229E", ttype:CONST},
  2389. {input:"\\boxtimes", tag:"mo", output:"\u22A0", ttype:CONST},
  2390. {input:"\\Bumpeq", tag:"mo", output:"\u224E", ttype:CONST},
  2391. {input:"\\bumpeq", tag:"mo", output:"\u224F", ttype:CONST},
  2392. {input:"\\Cap", tag:"mo", output:"\u22D2", ttype:CONST},
  2393. {input:"\\cdotp", tag:"mo", output:"\u00B7", ttype:CONST},
  2394. {input:"\\checkmark", tag:"mo", output:"\u2713", ttype:CONST},
  2395. {input:"\\circeq", tag:"mo", output:"\u2257", ttype:CONST},
  2396. {input:"\\circledast", tag:"mo", output:"\u229B", ttype:CONST},
  2397. {input:"\\circledcirc", tag:"mo", output:"\u229A", ttype:CONST},
  2398. {input:"\\circleddash", tag:"mo", output:"\u229D", ttype:CONST},
  2399. {input:"\\circledR", tag:"mo", output:"\u24C7", ttype:CONST},
  2400. {input:"\\circledS", tag:"mo", output:"\u24C8", ttype:CONST},
  2401. {input:"\\clubsuit", tag:"mo", output:"\u2663", ttype:CONST},
  2402. {input:"\\colon", tag:"mo", output:"\u003A", ttype:CONST},
  2403. {input:"\\complement", tag:"mo", output:"\u2201", ttype:CONST},
  2404. {input:"\\Cup", tag:"mo", output:"\u22D3", ttype:CONST},
  2405. {input:"\\curlyeqprec", tag:"mo", output:"\u22DE", ttype:CONST},
  2406. {input:"\\curlyeqsucc", tag:"mo", output:"\u22DF", ttype:CONST},
  2407. {input:"\\curlywedge", tag:"mo", output:"\u22CF", ttype:CONST},
  2408. {input:"\\curlyvee", tag:"mo", output:"\u22CE", ttype:CONST},
  2409. {input:"\\curvearrowleft", tag:"mo", output:"\u21B6", ttype:CONST},
  2410. {input:"\\curvearrowright", tag:"mo", output:"\u21B7", ttype:CONST},
  2411. {input:"\\daleth", tag:"mo", output:"\u2138", ttype:CONST},
  2412. {input:"\\diamondsuit", tag:"mo", output:"\u2662", ttype:CONST},
  2413. {input:"\\divideontimes", tag:"mo", output:"\u22C7", ttype:CONST},
  2414. {input:"\\Doteq", tag:"mo", output:"\u2251", ttype:CONST},
  2415. {input:"\\dotplus", tag:"mo", output:"\u2214", ttype:CONST},
  2416. {input:"\\dots", tag:"mo", output:"\u2026", ttype:CONST},
  2417. {input:"\\doublebarwedge", tag:"mo", output:"\u2A5E", ttype:CONST},
  2418. {input:"\\downdownarrows", tag:"mo", output:"\u21CA", ttype:CONST},
  2419. {input:"\\downharpoonleft", tag:"mo", output:"\u21C3", ttype:CONST},
  2420. {input:"\\downharpoonright", tag:"mo", output:"\u21C2", ttype:CONST},
  2421. {input:"\\eqcirc", tag:"mo", output:"\u2256", ttype:CONST},
  2422. {input:"\\eqsim", tag:"mo", output:"\u2242", ttype:CONST},
  2423. {input:"\\eqslantgtr", tag:"mo", output:"\u2A96", ttype:CONST},
  2424. {input:"\\eqslantless", tag:"mo", output:"\u2A95", ttype:CONST},
  2425. {input:"\\eta", tag:"mi", output:"\u03B7", ttype:CONST},
  2426. {input:"\\fallingdotseq", tag:"mo", output:"\u2252", ttype:CONST},
  2427. {input:"\\Finv", tag:"mo", output:"\u2132", ttype:CONST},
  2428. {input:"\\flat", tag:"mo", output:"\u266D", ttype:CONST},
  2429. {input:"\\Game", tag:"mo", output:"\u2141", ttype:CONST},
  2430. {input:"\\geqq", tag:"mo", output:"\u2267", ttype:CONST},
  2431. {input:"\\ggg", tag:"mo", output:"\u22D9", ttype:CONST},
  2432. {input:"\\gimel", tag:"mo", output:"\u2137", ttype:CONST},
  2433. {input:"\\gnapprox", tag:"mo", output:"\u2A8A", ttype:CONST},
  2434. {input:"\\gneq", tag:"mo", output:"\u2A88", ttype:CONST},
  2435. {input:"\\gneqq", tag:"mo", output:"\u2269", ttype:CONST},
  2436. {input:"\\gnsim", tag:"mo", output:"\u22E7", ttype:CONST},
  2437. {input:"\\gtrapprox", tag:"mo", output:"\u2A86", ttype:CONST},
  2438. {input:"\\gtrdot", tag:"mo", output:"\u22D7", ttype:CONST},
  2439. {input:"\\gtreqless", tag:"mo", output:"\u22DB", ttype:CONST},
  2440. {input:"\\gtreqqless", tag:"mo", output:"\u2A8C", ttype:CONST},
  2441. {input:"\\gtrless", tag:"mo", output:"\u2277", ttype:CONST},
  2442. {input:"\\gtrsim", tag:"mo", output:"\u2273", ttype:CONST},
  2443. {input:"\\heartsuit", tag:"mo", output:"\u2661", ttype:CONST},
  2444. {input:"\\hookleftarrow", tag:"mo", output:"\u21A9", ttype:CONST},
  2445. {input:"\\hookrightarrow", tag:"mo", output:"\u21AA", ttype:CONST},
  2446. {input:"\\hslash", tag:"mo", output:"\u210F", ttype:CONST},
  2447. //{input:"\\i", tag:"mo", output:"\u0131", ttype:CONST},
  2448. {input:"\\iiiint", tag:"mo", output:"\u2A0C", ttype:CONST},
  2449. {input:"\\iiint", tag:"mo", output:"\u222D", ttype:CONST},
  2450. {input:"\\iint", tag:"mo", output:"\u222C", ttype:CONST},
  2451. {input:"\\intercal", tag:"mo", output:"\u22BA", ttype:CONST},
  2452. {input:"\\itx", tag:"mo", output:"\uD835\uDC65", ttype:CONST},
  2453. {input:"\\varkappa", tag:"mi", output:"\u03F0", ttype:CONST},
  2454. {input:"\\digamma", tag:"mi", output:"\u03DC", ttype:CONST},
  2455. //{input:"\\L", tag:"mo", output:"\u0141", ttype:CONST},
  2456. //{input:"\\l", tag:"mo", output:"\u0142", ttype:CONST},
  2457. {input:"\\leftarrowtail", tag:"mo", output:"\u21A2", ttype:CONST},
  2458. {input:"\\leftharpoondown", tag:"mo", output:"\u21BD", ttype:CONST},
  2459. {input:"\\leftharpoonup", tag:"mo", output:"\u21BC", ttype:CONST},
  2460. {input:"\\leftleftarrows", tag:"mo", output:"\u21C7", ttype:CONST},
  2461. {input:"\\leftrightarrows", tag:"mo", output:"\u21C6", ttype:CONST},
  2462. {input:"\\leftrightharpoons", tag:"mo", output:"\u21CB", ttype:CONST},
  2463. {input:"\\leftrightsquigarrow", tag:"mo", output:"\u21AD", ttype:CONST},
  2464. {input:"\\leftthreetimes", tag:"mo", output:"\u22CB", ttype:CONST},
  2465. {input:"\\leqq", tag:"mo", output:"\u2266", ttype:CONST},
  2466. {input:"\\lessapprox", tag:"mo", output:"\u2A85", ttype:CONST},
  2467. {input:"\\lessdot", tag:"mo", output:"\u22D6", ttype:CONST},
  2468. {input:"\\lesseqgtr", tag:"mo", output:"\u22DA", ttype:CONST},
  2469. {input:"\\lesseqqgtr", tag:"mo", output:"\u2A8B", ttype:CONST},
  2470. {input:"\\lessgtr", tag:"mo", output:"\u2276", ttype:CONST},
  2471. {input:"\\lesssim", tag:"mo", output:"\u2272", ttype:CONST},
  2472. {input:"\\llcorner", tag:"mo", output:"\u231E", ttype:CONST},
  2473. {input:"\\Lleftarrow", tag:"mo", output:"\u21DA", ttype:CONST},
  2474. {input:"\\lll", tag:"mo", output:"\u22D8", ttype:CONST},
  2475. {input:"\\lmoustache", tag:"mo", output:"\u23B0", ttype:CONST},
  2476. {input:"\\lnapprox", tag:"mo", output:"\u2A89", ttype:CONST},
  2477. {input:"\\lneq", tag:"mo", output:"\u2A87", ttype:CONST},
  2478. {input:"\\lneqq", tag:"mo", output:"\u2268", ttype:CONST},
  2479. {input:"\\lnsim", tag:"mo", output:"\u22E6", ttype:CONST},
  2480. {input:"\\looparrowleft", tag:"mo", output:"\u21AB", ttype:CONST},
  2481. {input:"\\looparrowright", tag:"mo", output:"\u21AC", ttype:CONST},
  2482. {input:"\\lozenge", tag:"mo", output:"\u25CA", ttype:CONST},
  2483. {input:"\\lrcorner", tag:"mo", output:"\u231F", ttype:CONST},
  2484. {input:"\\Lsh", tag:"mo", output:"\u21B0", ttype:CONST},
  2485. {input:"\\ltimes", tag:"mo", output:"\u22C9", ttype:CONST},
  2486. {input:"\\maltese", tag:"mo", output:"\u2720", ttype:CONST},
  2487. {input:"\\measuredangle", tag:"mo", output:"\u2221", ttype:CONST},
  2488. {input:"\\mho", tag:"mo", output:"\u2127", ttype:CONST},
  2489. {input:"\\multimap", tag:"mo", output:"\u22B8", ttype:CONST},
  2490. {input:"\\natural", tag:"mo", output:"\u266E", ttype:CONST},
  2491. {input:"\\ncong", tag:"mo", output:"\u2247", ttype:CONST},
  2492. {input:"\\nearrow", tag:"mo", output:"\u2197", ttype:CONST},
  2493. {input:"\\nexists", tag:"mo", output:"\u2204", ttype:CONST},
  2494. {input:"\\ngeq", tag:"mo", output:"\u2271", ttype:CONST},
  2495. {input:"\\ngtr", tag:"mo", output:"\u226F", ttype:CONST},
  2496. {input:"\\nleftarrow", tag:"mo", output:"\u219A", ttype:CONST},
  2497. {input:"\\nLeftarrow", tag:"mo", output:"\u21CD", ttype:CONST},
  2498. {input:"\\nleftrightarrow", tag:"mo", output:"\u21AE", ttype:CONST},
  2499. {input:"\\nLeftrightarrow", tag:"mo", output:"\u21CE", ttype:CONST},
  2500. {input:"\\nleq", tag:"mo", output:"\u2270", ttype:CONST},
  2501. {input:"\\nless", tag:"mo", output:"\u226E", ttype:CONST},
  2502. {input:"\\nmid", tag:"mo", output:"\u2224", ttype:CONST},
  2503. {input:"\\not\\leq", tag:"mo", output:"\u2270", ttype:CONST},
  2504. {input:"\\nparallel", tag:"mo", output:"\u2226", ttype:CONST},
  2505. {input:"\\nprec", tag:"mo", output:"\u2280", ttype:CONST},
  2506. {input:"\\nrightarrow", tag:"mo", output:"\u219B", ttype:CONST},
  2507. {input:"\\nRightarrow", tag:"mo", output:"\u21CF", ttype:CONST},
  2508. {input:"\\nsim", tag:"mo", output:"\u2241", ttype:CONST},
  2509. {input:"\\nsubseteq", tag:"mo", output:"\u2288", ttype:CONST},
  2510. {input:"\\nsucc", tag:"mo", output:"\u2281", ttype:CONST},
  2511. {input:"\\nsupseteq", tag:"mo", output:"\u2289", ttype:CONST},
  2512. {input:"\\ntriangleleft", tag:"mo", output:"\u22EA", ttype:CONST},
  2513. {input:"\\ntrianglelefteq", tag:"mo", output:"\u22EC", ttype:CONST},
  2514. {input:"\\ntriangleright", tag:"mo", output:"\u22EB", ttype:CONST},
  2515. {input:"\\ntrianglerighteq", tag:"mo", output:"\u22ED", ttype:CONST},
  2516. {input:"\\nwarrow", tag:"mo", output:"\u2196", ttype:CONST},
  2517. {input:"\\nvdash", tag:"mo", output:"\u22AC", ttype:CONST},
  2518. {input:"\\nvDash", tag:"mo", output:"\u22AD", ttype:CONST},
  2519. {input:"\\nVdash", tag:"mo", output:"\u22AE", ttype:CONST},
  2520. {input:"\\nVDash", tag:"mo", output:"\u22AF", ttype:CONST},
  2521. //{input:"\\O", tag:"mo", output:"\u00D8", ttype:CONST},
  2522. //{input:"\\o", tag:"mo", output:"\u00F8", ttype:CONST},
  2523. {input:"\\OE", tag:"mo", output:"\u0152", ttype:CONST},
  2524. {input:"\\oe", tag:"mo", output:"\u0153", ttype:CONST},
  2525. {input:"\\overbracket", tag:"mover", output:"\u23B4", ttype:UNARY, acc:true}, //old overbrace = overbracket
  2526. {input:"\\overleftrightarrow", tag:"mo", output:"\u20E1", ttype:CONST},
  2527. {input:"\\pitchfork", tag:"mo", output:"\u22D4", ttype:CONST},
  2528. {input:"\\precapprox", tag:"mo", output:"\u2AB7", ttype:CONST},
  2529. {input:"\\preccurlyeq", tag:"mo", output:"\u227C", ttype:CONST},
  2530. {input:"\\precnapprox", tag:"mo", output:"\u2AB9", ttype:CONST},
  2531. {input:"\\precneqq", tag:"mo", output:"\u2AB5", ttype:CONST},
  2532. {input:"\\precnsim", tag:"mo", output:"\u22E8", ttype:CONST},
  2533. {input:"\\precsim", tag:"mo", output:"\u227E", ttype:CONST},
  2534. {input:"\\rightarrowtail", tag:"mo", output:"\u21A3", ttype:CONST},
  2535. {input:"\\rightharpoondown", tag:"mo", output:"\u21C1", ttype:CONST},
  2536. {input:"\\rightharpoonup", tag:"mo", output:"\u21C0", ttype:CONST},
  2537. {input:"\\rightleftarrows", tag:"mo", output:"\u21C4", ttype:CONST},
  2538. {input:"\\rightleftharpoons", tag:"mo", output:"\u21CC", ttype:CONST},
  2539. {input:"\\rightrightarrows", tag:"mo", output:"\u21C9", ttype:CONST},
  2540. {input:"\\rightsquigarrow", tag:"mo", output:"\u21DD", ttype:CONST},
  2541. {input:"\\rightthreetimes", tag:"mo", output:"\u22CC", ttype:CONST},
  2542. {input:"\\risingdotseq", tag:"mo", output:"\u2253", ttype:CONST},
  2543. {input:"\\rmoustache", tag:"mo", output:"\u23B1", ttype:CONST},
  2544. {input:"\\Rrightarrow", tag:"mo", output:"\u21DB", ttype:CONST},
  2545. {input:"\\Rsh", tag:"mo", output:"\u21B1", ttype:CONST},
  2546. {input:"\\rtimes", tag:"mo", output:"\u22CA", ttype:CONST},
  2547. //{input:"\\S", tag:"mo", output:"\u00A7", ttype:CONST},
  2548. {input:"\\searrow", tag:"mo", output:"\u2198", ttype:CONST},
  2549. {input:"\\sharp", tag:"mo", output:"\u266F", ttype:CONST},
  2550. {input:"\\slash", tag:"mo", output:"\u2215", ttype:CONST},
  2551. {input:"\\smallint", tag:"mo", output:"\u222B", ttype:CONST},
  2552. {input:"\\smallsetminus", tag:"mo", output:"\u2216", ttype:CONST},
  2553. {input:"\\spadesuit", tag:"mo", output:"\u2660", ttype:CONST},
  2554. {input:"\\sphericalangle", tag:"mo", output:"\u2222", ttype:CONST},
  2555. {input:"\\ss", tag:"mo", output:"\u00DF", ttype:CONST},
  2556. {input:"\\Subset", tag:"mo", output:"\u22D0", ttype:CONST},
  2557. {input:"\\subseteqq", tag:"mo", output:"\u2AC5", ttype:CONST},
  2558. {input:"\\subsetneq", tag:"mo", output:"\u228A", ttype:CONST},
  2559. {input:"\\subsetneqq", tag:"mo", output:"\u2ACB", ttype:CONST},
  2560. {input:"\\succapprox", tag:"mo", output:"\u2AB8", ttype:CONST},
  2561. {input:"\\succcurlyeq", tag:"mo", output:"\u227D", ttype:CONST},
  2562. {input:"\\succnapprox", tag:"mo", output:"\u2ABA", ttype:CONST},
  2563. {input:"\\succneqq", tag:"mo", output:"\u2AB6", ttype:CONST},
  2564. {input:"\\succnsim", tag:"mo", output:"\u22E9", ttype:CONST},
  2565. {input:"\\succsim", tag:"mo", output:"\u227F", ttype:CONST},
  2566. {input:"\\Supset", tag:"mo", output:"\u22D1", ttype:CONST},
  2567. {input:"\\supseteqq", tag:"mo", output:"\u2AC6", ttype:CONST},
  2568. {input:"\\supsetneq", tag:"mo", output:"\u228B", ttype:CONST},
  2569. {input:"\\supsetneqq", tag:"mo", output:"\u2ACC", ttype:CONST},
  2570. {input:"\\swarrow", tag:"mo", output:"\u2199", ttype:CONST},
  2571. {input:"\\textasciicircum", tag:"mo", output:"\u005E", ttype:CONST},
  2572. {input:"\\textasciitilde", tag:"mo", output:"\u007E", ttype:CONST},
  2573. {input:"\\textcolor",tag:"mstyle",atname:"mathvariant", atval:"mathcolor", ttype:BINARY},
  2574. {input:"\\textcopyright", tag:"mo", output:"\u00A9", ttype:CONST},
  2575. {input:"\\textdegree", tag:"mo", output:"\u00B0", ttype:CONST},
  2576. {input:"\\textdollar", tag:"mo", output:"\u0024", ttype:CONST},
  2577. {input:"\\textonehalf", tag:"mo", output:"\u00BD", ttype:CONST},
  2578. {input:"\\textonequarter", tag:"mo", output:"\u00BC", ttype:CONST},
  2579. {input:"\\textordfeminine", tag:"mo", output:"\u00AA", ttype:CONST},
  2580. {input:"\\textordmasculine", tag:"mo", output:"\u00BA", ttype:CONST},
  2581. {input:"\\textregistered", tag:"mo", output:"\u00AE", ttype:CONST},
  2582. {input:"\\textthreequarters", tag:"mo", output:"\u00BE", ttype:CONST},
  2583. {input:"\\texttrademark", tag:"mo", output:"\u2122", ttype:CONST},
  2584. {input:"\\theta", tag:"mi", output:"\u03B8", ttype:CONST},
  2585. {input:"\\thickapprox", tag:"mo", output:"\u2248", ttype:CONST},
  2586. {input:"\\thicksim", tag:"mo", output:"\u223C", ttype:CONST},
  2587. {input:"\\triangledown", tag:"mo", output:"\u25BF", ttype:CONST},
  2588. {input:"\\trianglelefteq", tag:"mo", output:"\u22B4", ttype:CONST},
  2589. {input:"\\triangleq", tag:"mo", output:"\u225C", ttype:CONST},
  2590. {input:"\\trianglerighteq", tag:"mo", output:"\u22B5", ttype:CONST},
  2591. {input:"\\twoheadleftarrow", tag:"mo", output:"\u219E", ttype:CONST},
  2592. {input:"\\twoheadrightarrow", tag:"mo", output:"\u21A0", ttype:CONST},
  2593. {input:"\\ulcorner", tag:"mo", output:"\u231C", ttype:CONST},
  2594. {input:"\\underbracket",tag:"munder", output:"\u23B5", ttype:UNARY, acc:true}, //old underbrace = underbracket
  2595. {input:"\\underleftarrow", tag:"mo", output:"\u20EE", ttype:CONST},
  2596. {input:"\\underrightarrow", tag:"mo", output:"\u20EF", ttype:CONST},
  2597. {input:"\\upharpoonleft", tag:"mo", output:"\u21BF", ttype:CONST},
  2598. {input:"\\upharpoonright", tag:"mo", output:"\u21BE", ttype:CONST},
  2599. {input:"\\upuparrows", tag:"mo", output:"\u21C8", ttype:CONST},
  2600. {input:"\\urcorner", tag:"mo", output:"\u231D", ttype:CONST},
  2601. {input:"\\varnothing", tag:"mo", output:"\u2205", ttype:CONST},
  2602. {input:"\\varpropto", tag:"mo", output:"\u221D", ttype:CONST},
  2603. {input:"\\vartriangle", tag:"mo", output:"\u22B5", ttype:CONST},
  2604. {input:"\\vartriangleleft", tag:"mo", output:"\u22B2", ttype:CONST},
  2605. {input:"\\vartriangleright", tag:"mo", output:"\u22B3", ttype:CONST},
  2606. {input:"\\vDash", tag:"mo", output:"\u22A8", ttype:CONST},
  2607. {input:"\\Vdash", tag:"mo", output:"\u22A9", ttype:CONST},
  2608. {input:"\\veebar", tag:"mo", output:"\u22BB", ttype:CONST},
  2609. {input:"\\Vert", tag:"mo", output:"\u2016", atval:"1", ttype:STRETCHY},
  2610. {input:"\\Vvdash", tag:"mo", output:"\u22AA", ttype:CONST},
  2611. {input:"\\yen", tag:"mo", output:"\u00A5", ttype:CONST},
  2612. {input:"\\usepackage[usenames]{color}",tag:"mstyle",atname:"mathvariant", output:"X", atval:"false", ttype:UNARY},
  2613. {input:"\\colorbox",tag:"mstyle",atname:"mathvariant", atval:"background", ttype:BINARY}
  2614. ];
  2615. var LMnames = []; //list of input symbols
  2616. var LMmathml = "http://www.w3.org/1998/Math/MathML";
  2617. var LMpreviousSymbol,LMcurrentSymbol;
  2618. var LaTeXColor = [];
  2619. LaTeXColor["greenyellow"] = "#D9FF4F";
  2620. LaTeXColor["yellow"] = "#FFFF00";
  2621. LaTeXColor["goldenrod"] = "#FFE529";
  2622. LaTeXColor["dandelion"] = "#FFB529";
  2623. LaTeXColor["apricot"] = "#FFAD7A";
  2624. LaTeXColor["peach"] = "#FF804D";
  2625. LaTeXColor["melon"] = "#FF8A80";
  2626. LaTeXColor["yelloworange"] = "#FF9400";
  2627. LaTeXColor["orange"] = "#FF6321";
  2628. LaTeXColor["burntorange"] = "#FF7D00";
  2629. LaTeXColor["bittersweet"] = "#C20300";
  2630. LaTeXColor["redorange"] = "#FF3B21";
  2631. LaTeXColor["mahogany"] = "#A60000";
  2632. LaTeXColor["maroon"] = "#AD0000";
  2633. LaTeXColor["brickred"] = "#B80000";
  2634. LaTeXColor["red"] = "#FF0000";
  2635. LaTeXColor["orangered"] = "#FF0080";
  2636. LaTeXColor["rubinered"] = "#FF00DE";
  2637. LaTeXColor["wildstrawberry"] = "#FF0A9C";
  2638. LaTeXColor["salmon"] = "#FF789E";
  2639. LaTeXColor["carnationpink"] = "#FF5EFF";
  2640. LaTeXColor["magenta"] = "#FF00FF";
  2641. LaTeXColor["violetred"] = "#FF30FF";
  2642. LaTeXColor["rhodamine"] = "#FF2EFF";
  2643. LaTeXColor["mulberry"] = "#A314FA";
  2644. LaTeXColor["redviolet"] = "#9600A8";
  2645. LaTeXColor["fuchsia"] = "#7303EB";
  2646. LaTeXColor["lavender"] = "#FF85FF";
  2647. LaTeXColor["thistle"] = "#E069FF";
  2648. LaTeXColor["orchid"] = "#AD5CFF";
  2649. LaTeXColor["darkorchid"] = "#9933CC";
  2650. LaTeXColor["purple"] = "#8C24FF";
  2651. LaTeXColor["plum"] = "#8000FF";
  2652. LaTeXColor["violet"] = "#361FFF";
  2653. LaTeXColor["royalpurple"] = "#401AFF";
  2654. LaTeXColor["blueviolet"] = "#1A0DF5";
  2655. LaTeXColor["periwinkle"] = "#6E73FF";
  2656. LaTeXColor["cadetblue"] = "#616EC4";
  2657. LaTeXColor["cornflowerblue"] = "#59DEFF";
  2658. LaTeXColor["midnightblue"] = "#007091";
  2659. LaTeXColor["navyblue"] = "#0F75FF";
  2660. LaTeXColor["royalblue"] = "#0080FF";
  2661. LaTeXColor["blue"] = "#0000FF";
  2662. LaTeXColor["cerulean"] = "#0FE3FF";
  2663. LaTeXColor["cyan"] = "#00FFFF";
  2664. LaTeXColor["processblue"] = "#0AFFFF";
  2665. LaTeXColor["skyblue"] = "#61FFE0";
  2666. LaTeXColor["turquoise"] = "#26FFCC";
  2667. LaTeXColor["tealblue"] = "#1FFAA3";
  2668. LaTeXColor["aquamarine"] = "#2EFFB2";
  2669. LaTeXColor["bluegreen"] = "#26FFAB";
  2670. LaTeXColor["emerald"] = "#00FF80";
  2671. LaTeXColor["junglegreen"] = "#03FF7A";
  2672. LaTeXColor["seagreen"] = "#4FFF80";
  2673. LaTeXColor["green"] = "#00FF00";
  2674. LaTeXColor["forestgreen"] = "#00E000";
  2675. LaTeXColor["pinegreen"] = "#00BF29";
  2676. LaTeXColor["limegreen"] = "#80FF00";
  2677. LaTeXColor["yellowgreen"] = "#8FFF42";
  2678. LaTeXColor["springgreen"] = "#BDFF3D";
  2679. LaTeXColor["olivegreen"] = "#009900";
  2680. LaTeXColor["rawsienna"] = "#8C0000";
  2681. LaTeXColor["sepia"] = "#4D0000";
  2682. LaTeXColor["brown"] = "#660000";
  2683. LaTeXColor["tan"] = "#DB9470";
  2684. LaTeXColor["gray"] = "#808080";
  2685. LaTeXColor["grey"] = "#808080";
  2686. LaTeXColor["black"] = "#000000";
  2687. LaTeXColor["white"] = "#FFFFFF";
  2688. var IsColorName = /^(?:greenyellow|yellow|goldenrod|dandelion|apricot|peach|melon|yelloworange|orange|burntorange|bittersweet|redorange|mahogany|maroon|brickred|red|orangered|rubinered|wildstrawberry|salmon|carnationpink|magenta|violetred|rhodamine|mulberry|redviolet|fuchsia|lavender|thistle|orchid|darkorchid|purple|plum|violet|royalpurple|blueviolet|periwinkle|cadetblue|cornflowerblue|midnightblue|navyblue|royalblue|blue|cerulean|cyan|processblue|skyblue|turquoise|tealblue|aquamarine|bluegreen|emerald|junglegreen|seagreen|green|forestgreen|pinegreen|limegreen|yellowgreen|springgreen|olivegreen|rawsienna|sepia|brown|tan|gray|grey|black|white)$/;
  2689. function LMremoveCharsAndBlanks(str,n) {
  2690. //remove n characters and any following blanks
  2691. var st;
  2692. st = str.slice(n);
  2693. for (var i=0; i<st.length && st.charCodeAt(i)<=32; i=i+1);
  2694. return st.slice(i);
  2695. }
  2696. function LMgetSymbol(str) {
  2697. //return maximal initial substring of str that appears in names
  2698. //return null if there is none
  2699. var k = 0; //new pos
  2700. var j = 0; //old pos
  2701. var mk; //match pos
  2702. var st;
  2703. var tagst;
  2704. var match = "";
  2705. var more = true;
  2706. for (var i=1; i<=str.length && more; i++) {
  2707. st = str.slice(0,i); //initial substring of length i
  2708. j = k;
  2709. k = position(LMnames, st, j);
  2710. if (k<LMnames.length && str.slice(0,LMnames[k].length)==LMnames[k]){
  2711. match = LMnames[k];
  2712. mk = k;
  2713. i = match.length;
  2714. }
  2715. more = k<LMnames.length && str.slice(0,LMnames[k].length)>=LMnames[k];
  2716. }
  2717. LMpreviousSymbol=LMcurrentSymbol;
  2718. if (match!=""){
  2719. LMcurrentSymbol=LMsymbols[mk].ttype;
  2720. return LMsymbols[mk];
  2721. }
  2722. LMcurrentSymbol=CONST;
  2723. k = 1;
  2724. st = str.slice(0,1); //take 1 character
  2725. if ("0"<=st && st<="9") tagst = "mn";
  2726. else tagst = (("A">st || st>"Z") && ("a">st || st>"z")?"mo":"mi");
  2727. /*
  2728. // Commented out by DRW (not fully understood, but probably to do with
  2729. // use of "/" as an INFIX version of "\\frac", which we don't want):
  2730. //}
  2731. //if (st=="-" && LMpreviousSymbol==INFIX) {
  2732. // LMcurrentSymbol = INFIX; //trick "/" into recognizing "-" on second parse
  2733. // return {input:st, tag:tagst, output:st, ttype:UNARY, func:true};
  2734. //}
  2735. */
  2736. return {input:st, tag:tagst, output:st, ttype:CONST};
  2737. }
  2738. /*Parsing ASCII math expressions with the following grammar
  2739. v ::= [A-Za-z] | greek letters | numbers | other constant symbols
  2740. u ::= sqrt | text | bb | other unary symbols for font commands
  2741. b ::= frac | root | stackrel binary symbols
  2742. l ::= { | \left left brackets
  2743. r ::= } | \right right brackets
  2744. S ::= v | lEr | uS | bSS Simple expression
  2745. I ::= S_S | S^S | S_S^S | S Intermediate expression
  2746. E ::= IE | I/I Expression
  2747. Each terminal symbol is translated into a corresponding mathml node.*/
  2748. var LMpreviousSymbol,LMcurrentSymbol;
  2749. function LMparseSexpr(str) { //parses str and returns [node,tailstr,(node)tag]
  2750. var symbol, node, result, result2, i, st,// rightvert = false,
  2751. newFrag = document.createDocumentFragment();
  2752. str = LMremoveCharsAndBlanks(str,0);
  2753. symbol = LMgetSymbol(str); //either a token or a bracket or empty
  2754. if (symbol == null || symbol.ttype == RIGHTBRACKET)
  2755. return [null,str,null];
  2756. if (symbol.ttype == DEFINITION) {
  2757. str = symbol.output+LMremoveCharsAndBlanks(str,symbol.input.length);
  2758. symbol = LMgetSymbol(str);
  2759. if (symbol == null || symbol.ttype == RIGHTBRACKET)
  2760. return [null,str,null];
  2761. }
  2762. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  2763. switch (symbol.ttype) {
  2764. case SPACE:
  2765. node = createMmlNode(symbol.tag);
  2766. node.setAttribute(symbol.atname,symbol.atval);
  2767. return [node,str,symbol.tag];
  2768. case UNDEROVER:
  2769. if (isIE) {
  2770. if (symbol.input.substr(0,4) == "\\big") { // botch for missing symbols
  2771. str = "\\"+symbol.input.substr(4)+str; // make \bigcup = \cup etc.
  2772. symbol = LMgetSymbol(str);
  2773. symbol.ttype = UNDEROVER;
  2774. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  2775. }
  2776. }
  2777. return [createMmlNode(symbol.tag,
  2778. document.createTextNode(symbol.output)),str,symbol.tag];
  2779. case CONST:
  2780. var output = symbol.output;
  2781. if (isIE) {
  2782. if (symbol.input == "'")
  2783. output = "\u2032";
  2784. else if (symbol.input == "''")
  2785. output = "\u2033";
  2786. else if (symbol.input == "'''")
  2787. output = "\u2033\u2032";
  2788. else if (symbol.input == "''''")
  2789. output = "\u2033\u2033";
  2790. else if (symbol.input == "\\square")
  2791. output = "\u25A1"; // same as \Box
  2792. else if (symbol.input.substr(0,5) == "\\frac") {
  2793. // botch for missing fractions
  2794. var denom = symbol.input.substr(6,1);
  2795. if (denom == "5" || denom == "6") {
  2796. str = symbol.input.replace(/\\frac/,"\\frac ")+str;
  2797. return [node,str,symbol.tag];
  2798. }
  2799. }
  2800. }
  2801. node = createMmlNode(symbol.tag,document.createTextNode(output));
  2802. return [node,str,symbol.tag];
  2803. case LONG: // added by DRW
  2804. node = createMmlNode(symbol.tag,document.createTextNode(symbol.output));
  2805. node.setAttribute("minsize","1.5");
  2806. node.setAttribute("maxsize","1.5");
  2807. node = createMmlNode("mover",node);
  2808. node.appendChild(createMmlNode("mspace"));
  2809. return [node,str,symbol.tag];
  2810. case STRETCHY: // added by DRW
  2811. if (isIE && symbol.input == "\\backslash")
  2812. symbol.output = "\\"; // doesn't expand, but then nor does "\u2216"
  2813. node = createMmlNode(symbol.tag,document.createTextNode(symbol.output));
  2814. if (symbol.input == "|" || symbol.input == "\\vert" ||
  2815. symbol.input == "\\|" || symbol.input == "\\Vert") {
  2816. node.setAttribute("lspace","0em");
  2817. node.setAttribute("rspace","0em");
  2818. }
  2819. node.setAttribute("maxsize",symbol.atval); // don't allow to stretch here
  2820. if (symbol.rtag != null)
  2821. return [node,str,symbol.rtag];
  2822. else
  2823. return [node,str,symbol.tag];
  2824. case BIG: // added by DRW
  2825. var atval = symbol.atval;
  2826. if (isIE)
  2827. atval = symbol.ieval;
  2828. symbol = LMgetSymbol(str);
  2829. if (symbol == null)
  2830. return [null,str,null];
  2831. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  2832. node = createMmlNode(symbol.tag,document.createTextNode(symbol.output));
  2833. if (isIE) { // to get brackets to expand
  2834. var space = createMmlNode("mspace");
  2835. space.setAttribute("height",atval+"ex");
  2836. node = createMmlNode("mrow",node);
  2837. node.appendChild(space);
  2838. } else { // ignored in IE
  2839. node.setAttribute("minsize",atval);
  2840. node.setAttribute("maxsize",atval);
  2841. }
  2842. return [node,str,symbol.tag];
  2843. case LEFTBRACKET: //read (expr+)
  2844. if (symbol.input == "\\left") { // left what?
  2845. symbol = LMgetSymbol(str);
  2846. if (symbol != null) {
  2847. if (symbol.input == ".")
  2848. symbol.invisible = true;
  2849. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  2850. }
  2851. }
  2852. result = LMparseExpr(str,true,false);
  2853. if (symbol==null ||
  2854. (typeof symbol.invisible == "boolean" && symbol.invisible))
  2855. node = createMmlNode("mrow",result[0]);
  2856. else {
  2857. node = createMmlNode("mo",document.createTextNode(symbol.output));
  2858. node = createMmlNode("mrow",node);
  2859. node.appendChild(result[0]);
  2860. }
  2861. return [node,result[1],result[2]];
  2862. case MATRIX: //read (expr+)
  2863. if (symbol.input == "\\begin{array}") {
  2864. var mask = "";
  2865. symbol = LMgetSymbol(str);
  2866. str = LMremoveCharsAndBlanks(str,0);
  2867. if (symbol == null)
  2868. mask = "l";
  2869. else {
  2870. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  2871. if (symbol.input != "{")
  2872. mask = "l";
  2873. else do {
  2874. symbol = LMgetSymbol(str);
  2875. if (symbol != null) {
  2876. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  2877. if (symbol.input != "}")
  2878. mask = mask+symbol.input;
  2879. }
  2880. } while (symbol != null && symbol.input != "" && symbol.input != "}");
  2881. }
  2882. result = LMparseExpr("{"+str,true,true);
  2883. // if (result[0]==null) return [createMmlNode("mo",
  2884. // document.createTextNode(symbol.input)),str];
  2885. node = createMmlNode("mtable",result[0]);
  2886. mask = mask.replace(/l/g,"left ");
  2887. mask = mask.replace(/r/g,"right ");
  2888. mask = mask.replace(/c/g,"center ");
  2889. node.setAttribute("columnalign",mask);
  2890. node.setAttribute("displaystyle","false");
  2891. if (isIE)
  2892. return [node,result[1],null];
  2893. // trying to get a *little* bit of space around the array
  2894. // (IE already includes it)
  2895. var lspace = createMmlNode("mspace");
  2896. lspace.setAttribute("width","0.167em");
  2897. var rspace = createMmlNode("mspace");
  2898. rspace.setAttribute("width","0.167em");
  2899. var node1 = createMmlNode("mrow",lspace);
  2900. node1.appendChild(node);
  2901. node1.appendChild(rspace);
  2902. return [node1,result[1],null];
  2903. } else { // eqnarray
  2904. result = LMparseExpr("{"+str,true,true);
  2905. node = createMmlNode("mtable",result[0]);
  2906. if (isIE)
  2907. node.setAttribute("columnspacing","0.25em"); // best in practice?
  2908. else
  2909. node.setAttribute("columnspacing","0.167em"); // correct (but ignored?)
  2910. node.setAttribute("columnalign","right center left");
  2911. node.setAttribute("displaystyle","true");
  2912. node = createMmlNode("mrow",node);
  2913. return [node,result[1],null];
  2914. }
  2915. case TEXT:
  2916. if (str.charAt(0)=="{") i=str.indexOf("}");
  2917. else i = 0;
  2918. if (i==-1)
  2919. i = str.length;
  2920. st = str.slice(1,i);
  2921. if (st.charAt(0) == " ") {
  2922. node = createMmlNode("mspace");
  2923. node.setAttribute("width","0.33em"); // was 1ex
  2924. newFrag.appendChild(node);
  2925. }
  2926. newFrag.appendChild(
  2927. createMmlNode(symbol.tag,document.createTextNode(st)));
  2928. if (st.charAt(st.length-1) == " ") {
  2929. node = createMmlNode("mspace");
  2930. node.setAttribute("width","0.33em"); // was 1ex
  2931. newFrag.appendChild(node);
  2932. }
  2933. str = LMremoveCharsAndBlanks(str,i+1);
  2934. return [createMmlNode("mrow",newFrag),str,null];
  2935. case UNARY:
  2936. result = LMparseSexpr(str);
  2937. if (result[0]==null) return [createMmlNode(symbol.tag,
  2938. document.createTextNode(symbol.output)),str];
  2939. if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
  2940. st = str.charAt(0);
  2941. // if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
  2942. if (st=="^" || st=="_" || st==",") {
  2943. return [createMmlNode(symbol.tag,
  2944. document.createTextNode(symbol.output)),str,symbol.tag];
  2945. } else {
  2946. node = createMmlNode("mrow",
  2947. createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
  2948. if (isIE) {
  2949. var space = createMmlNode("mspace");
  2950. space.setAttribute("width","0.167em");
  2951. node.appendChild(space);
  2952. }
  2953. node.appendChild(result[0]);
  2954. return [node,result[1],symbol.tag];
  2955. }
  2956. }
  2957. if (symbol.input == "\\sqrt") { // sqrt
  2958. if (isIE) { // set minsize, for \surd
  2959. var space = createMmlNode("mspace");
  2960. space.setAttribute("height","1.2ex");
  2961. space.setAttribute("width","0em"); // probably no effect
  2962. node = createMmlNode(symbol.tag,result[0])
  2963. // node.setAttribute("minsize","1"); // ignored
  2964. // node = createMmlNode("mrow",node); // hopefully unnecessary
  2965. node.appendChild(space);
  2966. return [node,result[1],symbol.tag];
  2967. } else
  2968. return [createMmlNode(symbol.tag,result[0]),result[1],symbol.tag];
  2969. } else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
  2970. node = createMmlNode(symbol.tag,result[0]);
  2971. var output = symbol.output;
  2972. if (isIE) {
  2973. if (symbol.input == "\\hat")
  2974. output = "\u0302";
  2975. else if (symbol.input == "\\widehat")
  2976. output = "\u005E";
  2977. else if (symbol.input == "\\bar")
  2978. output = "\u00AF";
  2979. else if (symbol.input == "\\grave")
  2980. output = "\u0300";
  2981. else if (symbol.input == "\\tilde")
  2982. output = "\u0303";
  2983. }
  2984. var node1 = createMmlNode("mo",document.createTextNode(output));
  2985. if (symbol.input == "\\vec" || symbol.input == "\\check")
  2986. // don't allow to stretch
  2987. node1.setAttribute("maxsize","1.2");
  2988. // why doesn't "1" work? \vec nearly disappears in firefox
  2989. if (isIE && symbol.input == "\\bar")
  2990. node1.setAttribute("maxsize","0.5");
  2991. if (symbol.input == "\\underbrace" || symbol.input == "\\underline")
  2992. node1.setAttribute("accentunder","true");
  2993. else
  2994. node1.setAttribute("accent","true");
  2995. node.appendChild(node1);
  2996. if (symbol.input == "\\overbrace" || symbol.input == "\\underbrace")
  2997. node.ttype = UNDEROVER;
  2998. return [node,result[1],symbol.tag];
  2999. } else { // font change or displaystyle command
  3000. if (!isIE && typeof symbol.codes != "undefined") {
  3001. for (i=0; i<result[0].childNodes.length; i++)
  3002. if (result[0].childNodes[i].nodeName=="mi" || result[0].nodeName=="mi") {
  3003. st = (result[0].nodeName=="mi"?result[0].firstChild.nodeValue:
  3004. result[0].childNodes[i].firstChild.nodeValue);
  3005. var newst = [];
  3006. for (var j=0; j<st.length; j++)
  3007. if (st.charCodeAt(j)>64 && st.charCodeAt(j)<91) newst = newst +
  3008. symbol.codes[st.charCodeAt(j)-65];
  3009. else newst = newst + st.charAt(j);
  3010. if (result[0].nodeName=="mi")
  3011. result[0]=createMmlNode("mo").
  3012. appendChild(document.createTextNode(newst));
  3013. else result[0].replaceChild(createMmlNode("mo").
  3014. appendChild(document.createTextNode(newst)),result[0].childNodes[i]);
  3015. }
  3016. }
  3017. node = createMmlNode(symbol.tag,result[0]);
  3018. node.setAttribute(symbol.atname,symbol.atval);
  3019. if (symbol.input == "\\scriptstyle" ||
  3020. symbol.input == "\\scriptscriptstyle")
  3021. node.setAttribute("displaystyle","false");
  3022. return [node,result[1],symbol.tag];
  3023. }
  3024. case BINARY:
  3025. result = LMparseSexpr(str);
  3026. if (result[0]==null) return [createMmlNode("mo",
  3027. document.createTextNode(symbol.input)),str,null];
  3028. result2 = LMparseSexpr(result[1]);
  3029. if (result2[0]==null) return [createMmlNode("mo",
  3030. document.createTextNode(symbol.input)),str,null];
  3031. if (symbol.input=="\\textcolor" || symbol.input=="\\colorbox") {
  3032. var tclr = str.match(/\{\s*([#\w]+)\s*\}/); //get's color from beginning of str
  3033. str = str.replace(/\{\s*[#\w]+\s*\}/,"");
  3034. if(tclr!=null) {
  3035. if(IsColorName.test(tclr[1].toLowerCase())) {
  3036. tclr=LaTeXColor[tclr[1].toLowerCase()];
  3037. } else {
  3038. tclr=tclr[1]; // no checking for valid color!!
  3039. }
  3040. node = createMmlNode("mstyle");
  3041. node.setAttribute(symbol.atval,tclr);
  3042. node.appendChild(result2[0]);
  3043. return [node,result2[1],symbol.tag];
  3044. }
  3045. }
  3046. if (symbol.input=="\\density") {
  3047. var tclrf = str.match(/\{\s*([#\w]+)\s*\}/); //get's size from beginning of str
  3048. str = str.replace(/\{\s*[#\w]+\s*\}/,"");
  3049. if(tclrf!=null) {
  3050. if(tclrf[1]>1000) {
  3051. tclrf=1000+'%';
  3052. } else {
  3053. tclrf=tclrf[1]+'%';
  3054. }
  3055. node = createMmlNode("mstyle");
  3056. node.setAttribute(symbol.atval,tclrf);
  3057. node.appendChild(result2[0]);
  3058. return [node,result2[1],symbol.tag];
  3059. }
  3060. }
  3061. if (symbol.input=="\\root" || symbol.input=="\\stackrel")
  3062. newFrag.appendChild(result2[0]);
  3063. newFrag.appendChild(result[0]);
  3064. if (symbol.input=="\\frac") newFrag.appendChild(result2[0]);
  3065. return [createMmlNode(symbol.tag,newFrag),result2[1],symbol.tag];
  3066. case INFIX:
  3067. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  3068. return [createMmlNode("mo",document.createTextNode(symbol.output)),
  3069. str,symbol.tag];
  3070. default:
  3071. return [createMmlNode(symbol.tag, //its a constant
  3072. document.createTextNode(symbol.output)),str,symbol.tag];
  3073. }
  3074. }
  3075. function LMparseIexpr(str) {
  3076. var symbol, sym1, sym2, node, result, tag, underover;
  3077. str = LMremoveCharsAndBlanks(str,0);
  3078. sym1 = LMgetSymbol(str);
  3079. result = LMparseSexpr(str);
  3080. node = result[0];
  3081. str = result[1];
  3082. tag = result[2];
  3083. symbol = LMgetSymbol(str);
  3084. if (symbol.ttype == INFIX) {
  3085. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  3086. result = LMparseSexpr(str);
  3087. if (result[0] == null) // show box in place of missing argument
  3088. result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
  3089. str = result[1];
  3090. tag = result[2];
  3091. if (symbol.input == "_" || symbol.input == "^") {
  3092. sym2 = LMgetSymbol(str);
  3093. tag = null; // no space between x^2 and a following sin, cos, etc.
  3094. // This is for \underbrace and \overbrace
  3095. underover = ((sym1.ttype == UNDEROVER) || (node.ttype == UNDEROVER));
  3096. // underover = (sym1.ttype == UNDEROVER);
  3097. if (symbol.input == "_" && sym2.input == "^") {
  3098. str = LMremoveCharsAndBlanks(str,sym2.input.length);
  3099. var res2 = LMparseSexpr(str);
  3100. str = res2[1];
  3101. tag = res2[2]; // leave space between x_1^2 and a following sin etc.
  3102. node = createMmlNode((underover?"munderover":"msubsup"),node);
  3103. node.appendChild(result[0]);
  3104. node.appendChild(res2[0]);
  3105. } else if (symbol.input == "_") {
  3106. node = createMmlNode((underover?"munder":"msub"),node);
  3107. node.appendChild(result[0]);
  3108. } else {
  3109. node = createMmlNode((underover?"mover":"msup"),node);
  3110. node.appendChild(result[0]);
  3111. }
  3112. node = createMmlNode("mrow",node); // so sum does not stretch
  3113. } else {
  3114. node = createMmlNode(symbol.tag,node);
  3115. if (symbol.input == "\\atop" || symbol.input == "\\choose")
  3116. node.setAttribute("linethickness","0ex");
  3117. node.appendChild(result[0]);
  3118. if (symbol.input == "\\choose")
  3119. node = createMmlNode("mfenced",node);
  3120. }
  3121. }
  3122. return [node,str,tag];
  3123. }
  3124. function LMparseExpr(str,rightbracket,matrix) {
  3125. var symbol, node, result, i, tag,
  3126. newFrag = document.createDocumentFragment();
  3127. do {
  3128. str = LMremoveCharsAndBlanks(str,0);
  3129. result = LMparseIexpr(str);
  3130. node = result[0];
  3131. str = result[1];
  3132. tag = result[2];
  3133. symbol = LMgetSymbol(str);
  3134. if (node!=undefined) {
  3135. if ((tag == "mn" || tag == "mi") && symbol!=null &&
  3136. typeof symbol.func == "boolean" && symbol.func) {
  3137. // Add space before \sin in 2\sin x or x\sin x
  3138. var space = createMmlNode("mspace");
  3139. space.setAttribute("width","0.167em");
  3140. node = createMmlNode("mrow",node);
  3141. node.appendChild(space);
  3142. }
  3143. newFrag.appendChild(node);
  3144. }
  3145. } while ((symbol.ttype != RIGHTBRACKET)
  3146. && symbol!=null && symbol.output!="");
  3147. tag = null;
  3148. if (symbol.ttype == RIGHTBRACKET) {
  3149. if (symbol.input == "\\right") { // right what?
  3150. str = LMremoveCharsAndBlanks(str,symbol.input.length);
  3151. symbol = LMgetSymbol(str);
  3152. if (symbol != null && symbol.input == ".")
  3153. symbol.invisible = true;
  3154. if (symbol != null)
  3155. tag = symbol.rtag;
  3156. }
  3157. if (symbol!=null)
  3158. str = LMremoveCharsAndBlanks(str,symbol.input.length); // ready to return
  3159. var len = newFrag.childNodes.length;
  3160. if (matrix &&
  3161. len>0 && newFrag.childNodes[len-1].nodeName == "mrow" && len>1 &&
  3162. newFrag.childNodes[len-2].nodeName == "mo" &&
  3163. newFrag.childNodes[len-2].firstChild.nodeValue == "&") { //matrix
  3164. var pos = []; // positions of ampersands
  3165. var m = newFrag.childNodes.length;
  3166. for (i=0; matrix && i<m; i=i+2) {
  3167. pos[i] = [];
  3168. node = newFrag.childNodes[i];
  3169. for (var j=0; j<node.childNodes.length; j++)
  3170. if (node.childNodes[j].firstChild.nodeValue=="&")
  3171. pos[i][pos[i].length]=j;
  3172. }
  3173. var row, frag, n, k, table = document.createDocumentFragment();
  3174. for (i=0; i<m; i=i+2) {
  3175. row = document.createDocumentFragment();
  3176. frag = document.createDocumentFragment();
  3177. node = newFrag.firstChild; // <mrow> -&-&...&-&- </mrow>
  3178. n = node.childNodes.length;
  3179. k = 0;
  3180. for (j=0; j<n; j++) {
  3181. if (typeof pos[i][k] != "undefined" && j==pos[i][k]){
  3182. node.removeChild(node.firstChild); //remove &
  3183. row.appendChild(createMmlNode("mtd",frag));
  3184. k++;
  3185. } else frag.appendChild(node.firstChild);
  3186. }
  3187. row.appendChild(createMmlNode("mtd",frag));
  3188. if (newFrag.childNodes.length>2) {
  3189. newFrag.removeChild(newFrag.firstChild); //remove <mrow> </mrow>
  3190. newFrag.removeChild(newFrag.firstChild); //remove <mo>&</mo>
  3191. }
  3192. table.appendChild(createMmlNode("mtr",row));
  3193. }
  3194. return [table,str];
  3195. }
  3196. if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
  3197. node = createMmlNode("mo",document.createTextNode(symbol.output));
  3198. newFrag.appendChild(node);
  3199. }
  3200. }
  3201. return [newFrag,str,tag];
  3202. }
  3203. var tcnt = 0, dcnt = 0; //theorem and definition counters
  3204. function simpleLaTeXformatting(st) {
  3205. st = st.replace(/\$\$((.|\n)*?)\$\$/g,"<p align=\"center\">$\\displaystyle{$1}$</p>");
  3206. st = st.replace(/\\begin{(theorem|lemma|proposition|corollary)}((.|\n)*?)\\end{\1}/g,function(r,s,t){tcnt++; return "<b>"+s.charAt(0).toUpperCase()+s.slice(1)+" "+tcnt+".</b> <i>"+t.replace(/^\s*<\/?\w+\/?>|\s*<\/?\w+\/?>$/g,"")+"</i>"});
  3207. st = st.replace(/\\begin{(definition|example|remark|problem|exercise|conjecture|solution)}((.|\n)*?)\\end{\1}/g,function(r,s,t){dcnt++; return "<b>"+s.charAt(0).toUpperCase()+s.slice(1)+" "+dcnt+".</b> "+t.replace(/^\s*<\/?\w+\/?>|\s*<\/?\w+\/?>$/g,"")});
  3208. st = st.replace(/\\begin{proof}((.|\n)*?)\\end{proof}/g,function(s,t){return "<i>Proof:</i> "+t.replace(/^\s*<\/?\w+\/?>|\s*<\/?\w+\/?>$/g,"")+" &#x25A1;"});
  3209. st = st.replace(/\\emph{(.*?)}/g,"<em>$1</em>");
  3210. st = st.replace(/\\textbf{(.*?)}/g,"<b>$1</b>");
  3211. st = st.replace(/\\cite{(.*?)}/g,"[$1]");
  3212. st = st.replace(/\\chapter{(.*?)}/g,"<h2>$1</h2>");
  3213. st = st.replace(/\\section{(.*?)}(\s*<\/?(br|p)\s?\/?>)?/g,"<h3>$1</h3>");
  3214. st = st.replace(/\\subsection{((.|\n)*?)}/g,"<h4>$1</h4>");
  3215. st = st.replace(/\\begin{itemize}(\s*<\/?(br|p)\s?\/?>)?/g,"<ul>");
  3216. st = st.replace(/\\item\s((.|\n)*?)(?=(\\item|\\end))/g,"<li>$1</li>");
  3217. st = st.replace(/\\end{itemize}(\s*<\/?(br|p)\s?\/?>)?/g,"</ul>");
  3218. st = st.replace(/\\begin{enumerate}(\s*<\/?(br|p)\s?\/?>)?/g,"<ol>");
  3219. st = st.replace(/\\end{enumerate}(\s*<\/?(br|p)\s?\/?>)?/g,"</ol>");
  3220. st = st.replace(/\\item\[(.*?)]{(.*?)}/g,"<dt>$1</dt><dd>$2</dd>");
  3221. st = st.replace(/\\begin{description}/g,"<dl>");
  3222. st = st.replace(/\\end{description}/g,"</dl>");
  3223. st = st.replace(/\\newline\b/g,"<br/>");
  3224. st = st.replace(/\\newpage\b/g,"<br style=\"page-break-after:always;\">");
  3225. st = st.replace(/\\par\b/g,"<p>&nbsp;</p>");
  3226. st = st.replace(/\\bigskip/g,"<p style=\"margin-bottom:0.5in\">&nbsp;</p>");
  3227. st = st.replace(/\\medskip/g,"<p style=\"margin-bottom:0.3in\">&nbsp;</p>");
  3228. st = st.replace(/\\smallskip/g,"<p style=\"margin-bottom:0.15in\">&nbsp;</p>");
  3229. st = st.replace(/\\begin{center}((.|\n)*?)\\end{center}/g,"<center>$1</center>");
  3230. return st
  3231. }
  3232. function ASCIIandgraphformatting(st) {
  3233. st = st.replace(/<sup>(.*?)<\/sup>(\s|(\S))/gi,"^{$1} $3");
  3234. //st = st.replace(/<\/?font.*?>/gi,""); // do this only in amath...endamath
  3235. st = st.replace(/(Proof:)/g,"<i>$1</i>");
  3236. st = st.replace(/QED/g,"&nbsp; &nbsp; &#x25A1;");
  3237. st = st.replace(/(\\?end{?a?math}?)/ig,"<span></span>$1");
  3238. st = st.replace(/(\bamath\b|\\begin{a?math})/ig,"<span></span>$1");
  3239. st = st.replace(/([>\n])(Theorem|Lemma|Proposition|Corollary|Definition|Example|Remark|Problem|Exercise|Conjecture|Solution)(:|\W\W?(\w|\s|-|\.)*?\W?:)/g,"$1<b>$2$3</b>");
  3240. st = st.replace(/<embed\s+class\s?=\s?"?ASCIIsvg"?/gi,"<embed class=\"ASCIIsvg\" src=\""+dsvglocation+"d.svg\" wmode=\"transparent\"");
  3241. st = st.replace(/(?:\\begin{a?graph}|\bagraph|\(:graph\s)((.|\n)*?)(?:\\end{a?graph}|enda?graph|:\))/g,function(s,t){return "<table><tr><td><div class=\"ASCIIsvg\"><embed class=\"ASCIIsvg\" src=\""+dsvglocation+"d.svg\" wmode=\"transparent\" script=\'"+t.replace(/<\/?(br|p|pre)\s?\/?>/gi,"\n")+"\'/></div></td></tr></table>"});
  3242. st = st.replace(/insertASCIIMathCalculator/g,"<div class=\"ASCIIMathCalculator\"></div>");
  3243. //alert(dsvglocation)
  3244. return st;
  3245. }
  3246. function LMprocessNode(n) {
  3247. var frag,st;
  3248. try {
  3249. st = n.innerHTML;
  3250. } catch(err) {};
  3251. var am = /amath\b|graph/i.test(st);
  3252. if ((st==null || st.indexOf("\$ ")!=-1 || st.indexOf("\$<")!=-1 ||
  3253. st.indexOf("\\begin")!=-1 || am || st.slice(-1)=="$" ||
  3254. st.indexOf("\$\n")!=-1)&& !/edit-content|HTMLArea|wikiedit|wpTextbox1/.test(st)){
  3255. if (!avoidinnerHTML && translateLaTeXformatting)
  3256. st = simpleLaTeXformatting(st);
  3257. if (st!=null && am && !avoidinnerHTML) {
  3258. st = ASCIIandgraphformatting(st);
  3259. }
  3260. st = st.replace(/%7E/g,"~"); // else PmWiki has url issues
  3261. //alert(st)
  3262. if (!avoidinnerHTML) n.innerHTML = st;
  3263. processNodeR(n,false,true);
  3264. }
  3265. /* if (isIE) { //needed to match size and font of formula to surrounding text
  3266. frag = document.getElementsByTagName('math');
  3267. for (var i=0;i<frag.length;i++) frag[i].update() //is this really needed?
  3268. }*/
  3269. }
  3270. /* ASCIIsvg.js
  3271. ==============
  3272. JavaScript routines to dynamically generate Scalable Vector Graphics
  3273. using a mathematical xy-coordinate system (y increases upwards) and
  3274. very intuitive JavaScript commands (no programming experience required).
  3275. ASCIIsvg.js is good for learning math and illustrating online math texts.
  3276. Works with Internet Explorer+Adobe SVGviewer and SVG enabled Mozilla/Firefox.
  3277. Ver 1.2.9 July 31, 2007 (c) Peter Jipsen http://www.chapman.edu/~jipsen
  3278. Latest version at http://math.chapman.edu/~jipsen/math/pub/ASCIIsvg.js
  3279. If you use it on a webpage, please send the URL to jipsen@chapman.edu
  3280. This program is free software; you can redistribute it and/or modify
  3281. it under the terms of the GNU Lesser General Public License as published by
  3282. the Free Software Foundation; either version 2.1 of the License, or (at
  3283. your option) any later version.
  3284. This program is distributed in the hope that it will be useful,
  3285. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3286. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  3287. General Public License (at http://www.gnu.org/license/lgpl.html)
  3288. for more details.*/
  3289. // you can change these
  3290. var checkIfSVGavailable = true;
  3291. // Modified by Ivan Tcholakov, 01-JUL-2010.
  3292. //var notifyIfNoSVG = true;
  3293. var notifyIfNoSVG = false;
  3294. //
  3295. var alertIfNoSVG = false;
  3296. var noSVG = false;
  3297. // global defaults used if not specified by graph (you can change these)
  3298. var defaultwidth = 300; var defaultheight = 200; // in pixels
  3299. var defaultxmin = -5.5; var defaultxmax = 5.5; // in usercoords
  3300. var defaultborder = 0; var border = defaultborder; // in pixel
  3301. var defaultstrokewidth = "1"; // default line width in pixel
  3302. var defaultstroke = "blue"; // default line color
  3303. var defaultstrokeopacity = 1; // transparent = 0, solid =1
  3304. var defaultstrokedasharray = null; // "10,10" gives 10px long dashes
  3305. var defaultfill = "none"; // default fill color
  3306. var defaultfillopacity = 1; // transparent = 0, solid =1
  3307. var defaultfontstyle = "normal"; // default text shape normal|italic|inherit
  3308. var defaultfontfamily = "times"; // default font times|ariel|helvetica|...
  3309. var defaultfontsize = "16"; // default size (scaled automatically)
  3310. var defaultfontweight = "normal";// normal|bold|bolder|lighter|100|...|900
  3311. var defaultfontstroke = "none"; // default font outline color
  3312. var defaultfontfill = "none"; // default font color
  3313. var defaultmarker = "none"; // "dot" | "arrow" | "+" | "-" | "|"
  3314. var defaultendpoints = ""; // "c-d" where c is <|o|* and d is >|o|*
  3315. // global values used for all pictures (you can change these)
  3316. var showcoordinates = true;
  3317. var markerstrokewidth = "1";
  3318. var markerstroke = "black";
  3319. var markerfill = "yellow";
  3320. var markersize = 4;
  3321. var arrowfill = stroke;
  3322. var dotradius = 4;
  3323. var ticklength = 4;
  3324. var axesstroke = "black";
  3325. var gridstroke = "grey";
  3326. var backgroundstyle = "fill-opacity:1; fill:white";
  3327. var singlelettersitalic = true;
  3328. // internal variables (probably no need to change these)
  3329. var picturepos = null; // position of picture relative to top of HTML page
  3330. var xunitlength; // in pixels, used to convert to user coordinates
  3331. var yunitlength; // in pixels
  3332. var origin = [0,0]; // in pixels (default is bottom left corner)
  3333. var above = "above"; // shorthands (to avoid typing quotes)
  3334. var below = "below";
  3335. var left = "left";
  3336. var right = "right";
  3337. var aboveleft = "aboveleft";
  3338. var aboveright = "aboveright";
  3339. var belowleft = "belowleft";
  3340. var belowright = "belowright";
  3341. var xmin, xmax, ymin, ymax, xscl, yscl,
  3342. xgrid, ygrid, xtick, ytick, initialized;
  3343. var strokewidth, strokedasharray, stroke, fill, strokeopacity, fillopacity;
  3344. var fontstyle, fontfamily, fontsize, fontweight, fontstroke, fontfill;
  3345. var marker, endpoints, dynamic = {};
  3346. var picture, svgpicture, doc, width, height;
  3347. var cpi = "\u03C0", ctheta = "\u03B8"; // character for pi, theta
  3348. var log = function(x) { return ln(x)/ln(10) };
  3349. var pi = Math.PI, e = Math.E, ln = Math.log, sqrt = Math.sqrt;
  3350. var floor = Math.floor, ceil = Math.ceil, abs = Math.abs;
  3351. var sin = Math.sin, cos = Math.cos, tan = Math.tan;
  3352. var arcsin = Math.asin, arccos = Math.acos, arctan = Math.atan;
  3353. var sec = function(x) { return 1/Math.cos(x) };
  3354. var csc = function(x) { return 1/Math.sin(x) };
  3355. var cot = function(x) { return 1/Math.tan(x) };
  3356. var arcsec = function(x) { return arccos(1/x) };
  3357. var arccsc = function(x) { return arcsin(1/x) };
  3358. var arccot = function(x) { return arctan(1/x) };
  3359. var sinh = function(x) { return (Math.exp(x)-Math.exp(-x))/2 };
  3360. var cosh = function(x) { return (Math.exp(x)+Math.exp(-x))/2 };
  3361. var tanh =
  3362. function(x) { return (Math.exp(x)-Math.exp(-x))/(Math.exp(x)+Math.exp(-x)) };
  3363. var sech = function(x) { return 1/cosh(x) };
  3364. var csch = function(x) { return 1/sinh(x) };
  3365. var coth = function(x) { return 1/tanh(x) };
  3366. var arcsinh = function(x) { return ln(x+Math.sqrt(x*x+1)) };
  3367. var arccosh = function(x) { return ln(x+Math.sqrt(x*x-1)) };
  3368. var arctanh = function(x) { return ln((1+x)/(1-x))/2 };
  3369. var arcsech = function(x) { return arccosh(1/x) };
  3370. var arccsch = function(x) { return arcsinh(1/x) };
  3371. var arccoth = function(x) { return arctanh(1/x) };
  3372. var sign = function(x) { return (x==0?0:(x<0?-1:1)) };
  3373. function factorial(x,n) { // Factorial function
  3374. if (n==null) n=1;
  3375. if (Math.abs(x-Math.round(x*1000000)/1000000)<1e-15)
  3376. x = Math.round(x*1000000)/1000000;
  3377. if (x-Math.floor(x)!=0) return NaN;
  3378. for (var i=x-n; i>0; i-=n) x*=i;
  3379. return (x<0?NaN:(x==0?1:x));
  3380. }
  3381. function C(x,k) { // Binomial coefficient function
  3382. var res=1;
  3383. for (var i=0; i<k; i++) res*=(x-i)/(k-i);
  3384. return res;
  3385. }
  3386. function chop(x,n) { // Truncate decimal number to n places after decimal point
  3387. if (n==null) n=0;
  3388. return Math.floor(x*Math.pow(10,n))/Math.pow(10,n);
  3389. }
  3390. function ran(a,b,n) { // Generate random number in [a,b] with n digits after .
  3391. if (n==null) n=0;
  3392. return chop((b+Math.pow(10,-n)-a)*Math.random()+a,n);
  3393. }
  3394. function myCreateElementSVG(t) {
  3395. if (isIE) return doc.createElement(t);
  3396. else return doc.createElementNS("http://www.w3.org/2000/svg",t);
  3397. }
  3398. function getElementsByClass(container, tagName, clsName){
  3399. var list = new Array(0);
  3400. var collection = container.getElementsByTagName(tagName);
  3401. for(var i = 0; i < collection.length; i++)
  3402. if(collection[i].className.slice(0,clsName.length)==clsName)
  3403. list[list.length] = collection[i];
  3404. return list;
  3405. }
  3406. function showobj(obj) {
  3407. var st="", i;
  3408. for (i in obj)
  3409. st += (obj.getAttribute(i)==null?"":" "+i+":"+obj.getAttribute(i));
  3410. return st;
  3411. }
  3412. function findPos(obj) { // top-left corner of obj on HTML page in pixel
  3413. var curleft = curtop = 0;
  3414. if (obj.offsetParent) {
  3415. curleft = obj.offsetLeft
  3416. curtop = obj.offsetTop
  3417. while (obj = obj.offsetParent) {
  3418. curleft += obj.offsetLeft
  3419. curtop += obj.offsetTop
  3420. //alert(showobj(obj)+[curleft,curtop])
  3421. }
  3422. }
  3423. return [curleft,curtop];
  3424. }
  3425. function checkSVG(){
  3426. if (navigator.appName.slice(0,8)=="Netscape")
  3427. if (window['SVGElement']) noSVG = null;
  3428. else noSVG = true;
  3429. else if (navigator.appName.slice(0,9)=="Microsoft")
  3430. try {
  3431. var oSVG=eval("new ActiveXObject('Adobe.SVGCtl.3');");
  3432. noSVG = null;
  3433. } catch (e) {
  3434. noSVG = true;
  3435. }
  3436. else if (navigator.appName.slice(0,5)=="Opera") // works only for 9.50b1
  3437. noSVG = null;
  3438. else noSVG = true;
  3439. //noSVG = true; //uncomment to check
  3440. if (noSVG && notifyIfNoSVG) {
  3441. var msg = "To view the ASCIIsvg images use Internet Explorer + Adobe SVGviewer or Mozilla Firefox 2.0 or later."
  3442. if (alertIfNoSVG)
  3443. alert(msg);
  3444. else return msg;
  3445. }
  3446. }
  3447. function setText(st,id) { // add text to an existing node with given id
  3448. var node = document.getElementById(id);
  3449. if (node!=null)
  3450. if (node.childNodes.length!=0) node.childNodes[0].nodeValue = st;
  3451. else node.appendChild(document.createTextNode(st));
  3452. }
  3453. function getX(evt) { // return mouse x-coord in user coordinate system
  3454. var svgroot = evt.target.parentNode;
  3455. pos = findPos(svgroot.parentNode);
  3456. return (evt.clientX+(isIE?0:window.pageXOffset)-pos[0]-svgroot.getAttribute("ox"))/parseFloat(svgroot.getAttribute("xunitlength"));
  3457. }
  3458. function getY(evt) { // return mouse y-coord in user coordinate system
  3459. var svgroot = evt.target.parentNode;
  3460. pos = findPos(svgroot.parentNode);
  3461. //alert(showobj(svgroot)+svgroot.getAttribute("mytop"))
  3462. return (svgroot.getAttribute("height")-svgroot.getAttribute("oy")-(evt.clientY+(isIE?0:window.pageYOffset)-pos[1]))/parseFloat(svgroot.getAttribute("yunitlength"));
  3463. }
  3464. function translateandeval(src) { //modify user input to JavaScript syntax
  3465. var errstr;
  3466. // replace plot(f(x),...) with plot("f(x)",...)
  3467. src = src.replace(/plot\(\x20*([^\"f\[][^\n\r;]+?)\,/g,"plot\(\"$1\",");
  3468. src = src.replace(/plot\(\x20*([^\"f\[][^\n\r;]+)\)/g,"plot(\"$1\")");
  3469. // replace (expr,expr) by [expr,expr] where expr has no (,) in it
  3470. src = src.replace(/([=[(,]\x20*)\(([-a-z0-9./+*]+?),([-a-z0-9./+*]+?)\)/g,"$1[$2,$3]");
  3471. //alert(src)
  3472. // insert * between digit and letter e.g. 2x --> 2*x
  3473. src = src.replace(/([0-9])([a-df-zA-Z]|e^)/g,"$1*$2");
  3474. src = src.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
  3475. try {
  3476. with (Math) eval(src); // here the svgpicture object is created
  3477. } catch(err) {
  3478. if (err!="wait") {
  3479. //alert(dsvglocation)
  3480. if (typeof err=="object")
  3481. errstr = err.name+" "+err.message+" "+err.number+" "+err.description;
  3482. else errstr = err;
  3483. alert(errstr+"\n"+src)
  3484. }
  3485. }
  3486. }
  3487. var lastSlot = 0;
  3488. function drawPictures() { // main routine; called after webpage has loaded
  3489. var src, id, dsvg, nd, node, ht, index, cols, arr, i, node2;
  3490. var ASbody = document.getElementsByTagName("body")[0];
  3491. pictures = getElementsByClass(ASbody,"embed","ASCIIsvg");
  3492. var len = pictures.length;
  3493. if(len==0) return;
  3494. for (index = lastSlot; index < len+lastSlot; index++) {
  3495. width = null; height = null;
  3496. xmin = null; xmax = null; ymin = null; ymax = null;
  3497. xscl = null; xgrid = null; yscl = null; ygrid = null;
  3498. initialized = false;
  3499. picture = pictures[index-lastSlot]; // current picture object
  3500. src = picture.getAttribute("script"); // get the ASCIIsvg code
  3501. if (src==null) src = "";
  3502. // insert "axes()" if not present ******** experimental
  3503. if (!/axes\b|initPicture/.test(src)) {
  3504. var i = 0;
  3505. while (/((yscl|ymax|ymin|xscl|xmax|xmin|\bwidth|\bheight)\s*=\s*-?\d*(\d\.|\.\d|\d)\d*\s*;?)/.test(src.slice(i))) i++;
  3506. src = (i==0?"axes(); "+src: src.slice(0,i)+src.slice(i).replace(/((scl|max|min|idth|eight)\s*=\s*-?\d*(\d\.|\.\d|\d)\d*\s*;?)/,"$1\naxes();"));
  3507. }
  3508. ht = picture.getAttribute("height");
  3509. if (isIE) {
  3510. picture.setAttribute("wmode","transparent");
  3511. //alert("*"+picture.getAttribute("src")+dsvglocation);
  3512. //adding d.svg dynamically greates problems in IE...
  3513. // if (picture.getAttribute("src")=="") picture.setAttribute("src",dsvglocation+"d.svg");
  3514. }
  3515. if (document.getElementById("picture"+(index+1)+"mml")==null) {
  3516. picture.parentNode.style.position = "relative";
  3517. node = createElementXHTML("div");
  3518. node.style.position = "absolute";
  3519. node.style.top = "0px";
  3520. node.style.left = "0px";
  3521. node.setAttribute("id","picture"+(index+1)+"mml");
  3522. picture.parentNode.insertBefore(node,picture.nextSibling);
  3523. }
  3524. if (ht==null) ht ="";
  3525. // if (ht!="") defaultborder = 25;
  3526. if (ht=="" || src=="")
  3527. if (document.getElementById("picture"+(index+1)+"input")==null) {
  3528. node = createElementXHTML("textarea");
  3529. arr = src.split("\n");
  3530. cols = 0;
  3531. for (i=0;i<arr.length;i++) cols = Math.max(cols,arr[i].length);
  3532. node.setAttribute("rows",Math.min(10,arr.length)+1);
  3533. node.setAttribute("cols",Math.max(Math.min(60,cols),20)+5);
  3534. // node.setAttribute("style","display:block");
  3535. if (isIE) src = src.replace(/([^\r])\n/g,"$1\r");
  3536. node.appendChild(document.createTextNode(src));
  3537. if (src.indexOf("showcode()")==-1) node.style.display = "none";
  3538. node.setAttribute("id","picture"+(index+1)+"input");
  3539. picture.parentNode.insertBefore(node,picture.nextSibling);
  3540. picture.parentNode.insertBefore(createElementXHTML("br"),node);
  3541. node2 = createElementXHTML("button");
  3542. node2.setAttribute("id","picture"+(index+1)+"button");
  3543. if (isIE) node2.onclick = function() {updatePicture(this)};
  3544. else node2.setAttribute("onclick","updatePicture(this)");
  3545. node2.appendChild(document.createTextNode("Update"));
  3546. if (src.indexOf("showcode()")==-1) node2.style.display = "none";
  3547. picture.parentNode.insertBefore(node2,node);
  3548. // picture.parentNode.insertBefore(document.createTextNode("ASCII"),node);
  3549. picture.parentNode.insertBefore(createElementXHTML("br"),node);
  3550. } else src = document.getElementById("picture"+(index+1)+"input").value;
  3551. id = picture.getAttribute("id");
  3552. dsvg = picture.getAttribute("src");
  3553. if (id == null || id == "") {
  3554. id = "picture"+(index+1);
  3555. picture.setAttribute("id",id);
  3556. }
  3557. translateandeval(src);
  3558. }
  3559. lastSlot+=len;
  3560. }
  3561. function setdefaults() { //called before each graph is evaluated
  3562. strokewidth = defaultstrokewidth;
  3563. stroke = defaultstroke;
  3564. strokeopacity = defaultstrokeopacity;
  3565. strokedasharray = defaultstrokedasharray;
  3566. fill = defaultfill;
  3567. fillopacity = defaultfillopacity;
  3568. fontstyle = defaultfontstyle;
  3569. fontfamily = defaultfontfamily;
  3570. fontsize = defaultfontsize;
  3571. fontweight = defaultfontweight;
  3572. fontstroke = defaultfontstroke;
  3573. fontfill = defaultfontfill;
  3574. marker = defaultmarker;
  3575. endpoints = defaultendpoints;
  3576. }
  3577. function switchTo(id) { // used by dynamic code to select appropriate graph
  3578. if (id==undefined) return;
  3579. var name = id;
  3580. if (typeof name!="string") name = id.target.parentNode.getAttribute("name");
  3581. picture = document.getElementById(name);
  3582. width = picture.getAttribute("width")-0;
  3583. height = picture.getAttribute("height")-0;
  3584. setdefaults();
  3585. if ((picture.nodeName == "EMBED" || picture.nodeName == "embed") && isIE) {
  3586. svgpicture = picture.getSVGDocument().getElementById("root");
  3587. doc = picture.getSVGDocument();
  3588. } else {
  3589. svgpicture = picture;
  3590. doc = document;
  3591. }
  3592. xunitlength = parseFloat(svgpicture.getAttribute("xunitlength"));
  3593. yunitlength = parseFloat(svgpicture.getAttribute("yunitlength"));
  3594. xmin = parseFloat(svgpicture.getAttribute("xmin"));
  3595. xmax = parseFloat(svgpicture.getAttribute("xmax"));
  3596. ymin = parseFloat(svgpicture.getAttribute("ymin"));
  3597. ymax = parseFloat(svgpicture.getAttribute("ymax"));
  3598. origin = [svgpicture.getAttribute("ox")-0,svgpicture.getAttribute("oy")-0];
  3599. }
  3600. function updatePicture(obj) {
  3601. var node, src, id, top, left;
  3602. if (typeof obj=="object") id = obj.id.slice(0,-6);
  3603. else id = (typeof obj=="string"?obj:"picture"+(obj+1));
  3604. src = document.getElementById(id+"input").value;
  3605. xmin = null; xmax = null; ymin = null; ymax = null;
  3606. xscl = null; xgrid = null; yscl = null; ygrid = null;
  3607. initialized = false;
  3608. picture = document.getElementById(id);
  3609. translateandeval(src)
  3610. }
  3611. function changepicturesize(evt,factor) {
  3612. var obj = evt.target;
  3613. var name = obj.parentNode.getAttribute("name");
  3614. var pic = document.getElementById(name);
  3615. var src = document.getElementById(name+"input").value;
  3616. if (!/height/.test(src)) src = "height=0; "+src;
  3617. if (!/width/.test(src)) src = "width=0; "+src;
  3618. src = src.replace(/width\s*=\s*\d+/,"width="+(factor*(pic.getAttribute("width")-0)));
  3619. src = src.replace(/height\s*=\s*\d+/,"height="+(factor*(pic.getAttribute("height")-0)));
  3620. document.getElementById(name+"input").value = src;
  3621. //alert(getKey(evt.keycode))
  3622. updatePicture(name);
  3623. }
  3624. function zoom(evt,factor) {
  3625. switchTo(evt);
  3626. var obj = evt.target;
  3627. var name = obj.parentNode.getAttribute("name");
  3628. var pic = document.getElementById(name);
  3629. var src = document.getElementById(name+"input").value;
  3630. var xlen = (xmax-xmin)/2;
  3631. var ylen = (ymax-ymin)/2;
  3632. var xcen = getX(evt), ycen = getY(evt);
  3633. if (!/ymax/.test(src)) src = "ymax=0; "+src;
  3634. if (!/ymin/.test(src)) src = "ymin=0; "+src;
  3635. if (!/xmax/.test(src)) src = "xmax=0; "+src;
  3636. if (!/xmin/.test(src)) src = "xmin=0; "+src;
  3637. src = src.replace(/xmin\s*=\s*[-\d.e]+/,"xmin="+(xcen-factor*xlen));
  3638. src = src.replace(/xmax\s*=\s*[-\d.e]+/,"xmax="+(xcen+factor*xlen));
  3639. src = src.replace(/ymin\s*=\s*[-\d.e]+/,"ymin="+(ycen-factor*ylen));
  3640. src = src.replace(/ymax\s*=\s*[-\d.e]+/,"ymax="+(ycen+factor*ylen));
  3641. document.getElementById(name+"input").value = src;
  3642. updatePicture(name);
  3643. }
  3644. var sinceFirstClick = 0; // ondblclick simulation from
  3645. var dblClkTimer; // http://www.enja.org/david/?cat=13 Thanks!
  3646. function timer() {
  3647. if(sinceFirstClick<60) {
  3648. sinceFirstClick++;
  3649. setTimeout("timer()",10);
  3650. } else {
  3651. clearTimeout(dblClkTimer);
  3652. dblClkTimer = "";
  3653. }
  3654. }
  3655. function mClick(evt) {
  3656. if(sinceFirstClick!=0) {
  3657. if(sinceFirstClick <= 40) {
  3658. if (evt.shiftKey) {
  3659. if (evt.altKey) changepicturesize(evt,2);
  3660. else zoom(evt,.5);
  3661. } else if (evt.altKey) zoom(evt,2);//changepicturesize(evt,.5);
  3662. else showHideCode(evt); // do this on dblclick
  3663. clearTimeout(dblClkTimer);
  3664. dblClkTimer = "";
  3665. } else {
  3666. clearTimeout(dblClkTimer);
  3667. sinceFirstClick = 0;
  3668. dblClkTimer = setTimeout("timer()",10);
  3669. }
  3670. } else {
  3671. sinceFirstClick = 0;
  3672. dblClkTimer = setTimeout("timer()",10);
  3673. }
  3674. }
  3675. function showHideCode(evt) { // called by onclick event
  3676. // if (evt.getDetail()==2) {//getDetail unfortunately not in Firefox
  3677. var obj=evt.target;
  3678. var name = obj.parentNode.getAttribute("name");
  3679. var node = document.getElementById(name+"input");
  3680. // The try-catch block has been added by Ivan Tcholakov, 08-JAN-2011.
  3681. try {
  3682. //
  3683. node.style.display = (node.style.display == "none"?"":"none");
  3684. var node = document.getElementById(name+"button");
  3685. node.style.display = (node.style.display == "none"?"":"none");
  3686. //
  3687. } catch (ex) { }
  3688. //
  3689. // }
  3690. }
  3691. function showcode() {} // do nothing
  3692. function setBorder(x) { border = x } //deprecate
  3693. function initPicture(x_min,x_max,y_min,y_max) { // set up the graph
  3694. // usually called by axes() or noaxes(), but can be used directly
  3695. if (!initialized) {
  3696. setdefaults();
  3697. initialized = true;
  3698. if (x_min!=null) xmin = x_min;
  3699. if (x_max!=null) xmax = x_max;
  3700. if (y_min!=null) ymin = y_min;
  3701. if (y_max!=null) ymax = y_max;
  3702. if (xmin==null) xmin = defaultxmin;
  3703. if (xmax==null) xmax = defaultxmax;
  3704. if (typeof xmin != "number" || typeof xmax != "number" || xmin >= xmax)
  3705. alert("Picture requires at least two numbers: xmin < xmax");
  3706. else if (y_max != null && (typeof y_min != "number" ||
  3707. typeof y_max != "number" || y_min >= y_max))
  3708. alert("initPicture(xmin,xmax,ymin,ymax) requires numbers ymin < ymax");
  3709. else {
  3710. if (width==null) {
  3711. width = picture.getAttribute("width");
  3712. if (width==null || width=="") width=defaultwidth;
  3713. }
  3714. picture.setAttribute("width",width);
  3715. if (height==null) {
  3716. height = picture.getAttribute("height");
  3717. if (height==null || height=="") height=defaultheight;
  3718. }
  3719. picture.setAttribute("height",height);
  3720. xunitlength = (width-2*border)/(xmax-xmin);
  3721. yunitlength = xunitlength;
  3722. //alert(xmin+" "+xmax+" "+ymin+" "+ymax)
  3723. if (ymin==null) {
  3724. origin = [-xmin*xunitlength+border,height/2];
  3725. ymin = -(height-2*border)/(2*yunitlength);
  3726. ymax = -ymin;
  3727. } else {
  3728. if (ymax!=null) yunitlength = (height-2*border)/(ymax-ymin);
  3729. else ymax = (height-2*border)/yunitlength + ymin;
  3730. origin = [-xmin*xunitlength+border,-ymin*yunitlength+border];
  3731. }
  3732. if (isIE) {
  3733. if (picture.FULLSCREEN==undefined) {
  3734. setTimeout('drawPictures()',50);
  3735. throw "wait";
  3736. }
  3737. svgpicture = picture.getSVGDocument().getElementById("root");
  3738. if (svgpicture==null) {
  3739. setTimeout('drawPictures()',50);
  3740. throw "wait";
  3741. }
  3742. svgpicture = picture.getSVGDocument().getElementById("root");
  3743. while (svgpicture.childNodes.length>0)
  3744. svgpicture.removeChild(svgpicture.lastChild);
  3745. svgpicture.setAttribute("width",width);
  3746. svgpicture.setAttribute("height",height);
  3747. svgpicture.setAttribute("name",picture.getAttribute("id"));
  3748. doc = picture.getSVGDocument();
  3749. } else {
  3750. var qnode = document.createElementNS("http://www.w3.org/2000/svg","svg");
  3751. qnode.setAttribute("id",picture.getAttribute("id"));
  3752. qnode.setAttribute("name",picture.getAttribute("id"));
  3753. // qnode.setAttribute("style","display:inline");
  3754. qnode.setAttribute("width",picture.getAttribute("width"));
  3755. qnode.setAttribute("height",picture.getAttribute("height"));
  3756. picturepos = findPos(picture);
  3757. // qnode.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");
  3758. if (picture.parentNode!=null) {
  3759. picture.parentNode.replaceChild(qnode,picture);
  3760. } else {
  3761. svgpicture.parentNode.replaceChild(qnode,svgpicture);
  3762. }
  3763. svgpicture = qnode;
  3764. doc = document;
  3765. }
  3766. var nd = document.getElementById(picture.getAttribute("id")+"mml");
  3767. if (nd!=null) // clear out MathML layer
  3768. while (nd.childNodes.length>0) nd.removeChild(nd.lastChild);
  3769. svgpicture.setAttribute("xunitlength",xunitlength);
  3770. svgpicture.setAttribute("yunitlength",yunitlength);
  3771. svgpicture.setAttribute("xmin",xmin);
  3772. svgpicture.setAttribute("xmax",xmax);
  3773. svgpicture.setAttribute("ymin",ymin);
  3774. svgpicture.setAttribute("ymax",ymax);
  3775. svgpicture.setAttribute("ox",origin[0]);
  3776. svgpicture.setAttribute("oy",origin[1]);
  3777. var node = myCreateElementSVG("rect");
  3778. node.setAttribute("x","0");
  3779. node.setAttribute("y","0");
  3780. node.setAttribute("width",width);
  3781. node.setAttribute("height",height);
  3782. node.setAttribute("style",backgroundstyle);
  3783. svgpicture.appendChild(node);
  3784. // Modified by Ivan Tcholakov, 08-JAN-2011.
  3785. // These events are suppressed because for some browsers
  3786. // the coordinates are not calculated correctly.
  3787. // TODO: Calculation to be tested and corrected after IE9 release.
  3788. //svgpicture.setAttribute("onmousemove","displayCoord(evt)");
  3789. //svgpicture.setAttribute("onmouseout","removeCoord(evt)");
  3790. //
  3791. svgpicture.setAttribute("onclick","mClick(evt)");
  3792. node = myCreateElementSVG("text"); // used for displayCoord
  3793. node.appendChild(doc.createTextNode(" "));
  3794. node.setAttribute("id","coords");
  3795. svgpicture.appendChild(node);
  3796. node = myCreateElementSVG("text"); // used for text display
  3797. node.appendChild(doc.createTextNode(" "));
  3798. node.setAttribute("id","coords");
  3799. svgpicture.appendChild(node);
  3800. border = defaultborder;
  3801. }
  3802. }
  3803. }
  3804. //////////////////////////user graphics commands start/////////////////////////
  3805. function line(p,q,id,endpts) { // segment connecting points p,q (coordinates in units)
  3806. var node;
  3807. if (id!=null) node = doc.getElementById(id);
  3808. if (node==null) {
  3809. node = myCreateElementSVG("path");
  3810. node.setAttribute("id", id);
  3811. svgpicture.appendChild(node);
  3812. }
  3813. node.setAttribute("d","M"+(p[0]*xunitlength+origin[0])+","+
  3814. (height-p[1]*yunitlength-origin[1])+" "+
  3815. (q[0]*xunitlength+origin[0])+","+(height-q[1]*yunitlength-origin[1]));
  3816. node.setAttribute("stroke-width", strokewidth);
  3817. if (strokedasharray!=null)
  3818. node.setAttribute("stroke-dasharray", strokedasharray);
  3819. node.setAttribute("stroke", stroke);
  3820. node.setAttribute("fill", fill);
  3821. node.setAttribute("stroke-opacity", strokeopacity);
  3822. node.setAttribute("fill-opacity", fillopacity);
  3823. if (marker=="dot" || marker=="arrowdot") {
  3824. ASdot(p,markersize,markerstroke,markerfill);
  3825. if (marker=="arrowdot") arrowhead(p,q);
  3826. ASdot(q,markersize,markerstroke,markerfill);
  3827. } else if (marker=="arrow") arrowhead(p,q);
  3828. if (endpts==null && endpoints!="") endpts = endpoints;
  3829. if (endpts!=null) {
  3830. if (endpts.indexOf("<-") != -1) arrowhead(q,p);
  3831. if (endpts.indexOf("o-") != -1) dot(p, "open");
  3832. if (endpts.indexOf("*-") != -1) dot(p, "closed");
  3833. if (endpts.indexOf("->") != -1) arrowhead(p,q);
  3834. if (endpts.indexOf("-o") != -1) dot(q, "open");
  3835. if (endpts.indexOf("-*") != -1) dot(q, "closed");
  3836. }
  3837. }
  3838. function path(plist,id,c,endpts) {
  3839. if (c==null) c="";
  3840. var node, st, i;
  3841. if (id!=null) node = doc.getElementById(id);
  3842. if (node==null) {
  3843. node = myCreateElementSVG("path");
  3844. node.setAttribute("id", id);
  3845. svgpicture.appendChild(node);
  3846. }
  3847. if (typeof plist == "string") st = plist;
  3848. else {
  3849. st = "M";
  3850. st += (plist[0][0]*xunitlength+origin[0])+","+
  3851. (height-plist[0][1]*yunitlength-origin[1])+" "+c;
  3852. for (i=1; i<plist.length; i++)
  3853. st += (plist[i][0]*xunitlength+origin[0])+","+
  3854. (height-plist[i][1]*yunitlength-origin[1])+" ";
  3855. }
  3856. node.setAttribute("d", st);
  3857. node.setAttribute("stroke-width", strokewidth);
  3858. if (strokedasharray!=null)
  3859. node.setAttribute("stroke-dasharray", strokedasharray);
  3860. node.setAttribute("stroke", stroke);
  3861. node.setAttribute("fill", fill);
  3862. node.setAttribute("stroke-opacity", strokeopacity);
  3863. node.setAttribute("fill-opacity", fillopacity);
  3864. if (marker=="dot" || marker=="arrowdot")
  3865. for (i=0; i<plist.length; i++)
  3866. if (c!="C" && c!="T" || i!=1 && i!=2)
  3867. ASdot(plist[i],markersize,markerstroke,markerfill);
  3868. if (endpts==null && endpoints!="") endpts = endpoints;
  3869. if (endpts!=null) {
  3870. if (endpts.indexOf("<-") != -1) arrowhead(plist[1],plist[0]);
  3871. if (endpts.indexOf("o-") != -1) dot(plist[0], "open");
  3872. if (endpts.indexOf("*-") != -1) dot(plist[0], "closed");
  3873. if (endpts.indexOf("->") != -1) arrowhead(plist[plist.length-2],plist[plist.length-1]);
  3874. if (endpts.indexOf("-o") != -1) dot(plist[plist.length-1], "open");
  3875. if (endpts.indexOf("-*") != -1) dot(plist[plist.length-1], "closed");
  3876. }
  3877. }
  3878. function curve(plist,id,endpts) {
  3879. path(plist,id,"T",endpts);
  3880. }
  3881. function vector(p,q,id) {
  3882. line(p,q,id,"","->");
  3883. }
  3884. function circle(center,radius,id) { // coordinates in units
  3885. var node;
  3886. if (id!=null) node = doc.getElementById(id);
  3887. if (node==null) {
  3888. node = myCreateElementSVG("circle");
  3889. node.setAttribute("id", id);
  3890. svgpicture.appendChild(node);
  3891. }
  3892. node.setAttribute("cx",center[0]*xunitlength+origin[0]);
  3893. node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
  3894. node.setAttribute("r",radius*xunitlength);
  3895. node.setAttribute("stroke-width", strokewidth);
  3896. node.setAttribute("stroke", stroke);
  3897. node.setAttribute("fill", fill);
  3898. node.setAttribute("stroke-opacity", strokeopacity);
  3899. node.setAttribute("fill-opacity", fillopacity);
  3900. }
  3901. function loop(p,d,id) {
  3902. // d is a direction vector e.g. [1,0] means loop starts in that direction
  3903. if (d==null) d=[1,0];
  3904. path([p,[p[0]+d[0],p[1]+d[1]],[p[0]-d[1],p[1]+d[0]],p],id,"C");
  3905. if (marker=="arrow" || marker=="arrowdot")
  3906. arrowhead([p[0]+Math.cos(1.4)*d[0]-Math.sin(1.4)*d[1],
  3907. p[1]+Math.sin(1.4)*d[0]+Math.cos(1.4)*d[1]],p);
  3908. }
  3909. function arc(start,end,radius,id,largearc) { // coordinates in units
  3910. var node, v;
  3911. //alert([fill, stroke, origin, xunitlength, yunitlength, height])
  3912. if (id!=null) node = doc.getElementById(id);
  3913. if (largearc==null) largearc=0;
  3914. if (radius==null) {
  3915. v=[end[0]-start[0],end[1]-start[1]];
  3916. radius = Math.sqrt(v[0]*v[0]+v[1]*v[1]);
  3917. }
  3918. if (node==null) {
  3919. node = myCreateElementSVG("path");
  3920. node.setAttribute("id", id);
  3921. svgpicture.appendChild(node);
  3922. }
  3923. node.setAttribute("d","M"+(start[0]*xunitlength+origin[0])+","+
  3924. (height-start[1]*yunitlength-origin[1])+" A"+radius*xunitlength+","+
  3925. radius*yunitlength+" 0 "+largearc+",0 "+(end[0]*xunitlength+origin[0])+","+
  3926. (height-end[1]*yunitlength-origin[1]));
  3927. node.setAttribute("stroke-width", strokewidth);
  3928. node.setAttribute("stroke", stroke);
  3929. node.setAttribute("fill", fill);
  3930. node.setAttribute("stroke-opacity", strokeopacity);
  3931. node.setAttribute("fill-opacity", fillopacity);
  3932. if (marker=="arrow" || marker=="arrowdot") {
  3933. u = [(end[1]-start[1])/4,(start[0]-end[0])/4];
  3934. v = [(end[0]-start[0])/2,(end[1]-start[1])/2];
  3935. //alert([u,v])
  3936. v = [start[0]+v[0]+u[0],start[1]+v[1]+u[1]];
  3937. } else v=[start[0],start[1]];
  3938. if (marker=="dot" || marker=="arrowdot") {
  3939. ASdot(start,markersize,markerstroke,markerfill);
  3940. if (marker=="arrowdot") arrowhead(v,end);
  3941. ASdot(end,markersize,markerstroke,markerfill);
  3942. } else if (marker=="arrow") arrowhead(v,end);
  3943. }
  3944. function sector(center,start,end,id) { // center,start,end should be isoceles
  3945. var rx = start[0]-center[0], ry = start[1]-center[1];
  3946. arc(start,end,Math.sqrt(rx*rx+ry*ry),id+"arc");
  3947. path([end,center,start],id+"path");
  3948. }
  3949. function ellipse(center,rx,ry,id) { // coordinates in units
  3950. var node;
  3951. if (id!=null) node = doc.getElementById(id);
  3952. if (node==null) {
  3953. node = myCreateElementSVG("ellipse");
  3954. node.setAttribute("id", id);
  3955. svgpicture.appendChild(node);
  3956. }
  3957. node.setAttribute("cx",center[0]*xunitlength+origin[0]);
  3958. node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
  3959. node.setAttribute("rx",rx*xunitlength);
  3960. node.setAttribute("ry",ry*yunitlength);
  3961. node.setAttribute("stroke-width", strokewidth);
  3962. node.setAttribute("stroke", stroke);
  3963. node.setAttribute("fill", fill);
  3964. node.setAttribute("stroke-opacity", strokeopacity);
  3965. node.setAttribute("fill-opacity", fillopacity);
  3966. }
  3967. function triangle(p,q,r,id) {
  3968. path([p,q,r,p],id)
  3969. }
  3970. function rect(p,q,id,rx,ry) { // opposite corners in units, rounded by radii
  3971. var node;
  3972. if (id!=null) node = doc.getElementById(id);
  3973. if (node==null) {
  3974. node = myCreateElementSVG("rect");
  3975. node.setAttribute("id", id);
  3976. svgpicture.appendChild(node);
  3977. }
  3978. node.setAttribute("x",p[0]*xunitlength+origin[0]);
  3979. node.setAttribute("y",height-q[1]*yunitlength-origin[1]);
  3980. node.setAttribute("width",(q[0]-p[0])*xunitlength);
  3981. node.setAttribute("height",(q[1]-p[1])*yunitlength);
  3982. if (rx!=null) node.setAttribute("rx",rx*xunitlength);
  3983. if (ry!=null) node.setAttribute("ry",ry*yunitlength);
  3984. node.setAttribute("stroke-width", strokewidth);
  3985. node.setAttribute("stroke", stroke);
  3986. node.setAttribute("fill", fill);
  3987. node.setAttribute("stroke-opacity", strokeopacity);
  3988. node.setAttribute("fill-opacity", fillopacity);
  3989. }
  3990. function text(p,st,pos,id,fontsty) {
  3991. var dnode, node, dx = 0, dy = fontsize/3, str = st.toString();
  3992. if (/(`|\$)/.test(str)) { // layer for ASCIIMathML and LaTeXMathML
  3993. dnode = document.getElementById(svgpicture.getAttribute("name")+"mml");
  3994. if (dnode!=null) {
  3995. if (id!=null) node = document.getElementById(id);
  3996. if (node==null) {
  3997. //alert(dnode.childNodes.length)
  3998. node = createElementXHTML("div");
  3999. node.setAttribute("id", id);
  4000. node.style.position = "absolute";
  4001. dnode.appendChild(node);
  4002. }
  4003. while (node.childNodes.length>0) node.removeChild(node.lastChild);
  4004. node.appendChild(document.createTextNode(str));
  4005. if (/`/.test(str)) AMprocessNode(node); else LMprocessNode(node);
  4006. dx = -node.offsetWidth/2;
  4007. dy = -node.offsetHeight/2;
  4008. if (pos!=null) {
  4009. if (/above/.test(pos)) dy = -node.offsetHeight;
  4010. if (/below/.test(pos)) dy = 0;
  4011. if (/right/.test(pos)) dx = 0;
  4012. if ( /left/.test(pos)) dx = -node.offsetWidth;
  4013. }
  4014. node.style.left = ""+(p[0]*xunitlength+origin[0]+dx)+"px";
  4015. node.style.top = ""+(height-p[1]*yunitlength-origin[1]+dy)+"px";
  4016. }
  4017. return p;
  4018. }
  4019. var textanchor = "middle"; // regular text goes into SVG
  4020. if (pos!=null) {
  4021. if (/above/.test(pos)) dy = -fontsize/2;
  4022. if (/below/.test(pos)) dy = fontsize-0;
  4023. if (/right/.test(pos)) {textanchor = "start"; dx = fontsize/4;}
  4024. if ( /left/.test(pos)) {textanchor = "end"; dx = -fontsize/4;}
  4025. }
  4026. if (id!=null) node = doc.getElementById(id);
  4027. if (node==null) {
  4028. node = myCreateElementSVG("text");
  4029. node.setAttribute("id", id);
  4030. svgpicture.appendChild(node);
  4031. node.appendChild(doc.createTextNode(str));
  4032. }
  4033. while (node.childNodes.length>1) node.removeChild(node.lastChild);
  4034. node.lastChild.nodeValue = "\xA0"+str+"\xA0";
  4035. node.setAttribute("x",p[0]*xunitlength+origin[0]+dx);
  4036. node.setAttribute("y",height-p[1]*yunitlength-origin[1]+dy);
  4037. node.setAttribute("font-style",(fontsty!=null?fontsty:
  4038. (str.search(/^[a-zA-Z]$/)!=-1?"italic":fontstyle)));
  4039. node.setAttribute("font-family",fontfamily);
  4040. node.setAttribute("font-size",fontsize);
  4041. node.setAttribute("font-weight",fontweight);
  4042. node.setAttribute("text-anchor",textanchor);
  4043. if (fontstroke!="none") node.setAttribute("stroke",fontstroke);
  4044. if (fontfill!="none") node.setAttribute("fill",fontfill);
  4045. return p;
  4046. }
  4047. function mtext(p,st,pos,fontsty,fontsz) { // method for updating text on an svg
  4048. // "this" is the text object or the svgpicture object
  4049. var textanchor = "middle";
  4050. var dx = 0; var dy = fontsize/3;
  4051. if (pos!=null) {
  4052. if (pos.slice(0,5)=="above") dy = -fontsize/2;
  4053. if (pos.slice(0,5)=="below") dy = fontsize-0;
  4054. if (pos.slice(0,5)=="right" || pos.slice(5,10)=="right") {
  4055. textanchor = "start";
  4056. dx = fontsize/2;
  4057. }
  4058. if (pos.slice(0,4)=="left" || pos.slice(5,9)=="left") {
  4059. textanchor = "end";
  4060. dx = -fontsize/2;
  4061. }
  4062. }
  4063. var node = this;
  4064. if (this.nodeName=="svg") {
  4065. node = myCreateElementSVG("text");
  4066. this.appendChild(node);
  4067. node.appendChild(doc.createTextNode(st));
  4068. }
  4069. node.lastChild.nodeValue = st;
  4070. node.setAttribute("x",p[0]+dx);
  4071. node.setAttribute("y",p[1]+dy);
  4072. node.setAttribute("font-style",(fontsty!=null?fontsty:fontstyle));
  4073. node.setAttribute("font-family",fontfamily);
  4074. node.setAttribute("font-size",(fontsz!=null?fontsz:fontsize));
  4075. node.setAttribute("font-weight",fontweight);
  4076. node.setAttribute("text-anchor",textanchor);
  4077. if (fontstroke!="none") node.setAttribute("stroke",fontstroke);
  4078. if (fontfill!="none") node.setAttribute("fill",fontfill);
  4079. }
  4080. function image(imgurl,p,w,h,id) { // not working yet
  4081. var node;
  4082. if (id!=null) node = doc.getElementById(id);
  4083. if (node==null) {
  4084. node = myCreateElementSVG("image");
  4085. node.setAttribute("id", id);
  4086. svgpicture.appendChild(node);
  4087. }
  4088. node.setAttribute("x",p[0]*xunitlength+origin[0]);
  4089. node.setAttribute("y",height-p[1]*yunitlength-origin[1]);
  4090. node.setAttribute("width",w);
  4091. node.setAttribute("height",h);
  4092. node.setAttribute("xlink:href", imgurl);
  4093. }
  4094. function ASdot(center,radius,s,f) { // coordinates in units, radius in pixel
  4095. if (s==null) s = stroke; if (f==null) f = fill;
  4096. var node = myCreateElementSVG("circle");
  4097. node.setAttribute("cx",center[0]*xunitlength+origin[0]);
  4098. node.setAttribute("cy",height-center[1]*yunitlength-origin[1]);
  4099. node.setAttribute("r",radius);
  4100. node.setAttribute("stroke-width", strokewidth);
  4101. node.setAttribute("stroke", s);
  4102. node.setAttribute("fill", f);
  4103. svgpicture.appendChild(node);
  4104. }
  4105. function dot(center, typ, label, pos, id) {
  4106. var node;
  4107. var cx = center[0]*xunitlength+origin[0];
  4108. var cy = height-center[1]*yunitlength-origin[1];
  4109. if (id!=null) node = doc.getElementById(id);
  4110. if (typ=="+" || typ=="-" || typ=="|") {
  4111. if (node==null) {
  4112. node = myCreateElementSVG("path");
  4113. node.setAttribute("id", id);
  4114. svgpicture.appendChild(node);
  4115. }
  4116. if (typ=="+") {
  4117. node.setAttribute("d",
  4118. " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy+
  4119. " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
  4120. node.setAttribute("stroke-width", .5);
  4121. node.setAttribute("stroke", axesstroke);
  4122. } else {
  4123. if (typ=="-") node.setAttribute("d",
  4124. " M "+(cx-ticklength)+" "+cy+" L "+(cx+ticklength)+" "+cy);
  4125. else node.setAttribute("d",
  4126. " M "+cx+" "+(cy-ticklength)+" L "+cx+" "+(cy+ticklength));
  4127. node.setAttribute("stroke-width", strokewidth);
  4128. node.setAttribute("stroke", stroke);
  4129. }
  4130. } else {
  4131. if (node==null) {
  4132. node = myCreateElementSVG("circle");
  4133. node.setAttribute("id", id);
  4134. svgpicture.appendChild(node);
  4135. }
  4136. node.setAttribute("cx",cx);
  4137. node.setAttribute("cy",cy);
  4138. node.setAttribute("r",dotradius);
  4139. node.setAttribute("stroke-width", strokewidth);
  4140. node.setAttribute("stroke", stroke);
  4141. node.setAttribute("fill", (typ=="open"?"white":
  4142. (typ=="closed"?stroke:markerfill)));
  4143. }
  4144. if (label!=null)
  4145. text(center,label,(pos==null?"below":pos),(id==null?id:id+"label"))
  4146. }
  4147. point = dot; //alternative name
  4148. function arrowhead(p,q) { // draw arrowhead at q (in units) add size param
  4149. var up;
  4150. var v = [p[0]*xunitlength+origin[0],height-p[1]*yunitlength-origin[1]];
  4151. var w = [q[0]*xunitlength+origin[0],height-q[1]*yunitlength-origin[1]];
  4152. var u = [w[0]-v[0],w[1]-v[1]];
  4153. var d = Math.sqrt(u[0]*u[0]+u[1]*u[1]);
  4154. if (d > 0.00000001) {
  4155. u = [u[0]/d, u[1]/d];
  4156. up = [-u[1],u[0]];
  4157. var node = myCreateElementSVG("path");
  4158. node.setAttribute("d","M "+(w[0]-15*u[0]-4*up[0])+" "+
  4159. (w[1]-15*u[1]-4*up[1])+" L "+(w[0]-3*u[0])+" "+(w[1]-3*u[1])+" L "+
  4160. (w[0]-15*u[0]+4*up[0])+" "+(w[1]-15*u[1]+4*up[1])+" z");
  4161. node.setAttribute("stroke-width", markerstrokewidth);
  4162. node.setAttribute("stroke", stroke); /*was markerstroke*/
  4163. node.setAttribute("fill", stroke); /*was arrowfill*/
  4164. node.setAttribute("stroke-opacity", strokeopacity);
  4165. node.setAttribute("fill-opacity", fillopacity);
  4166. svgpicture.appendChild(node);
  4167. }
  4168. }
  4169. function chopZ(st) {
  4170. var k = st.indexOf(".");
  4171. if (k==-1) return st;
  4172. for (var i=st.length-1; i>k && st.charAt(i)=="0"; i--);
  4173. if (i==k) i--;
  4174. return st.slice(0,i+1);
  4175. }
  4176. function grid(dx,dy) { // for backward compatibility
  4177. axes(dx,dy,null,dx,dy)
  4178. }
  4179. function noaxes() {
  4180. if (!initialized) initPicture();
  4181. }
  4182. function axes(dx,dy,labels,gdx,gdy) {
  4183. //xscl=x is equivalent to xtick=x; xgrid=x; labels=true;
  4184. var x, y, ldx, ldy, lx, ly, lxp, lyp, pnode, st;
  4185. if (!initialized) initPicture();
  4186. if (typeof dx=="string") { labels = dx; dx = null; }
  4187. if (typeof dy=="string") { gdx = dy; dy = null; }
  4188. if (xscl!=null) {dx = xscl; gdx = xscl; labels = dx}
  4189. if (yscl!=null) {dy = yscl; gdy = yscl}
  4190. if (xtick!=null) {dx = xtick}
  4191. if (ytick!=null) {dy = ytick}
  4192. dx = (dx==null?xunitlength:dx*xunitlength);
  4193. dy = (dy==null?dx:dy*yunitlength);
  4194. fontsize = Math.min(dx/2,dy/2,16); //alert(fontsize)
  4195. ticklength = fontsize/4;
  4196. if (xgrid!=null) gdx = xgrid;
  4197. if (ygrid!=null) gdy = ygrid;
  4198. if (gdx!=null) {
  4199. gdx = (typeof gdx=="string"?dx:gdx*xunitlength);
  4200. gdy = (gdy==null?dy:gdy*yunitlength);
  4201. pnode = myCreateElementSVG("path");
  4202. st="";
  4203. for (x = origin[0]; x<width; x = x+gdx)
  4204. st += " M"+x+",0"+" "+x+","+height;
  4205. for (x = origin[0]-gdx; x>0; x = x-gdx)
  4206. st += " M"+x+",0"+" "+x+","+height;
  4207. for (y = height-origin[1]; y<height; y = y+gdy)
  4208. st += " M0,"+y+" "+width+","+y;
  4209. for (y = height-origin[1]-gdy; y>0; y = y-gdy)
  4210. st += " M0,"+y+" "+width+","+y;
  4211. pnode.setAttribute("d",st);
  4212. pnode.setAttribute("stroke-width", .5);
  4213. pnode.setAttribute("stroke", gridstroke);
  4214. pnode.setAttribute("fill", fill);
  4215. svgpicture.appendChild(pnode);
  4216. }
  4217. pnode = myCreateElementSVG("path");
  4218. st="M0,"+(height-origin[1])+" "+width+","+
  4219. (height-origin[1])+" M"+origin[0]+",0 "+origin[0]+","+height;
  4220. for (x = origin[0]+dx; x<width; x = x+dx)
  4221. st += " M"+x+","+(height-origin[1]+ticklength)+" "+x+","+
  4222. (height-origin[1]-ticklength);
  4223. for (x = origin[0]-dx; x>0; x = x-dx)
  4224. st += " M"+x+","+(height-origin[1]+ticklength)+" "+x+","+
  4225. (height-origin[1]-ticklength);
  4226. for (y = height-origin[1]+dy; y<height; y = y+dy)
  4227. st += " M"+(origin[0]+ticklength)+","+y+" "+(origin[0]-ticklength)+","+y;
  4228. for (y = height-origin[1]-dy; y>0; y = y-dy)
  4229. st += " M"+(origin[0]+ticklength)+","+y+" "+(origin[0]-ticklength)+","+y;
  4230. if (labels!=null) with (Math) {
  4231. ldx = dx/xunitlength;
  4232. ldy = dy/yunitlength;
  4233. lx = (xmin>0 || xmax<0?xmin:0);
  4234. ly = (ymin>0 || ymax<0?ymin:0);
  4235. lxp = (ly==0?"below":"above");
  4236. lyp = (lx==0?"left":"right");
  4237. var ddx = floor(1.1-log(ldx)/log(10))+1;
  4238. var ddy = floor(1.1-log(ldy)/log(10))+1;
  4239. for (x = ldx; x<=xmax; x = x+ldx)
  4240. text([x,ly],chopZ(x.toFixed(ddx)),lxp);
  4241. for (x = -ldx; xmin<=x; x = x-ldx)
  4242. text([x,ly],chopZ(x.toFixed(ddx)),lxp);
  4243. for (y = ldy; y<=ymax; y = y+ldy)
  4244. text([lx,y],chopZ(y.toFixed(ddy)),lyp);
  4245. for (y = -ldy; ymin<=y; y = y-ldy)
  4246. text([lx,y],chopZ(y.toFixed(ddy)),lyp);
  4247. }
  4248. fontsize = defaultfontsize;
  4249. pnode.setAttribute("d",st);
  4250. pnode.setAttribute("stroke-width", .5);
  4251. pnode.setAttribute("stroke", axesstroke);
  4252. pnode.setAttribute("fill", fill);
  4253. pnode.setAttribute("stroke-opacity", strokeopacity);
  4254. pnode.setAttribute("fill-opacity", fillopacity);
  4255. svgpicture.appendChild(pnode);
  4256. }
  4257. function mathjs(st) {
  4258. //translate a math formula to js function notation
  4259. // a^b --> pow(a,b)
  4260. // na --> n*a
  4261. // (...)d --> (...)*d
  4262. // n! --> factorial(n)
  4263. // sin^-1 --> arcsin etc.
  4264. //while ^ in string, find term on left and right
  4265. //slice and concat new formula string
  4266. st = st.replace(/\s/g,"");
  4267. if (st.indexOf("^-1")!=-1) {
  4268. st = st.replace(/sin\^-1/g,"arcsin");
  4269. st = st.replace(/cos\^-1/g,"arccos");
  4270. st = st.replace(/tan\^-1/g,"arctan");
  4271. st = st.replace(/sec\^-1/g,"arcsec");
  4272. st = st.replace(/csc\^-1/g,"arccsc");
  4273. st = st.replace(/cot\^-1/g,"arccot");
  4274. st = st.replace(/sinh\^-1/g,"arcsinh");
  4275. st = st.replace(/cosh\^-1/g,"arccosh");
  4276. st = st.replace(/tanh\^-1/g,"arctanh");
  4277. st = st.replace(/sech\^-1/g,"arcsech");
  4278. st = st.replace(/csch\^-1/g,"arccsch");
  4279. st = st.replace(/coth\^-1/g,"arccoth");
  4280. }
  4281. st = st.replace(/^e$/g,"(Math.E)");
  4282. st = st.replace(/^e([^a-zA-Z])/g,"(Math.E)$1");
  4283. st = st.replace(/([^a-zA-Z])e/g,"$1(Math.E)");
  4284. // st = st.replace(/([^a-zA-Z])e([^a-zA-Z])/g,"$1(Math.E)$2");
  4285. st = st.replace(/([0-9])([\(a-zA-Z])/g,"$1*$2");
  4286. st = st.replace(/\)([\(0-9a-zA-Z])/g,"\)*$1");
  4287. var i,j,k, ch, nested;
  4288. while ((i=st.indexOf("^"))!=-1) {
  4289. //find left argument
  4290. if (i==0) return "Error: missing argument";
  4291. j = i-1;
  4292. ch = st.charAt(j);
  4293. if (ch>="0" && ch<="9") {// look for (decimal) number
  4294. j--;
  4295. while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
  4296. if (ch==".") {
  4297. j--;
  4298. while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
  4299. }
  4300. } else if (ch==")") {// look for matching opening bracket and function name
  4301. nested = 1;
  4302. j--;
  4303. while (j>=0 && nested>0) {
  4304. ch = st.charAt(j);
  4305. if (ch=="(") nested--;
  4306. else if (ch==")") nested++;
  4307. j--;
  4308. }
  4309. while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
  4310. j--;
  4311. } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
  4312. j--;
  4313. while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
  4314. j--;
  4315. } else {
  4316. return "Error: incorrect syntax in "+st+" at position "+j;
  4317. }
  4318. //find right argument
  4319. if (i==st.length-1) return "Error: missing argument";
  4320. k = i+1;
  4321. ch = st.charAt(k);
  4322. if (ch>="0" && ch<="9" || ch=="-") {// look for signed (decimal) number
  4323. k++;
  4324. while (k<st.length && (ch=st.charAt(k))>="0" && ch<="9") k++;
  4325. if (ch==".") {
  4326. k++;
  4327. while (k<st.length && (ch=st.charAt(k))>="0" && ch<="9") k++;
  4328. }
  4329. } else if (ch=="(") {// look for matching closing bracket and function name
  4330. nested = 1;
  4331. k++;
  4332. while (k<st.length && nested>0) {
  4333. ch = st.charAt(k);
  4334. if (ch=="(") nested++;
  4335. else if (ch==")") nested--;
  4336. k++;
  4337. }
  4338. } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
  4339. k++;
  4340. while (k<st.length && (ch=st.charAt(k))>="a" && ch<="z" ||
  4341. ch>="A" && ch<="Z") k++;
  4342. } else {
  4343. return "Error: incorrect syntax in "+st+" at position "+k;
  4344. }
  4345. st = st.slice(0,j+1)+"Math.pow("+st.slice(j+1,i)+","+st.slice(i+1,k)+")"+
  4346. st.slice(k);
  4347. }
  4348. while ((i=st.indexOf("!"))!=-1) {
  4349. //find left argument
  4350. if (i==0) return "Error: missing argument";
  4351. j = i-1;
  4352. ch = st.charAt(j);
  4353. if (ch>="0" && ch<="9") {// look for (decimal) number
  4354. j--;
  4355. while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
  4356. if (ch==".") {
  4357. j--;
  4358. while (j>=0 && (ch=st.charAt(j))>="0" && ch<="9") j--;
  4359. }
  4360. } else if (ch==")") {// look for matching opening bracket and function name
  4361. nested = 1;
  4362. j--;
  4363. while (j>=0 && nested>0) {
  4364. ch = st.charAt(j);
  4365. if (ch=="(") nested--;
  4366. else if (ch==")") nested++;
  4367. j--;
  4368. }
  4369. while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
  4370. j--;
  4371. } else if (ch>="a" && ch<="z" || ch>="A" && ch<="Z") {// look for variable
  4372. j--;
  4373. while (j>=0 && (ch=st.charAt(j))>="a" && ch<="z" || ch>="A" && ch<="Z")
  4374. j--;
  4375. } else {
  4376. return "Error: incorrect syntax in "+st+" at position "+j;
  4377. }
  4378. st = st.slice(0,j+1)+"factorial("+st.slice(j+1,i)+")"+st.slice(i+1);
  4379. }
  4380. return st;
  4381. }
  4382. function plot(fun,x_min,x_max,points,id,endpts) {
  4383. var pth = [];
  4384. var f = function(x) { return x }, g = fun;
  4385. var name = null;
  4386. if (typeof fun=="string")
  4387. eval("g = function(x){ with(Math) return "+mathjs(fun)+" }");
  4388. else if (typeof fun=="object") {
  4389. eval("f = function(t){ with(Math) return "+mathjs(fun[0])+" }");
  4390. eval("g = function(t){ with(Math) return "+mathjs(fun[1])+" }");
  4391. }
  4392. if (typeof x_min=="string") { name = x_min; x_min = xmin }
  4393. else name = id;
  4394. var min = (x_min==null?xmin:x_min);
  4395. var max = (x_max==null?xmax:x_max);
  4396. if (max <= min) { return null; }
  4397. var inc = max-min-0.000001*(max-min);
  4398. inc = (points==null?inc/200:inc/points);
  4399. var gt;
  4400. //alert(typeof g(min))
  4401. for (var t = min; t <= max; t += inc) {
  4402. gt = g(t);
  4403. if (!(isNaN(gt)||Math.abs(gt)=="Infinity")) pth[pth.length] = [f(t), gt];
  4404. }
  4405. path(pth,name,null,endpts);
  4406. return pth;
  4407. }
  4408. // make polar plot
  4409. // make Riemann sums
  4410. function slopefield(fun,dx,dy) {
  4411. var g = fun;
  4412. if (typeof fun=="string")
  4413. eval("g = function(x,y){ with(Math) return "+mathjs(fun)+" }");
  4414. var gxy,x,y,u,v,dz;
  4415. if (dx==null) dx=1;
  4416. if (dy==null) dy=1;
  4417. dz = Math.sqrt(dx*dx+dy*dy)/6;
  4418. var x_min = Math.ceil(xmin/dx);
  4419. var y_min = Math.ceil(ymin/dy);
  4420. for (x = x_min; x <= xmax; x += dx)
  4421. for (y = y_min; y <= ymax; y += dy) {
  4422. gxy = g(x,y);
  4423. if (!isNaN(gxy)) {
  4424. if (Math.abs(gxy)=="Infinity") {u = 0; v = dz;}
  4425. else {u = dz/Math.sqrt(1+gxy*gxy); v = gxy*u;}
  4426. line([x-u,y-v],[x+u,y+v]);
  4427. }
  4428. }
  4429. }
  4430. ///////////////////////user graphics commands end here/////////////////////////
  4431. function show_props(obj) {
  4432. var result = "";
  4433. for (var i=0; i< obj.childNodes.length; i++)
  4434. result += obj.childNodes.item(i) + "\n";
  4435. return result;
  4436. }
  4437. function displayCoord(evt) {
  4438. if (showcoordinates) {
  4439. var svgroot = evt.target.parentNode;
  4440. var nl = svgroot.childNodes;
  4441. for (var i=0; i<nl.length && nl.item(i).nodeName!="text"; i++);
  4442. var cnode = nl.item(i);
  4443. // Added by Ivan Tcholakov, 08-JAN-2011.
  4444. // Suppresing a javasript error that occurs on Opera 11.
  4445. if (typeof cnode != 'object') {
  4446. return;
  4447. }
  4448. //
  4449. cnode.mtext = mtext;
  4450. cnode.mtext([svgroot.getAttribute("width")-(-7),svgroot.getAttribute("height")-7],"("+getX(evt).toFixed(2)+", "+getY(evt).toFixed(2)+")", "left", "", "11");
  4451. /* var dnode = nl.item(i+1);
  4452. dnode.mtext = mtext;
  4453. dnode.mtext([0,svgroot.getAttribute("height")-6],"Try (shift/alt)-dblclick", "right", "", "8");
  4454. */ }
  4455. }
  4456. function removeCoord(evt) {
  4457. var svgroot = evt.target.parentNode;
  4458. var nl = svgroot.childNodes;
  4459. for (var i=0; i<nl.length && nl.item(i).nodeName!="text"; i++);
  4460. var cnode = nl.item(i);
  4461. // Added by Ivan Tcholakov, 08-JAN-2011.
  4462. // Suppresing a javasript error that occurs on Opera 11.
  4463. if (typeof cnode != 'object') {
  4464. return;
  4465. }
  4466. //
  4467. cnode.mtext = mtext;
  4468. cnode.mtext([svgroot.getAttribute("width")-0,svgroot.getAttribute("height")-0],"", "aboveleft", "");
  4469. /* var dnode = nl.item(i+1);
  4470. dnode.mtext = mtext;
  4471. dnode.mtext([0,svgroot.getAttribute("height")-0],"", "aboveright", "");
  4472. */}
  4473. function initASCIIMathCalculators(li) {
  4474. var i;
  4475. for (i=0; i<li.length; i++) {
  4476. li[i].innerHTML = calcstr;
  4477. AMprocessNode(li[i]);
  4478. }
  4479. li = document.getElementsByTagName("textarea");
  4480. var st;
  4481. for (i=0; i<li.length; i++) {
  4482. st = li[i].getAttribute("onkeyup");
  4483. if (st!=null) eval(String(st).replace(/function anonymous\(\)/,""));
  4484. }
  4485. }
  4486. function calculate(inputId,outputId) {
  4487. var str = document.getElementById(inputId).value;
  4488. var err = "";
  4489. var ind = str.lastIndexOf("\n");
  4490. if (ind==str.length-1) str = str.slice(0,ind);
  4491. str = str.slice(str.lastIndexOf("\n")+1);
  4492. try {
  4493. var res = eval(mathjs(str));
  4494. } catch(e) {
  4495. err = "syntax incomplete";
  4496. }
  4497. if (!isNaN(res) && res!="Infinity")
  4498. str = "`"+str+" =` "+(Math.abs(res-Math.round(res*1000000)/1000000)<1e-15?Math.round(res*1000000)/1000000:res)+err;
  4499. else if (str!="") str = "`"+str+"` = undefined"; //debug:+mathjs(str);
  4500. var outnode = document.getElementById(outputId);
  4501. var n = outnode.childNodes.length;
  4502. for (var i=0; i<n; i++)
  4503. outnode.removeChild(outnode.firstChild);
  4504. outnode.appendChild(document.createTextNode(str));
  4505. AMprocessNode(outnode);
  4506. }
  4507. function append(st){
  4508. document.getElementById('in').value+=st;
  4509. calculate('in','out');
  4510. document.getElementById('in').scrollTop = 1000;
  4511. document.getElementById('in').focus();
  4512. }
  4513. function clearTextArea(){
  4514. document.getElementById('in').value="";
  4515. calculate('in','out');
  4516. document.getElementById('in').focus();
  4517. }
  4518. function ASpreprocess() {
  4519. var ASbody = document.getElementsByTagName("body")[0];
  4520. pictures = ASbody.getElementsByTagName("embed");
  4521. //pictures = getElementsByClass(ASbody,"embed","ASCIIsvg");
  4522. var len = pictures.length;
  4523. for (var i=len-1; i>=0; i--) {
  4524. picture = pictures[i];
  4525. var sscr = picture.getAttribute("sscr");
  4526. if (sscr && sscr!='') {
  4527. if (noSVG) {
  4528. n = document.createElement('img');
  4529. n.setAttribute("style",picture.getAttribute("style"));
  4530. n.setAttribute("src",AScgiloc+'?sscr='+encodeURIComponent(picture.getAttribute("sscr")));
  4531. pn = picture.parentNode;
  4532. pn.replaceChild(n,picture);
  4533. } else {
  4534. com = parseShortScript(sscr);
  4535. picture.setAttribute("script",com);
  4536. //picture.className = "ASCIIsvg";
  4537. }
  4538. }
  4539. // Modified by Ivan Tcholakov, 06-JAN-2011.
  4540. //if (!noSVG) {
  4541. if (sscr && sscr!='' && !noSVG) {
  4542. //
  4543. picture.className = "ASCIIsvg";
  4544. }
  4545. }
  4546. }
  4547. //ShortScript format:
  4548. //xmin,xmax,ymin,ymax,xscl,yscl,labels,xgscl,ygscl,width,height plotcommands(see blow)
  4549. //plotcommands: type,eq1,eq2,startmaker,endmarker,xmin,xmax,color,strokewidth,strokedash
  4550. function parseShortScript(sscript,gw,gh) {
  4551. var sa= sscript.split(",");
  4552. if (gw && gh) {
  4553. sa[9] = gw;
  4554. sa[10] = gh;
  4555. sscript = sa.join(",");
  4556. }
  4557. if (sa.length > 10) {
  4558. commands = 'setBorder(5);';
  4559. commands += 'width=' +sa[9] + '; height=' +sa[10] + ';';
  4560. commands += 'initPicture(' + sa[0] +','+ sa[1] +','+ sa[2] +','+ sa[3] + ');';
  4561. commands += 'axes(' + sa[4] +','+ sa[5] +','+ sa[6] +','+ sa[7] +','+ sa[8]+ ');';
  4562. var inx = 11;
  4563. var eqnlist = 'Graphs: ';
  4564. while (sa.length > inx+9) {
  4565. commands += 'stroke="' + sa[inx+7] + '";';
  4566. commands += 'strokewidth="' + sa[inx+8] + '";'
  4567. //commands += 'strokedasharray="' + sa[inx+9] + '";'
  4568. if (sa[inx+9] != "") {
  4569. commands += 'strokedasharray="' + sa[inx+9].replace(/\s+/g,',') + '";';
  4570. }
  4571. if (sa[inx]=="slope") {
  4572. eqnlist += "dy/dx="+sa[inx+1] + "; ";
  4573. commands += 'slopefield("' + sa[inx+1] + '",' + sa[inx+2] + ',' + sa[inx+2] + ');';
  4574. } else {
  4575. if (sa[inx]=="func") {
  4576. eqnlist += "y="+sa[inx+1] + "; ";
  4577. eqn = '"' + sa[inx+1] + '"';
  4578. } else if (sa[inx] == "polar") {
  4579. eqnlist += "r="+sa[inx+1] + "; ";
  4580. eqn = '["cos(t)*(' + sa[inx+1] + ')","sin(t)*(' + sa[inx+1] + ')"]';
  4581. } else if (sa[inx] == "param") {
  4582. eqnlist += "[x,y]=["+sa[inx+1] + "," + sa[inx+2] + "]; ";
  4583. eqn = '["' + sa[inx+1] + '","'+ sa[inx+2] + '"]';
  4584. }
  4585. if (sa[inx+3] == 0) {
  4586. ep = '--';
  4587. } else if (sa[inx+3] == 1) {
  4588. ep = '<-';
  4589. } else if (sa[inx+3] == 2) {
  4590. ep = 'o-';
  4591. } else if (sa[inx+3] == 3) {
  4592. ep = '*-';
  4593. }
  4594. if (sa[inx+4] == 0) {
  4595. ep += '--';
  4596. } else if (sa[inx+4] == 1) {
  4597. ep += '->';
  4598. } else if (sa[inx+4] == 2) {
  4599. ep += '-o';
  4600. } else if (sa[inx+4] == 3) {
  4601. ep += '-*';
  4602. }
  4603. if (typeof eval(sa[inx+5]) == "number") {
  4604. // if ((sa[inx+5]!='null')&&(sa[inx+5].length>0)) {
  4605. //commands += 'myplot(' + eqn +',"' + sa[inx+3] + '","' + sa[inx+4]+'",' + sa[inx+5] + ',' + sa[inx+6] +');';
  4606. commands += 'plot(' + eqn +',' + sa[inx+5] + ',' + sa[inx+6] +',null,null,"' + ep +'");';
  4607. } else {
  4608. commands += 'plot(' + eqn +',null,null,null,null,"' + ep +'");';
  4609. }
  4610. }
  4611. inx += 10;
  4612. }
  4613. return commands;
  4614. }
  4615. }
  4616. var calcstr = "<table align=\"center\">\n<tr><th>\nASCIIMath Scientific Calculator\n</th></tr>\n<tr><td>\nClick in the box to use your keyboard or use the buttons\n</td></tr>\n<tr><td>\n<textarea id=\"in\" rows=\"3\" cols=\"40\" onkeyup=\"calculate('in','out')\"></textarea></td></tr>\n<tr><td height=\"50\">Result: &nbsp; &nbsp; <span id=\"out\"></span></td></tr>\n</table>\n<table align=\"center\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody align=\"center\">\n<tr>\n<td colspan=\"4\">\n<button onclick=\"append('sin^-1(')\"><font size=2>`sin^-1`</font></button><button onclick=\"append('cos^-1(')\"><font size=2>`cos^-1`</font></button><button onclick=\"append('tan^-1(')\"><font size=2>`tan^-1`</font></button></td>\n<td><button onclick=\"clearTextArea()\">&nbsp;`C`&nbsp;</button></td>\n\n</tr>\n<tr>\n<td><button onclick=\"append('pi')\">&nbsp;`pi` &nbsp;</button></td>\n<td><button onclick=\"append('sin(')\">&nbsp;`sin`</button></td>\n<td><button onclick=\"append('cos(')\">&nbsp;`cos`</button></td>\n<td><button onclick=\"append('tan(')\">&nbsp;`tan`</button></td>\n<td><button onclick=\"append('^')\">`x^y`</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('!')\">&nbsp; `!` &nbsp;</button></td>\n\n<td><button onclick=\"append('(')\"><font size=2>&nbsp;&nbsp;`(`&nbsp;&nbsp;</font></button></td>\n<td><button onclick=\"append(')')\"><font size=2>&nbsp;&nbsp;`)`&nbsp;&nbsp;</font></button></td>\n<td><button onclick=\"append('sqrt(')\"><font size=2>`sqrt({::}^\ )`</font></button></td>\n<td><button onclick=\"append('/')\">&nbsp;`-:\ `</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('log(')\">`log`</button></td>\n<td><button onclick=\"append('7')\">&nbsp; `7` &nbsp;</button></td>\n<td><button onclick=\"append('8')\">&nbsp; `8` &nbsp;</button></td>\n\n<td><button onclick=\"append('9')\">&nbsp; `9` &nbsp;</button></td>\n<td><button onclick=\"append('*')\">&nbsp;`times`&nbsp;</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('ln(')\">&nbsp;`ln`&nbsp;</button></td>\n<td><button onclick=\"append('4')\">&nbsp; `4` &nbsp;</button></td>\n<td><button onclick=\"append('5')\">&nbsp; `5` &nbsp;</button></td>\n<td><button onclick=\"append('6')\">&nbsp; `6` &nbsp;</button></td>\n\n<td><button onclick=\"append('-')\">&nbsp;`-{::}`&nbsp;</button></td>\n</tr>\n<tr>\n<td><button onclick=\"append('e')\">&nbsp; `e` &nbsp;</button></td>\n<td><button onclick=\"append('1')\">&nbsp;&nbsp;`1` &nbsp;</button></td>\n<td><button onclick=\"append('2')\">&nbsp; `2` &nbsp;</button></td>\n<td><button onclick=\"append('3')\">&nbsp; `3` &nbsp;</button></td>\n<td><button onclick=\"append('+')\">&nbsp;`+{::}`&nbsp;</button></td>\n\n</tr>\n<tr>\n<td> <!--button onclick=\"append('pi')\">&nbsp;`pi` &nbsp;</button--></td>\n<td><button onclick=\"append('0')\">&nbsp; `0` &nbsp;</button></td>\n<td><button onclick=\"append('.')\">&nbsp; `.` &nbsp;</button></td>\n<td><button onclick=\"append('\\n')\">&nbsp;`\"ent\"`</button></td>\n</tr>\n</tbody>\n</table>";
  4617. // GO1.1 Generic onload by Brothercake
  4618. // http://www.brothercake.com/
  4619. //onload function (replaces the onload="translate()" in the <body> tag)
  4620. function generic()
  4621. {
  4622. if(!init()) return;
  4623. if (translateOnLoad) {
  4624. var nd = document.getElementById("processasciimathinmoodle");
  4625. if (nd!=null) dsvglocation = nd.className;
  4626. if (nd!=null || !checkforprocessasciimathinmoodle) {
  4627. translate();
  4628. if (translateASCIIsvg) { ASpreprocess(); };
  4629. if (!noSVG && translateASCIIsvg) drawPictures();
  4630. }
  4631. var li = getElementsByClass(document,"div","ASCIIMathCalculator");
  4632. if (!noMathML && li.length>0) initASCIIMathCalculators(li);
  4633. }
  4634. };
  4635. //setup onload function
  4636. if(typeof window.addEventListener != 'undefined')
  4637. {
  4638. //.. gecko, safari, konqueror and standard
  4639. window.addEventListener('load', generic, false);
  4640. }
  4641. else if(typeof document.addEventListener != 'undefined')
  4642. {
  4643. //.. opera 7
  4644. document.addEventListener('load', generic, false);
  4645. }
  4646. else if(typeof window.attachEvent != 'undefined')
  4647. {
  4648. //.. win/ie
  4649. window.attachEvent('onload', generic);
  4650. }
  4651. //** remove this condition to degrade older browsers
  4652. else
  4653. {
  4654. //.. mac/ie5 and anything else that gets this far
  4655. //if there's an existing onload function
  4656. if(typeof window.onload == 'function')
  4657. {
  4658. //store it
  4659. var existing = onload;
  4660. //add new onload handler
  4661. window.onload = function()
  4662. {
  4663. //call existing onload function
  4664. existing();
  4665. //call generic onload function
  4666. generic();
  4667. };
  4668. }
  4669. else
  4670. {
  4671. //setup onload function
  4672. window.onload = generic;
  4673. }
  4674. }