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