ASCIIMathML.js 228 KB

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