katex.mjs 590 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380
  1. /**
  2. * Lexing or parsing positional information for error reporting.
  3. * This object is immutable.
  4. */
  5. class SourceLocation {
  6. // The + prefix indicates that these fields aren't writeable
  7. // Lexer holding the input string.
  8. // Start offset, zero-based inclusive.
  9. // End offset, zero-based exclusive.
  10. constructor(lexer, start, end) {
  11. this.lexer = void 0;
  12. this.start = void 0;
  13. this.end = void 0;
  14. this.lexer = lexer;
  15. this.start = start;
  16. this.end = end;
  17. }
  18. /**
  19. * Merges two `SourceLocation`s from location providers, given they are
  20. * provided in order of appearance.
  21. * - Returns the first one's location if only the first is provided.
  22. * - Returns a merged range of the first and the last if both are provided
  23. * and their lexers match.
  24. * - Otherwise, returns null.
  25. */
  26. static range(first, second) {
  27. if (!second) {
  28. return first && first.loc;
  29. } else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) {
  30. return null;
  31. } else {
  32. return new SourceLocation(first.loc.lexer, first.loc.start, second.loc.end);
  33. }
  34. }
  35. }
  36. /**
  37. * Interface required to break circular dependency between Token, Lexer, and
  38. * ParseError.
  39. */
  40. /**
  41. * The resulting token returned from `lex`.
  42. *
  43. * It consists of the token text plus some position information.
  44. * The position information is essentially a range in an input string,
  45. * but instead of referencing the bare input string, we refer to the lexer.
  46. * That way it is possible to attach extra metadata to the input string,
  47. * like for example a file name or similar.
  48. *
  49. * The position information is optional, so it is OK to construct synthetic
  50. * tokens if appropriate. Not providing available position information may
  51. * lead to degraded error reporting, though.
  52. */
  53. class Token {
  54. // don't expand the token
  55. // used in \noexpand
  56. constructor(text, // the text of this token
  57. loc) {
  58. this.text = void 0;
  59. this.loc = void 0;
  60. this.noexpand = void 0;
  61. this.treatAsRelax = void 0;
  62. this.text = text;
  63. this.loc = loc;
  64. }
  65. /**
  66. * Given a pair of tokens (this and endToken), compute a `Token` encompassing
  67. * the whole input range enclosed by these two.
  68. */
  69. range(endToken, // last token of the range, inclusive
  70. text // the text of the newly constructed token
  71. ) {
  72. return new Token(text, SourceLocation.range(this, endToken));
  73. }
  74. }
  75. /**
  76. * This is the ParseError class, which is the main error thrown by KaTeX
  77. * functions when something has gone wrong. This is used to distinguish internal
  78. * errors from errors in the expression that the user provided.
  79. *
  80. * If possible, a caller should provide a Token or ParseNode with information
  81. * about where in the source string the problem occurred.
  82. */
  83. class ParseError {
  84. // Error position based on passed-in Token or ParseNode.
  85. constructor(message, // The error message
  86. token // An object providing position information
  87. ) {
  88. this.position = void 0;
  89. var error = "KaTeX parse error: " + message;
  90. var start;
  91. var loc = token && token.loc;
  92. if (loc && loc.start <= loc.end) {
  93. // If we have the input and a position, make the error a bit fancier
  94. // Get the input
  95. var input = loc.lexer.input; // Prepend some information
  96. start = loc.start;
  97. var end = loc.end;
  98. if (start === input.length) {
  99. error += " at end of input: ";
  100. } else {
  101. error += " at position " + (start + 1) + ": ";
  102. } // Underline token in question using combining underscores
  103. var underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332"); // Extract some context from the input and add it to the error
  104. var left;
  105. if (start > 15) {
  106. left = "…" + input.slice(start - 15, start);
  107. } else {
  108. left = input.slice(0, start);
  109. }
  110. var right;
  111. if (end + 15 < input.length) {
  112. right = input.slice(end, end + 15) + "…";
  113. } else {
  114. right = input.slice(end);
  115. }
  116. error += left + underlined + right;
  117. } // Some hackery to make ParseError a prototype of Error
  118. // See http://stackoverflow.com/a/8460753
  119. var self = new Error(error);
  120. self.name = "ParseError"; // $FlowFixMe
  121. self.__proto__ = ParseError.prototype; // $FlowFixMe
  122. self.position = start;
  123. return self;
  124. }
  125. } // $FlowFixMe More hackery
  126. ParseError.prototype.__proto__ = Error.prototype;
  127. /**
  128. * This file contains a list of utility functions which are useful in other
  129. * files.
  130. */
  131. /**
  132. * Return whether an element is contained in a list
  133. */
  134. var contains = function contains(list, elem) {
  135. return list.indexOf(elem) !== -1;
  136. };
  137. /**
  138. * Provide a default value if a setting is undefined
  139. * NOTE: Couldn't use `T` as the output type due to facebook/flow#5022.
  140. */
  141. var deflt = function deflt(setting, defaultIfUndefined) {
  142. return setting === undefined ? defaultIfUndefined : setting;
  143. }; // hyphenate and escape adapted from Facebook's React under Apache 2 license
  144. var uppercase = /([A-Z])/g;
  145. var hyphenate = function hyphenate(str) {
  146. return str.replace(uppercase, "-$1").toLowerCase();
  147. };
  148. var ESCAPE_LOOKUP = {
  149. "&": "&amp;",
  150. ">": "&gt;",
  151. "<": "&lt;",
  152. "\"": "&quot;",
  153. "'": "&#x27;"
  154. };
  155. var ESCAPE_REGEX = /[&><"']/g;
  156. /**
  157. * Escapes text to prevent scripting attacks.
  158. */
  159. function escape(text) {
  160. return String(text).replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
  161. }
  162. /**
  163. * Sometimes we want to pull out the innermost element of a group. In most
  164. * cases, this will just be the group itself, but when ordgroups and colors have
  165. * a single element, we want to pull that out.
  166. */
  167. var getBaseElem = function getBaseElem(group) {
  168. if (group.type === "ordgroup") {
  169. if (group.body.length === 1) {
  170. return getBaseElem(group.body[0]);
  171. } else {
  172. return group;
  173. }
  174. } else if (group.type === "color") {
  175. if (group.body.length === 1) {
  176. return getBaseElem(group.body[0]);
  177. } else {
  178. return group;
  179. }
  180. } else if (group.type === "font") {
  181. return getBaseElem(group.body);
  182. } else {
  183. return group;
  184. }
  185. };
  186. /**
  187. * TeXbook algorithms often reference "character boxes", which are simply groups
  188. * with a single character in them. To decide if something is a character box,
  189. * we find its innermost group, and see if it is a single character.
  190. */
  191. var isCharacterBox = function isCharacterBox(group) {
  192. var baseElem = getBaseElem(group); // These are all they types of groups which hold single characters
  193. return baseElem.type === "mathord" || baseElem.type === "textord" || baseElem.type === "atom";
  194. };
  195. var assert = function assert(value) {
  196. if (!value) {
  197. throw new Error('Expected non-null, but got ' + String(value));
  198. }
  199. return value;
  200. };
  201. /**
  202. * Return the protocol of a URL, or "_relative" if the URL does not specify a
  203. * protocol (and thus is relative).
  204. */
  205. var protocolFromUrl = function protocolFromUrl(url) {
  206. var protocol = /^\s*([^\\/#]*?)(?::|&#0*58|&#x0*3a)/i.exec(url);
  207. return protocol != null ? protocol[1] : "_relative";
  208. };
  209. var utils = {
  210. contains,
  211. deflt,
  212. escape,
  213. hyphenate,
  214. getBaseElem,
  215. isCharacterBox,
  216. protocolFromUrl
  217. };
  218. /* eslint no-console:0 */
  219. // TODO: automatically generate documentation
  220. // TODO: check all properties on Settings exist
  221. // TODO: check the type of a property on Settings matches
  222. var SETTINGS_SCHEMA = {
  223. displayMode: {
  224. type: "boolean",
  225. description: "Render math in display mode, which puts the math in " + "display style (so \\int and \\sum are large, for example), and " + "centers the math on the page on its own line.",
  226. cli: "-d, --display-mode"
  227. },
  228. output: {
  229. type: {
  230. enum: ["htmlAndMathml", "html", "mathml"]
  231. },
  232. description: "Determines the markup language of the output.",
  233. cli: "-F, --format <type>"
  234. },
  235. leqno: {
  236. type: "boolean",
  237. description: "Render display math in leqno style (left-justified tags)."
  238. },
  239. fleqn: {
  240. type: "boolean",
  241. description: "Render display math flush left."
  242. },
  243. throwOnError: {
  244. type: "boolean",
  245. default: true,
  246. cli: "-t, --no-throw-on-error",
  247. cliDescription: "Render errors (in the color given by --error-color) ins" + "tead of throwing a ParseError exception when encountering an error."
  248. },
  249. errorColor: {
  250. type: "string",
  251. default: "#cc0000",
  252. cli: "-c, --error-color <color>",
  253. cliDescription: "A color string given in the format 'rgb' or 'rrggbb' " + "(no #). This option determines the color of errors rendered by the " + "-t option.",
  254. cliProcessor: color => "#" + color
  255. },
  256. macros: {
  257. type: "object",
  258. cli: "-m, --macro <def>",
  259. cliDescription: "Define custom macro of the form '\\foo:expansion' (use " + "multiple -m arguments for multiple macros).",
  260. cliDefault: [],
  261. cliProcessor: (def, defs) => {
  262. defs.push(def);
  263. return defs;
  264. }
  265. },
  266. minRuleThickness: {
  267. type: "number",
  268. description: "Specifies a minimum thickness, in ems, for fraction lines," + " `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, " + "`\\hdashline`, `\\underline`, `\\overline`, and the borders of " + "`\\fbox`, `\\boxed`, and `\\fcolorbox`.",
  269. processor: t => Math.max(0, t),
  270. cli: "--min-rule-thickness <size>",
  271. cliProcessor: parseFloat
  272. },
  273. colorIsTextColor: {
  274. type: "boolean",
  275. description: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " + "instead of LaTeX's one-argument \\color mode change.",
  276. cli: "-b, --color-is-text-color"
  277. },
  278. strict: {
  279. type: [{
  280. enum: ["warn", "ignore", "error"]
  281. }, "boolean", "function"],
  282. description: "Turn on strict / LaTeX faithfulness mode, which throws an " + "error if the input uses features that are not supported by LaTeX.",
  283. cli: "-S, --strict",
  284. cliDefault: false
  285. },
  286. trust: {
  287. type: ["boolean", "function"],
  288. description: "Trust the input, enabling all HTML features such as \\url.",
  289. cli: "-T, --trust"
  290. },
  291. maxSize: {
  292. type: "number",
  293. default: Infinity,
  294. description: "If non-zero, all user-specified sizes, e.g. in " + "\\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, " + "elements and spaces can be arbitrarily large",
  295. processor: s => Math.max(0, s),
  296. cli: "-s, --max-size <n>",
  297. cliProcessor: parseInt
  298. },
  299. maxExpand: {
  300. type: "number",
  301. default: 1000,
  302. description: "Limit the number of macro expansions to the specified " + "number, to prevent e.g. infinite macro loops. If set to Infinity, " + "the macro expander will try to fully expand as in LaTeX.",
  303. processor: n => Math.max(0, n),
  304. cli: "-e, --max-expand <n>",
  305. cliProcessor: n => n === "Infinity" ? Infinity : parseInt(n)
  306. },
  307. globalGroup: {
  308. type: "boolean",
  309. cli: false
  310. }
  311. };
  312. function getDefaultValue(schema) {
  313. if (schema.default) {
  314. return schema.default;
  315. }
  316. var type = schema.type;
  317. var defaultType = Array.isArray(type) ? type[0] : type;
  318. if (typeof defaultType !== 'string') {
  319. return defaultType.enum[0];
  320. }
  321. switch (defaultType) {
  322. case 'boolean':
  323. return false;
  324. case 'string':
  325. return '';
  326. case 'number':
  327. return 0;
  328. case 'object':
  329. return {};
  330. }
  331. }
  332. /**
  333. * The main Settings object
  334. *
  335. * The current options stored are:
  336. * - displayMode: Whether the expression should be typeset as inline math
  337. * (false, the default), meaning that the math starts in
  338. * \textstyle and is placed in an inline-block); or as display
  339. * math (true), meaning that the math starts in \displaystyle
  340. * and is placed in a block with vertical margin.
  341. */
  342. class Settings {
  343. constructor(options) {
  344. this.displayMode = void 0;
  345. this.output = void 0;
  346. this.leqno = void 0;
  347. this.fleqn = void 0;
  348. this.throwOnError = void 0;
  349. this.errorColor = void 0;
  350. this.macros = void 0;
  351. this.minRuleThickness = void 0;
  352. this.colorIsTextColor = void 0;
  353. this.strict = void 0;
  354. this.trust = void 0;
  355. this.maxSize = void 0;
  356. this.maxExpand = void 0;
  357. this.globalGroup = void 0;
  358. // allow null options
  359. options = options || {};
  360. for (var prop in SETTINGS_SCHEMA) {
  361. if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
  362. // $FlowFixMe
  363. var schema = SETTINGS_SCHEMA[prop]; // TODO: validate options
  364. // $FlowFixMe
  365. this[prop] = options[prop] !== undefined ? schema.processor ? schema.processor(options[prop]) : options[prop] : getDefaultValue(schema);
  366. }
  367. }
  368. }
  369. /**
  370. * Report nonstrict (non-LaTeX-compatible) input.
  371. * Can safely not be called if `this.strict` is false in JavaScript.
  372. */
  373. reportNonstrict(errorCode, errorMsg, token) {
  374. var strict = this.strict;
  375. if (typeof strict === "function") {
  376. // Allow return value of strict function to be boolean or string
  377. // (or null/undefined, meaning no further processing).
  378. strict = strict(errorCode, errorMsg, token);
  379. }
  380. if (!strict || strict === "ignore") {
  381. return;
  382. } else if (strict === true || strict === "error") {
  383. throw new ParseError("LaTeX-incompatible input and strict mode is set to 'error': " + (errorMsg + " [" + errorCode + "]"), token);
  384. } else if (strict === "warn") {
  385. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to 'warn': " + (errorMsg + " [" + errorCode + "]"));
  386. } else {
  387. // won't happen in type-safe code
  388. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to " + ("unrecognized '" + strict + "': " + errorMsg + " [" + errorCode + "]"));
  389. }
  390. }
  391. /**
  392. * Check whether to apply strict (LaTeX-adhering) behavior for unusual
  393. * input (like `\\`). Unlike `nonstrict`, will not throw an error;
  394. * instead, "error" translates to a return value of `true`, while "ignore"
  395. * translates to a return value of `false`. May still print a warning:
  396. * "warn" prints a warning and returns `false`.
  397. * This is for the second category of `errorCode`s listed in the README.
  398. */
  399. useStrictBehavior(errorCode, errorMsg, token) {
  400. var strict = this.strict;
  401. if (typeof strict === "function") {
  402. // Allow return value of strict function to be boolean or string
  403. // (or null/undefined, meaning no further processing).
  404. // But catch any exceptions thrown by function, treating them
  405. // like "error".
  406. try {
  407. strict = strict(errorCode, errorMsg, token);
  408. } catch (error) {
  409. strict = "error";
  410. }
  411. }
  412. if (!strict || strict === "ignore") {
  413. return false;
  414. } else if (strict === true || strict === "error") {
  415. return true;
  416. } else if (strict === "warn") {
  417. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to 'warn': " + (errorMsg + " [" + errorCode + "]"));
  418. return false;
  419. } else {
  420. // won't happen in type-safe code
  421. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to " + ("unrecognized '" + strict + "': " + errorMsg + " [" + errorCode + "]"));
  422. return false;
  423. }
  424. }
  425. /**
  426. * Check whether to test potentially dangerous input, and return
  427. * `true` (trusted) or `false` (untrusted). The sole argument `context`
  428. * should be an object with `command` field specifying the relevant LaTeX
  429. * command (as a string starting with `\`), and any other arguments, etc.
  430. * If `context` has a `url` field, a `protocol` field will automatically
  431. * get added by this function (changing the specified object).
  432. */
  433. isTrusted(context) {
  434. if (context.url && !context.protocol) {
  435. context.protocol = utils.protocolFromUrl(context.url);
  436. }
  437. var trust = typeof this.trust === "function" ? this.trust(context) : this.trust;
  438. return Boolean(trust);
  439. }
  440. }
  441. /**
  442. * This file contains information and classes for the various kinds of styles
  443. * used in TeX. It provides a generic `Style` class, which holds information
  444. * about a specific style. It then provides instances of all the different kinds
  445. * of styles possible, and provides functions to move between them and get
  446. * information about them.
  447. */
  448. /**
  449. * The main style class. Contains a unique id for the style, a size (which is
  450. * the same for cramped and uncramped version of a style), and a cramped flag.
  451. */
  452. class Style {
  453. constructor(id, size, cramped) {
  454. this.id = void 0;
  455. this.size = void 0;
  456. this.cramped = void 0;
  457. this.id = id;
  458. this.size = size;
  459. this.cramped = cramped;
  460. }
  461. /**
  462. * Get the style of a superscript given a base in the current style.
  463. */
  464. sup() {
  465. return styles[sup[this.id]];
  466. }
  467. /**
  468. * Get the style of a subscript given a base in the current style.
  469. */
  470. sub() {
  471. return styles[sub[this.id]];
  472. }
  473. /**
  474. * Get the style of a fraction numerator given the fraction in the current
  475. * style.
  476. */
  477. fracNum() {
  478. return styles[fracNum[this.id]];
  479. }
  480. /**
  481. * Get the style of a fraction denominator given the fraction in the current
  482. * style.
  483. */
  484. fracDen() {
  485. return styles[fracDen[this.id]];
  486. }
  487. /**
  488. * Get the cramped version of a style (in particular, cramping a cramped style
  489. * doesn't change the style).
  490. */
  491. cramp() {
  492. return styles[cramp[this.id]];
  493. }
  494. /**
  495. * Get a text or display version of this style.
  496. */
  497. text() {
  498. return styles[text$1[this.id]];
  499. }
  500. /**
  501. * Return true if this style is tightly spaced (scriptstyle/scriptscriptstyle)
  502. */
  503. isTight() {
  504. return this.size >= 2;
  505. }
  506. } // Export an interface for type checking, but don't expose the implementation.
  507. // This way, no more styles can be generated.
  508. // IDs of the different styles
  509. var D = 0;
  510. var Dc = 1;
  511. var T = 2;
  512. var Tc = 3;
  513. var S = 4;
  514. var Sc = 5;
  515. var SS = 6;
  516. var SSc = 7; // Instances of the different styles
  517. var styles = [new Style(D, 0, false), new Style(Dc, 0, true), new Style(T, 1, false), new Style(Tc, 1, true), new Style(S, 2, false), new Style(Sc, 2, true), new Style(SS, 3, false), new Style(SSc, 3, true)]; // Lookup tables for switching from one style to another
  518. var sup = [S, Sc, S, Sc, SS, SSc, SS, SSc];
  519. var sub = [Sc, Sc, Sc, Sc, SSc, SSc, SSc, SSc];
  520. var fracNum = [T, Tc, S, Sc, SS, SSc, SS, SSc];
  521. var fracDen = [Tc, Tc, Sc, Sc, SSc, SSc, SSc, SSc];
  522. var cramp = [Dc, Dc, Tc, Tc, Sc, Sc, SSc, SSc];
  523. var text$1 = [D, Dc, T, Tc, T, Tc, T, Tc]; // We only export some of the styles.
  524. var Style$1 = {
  525. DISPLAY: styles[D],
  526. TEXT: styles[T],
  527. SCRIPT: styles[S],
  528. SCRIPTSCRIPT: styles[SS]
  529. };
  530. /*
  531. * This file defines the Unicode scripts and script families that we
  532. * support. To add new scripts or families, just add a new entry to the
  533. * scriptData array below. Adding scripts to the scriptData array allows
  534. * characters from that script to appear in \text{} environments.
  535. */
  536. /**
  537. * Each script or script family has a name and an array of blocks.
  538. * Each block is an array of two numbers which specify the start and
  539. * end points (inclusive) of a block of Unicode codepoints.
  540. */
  541. /**
  542. * Unicode block data for the families of scripts we support in \text{}.
  543. * Scripts only need to appear here if they do not have font metrics.
  544. */
  545. var scriptData = [{
  546. // Latin characters beyond the Latin-1 characters we have metrics for.
  547. // Needed for Czech, Hungarian and Turkish text, for example.
  548. name: 'latin',
  549. blocks: [[0x0100, 0x024f], // Latin Extended-A and Latin Extended-B
  550. [0x0300, 0x036f] // Combining Diacritical marks
  551. ]
  552. }, {
  553. // The Cyrillic script used by Russian and related languages.
  554. // A Cyrillic subset used to be supported as explicitly defined
  555. // symbols in symbols.js
  556. name: 'cyrillic',
  557. blocks: [[0x0400, 0x04ff]]
  558. }, {
  559. // Armenian
  560. name: 'armenian',
  561. blocks: [[0x0530, 0x058F]]
  562. }, {
  563. // The Brahmic scripts of South and Southeast Asia
  564. // Devanagari (0900–097F)
  565. // Bengali (0980–09FF)
  566. // Gurmukhi (0A00–0A7F)
  567. // Gujarati (0A80–0AFF)
  568. // Oriya (0B00–0B7F)
  569. // Tamil (0B80–0BFF)
  570. // Telugu (0C00–0C7F)
  571. // Kannada (0C80–0CFF)
  572. // Malayalam (0D00–0D7F)
  573. // Sinhala (0D80–0DFF)
  574. // Thai (0E00–0E7F)
  575. // Lao (0E80–0EFF)
  576. // Tibetan (0F00–0FFF)
  577. // Myanmar (1000–109F)
  578. name: 'brahmic',
  579. blocks: [[0x0900, 0x109F]]
  580. }, {
  581. name: 'georgian',
  582. blocks: [[0x10A0, 0x10ff]]
  583. }, {
  584. // Chinese and Japanese.
  585. // The "k" in cjk is for Korean, but we've separated Korean out
  586. name: "cjk",
  587. blocks: [[0x3000, 0x30FF], // CJK symbols and punctuation, Hiragana, Katakana
  588. [0x4E00, 0x9FAF], // CJK ideograms
  589. [0xFF00, 0xFF60] // Fullwidth punctuation
  590. // TODO: add halfwidth Katakana and Romanji glyphs
  591. ]
  592. }, {
  593. // Korean
  594. name: 'hangul',
  595. blocks: [[0xAC00, 0xD7AF]]
  596. }];
  597. /**
  598. * Given a codepoint, return the name of the script or script family
  599. * it is from, or null if it is not part of a known block
  600. */
  601. function scriptFromCodepoint(codepoint) {
  602. for (var i = 0; i < scriptData.length; i++) {
  603. var script = scriptData[i];
  604. for (var _i = 0; _i < script.blocks.length; _i++) {
  605. var block = script.blocks[_i];
  606. if (codepoint >= block[0] && codepoint <= block[1]) {
  607. return script.name;
  608. }
  609. }
  610. }
  611. return null;
  612. }
  613. /**
  614. * A flattened version of all the supported blocks in a single array.
  615. * This is an optimization to make supportedCodepoint() fast.
  616. */
  617. var allBlocks = [];
  618. scriptData.forEach(s => s.blocks.forEach(b => allBlocks.push(...b)));
  619. /**
  620. * Given a codepoint, return true if it falls within one of the
  621. * scripts or script families defined above and false otherwise.
  622. *
  623. * Micro benchmarks shows that this is faster than
  624. * /[\u3000-\u30FF\u4E00-\u9FAF\uFF00-\uFF60\uAC00-\uD7AF\u0900-\u109F]/.test()
  625. * in Firefox, Chrome and Node.
  626. */
  627. function supportedCodepoint(codepoint) {
  628. for (var i = 0; i < allBlocks.length; i += 2) {
  629. if (codepoint >= allBlocks[i] && codepoint <= allBlocks[i + 1]) {
  630. return true;
  631. }
  632. }
  633. return false;
  634. }
  635. /**
  636. * This file provides support to domTree.js and delimiter.js.
  637. * It's a storehouse of path geometry for SVG images.
  638. */
  639. // In all paths below, the viewBox-to-em scale is 1000:1.
  640. var hLinePad = 80; // padding above a sqrt viniculum. Prevents image cropping.
  641. // The viniculum of a \sqrt can be made thicker by a KaTeX rendering option.
  642. // Think of variable extraViniculum as two detours in the SVG path.
  643. // The detour begins at the lower left of the area labeled extraViniculum below.
  644. // The detour proceeds one extraViniculum distance up and slightly to the right,
  645. // displacing the radiused corner between surd and viniculum. The radius is
  646. // traversed as usual, then the detour resumes. It goes right, to the end of
  647. // the very long viniculumn, then down one extraViniculum distance,
  648. // after which it resumes regular path geometry for the radical.
  649. /* viniculum
  650. /
  651. /▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒←extraViniculum
  652. / █████████████████████←0.04em (40 unit) std viniculum thickness
  653. / /
  654. / /
  655. / /\
  656. / / surd
  657. */
  658. var sqrtMain = function sqrtMain(extraViniculum, hLinePad) {
  659. // sqrtMain path geometry is from glyph U221A in the font KaTeX Main
  660. return "M95," + (622 + extraViniculum + hLinePad) + "\nc-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14\nc0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54\nc44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10\ns173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429\nc69,-144,104.5,-217.7,106.5,-221\nl" + extraViniculum / 2.075 + " -" + extraViniculum + "\nc5.3,-9.3,12,-14,20,-14\nH400000v" + (40 + extraViniculum) + "H845.2724\ns-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7\nc-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z\nM" + (834 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z";
  661. };
  662. var sqrtSize1 = function sqrtSize1(extraViniculum, hLinePad) {
  663. // size1 is from glyph U221A in the font KaTeX_Size1-Regular
  664. return "M263," + (601 + extraViniculum + hLinePad) + "c0.7,0,18,39.7,52,119\nc34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120\nc340,-704.7,510.7,-1060.3,512,-1067\nl" + extraViniculum / 2.084 + " -" + extraViniculum + "\nc4.7,-7.3,11,-11,19,-11\nH40000v" + (40 + extraViniculum) + "H1012.3\ns-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5,232\nc-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1\ns-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26\nc-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z\nM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z";
  665. };
  666. var sqrtSize2 = function sqrtSize2(extraViniculum, hLinePad) {
  667. // size2 is from glyph U221A in the font KaTeX_Size2-Regular
  668. return "M983 " + (10 + extraViniculum + hLinePad) + "\nl" + extraViniculum / 3.13 + " -" + extraViniculum + "\nc4,-6.7,10,-10,18,-10 H400000v" + (40 + extraViniculum) + "\nH1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7\ns-12,0,-12,0c-1.3,-3.3,-3.7,-11.7,-7,-25c-35.3,-125.3,-106.7,-373.3,-214,-744\nc-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30\nc26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722\nc56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5\nc53.7,-170.3,84.5,-266.8,92.5,-289.5z\nM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "h-400000z";
  669. };
  670. var sqrtSize3 = function sqrtSize3(extraViniculum, hLinePad) {
  671. // size3 is from glyph U221A in the font KaTeX_Size3-Regular
  672. return "M424," + (2398 + extraViniculum + hLinePad) + "\nc-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514\nc0,-2,-10.7,14.3,-32,49c-4.7,7.3,-9.8,15.7,-15.5,25c-5.7,9.3,-9.8,16,-12.5,20\ns-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121\ns209,968,209,968c0,-2,84.7,-361.7,254,-1079c169.3,-717.3,254.7,-1077.7,256,-1081\nl" + extraViniculum / 4.223 + " -" + extraViniculum + "c4,-6.7,10,-10,18,-10 H400000\nv" + (40 + extraViniculum) + "H1014.6\ns-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185\nc-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2z M" + (1001 + extraViniculum) + " " + hLinePad + "\nh400000v" + (40 + extraViniculum) + "h-400000z";
  673. };
  674. var sqrtSize4 = function sqrtSize4(extraViniculum, hLinePad) {
  675. // size4 is from glyph U221A in the font KaTeX_Size4-Regular
  676. return "M473," + (2713 + extraViniculum + hLinePad) + "\nc339.3,-1799.3,509.3,-2700,510,-2702 l" + extraViniculum / 5.298 + " -" + extraViniculum + "\nc3.3,-7.3,9.3,-11,18,-11 H400000v" + (40 + extraViniculum) + "H1017.7\ns-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9\nc-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200\nc0,-1.3,-5.3,8.7,-16,30c-10.7,21.3,-21.3,42.7,-32,64s-16,33,-16,33s-26,-26,-26,-26\ns76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104,\n606zM" + (1001 + extraViniculum) + " " + hLinePad + "h400000v" + (40 + extraViniculum) + "H1017.7z";
  677. };
  678. var phasePath = function phasePath(y) {
  679. var x = y / 2; // x coordinate at top of angle
  680. return "M400000 " + y + " H0 L" + x + " 0 l65 45 L145 " + (y - 80) + " H400000z";
  681. };
  682. var sqrtTall = function sqrtTall(extraViniculum, hLinePad, viewBoxHeight) {
  683. // sqrtTall is from glyph U23B7 in the font KaTeX_Size4-Regular
  684. // One path edge has a variable length. It runs vertically from the viniculumn
  685. // to a point near (14 units) the bottom of the surd. The viniculum
  686. // is normally 40 units thick. So the length of the line in question is:
  687. var vertSegment = viewBoxHeight - 54 - hLinePad - extraViniculum;
  688. return "M702 " + (extraViniculum + hLinePad) + "H400000" + (40 + extraViniculum) + "\nH742v" + vertSegment + "l-4 4-4 4c-.667.7 -2 1.5-4 2.5s-4.167 1.833-6.5 2.5-5.5 1-9.5 1\nh-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170\nc-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667\n219 661 l218 661zM702 " + hLinePad + "H400000v" + (40 + extraViniculum) + "H742z";
  689. };
  690. var sqrtPath = function sqrtPath(size, extraViniculum, viewBoxHeight) {
  691. extraViniculum = 1000 * extraViniculum; // Convert from document ems to viewBox.
  692. var path = "";
  693. switch (size) {
  694. case "sqrtMain":
  695. path = sqrtMain(extraViniculum, hLinePad);
  696. break;
  697. case "sqrtSize1":
  698. path = sqrtSize1(extraViniculum, hLinePad);
  699. break;
  700. case "sqrtSize2":
  701. path = sqrtSize2(extraViniculum, hLinePad);
  702. break;
  703. case "sqrtSize3":
  704. path = sqrtSize3(extraViniculum, hLinePad);
  705. break;
  706. case "sqrtSize4":
  707. path = sqrtSize4(extraViniculum, hLinePad);
  708. break;
  709. case "sqrtTall":
  710. path = sqrtTall(extraViniculum, hLinePad, viewBoxHeight);
  711. }
  712. return path;
  713. };
  714. var innerPath = function innerPath(name, height) {
  715. // The inner part of stretchy tall delimiters
  716. switch (name) {
  717. case "\u239c":
  718. return "M291 0 H417 V" + height + " H291z M291 0 H417 V" + height + " H291z";
  719. case "\u2223":
  720. return "M145 0 H188 V" + height + " H145z M145 0 H188 V" + height + " H145z";
  721. case "\u2225":
  722. return "M145 0 H188 V" + height + " H145z M145 0 H188 V" + height + " H145z" + ("M367 0 H410 V" + height + " H367z M367 0 H410 V" + height + " H367z");
  723. case "\u239f":
  724. return "M457 0 H583 V" + height + " H457z M457 0 H583 V" + height + " H457z";
  725. case "\u23a2":
  726. return "M319 0 H403 V" + height + " H319z M319 0 H403 V" + height + " H319z";
  727. case "\u23a5":
  728. return "M263 0 H347 V" + height + " H263z M263 0 H347 V" + height + " H263z";
  729. case "\u23aa":
  730. return "M384 0 H504 V" + height + " H384z M384 0 H504 V" + height + " H384z";
  731. case "\u23d0":
  732. return "M312 0 H355 V" + height + " H312z M312 0 H355 V" + height + " H312z";
  733. case "\u2016":
  734. return "M257 0 H300 V" + height + " H257z M257 0 H300 V" + height + " H257z" + ("M478 0 H521 V" + height + " H478z M478 0 H521 V" + height + " H478z");
  735. default:
  736. return "";
  737. }
  738. };
  739. var path = {
  740. // The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
  741. doubleleftarrow: "M262 157\nl10-10c34-36 62.7-77 86-123 3.3-8 5-13.3 5-16 0-5.3-6.7-8-20-8-7.3\n 0-12.2.5-14.5 1.5-2.3 1-4.8 4.5-7.5 10.5-49.3 97.3-121.7 169.3-217 216-28\n 14-57.3 25-88 33-6.7 2-11 3.8-13 5.5-2 1.7-3 4.2-3 7.5s1 5.8 3 7.5\nc2 1.7 6.3 3.5 13 5.5 68 17.3 128.2 47.8 180.5 91.5 52.3 43.7 93.8 96.2 124.5\n 157.5 9.3 8 15.3 12.3 18 13h6c12-.7 18-4 18-10 0-2-1.7-7-5-15-23.3-46-52-87\n-86-123l-10-10h399738v-40H218c328 0 0 0 0 0l-10-8c-26.7-20-65.7-43-117-69 2.7\n-2 6-3.7 10-5 36.7-16 72.3-37.3 107-64l10-8h399782v-40z\nm8 0v40h399730v-40zm0 194v40h399730v-40z",
  742. // doublerightarrow is from glyph U+21D2 in font KaTeX Main
  743. doublerightarrow: "M399738 392l\n-10 10c-34 36-62.7 77-86 123-3.3 8-5 13.3-5 16 0 5.3 6.7 8 20 8 7.3 0 12.2-.5\n 14.5-1.5 2.3-1 4.8-4.5 7.5-10.5 49.3-97.3 121.7-169.3 217-216 28-14 57.3-25 88\n-33 6.7-2 11-3.8 13-5.5 2-1.7 3-4.2 3-7.5s-1-5.8-3-7.5c-2-1.7-6.3-3.5-13-5.5-68\n-17.3-128.2-47.8-180.5-91.5-52.3-43.7-93.8-96.2-124.5-157.5-9.3-8-15.3-12.3-18\n-13h-6c-12 .7-18 4-18 10 0 2 1.7 7 5 15 23.3 46 52 87 86 123l10 10H0v40h399782\nc-328 0 0 0 0 0l10 8c26.7 20 65.7 43 117 69-2.7 2-6 3.7-10 5-36.7 16-72.3 37.3\n-107 64l-10 8H0v40zM0 157v40h399730v-40zm0 194v40h399730v-40z",
  744. // leftarrow is from glyph U+2190 in font KaTeX Main
  745. leftarrow: "M400000 241H110l3-3c68.7-52.7 113.7-120\n 135-202 4-14.7 6-23 6-25 0-7.3-7-11-21-11-8 0-13.2.8-15.5 2.5-2.3 1.7-4.2 5.8\n-5.5 12.5-1.3 4.7-2.7 10.3-4 17-12 48.7-34.8 92-68.5 130S65.3 228.3 18 247\nc-10 4-16 7.7-18 11 0 8.7 6 14.3 18 17 47.3 18.7 87.8 47 121.5 85S196 441.3 208\n 490c.7 2 1.3 5 2 9s1.2 6.7 1.5 8c.3 1.3 1 3.3 2 6s2.2 4.5 3.5 5.5c1.3 1 3.3\n 1.8 6 2.5s6 1 10 1c14 0 21-3.7 21-11 0-2-2-10.3-6-25-20-79.3-65-146.7-135-202\n l-3-3h399890zM100 241v40h399900v-40z",
  746. // overbrace is from glyphs U+23A9/23A8/23A7 in font KaTeX_Size4-Regular
  747. leftbrace: "M6 548l-6-6v-35l6-11c56-104 135.3-181.3 238-232 57.3-28.7 117\n-45 179-50h399577v120H403c-43.3 7-81 15-113 26-100.7 33-179.7 91-237 174-2.7\n 5-6 9-10 13-.7 1-7.3 1-20 1H6z",
  748. leftbraceunder: "M0 6l6-6h17c12.688 0 19.313.3 20 1 4 4 7.313 8.3 10 13\n 35.313 51.3 80.813 93.8 136.5 127.5 55.688 33.7 117.188 55.8 184.5 66.5.688\n 0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7\n-331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z",
  749. // overgroup is from the MnSymbol package (public domain)
  750. leftgroup: "M400000 80\nH435C64 80 168.3 229.4 21 260c-5.9 1.2-18 0-18 0-2 0-3-1-3-3v-38C76 61 257 0\n 435 0h399565z",
  751. leftgroupunder: "M400000 262\nH435C64 262 168.3 112.6 21 82c-5.9-1.2-18 0-18 0-2 0-3 1-3 3v38c76 158 257 219\n 435 219h399565z",
  752. // Harpoons are from glyph U+21BD in font KaTeX Main
  753. leftharpoon: "M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3\n-3.3 10.2-9.5 20.5-18.5s17.8-15.8 22.5-20.5c50.7-52 88-110.3 112-175 4-11.3 5\n-18.3 3-21-1.3-4-7.3-6-18-6-8 0-13 .7-15 2s-4.7 6.7-8 16c-42 98.7-107.3 174.7\n-196 228-6.7 4.7-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40z",
  754. leftharpoonplus: "M0 267c.7 5.3 3 10 7 14h399993v-40H93c3.3-3.3 10.2-9.5\n 20.5-18.5s17.8-15.8 22.5-20.5c50.7-52 88-110.3 112-175 4-11.3 5-18.3 3-21-1.3\n-4-7.3-6-18-6-8 0-13 .7-15 2s-4.7 6.7-8 16c-42 98.7-107.3 174.7-196 228-6.7 4.7\n-10.7 8-12 10-1.3 2-2 5.7-2 11zm100-26v40h399900v-40zM0 435v40h400000v-40z\nm0 0v40h400000v-40z",
  755. leftharpoondown: "M7 241c-4 4-6.333 8.667-7 14 0 5.333.667 9 2 11s5.333\n 5.333 12 10c90.667 54 156 130 196 228 3.333 10.667 6.333 16.333 9 17 2 .667 5\n 1 9 1h5c10.667 0 16.667-2 18-6 2-2.667 1-9.667-3-21-32-87.333-82.667-157.667\n-152-211l-3-3h399907v-40zM93 281 H400000 v-40L7 241z",
  756. leftharpoondownplus: "M7 435c-4 4-6.3 8.7-7 14 0 5.3.7 9 2 11s5.3 5.3 12\n 10c90.7 54 156 130 196 228 3.3 10.7 6.3 16.3 9 17 2 .7 5 1 9 1h5c10.7 0 16.7\n-2 18-6 2-2.7 1-9.7-3-21-32-87.3-82.7-157.7-152-211l-3-3h399907v-40H7zm93 0\nv40h399900v-40zM0 241v40h399900v-40zm0 0v40h399900v-40z",
  757. // hook is from glyph U+21A9 in font KaTeX Main
  758. lefthook: "M400000 281 H103s-33-11.2-61-33.5S0 197.3 0 164s14.2-61.2 42.5\n-83.5C70.8 58.2 104 47 142 47 c16.7 0 25 6.7 25 20 0 12-8.7 18.7-26 20-40 3.3\n-68.7 15.7-86 37-10 12-15 25.3-15 40 0 22.7 9.8 40.7 29.5 54 19.7 13.3 43.5 21\n 71.5 23h399859zM103 281v-40h399897v40z",
  759. leftlinesegment: "M40 281 V428 H0 V94 H40 V241 H400000 v40z\nM40 281 V428 H0 V94 H40 V241 H400000 v40z",
  760. leftmapsto: "M40 281 V448H0V74H40V241H400000v40z\nM40 281 V448H0V74H40V241H400000v40z",
  761. // tofrom is from glyph U+21C4 in font KaTeX AMS Regular
  762. leftToFrom: "M0 147h400000v40H0zm0 214c68 40 115.7 95.7 143 167h22c15.3 0 23\n-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69-70-101l-7-8h399905v-40H95l7-8\nc28.7-32 52-65.7 70-101 10.7-23.3 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 265.3\n 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z",
  763. longequal: "M0 50 h400000 v40H0z m0 194h40000v40H0z\nM0 50 h400000 v40H0z m0 194h40000v40H0z",
  764. midbrace: "M200428 334\nc-100.7-8.3-195.3-44-280-108-55.3-42-101.7-93-139-153l-9-14c-2.7 4-5.7 8.7-9 14\n-53.3 86.7-123.7 153-211 199-66.7 36-137.3 56.3-212 62H0V214h199568c178.3-11.7\n 311.7-78.3 403-201 6-8 9.7-12 11-12 .7-.7 6.7-1 18-1s17.3.3 18 1c1.3 0 5 4 11\n 12 44.7 59.3 101.3 106.3 170 141s145.3 54.3 229 60h199572v120z",
  765. midbraceunder: "M199572 214\nc100.7 8.3 195.3 44 280 108 55.3 42 101.7 93 139 153l9 14c2.7-4 5.7-8.7 9-14\n 53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3\n 11.7-311.7 78.3-403 201-6 8-9.7 12-11 12-.7.7-6.7 1-18 1s-17.3-.3-18-1c-1.3 0\n-5-4-11-12-44.7-59.3-101.3-106.3-170-141s-145.3-54.3-229-60H0V214z",
  766. oiintSize1: "M512.6 71.6c272.6 0 320.3 106.8 320.3 178.2 0 70.8-47.7 177.6\n-320.3 177.6S193.1 320.6 193.1 249.8c0-71.4 46.9-178.2 319.5-178.2z\nm368.1 178.2c0-86.4-60.9-215.4-368.1-215.4-306.4 0-367.3 129-367.3 215.4 0 85.8\n60.9 214.8 367.3 214.8 307.2 0 368.1-129 368.1-214.8z",
  767. oiintSize2: "M757.8 100.1c384.7 0 451.1 137.6 451.1 230 0 91.3-66.4 228.8\n-451.1 228.8-386.3 0-452.7-137.5-452.7-228.8 0-92.4 66.4-230 452.7-230z\nm502.4 230c0-111.2-82.4-277.2-502.4-277.2s-504 166-504 277.2\nc0 110 84 276 504 276s502.4-166 502.4-276z",
  768. oiiintSize1: "M681.4 71.6c408.9 0 480.5 106.8 480.5 178.2 0 70.8-71.6 177.6\n-480.5 177.6S202.1 320.6 202.1 249.8c0-71.4 70.5-178.2 479.3-178.2z\nm525.8 178.2c0-86.4-86.8-215.4-525.7-215.4-437.9 0-524.7 129-524.7 215.4 0\n85.8 86.8 214.8 524.7 214.8 438.9 0 525.7-129 525.7-214.8z",
  769. oiiintSize2: "M1021.2 53c603.6 0 707.8 165.8 707.8 277.2 0 110-104.2 275.8\n-707.8 275.8-606 0-710.2-165.8-710.2-275.8C311 218.8 415.2 53 1021.2 53z\nm770.4 277.1c0-131.2-126.4-327.6-770.5-327.6S248.4 198.9 248.4 330.1\nc0 130 128.8 326.4 772.7 326.4s770.5-196.4 770.5-326.4z",
  770. rightarrow: "M0 241v40h399891c-47.3 35.3-84 78-110 128\n-16.7 32-27.7 63.7-33 95 0 1.3-.2 2.7-.5 4-.3 1.3-.5 2.3-.5 3 0 7.3 6.7 11 20\n 11 8 0 13.2-.8 15.5-2.5 2.3-1.7 4.2-5.5 5.5-11.5 2-13.3 5.7-27 11-41 14.7-44.7\n 39-84.5 73-119.5s73.7-60.2 119-75.5c6-2 9-5.7 9-11s-3-9-9-11c-45.3-15.3-85\n-40.5-119-75.5s-58.3-74.8-73-119.5c-4.7-14-8.3-27.3-11-40-1.3-6.7-3.2-10.8-5.5\n-12.5-2.3-1.7-7.5-2.5-15.5-2.5-14 0-21 3.7-21 11 0 2 2 10.3 6 25 20.7 83.3 67\n 151.7 139 205zm0 0v40h399900v-40z",
  771. rightbrace: "M400000 542l\n-6 6h-17c-12.7 0-19.3-.3-20-1-4-4-7.3-8.3-10-13-35.3-51.3-80.8-93.8-136.5-127.5\ns-117.2-55.8-184.5-66.5c-.7 0-2-.3-4-1-18.7-2.7-76-4.3-172-5H0V214h399571l6 1\nc124.7 8 235 61.7 331 161 31.3 33.3 59.7 72.7 85 118l7 13v35z",
  772. rightbraceunder: "M399994 0l6 6v35l-6 11c-56 104-135.3 181.3-238 232-57.3\n 28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237\n-174 2.7-5 6-9 10-13 .7-1 7.3-1 20-1h17z",
  773. rightgroup: "M0 80h399565c371 0 266.7 149.4 414 180 5.9 1.2 18 0 18 0 2 0\n 3-1 3-3v-38c-76-158-257-219-435-219H0z",
  774. rightgroupunder: "M0 262h399565c371 0 266.7-149.4 414-180 5.9-1.2 18 0 18\n 0 2 0 3 1 3 3v38c-76 158-257 219-435 219H0z",
  775. rightharpoon: "M0 241v40h399993c4.7-4.7 7-9.3 7-14 0-9.3\n-3.7-15.3-11-18-92.7-56.7-159-133.7-199-231-3.3-9.3-6-14.7-8-16-2-1.3-7-2-15-2\n-10.7 0-16.7 2-18 6-2 2.7-1 9.7 3 21 15.3 42 36.7 81.8 64 119.5 27.3 37.7 58\n 69.2 92 94.5zm0 0v40h399900v-40z",
  776. rightharpoonplus: "M0 241v40h399993c4.7-4.7 7-9.3 7-14 0-9.3-3.7-15.3-11\n-18-92.7-56.7-159-133.7-199-231-3.3-9.3-6-14.7-8-16-2-1.3-7-2-15-2-10.7 0-16.7\n 2-18 6-2 2.7-1 9.7 3 21 15.3 42 36.7 81.8 64 119.5 27.3 37.7 58 69.2 92 94.5z\nm0 0v40h399900v-40z m100 194v40h399900v-40zm0 0v40h399900v-40z",
  777. rightharpoondown: "M399747 511c0 7.3 6.7 11 20 11 8 0 13-.8 15-2.5s4.7-6.8\n 8-15.5c40-94 99.3-166.3 178-217 13.3-8 20.3-12.3 21-13 5.3-3.3 8.5-5.8 9.5\n-7.5 1-1.7 1.5-5.2 1.5-10.5s-2.3-10.3-7-15H0v40h399908c-34 25.3-64.7 57-92 95\n-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 241v40h399900v-40z",
  778. rightharpoondownplus: "M399747 705c0 7.3 6.7 11 20 11 8 0 13-.8\n 15-2.5s4.7-6.8 8-15.5c40-94 99.3-166.3 178-217 13.3-8 20.3-12.3 21-13 5.3-3.3\n 8.5-5.8 9.5-7.5 1-1.7 1.5-5.2 1.5-10.5s-2.3-10.3-7-15H0v40h399908c-34 25.3\n-64.7 57-92 95-27.3 38-48.7 77.7-64 119-3.3 8.7-5 14-5 16zM0 435v40h399900v-40z\nm0-194v40h400000v-40zm0 0v40h400000v-40z",
  779. righthook: "M399859 241c-764 0 0 0 0 0 40-3.3 68.7-15.7 86-37 10-12 15-25.3\n 15-40 0-22.7-9.8-40.7-29.5-54-19.7-13.3-43.5-21-71.5-23-17.3-1.3-26-8-26-20 0\n-13.3 8.7-20 26-20 38 0 71 11.2 99 33.5 0 0 7 5.6 21 16.7 14 11.2 21 33.5 21\n 66.8s-14 61.2-42 83.5c-28 22.3-61 33.5-99 33.5L0 241z M0 281v-40h399859v40z",
  780. rightlinesegment: "M399960 241 V94 h40 V428 h-40 V281 H0 v-40z\nM399960 241 V94 h40 V428 h-40 V281 H0 v-40z",
  781. rightToFrom: "M400000 167c-70.7-42-118-97.7-142-167h-23c-15.3 0-23 .3-23\n 1 0 1.3 5.3 13.7 16 37 18 35.3 41.3 69 70 101l7 8H0v40h399905l-7 8c-28.7 32\n-52 65.7-70 101-10.7 23.3-16 35.7-16 37 0 .7 7.7 1 23 1h23c24-69.3 71.3-125 142\n-167z M100 147v40h399900v-40zM0 341v40h399900v-40z",
  782. // twoheadleftarrow is from glyph U+219E in font KaTeX AMS Regular
  783. twoheadleftarrow: "M0 167c68 40\n 115.7 95.7 143 167h22c15.3 0 23-.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69\n-70-101l-7-8h125l9 7c50.7 39.3 85 86 103 140h46c0-4.7-6.3-18.7-19-42-18-35.3\n-40-67.3-66-96l-9-9h399716v-40H284l9-9c26-28.7 48-60.7 66-96 12.7-23.333 19\n-37.333 19-42h-46c-18 54-52.3 100.7-103 140l-9 7H95l7-8c28.7-32 52-65.7 70-101\n 10.7-23.333 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 71.3 68 127 0 167z",
  784. twoheadrightarrow: "M400000 167\nc-68-40-115.7-95.7-143-167h-22c-15.3 0-23 .3-23 1 0 1.3 5.3 13.7 16 37 18 35.3\n 41.3 69 70 101l7 8h-125l-9-7c-50.7-39.3-85-86-103-140h-46c0 4.7 6.3 18.7 19 42\n 18 35.3 40 67.3 66 96l9 9H0v40h399716l-9 9c-26 28.7-48 60.7-66 96-12.7 23.333\n-19 37.333-19 42h46c18-54 52.3-100.7 103-140l9-7h125l-7 8c-28.7 32-52 65.7-70\n 101-10.7 23.333-16 35.7-16 37 0 .7 7.7 1 23 1h22c27.3-71.3 75-127 143-167z",
  785. // tilde1 is a modified version of a glyph from the MnSymbol package
  786. tilde1: "M200 55.538c-77 0-168 73.953-177 73.953-3 0-7\n-2.175-9-5.437L2 97c-1-2-2-4-2-6 0-4 2-7 5-9l20-12C116 12 171 0 207 0c86 0\n 114 68 191 68 78 0 168-68 177-68 4 0 7 2 9 5l12 19c1 2.175 2 4.35 2 6.525 0\n 4.35-2 7.613-5 9.788l-19 13.05c-92 63.077-116.937 75.308-183 76.128\n-68.267.847-113-73.952-191-73.952z",
  787. // ditto tilde2, tilde3, & tilde4
  788. tilde2: "M344 55.266c-142 0-300.638 81.316-311.5 86.418\n-8.01 3.762-22.5 10.91-23.5 5.562L1 120c-1-2-1-3-1-4 0-5 3-9 8-10l18.4-9C160.9\n 31.9 283 0 358 0c148 0 188 122 331 122s314-97 326-97c4 0 8 2 10 7l7 21.114\nc1 2.14 1 3.21 1 4.28 0 5.347-3 9.626-7 10.696l-22.3 12.622C852.6 158.372 751\n 181.476 676 181.476c-149 0-189-126.21-332-126.21z",
  789. tilde3: "M786 59C457 59 32 175.242 13 175.242c-6 0-10-3.457\n-11-10.37L.15 138c-1-7 3-12 10-13l19.2-6.4C378.4 40.7 634.3 0 804.3 0c337 0\n 411.8 157 746.8 157 328 0 754-112 773-112 5 0 10 3 11 9l1 14.075c1 8.066-.697\n 16.595-6.697 17.492l-21.052 7.31c-367.9 98.146-609.15 122.696-778.15 122.696\n -338 0-409-156.573-744-156.573z",
  790. tilde4: "M786 58C457 58 32 177.487 13 177.487c-6 0-10-3.345\n-11-10.035L.15 143c-1-7 3-12 10-13l22-6.7C381.2 35 637.15 0 807.15 0c337 0 409\n 177 744 177 328 0 754-127 773-127 5 0 10 3 11 9l1 14.794c1 7.805-3 13.38-9\n 14.495l-20.7 5.574c-366.85 99.79-607.3 139.372-776.3 139.372-338 0-409\n -175.236-744-175.236z",
  791. // vec is from glyph U+20D7 in font KaTeX Main
  792. vec: "M377 20c0-5.333 1.833-10 5.5-14S391 0 397 0c4.667 0 8.667 1.667 12 5\n3.333 2.667 6.667 9 10 19 6.667 24.667 20.333 43.667 41 57 7.333 4.667 11\n10.667 11 18 0 6-1 10-3 12s-6.667 5-14 9c-28.667 14.667-53.667 35.667-75 63\n-1.333 1.333-3.167 3.5-5.5 6.5s-4 4.833-5 5.5c-1 .667-2.5 1.333-4.5 2s-4.333 1\n-7 1c-4.667 0-9.167-1.833-13.5-5.5S337 184 337 178c0-12.667 15.667-32.333 47-59\nH213l-171-1c-8.667-6-13-12.333-13-19 0-4.667 4.333-11.333 13-20h359\nc-16-25.333-24-45-24-59z",
  793. // widehat1 is a modified version of a glyph from the MnSymbol package
  794. widehat1: "M529 0h5l519 115c5 1 9 5 9 10 0 1-1 2-1 3l-4 22\nc-1 5-5 9-11 9h-2L532 67 19 159h-2c-5 0-9-4-11-9l-5-22c-1-6 2-12 8-13z",
  795. // ditto widehat2, widehat3, & widehat4
  796. widehat2: "M1181 0h2l1171 176c6 0 10 5 10 11l-2 23c-1 6-5 10\n-11 10h-1L1182 67 15 220h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z",
  797. widehat3: "M1181 0h2l1171 236c6 0 10 5 10 11l-2 23c-1 6-5 10\n-11 10h-1L1182 67 15 280h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z",
  798. widehat4: "M1181 0h2l1171 296c6 0 10 5 10 11l-2 23c-1 6-5 10\n-11 10h-1L1182 67 15 340h-1c-6 0-10-4-11-10l-2-23c-1-6 4-11 10-11z",
  799. // widecheck paths are all inverted versions of widehat
  800. widecheck1: "M529,159h5l519,-115c5,-1,9,-5,9,-10c0,-1,-1,-2,-1,-3l-4,-22c-1,\n-5,-5,-9,-11,-9h-2l-512,92l-513,-92h-2c-5,0,-9,4,-11,9l-5,22c-1,6,2,12,8,13z",
  801. widecheck2: "M1181,220h2l1171,-176c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,\n-11,-10h-1l-1168,153l-1167,-153h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z",
  802. widecheck3: "M1181,280h2l1171,-236c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,\n-11,-10h-1l-1168,213l-1167,-213h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z",
  803. widecheck4: "M1181,340h2l1171,-296c6,0,10,-5,10,-11l-2,-23c-1,-6,-5,-10,\n-11,-10h-1l-1168,273l-1167,-273h-1c-6,0,-10,4,-11,10l-2,23c-1,6,4,11,10,11z",
  804. // The next ten paths support reaction arrows from the mhchem package.
  805. // Arrows for \ce{<-->} are offset from xAxis by 0.22ex, per mhchem in LaTeX
  806. // baraboveleftarrow is mostly from from glyph U+2190 in font KaTeX Main
  807. baraboveleftarrow: "M400000 620h-399890l3 -3c68.7 -52.7 113.7 -120 135 -202\nc4 -14.7 6 -23 6 -25c0 -7.3 -7 -11 -21 -11c-8 0 -13.2 0.8 -15.5 2.5\nc-2.3 1.7 -4.2 5.8 -5.5 12.5c-1.3 4.7 -2.7 10.3 -4 17c-12 48.7 -34.8 92 -68.5 130\ns-74.2 66.3 -121.5 85c-10 4 -16 7.7 -18 11c0 8.7 6 14.3 18 17c47.3 18.7 87.8 47\n121.5 85s56.5 81.3 68.5 130c0.7 2 1.3 5 2 9s1.2 6.7 1.5 8c0.3 1.3 1 3.3 2 6\ns2.2 4.5 3.5 5.5c1.3 1 3.3 1.8 6 2.5s6 1 10 1c14 0 21 -3.7 21 -11\nc0 -2 -2 -10.3 -6 -25c-20 -79.3 -65 -146.7 -135 -202l-3 -3h399890z\nM100 620v40h399900v-40z M0 241v40h399900v-40zM0 241v40h399900v-40z",
  808. // rightarrowabovebar is mostly from glyph U+2192, KaTeX Main
  809. rightarrowabovebar: "M0 241v40h399891c-47.3 35.3-84 78-110 128-16.7 32\n-27.7 63.7-33 95 0 1.3-.2 2.7-.5 4-.3 1.3-.5 2.3-.5 3 0 7.3 6.7 11 20 11 8 0\n13.2-.8 15.5-2.5 2.3-1.7 4.2-5.5 5.5-11.5 2-13.3 5.7-27 11-41 14.7-44.7 39\n-84.5 73-119.5s73.7-60.2 119-75.5c6-2 9-5.7 9-11s-3-9-9-11c-45.3-15.3-85-40.5\n-119-75.5s-58.3-74.8-73-119.5c-4.7-14-8.3-27.3-11-40-1.3-6.7-3.2-10.8-5.5\n-12.5-2.3-1.7-7.5-2.5-15.5-2.5-14 0-21 3.7-21 11 0 2 2 10.3 6 25 20.7 83.3 67\n151.7 139 205zm96 379h399894v40H0zm0 0h399904v40H0z",
  810. // The short left harpoon has 0.5em (i.e. 500 units) kern on the left end.
  811. // Ref from mhchem.sty: \rlap{\raisebox{-.22ex}{$\kern0.5em
  812. baraboveshortleftharpoon: "M507,435c-4,4,-6.3,8.7,-7,14c0,5.3,0.7,9,2,11\nc1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17\nc2,0.7,5,1,9,1c0,0,5,0,5,0c10.7,0,16.7,-2,18,-6c2,-2.7,1,-9.7,-3,-21\nc-32,-87.3,-82.7,-157.7,-152,-211c0,0,-3,-3,-3,-3l399351,0l0,-40\nc-398570,0,-399437,0,-399437,0z M593 435 v40 H399500 v-40z\nM0 281 v-40 H399908 v40z M0 281 v-40 H399908 v40z",
  813. rightharpoonaboveshortbar: "M0,241 l0,40c399126,0,399993,0,399993,0\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6\nc-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z\nM0 241 v40 H399908 v-40z M0 475 v-40 H399500 v40z M0 475 v-40 H399500 v40z",
  814. shortbaraboveleftharpoon: "M7,435c-4,4,-6.3,8.7,-7,14c0,5.3,0.7,9,2,11\nc1.3,2,5.3,5.3,12,10c90.7,54,156,130,196,228c3.3,10.7,6.3,16.3,9,17c2,0.7,5,1,9,\n1c0,0,5,0,5,0c10.7,0,16.7,-2,18,-6c2,-2.7,1,-9.7,-3,-21c-32,-87.3,-82.7,-157.7,\n-152,-211c0,0,-3,-3,-3,-3l399907,0l0,-40c-399126,0,-399993,0,-399993,0z\nM93 435 v40 H400000 v-40z M500 241 v40 H400000 v-40z M500 241 v40 H400000 v-40z",
  815. shortrightharpoonabovebar: "M53,241l0,40c398570,0,399437,0,399437,0\nc4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199,\n-231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6\nc-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z\nM500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z"
  816. };
  817. var tallDelim = function tallDelim(label, midHeight) {
  818. switch (label) {
  819. case "lbrack":
  820. return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v1759 h347 v-84\nH403z M403 1759 V0 H319 V1759 v" + midHeight + " v1759 h84z";
  821. case "rbrack":
  822. return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v1759 H0 v84 H347z\nM347 1759 V0 H263 V1759 v" + midHeight + " v1759 h84z";
  823. case "vert":
  824. return "M145 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M188 15 H145 v585 v" + midHeight + " v585 h43z";
  825. case "doublevert":
  826. return "M145 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M188 15 H145 v585 v" + midHeight + " v585 h43z\nM367 15 v585 v" + midHeight + " v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v" + -midHeight + " v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M410 15 H367 v585 v" + midHeight + " v585 h43z";
  827. case "lfloor":
  828. return "M319 602 V0 H403 V602 v" + midHeight + " v1715 h263 v84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
  829. case "rfloor":
  830. return "M319 602 V0 H403 V602 v" + midHeight + " v1799 H0 v-84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
  831. case "lceil":
  832. return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v602 h84z\nM403 1759 V0 H319 V1759 v" + midHeight + " v602 h84z";
  833. case "rceil":
  834. return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v602 h84z\nM347 1759 V0 h-84 V1759 v" + midHeight + " v602 h84z";
  835. case "lparen":
  836. return "M863,9c0,-2,-2,-5,-6,-9c0,0,-17,0,-17,0c-12.7,0,-19.3,0.3,-20,1\nc-5.3,5.3,-10.3,11,-15,17c-242.7,294.7,-395.3,682,-458,1162c-21.3,163.3,-33.3,349,\n-36,557 l0," + (midHeight + 84) + "c0.2,6,0,26,0,60c2,159.3,10,310.7,24,454c53.3,528,210,\n949.7,470,1265c4.7,6,9.7,11.7,15,17c0.7,0.7,7,1,19,1c0,0,18,0,18,0c4,-4,6,-7,6,-9\nc0,-2.7,-3.3,-8.7,-10,-18c-135.3,-192.7,-235.5,-414.3,-300.5,-665c-65,-250.7,-102.5,\n-544.7,-112.5,-882c-2,-104,-3,-167,-3,-189\nl0,-" + (midHeight + 92) + "c0,-162.7,5.7,-314,17,-454c20.7,-272,63.7,-513,129,-723c65.3,\n-210,155.3,-396.3,270,-559c6.7,-9.3,10,-15.3,10,-18z";
  837. case "rparen":
  838. return "M76,0c-16.7,0,-25,3,-25,9c0,2,2,6.3,6,13c21.3,28.7,42.3,60.3,\n63,95c96.7,156.7,172.8,332.5,228.5,527.5c55.7,195,92.8,416.5,111.5,664.5\nc11.3,139.3,17,290.7,17,454c0,28,1.7,43,3.3,45l0," + (midHeight + 9) + "\nc-3,4,-3.3,16.7,-3.3,38c0,162,-5.7,313.7,-17,455c-18.7,248,-55.8,469.3,-111.5,664\nc-55.7,194.7,-131.8,370.3,-228.5,527c-20.7,34.7,-41.7,66.3,-63,95c-2,3.3,-4,7,-6,11\nc0,7.3,5.7,11,17,11c0,0,11,0,11,0c9.3,0,14.3,-0.3,15,-1c5.3,-5.3,10.3,-11,15,-17\nc242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558\nl0,-" + (midHeight + 144) + "c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,\n-470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z";
  839. default:
  840. // We should not ever get here.
  841. throw new Error("Unknown stretchy delimiter.");
  842. }
  843. };
  844. /**
  845. * This node represents a document fragment, which contains elements, but when
  846. * placed into the DOM doesn't have any representation itself. It only contains
  847. * children and doesn't have any DOM node properties.
  848. */
  849. class DocumentFragment {
  850. // HtmlDomNode
  851. // Never used; needed for satisfying interface.
  852. constructor(children) {
  853. this.children = void 0;
  854. this.classes = void 0;
  855. this.height = void 0;
  856. this.depth = void 0;
  857. this.maxFontSize = void 0;
  858. this.style = void 0;
  859. this.children = children;
  860. this.classes = [];
  861. this.height = 0;
  862. this.depth = 0;
  863. this.maxFontSize = 0;
  864. this.style = {};
  865. }
  866. hasClass(className) {
  867. return utils.contains(this.classes, className);
  868. }
  869. /** Convert the fragment into a node. */
  870. toNode() {
  871. var frag = document.createDocumentFragment();
  872. for (var i = 0; i < this.children.length; i++) {
  873. frag.appendChild(this.children[i].toNode());
  874. }
  875. return frag;
  876. }
  877. /** Convert the fragment into HTML markup. */
  878. toMarkup() {
  879. var markup = ""; // Simply concatenate the markup for the children together.
  880. for (var i = 0; i < this.children.length; i++) {
  881. markup += this.children[i].toMarkup();
  882. }
  883. return markup;
  884. }
  885. /**
  886. * Converts the math node into a string, similar to innerText. Applies to
  887. * MathDomNode's only.
  888. */
  889. toText() {
  890. // To avoid this, we would subclass documentFragment separately for
  891. // MathML, but polyfills for subclassing is expensive per PR 1469.
  892. // $FlowFixMe: Only works for ChildType = MathDomNode.
  893. var toText = child => child.toText();
  894. return this.children.map(toText).join("");
  895. }
  896. }
  897. // This file is GENERATED by buildMetrics.sh. DO NOT MODIFY.
  898. var fontMetricsData = {
  899. "AMS-Regular": {
  900. "32": [0, 0, 0, 0, 0.25],
  901. "65": [0, 0.68889, 0, 0, 0.72222],
  902. "66": [0, 0.68889, 0, 0, 0.66667],
  903. "67": [0, 0.68889, 0, 0, 0.72222],
  904. "68": [0, 0.68889, 0, 0, 0.72222],
  905. "69": [0, 0.68889, 0, 0, 0.66667],
  906. "70": [0, 0.68889, 0, 0, 0.61111],
  907. "71": [0, 0.68889, 0, 0, 0.77778],
  908. "72": [0, 0.68889, 0, 0, 0.77778],
  909. "73": [0, 0.68889, 0, 0, 0.38889],
  910. "74": [0.16667, 0.68889, 0, 0, 0.5],
  911. "75": [0, 0.68889, 0, 0, 0.77778],
  912. "76": [0, 0.68889, 0, 0, 0.66667],
  913. "77": [0, 0.68889, 0, 0, 0.94445],
  914. "78": [0, 0.68889, 0, 0, 0.72222],
  915. "79": [0.16667, 0.68889, 0, 0, 0.77778],
  916. "80": [0, 0.68889, 0, 0, 0.61111],
  917. "81": [0.16667, 0.68889, 0, 0, 0.77778],
  918. "82": [0, 0.68889, 0, 0, 0.72222],
  919. "83": [0, 0.68889, 0, 0, 0.55556],
  920. "84": [0, 0.68889, 0, 0, 0.66667],
  921. "85": [0, 0.68889, 0, 0, 0.72222],
  922. "86": [0, 0.68889, 0, 0, 0.72222],
  923. "87": [0, 0.68889, 0, 0, 1.0],
  924. "88": [0, 0.68889, 0, 0, 0.72222],
  925. "89": [0, 0.68889, 0, 0, 0.72222],
  926. "90": [0, 0.68889, 0, 0, 0.66667],
  927. "107": [0, 0.68889, 0, 0, 0.55556],
  928. "160": [0, 0, 0, 0, 0.25],
  929. "165": [0, 0.675, 0.025, 0, 0.75],
  930. "174": [0.15559, 0.69224, 0, 0, 0.94666],
  931. "240": [0, 0.68889, 0, 0, 0.55556],
  932. "295": [0, 0.68889, 0, 0, 0.54028],
  933. "710": [0, 0.825, 0, 0, 2.33334],
  934. "732": [0, 0.9, 0, 0, 2.33334],
  935. "770": [0, 0.825, 0, 0, 2.33334],
  936. "771": [0, 0.9, 0, 0, 2.33334],
  937. "989": [0.08167, 0.58167, 0, 0, 0.77778],
  938. "1008": [0, 0.43056, 0.04028, 0, 0.66667],
  939. "8245": [0, 0.54986, 0, 0, 0.275],
  940. "8463": [0, 0.68889, 0, 0, 0.54028],
  941. "8487": [0, 0.68889, 0, 0, 0.72222],
  942. "8498": [0, 0.68889, 0, 0, 0.55556],
  943. "8502": [0, 0.68889, 0, 0, 0.66667],
  944. "8503": [0, 0.68889, 0, 0, 0.44445],
  945. "8504": [0, 0.68889, 0, 0, 0.66667],
  946. "8513": [0, 0.68889, 0, 0, 0.63889],
  947. "8592": [-0.03598, 0.46402, 0, 0, 0.5],
  948. "8594": [-0.03598, 0.46402, 0, 0, 0.5],
  949. "8602": [-0.13313, 0.36687, 0, 0, 1.0],
  950. "8603": [-0.13313, 0.36687, 0, 0, 1.0],
  951. "8606": [0.01354, 0.52239, 0, 0, 1.0],
  952. "8608": [0.01354, 0.52239, 0, 0, 1.0],
  953. "8610": [0.01354, 0.52239, 0, 0, 1.11111],
  954. "8611": [0.01354, 0.52239, 0, 0, 1.11111],
  955. "8619": [0, 0.54986, 0, 0, 1.0],
  956. "8620": [0, 0.54986, 0, 0, 1.0],
  957. "8621": [-0.13313, 0.37788, 0, 0, 1.38889],
  958. "8622": [-0.13313, 0.36687, 0, 0, 1.0],
  959. "8624": [0, 0.69224, 0, 0, 0.5],
  960. "8625": [0, 0.69224, 0, 0, 0.5],
  961. "8630": [0, 0.43056, 0, 0, 1.0],
  962. "8631": [0, 0.43056, 0, 0, 1.0],
  963. "8634": [0.08198, 0.58198, 0, 0, 0.77778],
  964. "8635": [0.08198, 0.58198, 0, 0, 0.77778],
  965. "8638": [0.19444, 0.69224, 0, 0, 0.41667],
  966. "8639": [0.19444, 0.69224, 0, 0, 0.41667],
  967. "8642": [0.19444, 0.69224, 0, 0, 0.41667],
  968. "8643": [0.19444, 0.69224, 0, 0, 0.41667],
  969. "8644": [0.1808, 0.675, 0, 0, 1.0],
  970. "8646": [0.1808, 0.675, 0, 0, 1.0],
  971. "8647": [0.1808, 0.675, 0, 0, 1.0],
  972. "8648": [0.19444, 0.69224, 0, 0, 0.83334],
  973. "8649": [0.1808, 0.675, 0, 0, 1.0],
  974. "8650": [0.19444, 0.69224, 0, 0, 0.83334],
  975. "8651": [0.01354, 0.52239, 0, 0, 1.0],
  976. "8652": [0.01354, 0.52239, 0, 0, 1.0],
  977. "8653": [-0.13313, 0.36687, 0, 0, 1.0],
  978. "8654": [-0.13313, 0.36687, 0, 0, 1.0],
  979. "8655": [-0.13313, 0.36687, 0, 0, 1.0],
  980. "8666": [0.13667, 0.63667, 0, 0, 1.0],
  981. "8667": [0.13667, 0.63667, 0, 0, 1.0],
  982. "8669": [-0.13313, 0.37788, 0, 0, 1.0],
  983. "8672": [-0.064, 0.437, 0, 0, 1.334],
  984. "8674": [-0.064, 0.437, 0, 0, 1.334],
  985. "8705": [0, 0.825, 0, 0, 0.5],
  986. "8708": [0, 0.68889, 0, 0, 0.55556],
  987. "8709": [0.08167, 0.58167, 0, 0, 0.77778],
  988. "8717": [0, 0.43056, 0, 0, 0.42917],
  989. "8722": [-0.03598, 0.46402, 0, 0, 0.5],
  990. "8724": [0.08198, 0.69224, 0, 0, 0.77778],
  991. "8726": [0.08167, 0.58167, 0, 0, 0.77778],
  992. "8733": [0, 0.69224, 0, 0, 0.77778],
  993. "8736": [0, 0.69224, 0, 0, 0.72222],
  994. "8737": [0, 0.69224, 0, 0, 0.72222],
  995. "8738": [0.03517, 0.52239, 0, 0, 0.72222],
  996. "8739": [0.08167, 0.58167, 0, 0, 0.22222],
  997. "8740": [0.25142, 0.74111, 0, 0, 0.27778],
  998. "8741": [0.08167, 0.58167, 0, 0, 0.38889],
  999. "8742": [0.25142, 0.74111, 0, 0, 0.5],
  1000. "8756": [0, 0.69224, 0, 0, 0.66667],
  1001. "8757": [0, 0.69224, 0, 0, 0.66667],
  1002. "8764": [-0.13313, 0.36687, 0, 0, 0.77778],
  1003. "8765": [-0.13313, 0.37788, 0, 0, 0.77778],
  1004. "8769": [-0.13313, 0.36687, 0, 0, 0.77778],
  1005. "8770": [-0.03625, 0.46375, 0, 0, 0.77778],
  1006. "8774": [0.30274, 0.79383, 0, 0, 0.77778],
  1007. "8776": [-0.01688, 0.48312, 0, 0, 0.77778],
  1008. "8778": [0.08167, 0.58167, 0, 0, 0.77778],
  1009. "8782": [0.06062, 0.54986, 0, 0, 0.77778],
  1010. "8783": [0.06062, 0.54986, 0, 0, 0.77778],
  1011. "8785": [0.08198, 0.58198, 0, 0, 0.77778],
  1012. "8786": [0.08198, 0.58198, 0, 0, 0.77778],
  1013. "8787": [0.08198, 0.58198, 0, 0, 0.77778],
  1014. "8790": [0, 0.69224, 0, 0, 0.77778],
  1015. "8791": [0.22958, 0.72958, 0, 0, 0.77778],
  1016. "8796": [0.08198, 0.91667, 0, 0, 0.77778],
  1017. "8806": [0.25583, 0.75583, 0, 0, 0.77778],
  1018. "8807": [0.25583, 0.75583, 0, 0, 0.77778],
  1019. "8808": [0.25142, 0.75726, 0, 0, 0.77778],
  1020. "8809": [0.25142, 0.75726, 0, 0, 0.77778],
  1021. "8812": [0.25583, 0.75583, 0, 0, 0.5],
  1022. "8814": [0.20576, 0.70576, 0, 0, 0.77778],
  1023. "8815": [0.20576, 0.70576, 0, 0, 0.77778],
  1024. "8816": [0.30274, 0.79383, 0, 0, 0.77778],
  1025. "8817": [0.30274, 0.79383, 0, 0, 0.77778],
  1026. "8818": [0.22958, 0.72958, 0, 0, 0.77778],
  1027. "8819": [0.22958, 0.72958, 0, 0, 0.77778],
  1028. "8822": [0.1808, 0.675, 0, 0, 0.77778],
  1029. "8823": [0.1808, 0.675, 0, 0, 0.77778],
  1030. "8828": [0.13667, 0.63667, 0, 0, 0.77778],
  1031. "8829": [0.13667, 0.63667, 0, 0, 0.77778],
  1032. "8830": [0.22958, 0.72958, 0, 0, 0.77778],
  1033. "8831": [0.22958, 0.72958, 0, 0, 0.77778],
  1034. "8832": [0.20576, 0.70576, 0, 0, 0.77778],
  1035. "8833": [0.20576, 0.70576, 0, 0, 0.77778],
  1036. "8840": [0.30274, 0.79383, 0, 0, 0.77778],
  1037. "8841": [0.30274, 0.79383, 0, 0, 0.77778],
  1038. "8842": [0.13597, 0.63597, 0, 0, 0.77778],
  1039. "8843": [0.13597, 0.63597, 0, 0, 0.77778],
  1040. "8847": [0.03517, 0.54986, 0, 0, 0.77778],
  1041. "8848": [0.03517, 0.54986, 0, 0, 0.77778],
  1042. "8858": [0.08198, 0.58198, 0, 0, 0.77778],
  1043. "8859": [0.08198, 0.58198, 0, 0, 0.77778],
  1044. "8861": [0.08198, 0.58198, 0, 0, 0.77778],
  1045. "8862": [0, 0.675, 0, 0, 0.77778],
  1046. "8863": [0, 0.675, 0, 0, 0.77778],
  1047. "8864": [0, 0.675, 0, 0, 0.77778],
  1048. "8865": [0, 0.675, 0, 0, 0.77778],
  1049. "8872": [0, 0.69224, 0, 0, 0.61111],
  1050. "8873": [0, 0.69224, 0, 0, 0.72222],
  1051. "8874": [0, 0.69224, 0, 0, 0.88889],
  1052. "8876": [0, 0.68889, 0, 0, 0.61111],
  1053. "8877": [0, 0.68889, 0, 0, 0.61111],
  1054. "8878": [0, 0.68889, 0, 0, 0.72222],
  1055. "8879": [0, 0.68889, 0, 0, 0.72222],
  1056. "8882": [0.03517, 0.54986, 0, 0, 0.77778],
  1057. "8883": [0.03517, 0.54986, 0, 0, 0.77778],
  1058. "8884": [0.13667, 0.63667, 0, 0, 0.77778],
  1059. "8885": [0.13667, 0.63667, 0, 0, 0.77778],
  1060. "8888": [0, 0.54986, 0, 0, 1.11111],
  1061. "8890": [0.19444, 0.43056, 0, 0, 0.55556],
  1062. "8891": [0.19444, 0.69224, 0, 0, 0.61111],
  1063. "8892": [0.19444, 0.69224, 0, 0, 0.61111],
  1064. "8901": [0, 0.54986, 0, 0, 0.27778],
  1065. "8903": [0.08167, 0.58167, 0, 0, 0.77778],
  1066. "8905": [0.08167, 0.58167, 0, 0, 0.77778],
  1067. "8906": [0.08167, 0.58167, 0, 0, 0.77778],
  1068. "8907": [0, 0.69224, 0, 0, 0.77778],
  1069. "8908": [0, 0.69224, 0, 0, 0.77778],
  1070. "8909": [-0.03598, 0.46402, 0, 0, 0.77778],
  1071. "8910": [0, 0.54986, 0, 0, 0.76042],
  1072. "8911": [0, 0.54986, 0, 0, 0.76042],
  1073. "8912": [0.03517, 0.54986, 0, 0, 0.77778],
  1074. "8913": [0.03517, 0.54986, 0, 0, 0.77778],
  1075. "8914": [0, 0.54986, 0, 0, 0.66667],
  1076. "8915": [0, 0.54986, 0, 0, 0.66667],
  1077. "8916": [0, 0.69224, 0, 0, 0.66667],
  1078. "8918": [0.0391, 0.5391, 0, 0, 0.77778],
  1079. "8919": [0.0391, 0.5391, 0, 0, 0.77778],
  1080. "8920": [0.03517, 0.54986, 0, 0, 1.33334],
  1081. "8921": [0.03517, 0.54986, 0, 0, 1.33334],
  1082. "8922": [0.38569, 0.88569, 0, 0, 0.77778],
  1083. "8923": [0.38569, 0.88569, 0, 0, 0.77778],
  1084. "8926": [0.13667, 0.63667, 0, 0, 0.77778],
  1085. "8927": [0.13667, 0.63667, 0, 0, 0.77778],
  1086. "8928": [0.30274, 0.79383, 0, 0, 0.77778],
  1087. "8929": [0.30274, 0.79383, 0, 0, 0.77778],
  1088. "8934": [0.23222, 0.74111, 0, 0, 0.77778],
  1089. "8935": [0.23222, 0.74111, 0, 0, 0.77778],
  1090. "8936": [0.23222, 0.74111, 0, 0, 0.77778],
  1091. "8937": [0.23222, 0.74111, 0, 0, 0.77778],
  1092. "8938": [0.20576, 0.70576, 0, 0, 0.77778],
  1093. "8939": [0.20576, 0.70576, 0, 0, 0.77778],
  1094. "8940": [0.30274, 0.79383, 0, 0, 0.77778],
  1095. "8941": [0.30274, 0.79383, 0, 0, 0.77778],
  1096. "8994": [0.19444, 0.69224, 0, 0, 0.77778],
  1097. "8995": [0.19444, 0.69224, 0, 0, 0.77778],
  1098. "9416": [0.15559, 0.69224, 0, 0, 0.90222],
  1099. "9484": [0, 0.69224, 0, 0, 0.5],
  1100. "9488": [0, 0.69224, 0, 0, 0.5],
  1101. "9492": [0, 0.37788, 0, 0, 0.5],
  1102. "9496": [0, 0.37788, 0, 0, 0.5],
  1103. "9585": [0.19444, 0.68889, 0, 0, 0.88889],
  1104. "9586": [0.19444, 0.74111, 0, 0, 0.88889],
  1105. "9632": [0, 0.675, 0, 0, 0.77778],
  1106. "9633": [0, 0.675, 0, 0, 0.77778],
  1107. "9650": [0, 0.54986, 0, 0, 0.72222],
  1108. "9651": [0, 0.54986, 0, 0, 0.72222],
  1109. "9654": [0.03517, 0.54986, 0, 0, 0.77778],
  1110. "9660": [0, 0.54986, 0, 0, 0.72222],
  1111. "9661": [0, 0.54986, 0, 0, 0.72222],
  1112. "9664": [0.03517, 0.54986, 0, 0, 0.77778],
  1113. "9674": [0.11111, 0.69224, 0, 0, 0.66667],
  1114. "9733": [0.19444, 0.69224, 0, 0, 0.94445],
  1115. "10003": [0, 0.69224, 0, 0, 0.83334],
  1116. "10016": [0, 0.69224, 0, 0, 0.83334],
  1117. "10731": [0.11111, 0.69224, 0, 0, 0.66667],
  1118. "10846": [0.19444, 0.75583, 0, 0, 0.61111],
  1119. "10877": [0.13667, 0.63667, 0, 0, 0.77778],
  1120. "10878": [0.13667, 0.63667, 0, 0, 0.77778],
  1121. "10885": [0.25583, 0.75583, 0, 0, 0.77778],
  1122. "10886": [0.25583, 0.75583, 0, 0, 0.77778],
  1123. "10887": [0.13597, 0.63597, 0, 0, 0.77778],
  1124. "10888": [0.13597, 0.63597, 0, 0, 0.77778],
  1125. "10889": [0.26167, 0.75726, 0, 0, 0.77778],
  1126. "10890": [0.26167, 0.75726, 0, 0, 0.77778],
  1127. "10891": [0.48256, 0.98256, 0, 0, 0.77778],
  1128. "10892": [0.48256, 0.98256, 0, 0, 0.77778],
  1129. "10901": [0.13667, 0.63667, 0, 0, 0.77778],
  1130. "10902": [0.13667, 0.63667, 0, 0, 0.77778],
  1131. "10933": [0.25142, 0.75726, 0, 0, 0.77778],
  1132. "10934": [0.25142, 0.75726, 0, 0, 0.77778],
  1133. "10935": [0.26167, 0.75726, 0, 0, 0.77778],
  1134. "10936": [0.26167, 0.75726, 0, 0, 0.77778],
  1135. "10937": [0.26167, 0.75726, 0, 0, 0.77778],
  1136. "10938": [0.26167, 0.75726, 0, 0, 0.77778],
  1137. "10949": [0.25583, 0.75583, 0, 0, 0.77778],
  1138. "10950": [0.25583, 0.75583, 0, 0, 0.77778],
  1139. "10955": [0.28481, 0.79383, 0, 0, 0.77778],
  1140. "10956": [0.28481, 0.79383, 0, 0, 0.77778],
  1141. "57350": [0.08167, 0.58167, 0, 0, 0.22222],
  1142. "57351": [0.08167, 0.58167, 0, 0, 0.38889],
  1143. "57352": [0.08167, 0.58167, 0, 0, 0.77778],
  1144. "57353": [0, 0.43056, 0.04028, 0, 0.66667],
  1145. "57356": [0.25142, 0.75726, 0, 0, 0.77778],
  1146. "57357": [0.25142, 0.75726, 0, 0, 0.77778],
  1147. "57358": [0.41951, 0.91951, 0, 0, 0.77778],
  1148. "57359": [0.30274, 0.79383, 0, 0, 0.77778],
  1149. "57360": [0.30274, 0.79383, 0, 0, 0.77778],
  1150. "57361": [0.41951, 0.91951, 0, 0, 0.77778],
  1151. "57366": [0.25142, 0.75726, 0, 0, 0.77778],
  1152. "57367": [0.25142, 0.75726, 0, 0, 0.77778],
  1153. "57368": [0.25142, 0.75726, 0, 0, 0.77778],
  1154. "57369": [0.25142, 0.75726, 0, 0, 0.77778],
  1155. "57370": [0.13597, 0.63597, 0, 0, 0.77778],
  1156. "57371": [0.13597, 0.63597, 0, 0, 0.77778]
  1157. },
  1158. "Caligraphic-Regular": {
  1159. "32": [0, 0, 0, 0, 0.25],
  1160. "65": [0, 0.68333, 0, 0.19445, 0.79847],
  1161. "66": [0, 0.68333, 0.03041, 0.13889, 0.65681],
  1162. "67": [0, 0.68333, 0.05834, 0.13889, 0.52653],
  1163. "68": [0, 0.68333, 0.02778, 0.08334, 0.77139],
  1164. "69": [0, 0.68333, 0.08944, 0.11111, 0.52778],
  1165. "70": [0, 0.68333, 0.09931, 0.11111, 0.71875],
  1166. "71": [0.09722, 0.68333, 0.0593, 0.11111, 0.59487],
  1167. "72": [0, 0.68333, 0.00965, 0.11111, 0.84452],
  1168. "73": [0, 0.68333, 0.07382, 0, 0.54452],
  1169. "74": [0.09722, 0.68333, 0.18472, 0.16667, 0.67778],
  1170. "75": [0, 0.68333, 0.01445, 0.05556, 0.76195],
  1171. "76": [0, 0.68333, 0, 0.13889, 0.68972],
  1172. "77": [0, 0.68333, 0, 0.13889, 1.2009],
  1173. "78": [0, 0.68333, 0.14736, 0.08334, 0.82049],
  1174. "79": [0, 0.68333, 0.02778, 0.11111, 0.79611],
  1175. "80": [0, 0.68333, 0.08222, 0.08334, 0.69556],
  1176. "81": [0.09722, 0.68333, 0, 0.11111, 0.81667],
  1177. "82": [0, 0.68333, 0, 0.08334, 0.8475],
  1178. "83": [0, 0.68333, 0.075, 0.13889, 0.60556],
  1179. "84": [0, 0.68333, 0.25417, 0, 0.54464],
  1180. "85": [0, 0.68333, 0.09931, 0.08334, 0.62583],
  1181. "86": [0, 0.68333, 0.08222, 0, 0.61278],
  1182. "87": [0, 0.68333, 0.08222, 0.08334, 0.98778],
  1183. "88": [0, 0.68333, 0.14643, 0.13889, 0.7133],
  1184. "89": [0.09722, 0.68333, 0.08222, 0.08334, 0.66834],
  1185. "90": [0, 0.68333, 0.07944, 0.13889, 0.72473],
  1186. "160": [0, 0, 0, 0, 0.25]
  1187. },
  1188. "Fraktur-Regular": {
  1189. "32": [0, 0, 0, 0, 0.25],
  1190. "33": [0, 0.69141, 0, 0, 0.29574],
  1191. "34": [0, 0.69141, 0, 0, 0.21471],
  1192. "38": [0, 0.69141, 0, 0, 0.73786],
  1193. "39": [0, 0.69141, 0, 0, 0.21201],
  1194. "40": [0.24982, 0.74947, 0, 0, 0.38865],
  1195. "41": [0.24982, 0.74947, 0, 0, 0.38865],
  1196. "42": [0, 0.62119, 0, 0, 0.27764],
  1197. "43": [0.08319, 0.58283, 0, 0, 0.75623],
  1198. "44": [0, 0.10803, 0, 0, 0.27764],
  1199. "45": [0.08319, 0.58283, 0, 0, 0.75623],
  1200. "46": [0, 0.10803, 0, 0, 0.27764],
  1201. "47": [0.24982, 0.74947, 0, 0, 0.50181],
  1202. "48": [0, 0.47534, 0, 0, 0.50181],
  1203. "49": [0, 0.47534, 0, 0, 0.50181],
  1204. "50": [0, 0.47534, 0, 0, 0.50181],
  1205. "51": [0.18906, 0.47534, 0, 0, 0.50181],
  1206. "52": [0.18906, 0.47534, 0, 0, 0.50181],
  1207. "53": [0.18906, 0.47534, 0, 0, 0.50181],
  1208. "54": [0, 0.69141, 0, 0, 0.50181],
  1209. "55": [0.18906, 0.47534, 0, 0, 0.50181],
  1210. "56": [0, 0.69141, 0, 0, 0.50181],
  1211. "57": [0.18906, 0.47534, 0, 0, 0.50181],
  1212. "58": [0, 0.47534, 0, 0, 0.21606],
  1213. "59": [0.12604, 0.47534, 0, 0, 0.21606],
  1214. "61": [-0.13099, 0.36866, 0, 0, 0.75623],
  1215. "63": [0, 0.69141, 0, 0, 0.36245],
  1216. "65": [0, 0.69141, 0, 0, 0.7176],
  1217. "66": [0, 0.69141, 0, 0, 0.88397],
  1218. "67": [0, 0.69141, 0, 0, 0.61254],
  1219. "68": [0, 0.69141, 0, 0, 0.83158],
  1220. "69": [0, 0.69141, 0, 0, 0.66278],
  1221. "70": [0.12604, 0.69141, 0, 0, 0.61119],
  1222. "71": [0, 0.69141, 0, 0, 0.78539],
  1223. "72": [0.06302, 0.69141, 0, 0, 0.7203],
  1224. "73": [0, 0.69141, 0, 0, 0.55448],
  1225. "74": [0.12604, 0.69141, 0, 0, 0.55231],
  1226. "75": [0, 0.69141, 0, 0, 0.66845],
  1227. "76": [0, 0.69141, 0, 0, 0.66602],
  1228. "77": [0, 0.69141, 0, 0, 1.04953],
  1229. "78": [0, 0.69141, 0, 0, 0.83212],
  1230. "79": [0, 0.69141, 0, 0, 0.82699],
  1231. "80": [0.18906, 0.69141, 0, 0, 0.82753],
  1232. "81": [0.03781, 0.69141, 0, 0, 0.82699],
  1233. "82": [0, 0.69141, 0, 0, 0.82807],
  1234. "83": [0, 0.69141, 0, 0, 0.82861],
  1235. "84": [0, 0.69141, 0, 0, 0.66899],
  1236. "85": [0, 0.69141, 0, 0, 0.64576],
  1237. "86": [0, 0.69141, 0, 0, 0.83131],
  1238. "87": [0, 0.69141, 0, 0, 1.04602],
  1239. "88": [0, 0.69141, 0, 0, 0.71922],
  1240. "89": [0.18906, 0.69141, 0, 0, 0.83293],
  1241. "90": [0.12604, 0.69141, 0, 0, 0.60201],
  1242. "91": [0.24982, 0.74947, 0, 0, 0.27764],
  1243. "93": [0.24982, 0.74947, 0, 0, 0.27764],
  1244. "94": [0, 0.69141, 0, 0, 0.49965],
  1245. "97": [0, 0.47534, 0, 0, 0.50046],
  1246. "98": [0, 0.69141, 0, 0, 0.51315],
  1247. "99": [0, 0.47534, 0, 0, 0.38946],
  1248. "100": [0, 0.62119, 0, 0, 0.49857],
  1249. "101": [0, 0.47534, 0, 0, 0.40053],
  1250. "102": [0.18906, 0.69141, 0, 0, 0.32626],
  1251. "103": [0.18906, 0.47534, 0, 0, 0.5037],
  1252. "104": [0.18906, 0.69141, 0, 0, 0.52126],
  1253. "105": [0, 0.69141, 0, 0, 0.27899],
  1254. "106": [0, 0.69141, 0, 0, 0.28088],
  1255. "107": [0, 0.69141, 0, 0, 0.38946],
  1256. "108": [0, 0.69141, 0, 0, 0.27953],
  1257. "109": [0, 0.47534, 0, 0, 0.76676],
  1258. "110": [0, 0.47534, 0, 0, 0.52666],
  1259. "111": [0, 0.47534, 0, 0, 0.48885],
  1260. "112": [0.18906, 0.52396, 0, 0, 0.50046],
  1261. "113": [0.18906, 0.47534, 0, 0, 0.48912],
  1262. "114": [0, 0.47534, 0, 0, 0.38919],
  1263. "115": [0, 0.47534, 0, 0, 0.44266],
  1264. "116": [0, 0.62119, 0, 0, 0.33301],
  1265. "117": [0, 0.47534, 0, 0, 0.5172],
  1266. "118": [0, 0.52396, 0, 0, 0.5118],
  1267. "119": [0, 0.52396, 0, 0, 0.77351],
  1268. "120": [0.18906, 0.47534, 0, 0, 0.38865],
  1269. "121": [0.18906, 0.47534, 0, 0, 0.49884],
  1270. "122": [0.18906, 0.47534, 0, 0, 0.39054],
  1271. "160": [0, 0, 0, 0, 0.25],
  1272. "8216": [0, 0.69141, 0, 0, 0.21471],
  1273. "8217": [0, 0.69141, 0, 0, 0.21471],
  1274. "58112": [0, 0.62119, 0, 0, 0.49749],
  1275. "58113": [0, 0.62119, 0, 0, 0.4983],
  1276. "58114": [0.18906, 0.69141, 0, 0, 0.33328],
  1277. "58115": [0.18906, 0.69141, 0, 0, 0.32923],
  1278. "58116": [0.18906, 0.47534, 0, 0, 0.50343],
  1279. "58117": [0, 0.69141, 0, 0, 0.33301],
  1280. "58118": [0, 0.62119, 0, 0, 0.33409],
  1281. "58119": [0, 0.47534, 0, 0, 0.50073]
  1282. },
  1283. "Main-Bold": {
  1284. "32": [0, 0, 0, 0, 0.25],
  1285. "33": [0, 0.69444, 0, 0, 0.35],
  1286. "34": [0, 0.69444, 0, 0, 0.60278],
  1287. "35": [0.19444, 0.69444, 0, 0, 0.95833],
  1288. "36": [0.05556, 0.75, 0, 0, 0.575],
  1289. "37": [0.05556, 0.75, 0, 0, 0.95833],
  1290. "38": [0, 0.69444, 0, 0, 0.89444],
  1291. "39": [0, 0.69444, 0, 0, 0.31944],
  1292. "40": [0.25, 0.75, 0, 0, 0.44722],
  1293. "41": [0.25, 0.75, 0, 0, 0.44722],
  1294. "42": [0, 0.75, 0, 0, 0.575],
  1295. "43": [0.13333, 0.63333, 0, 0, 0.89444],
  1296. "44": [0.19444, 0.15556, 0, 0, 0.31944],
  1297. "45": [0, 0.44444, 0, 0, 0.38333],
  1298. "46": [0, 0.15556, 0, 0, 0.31944],
  1299. "47": [0.25, 0.75, 0, 0, 0.575],
  1300. "48": [0, 0.64444, 0, 0, 0.575],
  1301. "49": [0, 0.64444, 0, 0, 0.575],
  1302. "50": [0, 0.64444, 0, 0, 0.575],
  1303. "51": [0, 0.64444, 0, 0, 0.575],
  1304. "52": [0, 0.64444, 0, 0, 0.575],
  1305. "53": [0, 0.64444, 0, 0, 0.575],
  1306. "54": [0, 0.64444, 0, 0, 0.575],
  1307. "55": [0, 0.64444, 0, 0, 0.575],
  1308. "56": [0, 0.64444, 0, 0, 0.575],
  1309. "57": [0, 0.64444, 0, 0, 0.575],
  1310. "58": [0, 0.44444, 0, 0, 0.31944],
  1311. "59": [0.19444, 0.44444, 0, 0, 0.31944],
  1312. "60": [0.08556, 0.58556, 0, 0, 0.89444],
  1313. "61": [-0.10889, 0.39111, 0, 0, 0.89444],
  1314. "62": [0.08556, 0.58556, 0, 0, 0.89444],
  1315. "63": [0, 0.69444, 0, 0, 0.54305],
  1316. "64": [0, 0.69444, 0, 0, 0.89444],
  1317. "65": [0, 0.68611, 0, 0, 0.86944],
  1318. "66": [0, 0.68611, 0, 0, 0.81805],
  1319. "67": [0, 0.68611, 0, 0, 0.83055],
  1320. "68": [0, 0.68611, 0, 0, 0.88194],
  1321. "69": [0, 0.68611, 0, 0, 0.75555],
  1322. "70": [0, 0.68611, 0, 0, 0.72361],
  1323. "71": [0, 0.68611, 0, 0, 0.90416],
  1324. "72": [0, 0.68611, 0, 0, 0.9],
  1325. "73": [0, 0.68611, 0, 0, 0.43611],
  1326. "74": [0, 0.68611, 0, 0, 0.59444],
  1327. "75": [0, 0.68611, 0, 0, 0.90138],
  1328. "76": [0, 0.68611, 0, 0, 0.69166],
  1329. "77": [0, 0.68611, 0, 0, 1.09166],
  1330. "78": [0, 0.68611, 0, 0, 0.9],
  1331. "79": [0, 0.68611, 0, 0, 0.86388],
  1332. "80": [0, 0.68611, 0, 0, 0.78611],
  1333. "81": [0.19444, 0.68611, 0, 0, 0.86388],
  1334. "82": [0, 0.68611, 0, 0, 0.8625],
  1335. "83": [0, 0.68611, 0, 0, 0.63889],
  1336. "84": [0, 0.68611, 0, 0, 0.8],
  1337. "85": [0, 0.68611, 0, 0, 0.88472],
  1338. "86": [0, 0.68611, 0.01597, 0, 0.86944],
  1339. "87": [0, 0.68611, 0.01597, 0, 1.18888],
  1340. "88": [0, 0.68611, 0, 0, 0.86944],
  1341. "89": [0, 0.68611, 0.02875, 0, 0.86944],
  1342. "90": [0, 0.68611, 0, 0, 0.70277],
  1343. "91": [0.25, 0.75, 0, 0, 0.31944],
  1344. "92": [0.25, 0.75, 0, 0, 0.575],
  1345. "93": [0.25, 0.75, 0, 0, 0.31944],
  1346. "94": [0, 0.69444, 0, 0, 0.575],
  1347. "95": [0.31, 0.13444, 0.03194, 0, 0.575],
  1348. "97": [0, 0.44444, 0, 0, 0.55902],
  1349. "98": [0, 0.69444, 0, 0, 0.63889],
  1350. "99": [0, 0.44444, 0, 0, 0.51111],
  1351. "100": [0, 0.69444, 0, 0, 0.63889],
  1352. "101": [0, 0.44444, 0, 0, 0.52708],
  1353. "102": [0, 0.69444, 0.10903, 0, 0.35139],
  1354. "103": [0.19444, 0.44444, 0.01597, 0, 0.575],
  1355. "104": [0, 0.69444, 0, 0, 0.63889],
  1356. "105": [0, 0.69444, 0, 0, 0.31944],
  1357. "106": [0.19444, 0.69444, 0, 0, 0.35139],
  1358. "107": [0, 0.69444, 0, 0, 0.60694],
  1359. "108": [0, 0.69444, 0, 0, 0.31944],
  1360. "109": [0, 0.44444, 0, 0, 0.95833],
  1361. "110": [0, 0.44444, 0, 0, 0.63889],
  1362. "111": [0, 0.44444, 0, 0, 0.575],
  1363. "112": [0.19444, 0.44444, 0, 0, 0.63889],
  1364. "113": [0.19444, 0.44444, 0, 0, 0.60694],
  1365. "114": [0, 0.44444, 0, 0, 0.47361],
  1366. "115": [0, 0.44444, 0, 0, 0.45361],
  1367. "116": [0, 0.63492, 0, 0, 0.44722],
  1368. "117": [0, 0.44444, 0, 0, 0.63889],
  1369. "118": [0, 0.44444, 0.01597, 0, 0.60694],
  1370. "119": [0, 0.44444, 0.01597, 0, 0.83055],
  1371. "120": [0, 0.44444, 0, 0, 0.60694],
  1372. "121": [0.19444, 0.44444, 0.01597, 0, 0.60694],
  1373. "122": [0, 0.44444, 0, 0, 0.51111],
  1374. "123": [0.25, 0.75, 0, 0, 0.575],
  1375. "124": [0.25, 0.75, 0, 0, 0.31944],
  1376. "125": [0.25, 0.75, 0, 0, 0.575],
  1377. "126": [0.35, 0.34444, 0, 0, 0.575],
  1378. "160": [0, 0, 0, 0, 0.25],
  1379. "163": [0, 0.69444, 0, 0, 0.86853],
  1380. "168": [0, 0.69444, 0, 0, 0.575],
  1381. "172": [0, 0.44444, 0, 0, 0.76666],
  1382. "176": [0, 0.69444, 0, 0, 0.86944],
  1383. "177": [0.13333, 0.63333, 0, 0, 0.89444],
  1384. "184": [0.17014, 0, 0, 0, 0.51111],
  1385. "198": [0, 0.68611, 0, 0, 1.04166],
  1386. "215": [0.13333, 0.63333, 0, 0, 0.89444],
  1387. "216": [0.04861, 0.73472, 0, 0, 0.89444],
  1388. "223": [0, 0.69444, 0, 0, 0.59722],
  1389. "230": [0, 0.44444, 0, 0, 0.83055],
  1390. "247": [0.13333, 0.63333, 0, 0, 0.89444],
  1391. "248": [0.09722, 0.54167, 0, 0, 0.575],
  1392. "305": [0, 0.44444, 0, 0, 0.31944],
  1393. "338": [0, 0.68611, 0, 0, 1.16944],
  1394. "339": [0, 0.44444, 0, 0, 0.89444],
  1395. "567": [0.19444, 0.44444, 0, 0, 0.35139],
  1396. "710": [0, 0.69444, 0, 0, 0.575],
  1397. "711": [0, 0.63194, 0, 0, 0.575],
  1398. "713": [0, 0.59611, 0, 0, 0.575],
  1399. "714": [0, 0.69444, 0, 0, 0.575],
  1400. "715": [0, 0.69444, 0, 0, 0.575],
  1401. "728": [0, 0.69444, 0, 0, 0.575],
  1402. "729": [0, 0.69444, 0, 0, 0.31944],
  1403. "730": [0, 0.69444, 0, 0, 0.86944],
  1404. "732": [0, 0.69444, 0, 0, 0.575],
  1405. "733": [0, 0.69444, 0, 0, 0.575],
  1406. "915": [0, 0.68611, 0, 0, 0.69166],
  1407. "916": [0, 0.68611, 0, 0, 0.95833],
  1408. "920": [0, 0.68611, 0, 0, 0.89444],
  1409. "923": [0, 0.68611, 0, 0, 0.80555],
  1410. "926": [0, 0.68611, 0, 0, 0.76666],
  1411. "928": [0, 0.68611, 0, 0, 0.9],
  1412. "931": [0, 0.68611, 0, 0, 0.83055],
  1413. "933": [0, 0.68611, 0, 0, 0.89444],
  1414. "934": [0, 0.68611, 0, 0, 0.83055],
  1415. "936": [0, 0.68611, 0, 0, 0.89444],
  1416. "937": [0, 0.68611, 0, 0, 0.83055],
  1417. "8211": [0, 0.44444, 0.03194, 0, 0.575],
  1418. "8212": [0, 0.44444, 0.03194, 0, 1.14999],
  1419. "8216": [0, 0.69444, 0, 0, 0.31944],
  1420. "8217": [0, 0.69444, 0, 0, 0.31944],
  1421. "8220": [0, 0.69444, 0, 0, 0.60278],
  1422. "8221": [0, 0.69444, 0, 0, 0.60278],
  1423. "8224": [0.19444, 0.69444, 0, 0, 0.51111],
  1424. "8225": [0.19444, 0.69444, 0, 0, 0.51111],
  1425. "8242": [0, 0.55556, 0, 0, 0.34444],
  1426. "8407": [0, 0.72444, 0.15486, 0, 0.575],
  1427. "8463": [0, 0.69444, 0, 0, 0.66759],
  1428. "8465": [0, 0.69444, 0, 0, 0.83055],
  1429. "8467": [0, 0.69444, 0, 0, 0.47361],
  1430. "8472": [0.19444, 0.44444, 0, 0, 0.74027],
  1431. "8476": [0, 0.69444, 0, 0, 0.83055],
  1432. "8501": [0, 0.69444, 0, 0, 0.70277],
  1433. "8592": [-0.10889, 0.39111, 0, 0, 1.14999],
  1434. "8593": [0.19444, 0.69444, 0, 0, 0.575],
  1435. "8594": [-0.10889, 0.39111, 0, 0, 1.14999],
  1436. "8595": [0.19444, 0.69444, 0, 0, 0.575],
  1437. "8596": [-0.10889, 0.39111, 0, 0, 1.14999],
  1438. "8597": [0.25, 0.75, 0, 0, 0.575],
  1439. "8598": [0.19444, 0.69444, 0, 0, 1.14999],
  1440. "8599": [0.19444, 0.69444, 0, 0, 1.14999],
  1441. "8600": [0.19444, 0.69444, 0, 0, 1.14999],
  1442. "8601": [0.19444, 0.69444, 0, 0, 1.14999],
  1443. "8636": [-0.10889, 0.39111, 0, 0, 1.14999],
  1444. "8637": [-0.10889, 0.39111, 0, 0, 1.14999],
  1445. "8640": [-0.10889, 0.39111, 0, 0, 1.14999],
  1446. "8641": [-0.10889, 0.39111, 0, 0, 1.14999],
  1447. "8656": [-0.10889, 0.39111, 0, 0, 1.14999],
  1448. "8657": [0.19444, 0.69444, 0, 0, 0.70277],
  1449. "8658": [-0.10889, 0.39111, 0, 0, 1.14999],
  1450. "8659": [0.19444, 0.69444, 0, 0, 0.70277],
  1451. "8660": [-0.10889, 0.39111, 0, 0, 1.14999],
  1452. "8661": [0.25, 0.75, 0, 0, 0.70277],
  1453. "8704": [0, 0.69444, 0, 0, 0.63889],
  1454. "8706": [0, 0.69444, 0.06389, 0, 0.62847],
  1455. "8707": [0, 0.69444, 0, 0, 0.63889],
  1456. "8709": [0.05556, 0.75, 0, 0, 0.575],
  1457. "8711": [0, 0.68611, 0, 0, 0.95833],
  1458. "8712": [0.08556, 0.58556, 0, 0, 0.76666],
  1459. "8715": [0.08556, 0.58556, 0, 0, 0.76666],
  1460. "8722": [0.13333, 0.63333, 0, 0, 0.89444],
  1461. "8723": [0.13333, 0.63333, 0, 0, 0.89444],
  1462. "8725": [0.25, 0.75, 0, 0, 0.575],
  1463. "8726": [0.25, 0.75, 0, 0, 0.575],
  1464. "8727": [-0.02778, 0.47222, 0, 0, 0.575],
  1465. "8728": [-0.02639, 0.47361, 0, 0, 0.575],
  1466. "8729": [-0.02639, 0.47361, 0, 0, 0.575],
  1467. "8730": [0.18, 0.82, 0, 0, 0.95833],
  1468. "8733": [0, 0.44444, 0, 0, 0.89444],
  1469. "8734": [0, 0.44444, 0, 0, 1.14999],
  1470. "8736": [0, 0.69224, 0, 0, 0.72222],
  1471. "8739": [0.25, 0.75, 0, 0, 0.31944],
  1472. "8741": [0.25, 0.75, 0, 0, 0.575],
  1473. "8743": [0, 0.55556, 0, 0, 0.76666],
  1474. "8744": [0, 0.55556, 0, 0, 0.76666],
  1475. "8745": [0, 0.55556, 0, 0, 0.76666],
  1476. "8746": [0, 0.55556, 0, 0, 0.76666],
  1477. "8747": [0.19444, 0.69444, 0.12778, 0, 0.56875],
  1478. "8764": [-0.10889, 0.39111, 0, 0, 0.89444],
  1479. "8768": [0.19444, 0.69444, 0, 0, 0.31944],
  1480. "8771": [0.00222, 0.50222, 0, 0, 0.89444],
  1481. "8773": [0.027, 0.638, 0, 0, 0.894],
  1482. "8776": [0.02444, 0.52444, 0, 0, 0.89444],
  1483. "8781": [0.00222, 0.50222, 0, 0, 0.89444],
  1484. "8801": [0.00222, 0.50222, 0, 0, 0.89444],
  1485. "8804": [0.19667, 0.69667, 0, 0, 0.89444],
  1486. "8805": [0.19667, 0.69667, 0, 0, 0.89444],
  1487. "8810": [0.08556, 0.58556, 0, 0, 1.14999],
  1488. "8811": [0.08556, 0.58556, 0, 0, 1.14999],
  1489. "8826": [0.08556, 0.58556, 0, 0, 0.89444],
  1490. "8827": [0.08556, 0.58556, 0, 0, 0.89444],
  1491. "8834": [0.08556, 0.58556, 0, 0, 0.89444],
  1492. "8835": [0.08556, 0.58556, 0, 0, 0.89444],
  1493. "8838": [0.19667, 0.69667, 0, 0, 0.89444],
  1494. "8839": [0.19667, 0.69667, 0, 0, 0.89444],
  1495. "8846": [0, 0.55556, 0, 0, 0.76666],
  1496. "8849": [0.19667, 0.69667, 0, 0, 0.89444],
  1497. "8850": [0.19667, 0.69667, 0, 0, 0.89444],
  1498. "8851": [0, 0.55556, 0, 0, 0.76666],
  1499. "8852": [0, 0.55556, 0, 0, 0.76666],
  1500. "8853": [0.13333, 0.63333, 0, 0, 0.89444],
  1501. "8854": [0.13333, 0.63333, 0, 0, 0.89444],
  1502. "8855": [0.13333, 0.63333, 0, 0, 0.89444],
  1503. "8856": [0.13333, 0.63333, 0, 0, 0.89444],
  1504. "8857": [0.13333, 0.63333, 0, 0, 0.89444],
  1505. "8866": [0, 0.69444, 0, 0, 0.70277],
  1506. "8867": [0, 0.69444, 0, 0, 0.70277],
  1507. "8868": [0, 0.69444, 0, 0, 0.89444],
  1508. "8869": [0, 0.69444, 0, 0, 0.89444],
  1509. "8900": [-0.02639, 0.47361, 0, 0, 0.575],
  1510. "8901": [-0.02639, 0.47361, 0, 0, 0.31944],
  1511. "8902": [-0.02778, 0.47222, 0, 0, 0.575],
  1512. "8968": [0.25, 0.75, 0, 0, 0.51111],
  1513. "8969": [0.25, 0.75, 0, 0, 0.51111],
  1514. "8970": [0.25, 0.75, 0, 0, 0.51111],
  1515. "8971": [0.25, 0.75, 0, 0, 0.51111],
  1516. "8994": [-0.13889, 0.36111, 0, 0, 1.14999],
  1517. "8995": [-0.13889, 0.36111, 0, 0, 1.14999],
  1518. "9651": [0.19444, 0.69444, 0, 0, 1.02222],
  1519. "9657": [-0.02778, 0.47222, 0, 0, 0.575],
  1520. "9661": [0.19444, 0.69444, 0, 0, 1.02222],
  1521. "9667": [-0.02778, 0.47222, 0, 0, 0.575],
  1522. "9711": [0.19444, 0.69444, 0, 0, 1.14999],
  1523. "9824": [0.12963, 0.69444, 0, 0, 0.89444],
  1524. "9825": [0.12963, 0.69444, 0, 0, 0.89444],
  1525. "9826": [0.12963, 0.69444, 0, 0, 0.89444],
  1526. "9827": [0.12963, 0.69444, 0, 0, 0.89444],
  1527. "9837": [0, 0.75, 0, 0, 0.44722],
  1528. "9838": [0.19444, 0.69444, 0, 0, 0.44722],
  1529. "9839": [0.19444, 0.69444, 0, 0, 0.44722],
  1530. "10216": [0.25, 0.75, 0, 0, 0.44722],
  1531. "10217": [0.25, 0.75, 0, 0, 0.44722],
  1532. "10815": [0, 0.68611, 0, 0, 0.9],
  1533. "10927": [0.19667, 0.69667, 0, 0, 0.89444],
  1534. "10928": [0.19667, 0.69667, 0, 0, 0.89444],
  1535. "57376": [0.19444, 0.69444, 0, 0, 0]
  1536. },
  1537. "Main-BoldItalic": {
  1538. "32": [0, 0, 0, 0, 0.25],
  1539. "33": [0, 0.69444, 0.11417, 0, 0.38611],
  1540. "34": [0, 0.69444, 0.07939, 0, 0.62055],
  1541. "35": [0.19444, 0.69444, 0.06833, 0, 0.94444],
  1542. "37": [0.05556, 0.75, 0.12861, 0, 0.94444],
  1543. "38": [0, 0.69444, 0.08528, 0, 0.88555],
  1544. "39": [0, 0.69444, 0.12945, 0, 0.35555],
  1545. "40": [0.25, 0.75, 0.15806, 0, 0.47333],
  1546. "41": [0.25, 0.75, 0.03306, 0, 0.47333],
  1547. "42": [0, 0.75, 0.14333, 0, 0.59111],
  1548. "43": [0.10333, 0.60333, 0.03306, 0, 0.88555],
  1549. "44": [0.19444, 0.14722, 0, 0, 0.35555],
  1550. "45": [0, 0.44444, 0.02611, 0, 0.41444],
  1551. "46": [0, 0.14722, 0, 0, 0.35555],
  1552. "47": [0.25, 0.75, 0.15806, 0, 0.59111],
  1553. "48": [0, 0.64444, 0.13167, 0, 0.59111],
  1554. "49": [0, 0.64444, 0.13167, 0, 0.59111],
  1555. "50": [0, 0.64444, 0.13167, 0, 0.59111],
  1556. "51": [0, 0.64444, 0.13167, 0, 0.59111],
  1557. "52": [0.19444, 0.64444, 0.13167, 0, 0.59111],
  1558. "53": [0, 0.64444, 0.13167, 0, 0.59111],
  1559. "54": [0, 0.64444, 0.13167, 0, 0.59111],
  1560. "55": [0.19444, 0.64444, 0.13167, 0, 0.59111],
  1561. "56": [0, 0.64444, 0.13167, 0, 0.59111],
  1562. "57": [0, 0.64444, 0.13167, 0, 0.59111],
  1563. "58": [0, 0.44444, 0.06695, 0, 0.35555],
  1564. "59": [0.19444, 0.44444, 0.06695, 0, 0.35555],
  1565. "61": [-0.10889, 0.39111, 0.06833, 0, 0.88555],
  1566. "63": [0, 0.69444, 0.11472, 0, 0.59111],
  1567. "64": [0, 0.69444, 0.09208, 0, 0.88555],
  1568. "65": [0, 0.68611, 0, 0, 0.86555],
  1569. "66": [0, 0.68611, 0.0992, 0, 0.81666],
  1570. "67": [0, 0.68611, 0.14208, 0, 0.82666],
  1571. "68": [0, 0.68611, 0.09062, 0, 0.87555],
  1572. "69": [0, 0.68611, 0.11431, 0, 0.75666],
  1573. "70": [0, 0.68611, 0.12903, 0, 0.72722],
  1574. "71": [0, 0.68611, 0.07347, 0, 0.89527],
  1575. "72": [0, 0.68611, 0.17208, 0, 0.8961],
  1576. "73": [0, 0.68611, 0.15681, 0, 0.47166],
  1577. "74": [0, 0.68611, 0.145, 0, 0.61055],
  1578. "75": [0, 0.68611, 0.14208, 0, 0.89499],
  1579. "76": [0, 0.68611, 0, 0, 0.69777],
  1580. "77": [0, 0.68611, 0.17208, 0, 1.07277],
  1581. "78": [0, 0.68611, 0.17208, 0, 0.8961],
  1582. "79": [0, 0.68611, 0.09062, 0, 0.85499],
  1583. "80": [0, 0.68611, 0.0992, 0, 0.78721],
  1584. "81": [0.19444, 0.68611, 0.09062, 0, 0.85499],
  1585. "82": [0, 0.68611, 0.02559, 0, 0.85944],
  1586. "83": [0, 0.68611, 0.11264, 0, 0.64999],
  1587. "84": [0, 0.68611, 0.12903, 0, 0.7961],
  1588. "85": [0, 0.68611, 0.17208, 0, 0.88083],
  1589. "86": [0, 0.68611, 0.18625, 0, 0.86555],
  1590. "87": [0, 0.68611, 0.18625, 0, 1.15999],
  1591. "88": [0, 0.68611, 0.15681, 0, 0.86555],
  1592. "89": [0, 0.68611, 0.19803, 0, 0.86555],
  1593. "90": [0, 0.68611, 0.14208, 0, 0.70888],
  1594. "91": [0.25, 0.75, 0.1875, 0, 0.35611],
  1595. "93": [0.25, 0.75, 0.09972, 0, 0.35611],
  1596. "94": [0, 0.69444, 0.06709, 0, 0.59111],
  1597. "95": [0.31, 0.13444, 0.09811, 0, 0.59111],
  1598. "97": [0, 0.44444, 0.09426, 0, 0.59111],
  1599. "98": [0, 0.69444, 0.07861, 0, 0.53222],
  1600. "99": [0, 0.44444, 0.05222, 0, 0.53222],
  1601. "100": [0, 0.69444, 0.10861, 0, 0.59111],
  1602. "101": [0, 0.44444, 0.085, 0, 0.53222],
  1603. "102": [0.19444, 0.69444, 0.21778, 0, 0.4],
  1604. "103": [0.19444, 0.44444, 0.105, 0, 0.53222],
  1605. "104": [0, 0.69444, 0.09426, 0, 0.59111],
  1606. "105": [0, 0.69326, 0.11387, 0, 0.35555],
  1607. "106": [0.19444, 0.69326, 0.1672, 0, 0.35555],
  1608. "107": [0, 0.69444, 0.11111, 0, 0.53222],
  1609. "108": [0, 0.69444, 0.10861, 0, 0.29666],
  1610. "109": [0, 0.44444, 0.09426, 0, 0.94444],
  1611. "110": [0, 0.44444, 0.09426, 0, 0.64999],
  1612. "111": [0, 0.44444, 0.07861, 0, 0.59111],
  1613. "112": [0.19444, 0.44444, 0.07861, 0, 0.59111],
  1614. "113": [0.19444, 0.44444, 0.105, 0, 0.53222],
  1615. "114": [0, 0.44444, 0.11111, 0, 0.50167],
  1616. "115": [0, 0.44444, 0.08167, 0, 0.48694],
  1617. "116": [0, 0.63492, 0.09639, 0, 0.385],
  1618. "117": [0, 0.44444, 0.09426, 0, 0.62055],
  1619. "118": [0, 0.44444, 0.11111, 0, 0.53222],
  1620. "119": [0, 0.44444, 0.11111, 0, 0.76777],
  1621. "120": [0, 0.44444, 0.12583, 0, 0.56055],
  1622. "121": [0.19444, 0.44444, 0.105, 0, 0.56166],
  1623. "122": [0, 0.44444, 0.13889, 0, 0.49055],
  1624. "126": [0.35, 0.34444, 0.11472, 0, 0.59111],
  1625. "160": [0, 0, 0, 0, 0.25],
  1626. "168": [0, 0.69444, 0.11473, 0, 0.59111],
  1627. "176": [0, 0.69444, 0, 0, 0.94888],
  1628. "184": [0.17014, 0, 0, 0, 0.53222],
  1629. "198": [0, 0.68611, 0.11431, 0, 1.02277],
  1630. "216": [0.04861, 0.73472, 0.09062, 0, 0.88555],
  1631. "223": [0.19444, 0.69444, 0.09736, 0, 0.665],
  1632. "230": [0, 0.44444, 0.085, 0, 0.82666],
  1633. "248": [0.09722, 0.54167, 0.09458, 0, 0.59111],
  1634. "305": [0, 0.44444, 0.09426, 0, 0.35555],
  1635. "338": [0, 0.68611, 0.11431, 0, 1.14054],
  1636. "339": [0, 0.44444, 0.085, 0, 0.82666],
  1637. "567": [0.19444, 0.44444, 0.04611, 0, 0.385],
  1638. "710": [0, 0.69444, 0.06709, 0, 0.59111],
  1639. "711": [0, 0.63194, 0.08271, 0, 0.59111],
  1640. "713": [0, 0.59444, 0.10444, 0, 0.59111],
  1641. "714": [0, 0.69444, 0.08528, 0, 0.59111],
  1642. "715": [0, 0.69444, 0, 0, 0.59111],
  1643. "728": [0, 0.69444, 0.10333, 0, 0.59111],
  1644. "729": [0, 0.69444, 0.12945, 0, 0.35555],
  1645. "730": [0, 0.69444, 0, 0, 0.94888],
  1646. "732": [0, 0.69444, 0.11472, 0, 0.59111],
  1647. "733": [0, 0.69444, 0.11472, 0, 0.59111],
  1648. "915": [0, 0.68611, 0.12903, 0, 0.69777],
  1649. "916": [0, 0.68611, 0, 0, 0.94444],
  1650. "920": [0, 0.68611, 0.09062, 0, 0.88555],
  1651. "923": [0, 0.68611, 0, 0, 0.80666],
  1652. "926": [0, 0.68611, 0.15092, 0, 0.76777],
  1653. "928": [0, 0.68611, 0.17208, 0, 0.8961],
  1654. "931": [0, 0.68611, 0.11431, 0, 0.82666],
  1655. "933": [0, 0.68611, 0.10778, 0, 0.88555],
  1656. "934": [0, 0.68611, 0.05632, 0, 0.82666],
  1657. "936": [0, 0.68611, 0.10778, 0, 0.88555],
  1658. "937": [0, 0.68611, 0.0992, 0, 0.82666],
  1659. "8211": [0, 0.44444, 0.09811, 0, 0.59111],
  1660. "8212": [0, 0.44444, 0.09811, 0, 1.18221],
  1661. "8216": [0, 0.69444, 0.12945, 0, 0.35555],
  1662. "8217": [0, 0.69444, 0.12945, 0, 0.35555],
  1663. "8220": [0, 0.69444, 0.16772, 0, 0.62055],
  1664. "8221": [0, 0.69444, 0.07939, 0, 0.62055]
  1665. },
  1666. "Main-Italic": {
  1667. "32": [0, 0, 0, 0, 0.25],
  1668. "33": [0, 0.69444, 0.12417, 0, 0.30667],
  1669. "34": [0, 0.69444, 0.06961, 0, 0.51444],
  1670. "35": [0.19444, 0.69444, 0.06616, 0, 0.81777],
  1671. "37": [0.05556, 0.75, 0.13639, 0, 0.81777],
  1672. "38": [0, 0.69444, 0.09694, 0, 0.76666],
  1673. "39": [0, 0.69444, 0.12417, 0, 0.30667],
  1674. "40": [0.25, 0.75, 0.16194, 0, 0.40889],
  1675. "41": [0.25, 0.75, 0.03694, 0, 0.40889],
  1676. "42": [0, 0.75, 0.14917, 0, 0.51111],
  1677. "43": [0.05667, 0.56167, 0.03694, 0, 0.76666],
  1678. "44": [0.19444, 0.10556, 0, 0, 0.30667],
  1679. "45": [0, 0.43056, 0.02826, 0, 0.35778],
  1680. "46": [0, 0.10556, 0, 0, 0.30667],
  1681. "47": [0.25, 0.75, 0.16194, 0, 0.51111],
  1682. "48": [0, 0.64444, 0.13556, 0, 0.51111],
  1683. "49": [0, 0.64444, 0.13556, 0, 0.51111],
  1684. "50": [0, 0.64444, 0.13556, 0, 0.51111],
  1685. "51": [0, 0.64444, 0.13556, 0, 0.51111],
  1686. "52": [0.19444, 0.64444, 0.13556, 0, 0.51111],
  1687. "53": [0, 0.64444, 0.13556, 0, 0.51111],
  1688. "54": [0, 0.64444, 0.13556, 0, 0.51111],
  1689. "55": [0.19444, 0.64444, 0.13556, 0, 0.51111],
  1690. "56": [0, 0.64444, 0.13556, 0, 0.51111],
  1691. "57": [0, 0.64444, 0.13556, 0, 0.51111],
  1692. "58": [0, 0.43056, 0.0582, 0, 0.30667],
  1693. "59": [0.19444, 0.43056, 0.0582, 0, 0.30667],
  1694. "61": [-0.13313, 0.36687, 0.06616, 0, 0.76666],
  1695. "63": [0, 0.69444, 0.1225, 0, 0.51111],
  1696. "64": [0, 0.69444, 0.09597, 0, 0.76666],
  1697. "65": [0, 0.68333, 0, 0, 0.74333],
  1698. "66": [0, 0.68333, 0.10257, 0, 0.70389],
  1699. "67": [0, 0.68333, 0.14528, 0, 0.71555],
  1700. "68": [0, 0.68333, 0.09403, 0, 0.755],
  1701. "69": [0, 0.68333, 0.12028, 0, 0.67833],
  1702. "70": [0, 0.68333, 0.13305, 0, 0.65277],
  1703. "71": [0, 0.68333, 0.08722, 0, 0.77361],
  1704. "72": [0, 0.68333, 0.16389, 0, 0.74333],
  1705. "73": [0, 0.68333, 0.15806, 0, 0.38555],
  1706. "74": [0, 0.68333, 0.14028, 0, 0.525],
  1707. "75": [0, 0.68333, 0.14528, 0, 0.76888],
  1708. "76": [0, 0.68333, 0, 0, 0.62722],
  1709. "77": [0, 0.68333, 0.16389, 0, 0.89666],
  1710. "78": [0, 0.68333, 0.16389, 0, 0.74333],
  1711. "79": [0, 0.68333, 0.09403, 0, 0.76666],
  1712. "80": [0, 0.68333, 0.10257, 0, 0.67833],
  1713. "81": [0.19444, 0.68333, 0.09403, 0, 0.76666],
  1714. "82": [0, 0.68333, 0.03868, 0, 0.72944],
  1715. "83": [0, 0.68333, 0.11972, 0, 0.56222],
  1716. "84": [0, 0.68333, 0.13305, 0, 0.71555],
  1717. "85": [0, 0.68333, 0.16389, 0, 0.74333],
  1718. "86": [0, 0.68333, 0.18361, 0, 0.74333],
  1719. "87": [0, 0.68333, 0.18361, 0, 0.99888],
  1720. "88": [0, 0.68333, 0.15806, 0, 0.74333],
  1721. "89": [0, 0.68333, 0.19383, 0, 0.74333],
  1722. "90": [0, 0.68333, 0.14528, 0, 0.61333],
  1723. "91": [0.25, 0.75, 0.1875, 0, 0.30667],
  1724. "93": [0.25, 0.75, 0.10528, 0, 0.30667],
  1725. "94": [0, 0.69444, 0.06646, 0, 0.51111],
  1726. "95": [0.31, 0.12056, 0.09208, 0, 0.51111],
  1727. "97": [0, 0.43056, 0.07671, 0, 0.51111],
  1728. "98": [0, 0.69444, 0.06312, 0, 0.46],
  1729. "99": [0, 0.43056, 0.05653, 0, 0.46],
  1730. "100": [0, 0.69444, 0.10333, 0, 0.51111],
  1731. "101": [0, 0.43056, 0.07514, 0, 0.46],
  1732. "102": [0.19444, 0.69444, 0.21194, 0, 0.30667],
  1733. "103": [0.19444, 0.43056, 0.08847, 0, 0.46],
  1734. "104": [0, 0.69444, 0.07671, 0, 0.51111],
  1735. "105": [0, 0.65536, 0.1019, 0, 0.30667],
  1736. "106": [0.19444, 0.65536, 0.14467, 0, 0.30667],
  1737. "107": [0, 0.69444, 0.10764, 0, 0.46],
  1738. "108": [0, 0.69444, 0.10333, 0, 0.25555],
  1739. "109": [0, 0.43056, 0.07671, 0, 0.81777],
  1740. "110": [0, 0.43056, 0.07671, 0, 0.56222],
  1741. "111": [0, 0.43056, 0.06312, 0, 0.51111],
  1742. "112": [0.19444, 0.43056, 0.06312, 0, 0.51111],
  1743. "113": [0.19444, 0.43056, 0.08847, 0, 0.46],
  1744. "114": [0, 0.43056, 0.10764, 0, 0.42166],
  1745. "115": [0, 0.43056, 0.08208, 0, 0.40889],
  1746. "116": [0, 0.61508, 0.09486, 0, 0.33222],
  1747. "117": [0, 0.43056, 0.07671, 0, 0.53666],
  1748. "118": [0, 0.43056, 0.10764, 0, 0.46],
  1749. "119": [0, 0.43056, 0.10764, 0, 0.66444],
  1750. "120": [0, 0.43056, 0.12042, 0, 0.46389],
  1751. "121": [0.19444, 0.43056, 0.08847, 0, 0.48555],
  1752. "122": [0, 0.43056, 0.12292, 0, 0.40889],
  1753. "126": [0.35, 0.31786, 0.11585, 0, 0.51111],
  1754. "160": [0, 0, 0, 0, 0.25],
  1755. "168": [0, 0.66786, 0.10474, 0, 0.51111],
  1756. "176": [0, 0.69444, 0, 0, 0.83129],
  1757. "184": [0.17014, 0, 0, 0, 0.46],
  1758. "198": [0, 0.68333, 0.12028, 0, 0.88277],
  1759. "216": [0.04861, 0.73194, 0.09403, 0, 0.76666],
  1760. "223": [0.19444, 0.69444, 0.10514, 0, 0.53666],
  1761. "230": [0, 0.43056, 0.07514, 0, 0.71555],
  1762. "248": [0.09722, 0.52778, 0.09194, 0, 0.51111],
  1763. "338": [0, 0.68333, 0.12028, 0, 0.98499],
  1764. "339": [0, 0.43056, 0.07514, 0, 0.71555],
  1765. "710": [0, 0.69444, 0.06646, 0, 0.51111],
  1766. "711": [0, 0.62847, 0.08295, 0, 0.51111],
  1767. "713": [0, 0.56167, 0.10333, 0, 0.51111],
  1768. "714": [0, 0.69444, 0.09694, 0, 0.51111],
  1769. "715": [0, 0.69444, 0, 0, 0.51111],
  1770. "728": [0, 0.69444, 0.10806, 0, 0.51111],
  1771. "729": [0, 0.66786, 0.11752, 0, 0.30667],
  1772. "730": [0, 0.69444, 0, 0, 0.83129],
  1773. "732": [0, 0.66786, 0.11585, 0, 0.51111],
  1774. "733": [0, 0.69444, 0.1225, 0, 0.51111],
  1775. "915": [0, 0.68333, 0.13305, 0, 0.62722],
  1776. "916": [0, 0.68333, 0, 0, 0.81777],
  1777. "920": [0, 0.68333, 0.09403, 0, 0.76666],
  1778. "923": [0, 0.68333, 0, 0, 0.69222],
  1779. "926": [0, 0.68333, 0.15294, 0, 0.66444],
  1780. "928": [0, 0.68333, 0.16389, 0, 0.74333],
  1781. "931": [0, 0.68333, 0.12028, 0, 0.71555],
  1782. "933": [0, 0.68333, 0.11111, 0, 0.76666],
  1783. "934": [0, 0.68333, 0.05986, 0, 0.71555],
  1784. "936": [0, 0.68333, 0.11111, 0, 0.76666],
  1785. "937": [0, 0.68333, 0.10257, 0, 0.71555],
  1786. "8211": [0, 0.43056, 0.09208, 0, 0.51111],
  1787. "8212": [0, 0.43056, 0.09208, 0, 1.02222],
  1788. "8216": [0, 0.69444, 0.12417, 0, 0.30667],
  1789. "8217": [0, 0.69444, 0.12417, 0, 0.30667],
  1790. "8220": [0, 0.69444, 0.1685, 0, 0.51444],
  1791. "8221": [0, 0.69444, 0.06961, 0, 0.51444],
  1792. "8463": [0, 0.68889, 0, 0, 0.54028]
  1793. },
  1794. "Main-Regular": {
  1795. "32": [0, 0, 0, 0, 0.25],
  1796. "33": [0, 0.69444, 0, 0, 0.27778],
  1797. "34": [0, 0.69444, 0, 0, 0.5],
  1798. "35": [0.19444, 0.69444, 0, 0, 0.83334],
  1799. "36": [0.05556, 0.75, 0, 0, 0.5],
  1800. "37": [0.05556, 0.75, 0, 0, 0.83334],
  1801. "38": [0, 0.69444, 0, 0, 0.77778],
  1802. "39": [0, 0.69444, 0, 0, 0.27778],
  1803. "40": [0.25, 0.75, 0, 0, 0.38889],
  1804. "41": [0.25, 0.75, 0, 0, 0.38889],
  1805. "42": [0, 0.75, 0, 0, 0.5],
  1806. "43": [0.08333, 0.58333, 0, 0, 0.77778],
  1807. "44": [0.19444, 0.10556, 0, 0, 0.27778],
  1808. "45": [0, 0.43056, 0, 0, 0.33333],
  1809. "46": [0, 0.10556, 0, 0, 0.27778],
  1810. "47": [0.25, 0.75, 0, 0, 0.5],
  1811. "48": [0, 0.64444, 0, 0, 0.5],
  1812. "49": [0, 0.64444, 0, 0, 0.5],
  1813. "50": [0, 0.64444, 0, 0, 0.5],
  1814. "51": [0, 0.64444, 0, 0, 0.5],
  1815. "52": [0, 0.64444, 0, 0, 0.5],
  1816. "53": [0, 0.64444, 0, 0, 0.5],
  1817. "54": [0, 0.64444, 0, 0, 0.5],
  1818. "55": [0, 0.64444, 0, 0, 0.5],
  1819. "56": [0, 0.64444, 0, 0, 0.5],
  1820. "57": [0, 0.64444, 0, 0, 0.5],
  1821. "58": [0, 0.43056, 0, 0, 0.27778],
  1822. "59": [0.19444, 0.43056, 0, 0, 0.27778],
  1823. "60": [0.0391, 0.5391, 0, 0, 0.77778],
  1824. "61": [-0.13313, 0.36687, 0, 0, 0.77778],
  1825. "62": [0.0391, 0.5391, 0, 0, 0.77778],
  1826. "63": [0, 0.69444, 0, 0, 0.47222],
  1827. "64": [0, 0.69444, 0, 0, 0.77778],
  1828. "65": [0, 0.68333, 0, 0, 0.75],
  1829. "66": [0, 0.68333, 0, 0, 0.70834],
  1830. "67": [0, 0.68333, 0, 0, 0.72222],
  1831. "68": [0, 0.68333, 0, 0, 0.76389],
  1832. "69": [0, 0.68333, 0, 0, 0.68056],
  1833. "70": [0, 0.68333, 0, 0, 0.65278],
  1834. "71": [0, 0.68333, 0, 0, 0.78472],
  1835. "72": [0, 0.68333, 0, 0, 0.75],
  1836. "73": [0, 0.68333, 0, 0, 0.36111],
  1837. "74": [0, 0.68333, 0, 0, 0.51389],
  1838. "75": [0, 0.68333, 0, 0, 0.77778],
  1839. "76": [0, 0.68333, 0, 0, 0.625],
  1840. "77": [0, 0.68333, 0, 0, 0.91667],
  1841. "78": [0, 0.68333, 0, 0, 0.75],
  1842. "79": [0, 0.68333, 0, 0, 0.77778],
  1843. "80": [0, 0.68333, 0, 0, 0.68056],
  1844. "81": [0.19444, 0.68333, 0, 0, 0.77778],
  1845. "82": [0, 0.68333, 0, 0, 0.73611],
  1846. "83": [0, 0.68333, 0, 0, 0.55556],
  1847. "84": [0, 0.68333, 0, 0, 0.72222],
  1848. "85": [0, 0.68333, 0, 0, 0.75],
  1849. "86": [0, 0.68333, 0.01389, 0, 0.75],
  1850. "87": [0, 0.68333, 0.01389, 0, 1.02778],
  1851. "88": [0, 0.68333, 0, 0, 0.75],
  1852. "89": [0, 0.68333, 0.025, 0, 0.75],
  1853. "90": [0, 0.68333, 0, 0, 0.61111],
  1854. "91": [0.25, 0.75, 0, 0, 0.27778],
  1855. "92": [0.25, 0.75, 0, 0, 0.5],
  1856. "93": [0.25, 0.75, 0, 0, 0.27778],
  1857. "94": [0, 0.69444, 0, 0, 0.5],
  1858. "95": [0.31, 0.12056, 0.02778, 0, 0.5],
  1859. "97": [0, 0.43056, 0, 0, 0.5],
  1860. "98": [0, 0.69444, 0, 0, 0.55556],
  1861. "99": [0, 0.43056, 0, 0, 0.44445],
  1862. "100": [0, 0.69444, 0, 0, 0.55556],
  1863. "101": [0, 0.43056, 0, 0, 0.44445],
  1864. "102": [0, 0.69444, 0.07778, 0, 0.30556],
  1865. "103": [0.19444, 0.43056, 0.01389, 0, 0.5],
  1866. "104": [0, 0.69444, 0, 0, 0.55556],
  1867. "105": [0, 0.66786, 0, 0, 0.27778],
  1868. "106": [0.19444, 0.66786, 0, 0, 0.30556],
  1869. "107": [0, 0.69444, 0, 0, 0.52778],
  1870. "108": [0, 0.69444, 0, 0, 0.27778],
  1871. "109": [0, 0.43056, 0, 0, 0.83334],
  1872. "110": [0, 0.43056, 0, 0, 0.55556],
  1873. "111": [0, 0.43056, 0, 0, 0.5],
  1874. "112": [0.19444, 0.43056, 0, 0, 0.55556],
  1875. "113": [0.19444, 0.43056, 0, 0, 0.52778],
  1876. "114": [0, 0.43056, 0, 0, 0.39167],
  1877. "115": [0, 0.43056, 0, 0, 0.39445],
  1878. "116": [0, 0.61508, 0, 0, 0.38889],
  1879. "117": [0, 0.43056, 0, 0, 0.55556],
  1880. "118": [0, 0.43056, 0.01389, 0, 0.52778],
  1881. "119": [0, 0.43056, 0.01389, 0, 0.72222],
  1882. "120": [0, 0.43056, 0, 0, 0.52778],
  1883. "121": [0.19444, 0.43056, 0.01389, 0, 0.52778],
  1884. "122": [0, 0.43056, 0, 0, 0.44445],
  1885. "123": [0.25, 0.75, 0, 0, 0.5],
  1886. "124": [0.25, 0.75, 0, 0, 0.27778],
  1887. "125": [0.25, 0.75, 0, 0, 0.5],
  1888. "126": [0.35, 0.31786, 0, 0, 0.5],
  1889. "160": [0, 0, 0, 0, 0.25],
  1890. "163": [0, 0.69444, 0, 0, 0.76909],
  1891. "167": [0.19444, 0.69444, 0, 0, 0.44445],
  1892. "168": [0, 0.66786, 0, 0, 0.5],
  1893. "172": [0, 0.43056, 0, 0, 0.66667],
  1894. "176": [0, 0.69444, 0, 0, 0.75],
  1895. "177": [0.08333, 0.58333, 0, 0, 0.77778],
  1896. "182": [0.19444, 0.69444, 0, 0, 0.61111],
  1897. "184": [0.17014, 0, 0, 0, 0.44445],
  1898. "198": [0, 0.68333, 0, 0, 0.90278],
  1899. "215": [0.08333, 0.58333, 0, 0, 0.77778],
  1900. "216": [0.04861, 0.73194, 0, 0, 0.77778],
  1901. "223": [0, 0.69444, 0, 0, 0.5],
  1902. "230": [0, 0.43056, 0, 0, 0.72222],
  1903. "247": [0.08333, 0.58333, 0, 0, 0.77778],
  1904. "248": [0.09722, 0.52778, 0, 0, 0.5],
  1905. "305": [0, 0.43056, 0, 0, 0.27778],
  1906. "338": [0, 0.68333, 0, 0, 1.01389],
  1907. "339": [0, 0.43056, 0, 0, 0.77778],
  1908. "567": [0.19444, 0.43056, 0, 0, 0.30556],
  1909. "710": [0, 0.69444, 0, 0, 0.5],
  1910. "711": [0, 0.62847, 0, 0, 0.5],
  1911. "713": [0, 0.56778, 0, 0, 0.5],
  1912. "714": [0, 0.69444, 0, 0, 0.5],
  1913. "715": [0, 0.69444, 0, 0, 0.5],
  1914. "728": [0, 0.69444, 0, 0, 0.5],
  1915. "729": [0, 0.66786, 0, 0, 0.27778],
  1916. "730": [0, 0.69444, 0, 0, 0.75],
  1917. "732": [0, 0.66786, 0, 0, 0.5],
  1918. "733": [0, 0.69444, 0, 0, 0.5],
  1919. "915": [0, 0.68333, 0, 0, 0.625],
  1920. "916": [0, 0.68333, 0, 0, 0.83334],
  1921. "920": [0, 0.68333, 0, 0, 0.77778],
  1922. "923": [0, 0.68333, 0, 0, 0.69445],
  1923. "926": [0, 0.68333, 0, 0, 0.66667],
  1924. "928": [0, 0.68333, 0, 0, 0.75],
  1925. "931": [0, 0.68333, 0, 0, 0.72222],
  1926. "933": [0, 0.68333, 0, 0, 0.77778],
  1927. "934": [0, 0.68333, 0, 0, 0.72222],
  1928. "936": [0, 0.68333, 0, 0, 0.77778],
  1929. "937": [0, 0.68333, 0, 0, 0.72222],
  1930. "8211": [0, 0.43056, 0.02778, 0, 0.5],
  1931. "8212": [0, 0.43056, 0.02778, 0, 1.0],
  1932. "8216": [0, 0.69444, 0, 0, 0.27778],
  1933. "8217": [0, 0.69444, 0, 0, 0.27778],
  1934. "8220": [0, 0.69444, 0, 0, 0.5],
  1935. "8221": [0, 0.69444, 0, 0, 0.5],
  1936. "8224": [0.19444, 0.69444, 0, 0, 0.44445],
  1937. "8225": [0.19444, 0.69444, 0, 0, 0.44445],
  1938. "8230": [0, 0.123, 0, 0, 1.172],
  1939. "8242": [0, 0.55556, 0, 0, 0.275],
  1940. "8407": [0, 0.71444, 0.15382, 0, 0.5],
  1941. "8463": [0, 0.68889, 0, 0, 0.54028],
  1942. "8465": [0, 0.69444, 0, 0, 0.72222],
  1943. "8467": [0, 0.69444, 0, 0.11111, 0.41667],
  1944. "8472": [0.19444, 0.43056, 0, 0.11111, 0.63646],
  1945. "8476": [0, 0.69444, 0, 0, 0.72222],
  1946. "8501": [0, 0.69444, 0, 0, 0.61111],
  1947. "8592": [-0.13313, 0.36687, 0, 0, 1.0],
  1948. "8593": [0.19444, 0.69444, 0, 0, 0.5],
  1949. "8594": [-0.13313, 0.36687, 0, 0, 1.0],
  1950. "8595": [0.19444, 0.69444, 0, 0, 0.5],
  1951. "8596": [-0.13313, 0.36687, 0, 0, 1.0],
  1952. "8597": [0.25, 0.75, 0, 0, 0.5],
  1953. "8598": [0.19444, 0.69444, 0, 0, 1.0],
  1954. "8599": [0.19444, 0.69444, 0, 0, 1.0],
  1955. "8600": [0.19444, 0.69444, 0, 0, 1.0],
  1956. "8601": [0.19444, 0.69444, 0, 0, 1.0],
  1957. "8614": [0.011, 0.511, 0, 0, 1.0],
  1958. "8617": [0.011, 0.511, 0, 0, 1.126],
  1959. "8618": [0.011, 0.511, 0, 0, 1.126],
  1960. "8636": [-0.13313, 0.36687, 0, 0, 1.0],
  1961. "8637": [-0.13313, 0.36687, 0, 0, 1.0],
  1962. "8640": [-0.13313, 0.36687, 0, 0, 1.0],
  1963. "8641": [-0.13313, 0.36687, 0, 0, 1.0],
  1964. "8652": [0.011, 0.671, 0, 0, 1.0],
  1965. "8656": [-0.13313, 0.36687, 0, 0, 1.0],
  1966. "8657": [0.19444, 0.69444, 0, 0, 0.61111],
  1967. "8658": [-0.13313, 0.36687, 0, 0, 1.0],
  1968. "8659": [0.19444, 0.69444, 0, 0, 0.61111],
  1969. "8660": [-0.13313, 0.36687, 0, 0, 1.0],
  1970. "8661": [0.25, 0.75, 0, 0, 0.61111],
  1971. "8704": [0, 0.69444, 0, 0, 0.55556],
  1972. "8706": [0, 0.69444, 0.05556, 0.08334, 0.5309],
  1973. "8707": [0, 0.69444, 0, 0, 0.55556],
  1974. "8709": [0.05556, 0.75, 0, 0, 0.5],
  1975. "8711": [0, 0.68333, 0, 0, 0.83334],
  1976. "8712": [0.0391, 0.5391, 0, 0, 0.66667],
  1977. "8715": [0.0391, 0.5391, 0, 0, 0.66667],
  1978. "8722": [0.08333, 0.58333, 0, 0, 0.77778],
  1979. "8723": [0.08333, 0.58333, 0, 0, 0.77778],
  1980. "8725": [0.25, 0.75, 0, 0, 0.5],
  1981. "8726": [0.25, 0.75, 0, 0, 0.5],
  1982. "8727": [-0.03472, 0.46528, 0, 0, 0.5],
  1983. "8728": [-0.05555, 0.44445, 0, 0, 0.5],
  1984. "8729": [-0.05555, 0.44445, 0, 0, 0.5],
  1985. "8730": [0.2, 0.8, 0, 0, 0.83334],
  1986. "8733": [0, 0.43056, 0, 0, 0.77778],
  1987. "8734": [0, 0.43056, 0, 0, 1.0],
  1988. "8736": [0, 0.69224, 0, 0, 0.72222],
  1989. "8739": [0.25, 0.75, 0, 0, 0.27778],
  1990. "8741": [0.25, 0.75, 0, 0, 0.5],
  1991. "8743": [0, 0.55556, 0, 0, 0.66667],
  1992. "8744": [0, 0.55556, 0, 0, 0.66667],
  1993. "8745": [0, 0.55556, 0, 0, 0.66667],
  1994. "8746": [0, 0.55556, 0, 0, 0.66667],
  1995. "8747": [0.19444, 0.69444, 0.11111, 0, 0.41667],
  1996. "8764": [-0.13313, 0.36687, 0, 0, 0.77778],
  1997. "8768": [0.19444, 0.69444, 0, 0, 0.27778],
  1998. "8771": [-0.03625, 0.46375, 0, 0, 0.77778],
  1999. "8773": [-0.022, 0.589, 0, 0, 0.778],
  2000. "8776": [-0.01688, 0.48312, 0, 0, 0.77778],
  2001. "8781": [-0.03625, 0.46375, 0, 0, 0.77778],
  2002. "8784": [-0.133, 0.673, 0, 0, 0.778],
  2003. "8801": [-0.03625, 0.46375, 0, 0, 0.77778],
  2004. "8804": [0.13597, 0.63597, 0, 0, 0.77778],
  2005. "8805": [0.13597, 0.63597, 0, 0, 0.77778],
  2006. "8810": [0.0391, 0.5391, 0, 0, 1.0],
  2007. "8811": [0.0391, 0.5391, 0, 0, 1.0],
  2008. "8826": [0.0391, 0.5391, 0, 0, 0.77778],
  2009. "8827": [0.0391, 0.5391, 0, 0, 0.77778],
  2010. "8834": [0.0391, 0.5391, 0, 0, 0.77778],
  2011. "8835": [0.0391, 0.5391, 0, 0, 0.77778],
  2012. "8838": [0.13597, 0.63597, 0, 0, 0.77778],
  2013. "8839": [0.13597, 0.63597, 0, 0, 0.77778],
  2014. "8846": [0, 0.55556, 0, 0, 0.66667],
  2015. "8849": [0.13597, 0.63597, 0, 0, 0.77778],
  2016. "8850": [0.13597, 0.63597, 0, 0, 0.77778],
  2017. "8851": [0, 0.55556, 0, 0, 0.66667],
  2018. "8852": [0, 0.55556, 0, 0, 0.66667],
  2019. "8853": [0.08333, 0.58333, 0, 0, 0.77778],
  2020. "8854": [0.08333, 0.58333, 0, 0, 0.77778],
  2021. "8855": [0.08333, 0.58333, 0, 0, 0.77778],
  2022. "8856": [0.08333, 0.58333, 0, 0, 0.77778],
  2023. "8857": [0.08333, 0.58333, 0, 0, 0.77778],
  2024. "8866": [0, 0.69444, 0, 0, 0.61111],
  2025. "8867": [0, 0.69444, 0, 0, 0.61111],
  2026. "8868": [0, 0.69444, 0, 0, 0.77778],
  2027. "8869": [0, 0.69444, 0, 0, 0.77778],
  2028. "8872": [0.249, 0.75, 0, 0, 0.867],
  2029. "8900": [-0.05555, 0.44445, 0, 0, 0.5],
  2030. "8901": [-0.05555, 0.44445, 0, 0, 0.27778],
  2031. "8902": [-0.03472, 0.46528, 0, 0, 0.5],
  2032. "8904": [0.005, 0.505, 0, 0, 0.9],
  2033. "8942": [0.03, 0.903, 0, 0, 0.278],
  2034. "8943": [-0.19, 0.313, 0, 0, 1.172],
  2035. "8945": [-0.1, 0.823, 0, 0, 1.282],
  2036. "8968": [0.25, 0.75, 0, 0, 0.44445],
  2037. "8969": [0.25, 0.75, 0, 0, 0.44445],
  2038. "8970": [0.25, 0.75, 0, 0, 0.44445],
  2039. "8971": [0.25, 0.75, 0, 0, 0.44445],
  2040. "8994": [-0.14236, 0.35764, 0, 0, 1.0],
  2041. "8995": [-0.14236, 0.35764, 0, 0, 1.0],
  2042. "9136": [0.244, 0.744, 0, 0, 0.412],
  2043. "9137": [0.244, 0.745, 0, 0, 0.412],
  2044. "9651": [0.19444, 0.69444, 0, 0, 0.88889],
  2045. "9657": [-0.03472, 0.46528, 0, 0, 0.5],
  2046. "9661": [0.19444, 0.69444, 0, 0, 0.88889],
  2047. "9667": [-0.03472, 0.46528, 0, 0, 0.5],
  2048. "9711": [0.19444, 0.69444, 0, 0, 1.0],
  2049. "9824": [0.12963, 0.69444, 0, 0, 0.77778],
  2050. "9825": [0.12963, 0.69444, 0, 0, 0.77778],
  2051. "9826": [0.12963, 0.69444, 0, 0, 0.77778],
  2052. "9827": [0.12963, 0.69444, 0, 0, 0.77778],
  2053. "9837": [0, 0.75, 0, 0, 0.38889],
  2054. "9838": [0.19444, 0.69444, 0, 0, 0.38889],
  2055. "9839": [0.19444, 0.69444, 0, 0, 0.38889],
  2056. "10216": [0.25, 0.75, 0, 0, 0.38889],
  2057. "10217": [0.25, 0.75, 0, 0, 0.38889],
  2058. "10222": [0.244, 0.744, 0, 0, 0.412],
  2059. "10223": [0.244, 0.745, 0, 0, 0.412],
  2060. "10229": [0.011, 0.511, 0, 0, 1.609],
  2061. "10230": [0.011, 0.511, 0, 0, 1.638],
  2062. "10231": [0.011, 0.511, 0, 0, 1.859],
  2063. "10232": [0.024, 0.525, 0, 0, 1.609],
  2064. "10233": [0.024, 0.525, 0, 0, 1.638],
  2065. "10234": [0.024, 0.525, 0, 0, 1.858],
  2066. "10236": [0.011, 0.511, 0, 0, 1.638],
  2067. "10815": [0, 0.68333, 0, 0, 0.75],
  2068. "10927": [0.13597, 0.63597, 0, 0, 0.77778],
  2069. "10928": [0.13597, 0.63597, 0, 0, 0.77778],
  2070. "57376": [0.19444, 0.69444, 0, 0, 0]
  2071. },
  2072. "Math-BoldItalic": {
  2073. "32": [0, 0, 0, 0, 0.25],
  2074. "48": [0, 0.44444, 0, 0, 0.575],
  2075. "49": [0, 0.44444, 0, 0, 0.575],
  2076. "50": [0, 0.44444, 0, 0, 0.575],
  2077. "51": [0.19444, 0.44444, 0, 0, 0.575],
  2078. "52": [0.19444, 0.44444, 0, 0, 0.575],
  2079. "53": [0.19444, 0.44444, 0, 0, 0.575],
  2080. "54": [0, 0.64444, 0, 0, 0.575],
  2081. "55": [0.19444, 0.44444, 0, 0, 0.575],
  2082. "56": [0, 0.64444, 0, 0, 0.575],
  2083. "57": [0.19444, 0.44444, 0, 0, 0.575],
  2084. "65": [0, 0.68611, 0, 0, 0.86944],
  2085. "66": [0, 0.68611, 0.04835, 0, 0.8664],
  2086. "67": [0, 0.68611, 0.06979, 0, 0.81694],
  2087. "68": [0, 0.68611, 0.03194, 0, 0.93812],
  2088. "69": [0, 0.68611, 0.05451, 0, 0.81007],
  2089. "70": [0, 0.68611, 0.15972, 0, 0.68889],
  2090. "71": [0, 0.68611, 0, 0, 0.88673],
  2091. "72": [0, 0.68611, 0.08229, 0, 0.98229],
  2092. "73": [0, 0.68611, 0.07778, 0, 0.51111],
  2093. "74": [0, 0.68611, 0.10069, 0, 0.63125],
  2094. "75": [0, 0.68611, 0.06979, 0, 0.97118],
  2095. "76": [0, 0.68611, 0, 0, 0.75555],
  2096. "77": [0, 0.68611, 0.11424, 0, 1.14201],
  2097. "78": [0, 0.68611, 0.11424, 0, 0.95034],
  2098. "79": [0, 0.68611, 0.03194, 0, 0.83666],
  2099. "80": [0, 0.68611, 0.15972, 0, 0.72309],
  2100. "81": [0.19444, 0.68611, 0, 0, 0.86861],
  2101. "82": [0, 0.68611, 0.00421, 0, 0.87235],
  2102. "83": [0, 0.68611, 0.05382, 0, 0.69271],
  2103. "84": [0, 0.68611, 0.15972, 0, 0.63663],
  2104. "85": [0, 0.68611, 0.11424, 0, 0.80027],
  2105. "86": [0, 0.68611, 0.25555, 0, 0.67778],
  2106. "87": [0, 0.68611, 0.15972, 0, 1.09305],
  2107. "88": [0, 0.68611, 0.07778, 0, 0.94722],
  2108. "89": [0, 0.68611, 0.25555, 0, 0.67458],
  2109. "90": [0, 0.68611, 0.06979, 0, 0.77257],
  2110. "97": [0, 0.44444, 0, 0, 0.63287],
  2111. "98": [0, 0.69444, 0, 0, 0.52083],
  2112. "99": [0, 0.44444, 0, 0, 0.51342],
  2113. "100": [0, 0.69444, 0, 0, 0.60972],
  2114. "101": [0, 0.44444, 0, 0, 0.55361],
  2115. "102": [0.19444, 0.69444, 0.11042, 0, 0.56806],
  2116. "103": [0.19444, 0.44444, 0.03704, 0, 0.5449],
  2117. "104": [0, 0.69444, 0, 0, 0.66759],
  2118. "105": [0, 0.69326, 0, 0, 0.4048],
  2119. "106": [0.19444, 0.69326, 0.0622, 0, 0.47083],
  2120. "107": [0, 0.69444, 0.01852, 0, 0.6037],
  2121. "108": [0, 0.69444, 0.0088, 0, 0.34815],
  2122. "109": [0, 0.44444, 0, 0, 1.0324],
  2123. "110": [0, 0.44444, 0, 0, 0.71296],
  2124. "111": [0, 0.44444, 0, 0, 0.58472],
  2125. "112": [0.19444, 0.44444, 0, 0, 0.60092],
  2126. "113": [0.19444, 0.44444, 0.03704, 0, 0.54213],
  2127. "114": [0, 0.44444, 0.03194, 0, 0.5287],
  2128. "115": [0, 0.44444, 0, 0, 0.53125],
  2129. "116": [0, 0.63492, 0, 0, 0.41528],
  2130. "117": [0, 0.44444, 0, 0, 0.68102],
  2131. "118": [0, 0.44444, 0.03704, 0, 0.56666],
  2132. "119": [0, 0.44444, 0.02778, 0, 0.83148],
  2133. "120": [0, 0.44444, 0, 0, 0.65903],
  2134. "121": [0.19444, 0.44444, 0.03704, 0, 0.59028],
  2135. "122": [0, 0.44444, 0.04213, 0, 0.55509],
  2136. "160": [0, 0, 0, 0, 0.25],
  2137. "915": [0, 0.68611, 0.15972, 0, 0.65694],
  2138. "916": [0, 0.68611, 0, 0, 0.95833],
  2139. "920": [0, 0.68611, 0.03194, 0, 0.86722],
  2140. "923": [0, 0.68611, 0, 0, 0.80555],
  2141. "926": [0, 0.68611, 0.07458, 0, 0.84125],
  2142. "928": [0, 0.68611, 0.08229, 0, 0.98229],
  2143. "931": [0, 0.68611, 0.05451, 0, 0.88507],
  2144. "933": [0, 0.68611, 0.15972, 0, 0.67083],
  2145. "934": [0, 0.68611, 0, 0, 0.76666],
  2146. "936": [0, 0.68611, 0.11653, 0, 0.71402],
  2147. "937": [0, 0.68611, 0.04835, 0, 0.8789],
  2148. "945": [0, 0.44444, 0, 0, 0.76064],
  2149. "946": [0.19444, 0.69444, 0.03403, 0, 0.65972],
  2150. "947": [0.19444, 0.44444, 0.06389, 0, 0.59003],
  2151. "948": [0, 0.69444, 0.03819, 0, 0.52222],
  2152. "949": [0, 0.44444, 0, 0, 0.52882],
  2153. "950": [0.19444, 0.69444, 0.06215, 0, 0.50833],
  2154. "951": [0.19444, 0.44444, 0.03704, 0, 0.6],
  2155. "952": [0, 0.69444, 0.03194, 0, 0.5618],
  2156. "953": [0, 0.44444, 0, 0, 0.41204],
  2157. "954": [0, 0.44444, 0, 0, 0.66759],
  2158. "955": [0, 0.69444, 0, 0, 0.67083],
  2159. "956": [0.19444, 0.44444, 0, 0, 0.70787],
  2160. "957": [0, 0.44444, 0.06898, 0, 0.57685],
  2161. "958": [0.19444, 0.69444, 0.03021, 0, 0.50833],
  2162. "959": [0, 0.44444, 0, 0, 0.58472],
  2163. "960": [0, 0.44444, 0.03704, 0, 0.68241],
  2164. "961": [0.19444, 0.44444, 0, 0, 0.6118],
  2165. "962": [0.09722, 0.44444, 0.07917, 0, 0.42361],
  2166. "963": [0, 0.44444, 0.03704, 0, 0.68588],
  2167. "964": [0, 0.44444, 0.13472, 0, 0.52083],
  2168. "965": [0, 0.44444, 0.03704, 0, 0.63055],
  2169. "966": [0.19444, 0.44444, 0, 0, 0.74722],
  2170. "967": [0.19444, 0.44444, 0, 0, 0.71805],
  2171. "968": [0.19444, 0.69444, 0.03704, 0, 0.75833],
  2172. "969": [0, 0.44444, 0.03704, 0, 0.71782],
  2173. "977": [0, 0.69444, 0, 0, 0.69155],
  2174. "981": [0.19444, 0.69444, 0, 0, 0.7125],
  2175. "982": [0, 0.44444, 0.03194, 0, 0.975],
  2176. "1009": [0.19444, 0.44444, 0, 0, 0.6118],
  2177. "1013": [0, 0.44444, 0, 0, 0.48333],
  2178. "57649": [0, 0.44444, 0, 0, 0.39352],
  2179. "57911": [0.19444, 0.44444, 0, 0, 0.43889]
  2180. },
  2181. "Math-Italic": {
  2182. "32": [0, 0, 0, 0, 0.25],
  2183. "48": [0, 0.43056, 0, 0, 0.5],
  2184. "49": [0, 0.43056, 0, 0, 0.5],
  2185. "50": [0, 0.43056, 0, 0, 0.5],
  2186. "51": [0.19444, 0.43056, 0, 0, 0.5],
  2187. "52": [0.19444, 0.43056, 0, 0, 0.5],
  2188. "53": [0.19444, 0.43056, 0, 0, 0.5],
  2189. "54": [0, 0.64444, 0, 0, 0.5],
  2190. "55": [0.19444, 0.43056, 0, 0, 0.5],
  2191. "56": [0, 0.64444, 0, 0, 0.5],
  2192. "57": [0.19444, 0.43056, 0, 0, 0.5],
  2193. "65": [0, 0.68333, 0, 0.13889, 0.75],
  2194. "66": [0, 0.68333, 0.05017, 0.08334, 0.75851],
  2195. "67": [0, 0.68333, 0.07153, 0.08334, 0.71472],
  2196. "68": [0, 0.68333, 0.02778, 0.05556, 0.82792],
  2197. "69": [0, 0.68333, 0.05764, 0.08334, 0.7382],
  2198. "70": [0, 0.68333, 0.13889, 0.08334, 0.64306],
  2199. "71": [0, 0.68333, 0, 0.08334, 0.78625],
  2200. "72": [0, 0.68333, 0.08125, 0.05556, 0.83125],
  2201. "73": [0, 0.68333, 0.07847, 0.11111, 0.43958],
  2202. "74": [0, 0.68333, 0.09618, 0.16667, 0.55451],
  2203. "75": [0, 0.68333, 0.07153, 0.05556, 0.84931],
  2204. "76": [0, 0.68333, 0, 0.02778, 0.68056],
  2205. "77": [0, 0.68333, 0.10903, 0.08334, 0.97014],
  2206. "78": [0, 0.68333, 0.10903, 0.08334, 0.80347],
  2207. "79": [0, 0.68333, 0.02778, 0.08334, 0.76278],
  2208. "80": [0, 0.68333, 0.13889, 0.08334, 0.64201],
  2209. "81": [0.19444, 0.68333, 0, 0.08334, 0.79056],
  2210. "82": [0, 0.68333, 0.00773, 0.08334, 0.75929],
  2211. "83": [0, 0.68333, 0.05764, 0.08334, 0.6132],
  2212. "84": [0, 0.68333, 0.13889, 0.08334, 0.58438],
  2213. "85": [0, 0.68333, 0.10903, 0.02778, 0.68278],
  2214. "86": [0, 0.68333, 0.22222, 0, 0.58333],
  2215. "87": [0, 0.68333, 0.13889, 0, 0.94445],
  2216. "88": [0, 0.68333, 0.07847, 0.08334, 0.82847],
  2217. "89": [0, 0.68333, 0.22222, 0, 0.58056],
  2218. "90": [0, 0.68333, 0.07153, 0.08334, 0.68264],
  2219. "97": [0, 0.43056, 0, 0, 0.52859],
  2220. "98": [0, 0.69444, 0, 0, 0.42917],
  2221. "99": [0, 0.43056, 0, 0.05556, 0.43276],
  2222. "100": [0, 0.69444, 0, 0.16667, 0.52049],
  2223. "101": [0, 0.43056, 0, 0.05556, 0.46563],
  2224. "102": [0.19444, 0.69444, 0.10764, 0.16667, 0.48959],
  2225. "103": [0.19444, 0.43056, 0.03588, 0.02778, 0.47697],
  2226. "104": [0, 0.69444, 0, 0, 0.57616],
  2227. "105": [0, 0.65952, 0, 0, 0.34451],
  2228. "106": [0.19444, 0.65952, 0.05724, 0, 0.41181],
  2229. "107": [0, 0.69444, 0.03148, 0, 0.5206],
  2230. "108": [0, 0.69444, 0.01968, 0.08334, 0.29838],
  2231. "109": [0, 0.43056, 0, 0, 0.87801],
  2232. "110": [0, 0.43056, 0, 0, 0.60023],
  2233. "111": [0, 0.43056, 0, 0.05556, 0.48472],
  2234. "112": [0.19444, 0.43056, 0, 0.08334, 0.50313],
  2235. "113": [0.19444, 0.43056, 0.03588, 0.08334, 0.44641],
  2236. "114": [0, 0.43056, 0.02778, 0.05556, 0.45116],
  2237. "115": [0, 0.43056, 0, 0.05556, 0.46875],
  2238. "116": [0, 0.61508, 0, 0.08334, 0.36111],
  2239. "117": [0, 0.43056, 0, 0.02778, 0.57246],
  2240. "118": [0, 0.43056, 0.03588, 0.02778, 0.48472],
  2241. "119": [0, 0.43056, 0.02691, 0.08334, 0.71592],
  2242. "120": [0, 0.43056, 0, 0.02778, 0.57153],
  2243. "121": [0.19444, 0.43056, 0.03588, 0.05556, 0.49028],
  2244. "122": [0, 0.43056, 0.04398, 0.05556, 0.46505],
  2245. "160": [0, 0, 0, 0, 0.25],
  2246. "915": [0, 0.68333, 0.13889, 0.08334, 0.61528],
  2247. "916": [0, 0.68333, 0, 0.16667, 0.83334],
  2248. "920": [0, 0.68333, 0.02778, 0.08334, 0.76278],
  2249. "923": [0, 0.68333, 0, 0.16667, 0.69445],
  2250. "926": [0, 0.68333, 0.07569, 0.08334, 0.74236],
  2251. "928": [0, 0.68333, 0.08125, 0.05556, 0.83125],
  2252. "931": [0, 0.68333, 0.05764, 0.08334, 0.77986],
  2253. "933": [0, 0.68333, 0.13889, 0.05556, 0.58333],
  2254. "934": [0, 0.68333, 0, 0.08334, 0.66667],
  2255. "936": [0, 0.68333, 0.11, 0.05556, 0.61222],
  2256. "937": [0, 0.68333, 0.05017, 0.08334, 0.7724],
  2257. "945": [0, 0.43056, 0.0037, 0.02778, 0.6397],
  2258. "946": [0.19444, 0.69444, 0.05278, 0.08334, 0.56563],
  2259. "947": [0.19444, 0.43056, 0.05556, 0, 0.51773],
  2260. "948": [0, 0.69444, 0.03785, 0.05556, 0.44444],
  2261. "949": [0, 0.43056, 0, 0.08334, 0.46632],
  2262. "950": [0.19444, 0.69444, 0.07378, 0.08334, 0.4375],
  2263. "951": [0.19444, 0.43056, 0.03588, 0.05556, 0.49653],
  2264. "952": [0, 0.69444, 0.02778, 0.08334, 0.46944],
  2265. "953": [0, 0.43056, 0, 0.05556, 0.35394],
  2266. "954": [0, 0.43056, 0, 0, 0.57616],
  2267. "955": [0, 0.69444, 0, 0, 0.58334],
  2268. "956": [0.19444, 0.43056, 0, 0.02778, 0.60255],
  2269. "957": [0, 0.43056, 0.06366, 0.02778, 0.49398],
  2270. "958": [0.19444, 0.69444, 0.04601, 0.11111, 0.4375],
  2271. "959": [0, 0.43056, 0, 0.05556, 0.48472],
  2272. "960": [0, 0.43056, 0.03588, 0, 0.57003],
  2273. "961": [0.19444, 0.43056, 0, 0.08334, 0.51702],
  2274. "962": [0.09722, 0.43056, 0.07986, 0.08334, 0.36285],
  2275. "963": [0, 0.43056, 0.03588, 0, 0.57141],
  2276. "964": [0, 0.43056, 0.1132, 0.02778, 0.43715],
  2277. "965": [0, 0.43056, 0.03588, 0.02778, 0.54028],
  2278. "966": [0.19444, 0.43056, 0, 0.08334, 0.65417],
  2279. "967": [0.19444, 0.43056, 0, 0.05556, 0.62569],
  2280. "968": [0.19444, 0.69444, 0.03588, 0.11111, 0.65139],
  2281. "969": [0, 0.43056, 0.03588, 0, 0.62245],
  2282. "977": [0, 0.69444, 0, 0.08334, 0.59144],
  2283. "981": [0.19444, 0.69444, 0, 0.08334, 0.59583],
  2284. "982": [0, 0.43056, 0.02778, 0, 0.82813],
  2285. "1009": [0.19444, 0.43056, 0, 0.08334, 0.51702],
  2286. "1013": [0, 0.43056, 0, 0.05556, 0.4059],
  2287. "57649": [0, 0.43056, 0, 0.02778, 0.32246],
  2288. "57911": [0.19444, 0.43056, 0, 0.08334, 0.38403]
  2289. },
  2290. "SansSerif-Bold": {
  2291. "32": [0, 0, 0, 0, 0.25],
  2292. "33": [0, 0.69444, 0, 0, 0.36667],
  2293. "34": [0, 0.69444, 0, 0, 0.55834],
  2294. "35": [0.19444, 0.69444, 0, 0, 0.91667],
  2295. "36": [0.05556, 0.75, 0, 0, 0.55],
  2296. "37": [0.05556, 0.75, 0, 0, 1.02912],
  2297. "38": [0, 0.69444, 0, 0, 0.83056],
  2298. "39": [0, 0.69444, 0, 0, 0.30556],
  2299. "40": [0.25, 0.75, 0, 0, 0.42778],
  2300. "41": [0.25, 0.75, 0, 0, 0.42778],
  2301. "42": [0, 0.75, 0, 0, 0.55],
  2302. "43": [0.11667, 0.61667, 0, 0, 0.85556],
  2303. "44": [0.10556, 0.13056, 0, 0, 0.30556],
  2304. "45": [0, 0.45833, 0, 0, 0.36667],
  2305. "46": [0, 0.13056, 0, 0, 0.30556],
  2306. "47": [0.25, 0.75, 0, 0, 0.55],
  2307. "48": [0, 0.69444, 0, 0, 0.55],
  2308. "49": [0, 0.69444, 0, 0, 0.55],
  2309. "50": [0, 0.69444, 0, 0, 0.55],
  2310. "51": [0, 0.69444, 0, 0, 0.55],
  2311. "52": [0, 0.69444, 0, 0, 0.55],
  2312. "53": [0, 0.69444, 0, 0, 0.55],
  2313. "54": [0, 0.69444, 0, 0, 0.55],
  2314. "55": [0, 0.69444, 0, 0, 0.55],
  2315. "56": [0, 0.69444, 0, 0, 0.55],
  2316. "57": [0, 0.69444, 0, 0, 0.55],
  2317. "58": [0, 0.45833, 0, 0, 0.30556],
  2318. "59": [0.10556, 0.45833, 0, 0, 0.30556],
  2319. "61": [-0.09375, 0.40625, 0, 0, 0.85556],
  2320. "63": [0, 0.69444, 0, 0, 0.51945],
  2321. "64": [0, 0.69444, 0, 0, 0.73334],
  2322. "65": [0, 0.69444, 0, 0, 0.73334],
  2323. "66": [0, 0.69444, 0, 0, 0.73334],
  2324. "67": [0, 0.69444, 0, 0, 0.70278],
  2325. "68": [0, 0.69444, 0, 0, 0.79445],
  2326. "69": [0, 0.69444, 0, 0, 0.64167],
  2327. "70": [0, 0.69444, 0, 0, 0.61111],
  2328. "71": [0, 0.69444, 0, 0, 0.73334],
  2329. "72": [0, 0.69444, 0, 0, 0.79445],
  2330. "73": [0, 0.69444, 0, 0, 0.33056],
  2331. "74": [0, 0.69444, 0, 0, 0.51945],
  2332. "75": [0, 0.69444, 0, 0, 0.76389],
  2333. "76": [0, 0.69444, 0, 0, 0.58056],
  2334. "77": [0, 0.69444, 0, 0, 0.97778],
  2335. "78": [0, 0.69444, 0, 0, 0.79445],
  2336. "79": [0, 0.69444, 0, 0, 0.79445],
  2337. "80": [0, 0.69444, 0, 0, 0.70278],
  2338. "81": [0.10556, 0.69444, 0, 0, 0.79445],
  2339. "82": [0, 0.69444, 0, 0, 0.70278],
  2340. "83": [0, 0.69444, 0, 0, 0.61111],
  2341. "84": [0, 0.69444, 0, 0, 0.73334],
  2342. "85": [0, 0.69444, 0, 0, 0.76389],
  2343. "86": [0, 0.69444, 0.01528, 0, 0.73334],
  2344. "87": [0, 0.69444, 0.01528, 0, 1.03889],
  2345. "88": [0, 0.69444, 0, 0, 0.73334],
  2346. "89": [0, 0.69444, 0.0275, 0, 0.73334],
  2347. "90": [0, 0.69444, 0, 0, 0.67223],
  2348. "91": [0.25, 0.75, 0, 0, 0.34306],
  2349. "93": [0.25, 0.75, 0, 0, 0.34306],
  2350. "94": [0, 0.69444, 0, 0, 0.55],
  2351. "95": [0.35, 0.10833, 0.03056, 0, 0.55],
  2352. "97": [0, 0.45833, 0, 0, 0.525],
  2353. "98": [0, 0.69444, 0, 0, 0.56111],
  2354. "99": [0, 0.45833, 0, 0, 0.48889],
  2355. "100": [0, 0.69444, 0, 0, 0.56111],
  2356. "101": [0, 0.45833, 0, 0, 0.51111],
  2357. "102": [0, 0.69444, 0.07639, 0, 0.33611],
  2358. "103": [0.19444, 0.45833, 0.01528, 0, 0.55],
  2359. "104": [0, 0.69444, 0, 0, 0.56111],
  2360. "105": [0, 0.69444, 0, 0, 0.25556],
  2361. "106": [0.19444, 0.69444, 0, 0, 0.28611],
  2362. "107": [0, 0.69444, 0, 0, 0.53056],
  2363. "108": [0, 0.69444, 0, 0, 0.25556],
  2364. "109": [0, 0.45833, 0, 0, 0.86667],
  2365. "110": [0, 0.45833, 0, 0, 0.56111],
  2366. "111": [0, 0.45833, 0, 0, 0.55],
  2367. "112": [0.19444, 0.45833, 0, 0, 0.56111],
  2368. "113": [0.19444, 0.45833, 0, 0, 0.56111],
  2369. "114": [0, 0.45833, 0.01528, 0, 0.37222],
  2370. "115": [0, 0.45833, 0, 0, 0.42167],
  2371. "116": [0, 0.58929, 0, 0, 0.40417],
  2372. "117": [0, 0.45833, 0, 0, 0.56111],
  2373. "118": [0, 0.45833, 0.01528, 0, 0.5],
  2374. "119": [0, 0.45833, 0.01528, 0, 0.74445],
  2375. "120": [0, 0.45833, 0, 0, 0.5],
  2376. "121": [0.19444, 0.45833, 0.01528, 0, 0.5],
  2377. "122": [0, 0.45833, 0, 0, 0.47639],
  2378. "126": [0.35, 0.34444, 0, 0, 0.55],
  2379. "160": [0, 0, 0, 0, 0.25],
  2380. "168": [0, 0.69444, 0, 0, 0.55],
  2381. "176": [0, 0.69444, 0, 0, 0.73334],
  2382. "180": [0, 0.69444, 0, 0, 0.55],
  2383. "184": [0.17014, 0, 0, 0, 0.48889],
  2384. "305": [0, 0.45833, 0, 0, 0.25556],
  2385. "567": [0.19444, 0.45833, 0, 0, 0.28611],
  2386. "710": [0, 0.69444, 0, 0, 0.55],
  2387. "711": [0, 0.63542, 0, 0, 0.55],
  2388. "713": [0, 0.63778, 0, 0, 0.55],
  2389. "728": [0, 0.69444, 0, 0, 0.55],
  2390. "729": [0, 0.69444, 0, 0, 0.30556],
  2391. "730": [0, 0.69444, 0, 0, 0.73334],
  2392. "732": [0, 0.69444, 0, 0, 0.55],
  2393. "733": [0, 0.69444, 0, 0, 0.55],
  2394. "915": [0, 0.69444, 0, 0, 0.58056],
  2395. "916": [0, 0.69444, 0, 0, 0.91667],
  2396. "920": [0, 0.69444, 0, 0, 0.85556],
  2397. "923": [0, 0.69444, 0, 0, 0.67223],
  2398. "926": [0, 0.69444, 0, 0, 0.73334],
  2399. "928": [0, 0.69444, 0, 0, 0.79445],
  2400. "931": [0, 0.69444, 0, 0, 0.79445],
  2401. "933": [0, 0.69444, 0, 0, 0.85556],
  2402. "934": [0, 0.69444, 0, 0, 0.79445],
  2403. "936": [0, 0.69444, 0, 0, 0.85556],
  2404. "937": [0, 0.69444, 0, 0, 0.79445],
  2405. "8211": [0, 0.45833, 0.03056, 0, 0.55],
  2406. "8212": [0, 0.45833, 0.03056, 0, 1.10001],
  2407. "8216": [0, 0.69444, 0, 0, 0.30556],
  2408. "8217": [0, 0.69444, 0, 0, 0.30556],
  2409. "8220": [0, 0.69444, 0, 0, 0.55834],
  2410. "8221": [0, 0.69444, 0, 0, 0.55834]
  2411. },
  2412. "SansSerif-Italic": {
  2413. "32": [0, 0, 0, 0, 0.25],
  2414. "33": [0, 0.69444, 0.05733, 0, 0.31945],
  2415. "34": [0, 0.69444, 0.00316, 0, 0.5],
  2416. "35": [0.19444, 0.69444, 0.05087, 0, 0.83334],
  2417. "36": [0.05556, 0.75, 0.11156, 0, 0.5],
  2418. "37": [0.05556, 0.75, 0.03126, 0, 0.83334],
  2419. "38": [0, 0.69444, 0.03058, 0, 0.75834],
  2420. "39": [0, 0.69444, 0.07816, 0, 0.27778],
  2421. "40": [0.25, 0.75, 0.13164, 0, 0.38889],
  2422. "41": [0.25, 0.75, 0.02536, 0, 0.38889],
  2423. "42": [0, 0.75, 0.11775, 0, 0.5],
  2424. "43": [0.08333, 0.58333, 0.02536, 0, 0.77778],
  2425. "44": [0.125, 0.08333, 0, 0, 0.27778],
  2426. "45": [0, 0.44444, 0.01946, 0, 0.33333],
  2427. "46": [0, 0.08333, 0, 0, 0.27778],
  2428. "47": [0.25, 0.75, 0.13164, 0, 0.5],
  2429. "48": [0, 0.65556, 0.11156, 0, 0.5],
  2430. "49": [0, 0.65556, 0.11156, 0, 0.5],
  2431. "50": [0, 0.65556, 0.11156, 0, 0.5],
  2432. "51": [0, 0.65556, 0.11156, 0, 0.5],
  2433. "52": [0, 0.65556, 0.11156, 0, 0.5],
  2434. "53": [0, 0.65556, 0.11156, 0, 0.5],
  2435. "54": [0, 0.65556, 0.11156, 0, 0.5],
  2436. "55": [0, 0.65556, 0.11156, 0, 0.5],
  2437. "56": [0, 0.65556, 0.11156, 0, 0.5],
  2438. "57": [0, 0.65556, 0.11156, 0, 0.5],
  2439. "58": [0, 0.44444, 0.02502, 0, 0.27778],
  2440. "59": [0.125, 0.44444, 0.02502, 0, 0.27778],
  2441. "61": [-0.13, 0.37, 0.05087, 0, 0.77778],
  2442. "63": [0, 0.69444, 0.11809, 0, 0.47222],
  2443. "64": [0, 0.69444, 0.07555, 0, 0.66667],
  2444. "65": [0, 0.69444, 0, 0, 0.66667],
  2445. "66": [0, 0.69444, 0.08293, 0, 0.66667],
  2446. "67": [0, 0.69444, 0.11983, 0, 0.63889],
  2447. "68": [0, 0.69444, 0.07555, 0, 0.72223],
  2448. "69": [0, 0.69444, 0.11983, 0, 0.59722],
  2449. "70": [0, 0.69444, 0.13372, 0, 0.56945],
  2450. "71": [0, 0.69444, 0.11983, 0, 0.66667],
  2451. "72": [0, 0.69444, 0.08094, 0, 0.70834],
  2452. "73": [0, 0.69444, 0.13372, 0, 0.27778],
  2453. "74": [0, 0.69444, 0.08094, 0, 0.47222],
  2454. "75": [0, 0.69444, 0.11983, 0, 0.69445],
  2455. "76": [0, 0.69444, 0, 0, 0.54167],
  2456. "77": [0, 0.69444, 0.08094, 0, 0.875],
  2457. "78": [0, 0.69444, 0.08094, 0, 0.70834],
  2458. "79": [0, 0.69444, 0.07555, 0, 0.73611],
  2459. "80": [0, 0.69444, 0.08293, 0, 0.63889],
  2460. "81": [0.125, 0.69444, 0.07555, 0, 0.73611],
  2461. "82": [0, 0.69444, 0.08293, 0, 0.64584],
  2462. "83": [0, 0.69444, 0.09205, 0, 0.55556],
  2463. "84": [0, 0.69444, 0.13372, 0, 0.68056],
  2464. "85": [0, 0.69444, 0.08094, 0, 0.6875],
  2465. "86": [0, 0.69444, 0.1615, 0, 0.66667],
  2466. "87": [0, 0.69444, 0.1615, 0, 0.94445],
  2467. "88": [0, 0.69444, 0.13372, 0, 0.66667],
  2468. "89": [0, 0.69444, 0.17261, 0, 0.66667],
  2469. "90": [0, 0.69444, 0.11983, 0, 0.61111],
  2470. "91": [0.25, 0.75, 0.15942, 0, 0.28889],
  2471. "93": [0.25, 0.75, 0.08719, 0, 0.28889],
  2472. "94": [0, 0.69444, 0.0799, 0, 0.5],
  2473. "95": [0.35, 0.09444, 0.08616, 0, 0.5],
  2474. "97": [0, 0.44444, 0.00981, 0, 0.48056],
  2475. "98": [0, 0.69444, 0.03057, 0, 0.51667],
  2476. "99": [0, 0.44444, 0.08336, 0, 0.44445],
  2477. "100": [0, 0.69444, 0.09483, 0, 0.51667],
  2478. "101": [0, 0.44444, 0.06778, 0, 0.44445],
  2479. "102": [0, 0.69444, 0.21705, 0, 0.30556],
  2480. "103": [0.19444, 0.44444, 0.10836, 0, 0.5],
  2481. "104": [0, 0.69444, 0.01778, 0, 0.51667],
  2482. "105": [0, 0.67937, 0.09718, 0, 0.23889],
  2483. "106": [0.19444, 0.67937, 0.09162, 0, 0.26667],
  2484. "107": [0, 0.69444, 0.08336, 0, 0.48889],
  2485. "108": [0, 0.69444, 0.09483, 0, 0.23889],
  2486. "109": [0, 0.44444, 0.01778, 0, 0.79445],
  2487. "110": [0, 0.44444, 0.01778, 0, 0.51667],
  2488. "111": [0, 0.44444, 0.06613, 0, 0.5],
  2489. "112": [0.19444, 0.44444, 0.0389, 0, 0.51667],
  2490. "113": [0.19444, 0.44444, 0.04169, 0, 0.51667],
  2491. "114": [0, 0.44444, 0.10836, 0, 0.34167],
  2492. "115": [0, 0.44444, 0.0778, 0, 0.38333],
  2493. "116": [0, 0.57143, 0.07225, 0, 0.36111],
  2494. "117": [0, 0.44444, 0.04169, 0, 0.51667],
  2495. "118": [0, 0.44444, 0.10836, 0, 0.46111],
  2496. "119": [0, 0.44444, 0.10836, 0, 0.68334],
  2497. "120": [0, 0.44444, 0.09169, 0, 0.46111],
  2498. "121": [0.19444, 0.44444, 0.10836, 0, 0.46111],
  2499. "122": [0, 0.44444, 0.08752, 0, 0.43472],
  2500. "126": [0.35, 0.32659, 0.08826, 0, 0.5],
  2501. "160": [0, 0, 0, 0, 0.25],
  2502. "168": [0, 0.67937, 0.06385, 0, 0.5],
  2503. "176": [0, 0.69444, 0, 0, 0.73752],
  2504. "184": [0.17014, 0, 0, 0, 0.44445],
  2505. "305": [0, 0.44444, 0.04169, 0, 0.23889],
  2506. "567": [0.19444, 0.44444, 0.04169, 0, 0.26667],
  2507. "710": [0, 0.69444, 0.0799, 0, 0.5],
  2508. "711": [0, 0.63194, 0.08432, 0, 0.5],
  2509. "713": [0, 0.60889, 0.08776, 0, 0.5],
  2510. "714": [0, 0.69444, 0.09205, 0, 0.5],
  2511. "715": [0, 0.69444, 0, 0, 0.5],
  2512. "728": [0, 0.69444, 0.09483, 0, 0.5],
  2513. "729": [0, 0.67937, 0.07774, 0, 0.27778],
  2514. "730": [0, 0.69444, 0, 0, 0.73752],
  2515. "732": [0, 0.67659, 0.08826, 0, 0.5],
  2516. "733": [0, 0.69444, 0.09205, 0, 0.5],
  2517. "915": [0, 0.69444, 0.13372, 0, 0.54167],
  2518. "916": [0, 0.69444, 0, 0, 0.83334],
  2519. "920": [0, 0.69444, 0.07555, 0, 0.77778],
  2520. "923": [0, 0.69444, 0, 0, 0.61111],
  2521. "926": [0, 0.69444, 0.12816, 0, 0.66667],
  2522. "928": [0, 0.69444, 0.08094, 0, 0.70834],
  2523. "931": [0, 0.69444, 0.11983, 0, 0.72222],
  2524. "933": [0, 0.69444, 0.09031, 0, 0.77778],
  2525. "934": [0, 0.69444, 0.04603, 0, 0.72222],
  2526. "936": [0, 0.69444, 0.09031, 0, 0.77778],
  2527. "937": [0, 0.69444, 0.08293, 0, 0.72222],
  2528. "8211": [0, 0.44444, 0.08616, 0, 0.5],
  2529. "8212": [0, 0.44444, 0.08616, 0, 1.0],
  2530. "8216": [0, 0.69444, 0.07816, 0, 0.27778],
  2531. "8217": [0, 0.69444, 0.07816, 0, 0.27778],
  2532. "8220": [0, 0.69444, 0.14205, 0, 0.5],
  2533. "8221": [0, 0.69444, 0.00316, 0, 0.5]
  2534. },
  2535. "SansSerif-Regular": {
  2536. "32": [0, 0, 0, 0, 0.25],
  2537. "33": [0, 0.69444, 0, 0, 0.31945],
  2538. "34": [0, 0.69444, 0, 0, 0.5],
  2539. "35": [0.19444, 0.69444, 0, 0, 0.83334],
  2540. "36": [0.05556, 0.75, 0, 0, 0.5],
  2541. "37": [0.05556, 0.75, 0, 0, 0.83334],
  2542. "38": [0, 0.69444, 0, 0, 0.75834],
  2543. "39": [0, 0.69444, 0, 0, 0.27778],
  2544. "40": [0.25, 0.75, 0, 0, 0.38889],
  2545. "41": [0.25, 0.75, 0, 0, 0.38889],
  2546. "42": [0, 0.75, 0, 0, 0.5],
  2547. "43": [0.08333, 0.58333, 0, 0, 0.77778],
  2548. "44": [0.125, 0.08333, 0, 0, 0.27778],
  2549. "45": [0, 0.44444, 0, 0, 0.33333],
  2550. "46": [0, 0.08333, 0, 0, 0.27778],
  2551. "47": [0.25, 0.75, 0, 0, 0.5],
  2552. "48": [0, 0.65556, 0, 0, 0.5],
  2553. "49": [0, 0.65556, 0, 0, 0.5],
  2554. "50": [0, 0.65556, 0, 0, 0.5],
  2555. "51": [0, 0.65556, 0, 0, 0.5],
  2556. "52": [0, 0.65556, 0, 0, 0.5],
  2557. "53": [0, 0.65556, 0, 0, 0.5],
  2558. "54": [0, 0.65556, 0, 0, 0.5],
  2559. "55": [0, 0.65556, 0, 0, 0.5],
  2560. "56": [0, 0.65556, 0, 0, 0.5],
  2561. "57": [0, 0.65556, 0, 0, 0.5],
  2562. "58": [0, 0.44444, 0, 0, 0.27778],
  2563. "59": [0.125, 0.44444, 0, 0, 0.27778],
  2564. "61": [-0.13, 0.37, 0, 0, 0.77778],
  2565. "63": [0, 0.69444, 0, 0, 0.47222],
  2566. "64": [0, 0.69444, 0, 0, 0.66667],
  2567. "65": [0, 0.69444, 0, 0, 0.66667],
  2568. "66": [0, 0.69444, 0, 0, 0.66667],
  2569. "67": [0, 0.69444, 0, 0, 0.63889],
  2570. "68": [0, 0.69444, 0, 0, 0.72223],
  2571. "69": [0, 0.69444, 0, 0, 0.59722],
  2572. "70": [0, 0.69444, 0, 0, 0.56945],
  2573. "71": [0, 0.69444, 0, 0, 0.66667],
  2574. "72": [0, 0.69444, 0, 0, 0.70834],
  2575. "73": [0, 0.69444, 0, 0, 0.27778],
  2576. "74": [0, 0.69444, 0, 0, 0.47222],
  2577. "75": [0, 0.69444, 0, 0, 0.69445],
  2578. "76": [0, 0.69444, 0, 0, 0.54167],
  2579. "77": [0, 0.69444, 0, 0, 0.875],
  2580. "78": [0, 0.69444, 0, 0, 0.70834],
  2581. "79": [0, 0.69444, 0, 0, 0.73611],
  2582. "80": [0, 0.69444, 0, 0, 0.63889],
  2583. "81": [0.125, 0.69444, 0, 0, 0.73611],
  2584. "82": [0, 0.69444, 0, 0, 0.64584],
  2585. "83": [0, 0.69444, 0, 0, 0.55556],
  2586. "84": [0, 0.69444, 0, 0, 0.68056],
  2587. "85": [0, 0.69444, 0, 0, 0.6875],
  2588. "86": [0, 0.69444, 0.01389, 0, 0.66667],
  2589. "87": [0, 0.69444, 0.01389, 0, 0.94445],
  2590. "88": [0, 0.69444, 0, 0, 0.66667],
  2591. "89": [0, 0.69444, 0.025, 0, 0.66667],
  2592. "90": [0, 0.69444, 0, 0, 0.61111],
  2593. "91": [0.25, 0.75, 0, 0, 0.28889],
  2594. "93": [0.25, 0.75, 0, 0, 0.28889],
  2595. "94": [0, 0.69444, 0, 0, 0.5],
  2596. "95": [0.35, 0.09444, 0.02778, 0, 0.5],
  2597. "97": [0, 0.44444, 0, 0, 0.48056],
  2598. "98": [0, 0.69444, 0, 0, 0.51667],
  2599. "99": [0, 0.44444, 0, 0, 0.44445],
  2600. "100": [0, 0.69444, 0, 0, 0.51667],
  2601. "101": [0, 0.44444, 0, 0, 0.44445],
  2602. "102": [0, 0.69444, 0.06944, 0, 0.30556],
  2603. "103": [0.19444, 0.44444, 0.01389, 0, 0.5],
  2604. "104": [0, 0.69444, 0, 0, 0.51667],
  2605. "105": [0, 0.67937, 0, 0, 0.23889],
  2606. "106": [0.19444, 0.67937, 0, 0, 0.26667],
  2607. "107": [0, 0.69444, 0, 0, 0.48889],
  2608. "108": [0, 0.69444, 0, 0, 0.23889],
  2609. "109": [0, 0.44444, 0, 0, 0.79445],
  2610. "110": [0, 0.44444, 0, 0, 0.51667],
  2611. "111": [0, 0.44444, 0, 0, 0.5],
  2612. "112": [0.19444, 0.44444, 0, 0, 0.51667],
  2613. "113": [0.19444, 0.44444, 0, 0, 0.51667],
  2614. "114": [0, 0.44444, 0.01389, 0, 0.34167],
  2615. "115": [0, 0.44444, 0, 0, 0.38333],
  2616. "116": [0, 0.57143, 0, 0, 0.36111],
  2617. "117": [0, 0.44444, 0, 0, 0.51667],
  2618. "118": [0, 0.44444, 0.01389, 0, 0.46111],
  2619. "119": [0, 0.44444, 0.01389, 0, 0.68334],
  2620. "120": [0, 0.44444, 0, 0, 0.46111],
  2621. "121": [0.19444, 0.44444, 0.01389, 0, 0.46111],
  2622. "122": [0, 0.44444, 0, 0, 0.43472],
  2623. "126": [0.35, 0.32659, 0, 0, 0.5],
  2624. "160": [0, 0, 0, 0, 0.25],
  2625. "168": [0, 0.67937, 0, 0, 0.5],
  2626. "176": [0, 0.69444, 0, 0, 0.66667],
  2627. "184": [0.17014, 0, 0, 0, 0.44445],
  2628. "305": [0, 0.44444, 0, 0, 0.23889],
  2629. "567": [0.19444, 0.44444, 0, 0, 0.26667],
  2630. "710": [0, 0.69444, 0, 0, 0.5],
  2631. "711": [0, 0.63194, 0, 0, 0.5],
  2632. "713": [0, 0.60889, 0, 0, 0.5],
  2633. "714": [0, 0.69444, 0, 0, 0.5],
  2634. "715": [0, 0.69444, 0, 0, 0.5],
  2635. "728": [0, 0.69444, 0, 0, 0.5],
  2636. "729": [0, 0.67937, 0, 0, 0.27778],
  2637. "730": [0, 0.69444, 0, 0, 0.66667],
  2638. "732": [0, 0.67659, 0, 0, 0.5],
  2639. "733": [0, 0.69444, 0, 0, 0.5],
  2640. "915": [0, 0.69444, 0, 0, 0.54167],
  2641. "916": [0, 0.69444, 0, 0, 0.83334],
  2642. "920": [0, 0.69444, 0, 0, 0.77778],
  2643. "923": [0, 0.69444, 0, 0, 0.61111],
  2644. "926": [0, 0.69444, 0, 0, 0.66667],
  2645. "928": [0, 0.69444, 0, 0, 0.70834],
  2646. "931": [0, 0.69444, 0, 0, 0.72222],
  2647. "933": [0, 0.69444, 0, 0, 0.77778],
  2648. "934": [0, 0.69444, 0, 0, 0.72222],
  2649. "936": [0, 0.69444, 0, 0, 0.77778],
  2650. "937": [0, 0.69444, 0, 0, 0.72222],
  2651. "8211": [0, 0.44444, 0.02778, 0, 0.5],
  2652. "8212": [0, 0.44444, 0.02778, 0, 1.0],
  2653. "8216": [0, 0.69444, 0, 0, 0.27778],
  2654. "8217": [0, 0.69444, 0, 0, 0.27778],
  2655. "8220": [0, 0.69444, 0, 0, 0.5],
  2656. "8221": [0, 0.69444, 0, 0, 0.5]
  2657. },
  2658. "Script-Regular": {
  2659. "32": [0, 0, 0, 0, 0.25],
  2660. "65": [0, 0.7, 0.22925, 0, 0.80253],
  2661. "66": [0, 0.7, 0.04087, 0, 0.90757],
  2662. "67": [0, 0.7, 0.1689, 0, 0.66619],
  2663. "68": [0, 0.7, 0.09371, 0, 0.77443],
  2664. "69": [0, 0.7, 0.18583, 0, 0.56162],
  2665. "70": [0, 0.7, 0.13634, 0, 0.89544],
  2666. "71": [0, 0.7, 0.17322, 0, 0.60961],
  2667. "72": [0, 0.7, 0.29694, 0, 0.96919],
  2668. "73": [0, 0.7, 0.19189, 0, 0.80907],
  2669. "74": [0.27778, 0.7, 0.19189, 0, 1.05159],
  2670. "75": [0, 0.7, 0.31259, 0, 0.91364],
  2671. "76": [0, 0.7, 0.19189, 0, 0.87373],
  2672. "77": [0, 0.7, 0.15981, 0, 1.08031],
  2673. "78": [0, 0.7, 0.3525, 0, 0.9015],
  2674. "79": [0, 0.7, 0.08078, 0, 0.73787],
  2675. "80": [0, 0.7, 0.08078, 0, 1.01262],
  2676. "81": [0, 0.7, 0.03305, 0, 0.88282],
  2677. "82": [0, 0.7, 0.06259, 0, 0.85],
  2678. "83": [0, 0.7, 0.19189, 0, 0.86767],
  2679. "84": [0, 0.7, 0.29087, 0, 0.74697],
  2680. "85": [0, 0.7, 0.25815, 0, 0.79996],
  2681. "86": [0, 0.7, 0.27523, 0, 0.62204],
  2682. "87": [0, 0.7, 0.27523, 0, 0.80532],
  2683. "88": [0, 0.7, 0.26006, 0, 0.94445],
  2684. "89": [0, 0.7, 0.2939, 0, 0.70961],
  2685. "90": [0, 0.7, 0.24037, 0, 0.8212],
  2686. "160": [0, 0, 0, 0, 0.25]
  2687. },
  2688. "Size1-Regular": {
  2689. "32": [0, 0, 0, 0, 0.25],
  2690. "40": [0.35001, 0.85, 0, 0, 0.45834],
  2691. "41": [0.35001, 0.85, 0, 0, 0.45834],
  2692. "47": [0.35001, 0.85, 0, 0, 0.57778],
  2693. "91": [0.35001, 0.85, 0, 0, 0.41667],
  2694. "92": [0.35001, 0.85, 0, 0, 0.57778],
  2695. "93": [0.35001, 0.85, 0, 0, 0.41667],
  2696. "123": [0.35001, 0.85, 0, 0, 0.58334],
  2697. "125": [0.35001, 0.85, 0, 0, 0.58334],
  2698. "160": [0, 0, 0, 0, 0.25],
  2699. "710": [0, 0.72222, 0, 0, 0.55556],
  2700. "732": [0, 0.72222, 0, 0, 0.55556],
  2701. "770": [0, 0.72222, 0, 0, 0.55556],
  2702. "771": [0, 0.72222, 0, 0, 0.55556],
  2703. "8214": [-0.00099, 0.601, 0, 0, 0.77778],
  2704. "8593": [1e-05, 0.6, 0, 0, 0.66667],
  2705. "8595": [1e-05, 0.6, 0, 0, 0.66667],
  2706. "8657": [1e-05, 0.6, 0, 0, 0.77778],
  2707. "8659": [1e-05, 0.6, 0, 0, 0.77778],
  2708. "8719": [0.25001, 0.75, 0, 0, 0.94445],
  2709. "8720": [0.25001, 0.75, 0, 0, 0.94445],
  2710. "8721": [0.25001, 0.75, 0, 0, 1.05556],
  2711. "8730": [0.35001, 0.85, 0, 0, 1.0],
  2712. "8739": [-0.00599, 0.606, 0, 0, 0.33333],
  2713. "8741": [-0.00599, 0.606, 0, 0, 0.55556],
  2714. "8747": [0.30612, 0.805, 0.19445, 0, 0.47222],
  2715. "8748": [0.306, 0.805, 0.19445, 0, 0.47222],
  2716. "8749": [0.306, 0.805, 0.19445, 0, 0.47222],
  2717. "8750": [0.30612, 0.805, 0.19445, 0, 0.47222],
  2718. "8896": [0.25001, 0.75, 0, 0, 0.83334],
  2719. "8897": [0.25001, 0.75, 0, 0, 0.83334],
  2720. "8898": [0.25001, 0.75, 0, 0, 0.83334],
  2721. "8899": [0.25001, 0.75, 0, 0, 0.83334],
  2722. "8968": [0.35001, 0.85, 0, 0, 0.47222],
  2723. "8969": [0.35001, 0.85, 0, 0, 0.47222],
  2724. "8970": [0.35001, 0.85, 0, 0, 0.47222],
  2725. "8971": [0.35001, 0.85, 0, 0, 0.47222],
  2726. "9168": [-0.00099, 0.601, 0, 0, 0.66667],
  2727. "10216": [0.35001, 0.85, 0, 0, 0.47222],
  2728. "10217": [0.35001, 0.85, 0, 0, 0.47222],
  2729. "10752": [0.25001, 0.75, 0, 0, 1.11111],
  2730. "10753": [0.25001, 0.75, 0, 0, 1.11111],
  2731. "10754": [0.25001, 0.75, 0, 0, 1.11111],
  2732. "10756": [0.25001, 0.75, 0, 0, 0.83334],
  2733. "10758": [0.25001, 0.75, 0, 0, 0.83334]
  2734. },
  2735. "Size2-Regular": {
  2736. "32": [0, 0, 0, 0, 0.25],
  2737. "40": [0.65002, 1.15, 0, 0, 0.59722],
  2738. "41": [0.65002, 1.15, 0, 0, 0.59722],
  2739. "47": [0.65002, 1.15, 0, 0, 0.81111],
  2740. "91": [0.65002, 1.15, 0, 0, 0.47222],
  2741. "92": [0.65002, 1.15, 0, 0, 0.81111],
  2742. "93": [0.65002, 1.15, 0, 0, 0.47222],
  2743. "123": [0.65002, 1.15, 0, 0, 0.66667],
  2744. "125": [0.65002, 1.15, 0, 0, 0.66667],
  2745. "160": [0, 0, 0, 0, 0.25],
  2746. "710": [0, 0.75, 0, 0, 1.0],
  2747. "732": [0, 0.75, 0, 0, 1.0],
  2748. "770": [0, 0.75, 0, 0, 1.0],
  2749. "771": [0, 0.75, 0, 0, 1.0],
  2750. "8719": [0.55001, 1.05, 0, 0, 1.27778],
  2751. "8720": [0.55001, 1.05, 0, 0, 1.27778],
  2752. "8721": [0.55001, 1.05, 0, 0, 1.44445],
  2753. "8730": [0.65002, 1.15, 0, 0, 1.0],
  2754. "8747": [0.86225, 1.36, 0.44445, 0, 0.55556],
  2755. "8748": [0.862, 1.36, 0.44445, 0, 0.55556],
  2756. "8749": [0.862, 1.36, 0.44445, 0, 0.55556],
  2757. "8750": [0.86225, 1.36, 0.44445, 0, 0.55556],
  2758. "8896": [0.55001, 1.05, 0, 0, 1.11111],
  2759. "8897": [0.55001, 1.05, 0, 0, 1.11111],
  2760. "8898": [0.55001, 1.05, 0, 0, 1.11111],
  2761. "8899": [0.55001, 1.05, 0, 0, 1.11111],
  2762. "8968": [0.65002, 1.15, 0, 0, 0.52778],
  2763. "8969": [0.65002, 1.15, 0, 0, 0.52778],
  2764. "8970": [0.65002, 1.15, 0, 0, 0.52778],
  2765. "8971": [0.65002, 1.15, 0, 0, 0.52778],
  2766. "10216": [0.65002, 1.15, 0, 0, 0.61111],
  2767. "10217": [0.65002, 1.15, 0, 0, 0.61111],
  2768. "10752": [0.55001, 1.05, 0, 0, 1.51112],
  2769. "10753": [0.55001, 1.05, 0, 0, 1.51112],
  2770. "10754": [0.55001, 1.05, 0, 0, 1.51112],
  2771. "10756": [0.55001, 1.05, 0, 0, 1.11111],
  2772. "10758": [0.55001, 1.05, 0, 0, 1.11111]
  2773. },
  2774. "Size3-Regular": {
  2775. "32": [0, 0, 0, 0, 0.25],
  2776. "40": [0.95003, 1.45, 0, 0, 0.73611],
  2777. "41": [0.95003, 1.45, 0, 0, 0.73611],
  2778. "47": [0.95003, 1.45, 0, 0, 1.04445],
  2779. "91": [0.95003, 1.45, 0, 0, 0.52778],
  2780. "92": [0.95003, 1.45, 0, 0, 1.04445],
  2781. "93": [0.95003, 1.45, 0, 0, 0.52778],
  2782. "123": [0.95003, 1.45, 0, 0, 0.75],
  2783. "125": [0.95003, 1.45, 0, 0, 0.75],
  2784. "160": [0, 0, 0, 0, 0.25],
  2785. "710": [0, 0.75, 0, 0, 1.44445],
  2786. "732": [0, 0.75, 0, 0, 1.44445],
  2787. "770": [0, 0.75, 0, 0, 1.44445],
  2788. "771": [0, 0.75, 0, 0, 1.44445],
  2789. "8730": [0.95003, 1.45, 0, 0, 1.0],
  2790. "8968": [0.95003, 1.45, 0, 0, 0.58334],
  2791. "8969": [0.95003, 1.45, 0, 0, 0.58334],
  2792. "8970": [0.95003, 1.45, 0, 0, 0.58334],
  2793. "8971": [0.95003, 1.45, 0, 0, 0.58334],
  2794. "10216": [0.95003, 1.45, 0, 0, 0.75],
  2795. "10217": [0.95003, 1.45, 0, 0, 0.75]
  2796. },
  2797. "Size4-Regular": {
  2798. "32": [0, 0, 0, 0, 0.25],
  2799. "40": [1.25003, 1.75, 0, 0, 0.79167],
  2800. "41": [1.25003, 1.75, 0, 0, 0.79167],
  2801. "47": [1.25003, 1.75, 0, 0, 1.27778],
  2802. "91": [1.25003, 1.75, 0, 0, 0.58334],
  2803. "92": [1.25003, 1.75, 0, 0, 1.27778],
  2804. "93": [1.25003, 1.75, 0, 0, 0.58334],
  2805. "123": [1.25003, 1.75, 0, 0, 0.80556],
  2806. "125": [1.25003, 1.75, 0, 0, 0.80556],
  2807. "160": [0, 0, 0, 0, 0.25],
  2808. "710": [0, 0.825, 0, 0, 1.8889],
  2809. "732": [0, 0.825, 0, 0, 1.8889],
  2810. "770": [0, 0.825, 0, 0, 1.8889],
  2811. "771": [0, 0.825, 0, 0, 1.8889],
  2812. "8730": [1.25003, 1.75, 0, 0, 1.0],
  2813. "8968": [1.25003, 1.75, 0, 0, 0.63889],
  2814. "8969": [1.25003, 1.75, 0, 0, 0.63889],
  2815. "8970": [1.25003, 1.75, 0, 0, 0.63889],
  2816. "8971": [1.25003, 1.75, 0, 0, 0.63889],
  2817. "9115": [0.64502, 1.155, 0, 0, 0.875],
  2818. "9116": [1e-05, 0.6, 0, 0, 0.875],
  2819. "9117": [0.64502, 1.155, 0, 0, 0.875],
  2820. "9118": [0.64502, 1.155, 0, 0, 0.875],
  2821. "9119": [1e-05, 0.6, 0, 0, 0.875],
  2822. "9120": [0.64502, 1.155, 0, 0, 0.875],
  2823. "9121": [0.64502, 1.155, 0, 0, 0.66667],
  2824. "9122": [-0.00099, 0.601, 0, 0, 0.66667],
  2825. "9123": [0.64502, 1.155, 0, 0, 0.66667],
  2826. "9124": [0.64502, 1.155, 0, 0, 0.66667],
  2827. "9125": [-0.00099, 0.601, 0, 0, 0.66667],
  2828. "9126": [0.64502, 1.155, 0, 0, 0.66667],
  2829. "9127": [1e-05, 0.9, 0, 0, 0.88889],
  2830. "9128": [0.65002, 1.15, 0, 0, 0.88889],
  2831. "9129": [0.90001, 0, 0, 0, 0.88889],
  2832. "9130": [0, 0.3, 0, 0, 0.88889],
  2833. "9131": [1e-05, 0.9, 0, 0, 0.88889],
  2834. "9132": [0.65002, 1.15, 0, 0, 0.88889],
  2835. "9133": [0.90001, 0, 0, 0, 0.88889],
  2836. "9143": [0.88502, 0.915, 0, 0, 1.05556],
  2837. "10216": [1.25003, 1.75, 0, 0, 0.80556],
  2838. "10217": [1.25003, 1.75, 0, 0, 0.80556],
  2839. "57344": [-0.00499, 0.605, 0, 0, 1.05556],
  2840. "57345": [-0.00499, 0.605, 0, 0, 1.05556],
  2841. "57680": [0, 0.12, 0, 0, 0.45],
  2842. "57681": [0, 0.12, 0, 0, 0.45],
  2843. "57682": [0, 0.12, 0, 0, 0.45],
  2844. "57683": [0, 0.12, 0, 0, 0.45]
  2845. },
  2846. "Typewriter-Regular": {
  2847. "32": [0, 0, 0, 0, 0.525],
  2848. "33": [0, 0.61111, 0, 0, 0.525],
  2849. "34": [0, 0.61111, 0, 0, 0.525],
  2850. "35": [0, 0.61111, 0, 0, 0.525],
  2851. "36": [0.08333, 0.69444, 0, 0, 0.525],
  2852. "37": [0.08333, 0.69444, 0, 0, 0.525],
  2853. "38": [0, 0.61111, 0, 0, 0.525],
  2854. "39": [0, 0.61111, 0, 0, 0.525],
  2855. "40": [0.08333, 0.69444, 0, 0, 0.525],
  2856. "41": [0.08333, 0.69444, 0, 0, 0.525],
  2857. "42": [0, 0.52083, 0, 0, 0.525],
  2858. "43": [-0.08056, 0.53055, 0, 0, 0.525],
  2859. "44": [0.13889, 0.125, 0, 0, 0.525],
  2860. "45": [-0.08056, 0.53055, 0, 0, 0.525],
  2861. "46": [0, 0.125, 0, 0, 0.525],
  2862. "47": [0.08333, 0.69444, 0, 0, 0.525],
  2863. "48": [0, 0.61111, 0, 0, 0.525],
  2864. "49": [0, 0.61111, 0, 0, 0.525],
  2865. "50": [0, 0.61111, 0, 0, 0.525],
  2866. "51": [0, 0.61111, 0, 0, 0.525],
  2867. "52": [0, 0.61111, 0, 0, 0.525],
  2868. "53": [0, 0.61111, 0, 0, 0.525],
  2869. "54": [0, 0.61111, 0, 0, 0.525],
  2870. "55": [0, 0.61111, 0, 0, 0.525],
  2871. "56": [0, 0.61111, 0, 0, 0.525],
  2872. "57": [0, 0.61111, 0, 0, 0.525],
  2873. "58": [0, 0.43056, 0, 0, 0.525],
  2874. "59": [0.13889, 0.43056, 0, 0, 0.525],
  2875. "60": [-0.05556, 0.55556, 0, 0, 0.525],
  2876. "61": [-0.19549, 0.41562, 0, 0, 0.525],
  2877. "62": [-0.05556, 0.55556, 0, 0, 0.525],
  2878. "63": [0, 0.61111, 0, 0, 0.525],
  2879. "64": [0, 0.61111, 0, 0, 0.525],
  2880. "65": [0, 0.61111, 0, 0, 0.525],
  2881. "66": [0, 0.61111, 0, 0, 0.525],
  2882. "67": [0, 0.61111, 0, 0, 0.525],
  2883. "68": [0, 0.61111, 0, 0, 0.525],
  2884. "69": [0, 0.61111, 0, 0, 0.525],
  2885. "70": [0, 0.61111, 0, 0, 0.525],
  2886. "71": [0, 0.61111, 0, 0, 0.525],
  2887. "72": [0, 0.61111, 0, 0, 0.525],
  2888. "73": [0, 0.61111, 0, 0, 0.525],
  2889. "74": [0, 0.61111, 0, 0, 0.525],
  2890. "75": [0, 0.61111, 0, 0, 0.525],
  2891. "76": [0, 0.61111, 0, 0, 0.525],
  2892. "77": [0, 0.61111, 0, 0, 0.525],
  2893. "78": [0, 0.61111, 0, 0, 0.525],
  2894. "79": [0, 0.61111, 0, 0, 0.525],
  2895. "80": [0, 0.61111, 0, 0, 0.525],
  2896. "81": [0.13889, 0.61111, 0, 0, 0.525],
  2897. "82": [0, 0.61111, 0, 0, 0.525],
  2898. "83": [0, 0.61111, 0, 0, 0.525],
  2899. "84": [0, 0.61111, 0, 0, 0.525],
  2900. "85": [0, 0.61111, 0, 0, 0.525],
  2901. "86": [0, 0.61111, 0, 0, 0.525],
  2902. "87": [0, 0.61111, 0, 0, 0.525],
  2903. "88": [0, 0.61111, 0, 0, 0.525],
  2904. "89": [0, 0.61111, 0, 0, 0.525],
  2905. "90": [0, 0.61111, 0, 0, 0.525],
  2906. "91": [0.08333, 0.69444, 0, 0, 0.525],
  2907. "92": [0.08333, 0.69444, 0, 0, 0.525],
  2908. "93": [0.08333, 0.69444, 0, 0, 0.525],
  2909. "94": [0, 0.61111, 0, 0, 0.525],
  2910. "95": [0.09514, 0, 0, 0, 0.525],
  2911. "96": [0, 0.61111, 0, 0, 0.525],
  2912. "97": [0, 0.43056, 0, 0, 0.525],
  2913. "98": [0, 0.61111, 0, 0, 0.525],
  2914. "99": [0, 0.43056, 0, 0, 0.525],
  2915. "100": [0, 0.61111, 0, 0, 0.525],
  2916. "101": [0, 0.43056, 0, 0, 0.525],
  2917. "102": [0, 0.61111, 0, 0, 0.525],
  2918. "103": [0.22222, 0.43056, 0, 0, 0.525],
  2919. "104": [0, 0.61111, 0, 0, 0.525],
  2920. "105": [0, 0.61111, 0, 0, 0.525],
  2921. "106": [0.22222, 0.61111, 0, 0, 0.525],
  2922. "107": [0, 0.61111, 0, 0, 0.525],
  2923. "108": [0, 0.61111, 0, 0, 0.525],
  2924. "109": [0, 0.43056, 0, 0, 0.525],
  2925. "110": [0, 0.43056, 0, 0, 0.525],
  2926. "111": [0, 0.43056, 0, 0, 0.525],
  2927. "112": [0.22222, 0.43056, 0, 0, 0.525],
  2928. "113": [0.22222, 0.43056, 0, 0, 0.525],
  2929. "114": [0, 0.43056, 0, 0, 0.525],
  2930. "115": [0, 0.43056, 0, 0, 0.525],
  2931. "116": [0, 0.55358, 0, 0, 0.525],
  2932. "117": [0, 0.43056, 0, 0, 0.525],
  2933. "118": [0, 0.43056, 0, 0, 0.525],
  2934. "119": [0, 0.43056, 0, 0, 0.525],
  2935. "120": [0, 0.43056, 0, 0, 0.525],
  2936. "121": [0.22222, 0.43056, 0, 0, 0.525],
  2937. "122": [0, 0.43056, 0, 0, 0.525],
  2938. "123": [0.08333, 0.69444, 0, 0, 0.525],
  2939. "124": [0.08333, 0.69444, 0, 0, 0.525],
  2940. "125": [0.08333, 0.69444, 0, 0, 0.525],
  2941. "126": [0, 0.61111, 0, 0, 0.525],
  2942. "127": [0, 0.61111, 0, 0, 0.525],
  2943. "160": [0, 0, 0, 0, 0.525],
  2944. "176": [0, 0.61111, 0, 0, 0.525],
  2945. "184": [0.19445, 0, 0, 0, 0.525],
  2946. "305": [0, 0.43056, 0, 0, 0.525],
  2947. "567": [0.22222, 0.43056, 0, 0, 0.525],
  2948. "711": [0, 0.56597, 0, 0, 0.525],
  2949. "713": [0, 0.56555, 0, 0, 0.525],
  2950. "714": [0, 0.61111, 0, 0, 0.525],
  2951. "715": [0, 0.61111, 0, 0, 0.525],
  2952. "728": [0, 0.61111, 0, 0, 0.525],
  2953. "730": [0, 0.61111, 0, 0, 0.525],
  2954. "770": [0, 0.61111, 0, 0, 0.525],
  2955. "771": [0, 0.61111, 0, 0, 0.525],
  2956. "776": [0, 0.61111, 0, 0, 0.525],
  2957. "915": [0, 0.61111, 0, 0, 0.525],
  2958. "916": [0, 0.61111, 0, 0, 0.525],
  2959. "920": [0, 0.61111, 0, 0, 0.525],
  2960. "923": [0, 0.61111, 0, 0, 0.525],
  2961. "926": [0, 0.61111, 0, 0, 0.525],
  2962. "928": [0, 0.61111, 0, 0, 0.525],
  2963. "931": [0, 0.61111, 0, 0, 0.525],
  2964. "933": [0, 0.61111, 0, 0, 0.525],
  2965. "934": [0, 0.61111, 0, 0, 0.525],
  2966. "936": [0, 0.61111, 0, 0, 0.525],
  2967. "937": [0, 0.61111, 0, 0, 0.525],
  2968. "8216": [0, 0.61111, 0, 0, 0.525],
  2969. "8217": [0, 0.61111, 0, 0, 0.525],
  2970. "8242": [0, 0.61111, 0, 0, 0.525],
  2971. "9251": [0.11111, 0.21944, 0, 0, 0.525]
  2972. }
  2973. };
  2974. /**
  2975. * This file contains metrics regarding fonts and individual symbols. The sigma
  2976. * and xi variables, as well as the metricMap map contain data extracted from
  2977. * TeX, TeX font metrics, and the TTF files. These data are then exposed via the
  2978. * `metrics` variable and the getCharacterMetrics function.
  2979. */
  2980. // In TeX, there are actually three sets of dimensions, one for each of
  2981. // textstyle (size index 5 and higher: >=9pt), scriptstyle (size index 3 and 4:
  2982. // 7-8pt), and scriptscriptstyle (size index 1 and 2: 5-6pt). These are
  2983. // provided in the the arrays below, in that order.
  2984. //
  2985. // The font metrics are stored in fonts cmsy10, cmsy7, and cmsy5 respsectively.
  2986. // This was determined by running the following script:
  2987. //
  2988. // latex -interaction=nonstopmode \
  2989. // '\documentclass{article}\usepackage{amsmath}\begin{document}' \
  2990. // '$a$ \expandafter\show\the\textfont2' \
  2991. // '\expandafter\show\the\scriptfont2' \
  2992. // '\expandafter\show\the\scriptscriptfont2' \
  2993. // '\stop'
  2994. //
  2995. // The metrics themselves were retreived using the following commands:
  2996. //
  2997. // tftopl cmsy10
  2998. // tftopl cmsy7
  2999. // tftopl cmsy5
  3000. //
  3001. // The output of each of these commands is quite lengthy. The only part we
  3002. // care about is the FONTDIMEN section. Each value is measured in EMs.
  3003. var sigmasAndXis = {
  3004. slant: [0.250, 0.250, 0.250],
  3005. // sigma1
  3006. space: [0.000, 0.000, 0.000],
  3007. // sigma2
  3008. stretch: [0.000, 0.000, 0.000],
  3009. // sigma3
  3010. shrink: [0.000, 0.000, 0.000],
  3011. // sigma4
  3012. xHeight: [0.431, 0.431, 0.431],
  3013. // sigma5
  3014. quad: [1.000, 1.171, 1.472],
  3015. // sigma6
  3016. extraSpace: [0.000, 0.000, 0.000],
  3017. // sigma7
  3018. num1: [0.677, 0.732, 0.925],
  3019. // sigma8
  3020. num2: [0.394, 0.384, 0.387],
  3021. // sigma9
  3022. num3: [0.444, 0.471, 0.504],
  3023. // sigma10
  3024. denom1: [0.686, 0.752, 1.025],
  3025. // sigma11
  3026. denom2: [0.345, 0.344, 0.532],
  3027. // sigma12
  3028. sup1: [0.413, 0.503, 0.504],
  3029. // sigma13
  3030. sup2: [0.363, 0.431, 0.404],
  3031. // sigma14
  3032. sup3: [0.289, 0.286, 0.294],
  3033. // sigma15
  3034. sub1: [0.150, 0.143, 0.200],
  3035. // sigma16
  3036. sub2: [0.247, 0.286, 0.400],
  3037. // sigma17
  3038. supDrop: [0.386, 0.353, 0.494],
  3039. // sigma18
  3040. subDrop: [0.050, 0.071, 0.100],
  3041. // sigma19
  3042. delim1: [2.390, 1.700, 1.980],
  3043. // sigma20
  3044. delim2: [1.010, 1.157, 1.420],
  3045. // sigma21
  3046. axisHeight: [0.250, 0.250, 0.250],
  3047. // sigma22
  3048. // These font metrics are extracted from TeX by using tftopl on cmex10.tfm;
  3049. // they correspond to the font parameters of the extension fonts (family 3).
  3050. // See the TeXbook, page 441. In AMSTeX, the extension fonts scale; to
  3051. // match cmex7, we'd use cmex7.tfm values for script and scriptscript
  3052. // values.
  3053. defaultRuleThickness: [0.04, 0.049, 0.049],
  3054. // xi8; cmex7: 0.049
  3055. bigOpSpacing1: [0.111, 0.111, 0.111],
  3056. // xi9
  3057. bigOpSpacing2: [0.166, 0.166, 0.166],
  3058. // xi10
  3059. bigOpSpacing3: [0.2, 0.2, 0.2],
  3060. // xi11
  3061. bigOpSpacing4: [0.6, 0.611, 0.611],
  3062. // xi12; cmex7: 0.611
  3063. bigOpSpacing5: [0.1, 0.143, 0.143],
  3064. // xi13; cmex7: 0.143
  3065. // The \sqrt rule width is taken from the height of the surd character.
  3066. // Since we use the same font at all sizes, this thickness doesn't scale.
  3067. sqrtRuleThickness: [0.04, 0.04, 0.04],
  3068. // This value determines how large a pt is, for metrics which are defined
  3069. // in terms of pts.
  3070. // This value is also used in katex.less; if you change it make sure the
  3071. // values match.
  3072. ptPerEm: [10.0, 10.0, 10.0],
  3073. // The space between adjacent `|` columns in an array definition. From
  3074. // `\showthe\doublerulesep` in LaTeX. Equals 2.0 / ptPerEm.
  3075. doubleRuleSep: [0.2, 0.2, 0.2],
  3076. // The width of separator lines in {array} environments. From
  3077. // `\showthe\arrayrulewidth` in LaTeX. Equals 0.4 / ptPerEm.
  3078. arrayRuleWidth: [0.04, 0.04, 0.04],
  3079. // Two values from LaTeX source2e:
  3080. fboxsep: [0.3, 0.3, 0.3],
  3081. // 3 pt / ptPerEm
  3082. fboxrule: [0.04, 0.04, 0.04] // 0.4 pt / ptPerEm
  3083. }; // This map contains a mapping from font name and character code to character
  3084. // should have Latin-1 and Cyrillic characters, but may not depending on the
  3085. // operating system. The metrics do not account for extra height from the
  3086. // accents. In the case of Cyrillic characters which have both ascenders and
  3087. // descenders we prefer approximations with ascenders, primarily to prevent
  3088. // the fraction bar or root line from intersecting the glyph.
  3089. // TODO(kevinb) allow union of multiple glyph metrics for better accuracy.
  3090. var extraCharacterMap = {
  3091. // Latin-1
  3092. 'Å': 'A',
  3093. 'Ð': 'D',
  3094. 'Þ': 'o',
  3095. 'å': 'a',
  3096. 'ð': 'd',
  3097. 'þ': 'o',
  3098. // Cyrillic
  3099. 'А': 'A',
  3100. 'Б': 'B',
  3101. 'В': 'B',
  3102. 'Г': 'F',
  3103. 'Д': 'A',
  3104. 'Е': 'E',
  3105. 'Ж': 'K',
  3106. 'З': '3',
  3107. 'И': 'N',
  3108. 'Й': 'N',
  3109. 'К': 'K',
  3110. 'Л': 'N',
  3111. 'М': 'M',
  3112. 'Н': 'H',
  3113. 'О': 'O',
  3114. 'П': 'N',
  3115. 'Р': 'P',
  3116. 'С': 'C',
  3117. 'Т': 'T',
  3118. 'У': 'y',
  3119. 'Ф': 'O',
  3120. 'Х': 'X',
  3121. 'Ц': 'U',
  3122. 'Ч': 'h',
  3123. 'Ш': 'W',
  3124. 'Щ': 'W',
  3125. 'Ъ': 'B',
  3126. 'Ы': 'X',
  3127. 'Ь': 'B',
  3128. 'Э': '3',
  3129. 'Ю': 'X',
  3130. 'Я': 'R',
  3131. 'а': 'a',
  3132. 'б': 'b',
  3133. 'в': 'a',
  3134. 'г': 'r',
  3135. 'д': 'y',
  3136. 'е': 'e',
  3137. 'ж': 'm',
  3138. 'з': 'e',
  3139. 'и': 'n',
  3140. 'й': 'n',
  3141. 'к': 'n',
  3142. 'л': 'n',
  3143. 'м': 'm',
  3144. 'н': 'n',
  3145. 'о': 'o',
  3146. 'п': 'n',
  3147. 'р': 'p',
  3148. 'с': 'c',
  3149. 'т': 'o',
  3150. 'у': 'y',
  3151. 'ф': 'b',
  3152. 'х': 'x',
  3153. 'ц': 'n',
  3154. 'ч': 'n',
  3155. 'ш': 'w',
  3156. 'щ': 'w',
  3157. 'ъ': 'a',
  3158. 'ы': 'm',
  3159. 'ь': 'a',
  3160. 'э': 'e',
  3161. 'ю': 'm',
  3162. 'я': 'r'
  3163. };
  3164. /**
  3165. * This function adds new font metrics to default metricMap
  3166. * It can also override existing metrics
  3167. */
  3168. function setFontMetrics(fontName, metrics) {
  3169. fontMetricsData[fontName] = metrics;
  3170. }
  3171. /**
  3172. * This function is a convenience function for looking up information in the
  3173. * metricMap table. It takes a character as a string, and a font.
  3174. *
  3175. * Note: the `width` property may be undefined if fontMetricsData.js wasn't
  3176. * built using `Make extended_metrics`.
  3177. */
  3178. function getCharacterMetrics(character, font, mode) {
  3179. if (!fontMetricsData[font]) {
  3180. throw new Error("Font metrics not found for font: " + font + ".");
  3181. }
  3182. var ch = character.charCodeAt(0);
  3183. var metrics = fontMetricsData[font][ch];
  3184. if (!metrics && character[0] in extraCharacterMap) {
  3185. ch = extraCharacterMap[character[0]].charCodeAt(0);
  3186. metrics = fontMetricsData[font][ch];
  3187. }
  3188. if (!metrics && mode === 'text') {
  3189. // We don't typically have font metrics for Asian scripts.
  3190. // But since we support them in text mode, we need to return
  3191. // some sort of metrics.
  3192. // So if the character is in a script we support but we
  3193. // don't have metrics for it, just use the metrics for
  3194. // the Latin capital letter M. This is close enough because
  3195. // we (currently) only care about the height of the glpyh
  3196. // not its width.
  3197. if (supportedCodepoint(ch)) {
  3198. metrics = fontMetricsData[font][77]; // 77 is the charcode for 'M'
  3199. }
  3200. }
  3201. if (metrics) {
  3202. return {
  3203. depth: metrics[0],
  3204. height: metrics[1],
  3205. italic: metrics[2],
  3206. skew: metrics[3],
  3207. width: metrics[4]
  3208. };
  3209. }
  3210. }
  3211. var fontMetricsBySizeIndex = {};
  3212. /**
  3213. * Get the font metrics for a given size.
  3214. */
  3215. function getGlobalMetrics(size) {
  3216. var sizeIndex;
  3217. if (size >= 5) {
  3218. sizeIndex = 0;
  3219. } else if (size >= 3) {
  3220. sizeIndex = 1;
  3221. } else {
  3222. sizeIndex = 2;
  3223. }
  3224. if (!fontMetricsBySizeIndex[sizeIndex]) {
  3225. var metrics = fontMetricsBySizeIndex[sizeIndex] = {
  3226. cssEmPerMu: sigmasAndXis.quad[sizeIndex] / 18
  3227. };
  3228. for (var key in sigmasAndXis) {
  3229. if (sigmasAndXis.hasOwnProperty(key)) {
  3230. metrics[key] = sigmasAndXis[key][sizeIndex];
  3231. }
  3232. }
  3233. }
  3234. return fontMetricsBySizeIndex[sizeIndex];
  3235. }
  3236. /**
  3237. * This file contains information about the options that the Parser carries
  3238. * around with it while parsing. Data is held in an `Options` object, and when
  3239. * recursing, a new `Options` object can be created with the `.with*` and
  3240. * `.reset` functions.
  3241. */
  3242. var sizeStyleMap = [// Each element contains [textsize, scriptsize, scriptscriptsize].
  3243. // The size mappings are taken from TeX with \normalsize=10pt.
  3244. [1, 1, 1], // size1: [5, 5, 5] \tiny
  3245. [2, 1, 1], // size2: [6, 5, 5]
  3246. [3, 1, 1], // size3: [7, 5, 5] \scriptsize
  3247. [4, 2, 1], // size4: [8, 6, 5] \footnotesize
  3248. [5, 2, 1], // size5: [9, 6, 5] \small
  3249. [6, 3, 1], // size6: [10, 7, 5] \normalsize
  3250. [7, 4, 2], // size7: [12, 8, 6] \large
  3251. [8, 6, 3], // size8: [14.4, 10, 7] \Large
  3252. [9, 7, 6], // size9: [17.28, 12, 10] \LARGE
  3253. [10, 8, 7], // size10: [20.74, 14.4, 12] \huge
  3254. [11, 10, 9] // size11: [24.88, 20.74, 17.28] \HUGE
  3255. ];
  3256. var sizeMultipliers = [// fontMetrics.js:getGlobalMetrics also uses size indexes, so if
  3257. // you change size indexes, change that function.
  3258. 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.44, 1.728, 2.074, 2.488];
  3259. var sizeAtStyle = function sizeAtStyle(size, style) {
  3260. return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
  3261. }; // In these types, "" (empty string) means "no change".
  3262. /**
  3263. * This is the main options class. It contains the current style, size, color,
  3264. * and font.
  3265. *
  3266. * Options objects should not be modified. To create a new Options with
  3267. * different properties, call a `.having*` method.
  3268. */
  3269. class Options {
  3270. // A font family applies to a group of fonts (i.e. SansSerif), while a font
  3271. // represents a specific font (i.e. SansSerif Bold).
  3272. // See: https://tex.stackexchange.com/questions/22350/difference-between-textrm-and-mathrm
  3273. /**
  3274. * The base size index.
  3275. */
  3276. constructor(data) {
  3277. this.style = void 0;
  3278. this.color = void 0;
  3279. this.size = void 0;
  3280. this.textSize = void 0;
  3281. this.phantom = void 0;
  3282. this.font = void 0;
  3283. this.fontFamily = void 0;
  3284. this.fontWeight = void 0;
  3285. this.fontShape = void 0;
  3286. this.sizeMultiplier = void 0;
  3287. this.maxSize = void 0;
  3288. this.minRuleThickness = void 0;
  3289. this._fontMetrics = void 0;
  3290. this.style = data.style;
  3291. this.color = data.color;
  3292. this.size = data.size || Options.BASESIZE;
  3293. this.textSize = data.textSize || this.size;
  3294. this.phantom = !!data.phantom;
  3295. this.font = data.font || "";
  3296. this.fontFamily = data.fontFamily || "";
  3297. this.fontWeight = data.fontWeight || '';
  3298. this.fontShape = data.fontShape || '';
  3299. this.sizeMultiplier = sizeMultipliers[this.size - 1];
  3300. this.maxSize = data.maxSize;
  3301. this.minRuleThickness = data.minRuleThickness;
  3302. this._fontMetrics = undefined;
  3303. }
  3304. /**
  3305. * Returns a new options object with the same properties as "this". Properties
  3306. * from "extension" will be copied to the new options object.
  3307. */
  3308. extend(extension) {
  3309. var data = {
  3310. style: this.style,
  3311. size: this.size,
  3312. textSize: this.textSize,
  3313. color: this.color,
  3314. phantom: this.phantom,
  3315. font: this.font,
  3316. fontFamily: this.fontFamily,
  3317. fontWeight: this.fontWeight,
  3318. fontShape: this.fontShape,
  3319. maxSize: this.maxSize,
  3320. minRuleThickness: this.minRuleThickness
  3321. };
  3322. for (var key in extension) {
  3323. if (extension.hasOwnProperty(key)) {
  3324. data[key] = extension[key];
  3325. }
  3326. }
  3327. return new Options(data);
  3328. }
  3329. /**
  3330. * Return an options object with the given style. If `this.style === style`,
  3331. * returns `this`.
  3332. */
  3333. havingStyle(style) {
  3334. if (this.style === style) {
  3335. return this;
  3336. } else {
  3337. return this.extend({
  3338. style: style,
  3339. size: sizeAtStyle(this.textSize, style)
  3340. });
  3341. }
  3342. }
  3343. /**
  3344. * Return an options object with a cramped version of the current style. If
  3345. * the current style is cramped, returns `this`.
  3346. */
  3347. havingCrampedStyle() {
  3348. return this.havingStyle(this.style.cramp());
  3349. }
  3350. /**
  3351. * Return an options object with the given size and in at least `\textstyle`.
  3352. * Returns `this` if appropriate.
  3353. */
  3354. havingSize(size) {
  3355. if (this.size === size && this.textSize === size) {
  3356. return this;
  3357. } else {
  3358. return this.extend({
  3359. style: this.style.text(),
  3360. size: size,
  3361. textSize: size,
  3362. sizeMultiplier: sizeMultipliers[size - 1]
  3363. });
  3364. }
  3365. }
  3366. /**
  3367. * Like `this.havingSize(BASESIZE).havingStyle(style)`. If `style` is omitted,
  3368. * changes to at least `\textstyle`.
  3369. */
  3370. havingBaseStyle(style) {
  3371. style = style || this.style.text();
  3372. var wantSize = sizeAtStyle(Options.BASESIZE, style);
  3373. if (this.size === wantSize && this.textSize === Options.BASESIZE && this.style === style) {
  3374. return this;
  3375. } else {
  3376. return this.extend({
  3377. style: style,
  3378. size: wantSize
  3379. });
  3380. }
  3381. }
  3382. /**
  3383. * Remove the effect of sizing changes such as \Huge.
  3384. * Keep the effect of the current style, such as \scriptstyle.
  3385. */
  3386. havingBaseSizing() {
  3387. var size;
  3388. switch (this.style.id) {
  3389. case 4:
  3390. case 5:
  3391. size = 3; // normalsize in scriptstyle
  3392. break;
  3393. case 6:
  3394. case 7:
  3395. size = 1; // normalsize in scriptscriptstyle
  3396. break;
  3397. default:
  3398. size = 6;
  3399. // normalsize in textstyle or displaystyle
  3400. }
  3401. return this.extend({
  3402. style: this.style.text(),
  3403. size: size
  3404. });
  3405. }
  3406. /**
  3407. * Create a new options object with the given color.
  3408. */
  3409. withColor(color) {
  3410. return this.extend({
  3411. color: color
  3412. });
  3413. }
  3414. /**
  3415. * Create a new options object with "phantom" set to true.
  3416. */
  3417. withPhantom() {
  3418. return this.extend({
  3419. phantom: true
  3420. });
  3421. }
  3422. /**
  3423. * Creates a new options object with the given math font or old text font.
  3424. * @type {[type]}
  3425. */
  3426. withFont(font) {
  3427. return this.extend({
  3428. font
  3429. });
  3430. }
  3431. /**
  3432. * Create a new options objects with the given fontFamily.
  3433. */
  3434. withTextFontFamily(fontFamily) {
  3435. return this.extend({
  3436. fontFamily,
  3437. font: ""
  3438. });
  3439. }
  3440. /**
  3441. * Creates a new options object with the given font weight
  3442. */
  3443. withTextFontWeight(fontWeight) {
  3444. return this.extend({
  3445. fontWeight,
  3446. font: ""
  3447. });
  3448. }
  3449. /**
  3450. * Creates a new options object with the given font weight
  3451. */
  3452. withTextFontShape(fontShape) {
  3453. return this.extend({
  3454. fontShape,
  3455. font: ""
  3456. });
  3457. }
  3458. /**
  3459. * Return the CSS sizing classes required to switch from enclosing options
  3460. * `oldOptions` to `this`. Returns an array of classes.
  3461. */
  3462. sizingClasses(oldOptions) {
  3463. if (oldOptions.size !== this.size) {
  3464. return ["sizing", "reset-size" + oldOptions.size, "size" + this.size];
  3465. } else {
  3466. return [];
  3467. }
  3468. }
  3469. /**
  3470. * Return the CSS sizing classes required to switch to the base size. Like
  3471. * `this.havingSize(BASESIZE).sizingClasses(this)`.
  3472. */
  3473. baseSizingClasses() {
  3474. if (this.size !== Options.BASESIZE) {
  3475. return ["sizing", "reset-size" + this.size, "size" + Options.BASESIZE];
  3476. } else {
  3477. return [];
  3478. }
  3479. }
  3480. /**
  3481. * Return the font metrics for this size.
  3482. */
  3483. fontMetrics() {
  3484. if (!this._fontMetrics) {
  3485. this._fontMetrics = getGlobalMetrics(this.size);
  3486. }
  3487. return this._fontMetrics;
  3488. }
  3489. /**
  3490. * Gets the CSS color of the current options object
  3491. */
  3492. getColor() {
  3493. if (this.phantom) {
  3494. return "transparent";
  3495. } else {
  3496. return this.color;
  3497. }
  3498. }
  3499. }
  3500. Options.BASESIZE = 6;
  3501. /**
  3502. * This file does conversion between units. In particular, it provides
  3503. * calculateSize to convert other units into ems.
  3504. */
  3505. // Thus, multiplying a length by this number converts the length from units
  3506. // into pts. Dividing the result by ptPerEm gives the number of ems
  3507. // *assuming* a font size of ptPerEm (normal size, normal style).
  3508. var ptPerUnit = {
  3509. // https://en.wikibooks.org/wiki/LaTeX/Lengths and
  3510. // https://tex.stackexchange.com/a/8263
  3511. "pt": 1,
  3512. // TeX point
  3513. "mm": 7227 / 2540,
  3514. // millimeter
  3515. "cm": 7227 / 254,
  3516. // centimeter
  3517. "in": 72.27,
  3518. // inch
  3519. "bp": 803 / 800,
  3520. // big (PostScript) points
  3521. "pc": 12,
  3522. // pica
  3523. "dd": 1238 / 1157,
  3524. // didot
  3525. "cc": 14856 / 1157,
  3526. // cicero (12 didot)
  3527. "nd": 685 / 642,
  3528. // new didot
  3529. "nc": 1370 / 107,
  3530. // new cicero (12 new didot)
  3531. "sp": 1 / 65536,
  3532. // scaled point (TeX's internal smallest unit)
  3533. // https://tex.stackexchange.com/a/41371
  3534. "px": 803 / 800 // \pdfpxdimen defaults to 1 bp in pdfTeX and LuaTeX
  3535. }; // Dictionary of relative units, for fast validity testing.
  3536. var relativeUnit = {
  3537. "ex": true,
  3538. "em": true,
  3539. "mu": true
  3540. };
  3541. /**
  3542. * Determine whether the specified unit (either a string defining the unit
  3543. * or a "size" parse node containing a unit field) is valid.
  3544. */
  3545. var validUnit = function validUnit(unit) {
  3546. if (typeof unit !== "string") {
  3547. unit = unit.unit;
  3548. }
  3549. return unit in ptPerUnit || unit in relativeUnit || unit === "ex";
  3550. };
  3551. /*
  3552. * Convert a "size" parse node (with numeric "number" and string "unit" fields,
  3553. * as parsed by functions.js argType "size") into a CSS em value for the
  3554. * current style/scale. `options` gives the current options.
  3555. */
  3556. var calculateSize = function calculateSize(sizeValue, options) {
  3557. var scale;
  3558. if (sizeValue.unit in ptPerUnit) {
  3559. // Absolute units
  3560. scale = ptPerUnit[sizeValue.unit] // Convert unit to pt
  3561. / options.fontMetrics().ptPerEm // Convert pt to CSS em
  3562. / options.sizeMultiplier; // Unscale to make absolute units
  3563. } else if (sizeValue.unit === "mu") {
  3564. // `mu` units scale with scriptstyle/scriptscriptstyle.
  3565. scale = options.fontMetrics().cssEmPerMu;
  3566. } else {
  3567. // Other relative units always refer to the *textstyle* font
  3568. // in the current size.
  3569. var unitOptions;
  3570. if (options.style.isTight()) {
  3571. // isTight() means current style is script/scriptscript.
  3572. unitOptions = options.havingStyle(options.style.text());
  3573. } else {
  3574. unitOptions = options;
  3575. } // TODO: In TeX these units are relative to the quad of the current
  3576. // *text* font, e.g. cmr10. KaTeX instead uses values from the
  3577. // comparably-sized *Computer Modern symbol* font. At 10pt, these
  3578. // match. At 7pt and 5pt, they differ: cmr7=1.138894, cmsy7=1.170641;
  3579. // cmr5=1.361133, cmsy5=1.472241. Consider $\scriptsize a\kern1emb$.
  3580. // TeX \showlists shows a kern of 1.13889 * fontsize;
  3581. // KaTeX shows a kern of 1.171 * fontsize.
  3582. if (sizeValue.unit === "ex") {
  3583. scale = unitOptions.fontMetrics().xHeight;
  3584. } else if (sizeValue.unit === "em") {
  3585. scale = unitOptions.fontMetrics().quad;
  3586. } else {
  3587. throw new ParseError("Invalid unit: '" + sizeValue.unit + "'");
  3588. }
  3589. if (unitOptions !== options) {
  3590. scale *= unitOptions.sizeMultiplier / options.sizeMultiplier;
  3591. }
  3592. }
  3593. return Math.min(sizeValue.number * scale, options.maxSize);
  3594. };
  3595. /**
  3596. * Round `n` to 4 decimal places, or to the nearest 1/10,000th em. See
  3597. * https://github.com/KaTeX/KaTeX/pull/2460.
  3598. */
  3599. var makeEm = function makeEm(n) {
  3600. return +n.toFixed(4) + "em";
  3601. };
  3602. /**
  3603. * These objects store the data about the DOM nodes we create, as well as some
  3604. * extra data. They can then be transformed into real DOM nodes with the
  3605. * `toNode` function or HTML markup using `toMarkup`. They are useful for both
  3606. * storing extra properties on the nodes, as well as providing a way to easily
  3607. * work with the DOM.
  3608. *
  3609. * Similar functions for working with MathML nodes exist in mathMLTree.js.
  3610. *
  3611. * TODO: refactor `span` and `anchor` into common superclass when
  3612. * target environments support class inheritance
  3613. */
  3614. /**
  3615. * Create an HTML className based on a list of classes. In addition to joining
  3616. * with spaces, we also remove empty classes.
  3617. */
  3618. var createClass = function createClass(classes) {
  3619. return classes.filter(cls => cls).join(" ");
  3620. };
  3621. var initNode = function initNode(classes, options, style) {
  3622. this.classes = classes || [];
  3623. this.attributes = {};
  3624. this.height = 0;
  3625. this.depth = 0;
  3626. this.maxFontSize = 0;
  3627. this.style = style || {};
  3628. if (options) {
  3629. if (options.style.isTight()) {
  3630. this.classes.push("mtight");
  3631. }
  3632. var color = options.getColor();
  3633. if (color) {
  3634. this.style.color = color;
  3635. }
  3636. }
  3637. };
  3638. /**
  3639. * Convert into an HTML node
  3640. */
  3641. var toNode = function toNode(tagName) {
  3642. var node = document.createElement(tagName); // Apply the class
  3643. node.className = createClass(this.classes); // Apply inline styles
  3644. for (var style in this.style) {
  3645. if (this.style.hasOwnProperty(style)) {
  3646. // $FlowFixMe Flow doesn't seem to understand span.style's type.
  3647. node.style[style] = this.style[style];
  3648. }
  3649. } // Apply attributes
  3650. for (var attr in this.attributes) {
  3651. if (this.attributes.hasOwnProperty(attr)) {
  3652. node.setAttribute(attr, this.attributes[attr]);
  3653. }
  3654. } // Append the children, also as HTML nodes
  3655. for (var i = 0; i < this.children.length; i++) {
  3656. node.appendChild(this.children[i].toNode());
  3657. }
  3658. return node;
  3659. };
  3660. /**
  3661. * Convert into an HTML markup string
  3662. */
  3663. var toMarkup = function toMarkup(tagName) {
  3664. var markup = "<" + tagName; // Add the class
  3665. if (this.classes.length) {
  3666. markup += " class=\"" + utils.escape(createClass(this.classes)) + "\"";
  3667. }
  3668. var styles = ""; // Add the styles, after hyphenation
  3669. for (var style in this.style) {
  3670. if (this.style.hasOwnProperty(style)) {
  3671. styles += utils.hyphenate(style) + ":" + this.style[style] + ";";
  3672. }
  3673. }
  3674. if (styles) {
  3675. markup += " style=\"" + utils.escape(styles) + "\"";
  3676. } // Add the attributes
  3677. for (var attr in this.attributes) {
  3678. if (this.attributes.hasOwnProperty(attr)) {
  3679. markup += " " + attr + "=\"" + utils.escape(this.attributes[attr]) + "\"";
  3680. }
  3681. }
  3682. markup += ">"; // Add the markup of the children, also as markup
  3683. for (var i = 0; i < this.children.length; i++) {
  3684. markup += this.children[i].toMarkup();
  3685. }
  3686. markup += "</" + tagName + ">";
  3687. return markup;
  3688. }; // Making the type below exact with all optional fields doesn't work due to
  3689. // - https://github.com/facebook/flow/issues/4582
  3690. // - https://github.com/facebook/flow/issues/5688
  3691. // However, since *all* fields are optional, $Shape<> works as suggested in 5688
  3692. // above.
  3693. // This type does not include all CSS properties. Additional properties should
  3694. // be added as needed.
  3695. /**
  3696. * This node represents a span node, with a className, a list of children, and
  3697. * an inline style. It also contains information about its height, depth, and
  3698. * maxFontSize.
  3699. *
  3700. * Represents two types with different uses: SvgSpan to wrap an SVG and DomSpan
  3701. * otherwise. This typesafety is important when HTML builders access a span's
  3702. * children.
  3703. */
  3704. class Span {
  3705. constructor(classes, children, options, style) {
  3706. this.children = void 0;
  3707. this.attributes = void 0;
  3708. this.classes = void 0;
  3709. this.height = void 0;
  3710. this.depth = void 0;
  3711. this.width = void 0;
  3712. this.maxFontSize = void 0;
  3713. this.style = void 0;
  3714. initNode.call(this, classes, options, style);
  3715. this.children = children || [];
  3716. }
  3717. /**
  3718. * Sets an arbitrary attribute on the span. Warning: use this wisely. Not
  3719. * all browsers support attributes the same, and having too many custom
  3720. * attributes is probably bad.
  3721. */
  3722. setAttribute(attribute, value) {
  3723. this.attributes[attribute] = value;
  3724. }
  3725. hasClass(className) {
  3726. return utils.contains(this.classes, className);
  3727. }
  3728. toNode() {
  3729. return toNode.call(this, "span");
  3730. }
  3731. toMarkup() {
  3732. return toMarkup.call(this, "span");
  3733. }
  3734. }
  3735. /**
  3736. * This node represents an anchor (<a>) element with a hyperlink. See `span`
  3737. * for further details.
  3738. */
  3739. class Anchor {
  3740. constructor(href, classes, children, options) {
  3741. this.children = void 0;
  3742. this.attributes = void 0;
  3743. this.classes = void 0;
  3744. this.height = void 0;
  3745. this.depth = void 0;
  3746. this.maxFontSize = void 0;
  3747. this.style = void 0;
  3748. initNode.call(this, classes, options);
  3749. this.children = children || [];
  3750. this.setAttribute('href', href);
  3751. }
  3752. setAttribute(attribute, value) {
  3753. this.attributes[attribute] = value;
  3754. }
  3755. hasClass(className) {
  3756. return utils.contains(this.classes, className);
  3757. }
  3758. toNode() {
  3759. return toNode.call(this, "a");
  3760. }
  3761. toMarkup() {
  3762. return toMarkup.call(this, "a");
  3763. }
  3764. }
  3765. /**
  3766. * This node represents an image embed (<img>) element.
  3767. */
  3768. class Img {
  3769. constructor(src, alt, style) {
  3770. this.src = void 0;
  3771. this.alt = void 0;
  3772. this.classes = void 0;
  3773. this.height = void 0;
  3774. this.depth = void 0;
  3775. this.maxFontSize = void 0;
  3776. this.style = void 0;
  3777. this.alt = alt;
  3778. this.src = src;
  3779. this.classes = ["mord"];
  3780. this.style = style;
  3781. }
  3782. hasClass(className) {
  3783. return utils.contains(this.classes, className);
  3784. }
  3785. toNode() {
  3786. var node = document.createElement("img");
  3787. node.src = this.src;
  3788. node.alt = this.alt;
  3789. node.className = "mord"; // Apply inline styles
  3790. for (var style in this.style) {
  3791. if (this.style.hasOwnProperty(style)) {
  3792. // $FlowFixMe
  3793. node.style[style] = this.style[style];
  3794. }
  3795. }
  3796. return node;
  3797. }
  3798. toMarkup() {
  3799. var markup = "<img src='" + this.src + " 'alt='" + this.alt + "' "; // Add the styles, after hyphenation
  3800. var styles = "";
  3801. for (var style in this.style) {
  3802. if (this.style.hasOwnProperty(style)) {
  3803. styles += utils.hyphenate(style) + ":" + this.style[style] + ";";
  3804. }
  3805. }
  3806. if (styles) {
  3807. markup += " style=\"" + utils.escape(styles) + "\"";
  3808. }
  3809. markup += "'/>";
  3810. return markup;
  3811. }
  3812. }
  3813. var iCombinations = {
  3814. 'î': '\u0131\u0302',
  3815. 'ï': '\u0131\u0308',
  3816. 'í': '\u0131\u0301',
  3817. // 'ī': '\u0131\u0304', // enable when we add Extended Latin
  3818. 'ì': '\u0131\u0300'
  3819. };
  3820. /**
  3821. * A symbol node contains information about a single symbol. It either renders
  3822. * to a single text node, or a span with a single text node in it, depending on
  3823. * whether it has CSS classes, styles, or needs italic correction.
  3824. */
  3825. class SymbolNode {
  3826. constructor(text, height, depth, italic, skew, width, classes, style) {
  3827. this.text = void 0;
  3828. this.height = void 0;
  3829. this.depth = void 0;
  3830. this.italic = void 0;
  3831. this.skew = void 0;
  3832. this.width = void 0;
  3833. this.maxFontSize = void 0;
  3834. this.classes = void 0;
  3835. this.style = void 0;
  3836. this.text = text;
  3837. this.height = height || 0;
  3838. this.depth = depth || 0;
  3839. this.italic = italic || 0;
  3840. this.skew = skew || 0;
  3841. this.width = width || 0;
  3842. this.classes = classes || [];
  3843. this.style = style || {};
  3844. this.maxFontSize = 0; // Mark text from non-Latin scripts with specific classes so that we
  3845. // can specify which fonts to use. This allows us to render these
  3846. // characters with a serif font in situations where the browser would
  3847. // either default to a sans serif or render a placeholder character.
  3848. // We use CSS class names like cjk_fallback, hangul_fallback and
  3849. // brahmic_fallback. See ./unicodeScripts.js for the set of possible
  3850. // script names
  3851. var script = scriptFromCodepoint(this.text.charCodeAt(0));
  3852. if (script) {
  3853. this.classes.push(script + "_fallback");
  3854. }
  3855. if (/[îïíì]/.test(this.text)) {
  3856. // add ī when we add Extended Latin
  3857. this.text = iCombinations[this.text];
  3858. }
  3859. }
  3860. hasClass(className) {
  3861. return utils.contains(this.classes, className);
  3862. }
  3863. /**
  3864. * Creates a text node or span from a symbol node. Note that a span is only
  3865. * created if it is needed.
  3866. */
  3867. toNode() {
  3868. var node = document.createTextNode(this.text);
  3869. var span = null;
  3870. if (this.italic > 0) {
  3871. span = document.createElement("span");
  3872. span.style.marginRight = makeEm(this.italic);
  3873. }
  3874. if (this.classes.length > 0) {
  3875. span = span || document.createElement("span");
  3876. span.className = createClass(this.classes);
  3877. }
  3878. for (var style in this.style) {
  3879. if (this.style.hasOwnProperty(style)) {
  3880. span = span || document.createElement("span"); // $FlowFixMe Flow doesn't seem to understand span.style's type.
  3881. span.style[style] = this.style[style];
  3882. }
  3883. }
  3884. if (span) {
  3885. span.appendChild(node);
  3886. return span;
  3887. } else {
  3888. return node;
  3889. }
  3890. }
  3891. /**
  3892. * Creates markup for a symbol node.
  3893. */
  3894. toMarkup() {
  3895. // TODO(alpert): More duplication than I'd like from
  3896. // span.prototype.toMarkup and symbolNode.prototype.toNode...
  3897. var needsSpan = false;
  3898. var markup = "<span";
  3899. if (this.classes.length) {
  3900. needsSpan = true;
  3901. markup += " class=\"";
  3902. markup += utils.escape(createClass(this.classes));
  3903. markup += "\"";
  3904. }
  3905. var styles = "";
  3906. if (this.italic > 0) {
  3907. styles += "margin-right:" + this.italic + "em;";
  3908. }
  3909. for (var style in this.style) {
  3910. if (this.style.hasOwnProperty(style)) {
  3911. styles += utils.hyphenate(style) + ":" + this.style[style] + ";";
  3912. }
  3913. }
  3914. if (styles) {
  3915. needsSpan = true;
  3916. markup += " style=\"" + utils.escape(styles) + "\"";
  3917. }
  3918. var escaped = utils.escape(this.text);
  3919. if (needsSpan) {
  3920. markup += ">";
  3921. markup += escaped;
  3922. markup += "</span>";
  3923. return markup;
  3924. } else {
  3925. return escaped;
  3926. }
  3927. }
  3928. }
  3929. /**
  3930. * SVG nodes are used to render stretchy wide elements.
  3931. */
  3932. class SvgNode {
  3933. constructor(children, attributes) {
  3934. this.children = void 0;
  3935. this.attributes = void 0;
  3936. this.children = children || [];
  3937. this.attributes = attributes || {};
  3938. }
  3939. toNode() {
  3940. var svgNS = "http://www.w3.org/2000/svg";
  3941. var node = document.createElementNS(svgNS, "svg"); // Apply attributes
  3942. for (var attr in this.attributes) {
  3943. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  3944. node.setAttribute(attr, this.attributes[attr]);
  3945. }
  3946. }
  3947. for (var i = 0; i < this.children.length; i++) {
  3948. node.appendChild(this.children[i].toNode());
  3949. }
  3950. return node;
  3951. }
  3952. toMarkup() {
  3953. var markup = "<svg xmlns=\"http://www.w3.org/2000/svg\""; // Apply attributes
  3954. for (var attr in this.attributes) {
  3955. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  3956. markup += " " + attr + "='" + this.attributes[attr] + "'";
  3957. }
  3958. }
  3959. markup += ">";
  3960. for (var i = 0; i < this.children.length; i++) {
  3961. markup += this.children[i].toMarkup();
  3962. }
  3963. markup += "</svg>";
  3964. return markup;
  3965. }
  3966. }
  3967. class PathNode {
  3968. constructor(pathName, alternate) {
  3969. this.pathName = void 0;
  3970. this.alternate = void 0;
  3971. this.pathName = pathName;
  3972. this.alternate = alternate; // Used only for \sqrt, \phase, & tall delims
  3973. }
  3974. toNode() {
  3975. var svgNS = "http://www.w3.org/2000/svg";
  3976. var node = document.createElementNS(svgNS, "path");
  3977. if (this.alternate) {
  3978. node.setAttribute("d", this.alternate);
  3979. } else {
  3980. node.setAttribute("d", path[this.pathName]);
  3981. }
  3982. return node;
  3983. }
  3984. toMarkup() {
  3985. if (this.alternate) {
  3986. return "<path d='" + this.alternate + "'/>";
  3987. } else {
  3988. return "<path d='" + path[this.pathName] + "'/>";
  3989. }
  3990. }
  3991. }
  3992. class LineNode {
  3993. constructor(attributes) {
  3994. this.attributes = void 0;
  3995. this.attributes = attributes || {};
  3996. }
  3997. toNode() {
  3998. var svgNS = "http://www.w3.org/2000/svg";
  3999. var node = document.createElementNS(svgNS, "line"); // Apply attributes
  4000. for (var attr in this.attributes) {
  4001. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  4002. node.setAttribute(attr, this.attributes[attr]);
  4003. }
  4004. }
  4005. return node;
  4006. }
  4007. toMarkup() {
  4008. var markup = "<line";
  4009. for (var attr in this.attributes) {
  4010. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  4011. markup += " " + attr + "='" + this.attributes[attr] + "'";
  4012. }
  4013. }
  4014. markup += "/>";
  4015. return markup;
  4016. }
  4017. }
  4018. function assertSymbolDomNode(group) {
  4019. if (group instanceof SymbolNode) {
  4020. return group;
  4021. } else {
  4022. throw new Error("Expected symbolNode but got " + String(group) + ".");
  4023. }
  4024. }
  4025. function assertSpan(group) {
  4026. if (group instanceof Span) {
  4027. return group;
  4028. } else {
  4029. throw new Error("Expected span<HtmlDomNode> but got " + String(group) + ".");
  4030. }
  4031. }
  4032. /**
  4033. * This file holds a list of all no-argument functions and single-character
  4034. * symbols (like 'a' or ';').
  4035. *
  4036. * For each of the symbols, there are three properties they can have:
  4037. * - font (required): the font to be used for this symbol. Either "main" (the
  4038. normal font), or "ams" (the ams fonts).
  4039. * - group (required): the ParseNode group type the symbol should have (i.e.
  4040. "textord", "mathord", etc).
  4041. See https://github.com/KaTeX/KaTeX/wiki/Examining-TeX#group-types
  4042. * - replace: the character that this symbol or function should be
  4043. * replaced with (i.e. "\phi" has a replace value of "\u03d5", the phi
  4044. * character in the main font).
  4045. *
  4046. * The outermost map in the table indicates what mode the symbols should be
  4047. * accepted in (e.g. "math" or "text").
  4048. */
  4049. // Some of these have a "-token" suffix since these are also used as `ParseNode`
  4050. // types for raw text tokens, and we want to avoid conflicts with higher-level
  4051. // `ParseNode` types. These `ParseNode`s are constructed within `Parser` by
  4052. // looking up the `symbols` map.
  4053. var ATOMS = {
  4054. "bin": 1,
  4055. "close": 1,
  4056. "inner": 1,
  4057. "open": 1,
  4058. "punct": 1,
  4059. "rel": 1
  4060. };
  4061. var NON_ATOMS = {
  4062. "accent-token": 1,
  4063. "mathord": 1,
  4064. "op-token": 1,
  4065. "spacing": 1,
  4066. "textord": 1
  4067. };
  4068. var symbols = {
  4069. "math": {},
  4070. "text": {}
  4071. };
  4072. /** `acceptUnicodeChar = true` is only applicable if `replace` is set. */
  4073. function defineSymbol(mode, font, group, replace, name, acceptUnicodeChar) {
  4074. symbols[mode][name] = {
  4075. font,
  4076. group,
  4077. replace
  4078. };
  4079. if (acceptUnicodeChar && replace) {
  4080. symbols[mode][replace] = symbols[mode][name];
  4081. }
  4082. } // Some abbreviations for commonly used strings.
  4083. // This helps minify the code, and also spotting typos using jshint.
  4084. // modes:
  4085. var math = "math";
  4086. var text = "text"; // fonts:
  4087. var main = "main";
  4088. var ams = "ams"; // groups:
  4089. var accent = "accent-token";
  4090. var bin = "bin";
  4091. var close = "close";
  4092. var inner = "inner";
  4093. var mathord = "mathord";
  4094. var op = "op-token";
  4095. var open = "open";
  4096. var punct = "punct";
  4097. var rel = "rel";
  4098. var spacing = "spacing";
  4099. var textord = "textord"; // Now comes the symbol table
  4100. // Relation Symbols
  4101. defineSymbol(math, main, rel, "\u2261", "\\equiv", true);
  4102. defineSymbol(math, main, rel, "\u227a", "\\prec", true);
  4103. defineSymbol(math, main, rel, "\u227b", "\\succ", true);
  4104. defineSymbol(math, main, rel, "\u223c", "\\sim", true);
  4105. defineSymbol(math, main, rel, "\u22a5", "\\perp");
  4106. defineSymbol(math, main, rel, "\u2aaf", "\\preceq", true);
  4107. defineSymbol(math, main, rel, "\u2ab0", "\\succeq", true);
  4108. defineSymbol(math, main, rel, "\u2243", "\\simeq", true);
  4109. defineSymbol(math, main, rel, "\u2223", "\\mid", true);
  4110. defineSymbol(math, main, rel, "\u226a", "\\ll", true);
  4111. defineSymbol(math, main, rel, "\u226b", "\\gg", true);
  4112. defineSymbol(math, main, rel, "\u224d", "\\asymp", true);
  4113. defineSymbol(math, main, rel, "\u2225", "\\parallel");
  4114. defineSymbol(math, main, rel, "\u22c8", "\\bowtie", true);
  4115. defineSymbol(math, main, rel, "\u2323", "\\smile", true);
  4116. defineSymbol(math, main, rel, "\u2291", "\\sqsubseteq", true);
  4117. defineSymbol(math, main, rel, "\u2292", "\\sqsupseteq", true);
  4118. defineSymbol(math, main, rel, "\u2250", "\\doteq", true);
  4119. defineSymbol(math, main, rel, "\u2322", "\\frown", true);
  4120. defineSymbol(math, main, rel, "\u220b", "\\ni", true);
  4121. defineSymbol(math, main, rel, "\u221d", "\\propto", true);
  4122. defineSymbol(math, main, rel, "\u22a2", "\\vdash", true);
  4123. defineSymbol(math, main, rel, "\u22a3", "\\dashv", true);
  4124. defineSymbol(math, main, rel, "\u220b", "\\owns"); // Punctuation
  4125. defineSymbol(math, main, punct, "\u002e", "\\ldotp");
  4126. defineSymbol(math, main, punct, "\u22c5", "\\cdotp"); // Misc Symbols
  4127. defineSymbol(math, main, textord, "\u0023", "\\#");
  4128. defineSymbol(text, main, textord, "\u0023", "\\#");
  4129. defineSymbol(math, main, textord, "\u0026", "\\&");
  4130. defineSymbol(text, main, textord, "\u0026", "\\&");
  4131. defineSymbol(math, main, textord, "\u2135", "\\aleph", true);
  4132. defineSymbol(math, main, textord, "\u2200", "\\forall", true);
  4133. defineSymbol(math, main, textord, "\u210f", "\\hbar", true);
  4134. defineSymbol(math, main, textord, "\u2203", "\\exists", true);
  4135. defineSymbol(math, main, textord, "\u2207", "\\nabla", true);
  4136. defineSymbol(math, main, textord, "\u266d", "\\flat", true);
  4137. defineSymbol(math, main, textord, "\u2113", "\\ell", true);
  4138. defineSymbol(math, main, textord, "\u266e", "\\natural", true);
  4139. defineSymbol(math, main, textord, "\u2663", "\\clubsuit", true);
  4140. defineSymbol(math, main, textord, "\u2118", "\\wp", true);
  4141. defineSymbol(math, main, textord, "\u266f", "\\sharp", true);
  4142. defineSymbol(math, main, textord, "\u2662", "\\diamondsuit", true);
  4143. defineSymbol(math, main, textord, "\u211c", "\\Re", true);
  4144. defineSymbol(math, main, textord, "\u2661", "\\heartsuit", true);
  4145. defineSymbol(math, main, textord, "\u2111", "\\Im", true);
  4146. defineSymbol(math, main, textord, "\u2660", "\\spadesuit", true);
  4147. defineSymbol(math, main, textord, "\u00a7", "\\S", true);
  4148. defineSymbol(text, main, textord, "\u00a7", "\\S");
  4149. defineSymbol(math, main, textord, "\u00b6", "\\P", true);
  4150. defineSymbol(text, main, textord, "\u00b6", "\\P"); // Math and Text
  4151. defineSymbol(math, main, textord, "\u2020", "\\dag");
  4152. defineSymbol(text, main, textord, "\u2020", "\\dag");
  4153. defineSymbol(text, main, textord, "\u2020", "\\textdagger");
  4154. defineSymbol(math, main, textord, "\u2021", "\\ddag");
  4155. defineSymbol(text, main, textord, "\u2021", "\\ddag");
  4156. defineSymbol(text, main, textord, "\u2021", "\\textdaggerdbl"); // Large Delimiters
  4157. defineSymbol(math, main, close, "\u23b1", "\\rmoustache", true);
  4158. defineSymbol(math, main, open, "\u23b0", "\\lmoustache", true);
  4159. defineSymbol(math, main, close, "\u27ef", "\\rgroup", true);
  4160. defineSymbol(math, main, open, "\u27ee", "\\lgroup", true); // Binary Operators
  4161. defineSymbol(math, main, bin, "\u2213", "\\mp", true);
  4162. defineSymbol(math, main, bin, "\u2296", "\\ominus", true);
  4163. defineSymbol(math, main, bin, "\u228e", "\\uplus", true);
  4164. defineSymbol(math, main, bin, "\u2293", "\\sqcap", true);
  4165. defineSymbol(math, main, bin, "\u2217", "\\ast");
  4166. defineSymbol(math, main, bin, "\u2294", "\\sqcup", true);
  4167. defineSymbol(math, main, bin, "\u25ef", "\\bigcirc", true);
  4168. defineSymbol(math, main, bin, "\u2219", "\\bullet", true);
  4169. defineSymbol(math, main, bin, "\u2021", "\\ddagger");
  4170. defineSymbol(math, main, bin, "\u2240", "\\wr", true);
  4171. defineSymbol(math, main, bin, "\u2a3f", "\\amalg");
  4172. defineSymbol(math, main, bin, "\u0026", "\\And"); // from amsmath
  4173. // Arrow Symbols
  4174. defineSymbol(math, main, rel, "\u27f5", "\\longleftarrow", true);
  4175. defineSymbol(math, main, rel, "\u21d0", "\\Leftarrow", true);
  4176. defineSymbol(math, main, rel, "\u27f8", "\\Longleftarrow", true);
  4177. defineSymbol(math, main, rel, "\u27f6", "\\longrightarrow", true);
  4178. defineSymbol(math, main, rel, "\u21d2", "\\Rightarrow", true);
  4179. defineSymbol(math, main, rel, "\u27f9", "\\Longrightarrow", true);
  4180. defineSymbol(math, main, rel, "\u2194", "\\leftrightarrow", true);
  4181. defineSymbol(math, main, rel, "\u27f7", "\\longleftrightarrow", true);
  4182. defineSymbol(math, main, rel, "\u21d4", "\\Leftrightarrow", true);
  4183. defineSymbol(math, main, rel, "\u27fa", "\\Longleftrightarrow", true);
  4184. defineSymbol(math, main, rel, "\u21a6", "\\mapsto", true);
  4185. defineSymbol(math, main, rel, "\u27fc", "\\longmapsto", true);
  4186. defineSymbol(math, main, rel, "\u2197", "\\nearrow", true);
  4187. defineSymbol(math, main, rel, "\u21a9", "\\hookleftarrow", true);
  4188. defineSymbol(math, main, rel, "\u21aa", "\\hookrightarrow", true);
  4189. defineSymbol(math, main, rel, "\u2198", "\\searrow", true);
  4190. defineSymbol(math, main, rel, "\u21bc", "\\leftharpoonup", true);
  4191. defineSymbol(math, main, rel, "\u21c0", "\\rightharpoonup", true);
  4192. defineSymbol(math, main, rel, "\u2199", "\\swarrow", true);
  4193. defineSymbol(math, main, rel, "\u21bd", "\\leftharpoondown", true);
  4194. defineSymbol(math, main, rel, "\u21c1", "\\rightharpoondown", true);
  4195. defineSymbol(math, main, rel, "\u2196", "\\nwarrow", true);
  4196. defineSymbol(math, main, rel, "\u21cc", "\\rightleftharpoons", true); // AMS Negated Binary Relations
  4197. defineSymbol(math, ams, rel, "\u226e", "\\nless", true); // Symbol names preceeded by "@" each have a corresponding macro.
  4198. defineSymbol(math, ams, rel, "\ue010", "\\@nleqslant");
  4199. defineSymbol(math, ams, rel, "\ue011", "\\@nleqq");
  4200. defineSymbol(math, ams, rel, "\u2a87", "\\lneq", true);
  4201. defineSymbol(math, ams, rel, "\u2268", "\\lneqq", true);
  4202. defineSymbol(math, ams, rel, "\ue00c", "\\@lvertneqq");
  4203. defineSymbol(math, ams, rel, "\u22e6", "\\lnsim", true);
  4204. defineSymbol(math, ams, rel, "\u2a89", "\\lnapprox", true);
  4205. defineSymbol(math, ams, rel, "\u2280", "\\nprec", true); // unicode-math maps \u22e0 to \npreccurlyeq. We'll use the AMS synonym.
  4206. defineSymbol(math, ams, rel, "\u22e0", "\\npreceq", true);
  4207. defineSymbol(math, ams, rel, "\u22e8", "\\precnsim", true);
  4208. defineSymbol(math, ams, rel, "\u2ab9", "\\precnapprox", true);
  4209. defineSymbol(math, ams, rel, "\u2241", "\\nsim", true);
  4210. defineSymbol(math, ams, rel, "\ue006", "\\@nshortmid");
  4211. defineSymbol(math, ams, rel, "\u2224", "\\nmid", true);
  4212. defineSymbol(math, ams, rel, "\u22ac", "\\nvdash", true);
  4213. defineSymbol(math, ams, rel, "\u22ad", "\\nvDash", true);
  4214. defineSymbol(math, ams, rel, "\u22ea", "\\ntriangleleft");
  4215. defineSymbol(math, ams, rel, "\u22ec", "\\ntrianglelefteq", true);
  4216. defineSymbol(math, ams, rel, "\u228a", "\\subsetneq", true);
  4217. defineSymbol(math, ams, rel, "\ue01a", "\\@varsubsetneq");
  4218. defineSymbol(math, ams, rel, "\u2acb", "\\subsetneqq", true);
  4219. defineSymbol(math, ams, rel, "\ue017", "\\@varsubsetneqq");
  4220. defineSymbol(math, ams, rel, "\u226f", "\\ngtr", true);
  4221. defineSymbol(math, ams, rel, "\ue00f", "\\@ngeqslant");
  4222. defineSymbol(math, ams, rel, "\ue00e", "\\@ngeqq");
  4223. defineSymbol(math, ams, rel, "\u2a88", "\\gneq", true);
  4224. defineSymbol(math, ams, rel, "\u2269", "\\gneqq", true);
  4225. defineSymbol(math, ams, rel, "\ue00d", "\\@gvertneqq");
  4226. defineSymbol(math, ams, rel, "\u22e7", "\\gnsim", true);
  4227. defineSymbol(math, ams, rel, "\u2a8a", "\\gnapprox", true);
  4228. defineSymbol(math, ams, rel, "\u2281", "\\nsucc", true); // unicode-math maps \u22e1 to \nsucccurlyeq. We'll use the AMS synonym.
  4229. defineSymbol(math, ams, rel, "\u22e1", "\\nsucceq", true);
  4230. defineSymbol(math, ams, rel, "\u22e9", "\\succnsim", true);
  4231. defineSymbol(math, ams, rel, "\u2aba", "\\succnapprox", true); // unicode-math maps \u2246 to \simneqq. We'll use the AMS synonym.
  4232. defineSymbol(math, ams, rel, "\u2246", "\\ncong", true);
  4233. defineSymbol(math, ams, rel, "\ue007", "\\@nshortparallel");
  4234. defineSymbol(math, ams, rel, "\u2226", "\\nparallel", true);
  4235. defineSymbol(math, ams, rel, "\u22af", "\\nVDash", true);
  4236. defineSymbol(math, ams, rel, "\u22eb", "\\ntriangleright");
  4237. defineSymbol(math, ams, rel, "\u22ed", "\\ntrianglerighteq", true);
  4238. defineSymbol(math, ams, rel, "\ue018", "\\@nsupseteqq");
  4239. defineSymbol(math, ams, rel, "\u228b", "\\supsetneq", true);
  4240. defineSymbol(math, ams, rel, "\ue01b", "\\@varsupsetneq");
  4241. defineSymbol(math, ams, rel, "\u2acc", "\\supsetneqq", true);
  4242. defineSymbol(math, ams, rel, "\ue019", "\\@varsupsetneqq");
  4243. defineSymbol(math, ams, rel, "\u22ae", "\\nVdash", true);
  4244. defineSymbol(math, ams, rel, "\u2ab5", "\\precneqq", true);
  4245. defineSymbol(math, ams, rel, "\u2ab6", "\\succneqq", true);
  4246. defineSymbol(math, ams, rel, "\ue016", "\\@nsubseteqq");
  4247. defineSymbol(math, ams, bin, "\u22b4", "\\unlhd");
  4248. defineSymbol(math, ams, bin, "\u22b5", "\\unrhd"); // AMS Negated Arrows
  4249. defineSymbol(math, ams, rel, "\u219a", "\\nleftarrow", true);
  4250. defineSymbol(math, ams, rel, "\u219b", "\\nrightarrow", true);
  4251. defineSymbol(math, ams, rel, "\u21cd", "\\nLeftarrow", true);
  4252. defineSymbol(math, ams, rel, "\u21cf", "\\nRightarrow", true);
  4253. defineSymbol(math, ams, rel, "\u21ae", "\\nleftrightarrow", true);
  4254. defineSymbol(math, ams, rel, "\u21ce", "\\nLeftrightarrow", true); // AMS Misc
  4255. defineSymbol(math, ams, rel, "\u25b3", "\\vartriangle");
  4256. defineSymbol(math, ams, textord, "\u210f", "\\hslash");
  4257. defineSymbol(math, ams, textord, "\u25bd", "\\triangledown");
  4258. defineSymbol(math, ams, textord, "\u25ca", "\\lozenge");
  4259. defineSymbol(math, ams, textord, "\u24c8", "\\circledS");
  4260. defineSymbol(math, ams, textord, "\u00ae", "\\circledR");
  4261. defineSymbol(text, ams, textord, "\u00ae", "\\circledR");
  4262. defineSymbol(math, ams, textord, "\u2221", "\\measuredangle", true);
  4263. defineSymbol(math, ams, textord, "\u2204", "\\nexists");
  4264. defineSymbol(math, ams, textord, "\u2127", "\\mho");
  4265. defineSymbol(math, ams, textord, "\u2132", "\\Finv", true);
  4266. defineSymbol(math, ams, textord, "\u2141", "\\Game", true);
  4267. defineSymbol(math, ams, textord, "\u2035", "\\backprime");
  4268. defineSymbol(math, ams, textord, "\u25b2", "\\blacktriangle");
  4269. defineSymbol(math, ams, textord, "\u25bc", "\\blacktriangledown");
  4270. defineSymbol(math, ams, textord, "\u25a0", "\\blacksquare");
  4271. defineSymbol(math, ams, textord, "\u29eb", "\\blacklozenge");
  4272. defineSymbol(math, ams, textord, "\u2605", "\\bigstar");
  4273. defineSymbol(math, ams, textord, "\u2222", "\\sphericalangle", true);
  4274. defineSymbol(math, ams, textord, "\u2201", "\\complement", true); // unicode-math maps U+F0 to \matheth. We map to AMS function \eth
  4275. defineSymbol(math, ams, textord, "\u00f0", "\\eth", true);
  4276. defineSymbol(text, main, textord, "\u00f0", "\u00f0");
  4277. defineSymbol(math, ams, textord, "\u2571", "\\diagup");
  4278. defineSymbol(math, ams, textord, "\u2572", "\\diagdown");
  4279. defineSymbol(math, ams, textord, "\u25a1", "\\square");
  4280. defineSymbol(math, ams, textord, "\u25a1", "\\Box");
  4281. defineSymbol(math, ams, textord, "\u25ca", "\\Diamond"); // unicode-math maps U+A5 to \mathyen. We map to AMS function \yen
  4282. defineSymbol(math, ams, textord, "\u00a5", "\\yen", true);
  4283. defineSymbol(text, ams, textord, "\u00a5", "\\yen", true);
  4284. defineSymbol(math, ams, textord, "\u2713", "\\checkmark", true);
  4285. defineSymbol(text, ams, textord, "\u2713", "\\checkmark"); // AMS Hebrew
  4286. defineSymbol(math, ams, textord, "\u2136", "\\beth", true);
  4287. defineSymbol(math, ams, textord, "\u2138", "\\daleth", true);
  4288. defineSymbol(math, ams, textord, "\u2137", "\\gimel", true); // AMS Greek
  4289. defineSymbol(math, ams, textord, "\u03dd", "\\digamma", true);
  4290. defineSymbol(math, ams, textord, "\u03f0", "\\varkappa"); // AMS Delimiters
  4291. defineSymbol(math, ams, open, "\u250c", "\\@ulcorner", true);
  4292. defineSymbol(math, ams, close, "\u2510", "\\@urcorner", true);
  4293. defineSymbol(math, ams, open, "\u2514", "\\@llcorner", true);
  4294. defineSymbol(math, ams, close, "\u2518", "\\@lrcorner", true); // AMS Binary Relations
  4295. defineSymbol(math, ams, rel, "\u2266", "\\leqq", true);
  4296. defineSymbol(math, ams, rel, "\u2a7d", "\\leqslant", true);
  4297. defineSymbol(math, ams, rel, "\u2a95", "\\eqslantless", true);
  4298. defineSymbol(math, ams, rel, "\u2272", "\\lesssim", true);
  4299. defineSymbol(math, ams, rel, "\u2a85", "\\lessapprox", true);
  4300. defineSymbol(math, ams, rel, "\u224a", "\\approxeq", true);
  4301. defineSymbol(math, ams, bin, "\u22d6", "\\lessdot");
  4302. defineSymbol(math, ams, rel, "\u22d8", "\\lll", true);
  4303. defineSymbol(math, ams, rel, "\u2276", "\\lessgtr", true);
  4304. defineSymbol(math, ams, rel, "\u22da", "\\lesseqgtr", true);
  4305. defineSymbol(math, ams, rel, "\u2a8b", "\\lesseqqgtr", true);
  4306. defineSymbol(math, ams, rel, "\u2251", "\\doteqdot");
  4307. defineSymbol(math, ams, rel, "\u2253", "\\risingdotseq", true);
  4308. defineSymbol(math, ams, rel, "\u2252", "\\fallingdotseq", true);
  4309. defineSymbol(math, ams, rel, "\u223d", "\\backsim", true);
  4310. defineSymbol(math, ams, rel, "\u22cd", "\\backsimeq", true);
  4311. defineSymbol(math, ams, rel, "\u2ac5", "\\subseteqq", true);
  4312. defineSymbol(math, ams, rel, "\u22d0", "\\Subset", true);
  4313. defineSymbol(math, ams, rel, "\u228f", "\\sqsubset", true);
  4314. defineSymbol(math, ams, rel, "\u227c", "\\preccurlyeq", true);
  4315. defineSymbol(math, ams, rel, "\u22de", "\\curlyeqprec", true);
  4316. defineSymbol(math, ams, rel, "\u227e", "\\precsim", true);
  4317. defineSymbol(math, ams, rel, "\u2ab7", "\\precapprox", true);
  4318. defineSymbol(math, ams, rel, "\u22b2", "\\vartriangleleft");
  4319. defineSymbol(math, ams, rel, "\u22b4", "\\trianglelefteq");
  4320. defineSymbol(math, ams, rel, "\u22a8", "\\vDash", true);
  4321. defineSymbol(math, ams, rel, "\u22aa", "\\Vvdash", true);
  4322. defineSymbol(math, ams, rel, "\u2323", "\\smallsmile");
  4323. defineSymbol(math, ams, rel, "\u2322", "\\smallfrown");
  4324. defineSymbol(math, ams, rel, "\u224f", "\\bumpeq", true);
  4325. defineSymbol(math, ams, rel, "\u224e", "\\Bumpeq", true);
  4326. defineSymbol(math, ams, rel, "\u2267", "\\geqq", true);
  4327. defineSymbol(math, ams, rel, "\u2a7e", "\\geqslant", true);
  4328. defineSymbol(math, ams, rel, "\u2a96", "\\eqslantgtr", true);
  4329. defineSymbol(math, ams, rel, "\u2273", "\\gtrsim", true);
  4330. defineSymbol(math, ams, rel, "\u2a86", "\\gtrapprox", true);
  4331. defineSymbol(math, ams, bin, "\u22d7", "\\gtrdot");
  4332. defineSymbol(math, ams, rel, "\u22d9", "\\ggg", true);
  4333. defineSymbol(math, ams, rel, "\u2277", "\\gtrless", true);
  4334. defineSymbol(math, ams, rel, "\u22db", "\\gtreqless", true);
  4335. defineSymbol(math, ams, rel, "\u2a8c", "\\gtreqqless", true);
  4336. defineSymbol(math, ams, rel, "\u2256", "\\eqcirc", true);
  4337. defineSymbol(math, ams, rel, "\u2257", "\\circeq", true);
  4338. defineSymbol(math, ams, rel, "\u225c", "\\triangleq", true);
  4339. defineSymbol(math, ams, rel, "\u223c", "\\thicksim");
  4340. defineSymbol(math, ams, rel, "\u2248", "\\thickapprox");
  4341. defineSymbol(math, ams, rel, "\u2ac6", "\\supseteqq", true);
  4342. defineSymbol(math, ams, rel, "\u22d1", "\\Supset", true);
  4343. defineSymbol(math, ams, rel, "\u2290", "\\sqsupset", true);
  4344. defineSymbol(math, ams, rel, "\u227d", "\\succcurlyeq", true);
  4345. defineSymbol(math, ams, rel, "\u22df", "\\curlyeqsucc", true);
  4346. defineSymbol(math, ams, rel, "\u227f", "\\succsim", true);
  4347. defineSymbol(math, ams, rel, "\u2ab8", "\\succapprox", true);
  4348. defineSymbol(math, ams, rel, "\u22b3", "\\vartriangleright");
  4349. defineSymbol(math, ams, rel, "\u22b5", "\\trianglerighteq");
  4350. defineSymbol(math, ams, rel, "\u22a9", "\\Vdash", true);
  4351. defineSymbol(math, ams, rel, "\u2223", "\\shortmid");
  4352. defineSymbol(math, ams, rel, "\u2225", "\\shortparallel");
  4353. defineSymbol(math, ams, rel, "\u226c", "\\between", true);
  4354. defineSymbol(math, ams, rel, "\u22d4", "\\pitchfork", true);
  4355. defineSymbol(math, ams, rel, "\u221d", "\\varpropto");
  4356. defineSymbol(math, ams, rel, "\u25c0", "\\blacktriangleleft"); // unicode-math says that \therefore is a mathord atom.
  4357. // We kept the amssymb atom type, which is rel.
  4358. defineSymbol(math, ams, rel, "\u2234", "\\therefore", true);
  4359. defineSymbol(math, ams, rel, "\u220d", "\\backepsilon");
  4360. defineSymbol(math, ams, rel, "\u25b6", "\\blacktriangleright"); // unicode-math says that \because is a mathord atom.
  4361. // We kept the amssymb atom type, which is rel.
  4362. defineSymbol(math, ams, rel, "\u2235", "\\because", true);
  4363. defineSymbol(math, ams, rel, "\u22d8", "\\llless");
  4364. defineSymbol(math, ams, rel, "\u22d9", "\\gggtr");
  4365. defineSymbol(math, ams, bin, "\u22b2", "\\lhd");
  4366. defineSymbol(math, ams, bin, "\u22b3", "\\rhd");
  4367. defineSymbol(math, ams, rel, "\u2242", "\\eqsim", true);
  4368. defineSymbol(math, main, rel, "\u22c8", "\\Join");
  4369. defineSymbol(math, ams, rel, "\u2251", "\\Doteq", true); // AMS Binary Operators
  4370. defineSymbol(math, ams, bin, "\u2214", "\\dotplus", true);
  4371. defineSymbol(math, ams, bin, "\u2216", "\\smallsetminus");
  4372. defineSymbol(math, ams, bin, "\u22d2", "\\Cap", true);
  4373. defineSymbol(math, ams, bin, "\u22d3", "\\Cup", true);
  4374. defineSymbol(math, ams, bin, "\u2a5e", "\\doublebarwedge", true);
  4375. defineSymbol(math, ams, bin, "\u229f", "\\boxminus", true);
  4376. defineSymbol(math, ams, bin, "\u229e", "\\boxplus", true);
  4377. defineSymbol(math, ams, bin, "\u22c7", "\\divideontimes", true);
  4378. defineSymbol(math, ams, bin, "\u22c9", "\\ltimes", true);
  4379. defineSymbol(math, ams, bin, "\u22ca", "\\rtimes", true);
  4380. defineSymbol(math, ams, bin, "\u22cb", "\\leftthreetimes", true);
  4381. defineSymbol(math, ams, bin, "\u22cc", "\\rightthreetimes", true);
  4382. defineSymbol(math, ams, bin, "\u22cf", "\\curlywedge", true);
  4383. defineSymbol(math, ams, bin, "\u22ce", "\\curlyvee", true);
  4384. defineSymbol(math, ams, bin, "\u229d", "\\circleddash", true);
  4385. defineSymbol(math, ams, bin, "\u229b", "\\circledast", true);
  4386. defineSymbol(math, ams, bin, "\u22c5", "\\centerdot");
  4387. defineSymbol(math, ams, bin, "\u22ba", "\\intercal", true);
  4388. defineSymbol(math, ams, bin, "\u22d2", "\\doublecap");
  4389. defineSymbol(math, ams, bin, "\u22d3", "\\doublecup");
  4390. defineSymbol(math, ams, bin, "\u22a0", "\\boxtimes", true); // AMS Arrows
  4391. // Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
  4392. // We'll map it to AMS function \dashrightarrow. It produces the same atom.
  4393. defineSymbol(math, ams, rel, "\u21e2", "\\dashrightarrow", true); // unicode-math maps \u21e0 to \leftdasharrow. We'll use the AMS synonym.
  4394. defineSymbol(math, ams, rel, "\u21e0", "\\dashleftarrow", true);
  4395. defineSymbol(math, ams, rel, "\u21c7", "\\leftleftarrows", true);
  4396. defineSymbol(math, ams, rel, "\u21c6", "\\leftrightarrows", true);
  4397. defineSymbol(math, ams, rel, "\u21da", "\\Lleftarrow", true);
  4398. defineSymbol(math, ams, rel, "\u219e", "\\twoheadleftarrow", true);
  4399. defineSymbol(math, ams, rel, "\u21a2", "\\leftarrowtail", true);
  4400. defineSymbol(math, ams, rel, "\u21ab", "\\looparrowleft", true);
  4401. defineSymbol(math, ams, rel, "\u21cb", "\\leftrightharpoons", true);
  4402. defineSymbol(math, ams, rel, "\u21b6", "\\curvearrowleft", true); // unicode-math maps \u21ba to \acwopencirclearrow. We'll use the AMS synonym.
  4403. defineSymbol(math, ams, rel, "\u21ba", "\\circlearrowleft", true);
  4404. defineSymbol(math, ams, rel, "\u21b0", "\\Lsh", true);
  4405. defineSymbol(math, ams, rel, "\u21c8", "\\upuparrows", true);
  4406. defineSymbol(math, ams, rel, "\u21bf", "\\upharpoonleft", true);
  4407. defineSymbol(math, ams, rel, "\u21c3", "\\downharpoonleft", true);
  4408. defineSymbol(math, main, rel, "\u22b6", "\\origof", true); // not in font
  4409. defineSymbol(math, main, rel, "\u22b7", "\\imageof", true); // not in font
  4410. defineSymbol(math, ams, rel, "\u22b8", "\\multimap", true);
  4411. defineSymbol(math, ams, rel, "\u21ad", "\\leftrightsquigarrow", true);
  4412. defineSymbol(math, ams, rel, "\u21c9", "\\rightrightarrows", true);
  4413. defineSymbol(math, ams, rel, "\u21c4", "\\rightleftarrows", true);
  4414. defineSymbol(math, ams, rel, "\u21a0", "\\twoheadrightarrow", true);
  4415. defineSymbol(math, ams, rel, "\u21a3", "\\rightarrowtail", true);
  4416. defineSymbol(math, ams, rel, "\u21ac", "\\looparrowright", true);
  4417. defineSymbol(math, ams, rel, "\u21b7", "\\curvearrowright", true); // unicode-math maps \u21bb to \cwopencirclearrow. We'll use the AMS synonym.
  4418. defineSymbol(math, ams, rel, "\u21bb", "\\circlearrowright", true);
  4419. defineSymbol(math, ams, rel, "\u21b1", "\\Rsh", true);
  4420. defineSymbol(math, ams, rel, "\u21ca", "\\downdownarrows", true);
  4421. defineSymbol(math, ams, rel, "\u21be", "\\upharpoonright", true);
  4422. defineSymbol(math, ams, rel, "\u21c2", "\\downharpoonright", true);
  4423. defineSymbol(math, ams, rel, "\u21dd", "\\rightsquigarrow", true);
  4424. defineSymbol(math, ams, rel, "\u21dd", "\\leadsto");
  4425. defineSymbol(math, ams, rel, "\u21db", "\\Rrightarrow", true);
  4426. defineSymbol(math, ams, rel, "\u21be", "\\restriction");
  4427. defineSymbol(math, main, textord, "\u2018", "`");
  4428. defineSymbol(math, main, textord, "$", "\\$");
  4429. defineSymbol(text, main, textord, "$", "\\$");
  4430. defineSymbol(text, main, textord, "$", "\\textdollar");
  4431. defineSymbol(math, main, textord, "%", "\\%");
  4432. defineSymbol(text, main, textord, "%", "\\%");
  4433. defineSymbol(math, main, textord, "_", "\\_");
  4434. defineSymbol(text, main, textord, "_", "\\_");
  4435. defineSymbol(text, main, textord, "_", "\\textunderscore");
  4436. defineSymbol(math, main, textord, "\u2220", "\\angle", true);
  4437. defineSymbol(math, main, textord, "\u221e", "\\infty", true);
  4438. defineSymbol(math, main, textord, "\u2032", "\\prime");
  4439. defineSymbol(math, main, textord, "\u25b3", "\\triangle");
  4440. defineSymbol(math, main, textord, "\u0393", "\\Gamma", true);
  4441. defineSymbol(math, main, textord, "\u0394", "\\Delta", true);
  4442. defineSymbol(math, main, textord, "\u0398", "\\Theta", true);
  4443. defineSymbol(math, main, textord, "\u039b", "\\Lambda", true);
  4444. defineSymbol(math, main, textord, "\u039e", "\\Xi", true);
  4445. defineSymbol(math, main, textord, "\u03a0", "\\Pi", true);
  4446. defineSymbol(math, main, textord, "\u03a3", "\\Sigma", true);
  4447. defineSymbol(math, main, textord, "\u03a5", "\\Upsilon", true);
  4448. defineSymbol(math, main, textord, "\u03a6", "\\Phi", true);
  4449. defineSymbol(math, main, textord, "\u03a8", "\\Psi", true);
  4450. defineSymbol(math, main, textord, "\u03a9", "\\Omega", true);
  4451. defineSymbol(math, main, textord, "A", "\u0391");
  4452. defineSymbol(math, main, textord, "B", "\u0392");
  4453. defineSymbol(math, main, textord, "E", "\u0395");
  4454. defineSymbol(math, main, textord, "Z", "\u0396");
  4455. defineSymbol(math, main, textord, "H", "\u0397");
  4456. defineSymbol(math, main, textord, "I", "\u0399");
  4457. defineSymbol(math, main, textord, "K", "\u039A");
  4458. defineSymbol(math, main, textord, "M", "\u039C");
  4459. defineSymbol(math, main, textord, "N", "\u039D");
  4460. defineSymbol(math, main, textord, "O", "\u039F");
  4461. defineSymbol(math, main, textord, "P", "\u03A1");
  4462. defineSymbol(math, main, textord, "T", "\u03A4");
  4463. defineSymbol(math, main, textord, "X", "\u03A7");
  4464. defineSymbol(math, main, textord, "\u00ac", "\\neg", true);
  4465. defineSymbol(math, main, textord, "\u00ac", "\\lnot");
  4466. defineSymbol(math, main, textord, "\u22a4", "\\top");
  4467. defineSymbol(math, main, textord, "\u22a5", "\\bot");
  4468. defineSymbol(math, main, textord, "\u2205", "\\emptyset");
  4469. defineSymbol(math, ams, textord, "\u2205", "\\varnothing");
  4470. defineSymbol(math, main, mathord, "\u03b1", "\\alpha", true);
  4471. defineSymbol(math, main, mathord, "\u03b2", "\\beta", true);
  4472. defineSymbol(math, main, mathord, "\u03b3", "\\gamma", true);
  4473. defineSymbol(math, main, mathord, "\u03b4", "\\delta", true);
  4474. defineSymbol(math, main, mathord, "\u03f5", "\\epsilon", true);
  4475. defineSymbol(math, main, mathord, "\u03b6", "\\zeta", true);
  4476. defineSymbol(math, main, mathord, "\u03b7", "\\eta", true);
  4477. defineSymbol(math, main, mathord, "\u03b8", "\\theta", true);
  4478. defineSymbol(math, main, mathord, "\u03b9", "\\iota", true);
  4479. defineSymbol(math, main, mathord, "\u03ba", "\\kappa", true);
  4480. defineSymbol(math, main, mathord, "\u03bb", "\\lambda", true);
  4481. defineSymbol(math, main, mathord, "\u03bc", "\\mu", true);
  4482. defineSymbol(math, main, mathord, "\u03bd", "\\nu", true);
  4483. defineSymbol(math, main, mathord, "\u03be", "\\xi", true);
  4484. defineSymbol(math, main, mathord, "\u03bf", "\\omicron", true);
  4485. defineSymbol(math, main, mathord, "\u03c0", "\\pi", true);
  4486. defineSymbol(math, main, mathord, "\u03c1", "\\rho", true);
  4487. defineSymbol(math, main, mathord, "\u03c3", "\\sigma", true);
  4488. defineSymbol(math, main, mathord, "\u03c4", "\\tau", true);
  4489. defineSymbol(math, main, mathord, "\u03c5", "\\upsilon", true);
  4490. defineSymbol(math, main, mathord, "\u03d5", "\\phi", true);
  4491. defineSymbol(math, main, mathord, "\u03c7", "\\chi", true);
  4492. defineSymbol(math, main, mathord, "\u03c8", "\\psi", true);
  4493. defineSymbol(math, main, mathord, "\u03c9", "\\omega", true);
  4494. defineSymbol(math, main, mathord, "\u03b5", "\\varepsilon", true);
  4495. defineSymbol(math, main, mathord, "\u03d1", "\\vartheta", true);
  4496. defineSymbol(math, main, mathord, "\u03d6", "\\varpi", true);
  4497. defineSymbol(math, main, mathord, "\u03f1", "\\varrho", true);
  4498. defineSymbol(math, main, mathord, "\u03c2", "\\varsigma", true);
  4499. defineSymbol(math, main, mathord, "\u03c6", "\\varphi", true);
  4500. defineSymbol(math, main, bin, "\u2217", "*", true);
  4501. defineSymbol(math, main, bin, "+", "+");
  4502. defineSymbol(math, main, bin, "\u2212", "-", true);
  4503. defineSymbol(math, main, bin, "\u22c5", "\\cdot", true);
  4504. defineSymbol(math, main, bin, "\u2218", "\\circ", true);
  4505. defineSymbol(math, main, bin, "\u00f7", "\\div", true);
  4506. defineSymbol(math, main, bin, "\u00b1", "\\pm", true);
  4507. defineSymbol(math, main, bin, "\u00d7", "\\times", true);
  4508. defineSymbol(math, main, bin, "\u2229", "\\cap", true);
  4509. defineSymbol(math, main, bin, "\u222a", "\\cup", true);
  4510. defineSymbol(math, main, bin, "\u2216", "\\setminus", true);
  4511. defineSymbol(math, main, bin, "\u2227", "\\land");
  4512. defineSymbol(math, main, bin, "\u2228", "\\lor");
  4513. defineSymbol(math, main, bin, "\u2227", "\\wedge", true);
  4514. defineSymbol(math, main, bin, "\u2228", "\\vee", true);
  4515. defineSymbol(math, main, textord, "\u221a", "\\surd");
  4516. defineSymbol(math, main, open, "\u27e8", "\\langle", true);
  4517. defineSymbol(math, main, open, "\u2223", "\\lvert");
  4518. defineSymbol(math, main, open, "\u2225", "\\lVert");
  4519. defineSymbol(math, main, close, "?", "?");
  4520. defineSymbol(math, main, close, "!", "!");
  4521. defineSymbol(math, main, close, "\u27e9", "\\rangle", true);
  4522. defineSymbol(math, main, close, "\u2223", "\\rvert");
  4523. defineSymbol(math, main, close, "\u2225", "\\rVert");
  4524. defineSymbol(math, main, rel, "=", "=");
  4525. defineSymbol(math, main, rel, ":", ":");
  4526. defineSymbol(math, main, rel, "\u2248", "\\approx", true);
  4527. defineSymbol(math, main, rel, "\u2245", "\\cong", true);
  4528. defineSymbol(math, main, rel, "\u2265", "\\ge");
  4529. defineSymbol(math, main, rel, "\u2265", "\\geq", true);
  4530. defineSymbol(math, main, rel, "\u2190", "\\gets");
  4531. defineSymbol(math, main, rel, ">", "\\gt", true);
  4532. defineSymbol(math, main, rel, "\u2208", "\\in", true);
  4533. defineSymbol(math, main, rel, "\ue020", "\\@not");
  4534. defineSymbol(math, main, rel, "\u2282", "\\subset", true);
  4535. defineSymbol(math, main, rel, "\u2283", "\\supset", true);
  4536. defineSymbol(math, main, rel, "\u2286", "\\subseteq", true);
  4537. defineSymbol(math, main, rel, "\u2287", "\\supseteq", true);
  4538. defineSymbol(math, ams, rel, "\u2288", "\\nsubseteq", true);
  4539. defineSymbol(math, ams, rel, "\u2289", "\\nsupseteq", true);
  4540. defineSymbol(math, main, rel, "\u22a8", "\\models");
  4541. defineSymbol(math, main, rel, "\u2190", "\\leftarrow", true);
  4542. defineSymbol(math, main, rel, "\u2264", "\\le");
  4543. defineSymbol(math, main, rel, "\u2264", "\\leq", true);
  4544. defineSymbol(math, main, rel, "<", "\\lt", true);
  4545. defineSymbol(math, main, rel, "\u2192", "\\rightarrow", true);
  4546. defineSymbol(math, main, rel, "\u2192", "\\to");
  4547. defineSymbol(math, ams, rel, "\u2271", "\\ngeq", true);
  4548. defineSymbol(math, ams, rel, "\u2270", "\\nleq", true);
  4549. defineSymbol(math, main, spacing, "\u00a0", "\\ ");
  4550. defineSymbol(math, main, spacing, "\u00a0", "\\space"); // Ref: LaTeX Source 2e: \DeclareRobustCommand{\nobreakspace}{%
  4551. defineSymbol(math, main, spacing, "\u00a0", "\\nobreakspace");
  4552. defineSymbol(text, main, spacing, "\u00a0", "\\ ");
  4553. defineSymbol(text, main, spacing, "\u00a0", " ");
  4554. defineSymbol(text, main, spacing, "\u00a0", "\\space");
  4555. defineSymbol(text, main, spacing, "\u00a0", "\\nobreakspace");
  4556. defineSymbol(math, main, spacing, null, "\\nobreak");
  4557. defineSymbol(math, main, spacing, null, "\\allowbreak");
  4558. defineSymbol(math, main, punct, ",", ",");
  4559. defineSymbol(math, main, punct, ";", ";");
  4560. defineSymbol(math, ams, bin, "\u22bc", "\\barwedge", true);
  4561. defineSymbol(math, ams, bin, "\u22bb", "\\veebar", true);
  4562. defineSymbol(math, main, bin, "\u2299", "\\odot", true);
  4563. defineSymbol(math, main, bin, "\u2295", "\\oplus", true);
  4564. defineSymbol(math, main, bin, "\u2297", "\\otimes", true);
  4565. defineSymbol(math, main, textord, "\u2202", "\\partial", true);
  4566. defineSymbol(math, main, bin, "\u2298", "\\oslash", true);
  4567. defineSymbol(math, ams, bin, "\u229a", "\\circledcirc", true);
  4568. defineSymbol(math, ams, bin, "\u22a1", "\\boxdot", true);
  4569. defineSymbol(math, main, bin, "\u25b3", "\\bigtriangleup");
  4570. defineSymbol(math, main, bin, "\u25bd", "\\bigtriangledown");
  4571. defineSymbol(math, main, bin, "\u2020", "\\dagger");
  4572. defineSymbol(math, main, bin, "\u22c4", "\\diamond");
  4573. defineSymbol(math, main, bin, "\u22c6", "\\star");
  4574. defineSymbol(math, main, bin, "\u25c3", "\\triangleleft");
  4575. defineSymbol(math, main, bin, "\u25b9", "\\triangleright");
  4576. defineSymbol(math, main, open, "{", "\\{");
  4577. defineSymbol(text, main, textord, "{", "\\{");
  4578. defineSymbol(text, main, textord, "{", "\\textbraceleft");
  4579. defineSymbol(math, main, close, "}", "\\}");
  4580. defineSymbol(text, main, textord, "}", "\\}");
  4581. defineSymbol(text, main, textord, "}", "\\textbraceright");
  4582. defineSymbol(math, main, open, "{", "\\lbrace");
  4583. defineSymbol(math, main, close, "}", "\\rbrace");
  4584. defineSymbol(math, main, open, "[", "\\lbrack", true);
  4585. defineSymbol(text, main, textord, "[", "\\lbrack", true);
  4586. defineSymbol(math, main, close, "]", "\\rbrack", true);
  4587. defineSymbol(text, main, textord, "]", "\\rbrack", true);
  4588. defineSymbol(math, main, open, "(", "\\lparen", true);
  4589. defineSymbol(math, main, close, ")", "\\rparen", true);
  4590. defineSymbol(text, main, textord, "<", "\\textless", true); // in T1 fontenc
  4591. defineSymbol(text, main, textord, ">", "\\textgreater", true); // in T1 fontenc
  4592. defineSymbol(math, main, open, "\u230a", "\\lfloor", true);
  4593. defineSymbol(math, main, close, "\u230b", "\\rfloor", true);
  4594. defineSymbol(math, main, open, "\u2308", "\\lceil", true);
  4595. defineSymbol(math, main, close, "\u2309", "\\rceil", true);
  4596. defineSymbol(math, main, textord, "\\", "\\backslash");
  4597. defineSymbol(math, main, textord, "\u2223", "|");
  4598. defineSymbol(math, main, textord, "\u2223", "\\vert");
  4599. defineSymbol(text, main, textord, "|", "\\textbar", true); // in T1 fontenc
  4600. defineSymbol(math, main, textord, "\u2225", "\\|");
  4601. defineSymbol(math, main, textord, "\u2225", "\\Vert");
  4602. defineSymbol(text, main, textord, "\u2225", "\\textbardbl");
  4603. defineSymbol(text, main, textord, "~", "\\textasciitilde");
  4604. defineSymbol(text, main, textord, "\\", "\\textbackslash");
  4605. defineSymbol(text, main, textord, "^", "\\textasciicircum");
  4606. defineSymbol(math, main, rel, "\u2191", "\\uparrow", true);
  4607. defineSymbol(math, main, rel, "\u21d1", "\\Uparrow", true);
  4608. defineSymbol(math, main, rel, "\u2193", "\\downarrow", true);
  4609. defineSymbol(math, main, rel, "\u21d3", "\\Downarrow", true);
  4610. defineSymbol(math, main, rel, "\u2195", "\\updownarrow", true);
  4611. defineSymbol(math, main, rel, "\u21d5", "\\Updownarrow", true);
  4612. defineSymbol(math, main, op, "\u2210", "\\coprod");
  4613. defineSymbol(math, main, op, "\u22c1", "\\bigvee");
  4614. defineSymbol(math, main, op, "\u22c0", "\\bigwedge");
  4615. defineSymbol(math, main, op, "\u2a04", "\\biguplus");
  4616. defineSymbol(math, main, op, "\u22c2", "\\bigcap");
  4617. defineSymbol(math, main, op, "\u22c3", "\\bigcup");
  4618. defineSymbol(math, main, op, "\u222b", "\\int");
  4619. defineSymbol(math, main, op, "\u222b", "\\intop");
  4620. defineSymbol(math, main, op, "\u222c", "\\iint");
  4621. defineSymbol(math, main, op, "\u222d", "\\iiint");
  4622. defineSymbol(math, main, op, "\u220f", "\\prod");
  4623. defineSymbol(math, main, op, "\u2211", "\\sum");
  4624. defineSymbol(math, main, op, "\u2a02", "\\bigotimes");
  4625. defineSymbol(math, main, op, "\u2a01", "\\bigoplus");
  4626. defineSymbol(math, main, op, "\u2a00", "\\bigodot");
  4627. defineSymbol(math, main, op, "\u222e", "\\oint");
  4628. defineSymbol(math, main, op, "\u222f", "\\oiint");
  4629. defineSymbol(math, main, op, "\u2230", "\\oiiint");
  4630. defineSymbol(math, main, op, "\u2a06", "\\bigsqcup");
  4631. defineSymbol(math, main, op, "\u222b", "\\smallint");
  4632. defineSymbol(text, main, inner, "\u2026", "\\textellipsis");
  4633. defineSymbol(math, main, inner, "\u2026", "\\mathellipsis");
  4634. defineSymbol(text, main, inner, "\u2026", "\\ldots", true);
  4635. defineSymbol(math, main, inner, "\u2026", "\\ldots", true);
  4636. defineSymbol(math, main, inner, "\u22ef", "\\@cdots", true);
  4637. defineSymbol(math, main, inner, "\u22f1", "\\ddots", true);
  4638. defineSymbol(math, main, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
  4639. defineSymbol(math, main, accent, "\u02ca", "\\acute");
  4640. defineSymbol(math, main, accent, "\u02cb", "\\grave");
  4641. defineSymbol(math, main, accent, "\u00a8", "\\ddot");
  4642. defineSymbol(math, main, accent, "\u007e", "\\tilde");
  4643. defineSymbol(math, main, accent, "\u02c9", "\\bar");
  4644. defineSymbol(math, main, accent, "\u02d8", "\\breve");
  4645. defineSymbol(math, main, accent, "\u02c7", "\\check");
  4646. defineSymbol(math, main, accent, "\u005e", "\\hat");
  4647. defineSymbol(math, main, accent, "\u20d7", "\\vec");
  4648. defineSymbol(math, main, accent, "\u02d9", "\\dot");
  4649. defineSymbol(math, main, accent, "\u02da", "\\mathring"); // \imath and \jmath should be invariant to \mathrm, \mathbf, etc., so use PUA
  4650. defineSymbol(math, main, mathord, "\ue131", "\\@imath");
  4651. defineSymbol(math, main, mathord, "\ue237", "\\@jmath");
  4652. defineSymbol(math, main, textord, "\u0131", "\u0131");
  4653. defineSymbol(math, main, textord, "\u0237", "\u0237");
  4654. defineSymbol(text, main, textord, "\u0131", "\\i", true);
  4655. defineSymbol(text, main, textord, "\u0237", "\\j", true);
  4656. defineSymbol(text, main, textord, "\u00df", "\\ss", true);
  4657. defineSymbol(text, main, textord, "\u00e6", "\\ae", true);
  4658. defineSymbol(text, main, textord, "\u0153", "\\oe", true);
  4659. defineSymbol(text, main, textord, "\u00f8", "\\o", true);
  4660. defineSymbol(text, main, textord, "\u00c6", "\\AE", true);
  4661. defineSymbol(text, main, textord, "\u0152", "\\OE", true);
  4662. defineSymbol(text, main, textord, "\u00d8", "\\O", true);
  4663. defineSymbol(text, main, accent, "\u02ca", "\\'"); // acute
  4664. defineSymbol(text, main, accent, "\u02cb", "\\`"); // grave
  4665. defineSymbol(text, main, accent, "\u02c6", "\\^"); // circumflex
  4666. defineSymbol(text, main, accent, "\u02dc", "\\~"); // tilde
  4667. defineSymbol(text, main, accent, "\u02c9", "\\="); // macron
  4668. defineSymbol(text, main, accent, "\u02d8", "\\u"); // breve
  4669. defineSymbol(text, main, accent, "\u02d9", "\\."); // dot above
  4670. defineSymbol(text, main, accent, "\u00b8", "\\c"); // cedilla
  4671. defineSymbol(text, main, accent, "\u02da", "\\r"); // ring above
  4672. defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
  4673. defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaresis
  4674. defineSymbol(text, main, accent, "\u02dd", "\\H"); // double acute
  4675. defineSymbol(text, main, accent, "\u25ef", "\\textcircled"); // \bigcirc glyph
  4676. // These ligatures are detected and created in Parser.js's `formLigatures`.
  4677. var ligatures = {
  4678. "--": true,
  4679. "---": true,
  4680. "``": true,
  4681. "''": true
  4682. };
  4683. defineSymbol(text, main, textord, "\u2013", "--", true);
  4684. defineSymbol(text, main, textord, "\u2013", "\\textendash");
  4685. defineSymbol(text, main, textord, "\u2014", "---", true);
  4686. defineSymbol(text, main, textord, "\u2014", "\\textemdash");
  4687. defineSymbol(text, main, textord, "\u2018", "`", true);
  4688. defineSymbol(text, main, textord, "\u2018", "\\textquoteleft");
  4689. defineSymbol(text, main, textord, "\u2019", "'", true);
  4690. defineSymbol(text, main, textord, "\u2019", "\\textquoteright");
  4691. defineSymbol(text, main, textord, "\u201c", "``", true);
  4692. defineSymbol(text, main, textord, "\u201c", "\\textquotedblleft");
  4693. defineSymbol(text, main, textord, "\u201d", "''", true);
  4694. defineSymbol(text, main, textord, "\u201d", "\\textquotedblright"); // \degree from gensymb package
  4695. defineSymbol(math, main, textord, "\u00b0", "\\degree", true);
  4696. defineSymbol(text, main, textord, "\u00b0", "\\degree"); // \textdegree from inputenc package
  4697. defineSymbol(text, main, textord, "\u00b0", "\\textdegree", true); // TODO: In LaTeX, \pounds can generate a different character in text and math
  4698. // mode, but among our fonts, only Main-Regular defines this character "163".
  4699. defineSymbol(math, main, textord, "\u00a3", "\\pounds");
  4700. defineSymbol(math, main, textord, "\u00a3", "\\mathsterling", true);
  4701. defineSymbol(text, main, textord, "\u00a3", "\\pounds");
  4702. defineSymbol(text, main, textord, "\u00a3", "\\textsterling", true);
  4703. defineSymbol(math, ams, textord, "\u2720", "\\maltese");
  4704. defineSymbol(text, ams, textord, "\u2720", "\\maltese"); // There are lots of symbols which are the same, so we add them in afterwards.
  4705. // All of these are textords in math mode
  4706. var mathTextSymbols = "0123456789/@.\"";
  4707. for (var i = 0; i < mathTextSymbols.length; i++) {
  4708. var ch = mathTextSymbols.charAt(i);
  4709. defineSymbol(math, main, textord, ch, ch);
  4710. } // All of these are textords in text mode
  4711. var textSymbols = "0123456789!@*()-=+\";:?/.,";
  4712. for (var _i = 0; _i < textSymbols.length; _i++) {
  4713. var _ch = textSymbols.charAt(_i);
  4714. defineSymbol(text, main, textord, _ch, _ch);
  4715. } // All of these are textords in text mode, and mathords in math mode
  4716. var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  4717. for (var _i2 = 0; _i2 < letters.length; _i2++) {
  4718. var _ch2 = letters.charAt(_i2);
  4719. defineSymbol(math, main, mathord, _ch2, _ch2);
  4720. defineSymbol(text, main, textord, _ch2, _ch2);
  4721. } // Blackboard bold and script letters in Unicode range
  4722. defineSymbol(math, ams, textord, "C", "\u2102"); // blackboard bold
  4723. defineSymbol(text, ams, textord, "C", "\u2102");
  4724. defineSymbol(math, ams, textord, "H", "\u210D");
  4725. defineSymbol(text, ams, textord, "H", "\u210D");
  4726. defineSymbol(math, ams, textord, "N", "\u2115");
  4727. defineSymbol(text, ams, textord, "N", "\u2115");
  4728. defineSymbol(math, ams, textord, "P", "\u2119");
  4729. defineSymbol(text, ams, textord, "P", "\u2119");
  4730. defineSymbol(math, ams, textord, "Q", "\u211A");
  4731. defineSymbol(text, ams, textord, "Q", "\u211A");
  4732. defineSymbol(math, ams, textord, "R", "\u211D");
  4733. defineSymbol(text, ams, textord, "R", "\u211D");
  4734. defineSymbol(math, ams, textord, "Z", "\u2124");
  4735. defineSymbol(text, ams, textord, "Z", "\u2124");
  4736. defineSymbol(math, main, mathord, "h", "\u210E"); // italic h, Planck constant
  4737. defineSymbol(text, main, mathord, "h", "\u210E"); // The next loop loads wide (surrogate pair) characters.
  4738. // We support some letters in the Unicode range U+1D400 to U+1D7FF,
  4739. // Mathematical Alphanumeric Symbols.
  4740. // Some editors do not deal well with wide characters. So don't write the
  4741. // string into this file. Instead, create the string from the surrogate pair.
  4742. var wideChar = "";
  4743. for (var _i3 = 0; _i3 < letters.length; _i3++) {
  4744. var _ch3 = letters.charAt(_i3); // The hex numbers in the next line are a surrogate pair.
  4745. // 0xD835 is the high surrogate for all letters in the range we support.
  4746. // 0xDC00 is the low surrogate for bold A.
  4747. wideChar = String.fromCharCode(0xD835, 0xDC00 + _i3); // A-Z a-z bold
  4748. defineSymbol(math, main, mathord, _ch3, wideChar);
  4749. defineSymbol(text, main, textord, _ch3, wideChar);
  4750. wideChar = String.fromCharCode(0xD835, 0xDC34 + _i3); // A-Z a-z italic
  4751. defineSymbol(math, main, mathord, _ch3, wideChar);
  4752. defineSymbol(text, main, textord, _ch3, wideChar);
  4753. wideChar = String.fromCharCode(0xD835, 0xDC68 + _i3); // A-Z a-z bold italic
  4754. defineSymbol(math, main, mathord, _ch3, wideChar);
  4755. defineSymbol(text, main, textord, _ch3, wideChar);
  4756. wideChar = String.fromCharCode(0xD835, 0xDD04 + _i3); // A-Z a-z Fractur
  4757. defineSymbol(math, main, mathord, _ch3, wideChar);
  4758. defineSymbol(text, main, textord, _ch3, wideChar);
  4759. wideChar = String.fromCharCode(0xD835, 0xDDA0 + _i3); // A-Z a-z sans-serif
  4760. defineSymbol(math, main, mathord, _ch3, wideChar);
  4761. defineSymbol(text, main, textord, _ch3, wideChar);
  4762. wideChar = String.fromCharCode(0xD835, 0xDDD4 + _i3); // A-Z a-z sans bold
  4763. defineSymbol(math, main, mathord, _ch3, wideChar);
  4764. defineSymbol(text, main, textord, _ch3, wideChar);
  4765. wideChar = String.fromCharCode(0xD835, 0xDE08 + _i3); // A-Z a-z sans italic
  4766. defineSymbol(math, main, mathord, _ch3, wideChar);
  4767. defineSymbol(text, main, textord, _ch3, wideChar);
  4768. wideChar = String.fromCharCode(0xD835, 0xDE70 + _i3); // A-Z a-z monospace
  4769. defineSymbol(math, main, mathord, _ch3, wideChar);
  4770. defineSymbol(text, main, textord, _ch3, wideChar);
  4771. if (_i3 < 26) {
  4772. // KaTeX fonts have only capital letters for blackboard bold and script.
  4773. // See exception for k below.
  4774. wideChar = String.fromCharCode(0xD835, 0xDD38 + _i3); // A-Z double struck
  4775. defineSymbol(math, main, mathord, _ch3, wideChar);
  4776. defineSymbol(text, main, textord, _ch3, wideChar);
  4777. wideChar = String.fromCharCode(0xD835, 0xDC9C + _i3); // A-Z script
  4778. defineSymbol(math, main, mathord, _ch3, wideChar);
  4779. defineSymbol(text, main, textord, _ch3, wideChar);
  4780. } // TODO: Add bold script when it is supported by a KaTeX font.
  4781. } // "k" is the only double struck lower case letter in the KaTeX fonts.
  4782. wideChar = String.fromCharCode(0xD835, 0xDD5C); // k double struck
  4783. defineSymbol(math, main, mathord, "k", wideChar);
  4784. defineSymbol(text, main, textord, "k", wideChar); // Next, some wide character numerals
  4785. for (var _i4 = 0; _i4 < 10; _i4++) {
  4786. var _ch4 = _i4.toString();
  4787. wideChar = String.fromCharCode(0xD835, 0xDFCE + _i4); // 0-9 bold
  4788. defineSymbol(math, main, mathord, _ch4, wideChar);
  4789. defineSymbol(text, main, textord, _ch4, wideChar);
  4790. wideChar = String.fromCharCode(0xD835, 0xDFE2 + _i4); // 0-9 sans serif
  4791. defineSymbol(math, main, mathord, _ch4, wideChar);
  4792. defineSymbol(text, main, textord, _ch4, wideChar);
  4793. wideChar = String.fromCharCode(0xD835, 0xDFEC + _i4); // 0-9 bold sans
  4794. defineSymbol(math, main, mathord, _ch4, wideChar);
  4795. defineSymbol(text, main, textord, _ch4, wideChar);
  4796. wideChar = String.fromCharCode(0xD835, 0xDFF6 + _i4); // 0-9 monospace
  4797. defineSymbol(math, main, mathord, _ch4, wideChar);
  4798. defineSymbol(text, main, textord, _ch4, wideChar);
  4799. } // We add these Latin-1 letters as symbols for backwards-compatibility,
  4800. // but they are not actually in the font, nor are they supported by the
  4801. // Unicode accent mechanism, so they fall back to Times font and look ugly.
  4802. // TODO(edemaine): Fix this.
  4803. var extraLatin = "\u00d0\u00de\u00fe";
  4804. for (var _i5 = 0; _i5 < extraLatin.length; _i5++) {
  4805. var _ch5 = extraLatin.charAt(_i5);
  4806. defineSymbol(math, main, mathord, _ch5, _ch5);
  4807. defineSymbol(text, main, textord, _ch5, _ch5);
  4808. }
  4809. /**
  4810. * This file provides support for Unicode range U+1D400 to U+1D7FF,
  4811. * Mathematical Alphanumeric Symbols.
  4812. *
  4813. * Function wideCharacterFont takes a wide character as input and returns
  4814. * the font information necessary to render it properly.
  4815. */
  4816. /**
  4817. * Data below is from https://www.unicode.org/charts/PDF/U1D400.pdf
  4818. * That document sorts characters into groups by font type, say bold or italic.
  4819. *
  4820. * In the arrays below, each subarray consists three elements:
  4821. * * The CSS class of that group when in math mode.
  4822. * * The CSS class of that group when in text mode.
  4823. * * The font name, so that KaTeX can get font metrics.
  4824. */
  4825. var wideLatinLetterData = [["mathbf", "textbf", "Main-Bold"], // A-Z bold upright
  4826. ["mathbf", "textbf", "Main-Bold"], // a-z bold upright
  4827. ["mathnormal", "textit", "Math-Italic"], // A-Z italic
  4828. ["mathnormal", "textit", "Math-Italic"], // a-z italic
  4829. ["boldsymbol", "boldsymbol", "Main-BoldItalic"], // A-Z bold italic
  4830. ["boldsymbol", "boldsymbol", "Main-BoldItalic"], // a-z bold italic
  4831. // Map fancy A-Z letters to script, not calligraphic.
  4832. // This aligns with unicode-math and math fonts (except Cambria Math).
  4833. ["mathscr", "textscr", "Script-Regular"], // A-Z script
  4834. ["", "", ""], // a-z script. No font
  4835. ["", "", ""], // A-Z bold script. No font
  4836. ["", "", ""], // a-z bold script. No font
  4837. ["mathfrak", "textfrak", "Fraktur-Regular"], // A-Z Fraktur
  4838. ["mathfrak", "textfrak", "Fraktur-Regular"], // a-z Fraktur
  4839. ["mathbb", "textbb", "AMS-Regular"], // A-Z double-struck
  4840. ["mathbb", "textbb", "AMS-Regular"], // k double-struck
  4841. ["", "", ""], // A-Z bold Fraktur No font metrics
  4842. ["", "", ""], // a-z bold Fraktur. No font.
  4843. ["mathsf", "textsf", "SansSerif-Regular"], // A-Z sans-serif
  4844. ["mathsf", "textsf", "SansSerif-Regular"], // a-z sans-serif
  4845. ["mathboldsf", "textboldsf", "SansSerif-Bold"], // A-Z bold sans-serif
  4846. ["mathboldsf", "textboldsf", "SansSerif-Bold"], // a-z bold sans-serif
  4847. ["mathitsf", "textitsf", "SansSerif-Italic"], // A-Z italic sans-serif
  4848. ["mathitsf", "textitsf", "SansSerif-Italic"], // a-z italic sans-serif
  4849. ["", "", ""], // A-Z bold italic sans. No font
  4850. ["", "", ""], // a-z bold italic sans. No font
  4851. ["mathtt", "texttt", "Typewriter-Regular"], // A-Z monospace
  4852. ["mathtt", "texttt", "Typewriter-Regular"] // a-z monospace
  4853. ];
  4854. var wideNumeralData = [["mathbf", "textbf", "Main-Bold"], // 0-9 bold
  4855. ["", "", ""], // 0-9 double-struck. No KaTeX font.
  4856. ["mathsf", "textsf", "SansSerif-Regular"], // 0-9 sans-serif
  4857. ["mathboldsf", "textboldsf", "SansSerif-Bold"], // 0-9 bold sans-serif
  4858. ["mathtt", "texttt", "Typewriter-Regular"] // 0-9 monospace
  4859. ];
  4860. var wideCharacterFont = function wideCharacterFont(wideChar, mode) {
  4861. // IE doesn't support codePointAt(). So work with the surrogate pair.
  4862. var H = wideChar.charCodeAt(0); // high surrogate
  4863. var L = wideChar.charCodeAt(1); // low surrogate
  4864. var codePoint = (H - 0xD800) * 0x400 + (L - 0xDC00) + 0x10000;
  4865. var j = mode === "math" ? 0 : 1; // column index for CSS class.
  4866. if (0x1D400 <= codePoint && codePoint < 0x1D6A4) {
  4867. // wideLatinLetterData contains exactly 26 chars on each row.
  4868. // So we can calculate the relevant row. No traverse necessary.
  4869. var i = Math.floor((codePoint - 0x1D400) / 26);
  4870. return [wideLatinLetterData[i][2], wideLatinLetterData[i][j]];
  4871. } else if (0x1D7CE <= codePoint && codePoint <= 0x1D7FF) {
  4872. // Numerals, ten per row.
  4873. var _i = Math.floor((codePoint - 0x1D7CE) / 10);
  4874. return [wideNumeralData[_i][2], wideNumeralData[_i][j]];
  4875. } else if (codePoint === 0x1D6A5 || codePoint === 0x1D6A6) {
  4876. // dotless i or j
  4877. return [wideLatinLetterData[0][2], wideLatinLetterData[0][j]];
  4878. } else if (0x1D6A6 < codePoint && codePoint < 0x1D7CE) {
  4879. // Greek letters. Not supported, yet.
  4880. return ["", ""];
  4881. } else {
  4882. // We don't support any wide characters outside 1D400–1D7FF.
  4883. throw new ParseError("Unsupported character: " + wideChar);
  4884. }
  4885. };
  4886. /* eslint no-console:0 */
  4887. /**
  4888. * Looks up the given symbol in fontMetrics, after applying any symbol
  4889. * replacements defined in symbol.js
  4890. */
  4891. var lookupSymbol = function lookupSymbol(value, // TODO(#963): Use a union type for this.
  4892. fontName, mode) {
  4893. // Replace the value with its replaced value from symbol.js
  4894. if (symbols[mode][value] && symbols[mode][value].replace) {
  4895. value = symbols[mode][value].replace;
  4896. }
  4897. return {
  4898. value: value,
  4899. metrics: getCharacterMetrics(value, fontName, mode)
  4900. };
  4901. };
  4902. /**
  4903. * Makes a symbolNode after translation via the list of symbols in symbols.js.
  4904. * Correctly pulls out metrics for the character, and optionally takes a list of
  4905. * classes to be attached to the node.
  4906. *
  4907. * TODO: make argument order closer to makeSpan
  4908. * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
  4909. * should if present come first in `classes`.
  4910. * TODO(#953): Make `options` mandatory and always pass it in.
  4911. */
  4912. var makeSymbol = function makeSymbol(value, fontName, mode, options, classes) {
  4913. var lookup = lookupSymbol(value, fontName, mode);
  4914. var metrics = lookup.metrics;
  4915. value = lookup.value;
  4916. var symbolNode;
  4917. if (metrics) {
  4918. var italic = metrics.italic;
  4919. if (mode === "text" || options && options.font === "mathit") {
  4920. italic = 0;
  4921. }
  4922. symbolNode = new SymbolNode(value, metrics.height, metrics.depth, italic, metrics.skew, metrics.width, classes);
  4923. } else {
  4924. // TODO(emily): Figure out a good way to only print this in development
  4925. typeof console !== "undefined" && console.warn("No character metrics " + ("for '" + value + "' in style '" + fontName + "' and mode '" + mode + "'"));
  4926. symbolNode = new SymbolNode(value, 0, 0, 0, 0, 0, classes);
  4927. }
  4928. if (options) {
  4929. symbolNode.maxFontSize = options.sizeMultiplier;
  4930. if (options.style.isTight()) {
  4931. symbolNode.classes.push("mtight");
  4932. }
  4933. var color = options.getColor();
  4934. if (color) {
  4935. symbolNode.style.color = color;
  4936. }
  4937. }
  4938. return symbolNode;
  4939. };
  4940. /**
  4941. * Makes a symbol in Main-Regular or AMS-Regular.
  4942. * Used for rel, bin, open, close, inner, and punct.
  4943. */
  4944. var mathsym = function mathsym(value, mode, options, classes) {
  4945. if (classes === void 0) {
  4946. classes = [];
  4947. }
  4948. // Decide what font to render the symbol in by its entry in the symbols
  4949. // table.
  4950. // Have a special case for when the value = \ because the \ is used as a
  4951. // textord in unsupported command errors but cannot be parsed as a regular
  4952. // text ordinal and is therefore not present as a symbol in the symbols
  4953. // table for text, as well as a special case for boldsymbol because it
  4954. // can be used for bold + and -
  4955. if (options.font === "boldsymbol" && lookupSymbol(value, "Main-Bold", mode).metrics) {
  4956. return makeSymbol(value, "Main-Bold", mode, options, classes.concat(["mathbf"]));
  4957. } else if (value === "\\" || symbols[mode][value].font === "main") {
  4958. return makeSymbol(value, "Main-Regular", mode, options, classes);
  4959. } else {
  4960. return makeSymbol(value, "AMS-Regular", mode, options, classes.concat(["amsrm"]));
  4961. }
  4962. };
  4963. /**
  4964. * Determines which of the two font names (Main-Bold and Math-BoldItalic) and
  4965. * corresponding style tags (mathbf or boldsymbol) to use for font "boldsymbol",
  4966. * depending on the symbol. Use this function instead of fontMap for font
  4967. * "boldsymbol".
  4968. */
  4969. var boldsymbol = function boldsymbol(value, mode, options, classes, type) {
  4970. if (type !== "textord" && lookupSymbol(value, "Math-BoldItalic", mode).metrics) {
  4971. return {
  4972. fontName: "Math-BoldItalic",
  4973. fontClass: "boldsymbol"
  4974. };
  4975. } else {
  4976. // Some glyphs do not exist in Math-BoldItalic so we need to use
  4977. // Main-Bold instead.
  4978. return {
  4979. fontName: "Main-Bold",
  4980. fontClass: "mathbf"
  4981. };
  4982. }
  4983. };
  4984. /**
  4985. * Makes either a mathord or textord in the correct font and color.
  4986. */
  4987. var makeOrd = function makeOrd(group, options, type) {
  4988. var mode = group.mode;
  4989. var text = group.text;
  4990. var classes = ["mord"]; // Math mode or Old font (i.e. \rm)
  4991. var isFont = mode === "math" || mode === "text" && options.font;
  4992. var fontOrFamily = isFont ? options.font : options.fontFamily;
  4993. if (text.charCodeAt(0) === 0xD835) {
  4994. // surrogate pairs get special treatment
  4995. var [wideFontName, wideFontClass] = wideCharacterFont(text, mode);
  4996. return makeSymbol(text, wideFontName, mode, options, classes.concat(wideFontClass));
  4997. } else if (fontOrFamily) {
  4998. var fontName;
  4999. var fontClasses;
  5000. if (fontOrFamily === "boldsymbol") {
  5001. var fontData = boldsymbol(text, mode, options, classes, type);
  5002. fontName = fontData.fontName;
  5003. fontClasses = [fontData.fontClass];
  5004. } else if (isFont) {
  5005. fontName = fontMap[fontOrFamily].fontName;
  5006. fontClasses = [fontOrFamily];
  5007. } else {
  5008. fontName = retrieveTextFontName(fontOrFamily, options.fontWeight, options.fontShape);
  5009. fontClasses = [fontOrFamily, options.fontWeight, options.fontShape];
  5010. }
  5011. if (lookupSymbol(text, fontName, mode).metrics) {
  5012. return makeSymbol(text, fontName, mode, options, classes.concat(fontClasses));
  5013. } else if (ligatures.hasOwnProperty(text) && fontName.slice(0, 10) === "Typewriter") {
  5014. // Deconstruct ligatures in monospace fonts (\texttt, \tt).
  5015. var parts = [];
  5016. for (var i = 0; i < text.length; i++) {
  5017. parts.push(makeSymbol(text[i], fontName, mode, options, classes.concat(fontClasses)));
  5018. }
  5019. return makeFragment(parts);
  5020. }
  5021. } // Makes a symbol in the default font for mathords and textords.
  5022. if (type === "mathord") {
  5023. return makeSymbol(text, "Math-Italic", mode, options, classes.concat(["mathnormal"]));
  5024. } else if (type === "textord") {
  5025. var font = symbols[mode][text] && symbols[mode][text].font;
  5026. if (font === "ams") {
  5027. var _fontName = retrieveTextFontName("amsrm", options.fontWeight, options.fontShape);
  5028. return makeSymbol(text, _fontName, mode, options, classes.concat("amsrm", options.fontWeight, options.fontShape));
  5029. } else if (font === "main" || !font) {
  5030. var _fontName2 = retrieveTextFontName("textrm", options.fontWeight, options.fontShape);
  5031. return makeSymbol(text, _fontName2, mode, options, classes.concat(options.fontWeight, options.fontShape));
  5032. } else {
  5033. // fonts added by plugins
  5034. var _fontName3 = retrieveTextFontName(font, options.fontWeight, options.fontShape); // We add font name as a css class
  5035. return makeSymbol(text, _fontName3, mode, options, classes.concat(_fontName3, options.fontWeight, options.fontShape));
  5036. }
  5037. } else {
  5038. throw new Error("unexpected type: " + type + " in makeOrd");
  5039. }
  5040. };
  5041. /**
  5042. * Returns true if subsequent symbolNodes have the same classes, skew, maxFont,
  5043. * and styles.
  5044. */
  5045. var canCombine = (prev, next) => {
  5046. if (createClass(prev.classes) !== createClass(next.classes) || prev.skew !== next.skew || prev.maxFontSize !== next.maxFontSize) {
  5047. return false;
  5048. } // If prev and next both are just "mbin"s or "mord"s we don't combine them
  5049. // so that the proper spacing can be preserved.
  5050. if (prev.classes.length === 1) {
  5051. var cls = prev.classes[0];
  5052. if (cls === "mbin" || cls === "mord") {
  5053. return false;
  5054. }
  5055. }
  5056. for (var style in prev.style) {
  5057. if (prev.style.hasOwnProperty(style) && prev.style[style] !== next.style[style]) {
  5058. return false;
  5059. }
  5060. }
  5061. for (var _style in next.style) {
  5062. if (next.style.hasOwnProperty(_style) && prev.style[_style] !== next.style[_style]) {
  5063. return false;
  5064. }
  5065. }
  5066. return true;
  5067. };
  5068. /**
  5069. * Combine consecutive domTree.symbolNodes into a single symbolNode.
  5070. * Note: this function mutates the argument.
  5071. */
  5072. var tryCombineChars = chars => {
  5073. for (var i = 0; i < chars.length - 1; i++) {
  5074. var prev = chars[i];
  5075. var next = chars[i + 1];
  5076. if (prev instanceof SymbolNode && next instanceof SymbolNode && canCombine(prev, next)) {
  5077. prev.text += next.text;
  5078. prev.height = Math.max(prev.height, next.height);
  5079. prev.depth = Math.max(prev.depth, next.depth); // Use the last character's italic correction since we use
  5080. // it to add padding to the right of the span created from
  5081. // the combined characters.
  5082. prev.italic = next.italic;
  5083. chars.splice(i + 1, 1);
  5084. i--;
  5085. }
  5086. }
  5087. return chars;
  5088. };
  5089. /**
  5090. * Calculate the height, depth, and maxFontSize of an element based on its
  5091. * children.
  5092. */
  5093. var sizeElementFromChildren = function sizeElementFromChildren(elem) {
  5094. var height = 0;
  5095. var depth = 0;
  5096. var maxFontSize = 0;
  5097. for (var i = 0; i < elem.children.length; i++) {
  5098. var child = elem.children[i];
  5099. if (child.height > height) {
  5100. height = child.height;
  5101. }
  5102. if (child.depth > depth) {
  5103. depth = child.depth;
  5104. }
  5105. if (child.maxFontSize > maxFontSize) {
  5106. maxFontSize = child.maxFontSize;
  5107. }
  5108. }
  5109. elem.height = height;
  5110. elem.depth = depth;
  5111. elem.maxFontSize = maxFontSize;
  5112. };
  5113. /**
  5114. * Makes a span with the given list of classes, list of children, and options.
  5115. *
  5116. * TODO(#953): Ensure that `options` is always provided (currently some call
  5117. * sites don't pass it) and make the type below mandatory.
  5118. * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
  5119. * should if present come first in `classes`.
  5120. */
  5121. var makeSpan$2 = function makeSpan(classes, children, options, style) {
  5122. var span = new Span(classes, children, options, style);
  5123. sizeElementFromChildren(span);
  5124. return span;
  5125. }; // SVG one is simpler -- doesn't require height, depth, max-font setting.
  5126. // This is also a separate method for typesafety.
  5127. var makeSvgSpan = (classes, children, options, style) => new Span(classes, children, options, style);
  5128. var makeLineSpan = function makeLineSpan(className, options, thickness) {
  5129. var line = makeSpan$2([className], [], options);
  5130. line.height = Math.max(thickness || options.fontMetrics().defaultRuleThickness, options.minRuleThickness);
  5131. line.style.borderBottomWidth = makeEm(line.height);
  5132. line.maxFontSize = 1.0;
  5133. return line;
  5134. };
  5135. /**
  5136. * Makes an anchor with the given href, list of classes, list of children,
  5137. * and options.
  5138. */
  5139. var makeAnchor = function makeAnchor(href, classes, children, options) {
  5140. var anchor = new Anchor(href, classes, children, options);
  5141. sizeElementFromChildren(anchor);
  5142. return anchor;
  5143. };
  5144. /**
  5145. * Makes a document fragment with the given list of children.
  5146. */
  5147. var makeFragment = function makeFragment(children) {
  5148. var fragment = new DocumentFragment(children);
  5149. sizeElementFromChildren(fragment);
  5150. return fragment;
  5151. };
  5152. /**
  5153. * Wraps group in a span if it's a document fragment, allowing to apply classes
  5154. * and styles
  5155. */
  5156. var wrapFragment = function wrapFragment(group, options) {
  5157. if (group instanceof DocumentFragment) {
  5158. return makeSpan$2([], [group], options);
  5159. }
  5160. return group;
  5161. }; // These are exact object types to catch typos in the names of the optional fields.
  5162. // Computes the updated `children` list and the overall depth.
  5163. //
  5164. // This helper function for makeVList makes it easier to enforce type safety by
  5165. // allowing early exits (returns) in the logic.
  5166. var getVListChildrenAndDepth = function getVListChildrenAndDepth(params) {
  5167. if (params.positionType === "individualShift") {
  5168. var oldChildren = params.children;
  5169. var children = [oldChildren[0]]; // Add in kerns to the list of params.children to get each element to be
  5170. // shifted to the correct specified shift
  5171. var _depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
  5172. var currPos = _depth;
  5173. for (var i = 1; i < oldChildren.length; i++) {
  5174. var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
  5175. var size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth);
  5176. currPos = currPos + diff;
  5177. children.push({
  5178. type: "kern",
  5179. size
  5180. });
  5181. children.push(oldChildren[i]);
  5182. }
  5183. return {
  5184. children,
  5185. depth: _depth
  5186. };
  5187. }
  5188. var depth;
  5189. if (params.positionType === "top") {
  5190. // We always start at the bottom, so calculate the bottom by adding up
  5191. // all the sizes
  5192. var bottom = params.positionData;
  5193. for (var _i = 0; _i < params.children.length; _i++) {
  5194. var child = params.children[_i];
  5195. bottom -= child.type === "kern" ? child.size : child.elem.height + child.elem.depth;
  5196. }
  5197. depth = bottom;
  5198. } else if (params.positionType === "bottom") {
  5199. depth = -params.positionData;
  5200. } else {
  5201. var firstChild = params.children[0];
  5202. if (firstChild.type !== "elem") {
  5203. throw new Error('First child must have type "elem".');
  5204. }
  5205. if (params.positionType === "shift") {
  5206. depth = -firstChild.elem.depth - params.positionData;
  5207. } else if (params.positionType === "firstBaseline") {
  5208. depth = -firstChild.elem.depth;
  5209. } else {
  5210. throw new Error("Invalid positionType " + params.positionType + ".");
  5211. }
  5212. }
  5213. return {
  5214. children: params.children,
  5215. depth
  5216. };
  5217. };
  5218. /**
  5219. * Makes a vertical list by stacking elements and kerns on top of each other.
  5220. * Allows for many different ways of specifying the positioning method.
  5221. *
  5222. * See VListParam documentation above.
  5223. */
  5224. var makeVList = function makeVList(params, options) {
  5225. var {
  5226. children,
  5227. depth
  5228. } = getVListChildrenAndDepth(params); // Create a strut that is taller than any list item. The strut is added to
  5229. // each item, where it will determine the item's baseline. Since it has
  5230. // `overflow:hidden`, the strut's top edge will sit on the item's line box's
  5231. // top edge and the strut's bottom edge will sit on the item's baseline,
  5232. // with no additional line-height spacing. This allows the item baseline to
  5233. // be positioned precisely without worrying about font ascent and
  5234. // line-height.
  5235. var pstrutSize = 0;
  5236. for (var i = 0; i < children.length; i++) {
  5237. var child = children[i];
  5238. if (child.type === "elem") {
  5239. var elem = child.elem;
  5240. pstrutSize = Math.max(pstrutSize, elem.maxFontSize, elem.height);
  5241. }
  5242. }
  5243. pstrutSize += 2;
  5244. var pstrut = makeSpan$2(["pstrut"], []);
  5245. pstrut.style.height = makeEm(pstrutSize); // Create a new list of actual children at the correct offsets
  5246. var realChildren = [];
  5247. var minPos = depth;
  5248. var maxPos = depth;
  5249. var currPos = depth;
  5250. for (var _i2 = 0; _i2 < children.length; _i2++) {
  5251. var _child = children[_i2];
  5252. if (_child.type === "kern") {
  5253. currPos += _child.size;
  5254. } else {
  5255. var _elem = _child.elem;
  5256. var classes = _child.wrapperClasses || [];
  5257. var style = _child.wrapperStyle || {};
  5258. var childWrap = makeSpan$2(classes, [pstrut, _elem], undefined, style);
  5259. childWrap.style.top = makeEm(-pstrutSize - currPos - _elem.depth);
  5260. if (_child.marginLeft) {
  5261. childWrap.style.marginLeft = _child.marginLeft;
  5262. }
  5263. if (_child.marginRight) {
  5264. childWrap.style.marginRight = _child.marginRight;
  5265. }
  5266. realChildren.push(childWrap);
  5267. currPos += _elem.height + _elem.depth;
  5268. }
  5269. minPos = Math.min(minPos, currPos);
  5270. maxPos = Math.max(maxPos, currPos);
  5271. } // The vlist contents go in a table-cell with `vertical-align:bottom`.
  5272. // This cell's bottom edge will determine the containing table's baseline
  5273. // without overly expanding the containing line-box.
  5274. var vlist = makeSpan$2(["vlist"], realChildren);
  5275. vlist.style.height = makeEm(maxPos); // A second row is used if necessary to represent the vlist's depth.
  5276. var rows;
  5277. if (minPos < 0) {
  5278. // We will define depth in an empty span with display: table-cell.
  5279. // It should render with the height that we define. But Chrome, in
  5280. // contenteditable mode only, treats that span as if it contains some
  5281. // text content. And that min-height over-rides our desired height.
  5282. // So we put another empty span inside the depth strut span.
  5283. var emptySpan = makeSpan$2([], []);
  5284. var depthStrut = makeSpan$2(["vlist"], [emptySpan]);
  5285. depthStrut.style.height = makeEm(-minPos); // Safari wants the first row to have inline content; otherwise it
  5286. // puts the bottom of the *second* row on the baseline.
  5287. var topStrut = makeSpan$2(["vlist-s"], [new SymbolNode("\u200b")]);
  5288. rows = [makeSpan$2(["vlist-r"], [vlist, topStrut]), makeSpan$2(["vlist-r"], [depthStrut])];
  5289. } else {
  5290. rows = [makeSpan$2(["vlist-r"], [vlist])];
  5291. }
  5292. var vtable = makeSpan$2(["vlist-t"], rows);
  5293. if (rows.length === 2) {
  5294. vtable.classes.push("vlist-t2");
  5295. }
  5296. vtable.height = maxPos;
  5297. vtable.depth = -minPos;
  5298. return vtable;
  5299. }; // Glue is a concept from TeX which is a flexible space between elements in
  5300. // either a vertical or horizontal list. In KaTeX, at least for now, it's
  5301. // static space between elements in a horizontal layout.
  5302. var makeGlue = (measurement, options) => {
  5303. // Make an empty span for the space
  5304. var rule = makeSpan$2(["mspace"], [], options);
  5305. var size = calculateSize(measurement, options);
  5306. rule.style.marginRight = makeEm(size);
  5307. return rule;
  5308. }; // Takes font options, and returns the appropriate fontLookup name
  5309. var retrieveTextFontName = function retrieveTextFontName(fontFamily, fontWeight, fontShape) {
  5310. var baseFontName = "";
  5311. switch (fontFamily) {
  5312. case "amsrm":
  5313. baseFontName = "AMS";
  5314. break;
  5315. case "textrm":
  5316. baseFontName = "Main";
  5317. break;
  5318. case "textsf":
  5319. baseFontName = "SansSerif";
  5320. break;
  5321. case "texttt":
  5322. baseFontName = "Typewriter";
  5323. break;
  5324. default:
  5325. baseFontName = fontFamily;
  5326. // use fonts added by a plugin
  5327. }
  5328. var fontStylesName;
  5329. if (fontWeight === "textbf" && fontShape === "textit") {
  5330. fontStylesName = "BoldItalic";
  5331. } else if (fontWeight === "textbf") {
  5332. fontStylesName = "Bold";
  5333. } else if (fontWeight === "textit") {
  5334. fontStylesName = "Italic";
  5335. } else {
  5336. fontStylesName = "Regular";
  5337. }
  5338. return baseFontName + "-" + fontStylesName;
  5339. };
  5340. /**
  5341. * Maps TeX font commands to objects containing:
  5342. * - variant: string used for "mathvariant" attribute in buildMathML.js
  5343. * - fontName: the "style" parameter to fontMetrics.getCharacterMetrics
  5344. */
  5345. // A map between tex font commands an MathML mathvariant attribute values
  5346. var fontMap = {
  5347. // styles
  5348. "mathbf": {
  5349. variant: "bold",
  5350. fontName: "Main-Bold"
  5351. },
  5352. "mathrm": {
  5353. variant: "normal",
  5354. fontName: "Main-Regular"
  5355. },
  5356. "textit": {
  5357. variant: "italic",
  5358. fontName: "Main-Italic"
  5359. },
  5360. "mathit": {
  5361. variant: "italic",
  5362. fontName: "Main-Italic"
  5363. },
  5364. "mathnormal": {
  5365. variant: "italic",
  5366. fontName: "Math-Italic"
  5367. },
  5368. // "boldsymbol" is missing because they require the use of multiple fonts:
  5369. // Math-BoldItalic and Main-Bold. This is handled by a special case in
  5370. // makeOrd which ends up calling boldsymbol.
  5371. // families
  5372. "mathbb": {
  5373. variant: "double-struck",
  5374. fontName: "AMS-Regular"
  5375. },
  5376. "mathcal": {
  5377. variant: "script",
  5378. fontName: "Caligraphic-Regular"
  5379. },
  5380. "mathfrak": {
  5381. variant: "fraktur",
  5382. fontName: "Fraktur-Regular"
  5383. },
  5384. "mathscr": {
  5385. variant: "script",
  5386. fontName: "Script-Regular"
  5387. },
  5388. "mathsf": {
  5389. variant: "sans-serif",
  5390. fontName: "SansSerif-Regular"
  5391. },
  5392. "mathtt": {
  5393. variant: "monospace",
  5394. fontName: "Typewriter-Regular"
  5395. }
  5396. };
  5397. var svgData = {
  5398. // path, width, height
  5399. vec: ["vec", 0.471, 0.714],
  5400. // values from the font glyph
  5401. oiintSize1: ["oiintSize1", 0.957, 0.499],
  5402. // oval to overlay the integrand
  5403. oiintSize2: ["oiintSize2", 1.472, 0.659],
  5404. oiiintSize1: ["oiiintSize1", 1.304, 0.499],
  5405. oiiintSize2: ["oiiintSize2", 1.98, 0.659]
  5406. };
  5407. var staticSvg = function staticSvg(value, options) {
  5408. // Create a span with inline SVG for the element.
  5409. var [pathName, width, height] = svgData[value];
  5410. var path = new PathNode(pathName);
  5411. var svgNode = new SvgNode([path], {
  5412. "width": makeEm(width),
  5413. "height": makeEm(height),
  5414. // Override CSS rule `.katex svg { width: 100% }`
  5415. "style": "width:" + makeEm(width),
  5416. "viewBox": "0 0 " + 1000 * width + " " + 1000 * height,
  5417. "preserveAspectRatio": "xMinYMin"
  5418. });
  5419. var span = makeSvgSpan(["overlay"], [svgNode], options);
  5420. span.height = height;
  5421. span.style.height = makeEm(height);
  5422. span.style.width = makeEm(width);
  5423. return span;
  5424. };
  5425. var buildCommon = {
  5426. fontMap,
  5427. makeSymbol,
  5428. mathsym,
  5429. makeSpan: makeSpan$2,
  5430. makeSvgSpan,
  5431. makeLineSpan,
  5432. makeAnchor,
  5433. makeFragment,
  5434. wrapFragment,
  5435. makeVList,
  5436. makeOrd,
  5437. makeGlue,
  5438. staticSvg,
  5439. svgData,
  5440. tryCombineChars
  5441. };
  5442. /**
  5443. * Describes spaces between different classes of atoms.
  5444. */
  5445. var thinspace = {
  5446. number: 3,
  5447. unit: "mu"
  5448. };
  5449. var mediumspace = {
  5450. number: 4,
  5451. unit: "mu"
  5452. };
  5453. var thickspace = {
  5454. number: 5,
  5455. unit: "mu"
  5456. }; // Making the type below exact with all optional fields doesn't work due to
  5457. // - https://github.com/facebook/flow/issues/4582
  5458. // - https://github.com/facebook/flow/issues/5688
  5459. // However, since *all* fields are optional, $Shape<> works as suggested in 5688
  5460. // above.
  5461. // Spacing relationships for display and text styles
  5462. var spacings = {
  5463. mord: {
  5464. mop: thinspace,
  5465. mbin: mediumspace,
  5466. mrel: thickspace,
  5467. minner: thinspace
  5468. },
  5469. mop: {
  5470. mord: thinspace,
  5471. mop: thinspace,
  5472. mrel: thickspace,
  5473. minner: thinspace
  5474. },
  5475. mbin: {
  5476. mord: mediumspace,
  5477. mop: mediumspace,
  5478. mopen: mediumspace,
  5479. minner: mediumspace
  5480. },
  5481. mrel: {
  5482. mord: thickspace,
  5483. mop: thickspace,
  5484. mopen: thickspace,
  5485. minner: thickspace
  5486. },
  5487. mopen: {},
  5488. mclose: {
  5489. mop: thinspace,
  5490. mbin: mediumspace,
  5491. mrel: thickspace,
  5492. minner: thinspace
  5493. },
  5494. mpunct: {
  5495. mord: thinspace,
  5496. mop: thinspace,
  5497. mrel: thickspace,
  5498. mopen: thinspace,
  5499. mclose: thinspace,
  5500. mpunct: thinspace,
  5501. minner: thinspace
  5502. },
  5503. minner: {
  5504. mord: thinspace,
  5505. mop: thinspace,
  5506. mbin: mediumspace,
  5507. mrel: thickspace,
  5508. mopen: thinspace,
  5509. mpunct: thinspace,
  5510. minner: thinspace
  5511. }
  5512. }; // Spacing relationships for script and scriptscript styles
  5513. var tightSpacings = {
  5514. mord: {
  5515. mop: thinspace
  5516. },
  5517. mop: {
  5518. mord: thinspace,
  5519. mop: thinspace
  5520. },
  5521. mbin: {},
  5522. mrel: {},
  5523. mopen: {},
  5524. mclose: {
  5525. mop: thinspace
  5526. },
  5527. mpunct: {},
  5528. minner: {
  5529. mop: thinspace
  5530. }
  5531. };
  5532. /** Context provided to function handlers for error messages. */
  5533. // Note: reverse the order of the return type union will cause a flow error.
  5534. // See https://github.com/facebook/flow/issues/3663.
  5535. // More general version of `HtmlBuilder` for nodes (e.g. \sum, accent types)
  5536. // whose presence impacts super/subscripting. In this case, ParseNode<"supsub">
  5537. // delegates its HTML building to the HtmlBuilder corresponding to these nodes.
  5538. /**
  5539. * Final function spec for use at parse time.
  5540. * This is almost identical to `FunctionPropSpec`, except it
  5541. * 1. includes the function handler, and
  5542. * 2. requires all arguments except argTypes.
  5543. * It is generated by `defineFunction()` below.
  5544. */
  5545. /**
  5546. * All registered functions.
  5547. * `functions.js` just exports this same dictionary again and makes it public.
  5548. * `Parser.js` requires this dictionary.
  5549. */
  5550. var _functions = {};
  5551. /**
  5552. * All HTML builders. Should be only used in the `define*` and the `build*ML`
  5553. * functions.
  5554. */
  5555. var _htmlGroupBuilders = {};
  5556. /**
  5557. * All MathML builders. Should be only used in the `define*` and the `build*ML`
  5558. * functions.
  5559. */
  5560. var _mathmlGroupBuilders = {};
  5561. function defineFunction(_ref) {
  5562. var {
  5563. type,
  5564. names,
  5565. props,
  5566. handler,
  5567. htmlBuilder,
  5568. mathmlBuilder
  5569. } = _ref;
  5570. // Set default values of functions
  5571. var data = {
  5572. type,
  5573. numArgs: props.numArgs,
  5574. argTypes: props.argTypes,
  5575. allowedInArgument: !!props.allowedInArgument,
  5576. allowedInText: !!props.allowedInText,
  5577. allowedInMath: props.allowedInMath === undefined ? true : props.allowedInMath,
  5578. numOptionalArgs: props.numOptionalArgs || 0,
  5579. infix: !!props.infix,
  5580. primitive: !!props.primitive,
  5581. handler: handler
  5582. };
  5583. for (var i = 0; i < names.length; ++i) {
  5584. _functions[names[i]] = data;
  5585. }
  5586. if (type) {
  5587. if (htmlBuilder) {
  5588. _htmlGroupBuilders[type] = htmlBuilder;
  5589. }
  5590. if (mathmlBuilder) {
  5591. _mathmlGroupBuilders[type] = mathmlBuilder;
  5592. }
  5593. }
  5594. }
  5595. /**
  5596. * Use this to register only the HTML and MathML builders for a function (e.g.
  5597. * if the function's ParseNode is generated in Parser.js rather than via a
  5598. * stand-alone handler provided to `defineFunction`).
  5599. */
  5600. function defineFunctionBuilders(_ref2) {
  5601. var {
  5602. type,
  5603. htmlBuilder,
  5604. mathmlBuilder
  5605. } = _ref2;
  5606. defineFunction({
  5607. type,
  5608. names: [],
  5609. props: {
  5610. numArgs: 0
  5611. },
  5612. handler() {
  5613. throw new Error('Should never be called.');
  5614. },
  5615. htmlBuilder,
  5616. mathmlBuilder
  5617. });
  5618. }
  5619. var normalizeArgument = function normalizeArgument(arg) {
  5620. return arg.type === "ordgroup" && arg.body.length === 1 ? arg.body[0] : arg;
  5621. }; // Since the corresponding buildHTML/buildMathML function expects a
  5622. // list of elements, we normalize for different kinds of arguments
  5623. var ordargument = function ordargument(arg) {
  5624. return arg.type === "ordgroup" ? arg.body : [arg];
  5625. };
  5626. /**
  5627. * This file does the main work of building a domTree structure from a parse
  5628. * tree. The entry point is the `buildHTML` function, which takes a parse tree.
  5629. * Then, the buildExpression, buildGroup, and various groupBuilders functions
  5630. * are called, to produce a final HTML tree.
  5631. */
  5632. var makeSpan$1 = buildCommon.makeSpan; // Binary atoms (first class `mbin`) change into ordinary atoms (`mord`)
  5633. // depending on their surroundings. See TeXbook pg. 442-446, Rules 5 and 6,
  5634. // and the text before Rule 19.
  5635. var binLeftCanceller = ["leftmost", "mbin", "mopen", "mrel", "mop", "mpunct"];
  5636. var binRightCanceller = ["rightmost", "mrel", "mclose", "mpunct"];
  5637. var styleMap$1 = {
  5638. "display": Style$1.DISPLAY,
  5639. "text": Style$1.TEXT,
  5640. "script": Style$1.SCRIPT,
  5641. "scriptscript": Style$1.SCRIPTSCRIPT
  5642. };
  5643. var DomEnum = {
  5644. mord: "mord",
  5645. mop: "mop",
  5646. mbin: "mbin",
  5647. mrel: "mrel",
  5648. mopen: "mopen",
  5649. mclose: "mclose",
  5650. mpunct: "mpunct",
  5651. minner: "minner"
  5652. };
  5653. /**
  5654. * Take a list of nodes, build them in order, and return a list of the built
  5655. * nodes. documentFragments are flattened into their contents, so the
  5656. * returned list contains no fragments. `isRealGroup` is true if `expression`
  5657. * is a real group (no atoms will be added on either side), as opposed to
  5658. * a partial group (e.g. one created by \color). `surrounding` is an array
  5659. * consisting type of nodes that will be added to the left and right.
  5660. */
  5661. var buildExpression$1 = function buildExpression(expression, options, isRealGroup, surrounding) {
  5662. if (surrounding === void 0) {
  5663. surrounding = [null, null];
  5664. }
  5665. // Parse expressions into `groups`.
  5666. var groups = [];
  5667. for (var i = 0; i < expression.length; i++) {
  5668. var output = buildGroup$1(expression[i], options);
  5669. if (output instanceof DocumentFragment) {
  5670. var children = output.children;
  5671. groups.push(...children);
  5672. } else {
  5673. groups.push(output);
  5674. }
  5675. } // Combine consecutive domTree.symbolNodes into a single symbolNode.
  5676. buildCommon.tryCombineChars(groups); // If `expression` is a partial group, let the parent handle spacings
  5677. // to avoid processing groups multiple times.
  5678. if (!isRealGroup) {
  5679. return groups;
  5680. }
  5681. var glueOptions = options;
  5682. if (expression.length === 1) {
  5683. var node = expression[0];
  5684. if (node.type === "sizing") {
  5685. glueOptions = options.havingSize(node.size);
  5686. } else if (node.type === "styling") {
  5687. glueOptions = options.havingStyle(styleMap$1[node.style]);
  5688. }
  5689. } // Dummy spans for determining spacings between surrounding atoms.
  5690. // If `expression` has no atoms on the left or right, class "leftmost"
  5691. // or "rightmost", respectively, is used to indicate it.
  5692. var dummyPrev = makeSpan$1([surrounding[0] || "leftmost"], [], options);
  5693. var dummyNext = makeSpan$1([surrounding[1] || "rightmost"], [], options); // TODO: These code assumes that a node's math class is the first element
  5694. // of its `classes` array. A later cleanup should ensure this, for
  5695. // instance by changing the signature of `makeSpan`.
  5696. // Before determining what spaces to insert, perform bin cancellation.
  5697. // Binary operators change to ordinary symbols in some contexts.
  5698. var isRoot = isRealGroup === "root";
  5699. traverseNonSpaceNodes(groups, (node, prev) => {
  5700. var prevType = prev.classes[0];
  5701. var type = node.classes[0];
  5702. if (prevType === "mbin" && utils.contains(binRightCanceller, type)) {
  5703. prev.classes[0] = "mord";
  5704. } else if (type === "mbin" && utils.contains(binLeftCanceller, prevType)) {
  5705. node.classes[0] = "mord";
  5706. }
  5707. }, {
  5708. node: dummyPrev
  5709. }, dummyNext, isRoot);
  5710. traverseNonSpaceNodes(groups, (node, prev) => {
  5711. var prevType = getTypeOfDomTree(prev);
  5712. var type = getTypeOfDomTree(node); // 'mtight' indicates that the node is script or scriptscript style.
  5713. var space = prevType && type ? node.hasClass("mtight") ? tightSpacings[prevType][type] : spacings[prevType][type] : null;
  5714. if (space) {
  5715. // Insert glue (spacing) after the `prev`.
  5716. return buildCommon.makeGlue(space, glueOptions);
  5717. }
  5718. }, {
  5719. node: dummyPrev
  5720. }, dummyNext, isRoot);
  5721. return groups;
  5722. }; // Depth-first traverse non-space `nodes`, calling `callback` with the current and
  5723. // previous node as arguments, optionally returning a node to insert after the
  5724. // previous node. `prev` is an object with the previous node and `insertAfter`
  5725. // function to insert after it. `next` is a node that will be added to the right.
  5726. // Used for bin cancellation and inserting spacings.
  5727. var traverseNonSpaceNodes = function traverseNonSpaceNodes(nodes, callback, prev, next, isRoot) {
  5728. if (next) {
  5729. // temporarily append the right node, if exists
  5730. nodes.push(next);
  5731. }
  5732. var i = 0;
  5733. for (; i < nodes.length; i++) {
  5734. var node = nodes[i];
  5735. var partialGroup = checkPartialGroup(node);
  5736. if (partialGroup) {
  5737. // Recursive DFS
  5738. // $FlowFixMe: make nodes a $ReadOnlyArray by returning a new array
  5739. traverseNonSpaceNodes(partialGroup.children, callback, prev, null, isRoot);
  5740. continue;
  5741. } // Ignore explicit spaces (e.g., \;, \,) when determining what implicit
  5742. // spacing should go between atoms of different classes
  5743. var nonspace = !node.hasClass("mspace");
  5744. if (nonspace) {
  5745. var result = callback(node, prev.node);
  5746. if (result) {
  5747. if (prev.insertAfter) {
  5748. prev.insertAfter(result);
  5749. } else {
  5750. // insert at front
  5751. nodes.unshift(result);
  5752. i++;
  5753. }
  5754. }
  5755. }
  5756. if (nonspace) {
  5757. prev.node = node;
  5758. } else if (isRoot && node.hasClass("newline")) {
  5759. prev.node = makeSpan$1(["leftmost"]); // treat like beginning of line
  5760. }
  5761. prev.insertAfter = (index => n => {
  5762. nodes.splice(index + 1, 0, n);
  5763. i++;
  5764. })(i);
  5765. }
  5766. if (next) {
  5767. nodes.pop();
  5768. }
  5769. }; // Check if given node is a partial group, i.e., does not affect spacing around.
  5770. var checkPartialGroup = function checkPartialGroup(node) {
  5771. if (node instanceof DocumentFragment || node instanceof Anchor || node instanceof Span && node.hasClass("enclosing")) {
  5772. return node;
  5773. }
  5774. return null;
  5775. }; // Return the outermost node of a domTree.
  5776. var getOutermostNode = function getOutermostNode(node, side) {
  5777. var partialGroup = checkPartialGroup(node);
  5778. if (partialGroup) {
  5779. var children = partialGroup.children;
  5780. if (children.length) {
  5781. if (side === "right") {
  5782. return getOutermostNode(children[children.length - 1], "right");
  5783. } else if (side === "left") {
  5784. return getOutermostNode(children[0], "left");
  5785. }
  5786. }
  5787. }
  5788. return node;
  5789. }; // Return math atom class (mclass) of a domTree.
  5790. // If `side` is given, it will get the type of the outermost node at given side.
  5791. var getTypeOfDomTree = function getTypeOfDomTree(node, side) {
  5792. if (!node) {
  5793. return null;
  5794. }
  5795. if (side) {
  5796. node = getOutermostNode(node, side);
  5797. } // This makes a lot of assumptions as to where the type of atom
  5798. // appears. We should do a better job of enforcing this.
  5799. return DomEnum[node.classes[0]] || null;
  5800. };
  5801. var makeNullDelimiter = function makeNullDelimiter(options, classes) {
  5802. var moreClasses = ["nulldelimiter"].concat(options.baseSizingClasses());
  5803. return makeSpan$1(classes.concat(moreClasses));
  5804. };
  5805. /**
  5806. * buildGroup is the function that takes a group and calls the correct groupType
  5807. * function for it. It also handles the interaction of size and style changes
  5808. * between parents and children.
  5809. */
  5810. var buildGroup$1 = function buildGroup(group, options, baseOptions) {
  5811. if (!group) {
  5812. return makeSpan$1();
  5813. }
  5814. if (_htmlGroupBuilders[group.type]) {
  5815. // Call the groupBuilders function
  5816. // $FlowFixMe
  5817. var groupNode = _htmlGroupBuilders[group.type](group, options); // If the size changed between the parent and the current group, account
  5818. // for that size difference.
  5819. if (baseOptions && options.size !== baseOptions.size) {
  5820. groupNode = makeSpan$1(options.sizingClasses(baseOptions), [groupNode], options);
  5821. var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier;
  5822. groupNode.height *= multiplier;
  5823. groupNode.depth *= multiplier;
  5824. }
  5825. return groupNode;
  5826. } else {
  5827. throw new ParseError("Got group of unknown type: '" + group.type + "'");
  5828. }
  5829. };
  5830. /**
  5831. * Combine an array of HTML DOM nodes (e.g., the output of `buildExpression`)
  5832. * into an unbreakable HTML node of class .base, with proper struts to
  5833. * guarantee correct vertical extent. `buildHTML` calls this repeatedly to
  5834. * make up the entire expression as a sequence of unbreakable units.
  5835. */
  5836. function buildHTMLUnbreakable(children, options) {
  5837. // Compute height and depth of this chunk.
  5838. var body = makeSpan$1(["base"], children, options); // Add strut, which ensures that the top of the HTML element falls at
  5839. // the height of the expression, and the bottom of the HTML element
  5840. // falls at the depth of the expression.
  5841. var strut = makeSpan$1(["strut"]);
  5842. strut.style.height = makeEm(body.height + body.depth);
  5843. if (body.depth) {
  5844. strut.style.verticalAlign = makeEm(-body.depth);
  5845. }
  5846. body.children.unshift(strut);
  5847. return body;
  5848. }
  5849. /**
  5850. * Take an entire parse tree, and build it into an appropriate set of HTML
  5851. * nodes.
  5852. */
  5853. function buildHTML(tree, options) {
  5854. // Strip off outer tag wrapper for processing below.
  5855. var tag = null;
  5856. if (tree.length === 1 && tree[0].type === "tag") {
  5857. tag = tree[0].tag;
  5858. tree = tree[0].body;
  5859. } // Build the expression contained in the tree
  5860. var expression = buildExpression$1(tree, options, "root");
  5861. var eqnNum;
  5862. if (expression.length === 2 && expression[1].hasClass("tag")) {
  5863. // An environment with automatic equation numbers, e.g. {gather}.
  5864. eqnNum = expression.pop();
  5865. }
  5866. var children = []; // Create one base node for each chunk between potential line breaks.
  5867. // The TeXBook [p.173] says "A formula will be broken only after a
  5868. // relation symbol like $=$ or $<$ or $\rightarrow$, or after a binary
  5869. // operation symbol like $+$ or $-$ or $\times$, where the relation or
  5870. // binary operation is on the ``outer level'' of the formula (i.e., not
  5871. // enclosed in {...} and not part of an \over construction)."
  5872. var parts = [];
  5873. for (var i = 0; i < expression.length; i++) {
  5874. parts.push(expression[i]);
  5875. if (expression[i].hasClass("mbin") || expression[i].hasClass("mrel") || expression[i].hasClass("allowbreak")) {
  5876. // Put any post-operator glue on same line as operator.
  5877. // Watch for \nobreak along the way, and stop at \newline.
  5878. var nobreak = false;
  5879. while (i < expression.length - 1 && expression[i + 1].hasClass("mspace") && !expression[i + 1].hasClass("newline")) {
  5880. i++;
  5881. parts.push(expression[i]);
  5882. if (expression[i].hasClass("nobreak")) {
  5883. nobreak = true;
  5884. }
  5885. } // Don't allow break if \nobreak among the post-operator glue.
  5886. if (!nobreak) {
  5887. children.push(buildHTMLUnbreakable(parts, options));
  5888. parts = [];
  5889. }
  5890. } else if (expression[i].hasClass("newline")) {
  5891. // Write the line except the newline
  5892. parts.pop();
  5893. if (parts.length > 0) {
  5894. children.push(buildHTMLUnbreakable(parts, options));
  5895. parts = [];
  5896. } // Put the newline at the top level
  5897. children.push(expression[i]);
  5898. }
  5899. }
  5900. if (parts.length > 0) {
  5901. children.push(buildHTMLUnbreakable(parts, options));
  5902. } // Now, if there was a tag, build it too and append it as a final child.
  5903. var tagChild;
  5904. if (tag) {
  5905. tagChild = buildHTMLUnbreakable(buildExpression$1(tag, options, true));
  5906. tagChild.classes = ["tag"];
  5907. children.push(tagChild);
  5908. } else if (eqnNum) {
  5909. children.push(eqnNum);
  5910. }
  5911. var htmlNode = makeSpan$1(["katex-html"], children);
  5912. htmlNode.setAttribute("aria-hidden", "true"); // Adjust the strut of the tag to be the maximum height of all children
  5913. // (the height of the enclosing htmlNode) for proper vertical alignment.
  5914. if (tagChild) {
  5915. var strut = tagChild.children[0];
  5916. strut.style.height = makeEm(htmlNode.height + htmlNode.depth);
  5917. if (htmlNode.depth) {
  5918. strut.style.verticalAlign = makeEm(-htmlNode.depth);
  5919. }
  5920. }
  5921. return htmlNode;
  5922. }
  5923. /**
  5924. * These objects store data about MathML nodes. This is the MathML equivalent
  5925. * of the types in domTree.js. Since MathML handles its own rendering, and
  5926. * since we're mainly using MathML to improve accessibility, we don't manage
  5927. * any of the styling state that the plain DOM nodes do.
  5928. *
  5929. * The `toNode` and `toMarkup` functions work simlarly to how they do in
  5930. * domTree.js, creating namespaced DOM nodes and HTML text markup respectively.
  5931. */
  5932. function newDocumentFragment(children) {
  5933. return new DocumentFragment(children);
  5934. }
  5935. /**
  5936. * This node represents a general purpose MathML node of any type. The
  5937. * constructor requires the type of node to create (for example, `"mo"` or
  5938. * `"mspace"`, corresponding to `<mo>` and `<mspace>` tags).
  5939. */
  5940. class MathNode {
  5941. constructor(type, children, classes) {
  5942. this.type = void 0;
  5943. this.attributes = void 0;
  5944. this.children = void 0;
  5945. this.classes = void 0;
  5946. this.type = type;
  5947. this.attributes = {};
  5948. this.children = children || [];
  5949. this.classes = classes || [];
  5950. }
  5951. /**
  5952. * Sets an attribute on a MathML node. MathML depends on attributes to convey a
  5953. * semantic content, so this is used heavily.
  5954. */
  5955. setAttribute(name, value) {
  5956. this.attributes[name] = value;
  5957. }
  5958. /**
  5959. * Gets an attribute on a MathML node.
  5960. */
  5961. getAttribute(name) {
  5962. return this.attributes[name];
  5963. }
  5964. /**
  5965. * Converts the math node into a MathML-namespaced DOM element.
  5966. */
  5967. toNode() {
  5968. var node = document.createElementNS("http://www.w3.org/1998/Math/MathML", this.type);
  5969. for (var attr in this.attributes) {
  5970. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  5971. node.setAttribute(attr, this.attributes[attr]);
  5972. }
  5973. }
  5974. if (this.classes.length > 0) {
  5975. node.className = createClass(this.classes);
  5976. }
  5977. for (var i = 0; i < this.children.length; i++) {
  5978. node.appendChild(this.children[i].toNode());
  5979. }
  5980. return node;
  5981. }
  5982. /**
  5983. * Converts the math node into an HTML markup string.
  5984. */
  5985. toMarkup() {
  5986. var markup = "<" + this.type; // Add the attributes
  5987. for (var attr in this.attributes) {
  5988. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  5989. markup += " " + attr + "=\"";
  5990. markup += utils.escape(this.attributes[attr]);
  5991. markup += "\"";
  5992. }
  5993. }
  5994. if (this.classes.length > 0) {
  5995. markup += " class =\"" + utils.escape(createClass(this.classes)) + "\"";
  5996. }
  5997. markup += ">";
  5998. for (var i = 0; i < this.children.length; i++) {
  5999. markup += this.children[i].toMarkup();
  6000. }
  6001. markup += "</" + this.type + ">";
  6002. return markup;
  6003. }
  6004. /**
  6005. * Converts the math node into a string, similar to innerText, but escaped.
  6006. */
  6007. toText() {
  6008. return this.children.map(child => child.toText()).join("");
  6009. }
  6010. }
  6011. /**
  6012. * This node represents a piece of text.
  6013. */
  6014. class TextNode {
  6015. constructor(text) {
  6016. this.text = void 0;
  6017. this.text = text;
  6018. }
  6019. /**
  6020. * Converts the text node into a DOM text node.
  6021. */
  6022. toNode() {
  6023. return document.createTextNode(this.text);
  6024. }
  6025. /**
  6026. * Converts the text node into escaped HTML markup
  6027. * (representing the text itself).
  6028. */
  6029. toMarkup() {
  6030. return utils.escape(this.toText());
  6031. }
  6032. /**
  6033. * Converts the text node into a string
  6034. * (representing the text iteself).
  6035. */
  6036. toText() {
  6037. return this.text;
  6038. }
  6039. }
  6040. /**
  6041. * This node represents a space, but may render as <mspace.../> or as text,
  6042. * depending on the width.
  6043. */
  6044. class SpaceNode {
  6045. /**
  6046. * Create a Space node with width given in CSS ems.
  6047. */
  6048. constructor(width) {
  6049. this.width = void 0;
  6050. this.character = void 0;
  6051. this.width = width; // See https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html
  6052. // for a table of space-like characters. We use Unicode
  6053. // representations instead of &LongNames; as it's not clear how to
  6054. // make the latter via document.createTextNode.
  6055. if (width >= 0.05555 && width <= 0.05556) {
  6056. this.character = "\u200a"; // &VeryThinSpace;
  6057. } else if (width >= 0.1666 && width <= 0.1667) {
  6058. this.character = "\u2009"; // &ThinSpace;
  6059. } else if (width >= 0.2222 && width <= 0.2223) {
  6060. this.character = "\u2005"; // &MediumSpace;
  6061. } else if (width >= 0.2777 && width <= 0.2778) {
  6062. this.character = "\u2005\u200a"; // &ThickSpace;
  6063. } else if (width >= -0.05556 && width <= -0.05555) {
  6064. this.character = "\u200a\u2063"; // &NegativeVeryThinSpace;
  6065. } else if (width >= -0.1667 && width <= -0.1666) {
  6066. this.character = "\u2009\u2063"; // &NegativeThinSpace;
  6067. } else if (width >= -0.2223 && width <= -0.2222) {
  6068. this.character = "\u205f\u2063"; // &NegativeMediumSpace;
  6069. } else if (width >= -0.2778 && width <= -0.2777) {
  6070. this.character = "\u2005\u2063"; // &NegativeThickSpace;
  6071. } else {
  6072. this.character = null;
  6073. }
  6074. }
  6075. /**
  6076. * Converts the math node into a MathML-namespaced DOM element.
  6077. */
  6078. toNode() {
  6079. if (this.character) {
  6080. return document.createTextNode(this.character);
  6081. } else {
  6082. var node = document.createElementNS("http://www.w3.org/1998/Math/MathML", "mspace");
  6083. node.setAttribute("width", makeEm(this.width));
  6084. return node;
  6085. }
  6086. }
  6087. /**
  6088. * Converts the math node into an HTML markup string.
  6089. */
  6090. toMarkup() {
  6091. if (this.character) {
  6092. return "<mtext>" + this.character + "</mtext>";
  6093. } else {
  6094. return "<mspace width=\"" + makeEm(this.width) + "\"/>";
  6095. }
  6096. }
  6097. /**
  6098. * Converts the math node into a string, similar to innerText.
  6099. */
  6100. toText() {
  6101. if (this.character) {
  6102. return this.character;
  6103. } else {
  6104. return " ";
  6105. }
  6106. }
  6107. }
  6108. var mathMLTree = {
  6109. MathNode,
  6110. TextNode,
  6111. SpaceNode,
  6112. newDocumentFragment
  6113. };
  6114. /**
  6115. * This file converts a parse tree into a cooresponding MathML tree. The main
  6116. * entry point is the `buildMathML` function, which takes a parse tree from the
  6117. * parser.
  6118. */
  6119. /**
  6120. * Takes a symbol and converts it into a MathML text node after performing
  6121. * optional replacement from symbols.js.
  6122. */
  6123. var makeText = function makeText(text, mode, options) {
  6124. if (symbols[mode][text] && symbols[mode][text].replace && text.charCodeAt(0) !== 0xD835 && !(ligatures.hasOwnProperty(text) && options && (options.fontFamily && options.fontFamily.slice(4, 6) === "tt" || options.font && options.font.slice(4, 6) === "tt"))) {
  6125. text = symbols[mode][text].replace;
  6126. }
  6127. return new mathMLTree.TextNode(text);
  6128. };
  6129. /**
  6130. * Wrap the given array of nodes in an <mrow> node if needed, i.e.,
  6131. * unless the array has length 1. Always returns a single node.
  6132. */
  6133. var makeRow = function makeRow(body) {
  6134. if (body.length === 1) {
  6135. return body[0];
  6136. } else {
  6137. return new mathMLTree.MathNode("mrow", body);
  6138. }
  6139. };
  6140. /**
  6141. * Returns the math variant as a string or null if none is required.
  6142. */
  6143. var getVariant = function getVariant(group, options) {
  6144. // Handle \text... font specifiers as best we can.
  6145. // MathML has a limited list of allowable mathvariant specifiers; see
  6146. // https://www.w3.org/TR/MathML3/chapter3.html#presm.commatt
  6147. if (options.fontFamily === "texttt") {
  6148. return "monospace";
  6149. } else if (options.fontFamily === "textsf") {
  6150. if (options.fontShape === "textit" && options.fontWeight === "textbf") {
  6151. return "sans-serif-bold-italic";
  6152. } else if (options.fontShape === "textit") {
  6153. return "sans-serif-italic";
  6154. } else if (options.fontWeight === "textbf") {
  6155. return "bold-sans-serif";
  6156. } else {
  6157. return "sans-serif";
  6158. }
  6159. } else if (options.fontShape === "textit" && options.fontWeight === "textbf") {
  6160. return "bold-italic";
  6161. } else if (options.fontShape === "textit") {
  6162. return "italic";
  6163. } else if (options.fontWeight === "textbf") {
  6164. return "bold";
  6165. }
  6166. var font = options.font;
  6167. if (!font || font === "mathnormal") {
  6168. return null;
  6169. }
  6170. var mode = group.mode;
  6171. if (font === "mathit") {
  6172. return "italic";
  6173. } else if (font === "boldsymbol") {
  6174. return group.type === "textord" ? "bold" : "bold-italic";
  6175. } else if (font === "mathbf") {
  6176. return "bold";
  6177. } else if (font === "mathbb") {
  6178. return "double-struck";
  6179. } else if (font === "mathfrak") {
  6180. return "fraktur";
  6181. } else if (font === "mathscr" || font === "mathcal") {
  6182. // MathML makes no distinction between script and caligrahpic
  6183. return "script";
  6184. } else if (font === "mathsf") {
  6185. return "sans-serif";
  6186. } else if (font === "mathtt") {
  6187. return "monospace";
  6188. }
  6189. var text = group.text;
  6190. if (utils.contains(["\\imath", "\\jmath"], text)) {
  6191. return null;
  6192. }
  6193. if (symbols[mode][text] && symbols[mode][text].replace) {
  6194. text = symbols[mode][text].replace;
  6195. }
  6196. var fontName = buildCommon.fontMap[font].fontName;
  6197. if (getCharacterMetrics(text, fontName, mode)) {
  6198. return buildCommon.fontMap[font].variant;
  6199. }
  6200. return null;
  6201. };
  6202. /**
  6203. * Takes a list of nodes, builds them, and returns a list of the generated
  6204. * MathML nodes. Also combine consecutive <mtext> outputs into a single
  6205. * <mtext> tag.
  6206. */
  6207. var buildExpression = function buildExpression(expression, options, isOrdgroup) {
  6208. if (expression.length === 1) {
  6209. var group = buildGroup(expression[0], options);
  6210. if (isOrdgroup && group instanceof MathNode && group.type === "mo") {
  6211. // When TeX writers want to suppress spacing on an operator,
  6212. // they often put the operator by itself inside braces.
  6213. group.setAttribute("lspace", "0em");
  6214. group.setAttribute("rspace", "0em");
  6215. }
  6216. return [group];
  6217. }
  6218. var groups = [];
  6219. var lastGroup;
  6220. for (var i = 0; i < expression.length; i++) {
  6221. var _group = buildGroup(expression[i], options);
  6222. if (_group instanceof MathNode && lastGroup instanceof MathNode) {
  6223. // Concatenate adjacent <mtext>s
  6224. if (_group.type === 'mtext' && lastGroup.type === 'mtext' && _group.getAttribute('mathvariant') === lastGroup.getAttribute('mathvariant')) {
  6225. lastGroup.children.push(..._group.children);
  6226. continue; // Concatenate adjacent <mn>s
  6227. } else if (_group.type === 'mn' && lastGroup.type === 'mn') {
  6228. lastGroup.children.push(..._group.children);
  6229. continue; // Concatenate <mn>...</mn> followed by <mi>.</mi>
  6230. } else if (_group.type === 'mi' && _group.children.length === 1 && lastGroup.type === 'mn') {
  6231. var child = _group.children[0];
  6232. if (child instanceof TextNode && child.text === '.') {
  6233. lastGroup.children.push(..._group.children);
  6234. continue;
  6235. }
  6236. } else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
  6237. var lastChild = lastGroup.children[0];
  6238. if (lastChild instanceof TextNode && lastChild.text === '\u0338' && (_group.type === 'mo' || _group.type === 'mi' || _group.type === 'mn')) {
  6239. var _child = _group.children[0];
  6240. if (_child instanceof TextNode && _child.text.length > 0) {
  6241. // Overlay with combining character long solidus
  6242. _child.text = _child.text.slice(0, 1) + "\u0338" + _child.text.slice(1);
  6243. groups.pop();
  6244. }
  6245. }
  6246. }
  6247. }
  6248. groups.push(_group);
  6249. lastGroup = _group;
  6250. }
  6251. return groups;
  6252. };
  6253. /**
  6254. * Equivalent to buildExpression, but wraps the elements in an <mrow>
  6255. * if there's more than one. Returns a single node instead of an array.
  6256. */
  6257. var buildExpressionRow = function buildExpressionRow(expression, options, isOrdgroup) {
  6258. return makeRow(buildExpression(expression, options, isOrdgroup));
  6259. };
  6260. /**
  6261. * Takes a group from the parser and calls the appropriate groupBuilders function
  6262. * on it to produce a MathML node.
  6263. */
  6264. var buildGroup = function buildGroup(group, options) {
  6265. if (!group) {
  6266. return new mathMLTree.MathNode("mrow");
  6267. }
  6268. if (_mathmlGroupBuilders[group.type]) {
  6269. // Call the groupBuilders function
  6270. // $FlowFixMe
  6271. var result = _mathmlGroupBuilders[group.type](group, options); // $FlowFixMe
  6272. return result;
  6273. } else {
  6274. throw new ParseError("Got group of unknown type: '" + group.type + "'");
  6275. }
  6276. };
  6277. /**
  6278. * Takes a full parse tree and settings and builds a MathML representation of
  6279. * it. In particular, we put the elements from building the parse tree into a
  6280. * <semantics> tag so we can also include that TeX source as an annotation.
  6281. *
  6282. * Note that we actually return a domTree element with a `<math>` inside it so
  6283. * we can do appropriate styling.
  6284. */
  6285. function buildMathML(tree, texExpression, options, isDisplayMode, forMathmlOnly) {
  6286. var expression = buildExpression(tree, options); // TODO: Make a pass thru the MathML similar to buildHTML.traverseNonSpaceNodes
  6287. // and add spacing nodes. This is necessary only adjacent to math operators
  6288. // like \sin or \lim or to subsup elements that contain math operators.
  6289. // MathML takes care of the other spacing issues.
  6290. // Wrap up the expression in an mrow so it is presented in the semantics
  6291. // tag correctly, unless it's a single <mrow> or <mtable>.
  6292. var wrapper;
  6293. if (expression.length === 1 && expression[0] instanceof MathNode && utils.contains(["mrow", "mtable"], expression[0].type)) {
  6294. wrapper = expression[0];
  6295. } else {
  6296. wrapper = new mathMLTree.MathNode("mrow", expression);
  6297. } // Build a TeX annotation of the source
  6298. var annotation = new mathMLTree.MathNode("annotation", [new mathMLTree.TextNode(texExpression)]);
  6299. annotation.setAttribute("encoding", "application/x-tex");
  6300. var semantics = new mathMLTree.MathNode("semantics", [wrapper, annotation]);
  6301. var math = new mathMLTree.MathNode("math", [semantics]);
  6302. math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
  6303. if (isDisplayMode) {
  6304. math.setAttribute("display", "block");
  6305. } // You can't style <math> nodes, so we wrap the node in a span.
  6306. // NOTE: The span class is not typed to have <math> nodes as children, and
  6307. // we don't want to make the children type more generic since the children
  6308. // of span are expected to have more fields in `buildHtml` contexts.
  6309. var wrapperClass = forMathmlOnly ? "katex" : "katex-mathml"; // $FlowFixMe
  6310. return buildCommon.makeSpan([wrapperClass], [math]);
  6311. }
  6312. var optionsFromSettings = function optionsFromSettings(settings) {
  6313. return new Options({
  6314. style: settings.displayMode ? Style$1.DISPLAY : Style$1.TEXT,
  6315. maxSize: settings.maxSize,
  6316. minRuleThickness: settings.minRuleThickness
  6317. });
  6318. };
  6319. var displayWrap = function displayWrap(node, settings) {
  6320. if (settings.displayMode) {
  6321. var classes = ["katex-display"];
  6322. if (settings.leqno) {
  6323. classes.push("leqno");
  6324. }
  6325. if (settings.fleqn) {
  6326. classes.push("fleqn");
  6327. }
  6328. node = buildCommon.makeSpan(classes, [node]);
  6329. }
  6330. return node;
  6331. };
  6332. var buildTree = function buildTree(tree, expression, settings) {
  6333. var options = optionsFromSettings(settings);
  6334. var katexNode;
  6335. if (settings.output === "mathml") {
  6336. return buildMathML(tree, expression, options, settings.displayMode, true);
  6337. } else if (settings.output === "html") {
  6338. var htmlNode = buildHTML(tree, options);
  6339. katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
  6340. } else {
  6341. var mathMLNode = buildMathML(tree, expression, options, settings.displayMode, false);
  6342. var _htmlNode = buildHTML(tree, options);
  6343. katexNode = buildCommon.makeSpan(["katex"], [mathMLNode, _htmlNode]);
  6344. }
  6345. return displayWrap(katexNode, settings);
  6346. };
  6347. var buildHTMLTree = function buildHTMLTree(tree, expression, settings) {
  6348. var options = optionsFromSettings(settings);
  6349. var htmlNode = buildHTML(tree, options);
  6350. var katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);
  6351. return displayWrap(katexNode, settings);
  6352. };
  6353. /**
  6354. * This file provides support to buildMathML.js and buildHTML.js
  6355. * for stretchy wide elements rendered from SVG files
  6356. * and other CSS trickery.
  6357. */
  6358. var stretchyCodePoint = {
  6359. widehat: "^",
  6360. widecheck: "ˇ",
  6361. widetilde: "~",
  6362. utilde: "~",
  6363. overleftarrow: "\u2190",
  6364. underleftarrow: "\u2190",
  6365. xleftarrow: "\u2190",
  6366. overrightarrow: "\u2192",
  6367. underrightarrow: "\u2192",
  6368. xrightarrow: "\u2192",
  6369. underbrace: "\u23df",
  6370. overbrace: "\u23de",
  6371. overgroup: "\u23e0",
  6372. undergroup: "\u23e1",
  6373. overleftrightarrow: "\u2194",
  6374. underleftrightarrow: "\u2194",
  6375. xleftrightarrow: "\u2194",
  6376. Overrightarrow: "\u21d2",
  6377. xRightarrow: "\u21d2",
  6378. overleftharpoon: "\u21bc",
  6379. xleftharpoonup: "\u21bc",
  6380. overrightharpoon: "\u21c0",
  6381. xrightharpoonup: "\u21c0",
  6382. xLeftarrow: "\u21d0",
  6383. xLeftrightarrow: "\u21d4",
  6384. xhookleftarrow: "\u21a9",
  6385. xhookrightarrow: "\u21aa",
  6386. xmapsto: "\u21a6",
  6387. xrightharpoondown: "\u21c1",
  6388. xleftharpoondown: "\u21bd",
  6389. xrightleftharpoons: "\u21cc",
  6390. xleftrightharpoons: "\u21cb",
  6391. xtwoheadleftarrow: "\u219e",
  6392. xtwoheadrightarrow: "\u21a0",
  6393. xlongequal: "=",
  6394. xtofrom: "\u21c4",
  6395. xrightleftarrows: "\u21c4",
  6396. xrightequilibrium: "\u21cc",
  6397. // Not a perfect match.
  6398. xleftequilibrium: "\u21cb",
  6399. // None better available.
  6400. "\\cdrightarrow": "\u2192",
  6401. "\\cdleftarrow": "\u2190",
  6402. "\\cdlongequal": "="
  6403. };
  6404. var mathMLnode = function mathMLnode(label) {
  6405. var node = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode(stretchyCodePoint[label.replace(/^\\/, '')])]);
  6406. node.setAttribute("stretchy", "true");
  6407. return node;
  6408. }; // Many of the KaTeX SVG images have been adapted from glyphs in KaTeX fonts.
  6409. // Copyright (c) 2009-2010, Design Science, Inc. (<www.mathjax.org>)
  6410. // Copyright (c) 2014-2017 Khan Academy (<www.khanacademy.org>)
  6411. // Licensed under the SIL Open Font License, Version 1.1.
  6412. // See \nhttp://scripts.sil.org/OFL
  6413. // Very Long SVGs
  6414. // Many of the KaTeX stretchy wide elements use a long SVG image and an
  6415. // overflow: hidden tactic to achieve a stretchy image while avoiding
  6416. // distortion of arrowheads or brace corners.
  6417. // The SVG typically contains a very long (400 em) arrow.
  6418. // The SVG is in a container span that has overflow: hidden, so the span
  6419. // acts like a window that exposes only part of the SVG.
  6420. // The SVG always has a longer, thinner aspect ratio than the container span.
  6421. // After the SVG fills 100% of the height of the container span,
  6422. // there is a long arrow shaft left over. That left-over shaft is not shown.
  6423. // Instead, it is sliced off because the span's CSS has overflow: hidden.
  6424. // Thus, the reader sees an arrow that matches the subject matter width
  6425. // without distortion.
  6426. // Some functions, such as \cancel, need to vary their aspect ratio. These
  6427. // functions do not get the overflow SVG treatment.
  6428. // Second Brush Stroke
  6429. // Low resolution monitors struggle to display images in fine detail.
  6430. // So browsers apply anti-aliasing. A long straight arrow shaft therefore
  6431. // will sometimes appear as if it has a blurred edge.
  6432. // To mitigate this, these SVG files contain a second "brush-stroke" on the
  6433. // arrow shafts. That is, a second long thin rectangular SVG path has been
  6434. // written directly on top of each arrow shaft. This reinforcement causes
  6435. // some of the screen pixels to display as black instead of the anti-aliased
  6436. // gray pixel that a single path would generate. So we get arrow shafts
  6437. // whose edges appear to be sharper.
  6438. // In the katexImagesData object just below, the dimensions all
  6439. // correspond to path geometry inside the relevant SVG.
  6440. // For example, \overrightarrow uses the same arrowhead as glyph U+2192
  6441. // from the KaTeX Main font. The scaling factor is 1000.
  6442. // That is, inside the font, that arrowhead is 522 units tall, which
  6443. // corresponds to 0.522 em inside the document.
  6444. var katexImagesData = {
  6445. // path(s), minWidth, height, align
  6446. overrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
  6447. overleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
  6448. underrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
  6449. underleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
  6450. xrightarrow: [["rightarrow"], 1.469, 522, "xMaxYMin"],
  6451. "\\cdrightarrow": [["rightarrow"], 3.0, 522, "xMaxYMin"],
  6452. // CD minwwidth2.5pc
  6453. xleftarrow: [["leftarrow"], 1.469, 522, "xMinYMin"],
  6454. "\\cdleftarrow": [["leftarrow"], 3.0, 522, "xMinYMin"],
  6455. Overrightarrow: [["doublerightarrow"], 0.888, 560, "xMaxYMin"],
  6456. xRightarrow: [["doublerightarrow"], 1.526, 560, "xMaxYMin"],
  6457. xLeftarrow: [["doubleleftarrow"], 1.526, 560, "xMinYMin"],
  6458. overleftharpoon: [["leftharpoon"], 0.888, 522, "xMinYMin"],
  6459. xleftharpoonup: [["leftharpoon"], 0.888, 522, "xMinYMin"],
  6460. xleftharpoondown: [["leftharpoondown"], 0.888, 522, "xMinYMin"],
  6461. overrightharpoon: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
  6462. xrightharpoonup: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
  6463. xrightharpoondown: [["rightharpoondown"], 0.888, 522, "xMaxYMin"],
  6464. xlongequal: [["longequal"], 0.888, 334, "xMinYMin"],
  6465. "\\cdlongequal": [["longequal"], 3.0, 334, "xMinYMin"],
  6466. xtwoheadleftarrow: [["twoheadleftarrow"], 0.888, 334, "xMinYMin"],
  6467. xtwoheadrightarrow: [["twoheadrightarrow"], 0.888, 334, "xMaxYMin"],
  6468. overleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
  6469. overbrace: [["leftbrace", "midbrace", "rightbrace"], 1.6, 548],
  6470. underbrace: [["leftbraceunder", "midbraceunder", "rightbraceunder"], 1.6, 548],
  6471. underleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
  6472. xleftrightarrow: [["leftarrow", "rightarrow"], 1.75, 522],
  6473. xLeftrightarrow: [["doubleleftarrow", "doublerightarrow"], 1.75, 560],
  6474. xrightleftharpoons: [["leftharpoondownplus", "rightharpoonplus"], 1.75, 716],
  6475. xleftrightharpoons: [["leftharpoonplus", "rightharpoondownplus"], 1.75, 716],
  6476. xhookleftarrow: [["leftarrow", "righthook"], 1.08, 522],
  6477. xhookrightarrow: [["lefthook", "rightarrow"], 1.08, 522],
  6478. overlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
  6479. underlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
  6480. overgroup: [["leftgroup", "rightgroup"], 0.888, 342],
  6481. undergroup: [["leftgroupunder", "rightgroupunder"], 0.888, 342],
  6482. xmapsto: [["leftmapsto", "rightarrow"], 1.5, 522],
  6483. xtofrom: [["leftToFrom", "rightToFrom"], 1.75, 528],
  6484. // The next three arrows are from the mhchem package.
  6485. // In mhchem.sty, min-length is 2.0em. But these arrows might appear in the
  6486. // document as \xrightarrow or \xrightleftharpoons. Those have
  6487. // min-length = 1.75em, so we set min-length on these next three to match.
  6488. xrightleftarrows: [["baraboveleftarrow", "rightarrowabovebar"], 1.75, 901],
  6489. xrightequilibrium: [["baraboveshortleftharpoon", "rightharpoonaboveshortbar"], 1.75, 716],
  6490. xleftequilibrium: [["shortbaraboveleftharpoon", "shortrightharpoonabovebar"], 1.75, 716]
  6491. };
  6492. var groupLength = function groupLength(arg) {
  6493. if (arg.type === "ordgroup") {
  6494. return arg.body.length;
  6495. } else {
  6496. return 1;
  6497. }
  6498. };
  6499. var svgSpan = function svgSpan(group, options) {
  6500. // Create a span with inline SVG for the element.
  6501. function buildSvgSpan_() {
  6502. var viewBoxWidth = 400000; // default
  6503. var label = group.label.slice(1);
  6504. if (utils.contains(["widehat", "widecheck", "widetilde", "utilde"], label)) {
  6505. // Each type in the `if` statement corresponds to one of the ParseNode
  6506. // types below. This narrowing is required to access `grp.base`.
  6507. // $FlowFixMe
  6508. var grp = group; // There are four SVG images available for each function.
  6509. // Choose a taller image when there are more characters.
  6510. var numChars = groupLength(grp.base);
  6511. var viewBoxHeight;
  6512. var pathName;
  6513. var _height;
  6514. if (numChars > 5) {
  6515. if (label === "widehat" || label === "widecheck") {
  6516. viewBoxHeight = 420;
  6517. viewBoxWidth = 2364;
  6518. _height = 0.42;
  6519. pathName = label + "4";
  6520. } else {
  6521. viewBoxHeight = 312;
  6522. viewBoxWidth = 2340;
  6523. _height = 0.34;
  6524. pathName = "tilde4";
  6525. }
  6526. } else {
  6527. var imgIndex = [1, 1, 2, 2, 3, 3][numChars];
  6528. if (label === "widehat" || label === "widecheck") {
  6529. viewBoxWidth = [0, 1062, 2364, 2364, 2364][imgIndex];
  6530. viewBoxHeight = [0, 239, 300, 360, 420][imgIndex];
  6531. _height = [0, 0.24, 0.3, 0.3, 0.36, 0.42][imgIndex];
  6532. pathName = label + imgIndex;
  6533. } else {
  6534. viewBoxWidth = [0, 600, 1033, 2339, 2340][imgIndex];
  6535. viewBoxHeight = [0, 260, 286, 306, 312][imgIndex];
  6536. _height = [0, 0.26, 0.286, 0.3, 0.306, 0.34][imgIndex];
  6537. pathName = "tilde" + imgIndex;
  6538. }
  6539. }
  6540. var path = new PathNode(pathName);
  6541. var svgNode = new SvgNode([path], {
  6542. "width": "100%",
  6543. "height": makeEm(_height),
  6544. "viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight,
  6545. "preserveAspectRatio": "none"
  6546. });
  6547. return {
  6548. span: buildCommon.makeSvgSpan([], [svgNode], options),
  6549. minWidth: 0,
  6550. height: _height
  6551. };
  6552. } else {
  6553. var spans = [];
  6554. var data = katexImagesData[label];
  6555. var [paths, _minWidth, _viewBoxHeight] = data;
  6556. var _height2 = _viewBoxHeight / 1000;
  6557. var numSvgChildren = paths.length;
  6558. var widthClasses;
  6559. var aligns;
  6560. if (numSvgChildren === 1) {
  6561. // $FlowFixMe: All these cases must be of the 4-tuple type.
  6562. var align1 = data[3];
  6563. widthClasses = ["hide-tail"];
  6564. aligns = [align1];
  6565. } else if (numSvgChildren === 2) {
  6566. widthClasses = ["halfarrow-left", "halfarrow-right"];
  6567. aligns = ["xMinYMin", "xMaxYMin"];
  6568. } else if (numSvgChildren === 3) {
  6569. widthClasses = ["brace-left", "brace-center", "brace-right"];
  6570. aligns = ["xMinYMin", "xMidYMin", "xMaxYMin"];
  6571. } else {
  6572. throw new Error("Correct katexImagesData or update code here to support\n " + numSvgChildren + " children.");
  6573. }
  6574. for (var i = 0; i < numSvgChildren; i++) {
  6575. var _path = new PathNode(paths[i]);
  6576. var _svgNode = new SvgNode([_path], {
  6577. "width": "400em",
  6578. "height": makeEm(_height2),
  6579. "viewBox": "0 0 " + viewBoxWidth + " " + _viewBoxHeight,
  6580. "preserveAspectRatio": aligns[i] + " slice"
  6581. });
  6582. var _span = buildCommon.makeSvgSpan([widthClasses[i]], [_svgNode], options);
  6583. if (numSvgChildren === 1) {
  6584. return {
  6585. span: _span,
  6586. minWidth: _minWidth,
  6587. height: _height2
  6588. };
  6589. } else {
  6590. _span.style.height = makeEm(_height2);
  6591. spans.push(_span);
  6592. }
  6593. }
  6594. return {
  6595. span: buildCommon.makeSpan(["stretchy"], spans, options),
  6596. minWidth: _minWidth,
  6597. height: _height2
  6598. };
  6599. }
  6600. } // buildSvgSpan_()
  6601. var {
  6602. span,
  6603. minWidth,
  6604. height
  6605. } = buildSvgSpan_(); // Note that we are returning span.depth = 0.
  6606. // Any adjustments relative to the baseline must be done in buildHTML.
  6607. span.height = height;
  6608. span.style.height = makeEm(height);
  6609. if (minWidth > 0) {
  6610. span.style.minWidth = makeEm(minWidth);
  6611. }
  6612. return span;
  6613. };
  6614. var encloseSpan = function encloseSpan(inner, label, topPad, bottomPad, options) {
  6615. // Return an image span for \cancel, \bcancel, \xcancel, \fbox, or \angl
  6616. var img;
  6617. var totalHeight = inner.height + inner.depth + topPad + bottomPad;
  6618. if (/fbox|color|angl/.test(label)) {
  6619. img = buildCommon.makeSpan(["stretchy", label], [], options);
  6620. if (label === "fbox") {
  6621. var color = options.color && options.getColor();
  6622. if (color) {
  6623. img.style.borderColor = color;
  6624. }
  6625. }
  6626. } else {
  6627. // \cancel, \bcancel, or \xcancel
  6628. // Since \cancel's SVG is inline and it omits the viewBox attribute,
  6629. // its stroke-width will not vary with span area.
  6630. var lines = [];
  6631. if (/^[bx]cancel$/.test(label)) {
  6632. lines.push(new LineNode({
  6633. "x1": "0",
  6634. "y1": "0",
  6635. "x2": "100%",
  6636. "y2": "100%",
  6637. "stroke-width": "0.046em"
  6638. }));
  6639. }
  6640. if (/^x?cancel$/.test(label)) {
  6641. lines.push(new LineNode({
  6642. "x1": "0",
  6643. "y1": "100%",
  6644. "x2": "100%",
  6645. "y2": "0",
  6646. "stroke-width": "0.046em"
  6647. }));
  6648. }
  6649. var svgNode = new SvgNode(lines, {
  6650. "width": "100%",
  6651. "height": makeEm(totalHeight)
  6652. });
  6653. img = buildCommon.makeSvgSpan([], [svgNode], options);
  6654. }
  6655. img.height = totalHeight;
  6656. img.style.height = makeEm(totalHeight);
  6657. return img;
  6658. };
  6659. var stretchy = {
  6660. encloseSpan,
  6661. mathMLnode,
  6662. svgSpan
  6663. };
  6664. /**
  6665. * Asserts that the node is of the given type and returns it with stricter
  6666. * typing. Throws if the node's type does not match.
  6667. */
  6668. function assertNodeType(node, type) {
  6669. if (!node || node.type !== type) {
  6670. throw new Error("Expected node of type " + type + ", but got " + (node ? "node of type " + node.type : String(node)));
  6671. } // $FlowFixMe, >=0.125
  6672. return node;
  6673. }
  6674. /**
  6675. * Returns the node more strictly typed iff it is of the given type. Otherwise,
  6676. * returns null.
  6677. */
  6678. function assertSymbolNodeType(node) {
  6679. var typedNode = checkSymbolNodeType(node);
  6680. if (!typedNode) {
  6681. throw new Error("Expected node of symbol group type, but got " + (node ? "node of type " + node.type : String(node)));
  6682. }
  6683. return typedNode;
  6684. }
  6685. /**
  6686. * Returns the node more strictly typed iff it is of the given type. Otherwise,
  6687. * returns null.
  6688. */
  6689. function checkSymbolNodeType(node) {
  6690. if (node && (node.type === "atom" || NON_ATOMS.hasOwnProperty(node.type))) {
  6691. // $FlowFixMe
  6692. return node;
  6693. }
  6694. return null;
  6695. }
  6696. // NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
  6697. // also "supsub" since an accent can affect super/subscripting.
  6698. var htmlBuilder$a = (grp, options) => {
  6699. // Accents are handled in the TeXbook pg. 443, rule 12.
  6700. var base;
  6701. var group;
  6702. var supSubGroup;
  6703. if (grp && grp.type === "supsub") {
  6704. // If our base is a character box, and we have superscripts and
  6705. // subscripts, the supsub will defer to us. In particular, we want
  6706. // to attach the superscripts and subscripts to the inner body (so
  6707. // that the position of the superscripts and subscripts won't be
  6708. // affected by the height of the accent). We accomplish this by
  6709. // sticking the base of the accent into the base of the supsub, and
  6710. // rendering that, while keeping track of where the accent is.
  6711. // The real accent group is the base of the supsub group
  6712. group = assertNodeType(grp.base, "accent"); // The character box is the base of the accent group
  6713. base = group.base; // Stick the character box into the base of the supsub group
  6714. grp.base = base; // Rerender the supsub group with its new base, and store that
  6715. // result.
  6716. supSubGroup = assertSpan(buildGroup$1(grp, options)); // reset original base
  6717. grp.base = group;
  6718. } else {
  6719. group = assertNodeType(grp, "accent");
  6720. base = group.base;
  6721. } // Build the base group
  6722. var body = buildGroup$1(base, options.havingCrampedStyle()); // Does the accent need to shift for the skew of a character?
  6723. var mustShift = group.isShifty && utils.isCharacterBox(base); // Calculate the skew of the accent. This is based on the line "If the
  6724. // nucleus is not a single character, let s = 0; otherwise set s to the
  6725. // kern amount for the nucleus followed by the \skewchar of its font."
  6726. // Note that our skew metrics are just the kern between each character
  6727. // and the skewchar.
  6728. var skew = 0;
  6729. if (mustShift) {
  6730. // If the base is a character box, then we want the skew of the
  6731. // innermost character. To do that, we find the innermost character:
  6732. var baseChar = utils.getBaseElem(base); // Then, we render its group to get the symbol inside it
  6733. var baseGroup = buildGroup$1(baseChar, options.havingCrampedStyle()); // Finally, we pull the skew off of the symbol.
  6734. skew = assertSymbolDomNode(baseGroup).skew; // Note that we now throw away baseGroup, because the layers we
  6735. // removed with getBaseElem might contain things like \color which
  6736. // we can't get rid of.
  6737. // TODO(emily): Find a better way to get the skew
  6738. }
  6739. var accentBelow = group.label === "\\c"; // calculate the amount of space between the body and the accent
  6740. var clearance = accentBelow ? body.height + body.depth : Math.min(body.height, options.fontMetrics().xHeight); // Build the accent
  6741. var accentBody;
  6742. if (!group.isStretchy) {
  6743. var accent;
  6744. var width;
  6745. if (group.label === "\\vec") {
  6746. // Before version 0.9, \vec used the combining font glyph U+20D7.
  6747. // But browsers, especially Safari, are not consistent in how they
  6748. // render combining characters when not preceded by a character.
  6749. // So now we use an SVG.
  6750. // If Safari reforms, we should consider reverting to the glyph.
  6751. accent = buildCommon.staticSvg("vec", options);
  6752. width = buildCommon.svgData.vec[1];
  6753. } else {
  6754. accent = buildCommon.makeOrd({
  6755. mode: group.mode,
  6756. text: group.label
  6757. }, options, "textord");
  6758. accent = assertSymbolDomNode(accent); // Remove the italic correction of the accent, because it only serves to
  6759. // shift the accent over to a place we don't want.
  6760. accent.italic = 0;
  6761. width = accent.width;
  6762. if (accentBelow) {
  6763. clearance += accent.depth;
  6764. }
  6765. }
  6766. accentBody = buildCommon.makeSpan(["accent-body"], [accent]); // "Full" accents expand the width of the resulting symbol to be
  6767. // at least the width of the accent, and overlap directly onto the
  6768. // character without any vertical offset.
  6769. var accentFull = group.label === "\\textcircled";
  6770. if (accentFull) {
  6771. accentBody.classes.push('accent-full');
  6772. clearance = body.height;
  6773. } // Shift the accent over by the skew.
  6774. var left = skew; // CSS defines `.katex .accent .accent-body:not(.accent-full) { width: 0 }`
  6775. // so that the accent doesn't contribute to the bounding box.
  6776. // We need to shift the character by its width (effectively half
  6777. // its width) to compensate.
  6778. if (!accentFull) {
  6779. left -= width / 2;
  6780. }
  6781. accentBody.style.left = makeEm(left); // \textcircled uses the \bigcirc glyph, so it needs some
  6782. // vertical adjustment to match LaTeX.
  6783. if (group.label === "\\textcircled") {
  6784. accentBody.style.top = ".2em";
  6785. }
  6786. accentBody = buildCommon.makeVList({
  6787. positionType: "firstBaseline",
  6788. children: [{
  6789. type: "elem",
  6790. elem: body
  6791. }, {
  6792. type: "kern",
  6793. size: -clearance
  6794. }, {
  6795. type: "elem",
  6796. elem: accentBody
  6797. }]
  6798. }, options);
  6799. } else {
  6800. accentBody = stretchy.svgSpan(group, options);
  6801. accentBody = buildCommon.makeVList({
  6802. positionType: "firstBaseline",
  6803. children: [{
  6804. type: "elem",
  6805. elem: body
  6806. }, {
  6807. type: "elem",
  6808. elem: accentBody,
  6809. wrapperClasses: ["svg-align"],
  6810. wrapperStyle: skew > 0 ? {
  6811. width: "calc(100% - " + makeEm(2 * skew) + ")",
  6812. marginLeft: makeEm(2 * skew)
  6813. } : undefined
  6814. }]
  6815. }, options);
  6816. }
  6817. var accentWrap = buildCommon.makeSpan(["mord", "accent"], [accentBody], options);
  6818. if (supSubGroup) {
  6819. // Here, we replace the "base" child of the supsub with our newly
  6820. // generated accent.
  6821. supSubGroup.children[0] = accentWrap; // Since we don't rerun the height calculation after replacing the
  6822. // accent, we manually recalculate height.
  6823. supSubGroup.height = Math.max(accentWrap.height, supSubGroup.height); // Accents should always be ords, even when their innards are not.
  6824. supSubGroup.classes[0] = "mord";
  6825. return supSubGroup;
  6826. } else {
  6827. return accentWrap;
  6828. }
  6829. };
  6830. var mathmlBuilder$9 = (group, options) => {
  6831. var accentNode = group.isStretchy ? stretchy.mathMLnode(group.label) : new mathMLTree.MathNode("mo", [makeText(group.label, group.mode)]);
  6832. var node = new mathMLTree.MathNode("mover", [buildGroup(group.base, options), accentNode]);
  6833. node.setAttribute("accent", "true");
  6834. return node;
  6835. };
  6836. var NON_STRETCHY_ACCENT_REGEX = new RegExp(["\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve", "\\check", "\\hat", "\\vec", "\\dot", "\\mathring"].map(accent => "\\" + accent).join("|")); // Accents
  6837. defineFunction({
  6838. type: "accent",
  6839. names: ["\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve", "\\check", "\\hat", "\\vec", "\\dot", "\\mathring", "\\widecheck", "\\widehat", "\\widetilde", "\\overrightarrow", "\\overleftarrow", "\\Overrightarrow", "\\overleftrightarrow", "\\overgroup", "\\overlinesegment", "\\overleftharpoon", "\\overrightharpoon"],
  6840. props: {
  6841. numArgs: 1
  6842. },
  6843. handler: (context, args) => {
  6844. var base = normalizeArgument(args[0]);
  6845. var isStretchy = !NON_STRETCHY_ACCENT_REGEX.test(context.funcName);
  6846. var isShifty = !isStretchy || context.funcName === "\\widehat" || context.funcName === "\\widetilde" || context.funcName === "\\widecheck";
  6847. return {
  6848. type: "accent",
  6849. mode: context.parser.mode,
  6850. label: context.funcName,
  6851. isStretchy: isStretchy,
  6852. isShifty: isShifty,
  6853. base: base
  6854. };
  6855. },
  6856. htmlBuilder: htmlBuilder$a,
  6857. mathmlBuilder: mathmlBuilder$9
  6858. }); // Text-mode accents
  6859. defineFunction({
  6860. type: "accent",
  6861. names: ["\\'", "\\`", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"', "\\c", "\\r", "\\H", "\\v", "\\textcircled"],
  6862. props: {
  6863. numArgs: 1,
  6864. allowedInText: true,
  6865. allowedInMath: true,
  6866. // unless in strict mode
  6867. argTypes: ["primitive"]
  6868. },
  6869. handler: (context, args) => {
  6870. var base = args[0];
  6871. var mode = context.parser.mode;
  6872. if (mode === "math") {
  6873. context.parser.settings.reportNonstrict("mathVsTextAccents", "LaTeX's accent " + context.funcName + " works only in text mode");
  6874. mode = "text";
  6875. }
  6876. return {
  6877. type: "accent",
  6878. mode: mode,
  6879. label: context.funcName,
  6880. isStretchy: false,
  6881. isShifty: true,
  6882. base: base
  6883. };
  6884. },
  6885. htmlBuilder: htmlBuilder$a,
  6886. mathmlBuilder: mathmlBuilder$9
  6887. });
  6888. // Horizontal overlap functions
  6889. defineFunction({
  6890. type: "accentUnder",
  6891. names: ["\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow", "\\undergroup", "\\underlinesegment", "\\utilde"],
  6892. props: {
  6893. numArgs: 1
  6894. },
  6895. handler: (_ref, args) => {
  6896. var {
  6897. parser,
  6898. funcName
  6899. } = _ref;
  6900. var base = args[0];
  6901. return {
  6902. type: "accentUnder",
  6903. mode: parser.mode,
  6904. label: funcName,
  6905. base: base
  6906. };
  6907. },
  6908. htmlBuilder: (group, options) => {
  6909. // Treat under accents much like underlines.
  6910. var innerGroup = buildGroup$1(group.base, options);
  6911. var accentBody = stretchy.svgSpan(group, options);
  6912. var kern = group.label === "\\utilde" ? 0.12 : 0; // Generate the vlist, with the appropriate kerns
  6913. var vlist = buildCommon.makeVList({
  6914. positionType: "top",
  6915. positionData: innerGroup.height,
  6916. children: [{
  6917. type: "elem",
  6918. elem: accentBody,
  6919. wrapperClasses: ["svg-align"]
  6920. }, {
  6921. type: "kern",
  6922. size: kern
  6923. }, {
  6924. type: "elem",
  6925. elem: innerGroup
  6926. }]
  6927. }, options);
  6928. return buildCommon.makeSpan(["mord", "accentunder"], [vlist], options);
  6929. },
  6930. mathmlBuilder: (group, options) => {
  6931. var accentNode = stretchy.mathMLnode(group.label);
  6932. var node = new mathMLTree.MathNode("munder", [buildGroup(group.base, options), accentNode]);
  6933. node.setAttribute("accentunder", "true");
  6934. return node;
  6935. }
  6936. });
  6937. // Helper function
  6938. var paddedNode = group => {
  6939. var node = new mathMLTree.MathNode("mpadded", group ? [group] : []);
  6940. node.setAttribute("width", "+0.6em");
  6941. node.setAttribute("lspace", "0.3em");
  6942. return node;
  6943. }; // Stretchy arrows with an optional argument
  6944. defineFunction({
  6945. type: "xArrow",
  6946. names: ["\\xleftarrow", "\\xrightarrow", "\\xLeftarrow", "\\xRightarrow", "\\xleftrightarrow", "\\xLeftrightarrow", "\\xhookleftarrow", "\\xhookrightarrow", "\\xmapsto", "\\xrightharpoondown", "\\xrightharpoonup", "\\xleftharpoondown", "\\xleftharpoonup", "\\xrightleftharpoons", "\\xleftrightharpoons", "\\xlongequal", "\\xtwoheadrightarrow", "\\xtwoheadleftarrow", "\\xtofrom", // The next 3 functions are here to support the mhchem extension.
  6947. // Direct use of these functions is discouraged and may break someday.
  6948. "\\xrightleftarrows", "\\xrightequilibrium", "\\xleftequilibrium", // The next 3 functions are here only to support the {CD} environment.
  6949. "\\\\cdrightarrow", "\\\\cdleftarrow", "\\\\cdlongequal"],
  6950. props: {
  6951. numArgs: 1,
  6952. numOptionalArgs: 1
  6953. },
  6954. handler(_ref, args, optArgs) {
  6955. var {
  6956. parser,
  6957. funcName
  6958. } = _ref;
  6959. return {
  6960. type: "xArrow",
  6961. mode: parser.mode,
  6962. label: funcName,
  6963. body: args[0],
  6964. below: optArgs[0]
  6965. };
  6966. },
  6967. // Flow is unable to correctly infer the type of `group`, even though it's
  6968. // unamibiguously determined from the passed-in `type` above.
  6969. htmlBuilder(group, options) {
  6970. var style = options.style; // Build the argument groups in the appropriate style.
  6971. // Ref: amsmath.dtx: \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
  6972. // Some groups can return document fragments. Handle those by wrapping
  6973. // them in a span.
  6974. var newOptions = options.havingStyle(style.sup());
  6975. var upperGroup = buildCommon.wrapFragment(buildGroup$1(group.body, newOptions, options), options);
  6976. var arrowPrefix = group.label.slice(0, 2) === "\\x" ? "x" : "cd";
  6977. upperGroup.classes.push(arrowPrefix + "-arrow-pad");
  6978. var lowerGroup;
  6979. if (group.below) {
  6980. // Build the lower group
  6981. newOptions = options.havingStyle(style.sub());
  6982. lowerGroup = buildCommon.wrapFragment(buildGroup$1(group.below, newOptions, options), options);
  6983. lowerGroup.classes.push(arrowPrefix + "-arrow-pad");
  6984. }
  6985. var arrowBody = stretchy.svgSpan(group, options); // Re shift: Note that stretchy.svgSpan returned arrowBody.depth = 0.
  6986. // The point we want on the math axis is at 0.5 * arrowBody.height.
  6987. var arrowShift = -options.fontMetrics().axisHeight + 0.5 * arrowBody.height; // 2 mu kern. Ref: amsmath.dtx: #7\if0#2\else\mkern#2mu\fi
  6988. var upperShift = -options.fontMetrics().axisHeight - 0.5 * arrowBody.height - 0.111; // 0.111 em = 2 mu
  6989. if (upperGroup.depth > 0.25 || group.label === "\\xleftequilibrium") {
  6990. upperShift -= upperGroup.depth; // shift up if depth encroaches
  6991. } // Generate the vlist
  6992. var vlist;
  6993. if (lowerGroup) {
  6994. var lowerShift = -options.fontMetrics().axisHeight + lowerGroup.height + 0.5 * arrowBody.height + 0.111;
  6995. vlist = buildCommon.makeVList({
  6996. positionType: "individualShift",
  6997. children: [{
  6998. type: "elem",
  6999. elem: upperGroup,
  7000. shift: upperShift
  7001. }, {
  7002. type: "elem",
  7003. elem: arrowBody,
  7004. shift: arrowShift
  7005. }, {
  7006. type: "elem",
  7007. elem: lowerGroup,
  7008. shift: lowerShift
  7009. }]
  7010. }, options);
  7011. } else {
  7012. vlist = buildCommon.makeVList({
  7013. positionType: "individualShift",
  7014. children: [{
  7015. type: "elem",
  7016. elem: upperGroup,
  7017. shift: upperShift
  7018. }, {
  7019. type: "elem",
  7020. elem: arrowBody,
  7021. shift: arrowShift
  7022. }]
  7023. }, options);
  7024. } // $FlowFixMe: Replace this with passing "svg-align" into makeVList.
  7025. vlist.children[0].children[0].children[1].classes.push("svg-align");
  7026. return buildCommon.makeSpan(["mrel", "x-arrow"], [vlist], options);
  7027. },
  7028. mathmlBuilder(group, options) {
  7029. var arrowNode = stretchy.mathMLnode(group.label);
  7030. arrowNode.setAttribute("minsize", group.label.charAt(0) === "x" ? "1.75em" : "3.0em");
  7031. var node;
  7032. if (group.body) {
  7033. var upperNode = paddedNode(buildGroup(group.body, options));
  7034. if (group.below) {
  7035. var lowerNode = paddedNode(buildGroup(group.below, options));
  7036. node = new mathMLTree.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
  7037. } else {
  7038. node = new mathMLTree.MathNode("mover", [arrowNode, upperNode]);
  7039. }
  7040. } else if (group.below) {
  7041. var _lowerNode = paddedNode(buildGroup(group.below, options));
  7042. node = new mathMLTree.MathNode("munder", [arrowNode, _lowerNode]);
  7043. } else {
  7044. // This should never happen.
  7045. // Parser.js throws an error if there is no argument.
  7046. node = paddedNode();
  7047. node = new mathMLTree.MathNode("mover", [arrowNode, node]);
  7048. }
  7049. return node;
  7050. }
  7051. });
  7052. var makeSpan = buildCommon.makeSpan;
  7053. function htmlBuilder$9(group, options) {
  7054. var elements = buildExpression$1(group.body, options, true);
  7055. return makeSpan([group.mclass], elements, options);
  7056. }
  7057. function mathmlBuilder$8(group, options) {
  7058. var node;
  7059. var inner = buildExpression(group.body, options);
  7060. if (group.mclass === "minner") {
  7061. node = new mathMLTree.MathNode("mpadded", inner);
  7062. } else if (group.mclass === "mord") {
  7063. if (group.isCharacterBox) {
  7064. node = inner[0];
  7065. node.type = "mi";
  7066. } else {
  7067. node = new mathMLTree.MathNode("mi", inner);
  7068. }
  7069. } else {
  7070. if (group.isCharacterBox) {
  7071. node = inner[0];
  7072. node.type = "mo";
  7073. } else {
  7074. node = new mathMLTree.MathNode("mo", inner);
  7075. } // Set spacing based on what is the most likely adjacent atom type.
  7076. // See TeXbook p170.
  7077. if (group.mclass === "mbin") {
  7078. node.attributes.lspace = "0.22em"; // medium space
  7079. node.attributes.rspace = "0.22em";
  7080. } else if (group.mclass === "mpunct") {
  7081. node.attributes.lspace = "0em";
  7082. node.attributes.rspace = "0.17em"; // thinspace
  7083. } else if (group.mclass === "mopen" || group.mclass === "mclose") {
  7084. node.attributes.lspace = "0em";
  7085. node.attributes.rspace = "0em";
  7086. } else if (group.mclass === "minner") {
  7087. node.attributes.lspace = "0.0556em"; // 1 mu is the most likely option
  7088. node.attributes.width = "+0.1111em";
  7089. } // MathML <mo> default space is 5/18 em, so <mrel> needs no action.
  7090. // Ref: https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo
  7091. }
  7092. return node;
  7093. } // Math class commands except \mathop
  7094. defineFunction({
  7095. type: "mclass",
  7096. names: ["\\mathord", "\\mathbin", "\\mathrel", "\\mathopen", "\\mathclose", "\\mathpunct", "\\mathinner"],
  7097. props: {
  7098. numArgs: 1,
  7099. primitive: true
  7100. },
  7101. handler(_ref, args) {
  7102. var {
  7103. parser,
  7104. funcName
  7105. } = _ref;
  7106. var body = args[0];
  7107. return {
  7108. type: "mclass",
  7109. mode: parser.mode,
  7110. mclass: "m" + funcName.slice(5),
  7111. // TODO(kevinb): don't prefix with 'm'
  7112. body: ordargument(body),
  7113. isCharacterBox: utils.isCharacterBox(body)
  7114. };
  7115. },
  7116. htmlBuilder: htmlBuilder$9,
  7117. mathmlBuilder: mathmlBuilder$8
  7118. });
  7119. var binrelClass = arg => {
  7120. // \binrel@ spacing varies with (bin|rel|ord) of the atom in the argument.
  7121. // (by rendering separately and with {}s before and after, and measuring
  7122. // the change in spacing). We'll do roughly the same by detecting the
  7123. // atom type directly.
  7124. var atom = arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg;
  7125. if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {
  7126. return "m" + atom.family;
  7127. } else {
  7128. return "mord";
  7129. }
  7130. }; // \@binrel{x}{y} renders like y but as mbin/mrel/mord if x is mbin/mrel/mord.
  7131. // This is equivalent to \binrel@{x}\binrel@@{y} in AMSTeX.
  7132. defineFunction({
  7133. type: "mclass",
  7134. names: ["\\@binrel"],
  7135. props: {
  7136. numArgs: 2
  7137. },
  7138. handler(_ref2, args) {
  7139. var {
  7140. parser
  7141. } = _ref2;
  7142. return {
  7143. type: "mclass",
  7144. mode: parser.mode,
  7145. mclass: binrelClass(args[0]),
  7146. body: ordargument(args[1]),
  7147. isCharacterBox: utils.isCharacterBox(args[1])
  7148. };
  7149. }
  7150. }); // Build a relation or stacked op by placing one symbol on top of another
  7151. defineFunction({
  7152. type: "mclass",
  7153. names: ["\\stackrel", "\\overset", "\\underset"],
  7154. props: {
  7155. numArgs: 2
  7156. },
  7157. handler(_ref3, args) {
  7158. var {
  7159. parser,
  7160. funcName
  7161. } = _ref3;
  7162. var baseArg = args[1];
  7163. var shiftedArg = args[0];
  7164. var mclass;
  7165. if (funcName !== "\\stackrel") {
  7166. // LaTeX applies \binrel spacing to \overset and \underset.
  7167. mclass = binrelClass(baseArg);
  7168. } else {
  7169. mclass = "mrel"; // for \stackrel
  7170. }
  7171. var baseOp = {
  7172. type: "op",
  7173. mode: baseArg.mode,
  7174. limits: true,
  7175. alwaysHandleSupSub: true,
  7176. parentIsSupSub: false,
  7177. symbol: false,
  7178. suppressBaseShift: funcName !== "\\stackrel",
  7179. body: ordargument(baseArg)
  7180. };
  7181. var supsub = {
  7182. type: "supsub",
  7183. mode: shiftedArg.mode,
  7184. base: baseOp,
  7185. sup: funcName === "\\underset" ? null : shiftedArg,
  7186. sub: funcName === "\\underset" ? shiftedArg : null
  7187. };
  7188. return {
  7189. type: "mclass",
  7190. mode: parser.mode,
  7191. mclass,
  7192. body: [supsub],
  7193. isCharacterBox: utils.isCharacterBox(supsub)
  7194. };
  7195. },
  7196. htmlBuilder: htmlBuilder$9,
  7197. mathmlBuilder: mathmlBuilder$8
  7198. });
  7199. // \pmb is a simulation of bold font.
  7200. // The version of \pmb in ambsy.sty works by typesetting three copies
  7201. // with small offsets. We use CSS text-shadow.
  7202. // It's a hack. Not as good as a real bold font. Better than nothing.
  7203. defineFunction({
  7204. type: "pmb",
  7205. names: ["\\pmb"],
  7206. props: {
  7207. numArgs: 1,
  7208. allowedInText: true
  7209. },
  7210. handler(_ref, args) {
  7211. var {
  7212. parser
  7213. } = _ref;
  7214. return {
  7215. type: "pmb",
  7216. mode: parser.mode,
  7217. mclass: binrelClass(args[0]),
  7218. body: ordargument(args[0])
  7219. };
  7220. },
  7221. htmlBuilder(group, options) {
  7222. var elements = buildExpression$1(group.body, options, true);
  7223. var node = buildCommon.makeSpan([group.mclass], elements, options);
  7224. node.style.textShadow = "0.02em 0.01em 0.04px";
  7225. return node;
  7226. },
  7227. mathmlBuilder(group, style) {
  7228. var inner = buildExpression(group.body, style); // Wrap with an <mstyle> element.
  7229. var node = new mathMLTree.MathNode("mstyle", inner);
  7230. node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px");
  7231. return node;
  7232. }
  7233. });
  7234. var cdArrowFunctionName = {
  7235. ">": "\\\\cdrightarrow",
  7236. "<": "\\\\cdleftarrow",
  7237. "=": "\\\\cdlongequal",
  7238. "A": "\\uparrow",
  7239. "V": "\\downarrow",
  7240. "|": "\\Vert",
  7241. ".": "no arrow"
  7242. };
  7243. var newCell = () => {
  7244. // Create an empty cell, to be filled below with parse nodes.
  7245. // The parseTree from this module must be constructed like the
  7246. // one created by parseArray(), so an empty CD cell must
  7247. // be a ParseNode<"styling">. And CD is always displaystyle.
  7248. // So these values are fixed and flow can do implicit typing.
  7249. return {
  7250. type: "styling",
  7251. body: [],
  7252. mode: "math",
  7253. style: "display"
  7254. };
  7255. };
  7256. var isStartOfArrow = node => {
  7257. return node.type === "textord" && node.text === "@";
  7258. };
  7259. var isLabelEnd = (node, endChar) => {
  7260. return (node.type === "mathord" || node.type === "atom") && node.text === endChar;
  7261. };
  7262. function cdArrow(arrowChar, labels, parser) {
  7263. // Return a parse tree of an arrow and its labels.
  7264. // This acts in a way similar to a macro expansion.
  7265. var funcName = cdArrowFunctionName[arrowChar];
  7266. switch (funcName) {
  7267. case "\\\\cdrightarrow":
  7268. case "\\\\cdleftarrow":
  7269. return parser.callFunction(funcName, [labels[0]], [labels[1]]);
  7270. case "\\uparrow":
  7271. case "\\downarrow":
  7272. {
  7273. var leftLabel = parser.callFunction("\\\\cdleft", [labels[0]], []);
  7274. var bareArrow = {
  7275. type: "atom",
  7276. text: funcName,
  7277. mode: "math",
  7278. family: "rel"
  7279. };
  7280. var sizedArrow = parser.callFunction("\\Big", [bareArrow], []);
  7281. var rightLabel = parser.callFunction("\\\\cdright", [labels[1]], []);
  7282. var arrowGroup = {
  7283. type: "ordgroup",
  7284. mode: "math",
  7285. body: [leftLabel, sizedArrow, rightLabel]
  7286. };
  7287. return parser.callFunction("\\\\cdparent", [arrowGroup], []);
  7288. }
  7289. case "\\\\cdlongequal":
  7290. return parser.callFunction("\\\\cdlongequal", [], []);
  7291. case "\\Vert":
  7292. {
  7293. var arrow = {
  7294. type: "textord",
  7295. text: "\\Vert",
  7296. mode: "math"
  7297. };
  7298. return parser.callFunction("\\Big", [arrow], []);
  7299. }
  7300. default:
  7301. return {
  7302. type: "textord",
  7303. text: " ",
  7304. mode: "math"
  7305. };
  7306. }
  7307. }
  7308. function parseCD(parser) {
  7309. // Get the array's parse nodes with \\ temporarily mapped to \cr.
  7310. var parsedRows = [];
  7311. parser.gullet.beginGroup();
  7312. parser.gullet.macros.set("\\cr", "\\\\\\relax");
  7313. parser.gullet.beginGroup();
  7314. while (true) {
  7315. // eslint-disable-line no-constant-condition
  7316. // Get the parse nodes for the next row.
  7317. parsedRows.push(parser.parseExpression(false, "\\\\"));
  7318. parser.gullet.endGroup();
  7319. parser.gullet.beginGroup();
  7320. var next = parser.fetch().text;
  7321. if (next === "&" || next === "\\\\") {
  7322. parser.consume();
  7323. } else if (next === "\\end") {
  7324. if (parsedRows[parsedRows.length - 1].length === 0) {
  7325. parsedRows.pop(); // final row ended in \\
  7326. }
  7327. break;
  7328. } else {
  7329. throw new ParseError("Expected \\\\ or \\cr or \\end", parser.nextToken);
  7330. }
  7331. }
  7332. var row = [];
  7333. var body = [row]; // Loop thru the parse nodes. Collect them into cells and arrows.
  7334. for (var i = 0; i < parsedRows.length; i++) {
  7335. // Start a new row.
  7336. var rowNodes = parsedRows[i]; // Create the first cell.
  7337. var cell = newCell();
  7338. for (var j = 0; j < rowNodes.length; j++) {
  7339. if (!isStartOfArrow(rowNodes[j])) {
  7340. // If a parseNode is not an arrow, it goes into a cell.
  7341. cell.body.push(rowNodes[j]);
  7342. } else {
  7343. // Parse node j is an "@", the start of an arrow.
  7344. // Before starting on the arrow, push the cell into `row`.
  7345. row.push(cell); // Now collect parseNodes into an arrow.
  7346. // The character after "@" defines the arrow type.
  7347. j += 1;
  7348. var arrowChar = assertSymbolNodeType(rowNodes[j]).text; // Create two empty label nodes. We may or may not use them.
  7349. var labels = new Array(2);
  7350. labels[0] = {
  7351. type: "ordgroup",
  7352. mode: "math",
  7353. body: []
  7354. };
  7355. labels[1] = {
  7356. type: "ordgroup",
  7357. mode: "math",
  7358. body: []
  7359. }; // Process the arrow.
  7360. if ("=|.".indexOf(arrowChar) > -1) ; else if ("<>AV".indexOf(arrowChar) > -1) {
  7361. // Four arrows, `@>>>`, `@<<<`, `@AAA`, and `@VVV`, each take
  7362. // two optional labels. E.g. the right-point arrow syntax is
  7363. // really: @>{optional label}>{optional label}>
  7364. // Collect parseNodes into labels.
  7365. for (var labelNum = 0; labelNum < 2; labelNum++) {
  7366. var inLabel = true;
  7367. for (var k = j + 1; k < rowNodes.length; k++) {
  7368. if (isLabelEnd(rowNodes[k], arrowChar)) {
  7369. inLabel = false;
  7370. j = k;
  7371. break;
  7372. }
  7373. if (isStartOfArrow(rowNodes[k])) {
  7374. throw new ParseError("Missing a " + arrowChar + " character to complete a CD arrow.", rowNodes[k]);
  7375. }
  7376. labels[labelNum].body.push(rowNodes[k]);
  7377. }
  7378. if (inLabel) {
  7379. // isLabelEnd never returned a true.
  7380. throw new ParseError("Missing a " + arrowChar + " character to complete a CD arrow.", rowNodes[j]);
  7381. }
  7382. }
  7383. } else {
  7384. throw new ParseError("Expected one of \"<>AV=|.\" after @", rowNodes[j]);
  7385. } // Now join the arrow to its labels.
  7386. var arrow = cdArrow(arrowChar, labels, parser); // Wrap the arrow in ParseNode<"styling">.
  7387. // This is done to match parseArray() behavior.
  7388. var wrappedArrow = {
  7389. type: "styling",
  7390. body: [arrow],
  7391. mode: "math",
  7392. style: "display" // CD is always displaystyle.
  7393. };
  7394. row.push(wrappedArrow); // In CD's syntax, cells are implicit. That is, everything that
  7395. // is not an arrow gets collected into a cell. So create an empty
  7396. // cell now. It will collect upcoming parseNodes.
  7397. cell = newCell();
  7398. }
  7399. }
  7400. if (i % 2 === 0) {
  7401. // Even-numbered rows consist of: cell, arrow, cell, arrow, ... cell
  7402. // The last cell is not yet pushed into `row`, so:
  7403. row.push(cell);
  7404. } else {
  7405. // Odd-numbered rows consist of: vert arrow, empty cell, ... vert arrow
  7406. // Remove the empty cell that was placed at the beginning of `row`.
  7407. row.shift();
  7408. }
  7409. row = [];
  7410. body.push(row);
  7411. } // End row group
  7412. parser.gullet.endGroup(); // End array group defining \\
  7413. parser.gullet.endGroup(); // define column separation.
  7414. var cols = new Array(body[0].length).fill({
  7415. type: "align",
  7416. align: "c",
  7417. pregap: 0.25,
  7418. // CD package sets \enskip between columns.
  7419. postgap: 0.25 // So pre and post each get half an \enskip, i.e. 0.25em.
  7420. });
  7421. return {
  7422. type: "array",
  7423. mode: "math",
  7424. body,
  7425. arraystretch: 1,
  7426. addJot: true,
  7427. rowGaps: [null],
  7428. cols,
  7429. colSeparationType: "CD",
  7430. hLinesBeforeRow: new Array(body.length + 1).fill([])
  7431. };
  7432. } // The functions below are not available for general use.
  7433. // They are here only for internal use by the {CD} environment in placing labels
  7434. // next to vertical arrows.
  7435. // We don't need any such functions for horizontal arrows because we can reuse
  7436. // the functionality that already exists for extensible arrows.
  7437. defineFunction({
  7438. type: "cdlabel",
  7439. names: ["\\\\cdleft", "\\\\cdright"],
  7440. props: {
  7441. numArgs: 1
  7442. },
  7443. handler(_ref, args) {
  7444. var {
  7445. parser,
  7446. funcName
  7447. } = _ref;
  7448. return {
  7449. type: "cdlabel",
  7450. mode: parser.mode,
  7451. side: funcName.slice(4),
  7452. label: args[0]
  7453. };
  7454. },
  7455. htmlBuilder(group, options) {
  7456. var newOptions = options.havingStyle(options.style.sup());
  7457. var label = buildCommon.wrapFragment(buildGroup$1(group.label, newOptions, options), options);
  7458. label.classes.push("cd-label-" + group.side);
  7459. label.style.bottom = makeEm(0.8 - label.depth); // Zero out label height & depth, so vertical align of arrow is set
  7460. // by the arrow height, not by the label.
  7461. label.height = 0;
  7462. label.depth = 0;
  7463. return label;
  7464. },
  7465. mathmlBuilder(group, options) {
  7466. var label = new mathMLTree.MathNode("mrow", [buildGroup(group.label, options)]);
  7467. label = new mathMLTree.MathNode("mpadded", [label]);
  7468. label.setAttribute("width", "0");
  7469. if (group.side === "left") {
  7470. label.setAttribute("lspace", "-1width");
  7471. } // We have to guess at vertical alignment. We know the arrow is 1.8em tall,
  7472. // But we don't know the height or depth of the label.
  7473. label.setAttribute("voffset", "0.7em");
  7474. label = new mathMLTree.MathNode("mstyle", [label]);
  7475. label.setAttribute("displaystyle", "false");
  7476. label.setAttribute("scriptlevel", "1");
  7477. return label;
  7478. }
  7479. });
  7480. defineFunction({
  7481. type: "cdlabelparent",
  7482. names: ["\\\\cdparent"],
  7483. props: {
  7484. numArgs: 1
  7485. },
  7486. handler(_ref2, args) {
  7487. var {
  7488. parser
  7489. } = _ref2;
  7490. return {
  7491. type: "cdlabelparent",
  7492. mode: parser.mode,
  7493. fragment: args[0]
  7494. };
  7495. },
  7496. htmlBuilder(group, options) {
  7497. // Wrap the vertical arrow and its labels.
  7498. // The parent gets position: relative. The child gets position: absolute.
  7499. // So CSS can locate the label correctly.
  7500. var parent = buildCommon.wrapFragment(buildGroup$1(group.fragment, options), options);
  7501. parent.classes.push("cd-vert-arrow");
  7502. return parent;
  7503. },
  7504. mathmlBuilder(group, options) {
  7505. return new mathMLTree.MathNode("mrow", [buildGroup(group.fragment, options)]);
  7506. }
  7507. });
  7508. // {123} and converts into symbol with code 123. It is used by the *macro*
  7509. // \char defined in macros.js.
  7510. defineFunction({
  7511. type: "textord",
  7512. names: ["\\@char"],
  7513. props: {
  7514. numArgs: 1,
  7515. allowedInText: true
  7516. },
  7517. handler(_ref, args) {
  7518. var {
  7519. parser
  7520. } = _ref;
  7521. var arg = assertNodeType(args[0], "ordgroup");
  7522. var group = arg.body;
  7523. var number = "";
  7524. for (var i = 0; i < group.length; i++) {
  7525. var node = assertNodeType(group[i], "textord");
  7526. number += node.text;
  7527. }
  7528. var code = parseInt(number);
  7529. var text;
  7530. if (isNaN(code)) {
  7531. throw new ParseError("\\@char has non-numeric argument " + number); // If we drop IE support, the following code could be replaced with
  7532. // text = String.fromCodePoint(code)
  7533. } else if (code < 0 || code >= 0x10ffff) {
  7534. throw new ParseError("\\@char with invalid code point " + number);
  7535. } else if (code <= 0xffff) {
  7536. text = String.fromCharCode(code);
  7537. } else {
  7538. // Astral code point; split into surrogate halves
  7539. code -= 0x10000;
  7540. text = String.fromCharCode((code >> 10) + 0xd800, (code & 0x3ff) + 0xdc00);
  7541. }
  7542. return {
  7543. type: "textord",
  7544. mode: parser.mode,
  7545. text: text
  7546. };
  7547. }
  7548. });
  7549. var htmlBuilder$8 = (group, options) => {
  7550. var elements = buildExpression$1(group.body, options.withColor(group.color), false); // \color isn't supposed to affect the type of the elements it contains.
  7551. // To accomplish this, we wrap the results in a fragment, so the inner
  7552. // elements will be able to directly interact with their neighbors. For
  7553. // example, `\color{red}{2 +} 3` has the same spacing as `2 + 3`
  7554. return buildCommon.makeFragment(elements);
  7555. };
  7556. var mathmlBuilder$7 = (group, options) => {
  7557. var inner = buildExpression(group.body, options.withColor(group.color));
  7558. var node = new mathMLTree.MathNode("mstyle", inner);
  7559. node.setAttribute("mathcolor", group.color);
  7560. return node;
  7561. };
  7562. defineFunction({
  7563. type: "color",
  7564. names: ["\\textcolor"],
  7565. props: {
  7566. numArgs: 2,
  7567. allowedInText: true,
  7568. argTypes: ["color", "original"]
  7569. },
  7570. handler(_ref, args) {
  7571. var {
  7572. parser
  7573. } = _ref;
  7574. var color = assertNodeType(args[0], "color-token").color;
  7575. var body = args[1];
  7576. return {
  7577. type: "color",
  7578. mode: parser.mode,
  7579. color,
  7580. body: ordargument(body)
  7581. };
  7582. },
  7583. htmlBuilder: htmlBuilder$8,
  7584. mathmlBuilder: mathmlBuilder$7
  7585. });
  7586. defineFunction({
  7587. type: "color",
  7588. names: ["\\color"],
  7589. props: {
  7590. numArgs: 1,
  7591. allowedInText: true,
  7592. argTypes: ["color"]
  7593. },
  7594. handler(_ref2, args) {
  7595. var {
  7596. parser,
  7597. breakOnTokenText
  7598. } = _ref2;
  7599. var color = assertNodeType(args[0], "color-token").color; // Set macro \current@color in current namespace to store the current
  7600. // color, mimicking the behavior of color.sty.
  7601. // This is currently used just to correctly color a \right
  7602. // that follows a \color command.
  7603. parser.gullet.macros.set("\\current@color", color); // Parse out the implicit body that should be colored.
  7604. var body = parser.parseExpression(true, breakOnTokenText);
  7605. return {
  7606. type: "color",
  7607. mode: parser.mode,
  7608. color,
  7609. body
  7610. };
  7611. },
  7612. htmlBuilder: htmlBuilder$8,
  7613. mathmlBuilder: mathmlBuilder$7
  7614. });
  7615. // Row breaks within tabular environments, and line breaks at top level
  7616. defineFunction({
  7617. type: "cr",
  7618. names: ["\\\\"],
  7619. props: {
  7620. numArgs: 0,
  7621. numOptionalArgs: 1,
  7622. argTypes: ["size"],
  7623. allowedInText: true
  7624. },
  7625. handler(_ref, args, optArgs) {
  7626. var {
  7627. parser
  7628. } = _ref;
  7629. var size = optArgs[0];
  7630. var newLine = !parser.settings.displayMode || !parser.settings.useStrictBehavior("newLineInDisplayMode", "In LaTeX, \\\\ or \\newline " + "does nothing in display mode");
  7631. return {
  7632. type: "cr",
  7633. mode: parser.mode,
  7634. newLine,
  7635. size: size && assertNodeType(size, "size").value
  7636. };
  7637. },
  7638. // The following builders are called only at the top level,
  7639. // not within tabular/array environments.
  7640. htmlBuilder(group, options) {
  7641. var span = buildCommon.makeSpan(["mspace"], [], options);
  7642. if (group.newLine) {
  7643. span.classes.push("newline");
  7644. if (group.size) {
  7645. span.style.marginTop = makeEm(calculateSize(group.size, options));
  7646. }
  7647. }
  7648. return span;
  7649. },
  7650. mathmlBuilder(group, options) {
  7651. var node = new mathMLTree.MathNode("mspace");
  7652. if (group.newLine) {
  7653. node.setAttribute("linebreak", "newline");
  7654. if (group.size) {
  7655. node.setAttribute("height", makeEm(calculateSize(group.size, options)));
  7656. }
  7657. }
  7658. return node;
  7659. }
  7660. });
  7661. var globalMap = {
  7662. "\\global": "\\global",
  7663. "\\long": "\\\\globallong",
  7664. "\\\\globallong": "\\\\globallong",
  7665. "\\def": "\\gdef",
  7666. "\\gdef": "\\gdef",
  7667. "\\edef": "\\xdef",
  7668. "\\xdef": "\\xdef",
  7669. "\\let": "\\\\globallet",
  7670. "\\futurelet": "\\\\globalfuture"
  7671. };
  7672. var checkControlSequence = tok => {
  7673. var name = tok.text;
  7674. if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
  7675. throw new ParseError("Expected a control sequence", tok);
  7676. }
  7677. return name;
  7678. };
  7679. var getRHS = parser => {
  7680. var tok = parser.gullet.popToken();
  7681. if (tok.text === "=") {
  7682. // consume optional equals
  7683. tok = parser.gullet.popToken();
  7684. if (tok.text === " ") {
  7685. // consume one optional space
  7686. tok = parser.gullet.popToken();
  7687. }
  7688. }
  7689. return tok;
  7690. };
  7691. var letCommand = (parser, name, tok, global) => {
  7692. var macro = parser.gullet.macros.get(tok.text);
  7693. if (macro == null) {
  7694. // don't expand it later even if a macro with the same name is defined
  7695. // e.g., \let\foo=\frac \def\frac{\relax} \frac12
  7696. tok.noexpand = true;
  7697. macro = {
  7698. tokens: [tok],
  7699. numArgs: 0,
  7700. // reproduce the same behavior in expansion
  7701. unexpandable: !parser.gullet.isExpandable(tok.text)
  7702. };
  7703. }
  7704. parser.gullet.macros.set(name, macro, global);
  7705. }; // <assignment> -> <non-macro assignment>|<macro assignment>
  7706. // <non-macro assignment> -> <simple assignment>|\global<non-macro assignment>
  7707. // <macro assignment> -> <definition>|<prefix><macro assignment>
  7708. // <prefix> -> \global|\long|\outer
  7709. defineFunction({
  7710. type: "internal",
  7711. names: ["\\global", "\\long", "\\\\globallong" // can’t be entered directly
  7712. ],
  7713. props: {
  7714. numArgs: 0,
  7715. allowedInText: true
  7716. },
  7717. handler(_ref) {
  7718. var {
  7719. parser,
  7720. funcName
  7721. } = _ref;
  7722. parser.consumeSpaces();
  7723. var token = parser.fetch();
  7724. if (globalMap[token.text]) {
  7725. // KaTeX doesn't have \par, so ignore \long
  7726. if (funcName === "\\global" || funcName === "\\\\globallong") {
  7727. token.text = globalMap[token.text];
  7728. }
  7729. return assertNodeType(parser.parseFunction(), "internal");
  7730. }
  7731. throw new ParseError("Invalid token after macro prefix", token);
  7732. }
  7733. }); // Basic support for macro definitions: \def, \gdef, \edef, \xdef
  7734. // <definition> -> <def><control sequence><definition text>
  7735. // <def> -> \def|\gdef|\edef|\xdef
  7736. // <definition text> -> <parameter text><left brace><balanced text><right brace>
  7737. defineFunction({
  7738. type: "internal",
  7739. names: ["\\def", "\\gdef", "\\edef", "\\xdef"],
  7740. props: {
  7741. numArgs: 0,
  7742. allowedInText: true,
  7743. primitive: true
  7744. },
  7745. handler(_ref2) {
  7746. var {
  7747. parser,
  7748. funcName
  7749. } = _ref2;
  7750. var tok = parser.gullet.popToken();
  7751. var name = tok.text;
  7752. if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
  7753. throw new ParseError("Expected a control sequence", tok);
  7754. }
  7755. var numArgs = 0;
  7756. var insert;
  7757. var delimiters = [[]]; // <parameter text> contains no braces
  7758. while (parser.gullet.future().text !== "{") {
  7759. tok = parser.gullet.popToken();
  7760. if (tok.text === "#") {
  7761. // If the very last character of the <parameter text> is #, so that
  7762. // this # is immediately followed by {, TeX will behave as if the {
  7763. // had been inserted at the right end of both the parameter text
  7764. // and the replacement text.
  7765. if (parser.gullet.future().text === "{") {
  7766. insert = parser.gullet.future();
  7767. delimiters[numArgs].push("{");
  7768. break;
  7769. } // A parameter, the first appearance of # must be followed by 1,
  7770. // the next by 2, and so on; up to nine #’s are allowed
  7771. tok = parser.gullet.popToken();
  7772. if (!/^[1-9]$/.test(tok.text)) {
  7773. throw new ParseError("Invalid argument number \"" + tok.text + "\"");
  7774. }
  7775. if (parseInt(tok.text) !== numArgs + 1) {
  7776. throw new ParseError("Argument number \"" + tok.text + "\" out of order");
  7777. }
  7778. numArgs++;
  7779. delimiters.push([]);
  7780. } else if (tok.text === "EOF") {
  7781. throw new ParseError("Expected a macro definition");
  7782. } else {
  7783. delimiters[numArgs].push(tok.text);
  7784. }
  7785. } // replacement text, enclosed in '{' and '}' and properly nested
  7786. var {
  7787. tokens
  7788. } = parser.gullet.consumeArg();
  7789. if (insert) {
  7790. tokens.unshift(insert);
  7791. }
  7792. if (funcName === "\\edef" || funcName === "\\xdef") {
  7793. tokens = parser.gullet.expandTokens(tokens);
  7794. tokens.reverse(); // to fit in with stack order
  7795. } // Final arg is the expansion of the macro
  7796. parser.gullet.macros.set(name, {
  7797. tokens,
  7798. numArgs,
  7799. delimiters
  7800. }, funcName === globalMap[funcName]);
  7801. return {
  7802. type: "internal",
  7803. mode: parser.mode
  7804. };
  7805. }
  7806. }); // <simple assignment> -> <let assignment>
  7807. // <let assignment> -> \futurelet<control sequence><token><token>
  7808. // | \let<control sequence><equals><one optional space><token>
  7809. // <equals> -> <optional spaces>|<optional spaces>=
  7810. defineFunction({
  7811. type: "internal",
  7812. names: ["\\let", "\\\\globallet" // can’t be entered directly
  7813. ],
  7814. props: {
  7815. numArgs: 0,
  7816. allowedInText: true,
  7817. primitive: true
  7818. },
  7819. handler(_ref3) {
  7820. var {
  7821. parser,
  7822. funcName
  7823. } = _ref3;
  7824. var name = checkControlSequence(parser.gullet.popToken());
  7825. parser.gullet.consumeSpaces();
  7826. var tok = getRHS(parser);
  7827. letCommand(parser, name, tok, funcName === "\\\\globallet");
  7828. return {
  7829. type: "internal",
  7830. mode: parser.mode
  7831. };
  7832. }
  7833. }); // ref: https://www.tug.org/TUGboat/tb09-3/tb22bechtolsheim.pdf
  7834. defineFunction({
  7835. type: "internal",
  7836. names: ["\\futurelet", "\\\\globalfuture" // can’t be entered directly
  7837. ],
  7838. props: {
  7839. numArgs: 0,
  7840. allowedInText: true,
  7841. primitive: true
  7842. },
  7843. handler(_ref4) {
  7844. var {
  7845. parser,
  7846. funcName
  7847. } = _ref4;
  7848. var name = checkControlSequence(parser.gullet.popToken());
  7849. var middle = parser.gullet.popToken();
  7850. var tok = parser.gullet.popToken();
  7851. letCommand(parser, name, tok, funcName === "\\\\globalfuture");
  7852. parser.gullet.pushToken(tok);
  7853. parser.gullet.pushToken(middle);
  7854. return {
  7855. type: "internal",
  7856. mode: parser.mode
  7857. };
  7858. }
  7859. });
  7860. /**
  7861. * This file deals with creating delimiters of various sizes. The TeXbook
  7862. * discusses these routines on page 441-442, in the "Another subroutine sets box
  7863. * x to a specified variable delimiter" paragraph.
  7864. *
  7865. * There are three main routines here. `makeSmallDelim` makes a delimiter in the
  7866. * normal font, but in either text, script, or scriptscript style.
  7867. * `makeLargeDelim` makes a delimiter in textstyle, but in one of the Size1,
  7868. * Size2, Size3, or Size4 fonts. `makeStackedDelim` makes a delimiter out of
  7869. * smaller pieces that are stacked on top of one another.
  7870. *
  7871. * The functions take a parameter `center`, which determines if the delimiter
  7872. * should be centered around the axis.
  7873. *
  7874. * Then, there are three exposed functions. `sizedDelim` makes a delimiter in
  7875. * one of the given sizes. This is used for things like `\bigl`.
  7876. * `customSizedDelim` makes a delimiter with a given total height+depth. It is
  7877. * called in places like `\sqrt`. `leftRightDelim` makes an appropriate
  7878. * delimiter which surrounds an expression of a given height an depth. It is
  7879. * used in `\left` and `\right`.
  7880. */
  7881. /**
  7882. * Get the metrics for a given symbol and font, after transformation (i.e.
  7883. * after following replacement from symbols.js)
  7884. */
  7885. var getMetrics = function getMetrics(symbol, font, mode) {
  7886. var replace = symbols.math[symbol] && symbols.math[symbol].replace;
  7887. var metrics = getCharacterMetrics(replace || symbol, font, mode);
  7888. if (!metrics) {
  7889. throw new Error("Unsupported symbol " + symbol + " and font size " + font + ".");
  7890. }
  7891. return metrics;
  7892. };
  7893. /**
  7894. * Puts a delimiter span in a given style, and adds appropriate height, depth,
  7895. * and maxFontSizes.
  7896. */
  7897. var styleWrap = function styleWrap(delim, toStyle, options, classes) {
  7898. var newOptions = options.havingBaseStyle(toStyle);
  7899. var span = buildCommon.makeSpan(classes.concat(newOptions.sizingClasses(options)), [delim], options);
  7900. var delimSizeMultiplier = newOptions.sizeMultiplier / options.sizeMultiplier;
  7901. span.height *= delimSizeMultiplier;
  7902. span.depth *= delimSizeMultiplier;
  7903. span.maxFontSize = newOptions.sizeMultiplier;
  7904. return span;
  7905. };
  7906. var centerSpan = function centerSpan(span, options, style) {
  7907. var newOptions = options.havingBaseStyle(style);
  7908. var shift = (1 - options.sizeMultiplier / newOptions.sizeMultiplier) * options.fontMetrics().axisHeight;
  7909. span.classes.push("delimcenter");
  7910. span.style.top = makeEm(shift);
  7911. span.height -= shift;
  7912. span.depth += shift;
  7913. };
  7914. /**
  7915. * Makes a small delimiter. This is a delimiter that comes in the Main-Regular
  7916. * font, but is restyled to either be in textstyle, scriptstyle, or
  7917. * scriptscriptstyle.
  7918. */
  7919. var makeSmallDelim = function makeSmallDelim(delim, style, center, options, mode, classes) {
  7920. var text = buildCommon.makeSymbol(delim, "Main-Regular", mode, options);
  7921. var span = styleWrap(text, style, options, classes);
  7922. if (center) {
  7923. centerSpan(span, options, style);
  7924. }
  7925. return span;
  7926. };
  7927. /**
  7928. * Builds a symbol in the given font size (note size is an integer)
  7929. */
  7930. var mathrmSize = function mathrmSize(value, size, mode, options) {
  7931. return buildCommon.makeSymbol(value, "Size" + size + "-Regular", mode, options);
  7932. };
  7933. /**
  7934. * Makes a large delimiter. This is a delimiter that comes in the Size1, Size2,
  7935. * Size3, or Size4 fonts. It is always rendered in textstyle.
  7936. */
  7937. var makeLargeDelim = function makeLargeDelim(delim, size, center, options, mode, classes) {
  7938. var inner = mathrmSize(delim, size, mode, options);
  7939. var span = styleWrap(buildCommon.makeSpan(["delimsizing", "size" + size], [inner], options), Style$1.TEXT, options, classes);
  7940. if (center) {
  7941. centerSpan(span, options, Style$1.TEXT);
  7942. }
  7943. return span;
  7944. };
  7945. /**
  7946. * Make a span from a font glyph with the given offset and in the given font.
  7947. * This is used in makeStackedDelim to make the stacking pieces for the delimiter.
  7948. */
  7949. var makeGlyphSpan = function makeGlyphSpan(symbol, font, mode) {
  7950. var sizeClass; // Apply the correct CSS class to choose the right font.
  7951. if (font === "Size1-Regular") {
  7952. sizeClass = "delim-size1";
  7953. } else
  7954. /* if (font === "Size4-Regular") */
  7955. {
  7956. sizeClass = "delim-size4";
  7957. }
  7958. var corner = buildCommon.makeSpan(["delimsizinginner", sizeClass], [buildCommon.makeSpan([], [buildCommon.makeSymbol(symbol, font, mode)])]); // Since this will be passed into `makeVList` in the end, wrap the element
  7959. // in the appropriate tag that VList uses.
  7960. return {
  7961. type: "elem",
  7962. elem: corner
  7963. };
  7964. };
  7965. var makeInner = function makeInner(ch, height, options) {
  7966. // Create a span with inline SVG for the inner part of a tall stacked delimiter.
  7967. var width = fontMetricsData['Size4-Regular'][ch.charCodeAt(0)] ? fontMetricsData['Size4-Regular'][ch.charCodeAt(0)][4] : fontMetricsData['Size1-Regular'][ch.charCodeAt(0)][4];
  7968. var path = new PathNode("inner", innerPath(ch, Math.round(1000 * height)));
  7969. var svgNode = new SvgNode([path], {
  7970. "width": makeEm(width),
  7971. "height": makeEm(height),
  7972. // Override CSS rule `.katex svg { width: 100% }`
  7973. "style": "width:" + makeEm(width),
  7974. "viewBox": "0 0 " + 1000 * width + " " + Math.round(1000 * height),
  7975. "preserveAspectRatio": "xMinYMin"
  7976. });
  7977. var span = buildCommon.makeSvgSpan([], [svgNode], options);
  7978. span.height = height;
  7979. span.style.height = makeEm(height);
  7980. span.style.width = makeEm(width);
  7981. return {
  7982. type: "elem",
  7983. elem: span
  7984. };
  7985. }; // Helpers for makeStackedDelim
  7986. var lapInEms = 0.008;
  7987. var lap = {
  7988. type: "kern",
  7989. size: -1 * lapInEms
  7990. };
  7991. var verts = ["|", "\\lvert", "\\rvert", "\\vert"];
  7992. var doubleVerts = ["\\|", "\\lVert", "\\rVert", "\\Vert"];
  7993. /**
  7994. * Make a stacked delimiter out of a given delimiter, with the total height at
  7995. * least `heightTotal`. This routine is mentioned on page 442 of the TeXbook.
  7996. */
  7997. var makeStackedDelim = function makeStackedDelim(delim, heightTotal, center, options, mode, classes) {
  7998. // There are four parts, the top, an optional middle, a repeated part, and a
  7999. // bottom.
  8000. var top;
  8001. var middle;
  8002. var repeat;
  8003. var bottom;
  8004. var svgLabel = "";
  8005. var viewBoxWidth = 0;
  8006. top = repeat = bottom = delim;
  8007. middle = null; // Also keep track of what font the delimiters are in
  8008. var font = "Size1-Regular"; // We set the parts and font based on the symbol. Note that we use
  8009. // '\u23d0' instead of '|' and '\u2016' instead of '\\|' for the
  8010. // repeats of the arrows
  8011. if (delim === "\\uparrow") {
  8012. repeat = bottom = "\u23d0";
  8013. } else if (delim === "\\Uparrow") {
  8014. repeat = bottom = "\u2016";
  8015. } else if (delim === "\\downarrow") {
  8016. top = repeat = "\u23d0";
  8017. } else if (delim === "\\Downarrow") {
  8018. top = repeat = "\u2016";
  8019. } else if (delim === "\\updownarrow") {
  8020. top = "\\uparrow";
  8021. repeat = "\u23d0";
  8022. bottom = "\\downarrow";
  8023. } else if (delim === "\\Updownarrow") {
  8024. top = "\\Uparrow";
  8025. repeat = "\u2016";
  8026. bottom = "\\Downarrow";
  8027. } else if (utils.contains(verts, delim)) {
  8028. repeat = "\u2223";
  8029. svgLabel = "vert";
  8030. viewBoxWidth = 333;
  8031. } else if (utils.contains(doubleVerts, delim)) {
  8032. repeat = "\u2225";
  8033. svgLabel = "doublevert";
  8034. viewBoxWidth = 556;
  8035. } else if (delim === "[" || delim === "\\lbrack") {
  8036. top = "\u23a1";
  8037. repeat = "\u23a2";
  8038. bottom = "\u23a3";
  8039. font = "Size4-Regular";
  8040. svgLabel = "lbrack";
  8041. viewBoxWidth = 667;
  8042. } else if (delim === "]" || delim === "\\rbrack") {
  8043. top = "\u23a4";
  8044. repeat = "\u23a5";
  8045. bottom = "\u23a6";
  8046. font = "Size4-Regular";
  8047. svgLabel = "rbrack";
  8048. viewBoxWidth = 667;
  8049. } else if (delim === "\\lfloor" || delim === "\u230a") {
  8050. repeat = top = "\u23a2";
  8051. bottom = "\u23a3";
  8052. font = "Size4-Regular";
  8053. svgLabel = "lfloor";
  8054. viewBoxWidth = 667;
  8055. } else if (delim === "\\lceil" || delim === "\u2308") {
  8056. top = "\u23a1";
  8057. repeat = bottom = "\u23a2";
  8058. font = "Size4-Regular";
  8059. svgLabel = "lceil";
  8060. viewBoxWidth = 667;
  8061. } else if (delim === "\\rfloor" || delim === "\u230b") {
  8062. repeat = top = "\u23a5";
  8063. bottom = "\u23a6";
  8064. font = "Size4-Regular";
  8065. svgLabel = "rfloor";
  8066. viewBoxWidth = 667;
  8067. } else if (delim === "\\rceil" || delim === "\u2309") {
  8068. top = "\u23a4";
  8069. repeat = bottom = "\u23a5";
  8070. font = "Size4-Regular";
  8071. svgLabel = "rceil";
  8072. viewBoxWidth = 667;
  8073. } else if (delim === "(" || delim === "\\lparen") {
  8074. top = "\u239b";
  8075. repeat = "\u239c";
  8076. bottom = "\u239d";
  8077. font = "Size4-Regular";
  8078. svgLabel = "lparen";
  8079. viewBoxWidth = 875;
  8080. } else if (delim === ")" || delim === "\\rparen") {
  8081. top = "\u239e";
  8082. repeat = "\u239f";
  8083. bottom = "\u23a0";
  8084. font = "Size4-Regular";
  8085. svgLabel = "rparen";
  8086. viewBoxWidth = 875;
  8087. } else if (delim === "\\{" || delim === "\\lbrace") {
  8088. top = "\u23a7";
  8089. middle = "\u23a8";
  8090. bottom = "\u23a9";
  8091. repeat = "\u23aa";
  8092. font = "Size4-Regular";
  8093. } else if (delim === "\\}" || delim === "\\rbrace") {
  8094. top = "\u23ab";
  8095. middle = "\u23ac";
  8096. bottom = "\u23ad";
  8097. repeat = "\u23aa";
  8098. font = "Size4-Regular";
  8099. } else if (delim === "\\lgroup" || delim === "\u27ee") {
  8100. top = "\u23a7";
  8101. bottom = "\u23a9";
  8102. repeat = "\u23aa";
  8103. font = "Size4-Regular";
  8104. } else if (delim === "\\rgroup" || delim === "\u27ef") {
  8105. top = "\u23ab";
  8106. bottom = "\u23ad";
  8107. repeat = "\u23aa";
  8108. font = "Size4-Regular";
  8109. } else if (delim === "\\lmoustache" || delim === "\u23b0") {
  8110. top = "\u23a7";
  8111. bottom = "\u23ad";
  8112. repeat = "\u23aa";
  8113. font = "Size4-Regular";
  8114. } else if (delim === "\\rmoustache" || delim === "\u23b1") {
  8115. top = "\u23ab";
  8116. bottom = "\u23a9";
  8117. repeat = "\u23aa";
  8118. font = "Size4-Regular";
  8119. } // Get the metrics of the four sections
  8120. var topMetrics = getMetrics(top, font, mode);
  8121. var topHeightTotal = topMetrics.height + topMetrics.depth;
  8122. var repeatMetrics = getMetrics(repeat, font, mode);
  8123. var repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
  8124. var bottomMetrics = getMetrics(bottom, font, mode);
  8125. var bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
  8126. var middleHeightTotal = 0;
  8127. var middleFactor = 1;
  8128. if (middle !== null) {
  8129. var middleMetrics = getMetrics(middle, font, mode);
  8130. middleHeightTotal = middleMetrics.height + middleMetrics.depth;
  8131. middleFactor = 2; // repeat symmetrically above and below middle
  8132. } // Calcuate the minimal height that the delimiter can have.
  8133. // It is at least the size of the top, bottom, and optional middle combined.
  8134. var minHeight = topHeightTotal + bottomHeightTotal + middleHeightTotal; // Compute the number of copies of the repeat symbol we will need
  8135. var repeatCount = Math.max(0, Math.ceil((heightTotal - minHeight) / (middleFactor * repeatHeightTotal))); // Compute the total height of the delimiter including all the symbols
  8136. var realHeightTotal = minHeight + repeatCount * middleFactor * repeatHeightTotal; // The center of the delimiter is placed at the center of the axis. Note
  8137. // that in this context, "center" means that the delimiter should be
  8138. // centered around the axis in the current style, while normally it is
  8139. // centered around the axis in textstyle.
  8140. var axisHeight = options.fontMetrics().axisHeight;
  8141. if (center) {
  8142. axisHeight *= options.sizeMultiplier;
  8143. } // Calculate the depth
  8144. var depth = realHeightTotal / 2 - axisHeight; // Now, we start building the pieces that will go into the vlist
  8145. // Keep a list of the pieces of the stacked delimiter
  8146. var stack = [];
  8147. if (svgLabel.length > 0) {
  8148. // Instead of stacking glyphs, create a single SVG.
  8149. // This evades browser problems with imprecise positioning of spans.
  8150. var midHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
  8151. var viewBoxHeight = Math.round(realHeightTotal * 1000);
  8152. var pathStr = tallDelim(svgLabel, Math.round(midHeight * 1000));
  8153. var path = new PathNode(svgLabel, pathStr);
  8154. var width = (viewBoxWidth / 1000).toFixed(3) + "em";
  8155. var height = (viewBoxHeight / 1000).toFixed(3) + "em";
  8156. var svg = new SvgNode([path], {
  8157. "width": width,
  8158. "height": height,
  8159. "viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight
  8160. });
  8161. var wrapper = buildCommon.makeSvgSpan([], [svg], options);
  8162. wrapper.height = viewBoxHeight / 1000;
  8163. wrapper.style.width = width;
  8164. wrapper.style.height = height;
  8165. stack.push({
  8166. type: "elem",
  8167. elem: wrapper
  8168. });
  8169. } else {
  8170. // Stack glyphs
  8171. // Start by adding the bottom symbol
  8172. stack.push(makeGlyphSpan(bottom, font, mode));
  8173. stack.push(lap); // overlap
  8174. if (middle === null) {
  8175. // The middle section will be an SVG. Make it an extra 0.016em tall.
  8176. // We'll overlap by 0.008em at top and bottom.
  8177. var innerHeight = realHeightTotal - topHeightTotal - bottomHeightTotal + 2 * lapInEms;
  8178. stack.push(makeInner(repeat, innerHeight, options));
  8179. } else {
  8180. // When there is a middle bit, we need the middle part and two repeated
  8181. // sections
  8182. var _innerHeight = (realHeightTotal - topHeightTotal - bottomHeightTotal - middleHeightTotal) / 2 + 2 * lapInEms;
  8183. stack.push(makeInner(repeat, _innerHeight, options)); // Now insert the middle of the brace.
  8184. stack.push(lap);
  8185. stack.push(makeGlyphSpan(middle, font, mode));
  8186. stack.push(lap);
  8187. stack.push(makeInner(repeat, _innerHeight, options));
  8188. } // Add the top symbol
  8189. stack.push(lap);
  8190. stack.push(makeGlyphSpan(top, font, mode));
  8191. } // Finally, build the vlist
  8192. var newOptions = options.havingBaseStyle(Style$1.TEXT);
  8193. var inner = buildCommon.makeVList({
  8194. positionType: "bottom",
  8195. positionData: depth,
  8196. children: stack
  8197. }, newOptions);
  8198. return styleWrap(buildCommon.makeSpan(["delimsizing", "mult"], [inner], newOptions), Style$1.TEXT, options, classes);
  8199. }; // All surds have 0.08em padding above the viniculum inside the SVG.
  8200. // That keeps browser span height rounding error from pinching the line.
  8201. var vbPad = 80; // padding above the surd, measured inside the viewBox.
  8202. var emPad = 0.08; // padding, in ems, measured in the document.
  8203. var sqrtSvg = function sqrtSvg(sqrtName, height, viewBoxHeight, extraViniculum, options) {
  8204. var path = sqrtPath(sqrtName, extraViniculum, viewBoxHeight);
  8205. var pathNode = new PathNode(sqrtName, path);
  8206. var svg = new SvgNode([pathNode], {
  8207. // Note: 1000:1 ratio of viewBox to document em width.
  8208. "width": "400em",
  8209. "height": makeEm(height),
  8210. "viewBox": "0 0 400000 " + viewBoxHeight,
  8211. "preserveAspectRatio": "xMinYMin slice"
  8212. });
  8213. return buildCommon.makeSvgSpan(["hide-tail"], [svg], options);
  8214. };
  8215. /**
  8216. * Make a sqrt image of the given height,
  8217. */
  8218. var makeSqrtImage = function makeSqrtImage(height, options) {
  8219. // Define a newOptions that removes the effect of size changes such as \Huge.
  8220. // We don't pick different a height surd for \Huge. For it, we scale up.
  8221. var newOptions = options.havingBaseSizing(); // Pick the desired surd glyph from a sequence of surds.
  8222. var delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier, stackLargeDelimiterSequence, newOptions);
  8223. var sizeMultiplier = newOptions.sizeMultiplier; // default
  8224. // The standard sqrt SVGs each have a 0.04em thick viniculum.
  8225. // If Settings.minRuleThickness is larger than that, we add extraViniculum.
  8226. var extraViniculum = Math.max(0, options.minRuleThickness - options.fontMetrics().sqrtRuleThickness); // Create a span containing an SVG image of a sqrt symbol.
  8227. var span;
  8228. var spanHeight = 0;
  8229. var texHeight = 0;
  8230. var viewBoxHeight = 0;
  8231. var advanceWidth; // We create viewBoxes with 80 units of "padding" above each surd.
  8232. // Then browser rounding error on the parent span height will not
  8233. // encroach on the ink of the viniculum. But that padding is not
  8234. // included in the TeX-like `height` used for calculation of
  8235. // vertical alignment. So texHeight = span.height < span.style.height.
  8236. if (delim.type === "small") {
  8237. // Get an SVG that is derived from glyph U+221A in font KaTeX-Main.
  8238. // 1000 unit normal glyph height.
  8239. viewBoxHeight = 1000 + 1000 * extraViniculum + vbPad;
  8240. if (height < 1.0) {
  8241. sizeMultiplier = 1.0; // mimic a \textfont radical
  8242. } else if (height < 1.4) {
  8243. sizeMultiplier = 0.7; // mimic a \scriptfont radical
  8244. }
  8245. spanHeight = (1.0 + extraViniculum + emPad) / sizeMultiplier;
  8246. texHeight = (1.00 + extraViniculum) / sizeMultiplier;
  8247. span = sqrtSvg("sqrtMain", spanHeight, viewBoxHeight, extraViniculum, options);
  8248. span.style.minWidth = "0.853em";
  8249. advanceWidth = 0.833 / sizeMultiplier; // from the font.
  8250. } else if (delim.type === "large") {
  8251. // These SVGs come from fonts: KaTeX_Size1, _Size2, etc.
  8252. viewBoxHeight = (1000 + vbPad) * sizeToMaxHeight[delim.size];
  8253. texHeight = (sizeToMaxHeight[delim.size] + extraViniculum) / sizeMultiplier;
  8254. spanHeight = (sizeToMaxHeight[delim.size] + extraViniculum + emPad) / sizeMultiplier;
  8255. span = sqrtSvg("sqrtSize" + delim.size, spanHeight, viewBoxHeight, extraViniculum, options);
  8256. span.style.minWidth = "1.02em";
  8257. advanceWidth = 1.0 / sizeMultiplier; // 1.0 from the font.
  8258. } else {
  8259. // Tall sqrt. In TeX, this would be stacked using multiple glyphs.
  8260. // We'll use a single SVG to accomplish the same thing.
  8261. spanHeight = height + extraViniculum + emPad;
  8262. texHeight = height + extraViniculum;
  8263. viewBoxHeight = Math.floor(1000 * height + extraViniculum) + vbPad;
  8264. span = sqrtSvg("sqrtTall", spanHeight, viewBoxHeight, extraViniculum, options);
  8265. span.style.minWidth = "0.742em";
  8266. advanceWidth = 1.056;
  8267. }
  8268. span.height = texHeight;
  8269. span.style.height = makeEm(spanHeight);
  8270. return {
  8271. span,
  8272. advanceWidth,
  8273. // Calculate the actual line width.
  8274. // This actually should depend on the chosen font -- e.g. \boldmath
  8275. // should use the thicker surd symbols from e.g. KaTeX_Main-Bold, and
  8276. // have thicker rules.
  8277. ruleWidth: (options.fontMetrics().sqrtRuleThickness + extraViniculum) * sizeMultiplier
  8278. };
  8279. }; // There are three kinds of delimiters, delimiters that stack when they become
  8280. // too large
  8281. var stackLargeDelimiters = ["(", "\\lparen", ")", "\\rparen", "[", "\\lbrack", "]", "\\rbrack", "\\{", "\\lbrace", "\\}", "\\rbrace", "\\lfloor", "\\rfloor", "\u230a", "\u230b", "\\lceil", "\\rceil", "\u2308", "\u2309", "\\surd"]; // delimiters that always stack
  8282. var stackAlwaysDelimiters = ["\\uparrow", "\\downarrow", "\\updownarrow", "\\Uparrow", "\\Downarrow", "\\Updownarrow", "|", "\\|", "\\vert", "\\Vert", "\\lvert", "\\rvert", "\\lVert", "\\rVert", "\\lgroup", "\\rgroup", "\u27ee", "\u27ef", "\\lmoustache", "\\rmoustache", "\u23b0", "\u23b1"]; // and delimiters that never stack
  8283. var stackNeverDelimiters = ["<", ">", "\\langle", "\\rangle", "/", "\\backslash", "\\lt", "\\gt"]; // Metrics of the different sizes. Found by looking at TeX's output of
  8284. // $\bigl| // \Bigl| \biggl| \Biggl| \showlists$
  8285. // Used to create stacked delimiters of appropriate sizes in makeSizedDelim.
  8286. var sizeToMaxHeight = [0, 1.2, 1.8, 2.4, 3.0];
  8287. /**
  8288. * Used to create a delimiter of a specific size, where `size` is 1, 2, 3, or 4.
  8289. */
  8290. var makeSizedDelim = function makeSizedDelim(delim, size, options, mode, classes) {
  8291. // < and > turn into \langle and \rangle in delimiters
  8292. if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
  8293. delim = "\\langle";
  8294. } else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
  8295. delim = "\\rangle";
  8296. } // Sized delimiters are never centered.
  8297. if (utils.contains(stackLargeDelimiters, delim) || utils.contains(stackNeverDelimiters, delim)) {
  8298. return makeLargeDelim(delim, size, false, options, mode, classes);
  8299. } else if (utils.contains(stackAlwaysDelimiters, delim)) {
  8300. return makeStackedDelim(delim, sizeToMaxHeight[size], false, options, mode, classes);
  8301. } else {
  8302. throw new ParseError("Illegal delimiter: '" + delim + "'");
  8303. }
  8304. };
  8305. /**
  8306. * There are three different sequences of delimiter sizes that the delimiters
  8307. * follow depending on the kind of delimiter. This is used when creating custom
  8308. * sized delimiters to decide whether to create a small, large, or stacked
  8309. * delimiter.
  8310. *
  8311. * In real TeX, these sequences aren't explicitly defined, but are instead
  8312. * defined inside the font metrics. Since there are only three sequences that
  8313. * are possible for the delimiters that TeX defines, it is easier to just encode
  8314. * them explicitly here.
  8315. */
  8316. // Delimiters that never stack try small delimiters and large delimiters only
  8317. var stackNeverDelimiterSequence = [{
  8318. type: "small",
  8319. style: Style$1.SCRIPTSCRIPT
  8320. }, {
  8321. type: "small",
  8322. style: Style$1.SCRIPT
  8323. }, {
  8324. type: "small",
  8325. style: Style$1.TEXT
  8326. }, {
  8327. type: "large",
  8328. size: 1
  8329. }, {
  8330. type: "large",
  8331. size: 2
  8332. }, {
  8333. type: "large",
  8334. size: 3
  8335. }, {
  8336. type: "large",
  8337. size: 4
  8338. }]; // Delimiters that always stack try the small delimiters first, then stack
  8339. var stackAlwaysDelimiterSequence = [{
  8340. type: "small",
  8341. style: Style$1.SCRIPTSCRIPT
  8342. }, {
  8343. type: "small",
  8344. style: Style$1.SCRIPT
  8345. }, {
  8346. type: "small",
  8347. style: Style$1.TEXT
  8348. }, {
  8349. type: "stack"
  8350. }]; // Delimiters that stack when large try the small and then large delimiters, and
  8351. // stack afterwards
  8352. var stackLargeDelimiterSequence = [{
  8353. type: "small",
  8354. style: Style$1.SCRIPTSCRIPT
  8355. }, {
  8356. type: "small",
  8357. style: Style$1.SCRIPT
  8358. }, {
  8359. type: "small",
  8360. style: Style$1.TEXT
  8361. }, {
  8362. type: "large",
  8363. size: 1
  8364. }, {
  8365. type: "large",
  8366. size: 2
  8367. }, {
  8368. type: "large",
  8369. size: 3
  8370. }, {
  8371. type: "large",
  8372. size: 4
  8373. }, {
  8374. type: "stack"
  8375. }];
  8376. /**
  8377. * Get the font used in a delimiter based on what kind of delimiter it is.
  8378. * TODO(#963) Use more specific font family return type once that is introduced.
  8379. */
  8380. var delimTypeToFont = function delimTypeToFont(type) {
  8381. if (type.type === "small") {
  8382. return "Main-Regular";
  8383. } else if (type.type === "large") {
  8384. return "Size" + type.size + "-Regular";
  8385. } else if (type.type === "stack") {
  8386. return "Size4-Regular";
  8387. } else {
  8388. throw new Error("Add support for delim type '" + type.type + "' here.");
  8389. }
  8390. };
  8391. /**
  8392. * Traverse a sequence of types of delimiters to decide what kind of delimiter
  8393. * should be used to create a delimiter of the given height+depth.
  8394. */
  8395. var traverseSequence = function traverseSequence(delim, height, sequence, options) {
  8396. // Here, we choose the index we should start at in the sequences. In smaller
  8397. // sizes (which correspond to larger numbers in style.size) we start earlier
  8398. // in the sequence. Thus, scriptscript starts at index 3-3=0, script starts
  8399. // at index 3-2=1, text starts at 3-1=2, and display starts at min(2,3-0)=2
  8400. var start = Math.min(2, 3 - options.style.size);
  8401. for (var i = start; i < sequence.length; i++) {
  8402. if (sequence[i].type === "stack") {
  8403. // This is always the last delimiter, so we just break the loop now.
  8404. break;
  8405. }
  8406. var metrics = getMetrics(delim, delimTypeToFont(sequence[i]), "math");
  8407. var heightDepth = metrics.height + metrics.depth; // Small delimiters are scaled down versions of the same font, so we
  8408. // account for the style change size.
  8409. if (sequence[i].type === "small") {
  8410. var newOptions = options.havingBaseStyle(sequence[i].style);
  8411. heightDepth *= newOptions.sizeMultiplier;
  8412. } // Check if the delimiter at this size works for the given height.
  8413. if (heightDepth > height) {
  8414. return sequence[i];
  8415. }
  8416. } // If we reached the end of the sequence, return the last sequence element.
  8417. return sequence[sequence.length - 1];
  8418. };
  8419. /**
  8420. * Make a delimiter of a given height+depth, with optional centering. Here, we
  8421. * traverse the sequences, and create a delimiter that the sequence tells us to.
  8422. */
  8423. var makeCustomSizedDelim = function makeCustomSizedDelim(delim, height, center, options, mode, classes) {
  8424. if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
  8425. delim = "\\langle";
  8426. } else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
  8427. delim = "\\rangle";
  8428. } // Decide what sequence to use
  8429. var sequence;
  8430. if (utils.contains(stackNeverDelimiters, delim)) {
  8431. sequence = stackNeverDelimiterSequence;
  8432. } else if (utils.contains(stackLargeDelimiters, delim)) {
  8433. sequence = stackLargeDelimiterSequence;
  8434. } else {
  8435. sequence = stackAlwaysDelimiterSequence;
  8436. } // Look through the sequence
  8437. var delimType = traverseSequence(delim, height, sequence, options); // Get the delimiter from font glyphs.
  8438. // Depending on the sequence element we decided on, call the
  8439. // appropriate function.
  8440. if (delimType.type === "small") {
  8441. return makeSmallDelim(delim, delimType.style, center, options, mode, classes);
  8442. } else if (delimType.type === "large") {
  8443. return makeLargeDelim(delim, delimType.size, center, options, mode, classes);
  8444. } else
  8445. /* if (delimType.type === "stack") */
  8446. {
  8447. return makeStackedDelim(delim, height, center, options, mode, classes);
  8448. }
  8449. };
  8450. /**
  8451. * Make a delimiter for use with `\left` and `\right`, given a height and depth
  8452. * of an expression that the delimiters surround.
  8453. */
  8454. var makeLeftRightDelim = function makeLeftRightDelim(delim, height, depth, options, mode, classes) {
  8455. // We always center \left/\right delimiters, so the axis is always shifted
  8456. var axisHeight = options.fontMetrics().axisHeight * options.sizeMultiplier; // Taken from TeX source, tex.web, function make_left_right
  8457. var delimiterFactor = 901;
  8458. var delimiterExtend = 5.0 / options.fontMetrics().ptPerEm;
  8459. var maxDistFromAxis = Math.max(height - axisHeight, depth + axisHeight);
  8460. var totalHeight = Math.max( // In real TeX, calculations are done using integral values which are
  8461. // 65536 per pt, or 655360 per em. So, the division here truncates in
  8462. // TeX but doesn't here, producing different results. If we wanted to
  8463. // exactly match TeX's calculation, we could do
  8464. // Math.floor(655360 * maxDistFromAxis / 500) *
  8465. // delimiterFactor / 655360
  8466. // (To see the difference, compare
  8467. // x^{x^{\left(\rule{0.1em}{0.68em}\right)}}
  8468. // in TeX and KaTeX)
  8469. maxDistFromAxis / 500 * delimiterFactor, 2 * maxDistFromAxis - delimiterExtend); // Finally, we defer to `makeCustomSizedDelim` with our calculated total
  8470. // height
  8471. return makeCustomSizedDelim(delim, totalHeight, true, options, mode, classes);
  8472. };
  8473. var delimiter = {
  8474. sqrtImage: makeSqrtImage,
  8475. sizedDelim: makeSizedDelim,
  8476. sizeToMaxHeight: sizeToMaxHeight,
  8477. customSizedDelim: makeCustomSizedDelim,
  8478. leftRightDelim: makeLeftRightDelim
  8479. };
  8480. // Extra data needed for the delimiter handler down below
  8481. var delimiterSizes = {
  8482. "\\bigl": {
  8483. mclass: "mopen",
  8484. size: 1
  8485. },
  8486. "\\Bigl": {
  8487. mclass: "mopen",
  8488. size: 2
  8489. },
  8490. "\\biggl": {
  8491. mclass: "mopen",
  8492. size: 3
  8493. },
  8494. "\\Biggl": {
  8495. mclass: "mopen",
  8496. size: 4
  8497. },
  8498. "\\bigr": {
  8499. mclass: "mclose",
  8500. size: 1
  8501. },
  8502. "\\Bigr": {
  8503. mclass: "mclose",
  8504. size: 2
  8505. },
  8506. "\\biggr": {
  8507. mclass: "mclose",
  8508. size: 3
  8509. },
  8510. "\\Biggr": {
  8511. mclass: "mclose",
  8512. size: 4
  8513. },
  8514. "\\bigm": {
  8515. mclass: "mrel",
  8516. size: 1
  8517. },
  8518. "\\Bigm": {
  8519. mclass: "mrel",
  8520. size: 2
  8521. },
  8522. "\\biggm": {
  8523. mclass: "mrel",
  8524. size: 3
  8525. },
  8526. "\\Biggm": {
  8527. mclass: "mrel",
  8528. size: 4
  8529. },
  8530. "\\big": {
  8531. mclass: "mord",
  8532. size: 1
  8533. },
  8534. "\\Big": {
  8535. mclass: "mord",
  8536. size: 2
  8537. },
  8538. "\\bigg": {
  8539. mclass: "mord",
  8540. size: 3
  8541. },
  8542. "\\Bigg": {
  8543. mclass: "mord",
  8544. size: 4
  8545. }
  8546. };
  8547. var delimiters = ["(", "\\lparen", ")", "\\rparen", "[", "\\lbrack", "]", "\\rbrack", "\\{", "\\lbrace", "\\}", "\\rbrace", "\\lfloor", "\\rfloor", "\u230a", "\u230b", "\\lceil", "\\rceil", "\u2308", "\u2309", "<", ">", "\\langle", "\u27e8", "\\rangle", "\u27e9", "\\lt", "\\gt", "\\lvert", "\\rvert", "\\lVert", "\\rVert", "\\lgroup", "\\rgroup", "\u27ee", "\u27ef", "\\lmoustache", "\\rmoustache", "\u23b0", "\u23b1", "/", "\\backslash", "|", "\\vert", "\\|", "\\Vert", "\\uparrow", "\\Uparrow", "\\downarrow", "\\Downarrow", "\\updownarrow", "\\Updownarrow", "."];
  8548. // Delimiter functions
  8549. function checkDelimiter(delim, context) {
  8550. var symDelim = checkSymbolNodeType(delim);
  8551. if (symDelim && utils.contains(delimiters, symDelim.text)) {
  8552. return symDelim;
  8553. } else if (symDelim) {
  8554. throw new ParseError("Invalid delimiter '" + symDelim.text + "' after '" + context.funcName + "'", delim);
  8555. } else {
  8556. throw new ParseError("Invalid delimiter type '" + delim.type + "'", delim);
  8557. }
  8558. }
  8559. defineFunction({
  8560. type: "delimsizing",
  8561. names: ["\\bigl", "\\Bigl", "\\biggl", "\\Biggl", "\\bigr", "\\Bigr", "\\biggr", "\\Biggr", "\\bigm", "\\Bigm", "\\biggm", "\\Biggm", "\\big", "\\Big", "\\bigg", "\\Bigg"],
  8562. props: {
  8563. numArgs: 1,
  8564. argTypes: ["primitive"]
  8565. },
  8566. handler: (context, args) => {
  8567. var delim = checkDelimiter(args[0], context);
  8568. return {
  8569. type: "delimsizing",
  8570. mode: context.parser.mode,
  8571. size: delimiterSizes[context.funcName].size,
  8572. mclass: delimiterSizes[context.funcName].mclass,
  8573. delim: delim.text
  8574. };
  8575. },
  8576. htmlBuilder: (group, options) => {
  8577. if (group.delim === ".") {
  8578. // Empty delimiters still count as elements, even though they don't
  8579. // show anything.
  8580. return buildCommon.makeSpan([group.mclass]);
  8581. } // Use delimiter.sizedDelim to generate the delimiter.
  8582. return delimiter.sizedDelim(group.delim, group.size, options, group.mode, [group.mclass]);
  8583. },
  8584. mathmlBuilder: group => {
  8585. var children = [];
  8586. if (group.delim !== ".") {
  8587. children.push(makeText(group.delim, group.mode));
  8588. }
  8589. var node = new mathMLTree.MathNode("mo", children);
  8590. if (group.mclass === "mopen" || group.mclass === "mclose") {
  8591. // Only some of the delimsizing functions act as fences, and they
  8592. // return "mopen" or "mclose" mclass.
  8593. node.setAttribute("fence", "true");
  8594. } else {
  8595. // Explicitly disable fencing if it's not a fence, to override the
  8596. // defaults.
  8597. node.setAttribute("fence", "false");
  8598. }
  8599. node.setAttribute("stretchy", "true");
  8600. var size = makeEm(delimiter.sizeToMaxHeight[group.size]);
  8601. node.setAttribute("minsize", size);
  8602. node.setAttribute("maxsize", size);
  8603. return node;
  8604. }
  8605. });
  8606. function assertParsed(group) {
  8607. if (!group.body) {
  8608. throw new Error("Bug: The leftright ParseNode wasn't fully parsed.");
  8609. }
  8610. }
  8611. defineFunction({
  8612. type: "leftright-right",
  8613. names: ["\\right"],
  8614. props: {
  8615. numArgs: 1,
  8616. primitive: true
  8617. },
  8618. handler: (context, args) => {
  8619. // \left case below triggers parsing of \right in
  8620. // `const right = parser.parseFunction();`
  8621. // uses this return value.
  8622. var color = context.parser.gullet.macros.get("\\current@color");
  8623. if (color && typeof color !== "string") {
  8624. throw new ParseError("\\current@color set to non-string in \\right");
  8625. }
  8626. return {
  8627. type: "leftright-right",
  8628. mode: context.parser.mode,
  8629. delim: checkDelimiter(args[0], context).text,
  8630. color // undefined if not set via \color
  8631. };
  8632. }
  8633. });
  8634. defineFunction({
  8635. type: "leftright",
  8636. names: ["\\left"],
  8637. props: {
  8638. numArgs: 1,
  8639. primitive: true
  8640. },
  8641. handler: (context, args) => {
  8642. var delim = checkDelimiter(args[0], context);
  8643. var parser = context.parser; // Parse out the implicit body
  8644. ++parser.leftrightDepth; // parseExpression stops before '\\right'
  8645. var body = parser.parseExpression(false);
  8646. --parser.leftrightDepth; // Check the next token
  8647. parser.expect("\\right", false);
  8648. var right = assertNodeType(parser.parseFunction(), "leftright-right");
  8649. return {
  8650. type: "leftright",
  8651. mode: parser.mode,
  8652. body,
  8653. left: delim.text,
  8654. right: right.delim,
  8655. rightColor: right.color
  8656. };
  8657. },
  8658. htmlBuilder: (group, options) => {
  8659. assertParsed(group); // Build the inner expression
  8660. var inner = buildExpression$1(group.body, options, true, ["mopen", "mclose"]);
  8661. var innerHeight = 0;
  8662. var innerDepth = 0;
  8663. var hadMiddle = false; // Calculate its height and depth
  8664. for (var i = 0; i < inner.length; i++) {
  8665. // Property `isMiddle` not defined on `span`. See comment in
  8666. // "middle"'s htmlBuilder.
  8667. // $FlowFixMe
  8668. if (inner[i].isMiddle) {
  8669. hadMiddle = true;
  8670. } else {
  8671. innerHeight = Math.max(inner[i].height, innerHeight);
  8672. innerDepth = Math.max(inner[i].depth, innerDepth);
  8673. }
  8674. } // The size of delimiters is the same, regardless of what style we are
  8675. // in. Thus, to correctly calculate the size of delimiter we need around
  8676. // a group, we scale down the inner size based on the size.
  8677. innerHeight *= options.sizeMultiplier;
  8678. innerDepth *= options.sizeMultiplier;
  8679. var leftDelim;
  8680. if (group.left === ".") {
  8681. // Empty delimiters in \left and \right make null delimiter spaces.
  8682. leftDelim = makeNullDelimiter(options, ["mopen"]);
  8683. } else {
  8684. // Otherwise, use leftRightDelim to generate the correct sized
  8685. // delimiter.
  8686. leftDelim = delimiter.leftRightDelim(group.left, innerHeight, innerDepth, options, group.mode, ["mopen"]);
  8687. } // Add it to the beginning of the expression
  8688. inner.unshift(leftDelim); // Handle middle delimiters
  8689. if (hadMiddle) {
  8690. for (var _i = 1; _i < inner.length; _i++) {
  8691. var middleDelim = inner[_i]; // Property `isMiddle` not defined on `span`. See comment in
  8692. // "middle"'s htmlBuilder.
  8693. // $FlowFixMe
  8694. var isMiddle = middleDelim.isMiddle;
  8695. if (isMiddle) {
  8696. // Apply the options that were active when \middle was called
  8697. inner[_i] = delimiter.leftRightDelim(isMiddle.delim, innerHeight, innerDepth, isMiddle.options, group.mode, []);
  8698. }
  8699. }
  8700. }
  8701. var rightDelim; // Same for the right delimiter, but using color specified by \color
  8702. if (group.right === ".") {
  8703. rightDelim = makeNullDelimiter(options, ["mclose"]);
  8704. } else {
  8705. var colorOptions = group.rightColor ? options.withColor(group.rightColor) : options;
  8706. rightDelim = delimiter.leftRightDelim(group.right, innerHeight, innerDepth, colorOptions, group.mode, ["mclose"]);
  8707. } // Add it to the end of the expression.
  8708. inner.push(rightDelim);
  8709. return buildCommon.makeSpan(["minner"], inner, options);
  8710. },
  8711. mathmlBuilder: (group, options) => {
  8712. assertParsed(group);
  8713. var inner = buildExpression(group.body, options);
  8714. if (group.left !== ".") {
  8715. var leftNode = new mathMLTree.MathNode("mo", [makeText(group.left, group.mode)]);
  8716. leftNode.setAttribute("fence", "true");
  8717. inner.unshift(leftNode);
  8718. }
  8719. if (group.right !== ".") {
  8720. var rightNode = new mathMLTree.MathNode("mo", [makeText(group.right, group.mode)]);
  8721. rightNode.setAttribute("fence", "true");
  8722. if (group.rightColor) {
  8723. rightNode.setAttribute("mathcolor", group.rightColor);
  8724. }
  8725. inner.push(rightNode);
  8726. }
  8727. return makeRow(inner);
  8728. }
  8729. });
  8730. defineFunction({
  8731. type: "middle",
  8732. names: ["\\middle"],
  8733. props: {
  8734. numArgs: 1,
  8735. primitive: true
  8736. },
  8737. handler: (context, args) => {
  8738. var delim = checkDelimiter(args[0], context);
  8739. if (!context.parser.leftrightDepth) {
  8740. throw new ParseError("\\middle without preceding \\left", delim);
  8741. }
  8742. return {
  8743. type: "middle",
  8744. mode: context.parser.mode,
  8745. delim: delim.text
  8746. };
  8747. },
  8748. htmlBuilder: (group, options) => {
  8749. var middleDelim;
  8750. if (group.delim === ".") {
  8751. middleDelim = makeNullDelimiter(options, []);
  8752. } else {
  8753. middleDelim = delimiter.sizedDelim(group.delim, 1, options, group.mode, []);
  8754. var isMiddle = {
  8755. delim: group.delim,
  8756. options
  8757. }; // Property `isMiddle` not defined on `span`. It is only used in
  8758. // this file above.
  8759. // TODO: Fix this violation of the `span` type and possibly rename
  8760. // things since `isMiddle` sounds like a boolean, but is a struct.
  8761. // $FlowFixMe
  8762. middleDelim.isMiddle = isMiddle;
  8763. }
  8764. return middleDelim;
  8765. },
  8766. mathmlBuilder: (group, options) => {
  8767. // A Firefox \middle will strech a character vertically only if it
  8768. // is in the fence part of the operator dictionary at:
  8769. // https://www.w3.org/TR/MathML3/appendixc.html.
  8770. // So we need to avoid U+2223 and use plain "|" instead.
  8771. var textNode = group.delim === "\\vert" || group.delim === "|" ? makeText("|", "text") : makeText(group.delim, group.mode);
  8772. var middleNode = new mathMLTree.MathNode("mo", [textNode]);
  8773. middleNode.setAttribute("fence", "true"); // MathML gives 5/18em spacing to each <mo> element.
  8774. // \middle should get delimiter spacing instead.
  8775. middleNode.setAttribute("lspace", "0.05em");
  8776. middleNode.setAttribute("rspace", "0.05em");
  8777. return middleNode;
  8778. }
  8779. });
  8780. var htmlBuilder$7 = (group, options) => {
  8781. // \cancel, \bcancel, \xcancel, \sout, \fbox, \colorbox, \fcolorbox, \phase
  8782. // Some groups can return document fragments. Handle those by wrapping
  8783. // them in a span.
  8784. var inner = buildCommon.wrapFragment(buildGroup$1(group.body, options), options);
  8785. var label = group.label.slice(1);
  8786. var scale = options.sizeMultiplier;
  8787. var img;
  8788. var imgShift = 0; // In the LaTeX cancel package, line geometry is slightly different
  8789. // depending on whether the subject is wider than it is tall, or vice versa.
  8790. // We don't know the width of a group, so as a proxy, we test if
  8791. // the subject is a single character. This captures most of the
  8792. // subjects that should get the "tall" treatment.
  8793. var isSingleChar = utils.isCharacterBox(group.body);
  8794. if (label === "sout") {
  8795. img = buildCommon.makeSpan(["stretchy", "sout"]);
  8796. img.height = options.fontMetrics().defaultRuleThickness / scale;
  8797. imgShift = -0.5 * options.fontMetrics().xHeight;
  8798. } else if (label === "phase") {
  8799. // Set a couple of dimensions from the steinmetz package.
  8800. var lineWeight = calculateSize({
  8801. number: 0.6,
  8802. unit: "pt"
  8803. }, options);
  8804. var clearance = calculateSize({
  8805. number: 0.35,
  8806. unit: "ex"
  8807. }, options); // Prevent size changes like \Huge from affecting line thickness
  8808. var newOptions = options.havingBaseSizing();
  8809. scale = scale / newOptions.sizeMultiplier;
  8810. var angleHeight = inner.height + inner.depth + lineWeight + clearance; // Reserve a left pad for the angle.
  8811. inner.style.paddingLeft = makeEm(angleHeight / 2 + lineWeight); // Create an SVG
  8812. var viewBoxHeight = Math.floor(1000 * angleHeight * scale);
  8813. var path = phasePath(viewBoxHeight);
  8814. var svgNode = new SvgNode([new PathNode("phase", path)], {
  8815. "width": "400em",
  8816. "height": makeEm(viewBoxHeight / 1000),
  8817. "viewBox": "0 0 400000 " + viewBoxHeight,
  8818. "preserveAspectRatio": "xMinYMin slice"
  8819. }); // Wrap it in a span with overflow: hidden.
  8820. img = buildCommon.makeSvgSpan(["hide-tail"], [svgNode], options);
  8821. img.style.height = makeEm(angleHeight);
  8822. imgShift = inner.depth + lineWeight + clearance;
  8823. } else {
  8824. // Add horizontal padding
  8825. if (/cancel/.test(label)) {
  8826. if (!isSingleChar) {
  8827. inner.classes.push("cancel-pad");
  8828. }
  8829. } else if (label === "angl") {
  8830. inner.classes.push("anglpad");
  8831. } else {
  8832. inner.classes.push("boxpad");
  8833. } // Add vertical padding
  8834. var topPad = 0;
  8835. var bottomPad = 0;
  8836. var ruleThickness = 0; // ref: cancel package: \advance\totalheight2\p@ % "+2"
  8837. if (/box/.test(label)) {
  8838. ruleThickness = Math.max(options.fontMetrics().fboxrule, // default
  8839. options.minRuleThickness // User override.
  8840. );
  8841. topPad = options.fontMetrics().fboxsep + (label === "colorbox" ? 0 : ruleThickness);
  8842. bottomPad = topPad;
  8843. } else if (label === "angl") {
  8844. ruleThickness = Math.max(options.fontMetrics().defaultRuleThickness, options.minRuleThickness);
  8845. topPad = 4 * ruleThickness; // gap = 3 × line, plus the line itself.
  8846. bottomPad = Math.max(0, 0.25 - inner.depth);
  8847. } else {
  8848. topPad = isSingleChar ? 0.2 : 0;
  8849. bottomPad = topPad;
  8850. }
  8851. img = stretchy.encloseSpan(inner, label, topPad, bottomPad, options);
  8852. if (/fbox|boxed|fcolorbox/.test(label)) {
  8853. img.style.borderStyle = "solid";
  8854. img.style.borderWidth = makeEm(ruleThickness);
  8855. } else if (label === "angl" && ruleThickness !== 0.049) {
  8856. img.style.borderTopWidth = makeEm(ruleThickness);
  8857. img.style.borderRightWidth = makeEm(ruleThickness);
  8858. }
  8859. imgShift = inner.depth + bottomPad;
  8860. if (group.backgroundColor) {
  8861. img.style.backgroundColor = group.backgroundColor;
  8862. if (group.borderColor) {
  8863. img.style.borderColor = group.borderColor;
  8864. }
  8865. }
  8866. }
  8867. var vlist;
  8868. if (group.backgroundColor) {
  8869. vlist = buildCommon.makeVList({
  8870. positionType: "individualShift",
  8871. children: [// Put the color background behind inner;
  8872. {
  8873. type: "elem",
  8874. elem: img,
  8875. shift: imgShift
  8876. }, {
  8877. type: "elem",
  8878. elem: inner,
  8879. shift: 0
  8880. }]
  8881. }, options);
  8882. } else {
  8883. var classes = /cancel|phase/.test(label) ? ["svg-align"] : [];
  8884. vlist = buildCommon.makeVList({
  8885. positionType: "individualShift",
  8886. children: [// Write the \cancel stroke on top of inner.
  8887. {
  8888. type: "elem",
  8889. elem: inner,
  8890. shift: 0
  8891. }, {
  8892. type: "elem",
  8893. elem: img,
  8894. shift: imgShift,
  8895. wrapperClasses: classes
  8896. }]
  8897. }, options);
  8898. }
  8899. if (/cancel/.test(label)) {
  8900. // The cancel package documentation says that cancel lines add their height
  8901. // to the expression, but tests show that isn't how it actually works.
  8902. vlist.height = inner.height;
  8903. vlist.depth = inner.depth;
  8904. }
  8905. if (/cancel/.test(label) && !isSingleChar) {
  8906. // cancel does not create horiz space for its line extension.
  8907. return buildCommon.makeSpan(["mord", "cancel-lap"], [vlist], options);
  8908. } else {
  8909. return buildCommon.makeSpan(["mord"], [vlist], options);
  8910. }
  8911. };
  8912. var mathmlBuilder$6 = (group, options) => {
  8913. var fboxsep = 0;
  8914. var node = new mathMLTree.MathNode(group.label.indexOf("colorbox") > -1 ? "mpadded" : "menclose", [buildGroup(group.body, options)]);
  8915. switch (group.label) {
  8916. case "\\cancel":
  8917. node.setAttribute("notation", "updiagonalstrike");
  8918. break;
  8919. case "\\bcancel":
  8920. node.setAttribute("notation", "downdiagonalstrike");
  8921. break;
  8922. case "\\phase":
  8923. node.setAttribute("notation", "phasorangle");
  8924. break;
  8925. case "\\sout":
  8926. node.setAttribute("notation", "horizontalstrike");
  8927. break;
  8928. case "\\fbox":
  8929. node.setAttribute("notation", "box");
  8930. break;
  8931. case "\\angl":
  8932. node.setAttribute("notation", "actuarial");
  8933. break;
  8934. case "\\fcolorbox":
  8935. case "\\colorbox":
  8936. // <menclose> doesn't have a good notation option. So use <mpadded>
  8937. // instead. Set some attributes that come included with <menclose>.
  8938. fboxsep = options.fontMetrics().fboxsep * options.fontMetrics().ptPerEm;
  8939. node.setAttribute("width", "+" + 2 * fboxsep + "pt");
  8940. node.setAttribute("height", "+" + 2 * fboxsep + "pt");
  8941. node.setAttribute("lspace", fboxsep + "pt"); //
  8942. node.setAttribute("voffset", fboxsep + "pt");
  8943. if (group.label === "\\fcolorbox") {
  8944. var thk = Math.max(options.fontMetrics().fboxrule, // default
  8945. options.minRuleThickness // user override
  8946. );
  8947. node.setAttribute("style", "border: " + thk + "em solid " + String(group.borderColor));
  8948. }
  8949. break;
  8950. case "\\xcancel":
  8951. node.setAttribute("notation", "updiagonalstrike downdiagonalstrike");
  8952. break;
  8953. }
  8954. if (group.backgroundColor) {
  8955. node.setAttribute("mathbackground", group.backgroundColor);
  8956. }
  8957. return node;
  8958. };
  8959. defineFunction({
  8960. type: "enclose",
  8961. names: ["\\colorbox"],
  8962. props: {
  8963. numArgs: 2,
  8964. allowedInText: true,
  8965. argTypes: ["color", "text"]
  8966. },
  8967. handler(_ref, args, optArgs) {
  8968. var {
  8969. parser,
  8970. funcName
  8971. } = _ref;
  8972. var color = assertNodeType(args[0], "color-token").color;
  8973. var body = args[1];
  8974. return {
  8975. type: "enclose",
  8976. mode: parser.mode,
  8977. label: funcName,
  8978. backgroundColor: color,
  8979. body
  8980. };
  8981. },
  8982. htmlBuilder: htmlBuilder$7,
  8983. mathmlBuilder: mathmlBuilder$6
  8984. });
  8985. defineFunction({
  8986. type: "enclose",
  8987. names: ["\\fcolorbox"],
  8988. props: {
  8989. numArgs: 3,
  8990. allowedInText: true,
  8991. argTypes: ["color", "color", "text"]
  8992. },
  8993. handler(_ref2, args, optArgs) {
  8994. var {
  8995. parser,
  8996. funcName
  8997. } = _ref2;
  8998. var borderColor = assertNodeType(args[0], "color-token").color;
  8999. var backgroundColor = assertNodeType(args[1], "color-token").color;
  9000. var body = args[2];
  9001. return {
  9002. type: "enclose",
  9003. mode: parser.mode,
  9004. label: funcName,
  9005. backgroundColor,
  9006. borderColor,
  9007. body
  9008. };
  9009. },
  9010. htmlBuilder: htmlBuilder$7,
  9011. mathmlBuilder: mathmlBuilder$6
  9012. });
  9013. defineFunction({
  9014. type: "enclose",
  9015. names: ["\\fbox"],
  9016. props: {
  9017. numArgs: 1,
  9018. argTypes: ["hbox"],
  9019. allowedInText: true
  9020. },
  9021. handler(_ref3, args) {
  9022. var {
  9023. parser
  9024. } = _ref3;
  9025. return {
  9026. type: "enclose",
  9027. mode: parser.mode,
  9028. label: "\\fbox",
  9029. body: args[0]
  9030. };
  9031. }
  9032. });
  9033. defineFunction({
  9034. type: "enclose",
  9035. names: ["\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\phase"],
  9036. props: {
  9037. numArgs: 1
  9038. },
  9039. handler(_ref4, args) {
  9040. var {
  9041. parser,
  9042. funcName
  9043. } = _ref4;
  9044. var body = args[0];
  9045. return {
  9046. type: "enclose",
  9047. mode: parser.mode,
  9048. label: funcName,
  9049. body
  9050. };
  9051. },
  9052. htmlBuilder: htmlBuilder$7,
  9053. mathmlBuilder: mathmlBuilder$6
  9054. });
  9055. defineFunction({
  9056. type: "enclose",
  9057. names: ["\\angl"],
  9058. props: {
  9059. numArgs: 1,
  9060. argTypes: ["hbox"],
  9061. allowedInText: false
  9062. },
  9063. handler(_ref5, args) {
  9064. var {
  9065. parser
  9066. } = _ref5;
  9067. return {
  9068. type: "enclose",
  9069. mode: parser.mode,
  9070. label: "\\angl",
  9071. body: args[0]
  9072. };
  9073. }
  9074. });
  9075. /**
  9076. * All registered environments.
  9077. * `environments.js` exports this same dictionary again and makes it public.
  9078. * `Parser.js` requires this dictionary via `environments.js`.
  9079. */
  9080. var _environments = {};
  9081. function defineEnvironment(_ref) {
  9082. var {
  9083. type,
  9084. names,
  9085. props,
  9086. handler,
  9087. htmlBuilder,
  9088. mathmlBuilder
  9089. } = _ref;
  9090. // Set default values of environments.
  9091. var data = {
  9092. type,
  9093. numArgs: props.numArgs || 0,
  9094. allowedInText: false,
  9095. numOptionalArgs: 0,
  9096. handler
  9097. };
  9098. for (var i = 0; i < names.length; ++i) {
  9099. // TODO: The value type of _environments should be a type union of all
  9100. // possible `EnvSpec<>` possibilities instead of `EnvSpec<*>`, which is
  9101. // an existential type.
  9102. _environments[names[i]] = data;
  9103. }
  9104. if (htmlBuilder) {
  9105. _htmlGroupBuilders[type] = htmlBuilder;
  9106. }
  9107. if (mathmlBuilder) {
  9108. _mathmlGroupBuilders[type] = mathmlBuilder;
  9109. }
  9110. }
  9111. /**
  9112. * All registered global/built-in macros.
  9113. * `macros.js` exports this same dictionary again and makes it public.
  9114. * `Parser.js` requires this dictionary via `macros.js`.
  9115. */
  9116. var _macros = {}; // This function might one day accept an additional argument and do more things.
  9117. function defineMacro(name, body) {
  9118. _macros[name] = body;
  9119. }
  9120. // Helper functions
  9121. function getHLines(parser) {
  9122. // Return an array. The array length = number of hlines.
  9123. // Each element in the array tells if the line is dashed.
  9124. var hlineInfo = [];
  9125. parser.consumeSpaces();
  9126. var nxt = parser.fetch().text;
  9127. while (nxt === "\\hline" || nxt === "\\hdashline") {
  9128. parser.consume();
  9129. hlineInfo.push(nxt === "\\hdashline");
  9130. parser.consumeSpaces();
  9131. nxt = parser.fetch().text;
  9132. }
  9133. return hlineInfo;
  9134. }
  9135. var validateAmsEnvironmentContext = context => {
  9136. var settings = context.parser.settings;
  9137. if (!settings.displayMode) {
  9138. throw new ParseError("{" + context.envName + "} can be used only in" + " display mode.");
  9139. }
  9140. }; // autoTag (an argument to parseArray) can be one of three values:
  9141. // * undefined: Regular (not-top-level) array; no tags on each row
  9142. // * true: Automatic equation numbering, overridable by \tag
  9143. // * false: Tags allowed on each row, but no automatic numbering
  9144. // This function *doesn't* work with the "split" environment name.
  9145. function getAutoTag(name) {
  9146. if (name.indexOf("ed") === -1) {
  9147. return name.indexOf("*") === -1;
  9148. } // return undefined;
  9149. }
  9150. /**
  9151. * Parse the body of the environment, with rows delimited by \\ and
  9152. * columns delimited by &, and create a nested list in row-major order
  9153. * with one group per cell. If given an optional argument style
  9154. * ("text", "display", etc.), then each cell is cast into that style.
  9155. */
  9156. function parseArray(parser, _ref, style) {
  9157. var {
  9158. hskipBeforeAndAfter,
  9159. addJot,
  9160. cols,
  9161. arraystretch,
  9162. colSeparationType,
  9163. autoTag,
  9164. singleRow,
  9165. emptySingleRow,
  9166. maxNumCols,
  9167. leqno
  9168. } = _ref;
  9169. parser.gullet.beginGroup();
  9170. if (!singleRow) {
  9171. // \cr is equivalent to \\ without the optional size argument (see below)
  9172. // TODO: provide helpful error when \cr is used outside array environment
  9173. parser.gullet.macros.set("\\cr", "\\\\\\relax");
  9174. } // Get current arraystretch if it's not set by the environment
  9175. if (!arraystretch) {
  9176. var stretch = parser.gullet.expandMacroAsText("\\arraystretch");
  9177. if (stretch == null) {
  9178. // Default \arraystretch from lttab.dtx
  9179. arraystretch = 1;
  9180. } else {
  9181. arraystretch = parseFloat(stretch);
  9182. if (!arraystretch || arraystretch < 0) {
  9183. throw new ParseError("Invalid \\arraystretch: " + stretch);
  9184. }
  9185. }
  9186. } // Start group for first cell
  9187. parser.gullet.beginGroup();
  9188. var row = [];
  9189. var body = [row];
  9190. var rowGaps = [];
  9191. var hLinesBeforeRow = [];
  9192. var tags = autoTag != null ? [] : undefined; // amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
  9193. // whether this row should have an equation number. Simulate this with
  9194. // a \@eqnsw macro set to 1 or 0.
  9195. function beginRow() {
  9196. if (autoTag) {
  9197. parser.gullet.macros.set("\\@eqnsw", "1", true);
  9198. }
  9199. }
  9200. function endRow() {
  9201. if (tags) {
  9202. if (parser.gullet.macros.get("\\df@tag")) {
  9203. tags.push(parser.subparse([new Token("\\df@tag")]));
  9204. parser.gullet.macros.set("\\df@tag", undefined, true);
  9205. } else {
  9206. tags.push(Boolean(autoTag) && parser.gullet.macros.get("\\@eqnsw") === "1");
  9207. }
  9208. }
  9209. }
  9210. beginRow(); // Test for \hline at the top of the array.
  9211. hLinesBeforeRow.push(getHLines(parser));
  9212. while (true) {
  9213. // eslint-disable-line no-constant-condition
  9214. // Parse each cell in its own group (namespace)
  9215. var cell = parser.parseExpression(false, singleRow ? "\\end" : "\\\\");
  9216. parser.gullet.endGroup();
  9217. parser.gullet.beginGroup();
  9218. cell = {
  9219. type: "ordgroup",
  9220. mode: parser.mode,
  9221. body: cell
  9222. };
  9223. if (style) {
  9224. cell = {
  9225. type: "styling",
  9226. mode: parser.mode,
  9227. style,
  9228. body: [cell]
  9229. };
  9230. }
  9231. row.push(cell);
  9232. var next = parser.fetch().text;
  9233. if (next === "&") {
  9234. if (maxNumCols && row.length === maxNumCols) {
  9235. if (singleRow || colSeparationType) {
  9236. // {equation} or {split}
  9237. throw new ParseError("Too many tab characters: &", parser.nextToken);
  9238. } else {
  9239. // {array} environment
  9240. parser.settings.reportNonstrict("textEnv", "Too few columns " + "specified in the {array} column argument.");
  9241. }
  9242. }
  9243. parser.consume();
  9244. } else if (next === "\\end") {
  9245. endRow(); // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
  9246. // the last line is empty. However, AMS environments keep the
  9247. // empty row if it's the only one.
  9248. // NOTE: Currently, `cell` is the last item added into `row`.
  9249. if (row.length === 1 && cell.type === "styling" && cell.body[0].body.length === 0 && (body.length > 1 || !emptySingleRow)) {
  9250. body.pop();
  9251. }
  9252. if (hLinesBeforeRow.length < body.length + 1) {
  9253. hLinesBeforeRow.push([]);
  9254. }
  9255. break;
  9256. } else if (next === "\\\\") {
  9257. parser.consume();
  9258. var size = void 0; // \def\Let@{\let\\\math@cr}
  9259. // \def\math@cr{...\math@cr@}
  9260. // \def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}}
  9261. // \def\math@cr@@[#1]{...\math@cr@@@...}
  9262. // \def\math@cr@@@{\cr}
  9263. if (parser.gullet.future().text !== " ") {
  9264. size = parser.parseSizeGroup(true);
  9265. }
  9266. rowGaps.push(size ? size.value : null);
  9267. endRow(); // check for \hline(s) following the row separator
  9268. hLinesBeforeRow.push(getHLines(parser));
  9269. row = [];
  9270. body.push(row);
  9271. beginRow();
  9272. } else {
  9273. throw new ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
  9274. }
  9275. } // End cell group
  9276. parser.gullet.endGroup(); // End array group defining \cr
  9277. parser.gullet.endGroup();
  9278. return {
  9279. type: "array",
  9280. mode: parser.mode,
  9281. addJot,
  9282. arraystretch,
  9283. body,
  9284. cols,
  9285. rowGaps,
  9286. hskipBeforeAndAfter,
  9287. hLinesBeforeRow,
  9288. colSeparationType,
  9289. tags,
  9290. leqno
  9291. };
  9292. } // Decides on a style for cells in an array according to whether the given
  9293. // environment name starts with the letter 'd'.
  9294. function dCellStyle(envName) {
  9295. if (envName.slice(0, 1) === "d") {
  9296. return "display";
  9297. } else {
  9298. return "text";
  9299. }
  9300. }
  9301. var htmlBuilder$6 = function htmlBuilder(group, options) {
  9302. var r;
  9303. var c;
  9304. var nr = group.body.length;
  9305. var hLinesBeforeRow = group.hLinesBeforeRow;
  9306. var nc = 0;
  9307. var body = new Array(nr);
  9308. var hlines = [];
  9309. var ruleThickness = Math.max( // From LaTeX \showthe\arrayrulewidth. Equals 0.04 em.
  9310. options.fontMetrics().arrayRuleWidth, options.minRuleThickness // User override.
  9311. ); // Horizontal spacing
  9312. var pt = 1 / options.fontMetrics().ptPerEm;
  9313. var arraycolsep = 5 * pt; // default value, i.e. \arraycolsep in article.cls
  9314. if (group.colSeparationType && group.colSeparationType === "small") {
  9315. // We're in a {smallmatrix}. Default column space is \thickspace,
  9316. // i.e. 5/18em = 0.2778em, per amsmath.dtx for {smallmatrix}.
  9317. // But that needs adjustment because LaTeX applies \scriptstyle to the
  9318. // entire array, including the colspace, but this function applies
  9319. // \scriptstyle only inside each element.
  9320. var localMultiplier = options.havingStyle(Style$1.SCRIPT).sizeMultiplier;
  9321. arraycolsep = 0.2778 * (localMultiplier / options.sizeMultiplier);
  9322. } // Vertical spacing
  9323. var baselineskip = group.colSeparationType === "CD" ? calculateSize({
  9324. number: 3,
  9325. unit: "ex"
  9326. }, options) : 12 * pt; // see size10.clo
  9327. // Default \jot from ltmath.dtx
  9328. // TODO(edemaine): allow overriding \jot via \setlength (#687)
  9329. var jot = 3 * pt;
  9330. var arrayskip = group.arraystretch * baselineskip;
  9331. var arstrutHeight = 0.7 * arrayskip; // \strutbox in ltfsstrc.dtx and
  9332. var arstrutDepth = 0.3 * arrayskip; // \@arstrutbox in lttab.dtx
  9333. var totalHeight = 0; // Set a position for \hline(s) at the top of the array, if any.
  9334. function setHLinePos(hlinesInGap) {
  9335. for (var i = 0; i < hlinesInGap.length; ++i) {
  9336. if (i > 0) {
  9337. totalHeight += 0.25;
  9338. }
  9339. hlines.push({
  9340. pos: totalHeight,
  9341. isDashed: hlinesInGap[i]
  9342. });
  9343. }
  9344. }
  9345. setHLinePos(hLinesBeforeRow[0]);
  9346. for (r = 0; r < group.body.length; ++r) {
  9347. var inrow = group.body[r];
  9348. var height = arstrutHeight; // \@array adds an \@arstrut
  9349. var depth = arstrutDepth; // to each tow (via the template)
  9350. if (nc < inrow.length) {
  9351. nc = inrow.length;
  9352. }
  9353. var outrow = new Array(inrow.length);
  9354. for (c = 0; c < inrow.length; ++c) {
  9355. var elt = buildGroup$1(inrow[c], options);
  9356. if (depth < elt.depth) {
  9357. depth = elt.depth;
  9358. }
  9359. if (height < elt.height) {
  9360. height = elt.height;
  9361. }
  9362. outrow[c] = elt;
  9363. }
  9364. var rowGap = group.rowGaps[r];
  9365. var gap = 0;
  9366. if (rowGap) {
  9367. gap = calculateSize(rowGap, options);
  9368. if (gap > 0) {
  9369. // \@argarraycr
  9370. gap += arstrutDepth;
  9371. if (depth < gap) {
  9372. depth = gap; // \@xargarraycr
  9373. }
  9374. gap = 0;
  9375. }
  9376. } // In AMS multiline environments such as aligned and gathered, rows
  9377. // correspond to lines that have additional \jot added to the
  9378. // \baselineskip via \openup.
  9379. if (group.addJot) {
  9380. depth += jot;
  9381. }
  9382. outrow.height = height;
  9383. outrow.depth = depth;
  9384. totalHeight += height;
  9385. outrow.pos = totalHeight;
  9386. totalHeight += depth + gap; // \@yargarraycr
  9387. body[r] = outrow; // Set a position for \hline(s), if any.
  9388. setHLinePos(hLinesBeforeRow[r + 1]);
  9389. }
  9390. var offset = totalHeight / 2 + options.fontMetrics().axisHeight;
  9391. var colDescriptions = group.cols || [];
  9392. var cols = [];
  9393. var colSep;
  9394. var colDescrNum;
  9395. var tagSpans = [];
  9396. if (group.tags && group.tags.some(tag => tag)) {
  9397. // An environment with manual tags and/or automatic equation numbers.
  9398. // Create node(s), the latter of which trigger CSS counter increment.
  9399. for (r = 0; r < nr; ++r) {
  9400. var rw = body[r];
  9401. var shift = rw.pos - offset;
  9402. var tag = group.tags[r];
  9403. var tagSpan = void 0;
  9404. if (tag === true) {
  9405. // automatic numbering
  9406. tagSpan = buildCommon.makeSpan(["eqn-num"], [], options);
  9407. } else if (tag === false) {
  9408. // \nonumber/\notag or starred environment
  9409. tagSpan = buildCommon.makeSpan([], [], options);
  9410. } else {
  9411. // manual \tag
  9412. tagSpan = buildCommon.makeSpan([], buildExpression$1(tag, options, true), options);
  9413. }
  9414. tagSpan.depth = rw.depth;
  9415. tagSpan.height = rw.height;
  9416. tagSpans.push({
  9417. type: "elem",
  9418. elem: tagSpan,
  9419. shift
  9420. });
  9421. }
  9422. }
  9423. for (c = 0, colDescrNum = 0; // Continue while either there are more columns or more column
  9424. // descriptions, so trailing separators don't get lost.
  9425. c < nc || colDescrNum < colDescriptions.length; ++c, ++colDescrNum) {
  9426. var colDescr = colDescriptions[colDescrNum] || {};
  9427. var firstSeparator = true;
  9428. while (colDescr.type === "separator") {
  9429. // If there is more than one separator in a row, add a space
  9430. // between them.
  9431. if (!firstSeparator) {
  9432. colSep = buildCommon.makeSpan(["arraycolsep"], []);
  9433. colSep.style.width = makeEm(options.fontMetrics().doubleRuleSep);
  9434. cols.push(colSep);
  9435. }
  9436. if (colDescr.separator === "|" || colDescr.separator === ":") {
  9437. var lineType = colDescr.separator === "|" ? "solid" : "dashed";
  9438. var separator = buildCommon.makeSpan(["vertical-separator"], [], options);
  9439. separator.style.height = makeEm(totalHeight);
  9440. separator.style.borderRightWidth = makeEm(ruleThickness);
  9441. separator.style.borderRightStyle = lineType;
  9442. separator.style.margin = "0 " + makeEm(-ruleThickness / 2);
  9443. var _shift = totalHeight - offset;
  9444. if (_shift) {
  9445. separator.style.verticalAlign = makeEm(-_shift);
  9446. }
  9447. cols.push(separator);
  9448. } else {
  9449. throw new ParseError("Invalid separator type: " + colDescr.separator);
  9450. }
  9451. colDescrNum++;
  9452. colDescr = colDescriptions[colDescrNum] || {};
  9453. firstSeparator = false;
  9454. }
  9455. if (c >= nc) {
  9456. continue;
  9457. }
  9458. var sepwidth = void 0;
  9459. if (c > 0 || group.hskipBeforeAndAfter) {
  9460. sepwidth = utils.deflt(colDescr.pregap, arraycolsep);
  9461. if (sepwidth !== 0) {
  9462. colSep = buildCommon.makeSpan(["arraycolsep"], []);
  9463. colSep.style.width = makeEm(sepwidth);
  9464. cols.push(colSep);
  9465. }
  9466. }
  9467. var col = [];
  9468. for (r = 0; r < nr; ++r) {
  9469. var row = body[r];
  9470. var elem = row[c];
  9471. if (!elem) {
  9472. continue;
  9473. }
  9474. var _shift2 = row.pos - offset;
  9475. elem.depth = row.depth;
  9476. elem.height = row.height;
  9477. col.push({
  9478. type: "elem",
  9479. elem: elem,
  9480. shift: _shift2
  9481. });
  9482. }
  9483. col = buildCommon.makeVList({
  9484. positionType: "individualShift",
  9485. children: col
  9486. }, options);
  9487. col = buildCommon.makeSpan(["col-align-" + (colDescr.align || "c")], [col]);
  9488. cols.push(col);
  9489. if (c < nc - 1 || group.hskipBeforeAndAfter) {
  9490. sepwidth = utils.deflt(colDescr.postgap, arraycolsep);
  9491. if (sepwidth !== 0) {
  9492. colSep = buildCommon.makeSpan(["arraycolsep"], []);
  9493. colSep.style.width = makeEm(sepwidth);
  9494. cols.push(colSep);
  9495. }
  9496. }
  9497. }
  9498. body = buildCommon.makeSpan(["mtable"], cols); // Add \hline(s), if any.
  9499. if (hlines.length > 0) {
  9500. var line = buildCommon.makeLineSpan("hline", options, ruleThickness);
  9501. var dashes = buildCommon.makeLineSpan("hdashline", options, ruleThickness);
  9502. var vListElems = [{
  9503. type: "elem",
  9504. elem: body,
  9505. shift: 0
  9506. }];
  9507. while (hlines.length > 0) {
  9508. var hline = hlines.pop();
  9509. var lineShift = hline.pos - offset;
  9510. if (hline.isDashed) {
  9511. vListElems.push({
  9512. type: "elem",
  9513. elem: dashes,
  9514. shift: lineShift
  9515. });
  9516. } else {
  9517. vListElems.push({
  9518. type: "elem",
  9519. elem: line,
  9520. shift: lineShift
  9521. });
  9522. }
  9523. }
  9524. body = buildCommon.makeVList({
  9525. positionType: "individualShift",
  9526. children: vListElems
  9527. }, options);
  9528. }
  9529. if (tagSpans.length === 0) {
  9530. return buildCommon.makeSpan(["mord"], [body], options);
  9531. } else {
  9532. var eqnNumCol = buildCommon.makeVList({
  9533. positionType: "individualShift",
  9534. children: tagSpans
  9535. }, options);
  9536. eqnNumCol = buildCommon.makeSpan(["tag"], [eqnNumCol], options);
  9537. return buildCommon.makeFragment([body, eqnNumCol]);
  9538. }
  9539. };
  9540. var alignMap = {
  9541. c: "center ",
  9542. l: "left ",
  9543. r: "right "
  9544. };
  9545. var mathmlBuilder$5 = function mathmlBuilder(group, options) {
  9546. var tbl = [];
  9547. var glue = new mathMLTree.MathNode("mtd", [], ["mtr-glue"]);
  9548. var tag = new mathMLTree.MathNode("mtd", [], ["mml-eqn-num"]);
  9549. for (var i = 0; i < group.body.length; i++) {
  9550. var rw = group.body[i];
  9551. var row = [];
  9552. for (var j = 0; j < rw.length; j++) {
  9553. row.push(new mathMLTree.MathNode("mtd", [buildGroup(rw[j], options)]));
  9554. }
  9555. if (group.tags && group.tags[i]) {
  9556. row.unshift(glue);
  9557. row.push(glue);
  9558. if (group.leqno) {
  9559. row.unshift(tag);
  9560. } else {
  9561. row.push(tag);
  9562. }
  9563. }
  9564. tbl.push(new mathMLTree.MathNode("mtr", row));
  9565. }
  9566. var table = new mathMLTree.MathNode("mtable", tbl); // Set column alignment, row spacing, column spacing, and
  9567. // array lines by setting attributes on the table element.
  9568. // Set the row spacing. In MathML, we specify a gap distance.
  9569. // We do not use rowGap[] because MathML automatically increases
  9570. // cell height with the height/depth of the element content.
  9571. // LaTeX \arraystretch multiplies the row baseline-to-baseline distance.
  9572. // We simulate this by adding (arraystretch - 1)em to the gap. This
  9573. // does a reasonable job of adjusting arrays containing 1 em tall content.
  9574. // The 0.16 and 0.09 values are found emprically. They produce an array
  9575. // similar to LaTeX and in which content does not interfere with \hines.
  9576. var gap = group.arraystretch === 0.5 ? 0.1 // {smallmatrix}, {subarray}
  9577. : 0.16 + group.arraystretch - 1 + (group.addJot ? 0.09 : 0);
  9578. table.setAttribute("rowspacing", makeEm(gap)); // MathML table lines go only between cells.
  9579. // To place a line on an edge we'll use <menclose>, if necessary.
  9580. var menclose = "";
  9581. var align = "";
  9582. if (group.cols && group.cols.length > 0) {
  9583. // Find column alignment, column spacing, and vertical lines.
  9584. var cols = group.cols;
  9585. var columnLines = "";
  9586. var prevTypeWasAlign = false;
  9587. var iStart = 0;
  9588. var iEnd = cols.length;
  9589. if (cols[0].type === "separator") {
  9590. menclose += "top ";
  9591. iStart = 1;
  9592. }
  9593. if (cols[cols.length - 1].type === "separator") {
  9594. menclose += "bottom ";
  9595. iEnd -= 1;
  9596. }
  9597. for (var _i = iStart; _i < iEnd; _i++) {
  9598. if (cols[_i].type === "align") {
  9599. align += alignMap[cols[_i].align];
  9600. if (prevTypeWasAlign) {
  9601. columnLines += "none ";
  9602. }
  9603. prevTypeWasAlign = true;
  9604. } else if (cols[_i].type === "separator") {
  9605. // MathML accepts only single lines between cells.
  9606. // So we read only the first of consecutive separators.
  9607. if (prevTypeWasAlign) {
  9608. columnLines += cols[_i].separator === "|" ? "solid " : "dashed ";
  9609. prevTypeWasAlign = false;
  9610. }
  9611. }
  9612. }
  9613. table.setAttribute("columnalign", align.trim());
  9614. if (/[sd]/.test(columnLines)) {
  9615. table.setAttribute("columnlines", columnLines.trim());
  9616. }
  9617. } // Set column spacing.
  9618. if (group.colSeparationType === "align") {
  9619. var _cols = group.cols || [];
  9620. var spacing = "";
  9621. for (var _i2 = 1; _i2 < _cols.length; _i2++) {
  9622. spacing += _i2 % 2 ? "0em " : "1em ";
  9623. }
  9624. table.setAttribute("columnspacing", spacing.trim());
  9625. } else if (group.colSeparationType === "alignat" || group.colSeparationType === "gather") {
  9626. table.setAttribute("columnspacing", "0em");
  9627. } else if (group.colSeparationType === "small") {
  9628. table.setAttribute("columnspacing", "0.2778em");
  9629. } else if (group.colSeparationType === "CD") {
  9630. table.setAttribute("columnspacing", "0.5em");
  9631. } else {
  9632. table.setAttribute("columnspacing", "1em");
  9633. } // Address \hline and \hdashline
  9634. var rowLines = "";
  9635. var hlines = group.hLinesBeforeRow;
  9636. menclose += hlines[0].length > 0 ? "left " : "";
  9637. menclose += hlines[hlines.length - 1].length > 0 ? "right " : "";
  9638. for (var _i3 = 1; _i3 < hlines.length - 1; _i3++) {
  9639. rowLines += hlines[_i3].length === 0 ? "none " // MathML accepts only a single line between rows. Read one element.
  9640. : hlines[_i3][0] ? "dashed " : "solid ";
  9641. }
  9642. if (/[sd]/.test(rowLines)) {
  9643. table.setAttribute("rowlines", rowLines.trim());
  9644. }
  9645. if (menclose !== "") {
  9646. table = new mathMLTree.MathNode("menclose", [table]);
  9647. table.setAttribute("notation", menclose.trim());
  9648. }
  9649. if (group.arraystretch && group.arraystretch < 1) {
  9650. // A small array. Wrap in scriptstyle so row gap is not too large.
  9651. table = new mathMLTree.MathNode("mstyle", [table]);
  9652. table.setAttribute("scriptlevel", "1");
  9653. }
  9654. return table;
  9655. }; // Convenience function for align, align*, aligned, alignat, alignat*, alignedat.
  9656. var alignedHandler = function alignedHandler(context, args) {
  9657. if (context.envName.indexOf("ed") === -1) {
  9658. validateAmsEnvironmentContext(context);
  9659. }
  9660. var cols = [];
  9661. var separationType = context.envName.indexOf("at") > -1 ? "alignat" : "align";
  9662. var isSplit = context.envName === "split";
  9663. var res = parseArray(context.parser, {
  9664. cols,
  9665. addJot: true,
  9666. autoTag: isSplit ? undefined : getAutoTag(context.envName),
  9667. emptySingleRow: true,
  9668. colSeparationType: separationType,
  9669. maxNumCols: isSplit ? 2 : undefined,
  9670. leqno: context.parser.settings.leqno
  9671. }, "display"); // Determining number of columns.
  9672. // 1. If the first argument is given, we use it as a number of columns,
  9673. // and makes sure that each row doesn't exceed that number.
  9674. // 2. Otherwise, just count number of columns = maximum number
  9675. // of cells in each row ("aligned" mode -- isAligned will be true).
  9676. //
  9677. // At the same time, prepend empty group {} at beginning of every second
  9678. // cell in each row (starting with second cell) so that operators become
  9679. // binary. This behavior is implemented in amsmath's \start@aligned.
  9680. var numMaths;
  9681. var numCols = 0;
  9682. var emptyGroup = {
  9683. type: "ordgroup",
  9684. mode: context.mode,
  9685. body: []
  9686. };
  9687. if (args[0] && args[0].type === "ordgroup") {
  9688. var arg0 = "";
  9689. for (var i = 0; i < args[0].body.length; i++) {
  9690. var textord = assertNodeType(args[0].body[i], "textord");
  9691. arg0 += textord.text;
  9692. }
  9693. numMaths = Number(arg0);
  9694. numCols = numMaths * 2;
  9695. }
  9696. var isAligned = !numCols;
  9697. res.body.forEach(function (row) {
  9698. for (var _i4 = 1; _i4 < row.length; _i4 += 2) {
  9699. // Modify ordgroup node within styling node
  9700. var styling = assertNodeType(row[_i4], "styling");
  9701. var ordgroup = assertNodeType(styling.body[0], "ordgroup");
  9702. ordgroup.body.unshift(emptyGroup);
  9703. }
  9704. if (!isAligned) {
  9705. // Case 1
  9706. var curMaths = row.length / 2;
  9707. if (numMaths < curMaths) {
  9708. throw new ParseError("Too many math in a row: " + ("expected " + numMaths + ", but got " + curMaths), row[0]);
  9709. }
  9710. } else if (numCols < row.length) {
  9711. // Case 2
  9712. numCols = row.length;
  9713. }
  9714. }); // Adjusting alignment.
  9715. // In aligned mode, we add one \qquad between columns;
  9716. // otherwise we add nothing.
  9717. for (var _i5 = 0; _i5 < numCols; ++_i5) {
  9718. var align = "r";
  9719. var pregap = 0;
  9720. if (_i5 % 2 === 1) {
  9721. align = "l";
  9722. } else if (_i5 > 0 && isAligned) {
  9723. // "aligned" mode.
  9724. pregap = 1; // add one \quad
  9725. }
  9726. cols[_i5] = {
  9727. type: "align",
  9728. align: align,
  9729. pregap: pregap,
  9730. postgap: 0
  9731. };
  9732. }
  9733. res.colSeparationType = isAligned ? "align" : "alignat";
  9734. return res;
  9735. }; // Arrays are part of LaTeX, defined in lttab.dtx so its documentation
  9736. // is part of the source2e.pdf file of LaTeX2e source documentation.
  9737. // {darray} is an {array} environment where cells are set in \displaystyle,
  9738. // as defined in nccmath.sty.
  9739. defineEnvironment({
  9740. type: "array",
  9741. names: ["array", "darray"],
  9742. props: {
  9743. numArgs: 1
  9744. },
  9745. handler(context, args) {
  9746. // Since no types are specified above, the two possibilities are
  9747. // - The argument is wrapped in {} or [], in which case Parser's
  9748. // parseGroup() returns an "ordgroup" wrapping some symbol node.
  9749. // - The argument is a bare symbol node.
  9750. var symNode = checkSymbolNodeType(args[0]);
  9751. var colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
  9752. var cols = colalign.map(function (nde) {
  9753. var node = assertSymbolNodeType(nde);
  9754. var ca = node.text;
  9755. if ("lcr".indexOf(ca) !== -1) {
  9756. return {
  9757. type: "align",
  9758. align: ca
  9759. };
  9760. } else if (ca === "|") {
  9761. return {
  9762. type: "separator",
  9763. separator: "|"
  9764. };
  9765. } else if (ca === ":") {
  9766. return {
  9767. type: "separator",
  9768. separator: ":"
  9769. };
  9770. }
  9771. throw new ParseError("Unknown column alignment: " + ca, nde);
  9772. });
  9773. var res = {
  9774. cols,
  9775. hskipBeforeAndAfter: true,
  9776. // \@preamble in lttab.dtx
  9777. maxNumCols: cols.length
  9778. };
  9779. return parseArray(context.parser, res, dCellStyle(context.envName));
  9780. },
  9781. htmlBuilder: htmlBuilder$6,
  9782. mathmlBuilder: mathmlBuilder$5
  9783. }); // The matrix environments of amsmath builds on the array environment
  9784. // of LaTeX, which is discussed above.
  9785. // The mathtools package adds starred versions of the same environments.
  9786. // These have an optional argument to choose left|center|right justification.
  9787. defineEnvironment({
  9788. type: "array",
  9789. names: ["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix", "matrix*", "pmatrix*", "bmatrix*", "Bmatrix*", "vmatrix*", "Vmatrix*"],
  9790. props: {
  9791. numArgs: 0
  9792. },
  9793. handler(context) {
  9794. var delimiters = {
  9795. "matrix": null,
  9796. "pmatrix": ["(", ")"],
  9797. "bmatrix": ["[", "]"],
  9798. "Bmatrix": ["\\{", "\\}"],
  9799. "vmatrix": ["|", "|"],
  9800. "Vmatrix": ["\\Vert", "\\Vert"]
  9801. }[context.envName.replace("*", "")]; // \hskip -\arraycolsep in amsmath
  9802. var colAlign = "c";
  9803. var payload = {
  9804. hskipBeforeAndAfter: false,
  9805. cols: [{
  9806. type: "align",
  9807. align: colAlign
  9808. }]
  9809. };
  9810. if (context.envName.charAt(context.envName.length - 1) === "*") {
  9811. // It's one of the mathtools starred functions.
  9812. // Parse the optional alignment argument.
  9813. var parser = context.parser;
  9814. parser.consumeSpaces();
  9815. if (parser.fetch().text === "[") {
  9816. parser.consume();
  9817. parser.consumeSpaces();
  9818. colAlign = parser.fetch().text;
  9819. if ("lcr".indexOf(colAlign) === -1) {
  9820. throw new ParseError("Expected l or c or r", parser.nextToken);
  9821. }
  9822. parser.consume();
  9823. parser.consumeSpaces();
  9824. parser.expect("]");
  9825. parser.consume();
  9826. payload.cols = [{
  9827. type: "align",
  9828. align: colAlign
  9829. }];
  9830. }
  9831. }
  9832. var res = parseArray(context.parser, payload, dCellStyle(context.envName)); // Populate cols with the correct number of column alignment specs.
  9833. var numCols = Math.max(0, ...res.body.map(row => row.length));
  9834. res.cols = new Array(numCols).fill({
  9835. type: "align",
  9836. align: colAlign
  9837. });
  9838. return delimiters ? {
  9839. type: "leftright",
  9840. mode: context.mode,
  9841. body: [res],
  9842. left: delimiters[0],
  9843. right: delimiters[1],
  9844. rightColor: undefined // \right uninfluenced by \color in array
  9845. } : res;
  9846. },
  9847. htmlBuilder: htmlBuilder$6,
  9848. mathmlBuilder: mathmlBuilder$5
  9849. });
  9850. defineEnvironment({
  9851. type: "array",
  9852. names: ["smallmatrix"],
  9853. props: {
  9854. numArgs: 0
  9855. },
  9856. handler(context) {
  9857. var payload = {
  9858. arraystretch: 0.5
  9859. };
  9860. var res = parseArray(context.parser, payload, "script");
  9861. res.colSeparationType = "small";
  9862. return res;
  9863. },
  9864. htmlBuilder: htmlBuilder$6,
  9865. mathmlBuilder: mathmlBuilder$5
  9866. });
  9867. defineEnvironment({
  9868. type: "array",
  9869. names: ["subarray"],
  9870. props: {
  9871. numArgs: 1
  9872. },
  9873. handler(context, args) {
  9874. // Parsing of {subarray} is similar to {array}
  9875. var symNode = checkSymbolNodeType(args[0]);
  9876. var colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
  9877. var cols = colalign.map(function (nde) {
  9878. var node = assertSymbolNodeType(nde);
  9879. var ca = node.text; // {subarray} only recognizes "l" & "c"
  9880. if ("lc".indexOf(ca) !== -1) {
  9881. return {
  9882. type: "align",
  9883. align: ca
  9884. };
  9885. }
  9886. throw new ParseError("Unknown column alignment: " + ca, nde);
  9887. });
  9888. if (cols.length > 1) {
  9889. throw new ParseError("{subarray} can contain only one column");
  9890. }
  9891. var res = {
  9892. cols,
  9893. hskipBeforeAndAfter: false,
  9894. arraystretch: 0.5
  9895. };
  9896. res = parseArray(context.parser, res, "script");
  9897. if (res.body.length > 0 && res.body[0].length > 1) {
  9898. throw new ParseError("{subarray} can contain only one column");
  9899. }
  9900. return res;
  9901. },
  9902. htmlBuilder: htmlBuilder$6,
  9903. mathmlBuilder: mathmlBuilder$5
  9904. }); // A cases environment (in amsmath.sty) is almost equivalent to
  9905. // \def\arraystretch{1.2}%
  9906. // \left\{\begin{array}{@{}l@{\quad}l@{}} … \end{array}\right.
  9907. // {dcases} is a {cases} environment where cells are set in \displaystyle,
  9908. // as defined in mathtools.sty.
  9909. // {rcases} is another mathtools environment. It's brace is on the right side.
  9910. defineEnvironment({
  9911. type: "array",
  9912. names: ["cases", "dcases", "rcases", "drcases"],
  9913. props: {
  9914. numArgs: 0
  9915. },
  9916. handler(context) {
  9917. var payload = {
  9918. arraystretch: 1.2,
  9919. cols: [{
  9920. type: "align",
  9921. align: "l",
  9922. pregap: 0,
  9923. // TODO(kevinb) get the current style.
  9924. // For now we use the metrics for TEXT style which is what we were
  9925. // doing before. Before attempting to get the current style we
  9926. // should look at TeX's behavior especially for \over and matrices.
  9927. postgap: 1.0
  9928. /* 1em quad */
  9929. }, {
  9930. type: "align",
  9931. align: "l",
  9932. pregap: 0,
  9933. postgap: 0
  9934. }]
  9935. };
  9936. var res = parseArray(context.parser, payload, dCellStyle(context.envName));
  9937. return {
  9938. type: "leftright",
  9939. mode: context.mode,
  9940. body: [res],
  9941. left: context.envName.indexOf("r") > -1 ? "." : "\\{",
  9942. right: context.envName.indexOf("r") > -1 ? "\\}" : ".",
  9943. rightColor: undefined
  9944. };
  9945. },
  9946. htmlBuilder: htmlBuilder$6,
  9947. mathmlBuilder: mathmlBuilder$5
  9948. }); // In the align environment, one uses ampersands, &, to specify number of
  9949. // columns in each row, and to locate spacing between each column.
  9950. // align gets automatic numbering. align* and aligned do not.
  9951. // The alignedat environment can be used in math mode.
  9952. // Note that we assume \nomallineskiplimit to be zero,
  9953. // so that \strut@ is the same as \strut.
  9954. defineEnvironment({
  9955. type: "array",
  9956. names: ["align", "align*", "aligned", "split"],
  9957. props: {
  9958. numArgs: 0
  9959. },
  9960. handler: alignedHandler,
  9961. htmlBuilder: htmlBuilder$6,
  9962. mathmlBuilder: mathmlBuilder$5
  9963. }); // A gathered environment is like an array environment with one centered
  9964. // column, but where rows are considered lines so get \jot line spacing
  9965. // and contents are set in \displaystyle.
  9966. defineEnvironment({
  9967. type: "array",
  9968. names: ["gathered", "gather", "gather*"],
  9969. props: {
  9970. numArgs: 0
  9971. },
  9972. handler(context) {
  9973. if (utils.contains(["gather", "gather*"], context.envName)) {
  9974. validateAmsEnvironmentContext(context);
  9975. }
  9976. var res = {
  9977. cols: [{
  9978. type: "align",
  9979. align: "c"
  9980. }],
  9981. addJot: true,
  9982. colSeparationType: "gather",
  9983. autoTag: getAutoTag(context.envName),
  9984. emptySingleRow: true,
  9985. leqno: context.parser.settings.leqno
  9986. };
  9987. return parseArray(context.parser, res, "display");
  9988. },
  9989. htmlBuilder: htmlBuilder$6,
  9990. mathmlBuilder: mathmlBuilder$5
  9991. }); // alignat environment is like an align environment, but one must explicitly
  9992. // specify maximum number of columns in each row, and can adjust spacing between
  9993. // each columns.
  9994. defineEnvironment({
  9995. type: "array",
  9996. names: ["alignat", "alignat*", "alignedat"],
  9997. props: {
  9998. numArgs: 1
  9999. },
  10000. handler: alignedHandler,
  10001. htmlBuilder: htmlBuilder$6,
  10002. mathmlBuilder: mathmlBuilder$5
  10003. });
  10004. defineEnvironment({
  10005. type: "array",
  10006. names: ["equation", "equation*"],
  10007. props: {
  10008. numArgs: 0
  10009. },
  10010. handler(context) {
  10011. validateAmsEnvironmentContext(context);
  10012. var res = {
  10013. autoTag: getAutoTag(context.envName),
  10014. emptySingleRow: true,
  10015. singleRow: true,
  10016. maxNumCols: 1,
  10017. leqno: context.parser.settings.leqno
  10018. };
  10019. return parseArray(context.parser, res, "display");
  10020. },
  10021. htmlBuilder: htmlBuilder$6,
  10022. mathmlBuilder: mathmlBuilder$5
  10023. });
  10024. defineEnvironment({
  10025. type: "array",
  10026. names: ["CD"],
  10027. props: {
  10028. numArgs: 0
  10029. },
  10030. handler(context) {
  10031. validateAmsEnvironmentContext(context);
  10032. return parseCD(context.parser);
  10033. },
  10034. htmlBuilder: htmlBuilder$6,
  10035. mathmlBuilder: mathmlBuilder$5
  10036. });
  10037. defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
  10038. defineMacro("\\notag", "\\nonumber"); // Catch \hline outside array environment
  10039. defineFunction({
  10040. type: "text",
  10041. // Doesn't matter what this is.
  10042. names: ["\\hline", "\\hdashline"],
  10043. props: {
  10044. numArgs: 0,
  10045. allowedInText: true,
  10046. allowedInMath: true
  10047. },
  10048. handler(context, args) {
  10049. throw new ParseError(context.funcName + " valid only within array environment");
  10050. }
  10051. });
  10052. var environments = _environments;
  10053. // defineEnvironment definitions.
  10054. defineFunction({
  10055. type: "environment",
  10056. names: ["\\begin", "\\end"],
  10057. props: {
  10058. numArgs: 1,
  10059. argTypes: ["text"]
  10060. },
  10061. handler(_ref, args) {
  10062. var {
  10063. parser,
  10064. funcName
  10065. } = _ref;
  10066. var nameGroup = args[0];
  10067. if (nameGroup.type !== "ordgroup") {
  10068. throw new ParseError("Invalid environment name", nameGroup);
  10069. }
  10070. var envName = "";
  10071. for (var i = 0; i < nameGroup.body.length; ++i) {
  10072. envName += assertNodeType(nameGroup.body[i], "textord").text;
  10073. }
  10074. if (funcName === "\\begin") {
  10075. // begin...end is similar to left...right
  10076. if (!environments.hasOwnProperty(envName)) {
  10077. throw new ParseError("No such environment: " + envName, nameGroup);
  10078. } // Build the environment object. Arguments and other information will
  10079. // be made available to the begin and end methods using properties.
  10080. var env = environments[envName];
  10081. var {
  10082. args: _args,
  10083. optArgs
  10084. } = parser.parseArguments("\\begin{" + envName + "}", env);
  10085. var context = {
  10086. mode: parser.mode,
  10087. envName,
  10088. parser
  10089. };
  10090. var result = env.handler(context, _args, optArgs);
  10091. parser.expect("\\end", false);
  10092. var endNameToken = parser.nextToken;
  10093. var end = assertNodeType(parser.parseFunction(), "environment");
  10094. if (end.name !== envName) {
  10095. throw new ParseError("Mismatch: \\begin{" + envName + "} matched by \\end{" + end.name + "}", endNameToken);
  10096. } // $FlowFixMe, "environment" handler returns an environment ParseNode
  10097. return result;
  10098. }
  10099. return {
  10100. type: "environment",
  10101. mode: parser.mode,
  10102. name: envName,
  10103. nameGroup
  10104. };
  10105. }
  10106. });
  10107. // TODO(kevinb): implement \\sl and \\sc
  10108. var htmlBuilder$5 = (group, options) => {
  10109. var font = group.font;
  10110. var newOptions = options.withFont(font);
  10111. return buildGroup$1(group.body, newOptions);
  10112. };
  10113. var mathmlBuilder$4 = (group, options) => {
  10114. var font = group.font;
  10115. var newOptions = options.withFont(font);
  10116. return buildGroup(group.body, newOptions);
  10117. };
  10118. var fontAliases = {
  10119. "\\Bbb": "\\mathbb",
  10120. "\\bold": "\\mathbf",
  10121. "\\frak": "\\mathfrak",
  10122. "\\bm": "\\boldsymbol"
  10123. };
  10124. defineFunction({
  10125. type: "font",
  10126. names: [// styles, except \boldsymbol defined below
  10127. "\\mathrm", "\\mathit", "\\mathbf", "\\mathnormal", // families
  10128. "\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf", "\\mathtt", // aliases, except \bm defined below
  10129. "\\Bbb", "\\bold", "\\frak"],
  10130. props: {
  10131. numArgs: 1,
  10132. allowedInArgument: true
  10133. },
  10134. handler: (_ref, args) => {
  10135. var {
  10136. parser,
  10137. funcName
  10138. } = _ref;
  10139. var body = normalizeArgument(args[0]);
  10140. var func = funcName;
  10141. if (func in fontAliases) {
  10142. func = fontAliases[func];
  10143. }
  10144. return {
  10145. type: "font",
  10146. mode: parser.mode,
  10147. font: func.slice(1),
  10148. body
  10149. };
  10150. },
  10151. htmlBuilder: htmlBuilder$5,
  10152. mathmlBuilder: mathmlBuilder$4
  10153. });
  10154. defineFunction({
  10155. type: "mclass",
  10156. names: ["\\boldsymbol", "\\bm"],
  10157. props: {
  10158. numArgs: 1
  10159. },
  10160. handler: (_ref2, args) => {
  10161. var {
  10162. parser
  10163. } = _ref2;
  10164. var body = args[0];
  10165. var isCharacterBox = utils.isCharacterBox(body); // amsbsy.sty's \boldsymbol uses \binrel spacing to inherit the
  10166. // argument's bin|rel|ord status
  10167. return {
  10168. type: "mclass",
  10169. mode: parser.mode,
  10170. mclass: binrelClass(body),
  10171. body: [{
  10172. type: "font",
  10173. mode: parser.mode,
  10174. font: "boldsymbol",
  10175. body
  10176. }],
  10177. isCharacterBox: isCharacterBox
  10178. };
  10179. }
  10180. }); // Old font changing functions
  10181. defineFunction({
  10182. type: "font",
  10183. names: ["\\rm", "\\sf", "\\tt", "\\bf", "\\it", "\\cal"],
  10184. props: {
  10185. numArgs: 0,
  10186. allowedInText: true
  10187. },
  10188. handler: (_ref3, args) => {
  10189. var {
  10190. parser,
  10191. funcName,
  10192. breakOnTokenText
  10193. } = _ref3;
  10194. var {
  10195. mode
  10196. } = parser;
  10197. var body = parser.parseExpression(true, breakOnTokenText);
  10198. var style = "math" + funcName.slice(1);
  10199. return {
  10200. type: "font",
  10201. mode: mode,
  10202. font: style,
  10203. body: {
  10204. type: "ordgroup",
  10205. mode: parser.mode,
  10206. body
  10207. }
  10208. };
  10209. },
  10210. htmlBuilder: htmlBuilder$5,
  10211. mathmlBuilder: mathmlBuilder$4
  10212. });
  10213. var adjustStyle = (size, originalStyle) => {
  10214. // Figure out what style this fraction should be in based on the
  10215. // function used
  10216. var style = originalStyle;
  10217. if (size === "display") {
  10218. // Get display style as a default.
  10219. // If incoming style is sub/sup, use style.text() to get correct size.
  10220. style = style.id >= Style$1.SCRIPT.id ? style.text() : Style$1.DISPLAY;
  10221. } else if (size === "text" && style.size === Style$1.DISPLAY.size) {
  10222. // We're in a \tfrac but incoming style is displaystyle, so:
  10223. style = Style$1.TEXT;
  10224. } else if (size === "script") {
  10225. style = Style$1.SCRIPT;
  10226. } else if (size === "scriptscript") {
  10227. style = Style$1.SCRIPTSCRIPT;
  10228. }
  10229. return style;
  10230. };
  10231. var htmlBuilder$4 = (group, options) => {
  10232. // Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
  10233. var style = adjustStyle(group.size, options.style);
  10234. var nstyle = style.fracNum();
  10235. var dstyle = style.fracDen();
  10236. var newOptions;
  10237. newOptions = options.havingStyle(nstyle);
  10238. var numerm = buildGroup$1(group.numer, newOptions, options);
  10239. if (group.continued) {
  10240. // \cfrac inserts a \strut into the numerator.
  10241. // Get \strut dimensions from TeXbook page 353.
  10242. var hStrut = 8.5 / options.fontMetrics().ptPerEm;
  10243. var dStrut = 3.5 / options.fontMetrics().ptPerEm;
  10244. numerm.height = numerm.height < hStrut ? hStrut : numerm.height;
  10245. numerm.depth = numerm.depth < dStrut ? dStrut : numerm.depth;
  10246. }
  10247. newOptions = options.havingStyle(dstyle);
  10248. var denomm = buildGroup$1(group.denom, newOptions, options);
  10249. var rule;
  10250. var ruleWidth;
  10251. var ruleSpacing;
  10252. if (group.hasBarLine) {
  10253. if (group.barSize) {
  10254. ruleWidth = calculateSize(group.barSize, options);
  10255. rule = buildCommon.makeLineSpan("frac-line", options, ruleWidth);
  10256. } else {
  10257. rule = buildCommon.makeLineSpan("frac-line", options);
  10258. }
  10259. ruleWidth = rule.height;
  10260. ruleSpacing = rule.height;
  10261. } else {
  10262. rule = null;
  10263. ruleWidth = 0;
  10264. ruleSpacing = options.fontMetrics().defaultRuleThickness;
  10265. } // Rule 15b
  10266. var numShift;
  10267. var clearance;
  10268. var denomShift;
  10269. if (style.size === Style$1.DISPLAY.size || group.size === "display") {
  10270. numShift = options.fontMetrics().num1;
  10271. if (ruleWidth > 0) {
  10272. clearance = 3 * ruleSpacing;
  10273. } else {
  10274. clearance = 7 * ruleSpacing;
  10275. }
  10276. denomShift = options.fontMetrics().denom1;
  10277. } else {
  10278. if (ruleWidth > 0) {
  10279. numShift = options.fontMetrics().num2;
  10280. clearance = ruleSpacing;
  10281. } else {
  10282. numShift = options.fontMetrics().num3;
  10283. clearance = 3 * ruleSpacing;
  10284. }
  10285. denomShift = options.fontMetrics().denom2;
  10286. }
  10287. var frac;
  10288. if (!rule) {
  10289. // Rule 15c
  10290. var candidateClearance = numShift - numerm.depth - (denomm.height - denomShift);
  10291. if (candidateClearance < clearance) {
  10292. numShift += 0.5 * (clearance - candidateClearance);
  10293. denomShift += 0.5 * (clearance - candidateClearance);
  10294. }
  10295. frac = buildCommon.makeVList({
  10296. positionType: "individualShift",
  10297. children: [{
  10298. type: "elem",
  10299. elem: denomm,
  10300. shift: denomShift
  10301. }, {
  10302. type: "elem",
  10303. elem: numerm,
  10304. shift: -numShift
  10305. }]
  10306. }, options);
  10307. } else {
  10308. // Rule 15d
  10309. var axisHeight = options.fontMetrics().axisHeight;
  10310. if (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth) < clearance) {
  10311. numShift += clearance - (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth));
  10312. }
  10313. if (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift) < clearance) {
  10314. denomShift += clearance - (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift));
  10315. }
  10316. var midShift = -(axisHeight - 0.5 * ruleWidth);
  10317. frac = buildCommon.makeVList({
  10318. positionType: "individualShift",
  10319. children: [{
  10320. type: "elem",
  10321. elem: denomm,
  10322. shift: denomShift
  10323. }, {
  10324. type: "elem",
  10325. elem: rule,
  10326. shift: midShift
  10327. }, {
  10328. type: "elem",
  10329. elem: numerm,
  10330. shift: -numShift
  10331. }]
  10332. }, options);
  10333. } // Since we manually change the style sometimes (with \dfrac or \tfrac),
  10334. // account for the possible size change here.
  10335. newOptions = options.havingStyle(style);
  10336. frac.height *= newOptions.sizeMultiplier / options.sizeMultiplier;
  10337. frac.depth *= newOptions.sizeMultiplier / options.sizeMultiplier; // Rule 15e
  10338. var delimSize;
  10339. if (style.size === Style$1.DISPLAY.size) {
  10340. delimSize = options.fontMetrics().delim1;
  10341. } else if (style.size === Style$1.SCRIPTSCRIPT.size) {
  10342. delimSize = options.havingStyle(Style$1.SCRIPT).fontMetrics().delim2;
  10343. } else {
  10344. delimSize = options.fontMetrics().delim2;
  10345. }
  10346. var leftDelim;
  10347. var rightDelim;
  10348. if (group.leftDelim == null) {
  10349. leftDelim = makeNullDelimiter(options, ["mopen"]);
  10350. } else {
  10351. leftDelim = delimiter.customSizedDelim(group.leftDelim, delimSize, true, options.havingStyle(style), group.mode, ["mopen"]);
  10352. }
  10353. if (group.continued) {
  10354. rightDelim = buildCommon.makeSpan([]); // zero width for \cfrac
  10355. } else if (group.rightDelim == null) {
  10356. rightDelim = makeNullDelimiter(options, ["mclose"]);
  10357. } else {
  10358. rightDelim = delimiter.customSizedDelim(group.rightDelim, delimSize, true, options.havingStyle(style), group.mode, ["mclose"]);
  10359. }
  10360. return buildCommon.makeSpan(["mord"].concat(newOptions.sizingClasses(options)), [leftDelim, buildCommon.makeSpan(["mfrac"], [frac]), rightDelim], options);
  10361. };
  10362. var mathmlBuilder$3 = (group, options) => {
  10363. var node = new mathMLTree.MathNode("mfrac", [buildGroup(group.numer, options), buildGroup(group.denom, options)]);
  10364. if (!group.hasBarLine) {
  10365. node.setAttribute("linethickness", "0px");
  10366. } else if (group.barSize) {
  10367. var ruleWidth = calculateSize(group.barSize, options);
  10368. node.setAttribute("linethickness", makeEm(ruleWidth));
  10369. }
  10370. var style = adjustStyle(group.size, options.style);
  10371. if (style.size !== options.style.size) {
  10372. node = new mathMLTree.MathNode("mstyle", [node]);
  10373. var isDisplay = style.size === Style$1.DISPLAY.size ? "true" : "false";
  10374. node.setAttribute("displaystyle", isDisplay);
  10375. node.setAttribute("scriptlevel", "0");
  10376. }
  10377. if (group.leftDelim != null || group.rightDelim != null) {
  10378. var withDelims = [];
  10379. if (group.leftDelim != null) {
  10380. var leftOp = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode(group.leftDelim.replace("\\", ""))]);
  10381. leftOp.setAttribute("fence", "true");
  10382. withDelims.push(leftOp);
  10383. }
  10384. withDelims.push(node);
  10385. if (group.rightDelim != null) {
  10386. var rightOp = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode(group.rightDelim.replace("\\", ""))]);
  10387. rightOp.setAttribute("fence", "true");
  10388. withDelims.push(rightOp);
  10389. }
  10390. return makeRow(withDelims);
  10391. }
  10392. return node;
  10393. };
  10394. defineFunction({
  10395. type: "genfrac",
  10396. names: ["\\dfrac", "\\frac", "\\tfrac", "\\dbinom", "\\binom", "\\tbinom", "\\\\atopfrac", // can’t be entered directly
  10397. "\\\\bracefrac", "\\\\brackfrac" // ditto
  10398. ],
  10399. props: {
  10400. numArgs: 2,
  10401. allowedInArgument: true
  10402. },
  10403. handler: (_ref, args) => {
  10404. var {
  10405. parser,
  10406. funcName
  10407. } = _ref;
  10408. var numer = args[0];
  10409. var denom = args[1];
  10410. var hasBarLine;
  10411. var leftDelim = null;
  10412. var rightDelim = null;
  10413. var size = "auto";
  10414. switch (funcName) {
  10415. case "\\dfrac":
  10416. case "\\frac":
  10417. case "\\tfrac":
  10418. hasBarLine = true;
  10419. break;
  10420. case "\\\\atopfrac":
  10421. hasBarLine = false;
  10422. break;
  10423. case "\\dbinom":
  10424. case "\\binom":
  10425. case "\\tbinom":
  10426. hasBarLine = false;
  10427. leftDelim = "(";
  10428. rightDelim = ")";
  10429. break;
  10430. case "\\\\bracefrac":
  10431. hasBarLine = false;
  10432. leftDelim = "\\{";
  10433. rightDelim = "\\}";
  10434. break;
  10435. case "\\\\brackfrac":
  10436. hasBarLine = false;
  10437. leftDelim = "[";
  10438. rightDelim = "]";
  10439. break;
  10440. default:
  10441. throw new Error("Unrecognized genfrac command");
  10442. }
  10443. switch (funcName) {
  10444. case "\\dfrac":
  10445. case "\\dbinom":
  10446. size = "display";
  10447. break;
  10448. case "\\tfrac":
  10449. case "\\tbinom":
  10450. size = "text";
  10451. break;
  10452. }
  10453. return {
  10454. type: "genfrac",
  10455. mode: parser.mode,
  10456. continued: false,
  10457. numer,
  10458. denom,
  10459. hasBarLine,
  10460. leftDelim,
  10461. rightDelim,
  10462. size,
  10463. barSize: null
  10464. };
  10465. },
  10466. htmlBuilder: htmlBuilder$4,
  10467. mathmlBuilder: mathmlBuilder$3
  10468. });
  10469. defineFunction({
  10470. type: "genfrac",
  10471. names: ["\\cfrac"],
  10472. props: {
  10473. numArgs: 2
  10474. },
  10475. handler: (_ref2, args) => {
  10476. var {
  10477. parser,
  10478. funcName
  10479. } = _ref2;
  10480. var numer = args[0];
  10481. var denom = args[1];
  10482. return {
  10483. type: "genfrac",
  10484. mode: parser.mode,
  10485. continued: true,
  10486. numer,
  10487. denom,
  10488. hasBarLine: true,
  10489. leftDelim: null,
  10490. rightDelim: null,
  10491. size: "display",
  10492. barSize: null
  10493. };
  10494. }
  10495. }); // Infix generalized fractions -- these are not rendered directly, but replaced
  10496. // immediately by one of the variants above.
  10497. defineFunction({
  10498. type: "infix",
  10499. names: ["\\over", "\\choose", "\\atop", "\\brace", "\\brack"],
  10500. props: {
  10501. numArgs: 0,
  10502. infix: true
  10503. },
  10504. handler(_ref3) {
  10505. var {
  10506. parser,
  10507. funcName,
  10508. token
  10509. } = _ref3;
  10510. var replaceWith;
  10511. switch (funcName) {
  10512. case "\\over":
  10513. replaceWith = "\\frac";
  10514. break;
  10515. case "\\choose":
  10516. replaceWith = "\\binom";
  10517. break;
  10518. case "\\atop":
  10519. replaceWith = "\\\\atopfrac";
  10520. break;
  10521. case "\\brace":
  10522. replaceWith = "\\\\bracefrac";
  10523. break;
  10524. case "\\brack":
  10525. replaceWith = "\\\\brackfrac";
  10526. break;
  10527. default:
  10528. throw new Error("Unrecognized infix genfrac command");
  10529. }
  10530. return {
  10531. type: "infix",
  10532. mode: parser.mode,
  10533. replaceWith,
  10534. token
  10535. };
  10536. }
  10537. });
  10538. var stylArray = ["display", "text", "script", "scriptscript"];
  10539. var delimFromValue = function delimFromValue(delimString) {
  10540. var delim = null;
  10541. if (delimString.length > 0) {
  10542. delim = delimString;
  10543. delim = delim === "." ? null : delim;
  10544. }
  10545. return delim;
  10546. };
  10547. defineFunction({
  10548. type: "genfrac",
  10549. names: ["\\genfrac"],
  10550. props: {
  10551. numArgs: 6,
  10552. allowedInArgument: true,
  10553. argTypes: ["math", "math", "size", "text", "math", "math"]
  10554. },
  10555. handler(_ref4, args) {
  10556. var {
  10557. parser
  10558. } = _ref4;
  10559. var numer = args[4];
  10560. var denom = args[5]; // Look into the parse nodes to get the desired delimiters.
  10561. var leftNode = normalizeArgument(args[0]);
  10562. var leftDelim = leftNode.type === "atom" && leftNode.family === "open" ? delimFromValue(leftNode.text) : null;
  10563. var rightNode = normalizeArgument(args[1]);
  10564. var rightDelim = rightNode.type === "atom" && rightNode.family === "close" ? delimFromValue(rightNode.text) : null;
  10565. var barNode = assertNodeType(args[2], "size");
  10566. var hasBarLine;
  10567. var barSize = null;
  10568. if (barNode.isBlank) {
  10569. // \genfrac acts differently than \above.
  10570. // \genfrac treats an empty size group as a signal to use a
  10571. // standard bar size. \above would see size = 0 and omit the bar.
  10572. hasBarLine = true;
  10573. } else {
  10574. barSize = barNode.value;
  10575. hasBarLine = barSize.number > 0;
  10576. } // Find out if we want displaystyle, textstyle, etc.
  10577. var size = "auto";
  10578. var styl = args[3];
  10579. if (styl.type === "ordgroup") {
  10580. if (styl.body.length > 0) {
  10581. var textOrd = assertNodeType(styl.body[0], "textord");
  10582. size = stylArray[Number(textOrd.text)];
  10583. }
  10584. } else {
  10585. styl = assertNodeType(styl, "textord");
  10586. size = stylArray[Number(styl.text)];
  10587. }
  10588. return {
  10589. type: "genfrac",
  10590. mode: parser.mode,
  10591. numer,
  10592. denom,
  10593. continued: false,
  10594. hasBarLine,
  10595. barSize,
  10596. leftDelim,
  10597. rightDelim,
  10598. size
  10599. };
  10600. },
  10601. htmlBuilder: htmlBuilder$4,
  10602. mathmlBuilder: mathmlBuilder$3
  10603. }); // \above is an infix fraction that also defines a fraction bar size.
  10604. defineFunction({
  10605. type: "infix",
  10606. names: ["\\above"],
  10607. props: {
  10608. numArgs: 1,
  10609. argTypes: ["size"],
  10610. infix: true
  10611. },
  10612. handler(_ref5, args) {
  10613. var {
  10614. parser,
  10615. funcName,
  10616. token
  10617. } = _ref5;
  10618. return {
  10619. type: "infix",
  10620. mode: parser.mode,
  10621. replaceWith: "\\\\abovefrac",
  10622. size: assertNodeType(args[0], "size").value,
  10623. token
  10624. };
  10625. }
  10626. });
  10627. defineFunction({
  10628. type: "genfrac",
  10629. names: ["\\\\abovefrac"],
  10630. props: {
  10631. numArgs: 3,
  10632. argTypes: ["math", "size", "math"]
  10633. },
  10634. handler: (_ref6, args) => {
  10635. var {
  10636. parser,
  10637. funcName
  10638. } = _ref6;
  10639. var numer = args[0];
  10640. var barSize = assert(assertNodeType(args[1], "infix").size);
  10641. var denom = args[2];
  10642. var hasBarLine = barSize.number > 0;
  10643. return {
  10644. type: "genfrac",
  10645. mode: parser.mode,
  10646. numer,
  10647. denom,
  10648. continued: false,
  10649. hasBarLine,
  10650. barSize,
  10651. leftDelim: null,
  10652. rightDelim: null,
  10653. size: "auto"
  10654. };
  10655. },
  10656. htmlBuilder: htmlBuilder$4,
  10657. mathmlBuilder: mathmlBuilder$3
  10658. });
  10659. // NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
  10660. // also "supsub" since an over/underbrace can affect super/subscripting.
  10661. var htmlBuilder$3 = (grp, options) => {
  10662. var style = options.style; // Pull out the `ParseNode<"horizBrace">` if `grp` is a "supsub" node.
  10663. var supSubGroup;
  10664. var group;
  10665. if (grp.type === "supsub") {
  10666. // Ref: LaTeX source2e: }}}}\limits}
  10667. // i.e. LaTeX treats the brace similar to an op and passes it
  10668. // with \limits, so we need to assign supsub style.
  10669. supSubGroup = grp.sup ? buildGroup$1(grp.sup, options.havingStyle(style.sup()), options) : buildGroup$1(grp.sub, options.havingStyle(style.sub()), options);
  10670. group = assertNodeType(grp.base, "horizBrace");
  10671. } else {
  10672. group = assertNodeType(grp, "horizBrace");
  10673. } // Build the base group
  10674. var body = buildGroup$1(group.base, options.havingBaseStyle(Style$1.DISPLAY)); // Create the stretchy element
  10675. var braceBody = stretchy.svgSpan(group, options); // Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
  10676. // This first vlist contains the content and the brace: equation
  10677. var vlist;
  10678. if (group.isOver) {
  10679. vlist = buildCommon.makeVList({
  10680. positionType: "firstBaseline",
  10681. children: [{
  10682. type: "elem",
  10683. elem: body
  10684. }, {
  10685. type: "kern",
  10686. size: 0.1
  10687. }, {
  10688. type: "elem",
  10689. elem: braceBody
  10690. }]
  10691. }, options); // $FlowFixMe: Replace this with passing "svg-align" into makeVList.
  10692. vlist.children[0].children[0].children[1].classes.push("svg-align");
  10693. } else {
  10694. vlist = buildCommon.makeVList({
  10695. positionType: "bottom",
  10696. positionData: body.depth + 0.1 + braceBody.height,
  10697. children: [{
  10698. type: "elem",
  10699. elem: braceBody
  10700. }, {
  10701. type: "kern",
  10702. size: 0.1
  10703. }, {
  10704. type: "elem",
  10705. elem: body
  10706. }]
  10707. }, options); // $FlowFixMe: Replace this with passing "svg-align" into makeVList.
  10708. vlist.children[0].children[0].children[0].classes.push("svg-align");
  10709. }
  10710. if (supSubGroup) {
  10711. // To write the supsub, wrap the first vlist in another vlist:
  10712. // They can't all go in the same vlist, because the note might be
  10713. // wider than the equation. We want the equation to control the
  10714. // brace width.
  10715. // note long note long note
  10716. // ┏━━━━━━━━┓ or ┏━━━┓ not ┏━━━━━━━━━┓
  10717. // equation eqn eqn
  10718. var vSpan = buildCommon.makeSpan(["mord", group.isOver ? "mover" : "munder"], [vlist], options);
  10719. if (group.isOver) {
  10720. vlist = buildCommon.makeVList({
  10721. positionType: "firstBaseline",
  10722. children: [{
  10723. type: "elem",
  10724. elem: vSpan
  10725. }, {
  10726. type: "kern",
  10727. size: 0.2
  10728. }, {
  10729. type: "elem",
  10730. elem: supSubGroup
  10731. }]
  10732. }, options);
  10733. } else {
  10734. vlist = buildCommon.makeVList({
  10735. positionType: "bottom",
  10736. positionData: vSpan.depth + 0.2 + supSubGroup.height + supSubGroup.depth,
  10737. children: [{
  10738. type: "elem",
  10739. elem: supSubGroup
  10740. }, {
  10741. type: "kern",
  10742. size: 0.2
  10743. }, {
  10744. type: "elem",
  10745. elem: vSpan
  10746. }]
  10747. }, options);
  10748. }
  10749. }
  10750. return buildCommon.makeSpan(["mord", group.isOver ? "mover" : "munder"], [vlist], options);
  10751. };
  10752. var mathmlBuilder$2 = (group, options) => {
  10753. var accentNode = stretchy.mathMLnode(group.label);
  10754. return new mathMLTree.MathNode(group.isOver ? "mover" : "munder", [buildGroup(group.base, options), accentNode]);
  10755. }; // Horizontal stretchy braces
  10756. defineFunction({
  10757. type: "horizBrace",
  10758. names: ["\\overbrace", "\\underbrace"],
  10759. props: {
  10760. numArgs: 1
  10761. },
  10762. handler(_ref, args) {
  10763. var {
  10764. parser,
  10765. funcName
  10766. } = _ref;
  10767. return {
  10768. type: "horizBrace",
  10769. mode: parser.mode,
  10770. label: funcName,
  10771. isOver: /^\\over/.test(funcName),
  10772. base: args[0]
  10773. };
  10774. },
  10775. htmlBuilder: htmlBuilder$3,
  10776. mathmlBuilder: mathmlBuilder$2
  10777. });
  10778. defineFunction({
  10779. type: "href",
  10780. names: ["\\href"],
  10781. props: {
  10782. numArgs: 2,
  10783. argTypes: ["url", "original"],
  10784. allowedInText: true
  10785. },
  10786. handler: (_ref, args) => {
  10787. var {
  10788. parser
  10789. } = _ref;
  10790. var body = args[1];
  10791. var href = assertNodeType(args[0], "url").url;
  10792. if (!parser.settings.isTrusted({
  10793. command: "\\href",
  10794. url: href
  10795. })) {
  10796. return parser.formatUnsupportedCmd("\\href");
  10797. }
  10798. return {
  10799. type: "href",
  10800. mode: parser.mode,
  10801. href,
  10802. body: ordargument(body)
  10803. };
  10804. },
  10805. htmlBuilder: (group, options) => {
  10806. var elements = buildExpression$1(group.body, options, false);
  10807. return buildCommon.makeAnchor(group.href, [], elements, options);
  10808. },
  10809. mathmlBuilder: (group, options) => {
  10810. var math = buildExpressionRow(group.body, options);
  10811. if (!(math instanceof MathNode)) {
  10812. math = new MathNode("mrow", [math]);
  10813. }
  10814. math.setAttribute("href", group.href);
  10815. return math;
  10816. }
  10817. });
  10818. defineFunction({
  10819. type: "href",
  10820. names: ["\\url"],
  10821. props: {
  10822. numArgs: 1,
  10823. argTypes: ["url"],
  10824. allowedInText: true
  10825. },
  10826. handler: (_ref2, args) => {
  10827. var {
  10828. parser
  10829. } = _ref2;
  10830. var href = assertNodeType(args[0], "url").url;
  10831. if (!parser.settings.isTrusted({
  10832. command: "\\url",
  10833. url: href
  10834. })) {
  10835. return parser.formatUnsupportedCmd("\\url");
  10836. }
  10837. var chars = [];
  10838. for (var i = 0; i < href.length; i++) {
  10839. var c = href[i];
  10840. if (c === "~") {
  10841. c = "\\textasciitilde";
  10842. }
  10843. chars.push({
  10844. type: "textord",
  10845. mode: "text",
  10846. text: c
  10847. });
  10848. }
  10849. var body = {
  10850. type: "text",
  10851. mode: parser.mode,
  10852. font: "\\texttt",
  10853. body: chars
  10854. };
  10855. return {
  10856. type: "href",
  10857. mode: parser.mode,
  10858. href,
  10859. body: ordargument(body)
  10860. };
  10861. }
  10862. });
  10863. // In LaTeX, \vcenter can act only on a box, as in
  10864. // \vcenter{\hbox{$\frac{a+b}{\dfrac{c}{d}}$}}
  10865. // This function by itself doesn't do anything but prevent a soft line break.
  10866. defineFunction({
  10867. type: "hbox",
  10868. names: ["\\hbox"],
  10869. props: {
  10870. numArgs: 1,
  10871. argTypes: ["text"],
  10872. allowedInText: true,
  10873. primitive: true
  10874. },
  10875. handler(_ref, args) {
  10876. var {
  10877. parser
  10878. } = _ref;
  10879. return {
  10880. type: "hbox",
  10881. mode: parser.mode,
  10882. body: ordargument(args[0])
  10883. };
  10884. },
  10885. htmlBuilder(group, options) {
  10886. var elements = buildExpression$1(group.body, options, false);
  10887. return buildCommon.makeFragment(elements);
  10888. },
  10889. mathmlBuilder(group, options) {
  10890. return new mathMLTree.MathNode("mrow", buildExpression(group.body, options));
  10891. }
  10892. });
  10893. defineFunction({
  10894. type: "html",
  10895. names: ["\\htmlClass", "\\htmlId", "\\htmlStyle", "\\htmlData"],
  10896. props: {
  10897. numArgs: 2,
  10898. argTypes: ["raw", "original"],
  10899. allowedInText: true
  10900. },
  10901. handler: (_ref, args) => {
  10902. var {
  10903. parser,
  10904. funcName,
  10905. token
  10906. } = _ref;
  10907. var value = assertNodeType(args[0], "raw").string;
  10908. var body = args[1];
  10909. if (parser.settings.strict) {
  10910. parser.settings.reportNonstrict("htmlExtension", "HTML extension is disabled on strict mode");
  10911. }
  10912. var trustContext;
  10913. var attributes = {};
  10914. switch (funcName) {
  10915. case "\\htmlClass":
  10916. attributes.class = value;
  10917. trustContext = {
  10918. command: "\\htmlClass",
  10919. class: value
  10920. };
  10921. break;
  10922. case "\\htmlId":
  10923. attributes.id = value;
  10924. trustContext = {
  10925. command: "\\htmlId",
  10926. id: value
  10927. };
  10928. break;
  10929. case "\\htmlStyle":
  10930. attributes.style = value;
  10931. trustContext = {
  10932. command: "\\htmlStyle",
  10933. style: value
  10934. };
  10935. break;
  10936. case "\\htmlData":
  10937. {
  10938. var data = value.split(",");
  10939. for (var i = 0; i < data.length; i++) {
  10940. var keyVal = data[i].split("=");
  10941. if (keyVal.length !== 2) {
  10942. throw new ParseError("Error parsing key-value for \\htmlData");
  10943. }
  10944. attributes["data-" + keyVal[0].trim()] = keyVal[1].trim();
  10945. }
  10946. trustContext = {
  10947. command: "\\htmlData",
  10948. attributes
  10949. };
  10950. break;
  10951. }
  10952. default:
  10953. throw new Error("Unrecognized html command");
  10954. }
  10955. if (!parser.settings.isTrusted(trustContext)) {
  10956. return parser.formatUnsupportedCmd(funcName);
  10957. }
  10958. return {
  10959. type: "html",
  10960. mode: parser.mode,
  10961. attributes,
  10962. body: ordargument(body)
  10963. };
  10964. },
  10965. htmlBuilder: (group, options) => {
  10966. var elements = buildExpression$1(group.body, options, false);
  10967. var classes = ["enclosing"];
  10968. if (group.attributes.class) {
  10969. classes.push(...group.attributes.class.trim().split(/\s+/));
  10970. }
  10971. var span = buildCommon.makeSpan(classes, elements, options);
  10972. for (var attr in group.attributes) {
  10973. if (attr !== "class" && group.attributes.hasOwnProperty(attr)) {
  10974. span.setAttribute(attr, group.attributes[attr]);
  10975. }
  10976. }
  10977. return span;
  10978. },
  10979. mathmlBuilder: (group, options) => {
  10980. return buildExpressionRow(group.body, options);
  10981. }
  10982. });
  10983. defineFunction({
  10984. type: "htmlmathml",
  10985. names: ["\\html@mathml"],
  10986. props: {
  10987. numArgs: 2,
  10988. allowedInText: true
  10989. },
  10990. handler: (_ref, args) => {
  10991. var {
  10992. parser
  10993. } = _ref;
  10994. return {
  10995. type: "htmlmathml",
  10996. mode: parser.mode,
  10997. html: ordargument(args[0]),
  10998. mathml: ordargument(args[1])
  10999. };
  11000. },
  11001. htmlBuilder: (group, options) => {
  11002. var elements = buildExpression$1(group.html, options, false);
  11003. return buildCommon.makeFragment(elements);
  11004. },
  11005. mathmlBuilder: (group, options) => {
  11006. return buildExpressionRow(group.mathml, options);
  11007. }
  11008. });
  11009. var sizeData = function sizeData(str) {
  11010. if (/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(str)) {
  11011. // str is a number with no unit specified.
  11012. // default unit is bp, per graphix package.
  11013. return {
  11014. number: +str,
  11015. unit: "bp"
  11016. };
  11017. } else {
  11018. var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(str);
  11019. if (!match) {
  11020. throw new ParseError("Invalid size: '" + str + "' in \\includegraphics");
  11021. }
  11022. var data = {
  11023. number: +(match[1] + match[2]),
  11024. // sign + magnitude, cast to number
  11025. unit: match[3]
  11026. };
  11027. if (!validUnit(data)) {
  11028. throw new ParseError("Invalid unit: '" + data.unit + "' in \\includegraphics.");
  11029. }
  11030. return data;
  11031. }
  11032. };
  11033. defineFunction({
  11034. type: "includegraphics",
  11035. names: ["\\includegraphics"],
  11036. props: {
  11037. numArgs: 1,
  11038. numOptionalArgs: 1,
  11039. argTypes: ["raw", "url"],
  11040. allowedInText: false
  11041. },
  11042. handler: (_ref, args, optArgs) => {
  11043. var {
  11044. parser
  11045. } = _ref;
  11046. var width = {
  11047. number: 0,
  11048. unit: "em"
  11049. };
  11050. var height = {
  11051. number: 0.9,
  11052. unit: "em"
  11053. }; // sorta character sized.
  11054. var totalheight = {
  11055. number: 0,
  11056. unit: "em"
  11057. };
  11058. var alt = "";
  11059. if (optArgs[0]) {
  11060. var attributeStr = assertNodeType(optArgs[0], "raw").string; // Parser.js does not parse key/value pairs. We get a string.
  11061. var attributes = attributeStr.split(",");
  11062. for (var i = 0; i < attributes.length; i++) {
  11063. var keyVal = attributes[i].split("=");
  11064. if (keyVal.length === 2) {
  11065. var str = keyVal[1].trim();
  11066. switch (keyVal[0].trim()) {
  11067. case "alt":
  11068. alt = str;
  11069. break;
  11070. case "width":
  11071. width = sizeData(str);
  11072. break;
  11073. case "height":
  11074. height = sizeData(str);
  11075. break;
  11076. case "totalheight":
  11077. totalheight = sizeData(str);
  11078. break;
  11079. default:
  11080. throw new ParseError("Invalid key: '" + keyVal[0] + "' in \\includegraphics.");
  11081. }
  11082. }
  11083. }
  11084. }
  11085. var src = assertNodeType(args[0], "url").url;
  11086. if (alt === "") {
  11087. // No alt given. Use the file name. Strip away the path.
  11088. alt = src;
  11089. alt = alt.replace(/^.*[\\/]/, '');
  11090. alt = alt.substring(0, alt.lastIndexOf('.'));
  11091. }
  11092. if (!parser.settings.isTrusted({
  11093. command: "\\includegraphics",
  11094. url: src
  11095. })) {
  11096. return parser.formatUnsupportedCmd("\\includegraphics");
  11097. }
  11098. return {
  11099. type: "includegraphics",
  11100. mode: parser.mode,
  11101. alt: alt,
  11102. width: width,
  11103. height: height,
  11104. totalheight: totalheight,
  11105. src: src
  11106. };
  11107. },
  11108. htmlBuilder: (group, options) => {
  11109. var height = calculateSize(group.height, options);
  11110. var depth = 0;
  11111. if (group.totalheight.number > 0) {
  11112. depth = calculateSize(group.totalheight, options) - height;
  11113. }
  11114. var width = 0;
  11115. if (group.width.number > 0) {
  11116. width = calculateSize(group.width, options);
  11117. }
  11118. var style = {
  11119. height: makeEm(height + depth)
  11120. };
  11121. if (width > 0) {
  11122. style.width = makeEm(width);
  11123. }
  11124. if (depth > 0) {
  11125. style.verticalAlign = makeEm(-depth);
  11126. }
  11127. var node = new Img(group.src, group.alt, style);
  11128. node.height = height;
  11129. node.depth = depth;
  11130. return node;
  11131. },
  11132. mathmlBuilder: (group, options) => {
  11133. var node = new mathMLTree.MathNode("mglyph", []);
  11134. node.setAttribute("alt", group.alt);
  11135. var height = calculateSize(group.height, options);
  11136. var depth = 0;
  11137. if (group.totalheight.number > 0) {
  11138. depth = calculateSize(group.totalheight, options) - height;
  11139. node.setAttribute("valign", makeEm(-depth));
  11140. }
  11141. node.setAttribute("height", makeEm(height + depth));
  11142. if (group.width.number > 0) {
  11143. var width = calculateSize(group.width, options);
  11144. node.setAttribute("width", makeEm(width));
  11145. }
  11146. node.setAttribute("src", group.src);
  11147. return node;
  11148. }
  11149. });
  11150. // Horizontal spacing commands
  11151. defineFunction({
  11152. type: "kern",
  11153. names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
  11154. props: {
  11155. numArgs: 1,
  11156. argTypes: ["size"],
  11157. primitive: true,
  11158. allowedInText: true
  11159. },
  11160. handler(_ref, args) {
  11161. var {
  11162. parser,
  11163. funcName
  11164. } = _ref;
  11165. var size = assertNodeType(args[0], "size");
  11166. if (parser.settings.strict) {
  11167. var mathFunction = funcName[1] === 'm'; // \mkern, \mskip
  11168. var muUnit = size.value.unit === 'mu';
  11169. if (mathFunction) {
  11170. if (!muUnit) {
  11171. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " supports only mu units, " + ("not " + size.value.unit + " units"));
  11172. }
  11173. if (parser.mode !== "math") {
  11174. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " works only in math mode");
  11175. }
  11176. } else {
  11177. // !mathFunction
  11178. if (muUnit) {
  11179. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " doesn't support mu units");
  11180. }
  11181. }
  11182. }
  11183. return {
  11184. type: "kern",
  11185. mode: parser.mode,
  11186. dimension: size.value
  11187. };
  11188. },
  11189. htmlBuilder(group, options) {
  11190. return buildCommon.makeGlue(group.dimension, options);
  11191. },
  11192. mathmlBuilder(group, options) {
  11193. var dimension = calculateSize(group.dimension, options);
  11194. return new mathMLTree.SpaceNode(dimension);
  11195. }
  11196. });
  11197. // Horizontal overlap functions
  11198. defineFunction({
  11199. type: "lap",
  11200. names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
  11201. props: {
  11202. numArgs: 1,
  11203. allowedInText: true
  11204. },
  11205. handler: (_ref, args) => {
  11206. var {
  11207. parser,
  11208. funcName
  11209. } = _ref;
  11210. var body = args[0];
  11211. return {
  11212. type: "lap",
  11213. mode: parser.mode,
  11214. alignment: funcName.slice(5),
  11215. body
  11216. };
  11217. },
  11218. htmlBuilder: (group, options) => {
  11219. // mathllap, mathrlap, mathclap
  11220. var inner;
  11221. if (group.alignment === "clap") {
  11222. // ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
  11223. inner = buildCommon.makeSpan([], [buildGroup$1(group.body, options)]); // wrap, since CSS will center a .clap > .inner > span
  11224. inner = buildCommon.makeSpan(["inner"], [inner], options);
  11225. } else {
  11226. inner = buildCommon.makeSpan(["inner"], [buildGroup$1(group.body, options)]);
  11227. }
  11228. var fix = buildCommon.makeSpan(["fix"], []);
  11229. var node = buildCommon.makeSpan([group.alignment], [inner, fix], options); // At this point, we have correctly set horizontal alignment of the
  11230. // two items involved in the lap.
  11231. // Next, use a strut to set the height of the HTML bounding box.
  11232. // Otherwise, a tall argument may be misplaced.
  11233. // This code resolved issue #1153
  11234. var strut = buildCommon.makeSpan(["strut"]);
  11235. strut.style.height = makeEm(node.height + node.depth);
  11236. if (node.depth) {
  11237. strut.style.verticalAlign = makeEm(-node.depth);
  11238. }
  11239. node.children.unshift(strut); // Next, prevent vertical misplacement when next to something tall.
  11240. // This code resolves issue #1234
  11241. node = buildCommon.makeSpan(["thinbox"], [node], options);
  11242. return buildCommon.makeSpan(["mord", "vbox"], [node], options);
  11243. },
  11244. mathmlBuilder: (group, options) => {
  11245. // mathllap, mathrlap, mathclap
  11246. var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
  11247. if (group.alignment !== "rlap") {
  11248. var offset = group.alignment === "llap" ? "-1" : "-0.5";
  11249. node.setAttribute("lspace", offset + "width");
  11250. }
  11251. node.setAttribute("width", "0px");
  11252. return node;
  11253. }
  11254. });
  11255. defineFunction({
  11256. type: "styling",
  11257. names: ["\\(", "$"],
  11258. props: {
  11259. numArgs: 0,
  11260. allowedInText: true,
  11261. allowedInMath: false
  11262. },
  11263. handler(_ref, args) {
  11264. var {
  11265. funcName,
  11266. parser
  11267. } = _ref;
  11268. var outerMode = parser.mode;
  11269. parser.switchMode("math");
  11270. var close = funcName === "\\(" ? "\\)" : "$";
  11271. var body = parser.parseExpression(false, close);
  11272. parser.expect(close);
  11273. parser.switchMode(outerMode);
  11274. return {
  11275. type: "styling",
  11276. mode: parser.mode,
  11277. style: "text",
  11278. body
  11279. };
  11280. }
  11281. }); // Check for extra closing math delimiters
  11282. defineFunction({
  11283. type: "text",
  11284. // Doesn't matter what this is.
  11285. names: ["\\)", "\\]"],
  11286. props: {
  11287. numArgs: 0,
  11288. allowedInText: true,
  11289. allowedInMath: false
  11290. },
  11291. handler(context, args) {
  11292. throw new ParseError("Mismatched " + context.funcName);
  11293. }
  11294. });
  11295. var chooseMathStyle = (group, options) => {
  11296. switch (options.style.size) {
  11297. case Style$1.DISPLAY.size:
  11298. return group.display;
  11299. case Style$1.TEXT.size:
  11300. return group.text;
  11301. case Style$1.SCRIPT.size:
  11302. return group.script;
  11303. case Style$1.SCRIPTSCRIPT.size:
  11304. return group.scriptscript;
  11305. default:
  11306. return group.text;
  11307. }
  11308. };
  11309. defineFunction({
  11310. type: "mathchoice",
  11311. names: ["\\mathchoice"],
  11312. props: {
  11313. numArgs: 4,
  11314. primitive: true
  11315. },
  11316. handler: (_ref, args) => {
  11317. var {
  11318. parser
  11319. } = _ref;
  11320. return {
  11321. type: "mathchoice",
  11322. mode: parser.mode,
  11323. display: ordargument(args[0]),
  11324. text: ordargument(args[1]),
  11325. script: ordargument(args[2]),
  11326. scriptscript: ordargument(args[3])
  11327. };
  11328. },
  11329. htmlBuilder: (group, options) => {
  11330. var body = chooseMathStyle(group, options);
  11331. var elements = buildExpression$1(body, options, false);
  11332. return buildCommon.makeFragment(elements);
  11333. },
  11334. mathmlBuilder: (group, options) => {
  11335. var body = chooseMathStyle(group, options);
  11336. return buildExpressionRow(body, options);
  11337. }
  11338. });
  11339. var assembleSupSub = (base, supGroup, subGroup, options, style, slant, baseShift) => {
  11340. base = buildCommon.makeSpan([], [base]);
  11341. var subIsSingleCharacter = subGroup && utils.isCharacterBox(subGroup);
  11342. var sub;
  11343. var sup; // We manually have to handle the superscripts and subscripts. This,
  11344. // aside from the kern calculations, is copied from supsub.
  11345. if (supGroup) {
  11346. var elem = buildGroup$1(supGroup, options.havingStyle(style.sup()), options);
  11347. sup = {
  11348. elem,
  11349. kern: Math.max(options.fontMetrics().bigOpSpacing1, options.fontMetrics().bigOpSpacing3 - elem.depth)
  11350. };
  11351. }
  11352. if (subGroup) {
  11353. var _elem = buildGroup$1(subGroup, options.havingStyle(style.sub()), options);
  11354. sub = {
  11355. elem: _elem,
  11356. kern: Math.max(options.fontMetrics().bigOpSpacing2, options.fontMetrics().bigOpSpacing4 - _elem.height)
  11357. };
  11358. } // Build the final group as a vlist of the possible subscript, base,
  11359. // and possible superscript.
  11360. var finalGroup;
  11361. if (sup && sub) {
  11362. var bottom = options.fontMetrics().bigOpSpacing5 + sub.elem.height + sub.elem.depth + sub.kern + base.depth + baseShift;
  11363. finalGroup = buildCommon.makeVList({
  11364. positionType: "bottom",
  11365. positionData: bottom,
  11366. children: [{
  11367. type: "kern",
  11368. size: options.fontMetrics().bigOpSpacing5
  11369. }, {
  11370. type: "elem",
  11371. elem: sub.elem,
  11372. marginLeft: makeEm(-slant)
  11373. }, {
  11374. type: "kern",
  11375. size: sub.kern
  11376. }, {
  11377. type: "elem",
  11378. elem: base
  11379. }, {
  11380. type: "kern",
  11381. size: sup.kern
  11382. }, {
  11383. type: "elem",
  11384. elem: sup.elem,
  11385. marginLeft: makeEm(slant)
  11386. }, {
  11387. type: "kern",
  11388. size: options.fontMetrics().bigOpSpacing5
  11389. }]
  11390. }, options);
  11391. } else if (sub) {
  11392. var top = base.height - baseShift; // Shift the limits by the slant of the symbol. Note
  11393. // that we are supposed to shift the limits by 1/2 of the slant,
  11394. // but since we are centering the limits adding a full slant of
  11395. // margin will shift by 1/2 that.
  11396. finalGroup = buildCommon.makeVList({
  11397. positionType: "top",
  11398. positionData: top,
  11399. children: [{
  11400. type: "kern",
  11401. size: options.fontMetrics().bigOpSpacing5
  11402. }, {
  11403. type: "elem",
  11404. elem: sub.elem,
  11405. marginLeft: makeEm(-slant)
  11406. }, {
  11407. type: "kern",
  11408. size: sub.kern
  11409. }, {
  11410. type: "elem",
  11411. elem: base
  11412. }]
  11413. }, options);
  11414. } else if (sup) {
  11415. var _bottom = base.depth + baseShift;
  11416. finalGroup = buildCommon.makeVList({
  11417. positionType: "bottom",
  11418. positionData: _bottom,
  11419. children: [{
  11420. type: "elem",
  11421. elem: base
  11422. }, {
  11423. type: "kern",
  11424. size: sup.kern
  11425. }, {
  11426. type: "elem",
  11427. elem: sup.elem,
  11428. marginLeft: makeEm(slant)
  11429. }, {
  11430. type: "kern",
  11431. size: options.fontMetrics().bigOpSpacing5
  11432. }]
  11433. }, options);
  11434. } else {
  11435. // This case probably shouldn't occur (this would mean the
  11436. // supsub was sending us a group with no superscript or
  11437. // subscript) but be safe.
  11438. return base;
  11439. }
  11440. var parts = [finalGroup];
  11441. if (sub && slant !== 0 && !subIsSingleCharacter) {
  11442. // A negative margin-left was applied to the lower limit.
  11443. // Avoid an overlap by placing a spacer on the left on the group.
  11444. var spacer = buildCommon.makeSpan(["mspace"], [], options);
  11445. spacer.style.marginRight = makeEm(slant);
  11446. parts.unshift(spacer);
  11447. }
  11448. return buildCommon.makeSpan(["mop", "op-limits"], parts, options);
  11449. };
  11450. // Limits, symbols
  11451. // Most operators have a large successor symbol, but these don't.
  11452. var noSuccessor = ["\\smallint"]; // NOTE: Unlike most `htmlBuilder`s, this one handles not only "op", but also
  11453. // "supsub" since some of them (like \int) can affect super/subscripting.
  11454. var htmlBuilder$2 = (grp, options) => {
  11455. // Operators are handled in the TeXbook pg. 443-444, rule 13(a).
  11456. var supGroup;
  11457. var subGroup;
  11458. var hasLimits = false;
  11459. var group;
  11460. if (grp.type === "supsub") {
  11461. // If we have limits, supsub will pass us its group to handle. Pull
  11462. // out the superscript and subscript and set the group to the op in
  11463. // its base.
  11464. supGroup = grp.sup;
  11465. subGroup = grp.sub;
  11466. group = assertNodeType(grp.base, "op");
  11467. hasLimits = true;
  11468. } else {
  11469. group = assertNodeType(grp, "op");
  11470. }
  11471. var style = options.style;
  11472. var large = false;
  11473. if (style.size === Style$1.DISPLAY.size && group.symbol && !utils.contains(noSuccessor, group.name)) {
  11474. // Most symbol operators get larger in displaystyle (rule 13)
  11475. large = true;
  11476. }
  11477. var base;
  11478. if (group.symbol) {
  11479. // If this is a symbol, create the symbol.
  11480. var fontName = large ? "Size2-Regular" : "Size1-Regular";
  11481. var stash = "";
  11482. if (group.name === "\\oiint" || group.name === "\\oiiint") {
  11483. // No font glyphs yet, so use a glyph w/o the oval.
  11484. // TODO: When font glyphs are available, delete this code.
  11485. stash = group.name.slice(1);
  11486. group.name = stash === "oiint" ? "\\iint" : "\\iiint";
  11487. }
  11488. base = buildCommon.makeSymbol(group.name, fontName, "math", options, ["mop", "op-symbol", large ? "large-op" : "small-op"]);
  11489. if (stash.length > 0) {
  11490. // We're in \oiint or \oiiint. Overlay the oval.
  11491. // TODO: When font glyphs are available, delete this code.
  11492. var italic = base.italic;
  11493. var oval = buildCommon.staticSvg(stash + "Size" + (large ? "2" : "1"), options);
  11494. base = buildCommon.makeVList({
  11495. positionType: "individualShift",
  11496. children: [{
  11497. type: "elem",
  11498. elem: base,
  11499. shift: 0
  11500. }, {
  11501. type: "elem",
  11502. elem: oval,
  11503. shift: large ? 0.08 : 0
  11504. }]
  11505. }, options);
  11506. group.name = "\\" + stash;
  11507. base.classes.unshift("mop"); // $FlowFixMe
  11508. base.italic = italic;
  11509. }
  11510. } else if (group.body) {
  11511. // If this is a list, compose that list.
  11512. var inner = buildExpression$1(group.body, options, true);
  11513. if (inner.length === 1 && inner[0] instanceof SymbolNode) {
  11514. base = inner[0];
  11515. base.classes[0] = "mop"; // replace old mclass
  11516. } else {
  11517. base = buildCommon.makeSpan(["mop"], inner, options);
  11518. }
  11519. } else {
  11520. // Otherwise, this is a text operator. Build the text from the
  11521. // operator's name.
  11522. var output = [];
  11523. for (var i = 1; i < group.name.length; i++) {
  11524. output.push(buildCommon.mathsym(group.name[i], group.mode, options));
  11525. }
  11526. base = buildCommon.makeSpan(["mop"], output, options);
  11527. } // If content of op is a single symbol, shift it vertically.
  11528. var baseShift = 0;
  11529. var slant = 0;
  11530. if ((base instanceof SymbolNode || group.name === "\\oiint" || group.name === "\\oiiint") && !group.suppressBaseShift) {
  11531. // We suppress the shift of the base of \overset and \underset. Otherwise,
  11532. // shift the symbol so its center lies on the axis (rule 13). It
  11533. // appears that our fonts have the centers of the symbols already
  11534. // almost on the axis, so these numbers are very small. Note we
  11535. // don't actually apply this here, but instead it is used either in
  11536. // the vlist creation or separately when there are no limits.
  11537. baseShift = (base.height - base.depth) / 2 - options.fontMetrics().axisHeight; // The slant of the symbol is just its italic correction.
  11538. // $FlowFixMe
  11539. slant = base.italic;
  11540. }
  11541. if (hasLimits) {
  11542. return assembleSupSub(base, supGroup, subGroup, options, style, slant, baseShift);
  11543. } else {
  11544. if (baseShift) {
  11545. base.style.position = "relative";
  11546. base.style.top = makeEm(baseShift);
  11547. }
  11548. return base;
  11549. }
  11550. };
  11551. var mathmlBuilder$1 = (group, options) => {
  11552. var node;
  11553. if (group.symbol) {
  11554. // This is a symbol. Just add the symbol.
  11555. node = new MathNode("mo", [makeText(group.name, group.mode)]);
  11556. if (utils.contains(noSuccessor, group.name)) {
  11557. node.setAttribute("largeop", "false");
  11558. }
  11559. } else if (group.body) {
  11560. // This is an operator with children. Add them.
  11561. node = new MathNode("mo", buildExpression(group.body, options));
  11562. } else {
  11563. // This is a text operator. Add all of the characters from the
  11564. // operator's name.
  11565. node = new MathNode("mi", [new TextNode(group.name.slice(1))]); // Append an <mo>&ApplyFunction;</mo>.
  11566. // ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
  11567. var operator = new MathNode("mo", [makeText("\u2061", "text")]);
  11568. if (group.parentIsSupSub) {
  11569. node = new MathNode("mrow", [node, operator]);
  11570. } else {
  11571. node = newDocumentFragment([node, operator]);
  11572. }
  11573. }
  11574. return node;
  11575. };
  11576. var singleCharBigOps = {
  11577. "\u220F": "\\prod",
  11578. "\u2210": "\\coprod",
  11579. "\u2211": "\\sum",
  11580. "\u22c0": "\\bigwedge",
  11581. "\u22c1": "\\bigvee",
  11582. "\u22c2": "\\bigcap",
  11583. "\u22c3": "\\bigcup",
  11584. "\u2a00": "\\bigodot",
  11585. "\u2a01": "\\bigoplus",
  11586. "\u2a02": "\\bigotimes",
  11587. "\u2a04": "\\biguplus",
  11588. "\u2a06": "\\bigsqcup"
  11589. };
  11590. defineFunction({
  11591. type: "op",
  11592. names: ["\\coprod", "\\bigvee", "\\bigwedge", "\\biguplus", "\\bigcap", "\\bigcup", "\\intop", "\\prod", "\\sum", "\\bigotimes", "\\bigoplus", "\\bigodot", "\\bigsqcup", "\\smallint", "\u220F", "\u2210", "\u2211", "\u22c0", "\u22c1", "\u22c2", "\u22c3", "\u2a00", "\u2a01", "\u2a02", "\u2a04", "\u2a06"],
  11593. props: {
  11594. numArgs: 0
  11595. },
  11596. handler: (_ref, args) => {
  11597. var {
  11598. parser,
  11599. funcName
  11600. } = _ref;
  11601. var fName = funcName;
  11602. if (fName.length === 1) {
  11603. fName = singleCharBigOps[fName];
  11604. }
  11605. return {
  11606. type: "op",
  11607. mode: parser.mode,
  11608. limits: true,
  11609. parentIsSupSub: false,
  11610. symbol: true,
  11611. name: fName
  11612. };
  11613. },
  11614. htmlBuilder: htmlBuilder$2,
  11615. mathmlBuilder: mathmlBuilder$1
  11616. }); // Note: calling defineFunction with a type that's already been defined only
  11617. // works because the same htmlBuilder and mathmlBuilder are being used.
  11618. defineFunction({
  11619. type: "op",
  11620. names: ["\\mathop"],
  11621. props: {
  11622. numArgs: 1,
  11623. primitive: true
  11624. },
  11625. handler: (_ref2, args) => {
  11626. var {
  11627. parser
  11628. } = _ref2;
  11629. var body = args[0];
  11630. return {
  11631. type: "op",
  11632. mode: parser.mode,
  11633. limits: false,
  11634. parentIsSupSub: false,
  11635. symbol: false,
  11636. body: ordargument(body)
  11637. };
  11638. },
  11639. htmlBuilder: htmlBuilder$2,
  11640. mathmlBuilder: mathmlBuilder$1
  11641. }); // There are 2 flags for operators; whether they produce limits in
  11642. // displaystyle, and whether they are symbols and should grow in
  11643. // displaystyle. These four groups cover the four possible choices.
  11644. var singleCharIntegrals = {
  11645. "\u222b": "\\int",
  11646. "\u222c": "\\iint",
  11647. "\u222d": "\\iiint",
  11648. "\u222e": "\\oint",
  11649. "\u222f": "\\oiint",
  11650. "\u2230": "\\oiiint"
  11651. }; // No limits, not symbols
  11652. defineFunction({
  11653. type: "op",
  11654. names: ["\\arcsin", "\\arccos", "\\arctan", "\\arctg", "\\arcctg", "\\arg", "\\ch", "\\cos", "\\cosec", "\\cosh", "\\cot", "\\cotg", "\\coth", "\\csc", "\\ctg", "\\cth", "\\deg", "\\dim", "\\exp", "\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin", "\\sinh", "\\sh", "\\tan", "\\tanh", "\\tg", "\\th"],
  11655. props: {
  11656. numArgs: 0
  11657. },
  11658. handler(_ref3) {
  11659. var {
  11660. parser,
  11661. funcName
  11662. } = _ref3;
  11663. return {
  11664. type: "op",
  11665. mode: parser.mode,
  11666. limits: false,
  11667. parentIsSupSub: false,
  11668. symbol: false,
  11669. name: funcName
  11670. };
  11671. },
  11672. htmlBuilder: htmlBuilder$2,
  11673. mathmlBuilder: mathmlBuilder$1
  11674. }); // Limits, not symbols
  11675. defineFunction({
  11676. type: "op",
  11677. names: ["\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup"],
  11678. props: {
  11679. numArgs: 0
  11680. },
  11681. handler(_ref4) {
  11682. var {
  11683. parser,
  11684. funcName
  11685. } = _ref4;
  11686. return {
  11687. type: "op",
  11688. mode: parser.mode,
  11689. limits: true,
  11690. parentIsSupSub: false,
  11691. symbol: false,
  11692. name: funcName
  11693. };
  11694. },
  11695. htmlBuilder: htmlBuilder$2,
  11696. mathmlBuilder: mathmlBuilder$1
  11697. }); // No limits, symbols
  11698. defineFunction({
  11699. type: "op",
  11700. names: ["\\int", "\\iint", "\\iiint", "\\oint", "\\oiint", "\\oiiint", "\u222b", "\u222c", "\u222d", "\u222e", "\u222f", "\u2230"],
  11701. props: {
  11702. numArgs: 0
  11703. },
  11704. handler(_ref5) {
  11705. var {
  11706. parser,
  11707. funcName
  11708. } = _ref5;
  11709. var fName = funcName;
  11710. if (fName.length === 1) {
  11711. fName = singleCharIntegrals[fName];
  11712. }
  11713. return {
  11714. type: "op",
  11715. mode: parser.mode,
  11716. limits: false,
  11717. parentIsSupSub: false,
  11718. symbol: true,
  11719. name: fName
  11720. };
  11721. },
  11722. htmlBuilder: htmlBuilder$2,
  11723. mathmlBuilder: mathmlBuilder$1
  11724. });
  11725. // NOTE: Unlike most `htmlBuilder`s, this one handles not only
  11726. // "operatorname", but also "supsub" since \operatorname* can
  11727. // affect super/subscripting.
  11728. var htmlBuilder$1 = (grp, options) => {
  11729. // Operators are handled in the TeXbook pg. 443-444, rule 13(a).
  11730. var supGroup;
  11731. var subGroup;
  11732. var hasLimits = false;
  11733. var group;
  11734. if (grp.type === "supsub") {
  11735. // If we have limits, supsub will pass us its group to handle. Pull
  11736. // out the superscript and subscript and set the group to the op in
  11737. // its base.
  11738. supGroup = grp.sup;
  11739. subGroup = grp.sub;
  11740. group = assertNodeType(grp.base, "operatorname");
  11741. hasLimits = true;
  11742. } else {
  11743. group = assertNodeType(grp, "operatorname");
  11744. }
  11745. var base;
  11746. if (group.body.length > 0) {
  11747. var body = group.body.map(child => {
  11748. // $FlowFixMe: Check if the node has a string `text` property.
  11749. var childText = child.text;
  11750. if (typeof childText === "string") {
  11751. return {
  11752. type: "textord",
  11753. mode: child.mode,
  11754. text: childText
  11755. };
  11756. } else {
  11757. return child;
  11758. }
  11759. }); // Consolidate function names into symbol characters.
  11760. var expression = buildExpression$1(body, options.withFont("mathrm"), true);
  11761. for (var i = 0; i < expression.length; i++) {
  11762. var child = expression[i];
  11763. if (child instanceof SymbolNode) {
  11764. // Per amsopn package,
  11765. // change minus to hyphen and \ast to asterisk
  11766. child.text = child.text.replace(/\u2212/, "-").replace(/\u2217/, "*");
  11767. }
  11768. }
  11769. base = buildCommon.makeSpan(["mop"], expression, options);
  11770. } else {
  11771. base = buildCommon.makeSpan(["mop"], [], options);
  11772. }
  11773. if (hasLimits) {
  11774. return assembleSupSub(base, supGroup, subGroup, options, options.style, 0, 0);
  11775. } else {
  11776. return base;
  11777. }
  11778. };
  11779. var mathmlBuilder = (group, options) => {
  11780. // The steps taken here are similar to the html version.
  11781. var expression = buildExpression(group.body, options.withFont("mathrm")); // Is expression a string or has it something like a fraction?
  11782. var isAllString = true; // default
  11783. for (var i = 0; i < expression.length; i++) {
  11784. var node = expression[i];
  11785. if (node instanceof mathMLTree.SpaceNode) ; else if (node instanceof mathMLTree.MathNode) {
  11786. switch (node.type) {
  11787. case "mi":
  11788. case "mn":
  11789. case "ms":
  11790. case "mspace":
  11791. case "mtext":
  11792. break;
  11793. // Do nothing yet.
  11794. case "mo":
  11795. {
  11796. var child = node.children[0];
  11797. if (node.children.length === 1 && child instanceof mathMLTree.TextNode) {
  11798. child.text = child.text.replace(/\u2212/, "-").replace(/\u2217/, "*");
  11799. } else {
  11800. isAllString = false;
  11801. }
  11802. break;
  11803. }
  11804. default:
  11805. isAllString = false;
  11806. }
  11807. } else {
  11808. isAllString = false;
  11809. }
  11810. }
  11811. if (isAllString) {
  11812. // Write a single TextNode instead of multiple nested tags.
  11813. var word = expression.map(node => node.toText()).join("");
  11814. expression = [new mathMLTree.TextNode(word)];
  11815. }
  11816. var identifier = new mathMLTree.MathNode("mi", expression);
  11817. identifier.setAttribute("mathvariant", "normal"); // \u2061 is the same as &ApplyFunction;
  11818. // ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp
  11819. var operator = new mathMLTree.MathNode("mo", [makeText("\u2061", "text")]);
  11820. if (group.parentIsSupSub) {
  11821. return new mathMLTree.MathNode("mrow", [identifier, operator]);
  11822. } else {
  11823. return mathMLTree.newDocumentFragment([identifier, operator]);
  11824. }
  11825. }; // \operatorname
  11826. // amsopn.dtx: \mathop{#1\kern\z@\operator@font#3}\newmcodes@
  11827. defineFunction({
  11828. type: "operatorname",
  11829. names: ["\\operatorname@", "\\operatornamewithlimits"],
  11830. props: {
  11831. numArgs: 1
  11832. },
  11833. handler: (_ref, args) => {
  11834. var {
  11835. parser,
  11836. funcName
  11837. } = _ref;
  11838. var body = args[0];
  11839. return {
  11840. type: "operatorname",
  11841. mode: parser.mode,
  11842. body: ordargument(body),
  11843. alwaysHandleSupSub: funcName === "\\operatornamewithlimits",
  11844. limits: false,
  11845. parentIsSupSub: false
  11846. };
  11847. },
  11848. htmlBuilder: htmlBuilder$1,
  11849. mathmlBuilder
  11850. });
  11851. defineMacro("\\operatorname", "\\@ifstar\\operatornamewithlimits\\operatorname@");
  11852. defineFunctionBuilders({
  11853. type: "ordgroup",
  11854. htmlBuilder(group, options) {
  11855. if (group.semisimple) {
  11856. return buildCommon.makeFragment(buildExpression$1(group.body, options, false));
  11857. }
  11858. return buildCommon.makeSpan(["mord"], buildExpression$1(group.body, options, true), options);
  11859. },
  11860. mathmlBuilder(group, options) {
  11861. return buildExpressionRow(group.body, options, true);
  11862. }
  11863. });
  11864. defineFunction({
  11865. type: "overline",
  11866. names: ["\\overline"],
  11867. props: {
  11868. numArgs: 1
  11869. },
  11870. handler(_ref, args) {
  11871. var {
  11872. parser
  11873. } = _ref;
  11874. var body = args[0];
  11875. return {
  11876. type: "overline",
  11877. mode: parser.mode,
  11878. body
  11879. };
  11880. },
  11881. htmlBuilder(group, options) {
  11882. // Overlines are handled in the TeXbook pg 443, Rule 9.
  11883. // Build the inner group in the cramped style.
  11884. var innerGroup = buildGroup$1(group.body, options.havingCrampedStyle()); // Create the line above the body
  11885. var line = buildCommon.makeLineSpan("overline-line", options); // Generate the vlist, with the appropriate kerns
  11886. var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
  11887. var vlist = buildCommon.makeVList({
  11888. positionType: "firstBaseline",
  11889. children: [{
  11890. type: "elem",
  11891. elem: innerGroup
  11892. }, {
  11893. type: "kern",
  11894. size: 3 * defaultRuleThickness
  11895. }, {
  11896. type: "elem",
  11897. elem: line
  11898. }, {
  11899. type: "kern",
  11900. size: defaultRuleThickness
  11901. }]
  11902. }, options);
  11903. return buildCommon.makeSpan(["mord", "overline"], [vlist], options);
  11904. },
  11905. mathmlBuilder(group, options) {
  11906. var operator = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode("\u203e")]);
  11907. operator.setAttribute("stretchy", "true");
  11908. var node = new mathMLTree.MathNode("mover", [buildGroup(group.body, options), operator]);
  11909. node.setAttribute("accent", "true");
  11910. return node;
  11911. }
  11912. });
  11913. defineFunction({
  11914. type: "phantom",
  11915. names: ["\\phantom"],
  11916. props: {
  11917. numArgs: 1,
  11918. allowedInText: true
  11919. },
  11920. handler: (_ref, args) => {
  11921. var {
  11922. parser
  11923. } = _ref;
  11924. var body = args[0];
  11925. return {
  11926. type: "phantom",
  11927. mode: parser.mode,
  11928. body: ordargument(body)
  11929. };
  11930. },
  11931. htmlBuilder: (group, options) => {
  11932. var elements = buildExpression$1(group.body, options.withPhantom(), false); // \phantom isn't supposed to affect the elements it contains.
  11933. // See "color" for more details.
  11934. return buildCommon.makeFragment(elements);
  11935. },
  11936. mathmlBuilder: (group, options) => {
  11937. var inner = buildExpression(group.body, options);
  11938. return new mathMLTree.MathNode("mphantom", inner);
  11939. }
  11940. });
  11941. defineFunction({
  11942. type: "hphantom",
  11943. names: ["\\hphantom"],
  11944. props: {
  11945. numArgs: 1,
  11946. allowedInText: true
  11947. },
  11948. handler: (_ref2, args) => {
  11949. var {
  11950. parser
  11951. } = _ref2;
  11952. var body = args[0];
  11953. return {
  11954. type: "hphantom",
  11955. mode: parser.mode,
  11956. body
  11957. };
  11958. },
  11959. htmlBuilder: (group, options) => {
  11960. var node = buildCommon.makeSpan([], [buildGroup$1(group.body, options.withPhantom())]);
  11961. node.height = 0;
  11962. node.depth = 0;
  11963. if (node.children) {
  11964. for (var i = 0; i < node.children.length; i++) {
  11965. node.children[i].height = 0;
  11966. node.children[i].depth = 0;
  11967. }
  11968. } // See smash for comment re: use of makeVList
  11969. node = buildCommon.makeVList({
  11970. positionType: "firstBaseline",
  11971. children: [{
  11972. type: "elem",
  11973. elem: node
  11974. }]
  11975. }, options); // For spacing, TeX treats \smash as a math group (same spacing as ord).
  11976. return buildCommon.makeSpan(["mord"], [node], options);
  11977. },
  11978. mathmlBuilder: (group, options) => {
  11979. var inner = buildExpression(ordargument(group.body), options);
  11980. var phantom = new mathMLTree.MathNode("mphantom", inner);
  11981. var node = new mathMLTree.MathNode("mpadded", [phantom]);
  11982. node.setAttribute("height", "0px");
  11983. node.setAttribute("depth", "0px");
  11984. return node;
  11985. }
  11986. });
  11987. defineFunction({
  11988. type: "vphantom",
  11989. names: ["\\vphantom"],
  11990. props: {
  11991. numArgs: 1,
  11992. allowedInText: true
  11993. },
  11994. handler: (_ref3, args) => {
  11995. var {
  11996. parser
  11997. } = _ref3;
  11998. var body = args[0];
  11999. return {
  12000. type: "vphantom",
  12001. mode: parser.mode,
  12002. body
  12003. };
  12004. },
  12005. htmlBuilder: (group, options) => {
  12006. var inner = buildCommon.makeSpan(["inner"], [buildGroup$1(group.body, options.withPhantom())]);
  12007. var fix = buildCommon.makeSpan(["fix"], []);
  12008. return buildCommon.makeSpan(["mord", "rlap"], [inner, fix], options);
  12009. },
  12010. mathmlBuilder: (group, options) => {
  12011. var inner = buildExpression(ordargument(group.body), options);
  12012. var phantom = new mathMLTree.MathNode("mphantom", inner);
  12013. var node = new mathMLTree.MathNode("mpadded", [phantom]);
  12014. node.setAttribute("width", "0px");
  12015. return node;
  12016. }
  12017. });
  12018. defineFunction({
  12019. type: "raisebox",
  12020. names: ["\\raisebox"],
  12021. props: {
  12022. numArgs: 2,
  12023. argTypes: ["size", "hbox"],
  12024. allowedInText: true
  12025. },
  12026. handler(_ref, args) {
  12027. var {
  12028. parser
  12029. } = _ref;
  12030. var amount = assertNodeType(args[0], "size").value;
  12031. var body = args[1];
  12032. return {
  12033. type: "raisebox",
  12034. mode: parser.mode,
  12035. dy: amount,
  12036. body
  12037. };
  12038. },
  12039. htmlBuilder(group, options) {
  12040. var body = buildGroup$1(group.body, options);
  12041. var dy = calculateSize(group.dy, options);
  12042. return buildCommon.makeVList({
  12043. positionType: "shift",
  12044. positionData: -dy,
  12045. children: [{
  12046. type: "elem",
  12047. elem: body
  12048. }]
  12049. }, options);
  12050. },
  12051. mathmlBuilder(group, options) {
  12052. var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
  12053. var dy = group.dy.number + group.dy.unit;
  12054. node.setAttribute("voffset", dy);
  12055. return node;
  12056. }
  12057. });
  12058. defineFunction({
  12059. type: "internal",
  12060. names: ["\\relax"],
  12061. props: {
  12062. numArgs: 0,
  12063. allowedInText: true
  12064. },
  12065. handler(_ref) {
  12066. var {
  12067. parser
  12068. } = _ref;
  12069. return {
  12070. type: "internal",
  12071. mode: parser.mode
  12072. };
  12073. }
  12074. });
  12075. defineFunction({
  12076. type: "rule",
  12077. names: ["\\rule"],
  12078. props: {
  12079. numArgs: 2,
  12080. numOptionalArgs: 1,
  12081. argTypes: ["size", "size", "size"]
  12082. },
  12083. handler(_ref, args, optArgs) {
  12084. var {
  12085. parser
  12086. } = _ref;
  12087. var shift = optArgs[0];
  12088. var width = assertNodeType(args[0], "size");
  12089. var height = assertNodeType(args[1], "size");
  12090. return {
  12091. type: "rule",
  12092. mode: parser.mode,
  12093. shift: shift && assertNodeType(shift, "size").value,
  12094. width: width.value,
  12095. height: height.value
  12096. };
  12097. },
  12098. htmlBuilder(group, options) {
  12099. // Make an empty span for the rule
  12100. var rule = buildCommon.makeSpan(["mord", "rule"], [], options); // Calculate the shift, width, and height of the rule, and account for units
  12101. var width = calculateSize(group.width, options);
  12102. var height = calculateSize(group.height, options);
  12103. var shift = group.shift ? calculateSize(group.shift, options) : 0; // Style the rule to the right size
  12104. rule.style.borderRightWidth = makeEm(width);
  12105. rule.style.borderTopWidth = makeEm(height);
  12106. rule.style.bottom = makeEm(shift); // Record the height and width
  12107. rule.width = width;
  12108. rule.height = height + shift;
  12109. rule.depth = -shift; // Font size is the number large enough that the browser will
  12110. // reserve at least `absHeight` space above the baseline.
  12111. // The 1.125 factor was empirically determined
  12112. rule.maxFontSize = height * 1.125 * options.sizeMultiplier;
  12113. return rule;
  12114. },
  12115. mathmlBuilder(group, options) {
  12116. var width = calculateSize(group.width, options);
  12117. var height = calculateSize(group.height, options);
  12118. var shift = group.shift ? calculateSize(group.shift, options) : 0;
  12119. var color = options.color && options.getColor() || "black";
  12120. var rule = new mathMLTree.MathNode("mspace");
  12121. rule.setAttribute("mathbackground", color);
  12122. rule.setAttribute("width", makeEm(width));
  12123. rule.setAttribute("height", makeEm(height));
  12124. var wrapper = new mathMLTree.MathNode("mpadded", [rule]);
  12125. if (shift >= 0) {
  12126. wrapper.setAttribute("height", makeEm(shift));
  12127. } else {
  12128. wrapper.setAttribute("height", makeEm(shift));
  12129. wrapper.setAttribute("depth", makeEm(-shift));
  12130. }
  12131. wrapper.setAttribute("voffset", makeEm(shift));
  12132. return wrapper;
  12133. }
  12134. });
  12135. function sizingGroup(value, options, baseOptions) {
  12136. var inner = buildExpression$1(value, options, false);
  12137. var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier; // Add size-resetting classes to the inner list and set maxFontSize
  12138. // manually. Handle nested size changes.
  12139. for (var i = 0; i < inner.length; i++) {
  12140. var pos = inner[i].classes.indexOf("sizing");
  12141. if (pos < 0) {
  12142. Array.prototype.push.apply(inner[i].classes, options.sizingClasses(baseOptions));
  12143. } else if (inner[i].classes[pos + 1] === "reset-size" + options.size) {
  12144. // This is a nested size change: e.g., inner[i] is the "b" in
  12145. // `\Huge a \small b`. Override the old size (the `reset-` class)
  12146. // but not the new size.
  12147. inner[i].classes[pos + 1] = "reset-size" + baseOptions.size;
  12148. }
  12149. inner[i].height *= multiplier;
  12150. inner[i].depth *= multiplier;
  12151. }
  12152. return buildCommon.makeFragment(inner);
  12153. }
  12154. var sizeFuncs = ["\\tiny", "\\sixptsize", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"];
  12155. var htmlBuilder = (group, options) => {
  12156. // Handle sizing operators like \Huge. Real TeX doesn't actually allow
  12157. // these functions inside of math expressions, so we do some special
  12158. // handling.
  12159. var newOptions = options.havingSize(group.size);
  12160. return sizingGroup(group.body, newOptions, options);
  12161. };
  12162. defineFunction({
  12163. type: "sizing",
  12164. names: sizeFuncs,
  12165. props: {
  12166. numArgs: 0,
  12167. allowedInText: true
  12168. },
  12169. handler: (_ref, args) => {
  12170. var {
  12171. breakOnTokenText,
  12172. funcName,
  12173. parser
  12174. } = _ref;
  12175. var body = parser.parseExpression(false, breakOnTokenText);
  12176. return {
  12177. type: "sizing",
  12178. mode: parser.mode,
  12179. // Figure out what size to use based on the list of functions above
  12180. size: sizeFuncs.indexOf(funcName) + 1,
  12181. body
  12182. };
  12183. },
  12184. htmlBuilder,
  12185. mathmlBuilder: (group, options) => {
  12186. var newOptions = options.havingSize(group.size);
  12187. var inner = buildExpression(group.body, newOptions);
  12188. var node = new mathMLTree.MathNode("mstyle", inner); // TODO(emily): This doesn't produce the correct size for nested size
  12189. // changes, because we don't keep state of what style we're currently
  12190. // in, so we can't reset the size to normal before changing it. Now
  12191. // that we're passing an options parameter we should be able to fix
  12192. // this.
  12193. node.setAttribute("mathsize", makeEm(newOptions.sizeMultiplier));
  12194. return node;
  12195. }
  12196. });
  12197. // smash, with optional [tb], as in AMS
  12198. defineFunction({
  12199. type: "smash",
  12200. names: ["\\smash"],
  12201. props: {
  12202. numArgs: 1,
  12203. numOptionalArgs: 1,
  12204. allowedInText: true
  12205. },
  12206. handler: (_ref, args, optArgs) => {
  12207. var {
  12208. parser
  12209. } = _ref;
  12210. var smashHeight = false;
  12211. var smashDepth = false;
  12212. var tbArg = optArgs[0] && assertNodeType(optArgs[0], "ordgroup");
  12213. if (tbArg) {
  12214. // Optional [tb] argument is engaged.
  12215. // ref: amsmath: \renewcommand{\smash}[1][tb]{%
  12216. // def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}%
  12217. var letter = "";
  12218. for (var i = 0; i < tbArg.body.length; ++i) {
  12219. var node = tbArg.body[i]; // $FlowFixMe: Not every node type has a `text` property.
  12220. letter = node.text;
  12221. if (letter === "t") {
  12222. smashHeight = true;
  12223. } else if (letter === "b") {
  12224. smashDepth = true;
  12225. } else {
  12226. smashHeight = false;
  12227. smashDepth = false;
  12228. break;
  12229. }
  12230. }
  12231. } else {
  12232. smashHeight = true;
  12233. smashDepth = true;
  12234. }
  12235. var body = args[0];
  12236. return {
  12237. type: "smash",
  12238. mode: parser.mode,
  12239. body,
  12240. smashHeight,
  12241. smashDepth
  12242. };
  12243. },
  12244. htmlBuilder: (group, options) => {
  12245. var node = buildCommon.makeSpan([], [buildGroup$1(group.body, options)]);
  12246. if (!group.smashHeight && !group.smashDepth) {
  12247. return node;
  12248. }
  12249. if (group.smashHeight) {
  12250. node.height = 0; // In order to influence makeVList, we have to reset the children.
  12251. if (node.children) {
  12252. for (var i = 0; i < node.children.length; i++) {
  12253. node.children[i].height = 0;
  12254. }
  12255. }
  12256. }
  12257. if (group.smashDepth) {
  12258. node.depth = 0;
  12259. if (node.children) {
  12260. for (var _i = 0; _i < node.children.length; _i++) {
  12261. node.children[_i].depth = 0;
  12262. }
  12263. }
  12264. } // At this point, we've reset the TeX-like height and depth values.
  12265. // But the span still has an HTML line height.
  12266. // makeVList applies "display: table-cell", which prevents the browser
  12267. // from acting on that line height. So we'll call makeVList now.
  12268. var smashedNode = buildCommon.makeVList({
  12269. positionType: "firstBaseline",
  12270. children: [{
  12271. type: "elem",
  12272. elem: node
  12273. }]
  12274. }, options); // For spacing, TeX treats \hphantom as a math group (same spacing as ord).
  12275. return buildCommon.makeSpan(["mord"], [smashedNode], options);
  12276. },
  12277. mathmlBuilder: (group, options) => {
  12278. var node = new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)]);
  12279. if (group.smashHeight) {
  12280. node.setAttribute("height", "0px");
  12281. }
  12282. if (group.smashDepth) {
  12283. node.setAttribute("depth", "0px");
  12284. }
  12285. return node;
  12286. }
  12287. });
  12288. defineFunction({
  12289. type: "sqrt",
  12290. names: ["\\sqrt"],
  12291. props: {
  12292. numArgs: 1,
  12293. numOptionalArgs: 1
  12294. },
  12295. handler(_ref, args, optArgs) {
  12296. var {
  12297. parser
  12298. } = _ref;
  12299. var index = optArgs[0];
  12300. var body = args[0];
  12301. return {
  12302. type: "sqrt",
  12303. mode: parser.mode,
  12304. body,
  12305. index
  12306. };
  12307. },
  12308. htmlBuilder(group, options) {
  12309. // Square roots are handled in the TeXbook pg. 443, Rule 11.
  12310. // First, we do the same steps as in overline to build the inner group
  12311. // and line
  12312. var inner = buildGroup$1(group.body, options.havingCrampedStyle());
  12313. if (inner.height === 0) {
  12314. // Render a small surd.
  12315. inner.height = options.fontMetrics().xHeight;
  12316. } // Some groups can return document fragments. Handle those by wrapping
  12317. // them in a span.
  12318. inner = buildCommon.wrapFragment(inner, options); // Calculate the minimum size for the \surd delimiter
  12319. var metrics = options.fontMetrics();
  12320. var theta = metrics.defaultRuleThickness;
  12321. var phi = theta;
  12322. if (options.style.id < Style$1.TEXT.id) {
  12323. phi = options.fontMetrics().xHeight;
  12324. } // Calculate the clearance between the body and line
  12325. var lineClearance = theta + phi / 4;
  12326. var minDelimiterHeight = inner.height + inner.depth + lineClearance + theta; // Create a sqrt SVG of the required minimum size
  12327. var {
  12328. span: img,
  12329. ruleWidth,
  12330. advanceWidth
  12331. } = delimiter.sqrtImage(minDelimiterHeight, options);
  12332. var delimDepth = img.height - ruleWidth; // Adjust the clearance based on the delimiter size
  12333. if (delimDepth > inner.height + inner.depth + lineClearance) {
  12334. lineClearance = (lineClearance + delimDepth - inner.height - inner.depth) / 2;
  12335. } // Shift the sqrt image
  12336. var imgShift = img.height - inner.height - lineClearance - ruleWidth;
  12337. inner.style.paddingLeft = makeEm(advanceWidth); // Overlay the image and the argument.
  12338. var body = buildCommon.makeVList({
  12339. positionType: "firstBaseline",
  12340. children: [{
  12341. type: "elem",
  12342. elem: inner,
  12343. wrapperClasses: ["svg-align"]
  12344. }, {
  12345. type: "kern",
  12346. size: -(inner.height + imgShift)
  12347. }, {
  12348. type: "elem",
  12349. elem: img
  12350. }, {
  12351. type: "kern",
  12352. size: ruleWidth
  12353. }]
  12354. }, options);
  12355. if (!group.index) {
  12356. return buildCommon.makeSpan(["mord", "sqrt"], [body], options);
  12357. } else {
  12358. // Handle the optional root index
  12359. // The index is always in scriptscript style
  12360. var newOptions = options.havingStyle(Style$1.SCRIPTSCRIPT);
  12361. var rootm = buildGroup$1(group.index, newOptions, options); // The amount the index is shifted by. This is taken from the TeX
  12362. // source, in the definition of `\r@@t`.
  12363. var toShift = 0.6 * (body.height - body.depth); // Build a VList with the superscript shifted up correctly
  12364. var rootVList = buildCommon.makeVList({
  12365. positionType: "shift",
  12366. positionData: -toShift,
  12367. children: [{
  12368. type: "elem",
  12369. elem: rootm
  12370. }]
  12371. }, options); // Add a class surrounding it so we can add on the appropriate
  12372. // kerning
  12373. var rootVListWrap = buildCommon.makeSpan(["root"], [rootVList]);
  12374. return buildCommon.makeSpan(["mord", "sqrt"], [rootVListWrap, body], options);
  12375. }
  12376. },
  12377. mathmlBuilder(group, options) {
  12378. var {
  12379. body,
  12380. index
  12381. } = group;
  12382. return index ? new mathMLTree.MathNode("mroot", [buildGroup(body, options), buildGroup(index, options)]) : new mathMLTree.MathNode("msqrt", [buildGroup(body, options)]);
  12383. }
  12384. });
  12385. var styleMap = {
  12386. "display": Style$1.DISPLAY,
  12387. "text": Style$1.TEXT,
  12388. "script": Style$1.SCRIPT,
  12389. "scriptscript": Style$1.SCRIPTSCRIPT
  12390. };
  12391. defineFunction({
  12392. type: "styling",
  12393. names: ["\\displaystyle", "\\textstyle", "\\scriptstyle", "\\scriptscriptstyle"],
  12394. props: {
  12395. numArgs: 0,
  12396. allowedInText: true,
  12397. primitive: true
  12398. },
  12399. handler(_ref, args) {
  12400. var {
  12401. breakOnTokenText,
  12402. funcName,
  12403. parser
  12404. } = _ref;
  12405. // parse out the implicit body
  12406. var body = parser.parseExpression(true, breakOnTokenText); // TODO: Refactor to avoid duplicating styleMap in multiple places (e.g.
  12407. // here and in buildHTML and de-dupe the enumeration of all the styles).
  12408. // $FlowFixMe: The names above exactly match the styles.
  12409. var style = funcName.slice(1, funcName.length - 5);
  12410. return {
  12411. type: "styling",
  12412. mode: parser.mode,
  12413. // Figure out what style to use by pulling out the style from
  12414. // the function name
  12415. style,
  12416. body
  12417. };
  12418. },
  12419. htmlBuilder(group, options) {
  12420. // Style changes are handled in the TeXbook on pg. 442, Rule 3.
  12421. var newStyle = styleMap[group.style];
  12422. var newOptions = options.havingStyle(newStyle).withFont('');
  12423. return sizingGroup(group.body, newOptions, options);
  12424. },
  12425. mathmlBuilder(group, options) {
  12426. // Figure out what style we're changing to.
  12427. var newStyle = styleMap[group.style];
  12428. var newOptions = options.havingStyle(newStyle);
  12429. var inner = buildExpression(group.body, newOptions);
  12430. var node = new mathMLTree.MathNode("mstyle", inner);
  12431. var styleAttributes = {
  12432. "display": ["0", "true"],
  12433. "text": ["0", "false"],
  12434. "script": ["1", "false"],
  12435. "scriptscript": ["2", "false"]
  12436. };
  12437. var attr = styleAttributes[group.style];
  12438. node.setAttribute("scriptlevel", attr[0]);
  12439. node.setAttribute("displaystyle", attr[1]);
  12440. return node;
  12441. }
  12442. });
  12443. /**
  12444. * Sometimes, groups perform special rules when they have superscripts or
  12445. * subscripts attached to them. This function lets the `supsub` group know that
  12446. * Sometimes, groups perform special rules when they have superscripts or
  12447. * its inner element should handle the superscripts and subscripts instead of
  12448. * handling them itself.
  12449. */
  12450. var htmlBuilderDelegate = function htmlBuilderDelegate(group, options) {
  12451. var base = group.base;
  12452. if (!base) {
  12453. return null;
  12454. } else if (base.type === "op") {
  12455. // Operators handle supsubs differently when they have limits
  12456. // (e.g. `\displaystyle\sum_2^3`)
  12457. var delegate = base.limits && (options.style.size === Style$1.DISPLAY.size || base.alwaysHandleSupSub);
  12458. return delegate ? htmlBuilder$2 : null;
  12459. } else if (base.type === "operatorname") {
  12460. var _delegate = base.alwaysHandleSupSub && (options.style.size === Style$1.DISPLAY.size || base.limits);
  12461. return _delegate ? htmlBuilder$1 : null;
  12462. } else if (base.type === "accent") {
  12463. return utils.isCharacterBox(base.base) ? htmlBuilder$a : null;
  12464. } else if (base.type === "horizBrace") {
  12465. var isSup = !group.sub;
  12466. return isSup === base.isOver ? htmlBuilder$3 : null;
  12467. } else {
  12468. return null;
  12469. }
  12470. }; // Super scripts and subscripts, whose precise placement can depend on other
  12471. // functions that precede them.
  12472. defineFunctionBuilders({
  12473. type: "supsub",
  12474. htmlBuilder(group, options) {
  12475. // Superscript and subscripts are handled in the TeXbook on page
  12476. // 445-446, rules 18(a-f).
  12477. // Here is where we defer to the inner group if it should handle
  12478. // superscripts and subscripts itself.
  12479. var builderDelegate = htmlBuilderDelegate(group, options);
  12480. if (builderDelegate) {
  12481. return builderDelegate(group, options);
  12482. }
  12483. var {
  12484. base: valueBase,
  12485. sup: valueSup,
  12486. sub: valueSub
  12487. } = group;
  12488. var base = buildGroup$1(valueBase, options);
  12489. var supm;
  12490. var subm;
  12491. var metrics = options.fontMetrics(); // Rule 18a
  12492. var supShift = 0;
  12493. var subShift = 0;
  12494. var isCharacterBox = valueBase && utils.isCharacterBox(valueBase);
  12495. if (valueSup) {
  12496. var newOptions = options.havingStyle(options.style.sup());
  12497. supm = buildGroup$1(valueSup, newOptions, options);
  12498. if (!isCharacterBox) {
  12499. supShift = base.height - newOptions.fontMetrics().supDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
  12500. }
  12501. }
  12502. if (valueSub) {
  12503. var _newOptions = options.havingStyle(options.style.sub());
  12504. subm = buildGroup$1(valueSub, _newOptions, options);
  12505. if (!isCharacterBox) {
  12506. subShift = base.depth + _newOptions.fontMetrics().subDrop * _newOptions.sizeMultiplier / options.sizeMultiplier;
  12507. }
  12508. } // Rule 18c
  12509. var minSupShift;
  12510. if (options.style === Style$1.DISPLAY) {
  12511. minSupShift = metrics.sup1;
  12512. } else if (options.style.cramped) {
  12513. minSupShift = metrics.sup3;
  12514. } else {
  12515. minSupShift = metrics.sup2;
  12516. } // scriptspace is a font-size-independent size, so scale it
  12517. // appropriately for use as the marginRight.
  12518. var multiplier = options.sizeMultiplier;
  12519. var marginRight = makeEm(0.5 / metrics.ptPerEm / multiplier);
  12520. var marginLeft = null;
  12521. if (subm) {
  12522. // Subscripts shouldn't be shifted by the base's italic correction.
  12523. // Account for that by shifting the subscript back the appropriate
  12524. // amount. Note we only do this when the base is a single symbol.
  12525. var isOiint = group.base && group.base.type === "op" && group.base.name && (group.base.name === "\\oiint" || group.base.name === "\\oiiint");
  12526. if (base instanceof SymbolNode || isOiint) {
  12527. // $FlowFixMe
  12528. marginLeft = makeEm(-base.italic);
  12529. }
  12530. }
  12531. var supsub;
  12532. if (supm && subm) {
  12533. supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
  12534. subShift = Math.max(subShift, metrics.sub2);
  12535. var ruleWidth = metrics.defaultRuleThickness; // Rule 18e
  12536. var maxWidth = 4 * ruleWidth;
  12537. if (supShift - supm.depth - (subm.height - subShift) < maxWidth) {
  12538. subShift = maxWidth - (supShift - supm.depth) + subm.height;
  12539. var psi = 0.8 * metrics.xHeight - (supShift - supm.depth);
  12540. if (psi > 0) {
  12541. supShift += psi;
  12542. subShift -= psi;
  12543. }
  12544. }
  12545. var vlistElem = [{
  12546. type: "elem",
  12547. elem: subm,
  12548. shift: subShift,
  12549. marginRight,
  12550. marginLeft
  12551. }, {
  12552. type: "elem",
  12553. elem: supm,
  12554. shift: -supShift,
  12555. marginRight
  12556. }];
  12557. supsub = buildCommon.makeVList({
  12558. positionType: "individualShift",
  12559. children: vlistElem
  12560. }, options);
  12561. } else if (subm) {
  12562. // Rule 18b
  12563. subShift = Math.max(subShift, metrics.sub1, subm.height - 0.8 * metrics.xHeight);
  12564. var _vlistElem = [{
  12565. type: "elem",
  12566. elem: subm,
  12567. marginLeft,
  12568. marginRight
  12569. }];
  12570. supsub = buildCommon.makeVList({
  12571. positionType: "shift",
  12572. positionData: subShift,
  12573. children: _vlistElem
  12574. }, options);
  12575. } else if (supm) {
  12576. // Rule 18c, d
  12577. supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
  12578. supsub = buildCommon.makeVList({
  12579. positionType: "shift",
  12580. positionData: -supShift,
  12581. children: [{
  12582. type: "elem",
  12583. elem: supm,
  12584. marginRight
  12585. }]
  12586. }, options);
  12587. } else {
  12588. throw new Error("supsub must have either sup or sub.");
  12589. } // Wrap the supsub vlist in a span.msupsub to reset text-align.
  12590. var mclass = getTypeOfDomTree(base, "right") || "mord";
  12591. return buildCommon.makeSpan([mclass], [base, buildCommon.makeSpan(["msupsub"], [supsub])], options);
  12592. },
  12593. mathmlBuilder(group, options) {
  12594. // Is the inner group a relevant horizonal brace?
  12595. var isBrace = false;
  12596. var isOver;
  12597. var isSup;
  12598. if (group.base && group.base.type === "horizBrace") {
  12599. isSup = !!group.sup;
  12600. if (isSup === group.base.isOver) {
  12601. isBrace = true;
  12602. isOver = group.base.isOver;
  12603. }
  12604. }
  12605. if (group.base && (group.base.type === "op" || group.base.type === "operatorname")) {
  12606. group.base.parentIsSupSub = true;
  12607. }
  12608. var children = [buildGroup(group.base, options)];
  12609. if (group.sub) {
  12610. children.push(buildGroup(group.sub, options));
  12611. }
  12612. if (group.sup) {
  12613. children.push(buildGroup(group.sup, options));
  12614. }
  12615. var nodeType;
  12616. if (isBrace) {
  12617. nodeType = isOver ? "mover" : "munder";
  12618. } else if (!group.sub) {
  12619. var base = group.base;
  12620. if (base && base.type === "op" && base.limits && (options.style === Style$1.DISPLAY || base.alwaysHandleSupSub)) {
  12621. nodeType = "mover";
  12622. } else if (base && base.type === "operatorname" && base.alwaysHandleSupSub && (base.limits || options.style === Style$1.DISPLAY)) {
  12623. nodeType = "mover";
  12624. } else {
  12625. nodeType = "msup";
  12626. }
  12627. } else if (!group.sup) {
  12628. var _base = group.base;
  12629. if (_base && _base.type === "op" && _base.limits && (options.style === Style$1.DISPLAY || _base.alwaysHandleSupSub)) {
  12630. nodeType = "munder";
  12631. } else if (_base && _base.type === "operatorname" && _base.alwaysHandleSupSub && (_base.limits || options.style === Style$1.DISPLAY)) {
  12632. nodeType = "munder";
  12633. } else {
  12634. nodeType = "msub";
  12635. }
  12636. } else {
  12637. var _base2 = group.base;
  12638. if (_base2 && _base2.type === "op" && _base2.limits && options.style === Style$1.DISPLAY) {
  12639. nodeType = "munderover";
  12640. } else if (_base2 && _base2.type === "operatorname" && _base2.alwaysHandleSupSub && (options.style === Style$1.DISPLAY || _base2.limits)) {
  12641. nodeType = "munderover";
  12642. } else {
  12643. nodeType = "msubsup";
  12644. }
  12645. }
  12646. return new mathMLTree.MathNode(nodeType, children);
  12647. }
  12648. });
  12649. defineFunctionBuilders({
  12650. type: "atom",
  12651. htmlBuilder(group, options) {
  12652. return buildCommon.mathsym(group.text, group.mode, options, ["m" + group.family]);
  12653. },
  12654. mathmlBuilder(group, options) {
  12655. var node = new mathMLTree.MathNode("mo", [makeText(group.text, group.mode)]);
  12656. if (group.family === "bin") {
  12657. var variant = getVariant(group, options);
  12658. if (variant === "bold-italic") {
  12659. node.setAttribute("mathvariant", variant);
  12660. }
  12661. } else if (group.family === "punct") {
  12662. node.setAttribute("separator", "true");
  12663. } else if (group.family === "open" || group.family === "close") {
  12664. // Delims built here should not stretch vertically.
  12665. // See delimsizing.js for stretchy delims.
  12666. node.setAttribute("stretchy", "false");
  12667. }
  12668. return node;
  12669. }
  12670. });
  12671. // "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
  12672. // src/symbols.js.
  12673. var defaultVariant = {
  12674. "mi": "italic",
  12675. "mn": "normal",
  12676. "mtext": "normal"
  12677. };
  12678. defineFunctionBuilders({
  12679. type: "mathord",
  12680. htmlBuilder(group, options) {
  12681. return buildCommon.makeOrd(group, options, "mathord");
  12682. },
  12683. mathmlBuilder(group, options) {
  12684. var node = new mathMLTree.MathNode("mi", [makeText(group.text, group.mode, options)]);
  12685. var variant = getVariant(group, options) || "italic";
  12686. if (variant !== defaultVariant[node.type]) {
  12687. node.setAttribute("mathvariant", variant);
  12688. }
  12689. return node;
  12690. }
  12691. });
  12692. defineFunctionBuilders({
  12693. type: "textord",
  12694. htmlBuilder(group, options) {
  12695. return buildCommon.makeOrd(group, options, "textord");
  12696. },
  12697. mathmlBuilder(group, options) {
  12698. var text = makeText(group.text, group.mode, options);
  12699. var variant = getVariant(group, options) || "normal";
  12700. var node;
  12701. if (group.mode === 'text') {
  12702. node = new mathMLTree.MathNode("mtext", [text]);
  12703. } else if (/[0-9]/.test(group.text)) {
  12704. node = new mathMLTree.MathNode("mn", [text]);
  12705. } else if (group.text === "\\prime") {
  12706. node = new mathMLTree.MathNode("mo", [text]);
  12707. } else {
  12708. node = new mathMLTree.MathNode("mi", [text]);
  12709. }
  12710. if (variant !== defaultVariant[node.type]) {
  12711. node.setAttribute("mathvariant", variant);
  12712. }
  12713. return node;
  12714. }
  12715. });
  12716. var cssSpace = {
  12717. "\\nobreak": "nobreak",
  12718. "\\allowbreak": "allowbreak"
  12719. }; // A lookup table to determine whether a spacing function/symbol should be
  12720. // treated like a regular space character. If a symbol or command is a key
  12721. // in this table, then it should be a regular space character. Furthermore,
  12722. // the associated value may have a `className` specifying an extra CSS class
  12723. // to add to the created `span`.
  12724. var regularSpace = {
  12725. " ": {},
  12726. "\\ ": {},
  12727. "~": {
  12728. className: "nobreak"
  12729. },
  12730. "\\space": {},
  12731. "\\nobreakspace": {
  12732. className: "nobreak"
  12733. }
  12734. }; // ParseNode<"spacing"> created in Parser.js from the "spacing" symbol Groups in
  12735. // src/symbols.js.
  12736. defineFunctionBuilders({
  12737. type: "spacing",
  12738. htmlBuilder(group, options) {
  12739. if (regularSpace.hasOwnProperty(group.text)) {
  12740. var className = regularSpace[group.text].className || ""; // Spaces are generated by adding an actual space. Each of these
  12741. // things has an entry in the symbols table, so these will be turned
  12742. // into appropriate outputs.
  12743. if (group.mode === "text") {
  12744. var ord = buildCommon.makeOrd(group, options, "textord");
  12745. ord.classes.push(className);
  12746. return ord;
  12747. } else {
  12748. return buildCommon.makeSpan(["mspace", className], [buildCommon.mathsym(group.text, group.mode, options)], options);
  12749. }
  12750. } else if (cssSpace.hasOwnProperty(group.text)) {
  12751. // Spaces based on just a CSS class.
  12752. return buildCommon.makeSpan(["mspace", cssSpace[group.text]], [], options);
  12753. } else {
  12754. throw new ParseError("Unknown type of space \"" + group.text + "\"");
  12755. }
  12756. },
  12757. mathmlBuilder(group, options) {
  12758. var node;
  12759. if (regularSpace.hasOwnProperty(group.text)) {
  12760. node = new mathMLTree.MathNode("mtext", [new mathMLTree.TextNode("\u00a0")]);
  12761. } else if (cssSpace.hasOwnProperty(group.text)) {
  12762. // CSS-based MathML spaces (\nobreak, \allowbreak) are ignored
  12763. return new mathMLTree.MathNode("mspace");
  12764. } else {
  12765. throw new ParseError("Unknown type of space \"" + group.text + "\"");
  12766. }
  12767. return node;
  12768. }
  12769. });
  12770. var pad = () => {
  12771. var padNode = new mathMLTree.MathNode("mtd", []);
  12772. padNode.setAttribute("width", "50%");
  12773. return padNode;
  12774. };
  12775. defineFunctionBuilders({
  12776. type: "tag",
  12777. mathmlBuilder(group, options) {
  12778. var table = new mathMLTree.MathNode("mtable", [new mathMLTree.MathNode("mtr", [pad(), new mathMLTree.MathNode("mtd", [buildExpressionRow(group.body, options)]), pad(), new mathMLTree.MathNode("mtd", [buildExpressionRow(group.tag, options)])])]);
  12779. table.setAttribute("width", "100%");
  12780. return table; // TODO: Left-aligned tags.
  12781. // Currently, the group and options passed here do not contain
  12782. // enough info to set tag alignment. `leqno` is in Settings but it is
  12783. // not passed to Options. On the HTML side, leqno is
  12784. // set by a CSS class applied in buildTree.js. That would have worked
  12785. // in MathML if browsers supported <mlabeledtr>. Since they don't, we
  12786. // need to rewrite the way this function is called.
  12787. }
  12788. });
  12789. var textFontFamilies = {
  12790. "\\text": undefined,
  12791. "\\textrm": "textrm",
  12792. "\\textsf": "textsf",
  12793. "\\texttt": "texttt",
  12794. "\\textnormal": "textrm"
  12795. };
  12796. var textFontWeights = {
  12797. "\\textbf": "textbf",
  12798. "\\textmd": "textmd"
  12799. };
  12800. var textFontShapes = {
  12801. "\\textit": "textit",
  12802. "\\textup": "textup"
  12803. };
  12804. var optionsWithFont = (group, options) => {
  12805. var font = group.font; // Checks if the argument is a font family or a font style.
  12806. if (!font) {
  12807. return options;
  12808. } else if (textFontFamilies[font]) {
  12809. return options.withTextFontFamily(textFontFamilies[font]);
  12810. } else if (textFontWeights[font]) {
  12811. return options.withTextFontWeight(textFontWeights[font]);
  12812. } else {
  12813. return options.withTextFontShape(textFontShapes[font]);
  12814. }
  12815. };
  12816. defineFunction({
  12817. type: "text",
  12818. names: [// Font families
  12819. "\\text", "\\textrm", "\\textsf", "\\texttt", "\\textnormal", // Font weights
  12820. "\\textbf", "\\textmd", // Font Shapes
  12821. "\\textit", "\\textup"],
  12822. props: {
  12823. numArgs: 1,
  12824. argTypes: ["text"],
  12825. allowedInArgument: true,
  12826. allowedInText: true
  12827. },
  12828. handler(_ref, args) {
  12829. var {
  12830. parser,
  12831. funcName
  12832. } = _ref;
  12833. var body = args[0];
  12834. return {
  12835. type: "text",
  12836. mode: parser.mode,
  12837. body: ordargument(body),
  12838. font: funcName
  12839. };
  12840. },
  12841. htmlBuilder(group, options) {
  12842. var newOptions = optionsWithFont(group, options);
  12843. var inner = buildExpression$1(group.body, newOptions, true);
  12844. return buildCommon.makeSpan(["mord", "text"], inner, newOptions);
  12845. },
  12846. mathmlBuilder(group, options) {
  12847. var newOptions = optionsWithFont(group, options);
  12848. return buildExpressionRow(group.body, newOptions);
  12849. }
  12850. });
  12851. defineFunction({
  12852. type: "underline",
  12853. names: ["\\underline"],
  12854. props: {
  12855. numArgs: 1,
  12856. allowedInText: true
  12857. },
  12858. handler(_ref, args) {
  12859. var {
  12860. parser
  12861. } = _ref;
  12862. return {
  12863. type: "underline",
  12864. mode: parser.mode,
  12865. body: args[0]
  12866. };
  12867. },
  12868. htmlBuilder(group, options) {
  12869. // Underlines are handled in the TeXbook pg 443, Rule 10.
  12870. // Build the inner group.
  12871. var innerGroup = buildGroup$1(group.body, options); // Create the line to go below the body
  12872. var line = buildCommon.makeLineSpan("underline-line", options); // Generate the vlist, with the appropriate kerns
  12873. var defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
  12874. var vlist = buildCommon.makeVList({
  12875. positionType: "top",
  12876. positionData: innerGroup.height,
  12877. children: [{
  12878. type: "kern",
  12879. size: defaultRuleThickness
  12880. }, {
  12881. type: "elem",
  12882. elem: line
  12883. }, {
  12884. type: "kern",
  12885. size: 3 * defaultRuleThickness
  12886. }, {
  12887. type: "elem",
  12888. elem: innerGroup
  12889. }]
  12890. }, options);
  12891. return buildCommon.makeSpan(["mord", "underline"], [vlist], options);
  12892. },
  12893. mathmlBuilder(group, options) {
  12894. var operator = new mathMLTree.MathNode("mo", [new mathMLTree.TextNode("\u203e")]);
  12895. operator.setAttribute("stretchy", "true");
  12896. var node = new mathMLTree.MathNode("munder", [buildGroup(group.body, options), operator]);
  12897. node.setAttribute("accentunder", "true");
  12898. return node;
  12899. }
  12900. });
  12901. defineFunction({
  12902. type: "vcenter",
  12903. names: ["\\vcenter"],
  12904. props: {
  12905. numArgs: 1,
  12906. argTypes: ["original"],
  12907. // In LaTeX, \vcenter can act only on a box.
  12908. allowedInText: false
  12909. },
  12910. handler(_ref, args) {
  12911. var {
  12912. parser
  12913. } = _ref;
  12914. return {
  12915. type: "vcenter",
  12916. mode: parser.mode,
  12917. body: args[0]
  12918. };
  12919. },
  12920. htmlBuilder(group, options) {
  12921. var body = buildGroup$1(group.body, options);
  12922. var axisHeight = options.fontMetrics().axisHeight;
  12923. var dy = 0.5 * (body.height - axisHeight - (body.depth + axisHeight));
  12924. return buildCommon.makeVList({
  12925. positionType: "shift",
  12926. positionData: dy,
  12927. children: [{
  12928. type: "elem",
  12929. elem: body
  12930. }]
  12931. }, options);
  12932. },
  12933. mathmlBuilder(group, options) {
  12934. // There is no way to do this in MathML.
  12935. // Write a class as a breadcrumb in case some post-processor wants
  12936. // to perform a vcenter adjustment.
  12937. return new mathMLTree.MathNode("mpadded", [buildGroup(group.body, options)], ["vcenter"]);
  12938. }
  12939. });
  12940. defineFunction({
  12941. type: "verb",
  12942. names: ["\\verb"],
  12943. props: {
  12944. numArgs: 0,
  12945. allowedInText: true
  12946. },
  12947. handler(context, args, optArgs) {
  12948. // \verb and \verb* are dealt with directly in Parser.js.
  12949. // If we end up here, it's because of a failure to match the two delimiters
  12950. // in the regex in Lexer.js. LaTeX raises the following error when \verb is
  12951. // terminated by end of line (or file).
  12952. throw new ParseError("\\verb ended by end of line instead of matching delimiter");
  12953. },
  12954. htmlBuilder(group, options) {
  12955. var text = makeVerb(group);
  12956. var body = []; // \verb enters text mode and therefore is sized like \textstyle
  12957. var newOptions = options.havingStyle(options.style.text());
  12958. for (var i = 0; i < text.length; i++) {
  12959. var c = text[i];
  12960. if (c === '~') {
  12961. c = '\\textasciitilde';
  12962. }
  12963. body.push(buildCommon.makeSymbol(c, "Typewriter-Regular", group.mode, newOptions, ["mord", "texttt"]));
  12964. }
  12965. return buildCommon.makeSpan(["mord", "text"].concat(newOptions.sizingClasses(options)), buildCommon.tryCombineChars(body), newOptions);
  12966. },
  12967. mathmlBuilder(group, options) {
  12968. var text = new mathMLTree.TextNode(makeVerb(group));
  12969. var node = new mathMLTree.MathNode("mtext", [text]);
  12970. node.setAttribute("mathvariant", "monospace");
  12971. return node;
  12972. }
  12973. });
  12974. /**
  12975. * Converts verb group into body string.
  12976. *
  12977. * \verb* replaces each space with an open box \u2423
  12978. * \verb replaces each space with a no-break space \xA0
  12979. */
  12980. var makeVerb = group => group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');
  12981. /** Include this to ensure that all functions are defined. */
  12982. var functions = _functions;
  12983. /**
  12984. * The Lexer class handles tokenizing the input in various ways. Since our
  12985. * parser expects us to be able to backtrack, the lexer allows lexing from any
  12986. * given starting point.
  12987. *
  12988. * Its main exposed function is the `lex` function, which takes a position to
  12989. * lex from and a type of token to lex. It defers to the appropriate `_innerLex`
  12990. * function.
  12991. *
  12992. * The various `_innerLex` functions perform the actual lexing of different
  12993. * kinds.
  12994. */
  12995. /* The following tokenRegex
  12996. * - matches typical whitespace (but not NBSP etc.) using its first group
  12997. * - does not match any control character \x00-\x1f except whitespace
  12998. * - does not match a bare backslash
  12999. * - matches any ASCII character except those just mentioned
  13000. * - does not match the BMP private use area \uE000-\uF8FF
  13001. * - does not match bare surrogate code units
  13002. * - matches any BMP character except for those just described
  13003. * - matches any valid Unicode surrogate pair
  13004. * - matches a backslash followed by one or more whitespace characters
  13005. * - matches a backslash followed by one or more letters then whitespace
  13006. * - matches a backslash followed by any BMP character
  13007. * Capturing groups:
  13008. * [1] regular whitespace
  13009. * [2] backslash followed by whitespace
  13010. * [3] anything else, which may include:
  13011. * [4] left character of \verb*
  13012. * [5] left character of \verb
  13013. * [6] backslash followed by word, excluding any trailing whitespace
  13014. * Just because the Lexer matches something doesn't mean it's valid input:
  13015. * If there is no matching function or symbol definition, the Parser will
  13016. * still reject the input.
  13017. */
  13018. var spaceRegexString = "[ \r\n\t]";
  13019. var controlWordRegexString = "\\\\[a-zA-Z@]+";
  13020. var controlSymbolRegexString = "\\\\[^\uD800-\uDFFF]";
  13021. var controlWordWhitespaceRegexString = "(" + controlWordRegexString + ")" + spaceRegexString + "*";
  13022. var controlSpaceRegexString = "\\\\(\n|[ \r\t]+\n?)[ \r\t]*";
  13023. var combiningDiacriticalMarkString = "[\u0300-\u036f]";
  13024. var combiningDiacriticalMarksEndRegex = new RegExp(combiningDiacriticalMarkString + "+$");
  13025. var tokenRegexString = "(" + spaceRegexString + "+)|" + ( // whitespace
  13026. controlSpaceRegexString + "|") + // \whitespace
  13027. "([!-\\[\\]-\u2027\u202A-\uD7FF\uF900-\uFFFF]" + ( // single codepoint
  13028. combiningDiacriticalMarkString + "*") + // ...plus accents
  13029. "|[\uD800-\uDBFF][\uDC00-\uDFFF]" + ( // surrogate pair
  13030. combiningDiacriticalMarkString + "*") + // ...plus accents
  13031. "|\\\\verb\\*([^]).*?\\4" + // \verb*
  13032. "|\\\\verb([^*a-zA-Z]).*?\\5" + ( // \verb unstarred
  13033. "|" + controlWordWhitespaceRegexString) + ( // \macroName + spaces
  13034. "|" + controlSymbolRegexString + ")"); // \\, \', etc.
  13035. /** Main Lexer class */
  13036. class Lexer {
  13037. // Category codes. The lexer only supports comment characters (14) for now.
  13038. // MacroExpander additionally distinguishes active (13).
  13039. constructor(input, settings) {
  13040. this.input = void 0;
  13041. this.settings = void 0;
  13042. this.tokenRegex = void 0;
  13043. this.catcodes = void 0;
  13044. // Separate accents from characters
  13045. this.input = input;
  13046. this.settings = settings;
  13047. this.tokenRegex = new RegExp(tokenRegexString, 'g');
  13048. this.catcodes = {
  13049. "%": 14,
  13050. // comment character
  13051. "~": 13 // active character
  13052. };
  13053. }
  13054. setCatcode(char, code) {
  13055. this.catcodes[char] = code;
  13056. }
  13057. /**
  13058. * This function lexes a single token.
  13059. */
  13060. lex() {
  13061. var input = this.input;
  13062. var pos = this.tokenRegex.lastIndex;
  13063. if (pos === input.length) {
  13064. return new Token("EOF", new SourceLocation(this, pos, pos));
  13065. }
  13066. var match = this.tokenRegex.exec(input);
  13067. if (match === null || match.index !== pos) {
  13068. throw new ParseError("Unexpected character: '" + input[pos] + "'", new Token(input[pos], new SourceLocation(this, pos, pos + 1)));
  13069. }
  13070. var text = match[6] || match[3] || (match[2] ? "\\ " : " ");
  13071. if (this.catcodes[text] === 14) {
  13072. // comment character
  13073. var nlIndex = input.indexOf('\n', this.tokenRegex.lastIndex);
  13074. if (nlIndex === -1) {
  13075. this.tokenRegex.lastIndex = input.length; // EOF
  13076. this.settings.reportNonstrict("commentAtEnd", "% comment has no terminating newline; LaTeX would " + "fail because of commenting the end of math mode (e.g. $)");
  13077. } else {
  13078. this.tokenRegex.lastIndex = nlIndex + 1;
  13079. }
  13080. return this.lex();
  13081. }
  13082. return new Token(text, new SourceLocation(this, pos, this.tokenRegex.lastIndex));
  13083. }
  13084. }
  13085. /**
  13086. * A `Namespace` refers to a space of nameable things like macros or lengths,
  13087. * which can be `set` either globally or local to a nested group, using an
  13088. * undo stack similar to how TeX implements this functionality.
  13089. * Performance-wise, `get` and local `set` take constant time, while global
  13090. * `set` takes time proportional to the depth of group nesting.
  13091. */
  13092. class Namespace {
  13093. /**
  13094. * Both arguments are optional. The first argument is an object of
  13095. * built-in mappings which never change. The second argument is an object
  13096. * of initial (global-level) mappings, which will constantly change
  13097. * according to any global/top-level `set`s done.
  13098. */
  13099. constructor(builtins, globalMacros) {
  13100. if (builtins === void 0) {
  13101. builtins = {};
  13102. }
  13103. if (globalMacros === void 0) {
  13104. globalMacros = {};
  13105. }
  13106. this.current = void 0;
  13107. this.builtins = void 0;
  13108. this.undefStack = void 0;
  13109. this.current = globalMacros;
  13110. this.builtins = builtins;
  13111. this.undefStack = [];
  13112. }
  13113. /**
  13114. * Start a new nested group, affecting future local `set`s.
  13115. */
  13116. beginGroup() {
  13117. this.undefStack.push({});
  13118. }
  13119. /**
  13120. * End current nested group, restoring values before the group began.
  13121. */
  13122. endGroup() {
  13123. if (this.undefStack.length === 0) {
  13124. throw new ParseError("Unbalanced namespace destruction: attempt " + "to pop global namespace; please report this as a bug");
  13125. }
  13126. var undefs = this.undefStack.pop();
  13127. for (var undef in undefs) {
  13128. if (undefs.hasOwnProperty(undef)) {
  13129. if (undefs[undef] == null) {
  13130. delete this.current[undef];
  13131. } else {
  13132. this.current[undef] = undefs[undef];
  13133. }
  13134. }
  13135. }
  13136. }
  13137. /**
  13138. * Ends all currently nested groups (if any), restoring values before the
  13139. * groups began. Useful in case of an error in the middle of parsing.
  13140. */
  13141. endGroups() {
  13142. while (this.undefStack.length > 0) {
  13143. this.endGroup();
  13144. }
  13145. }
  13146. /**
  13147. * Detect whether `name` has a definition. Equivalent to
  13148. * `get(name) != null`.
  13149. */
  13150. has(name) {
  13151. return this.current.hasOwnProperty(name) || this.builtins.hasOwnProperty(name);
  13152. }
  13153. /**
  13154. * Get the current value of a name, or `undefined` if there is no value.
  13155. *
  13156. * Note: Do not use `if (namespace.get(...))` to detect whether a macro
  13157. * is defined, as the definition may be the empty string which evaluates
  13158. * to `false` in JavaScript. Use `if (namespace.get(...) != null)` or
  13159. * `if (namespace.has(...))`.
  13160. */
  13161. get(name) {
  13162. if (this.current.hasOwnProperty(name)) {
  13163. return this.current[name];
  13164. } else {
  13165. return this.builtins[name];
  13166. }
  13167. }
  13168. /**
  13169. * Set the current value of a name, and optionally set it globally too.
  13170. * Local set() sets the current value and (when appropriate) adds an undo
  13171. * operation to the undo stack. Global set() may change the undo
  13172. * operation at every level, so takes time linear in their number.
  13173. * A value of undefined means to delete existing definitions.
  13174. */
  13175. set(name, value, global) {
  13176. if (global === void 0) {
  13177. global = false;
  13178. }
  13179. if (global) {
  13180. // Global set is equivalent to setting in all groups. Simulate this
  13181. // by destroying any undos currently scheduled for this name,
  13182. // and adding an undo with the *new* value (in case it later gets
  13183. // locally reset within this environment).
  13184. for (var i = 0; i < this.undefStack.length; i++) {
  13185. delete this.undefStack[i][name];
  13186. }
  13187. if (this.undefStack.length > 0) {
  13188. this.undefStack[this.undefStack.length - 1][name] = value;
  13189. }
  13190. } else {
  13191. // Undo this set at end of this group (possibly to `undefined`),
  13192. // unless an undo is already in place, in which case that older
  13193. // value is the correct one.
  13194. var top = this.undefStack[this.undefStack.length - 1];
  13195. if (top && !top.hasOwnProperty(name)) {
  13196. top[name] = this.current[name];
  13197. }
  13198. }
  13199. if (value == null) {
  13200. delete this.current[name];
  13201. } else {
  13202. this.current[name] = value;
  13203. }
  13204. }
  13205. }
  13206. /**
  13207. * Predefined macros for KaTeX.
  13208. * This can be used to define some commands in terms of others.
  13209. */
  13210. var macros = _macros;
  13211. // macro tools
  13212. defineMacro("\\noexpand", function (context) {
  13213. // The expansion is the token itself; but that token is interpreted
  13214. // as if its meaning were ‘\relax’ if it is a control sequence that
  13215. // would ordinarily be expanded by TeX’s expansion rules.
  13216. var t = context.popToken();
  13217. if (context.isExpandable(t.text)) {
  13218. t.noexpand = true;
  13219. t.treatAsRelax = true;
  13220. }
  13221. return {
  13222. tokens: [t],
  13223. numArgs: 0
  13224. };
  13225. });
  13226. defineMacro("\\expandafter", function (context) {
  13227. // TeX first reads the token that comes immediately after \expandafter,
  13228. // without expanding it; let’s call this token t. Then TeX reads the
  13229. // token that comes after t (and possibly more tokens, if that token
  13230. // has an argument), replacing it by its expansion. Finally TeX puts
  13231. // t back in front of that expansion.
  13232. var t = context.popToken();
  13233. context.expandOnce(true); // expand only an expandable token
  13234. return {
  13235. tokens: [t],
  13236. numArgs: 0
  13237. };
  13238. }); // LaTeX's \@firstoftwo{#1}{#2} expands to #1, skipping #2
  13239. // TeX source: \long\def\@firstoftwo#1#2{#1}
  13240. defineMacro("\\@firstoftwo", function (context) {
  13241. var args = context.consumeArgs(2);
  13242. return {
  13243. tokens: args[0],
  13244. numArgs: 0
  13245. };
  13246. }); // LaTeX's \@secondoftwo{#1}{#2} expands to #2, skipping #1
  13247. // TeX source: \long\def\@secondoftwo#1#2{#2}
  13248. defineMacro("\\@secondoftwo", function (context) {
  13249. var args = context.consumeArgs(2);
  13250. return {
  13251. tokens: args[1],
  13252. numArgs: 0
  13253. };
  13254. }); // LaTeX's \@ifnextchar{#1}{#2}{#3} looks ahead to the next (unexpanded)
  13255. // symbol that isn't a space, consuming any spaces but not consuming the
  13256. // first nonspace character. If that nonspace character matches #1, then
  13257. // the macro expands to #2; otherwise, it expands to #3.
  13258. defineMacro("\\@ifnextchar", function (context) {
  13259. var args = context.consumeArgs(3); // symbol, if, else
  13260. context.consumeSpaces();
  13261. var nextToken = context.future();
  13262. if (args[0].length === 1 && args[0][0].text === nextToken.text) {
  13263. return {
  13264. tokens: args[1],
  13265. numArgs: 0
  13266. };
  13267. } else {
  13268. return {
  13269. tokens: args[2],
  13270. numArgs: 0
  13271. };
  13272. }
  13273. }); // LaTeX's \@ifstar{#1}{#2} looks ahead to the next (unexpanded) symbol.
  13274. // If it is `*`, then it consumes the symbol, and the macro expands to #1;
  13275. // otherwise, the macro expands to #2 (without consuming the symbol).
  13276. // TeX source: \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
  13277. defineMacro("\\@ifstar", "\\@ifnextchar *{\\@firstoftwo{#1}}"); // LaTeX's \TextOrMath{#1}{#2} expands to #1 in text mode, #2 in math mode
  13278. defineMacro("\\TextOrMath", function (context) {
  13279. var args = context.consumeArgs(2);
  13280. if (context.mode === 'text') {
  13281. return {
  13282. tokens: args[0],
  13283. numArgs: 0
  13284. };
  13285. } else {
  13286. return {
  13287. tokens: args[1],
  13288. numArgs: 0
  13289. };
  13290. }
  13291. }); // Lookup table for parsing numbers in base 8 through 16
  13292. var digitToNumber = {
  13293. "0": 0,
  13294. "1": 1,
  13295. "2": 2,
  13296. "3": 3,
  13297. "4": 4,
  13298. "5": 5,
  13299. "6": 6,
  13300. "7": 7,
  13301. "8": 8,
  13302. "9": 9,
  13303. "a": 10,
  13304. "A": 10,
  13305. "b": 11,
  13306. "B": 11,
  13307. "c": 12,
  13308. "C": 12,
  13309. "d": 13,
  13310. "D": 13,
  13311. "e": 14,
  13312. "E": 14,
  13313. "f": 15,
  13314. "F": 15
  13315. }; // TeX \char makes a literal character (catcode 12) using the following forms:
  13316. // (see The TeXBook, p. 43)
  13317. // \char123 -- decimal
  13318. // \char'123 -- octal
  13319. // \char"123 -- hex
  13320. // \char`x -- character that can be written (i.e. isn't active)
  13321. // \char`\x -- character that cannot be written (e.g. %)
  13322. // These all refer to characters from the font, so we turn them into special
  13323. // calls to a function \@char dealt with in the Parser.
  13324. defineMacro("\\char", function (context) {
  13325. var token = context.popToken();
  13326. var base;
  13327. var number = '';
  13328. if (token.text === "'") {
  13329. base = 8;
  13330. token = context.popToken();
  13331. } else if (token.text === '"') {
  13332. base = 16;
  13333. token = context.popToken();
  13334. } else if (token.text === "`") {
  13335. token = context.popToken();
  13336. if (token.text[0] === "\\") {
  13337. number = token.text.charCodeAt(1);
  13338. } else if (token.text === "EOF") {
  13339. throw new ParseError("\\char` missing argument");
  13340. } else {
  13341. number = token.text.charCodeAt(0);
  13342. }
  13343. } else {
  13344. base = 10;
  13345. }
  13346. if (base) {
  13347. // Parse a number in the given base, starting with first `token`.
  13348. number = digitToNumber[token.text];
  13349. if (number == null || number >= base) {
  13350. throw new ParseError("Invalid base-" + base + " digit " + token.text);
  13351. }
  13352. var digit;
  13353. while ((digit = digitToNumber[context.future().text]) != null && digit < base) {
  13354. number *= base;
  13355. number += digit;
  13356. context.popToken();
  13357. }
  13358. }
  13359. return "\\@char{" + number + "}";
  13360. }); // \newcommand{\macro}[args]{definition}
  13361. // \renewcommand{\macro}[args]{definition}
  13362. // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
  13363. var newcommand = (context, existsOK, nonexistsOK) => {
  13364. var arg = context.consumeArg().tokens;
  13365. if (arg.length !== 1) {
  13366. throw new ParseError("\\newcommand's first argument must be a macro name");
  13367. }
  13368. var name = arg[0].text;
  13369. var exists = context.isDefined(name);
  13370. if (exists && !existsOK) {
  13371. throw new ParseError("\\newcommand{" + name + "} attempting to redefine " + (name + "; use \\renewcommand"));
  13372. }
  13373. if (!exists && !nonexistsOK) {
  13374. throw new ParseError("\\renewcommand{" + name + "} when command " + name + " " + "does not yet exist; use \\newcommand");
  13375. }
  13376. var numArgs = 0;
  13377. arg = context.consumeArg().tokens;
  13378. if (arg.length === 1 && arg[0].text === "[") {
  13379. var argText = '';
  13380. var token = context.expandNextToken();
  13381. while (token.text !== "]" && token.text !== "EOF") {
  13382. // TODO: Should properly expand arg, e.g., ignore {}s
  13383. argText += token.text;
  13384. token = context.expandNextToken();
  13385. }
  13386. if (!argText.match(/^\s*[0-9]+\s*$/)) {
  13387. throw new ParseError("Invalid number of arguments: " + argText);
  13388. }
  13389. numArgs = parseInt(argText);
  13390. arg = context.consumeArg().tokens;
  13391. } // Final arg is the expansion of the macro
  13392. context.macros.set(name, {
  13393. tokens: arg,
  13394. numArgs
  13395. });
  13396. return '';
  13397. };
  13398. defineMacro("\\newcommand", context => newcommand(context, false, true));
  13399. defineMacro("\\renewcommand", context => newcommand(context, true, false));
  13400. defineMacro("\\providecommand", context => newcommand(context, true, true)); // terminal (console) tools
  13401. defineMacro("\\message", context => {
  13402. var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
  13403. console.log(arg.reverse().map(token => token.text).join(""));
  13404. return '';
  13405. });
  13406. defineMacro("\\errmessage", context => {
  13407. var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
  13408. console.error(arg.reverse().map(token => token.text).join(""));
  13409. return '';
  13410. });
  13411. defineMacro("\\show", context => {
  13412. var tok = context.popToken();
  13413. var name = tok.text; // eslint-disable-next-line no-console
  13414. console.log(tok, context.macros.get(name), functions[name], symbols.math[name], symbols.text[name]);
  13415. return '';
  13416. }); //////////////////////////////////////////////////////////////////////
  13417. // Grouping
  13418. // \let\bgroup={ \let\egroup=}
  13419. defineMacro("\\bgroup", "{");
  13420. defineMacro("\\egroup", "}"); // Symbols from latex.ltx:
  13421. // \def~{\nobreakspace{}}
  13422. // \def\lq{`}
  13423. // \def\rq{'}
  13424. // \def \aa {\r a}
  13425. // \def \AA {\r A}
  13426. defineMacro("~", "\\nobreakspace");
  13427. defineMacro("\\lq", "`");
  13428. defineMacro("\\rq", "'");
  13429. defineMacro("\\aa", "\\r a");
  13430. defineMacro("\\AA", "\\r A"); // Copyright (C) and registered (R) symbols. Use raw symbol in MathML.
  13431. // \DeclareTextCommandDefault{\textcopyright}{\textcircled{c}}
  13432. // \DeclareTextCommandDefault{\textregistered}{\textcircled{%
  13433. // \check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont R}}
  13434. // \DeclareRobustCommand{\copyright}{%
  13435. // \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
  13436. defineMacro("\\textcopyright", "\\html@mathml{\\textcircled{c}}{\\char`©}");
  13437. defineMacro("\\copyright", "\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");
  13438. defineMacro("\\textregistered", "\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"); // Characters omitted from Unicode range 1D400–1D7FF
  13439. defineMacro("\u212C", "\\mathscr{B}"); // script
  13440. defineMacro("\u2130", "\\mathscr{E}");
  13441. defineMacro("\u2131", "\\mathscr{F}");
  13442. defineMacro("\u210B", "\\mathscr{H}");
  13443. defineMacro("\u2110", "\\mathscr{I}");
  13444. defineMacro("\u2112", "\\mathscr{L}");
  13445. defineMacro("\u2133", "\\mathscr{M}");
  13446. defineMacro("\u211B", "\\mathscr{R}");
  13447. defineMacro("\u212D", "\\mathfrak{C}"); // Fraktur
  13448. defineMacro("\u210C", "\\mathfrak{H}");
  13449. defineMacro("\u2128", "\\mathfrak{Z}"); // Define \Bbbk with a macro that works in both HTML and MathML.
  13450. defineMacro("\\Bbbk", "\\Bbb{k}"); // Unicode middle dot
  13451. // The KaTeX fonts do not contain U+00B7. Instead, \cdotp displays
  13452. // the dot at U+22C5 and gives it punct spacing.
  13453. defineMacro("\u00b7", "\\cdotp"); // \llap and \rlap render their contents in text mode
  13454. defineMacro("\\llap", "\\mathllap{\\textrm{#1}}");
  13455. defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}");
  13456. defineMacro("\\clap", "\\mathclap{\\textrm{#1}}"); // \mathstrut from the TeXbook, p 360
  13457. defineMacro("\\mathstrut", "\\vphantom{(}"); // \underbar from TeXbook p 353
  13458. defineMacro("\\underbar", "\\underline{\\text{#1}}"); // \not is defined by base/fontmath.ltx via
  13459. // \DeclareMathSymbol{\not}{\mathrel}{symbols}{"36}
  13460. // It's thus treated like a \mathrel, but defined by a symbol that has zero
  13461. // width but extends to the right. We use \rlap to get that spacing.
  13462. // For MathML we write U+0338 here. buildMathML.js will then do the overlay.
  13463. defineMacro("\\not", '\\html@mathml{\\mathrel{\\mathrlap\\@not}}{\\char"338}'); // Negated symbols from base/fontmath.ltx:
  13464. // \def\neq{\not=} \let\ne=\neq
  13465. // \DeclareRobustCommand
  13466. // \notin{\mathrel{\m@th\mathpalette\c@ncel\in}}
  13467. // \def\c@ncel#1#2{\m@th\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
  13468. defineMacro("\\neq", "\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}");
  13469. defineMacro("\\ne", "\\neq");
  13470. defineMacro("\u2260", "\\neq");
  13471. defineMacro("\\notin", "\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}" + "{\\mathrel{\\char`∉}}");
  13472. defineMacro("\u2209", "\\notin"); // Unicode stacked relations
  13473. defineMacro("\u2258", "\\html@mathml{" + "\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}" + "}{\\mathrel{\\char`\u2258}}");
  13474. defineMacro("\u2259", "\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`\u2258}}");
  13475. defineMacro("\u225A", "\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`\u225A}}");
  13476. defineMacro("\u225B", "\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}" + "{\\mathrel{\\char`\u225B}}");
  13477. defineMacro("\u225D", "\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}" + "{\\mathrel{\\char`\u225D}}");
  13478. defineMacro("\u225E", "\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}" + "{\\mathrel{\\char`\u225E}}");
  13479. defineMacro("\u225F", "\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`\u225F}}"); // Misc Unicode
  13480. defineMacro("\u27C2", "\\perp");
  13481. defineMacro("\u203C", "\\mathclose{!\\mkern-0.8mu!}");
  13482. defineMacro("\u220C", "\\notni");
  13483. defineMacro("\u231C", "\\ulcorner");
  13484. defineMacro("\u231D", "\\urcorner");
  13485. defineMacro("\u231E", "\\llcorner");
  13486. defineMacro("\u231F", "\\lrcorner");
  13487. defineMacro("\u00A9", "\\copyright");
  13488. defineMacro("\u00AE", "\\textregistered");
  13489. defineMacro("\uFE0F", "\\textregistered"); // The KaTeX fonts have corners at codepoints that don't match Unicode.
  13490. // For MathML purposes, use the Unicode code point.
  13491. defineMacro("\\ulcorner", "\\html@mathml{\\@ulcorner}{\\mathop{\\char\"231c}}");
  13492. defineMacro("\\urcorner", "\\html@mathml{\\@urcorner}{\\mathop{\\char\"231d}}");
  13493. defineMacro("\\llcorner", "\\html@mathml{\\@llcorner}{\\mathop{\\char\"231e}}");
  13494. defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}"); //////////////////////////////////////////////////////////////////////
  13495. // LaTeX_2ε
  13496. // \vdots{\vbox{\baselineskip4\p@ \lineskiplimit\z@
  13497. // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
  13498. // We'll call \varvdots, which gets a glyph from symbols.js.
  13499. // The zero-width rule gets us an equivalent to the vertical 6pt kern.
  13500. defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
  13501. defineMacro("\u22ee", "\\vdots"); //////////////////////////////////////////////////////////////////////
  13502. // amsmath.sty
  13503. // http://mirrors.concertpass.com/tex-archive/macros/latex/required/amsmath/amsmath.pdf
  13504. // Italic Greek capital letters. AMS defines these with \DeclareMathSymbol,
  13505. // but they are equivalent to \mathit{\Letter}.
  13506. defineMacro("\\varGamma", "\\mathit{\\Gamma}");
  13507. defineMacro("\\varDelta", "\\mathit{\\Delta}");
  13508. defineMacro("\\varTheta", "\\mathit{\\Theta}");
  13509. defineMacro("\\varLambda", "\\mathit{\\Lambda}");
  13510. defineMacro("\\varXi", "\\mathit{\\Xi}");
  13511. defineMacro("\\varPi", "\\mathit{\\Pi}");
  13512. defineMacro("\\varSigma", "\\mathit{\\Sigma}");
  13513. defineMacro("\\varUpsilon", "\\mathit{\\Upsilon}");
  13514. defineMacro("\\varPhi", "\\mathit{\\Phi}");
  13515. defineMacro("\\varPsi", "\\mathit{\\Psi}");
  13516. defineMacro("\\varOmega", "\\mathit{\\Omega}"); //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
  13517. defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}"); // \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
  13518. // \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
  13519. defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}" + "\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax"); // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
  13520. defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}"); // \def\iff{\DOTSB\;\Longleftrightarrow\;}
  13521. // \def\implies{\DOTSB\;\Longrightarrow\;}
  13522. // \def\impliedby{\DOTSB\;\Longleftarrow\;}
  13523. defineMacro("\\iff", "\\DOTSB\\;\\Longleftrightarrow\\;");
  13524. defineMacro("\\implies", "\\DOTSB\\;\\Longrightarrow\\;");
  13525. defineMacro("\\impliedby", "\\DOTSB\\;\\Longleftarrow\\;"); // AMSMath's automatic \dots, based on \mdots@@ macro.
  13526. var dotsByToken = {
  13527. ',': '\\dotsc',
  13528. '\\not': '\\dotsb',
  13529. // \keybin@ checks for the following:
  13530. '+': '\\dotsb',
  13531. '=': '\\dotsb',
  13532. '<': '\\dotsb',
  13533. '>': '\\dotsb',
  13534. '-': '\\dotsb',
  13535. '*': '\\dotsb',
  13536. ':': '\\dotsb',
  13537. // Symbols whose definition starts with \DOTSB:
  13538. '\\DOTSB': '\\dotsb',
  13539. '\\coprod': '\\dotsb',
  13540. '\\bigvee': '\\dotsb',
  13541. '\\bigwedge': '\\dotsb',
  13542. '\\biguplus': '\\dotsb',
  13543. '\\bigcap': '\\dotsb',
  13544. '\\bigcup': '\\dotsb',
  13545. '\\prod': '\\dotsb',
  13546. '\\sum': '\\dotsb',
  13547. '\\bigotimes': '\\dotsb',
  13548. '\\bigoplus': '\\dotsb',
  13549. '\\bigodot': '\\dotsb',
  13550. '\\bigsqcup': '\\dotsb',
  13551. '\\And': '\\dotsb',
  13552. '\\longrightarrow': '\\dotsb',
  13553. '\\Longrightarrow': '\\dotsb',
  13554. '\\longleftarrow': '\\dotsb',
  13555. '\\Longleftarrow': '\\dotsb',
  13556. '\\longleftrightarrow': '\\dotsb',
  13557. '\\Longleftrightarrow': '\\dotsb',
  13558. '\\mapsto': '\\dotsb',
  13559. '\\longmapsto': '\\dotsb',
  13560. '\\hookrightarrow': '\\dotsb',
  13561. '\\doteq': '\\dotsb',
  13562. // Symbols whose definition starts with \mathbin:
  13563. '\\mathbin': '\\dotsb',
  13564. // Symbols whose definition starts with \mathrel:
  13565. '\\mathrel': '\\dotsb',
  13566. '\\relbar': '\\dotsb',
  13567. '\\Relbar': '\\dotsb',
  13568. '\\xrightarrow': '\\dotsb',
  13569. '\\xleftarrow': '\\dotsb',
  13570. // Symbols whose definition starts with \DOTSI:
  13571. '\\DOTSI': '\\dotsi',
  13572. '\\int': '\\dotsi',
  13573. '\\oint': '\\dotsi',
  13574. '\\iint': '\\dotsi',
  13575. '\\iiint': '\\dotsi',
  13576. '\\iiiint': '\\dotsi',
  13577. '\\idotsint': '\\dotsi',
  13578. // Symbols whose definition starts with \DOTSX:
  13579. '\\DOTSX': '\\dotsx'
  13580. };
  13581. defineMacro("\\dots", function (context) {
  13582. // TODO: If used in text mode, should expand to \textellipsis.
  13583. // However, in KaTeX, \textellipsis and \ldots behave the same
  13584. // (in text mode), and it's unlikely we'd see any of the math commands
  13585. // that affect the behavior of \dots when in text mode. So fine for now
  13586. // (until we support \ifmmode ... \else ... \fi).
  13587. var thedots = '\\dotso';
  13588. var next = context.expandAfterFuture().text;
  13589. if (next in dotsByToken) {
  13590. thedots = dotsByToken[next];
  13591. } else if (next.slice(0, 4) === '\\not') {
  13592. thedots = '\\dotsb';
  13593. } else if (next in symbols.math) {
  13594. if (utils.contains(['bin', 'rel'], symbols.math[next].group)) {
  13595. thedots = '\\dotsb';
  13596. }
  13597. }
  13598. return thedots;
  13599. });
  13600. var spaceAfterDots = {
  13601. // \rightdelim@ checks for the following:
  13602. ')': true,
  13603. ']': true,
  13604. '\\rbrack': true,
  13605. '\\}': true,
  13606. '\\rbrace': true,
  13607. '\\rangle': true,
  13608. '\\rceil': true,
  13609. '\\rfloor': true,
  13610. '\\rgroup': true,
  13611. '\\rmoustache': true,
  13612. '\\right': true,
  13613. '\\bigr': true,
  13614. '\\biggr': true,
  13615. '\\Bigr': true,
  13616. '\\Biggr': true,
  13617. // \extra@ also tests for the following:
  13618. '$': true,
  13619. // \extrap@ checks for the following:
  13620. ';': true,
  13621. '.': true,
  13622. ',': true
  13623. };
  13624. defineMacro("\\dotso", function (context) {
  13625. var next = context.future().text;
  13626. if (next in spaceAfterDots) {
  13627. return "\\ldots\\,";
  13628. } else {
  13629. return "\\ldots";
  13630. }
  13631. });
  13632. defineMacro("\\dotsc", function (context) {
  13633. var next = context.future().text; // \dotsc uses \extra@ but not \extrap@, instead specially checking for
  13634. // ';' and '.', but doesn't check for ','.
  13635. if (next in spaceAfterDots && next !== ',') {
  13636. return "\\ldots\\,";
  13637. } else {
  13638. return "\\ldots";
  13639. }
  13640. });
  13641. defineMacro("\\cdots", function (context) {
  13642. var next = context.future().text;
  13643. if (next in spaceAfterDots) {
  13644. return "\\@cdots\\,";
  13645. } else {
  13646. return "\\@cdots";
  13647. }
  13648. });
  13649. defineMacro("\\dotsb", "\\cdots");
  13650. defineMacro("\\dotsm", "\\cdots");
  13651. defineMacro("\\dotsi", "\\!\\cdots"); // amsmath doesn't actually define \dotsx, but \dots followed by a macro
  13652. // starting with \DOTSX implies \dotso, and then \extra@ detects this case
  13653. // and forces the added `\,`.
  13654. defineMacro("\\dotsx", "\\ldots\\,"); // \let\DOTSI\relax
  13655. // \let\DOTSB\relax
  13656. // \let\DOTSX\relax
  13657. defineMacro("\\DOTSI", "\\relax");
  13658. defineMacro("\\DOTSB", "\\relax");
  13659. defineMacro("\\DOTSX", "\\relax"); // Spacing, based on amsmath.sty's override of LaTeX defaults
  13660. // \DeclareRobustCommand{\tmspace}[3]{%
  13661. // \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
  13662. defineMacro("\\tmspace", "\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax"); // \renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
  13663. // TODO: math mode should use \thinmuskip
  13664. defineMacro("\\,", "\\tmspace+{3mu}{.1667em}"); // \let\thinspace\,
  13665. defineMacro("\\thinspace", "\\,"); // \def\>{\mskip\medmuskip}
  13666. // \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
  13667. // TODO: \> and math mode of \: should use \medmuskip = 4mu plus 2mu minus 4mu
  13668. defineMacro("\\>", "\\mskip{4mu}");
  13669. defineMacro("\\:", "\\tmspace+{4mu}{.2222em}"); // \let\medspace\:
  13670. defineMacro("\\medspace", "\\:"); // \renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
  13671. // TODO: math mode should use \thickmuskip = 5mu plus 5mu
  13672. defineMacro("\\;", "\\tmspace+{5mu}{.2777em}"); // \let\thickspace\;
  13673. defineMacro("\\thickspace", "\\;"); // \renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
  13674. // TODO: math mode should use \thinmuskip
  13675. defineMacro("\\!", "\\tmspace-{3mu}{.1667em}"); // \let\negthinspace\!
  13676. defineMacro("\\negthinspace", "\\!"); // \newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
  13677. // TODO: math mode should use \medmuskip
  13678. defineMacro("\\negmedspace", "\\tmspace-{4mu}{.2222em}"); // \newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
  13679. // TODO: math mode should use \thickmuskip
  13680. defineMacro("\\negthickspace", "\\tmspace-{5mu}{.277em}"); // \def\enspace{\kern.5em }
  13681. defineMacro("\\enspace", "\\kern.5em "); // \def\enskip{\hskip.5em\relax}
  13682. defineMacro("\\enskip", "\\hskip.5em\\relax"); // \def\quad{\hskip1em\relax}
  13683. defineMacro("\\quad", "\\hskip1em\\relax"); // \def\qquad{\hskip2em\relax}
  13684. defineMacro("\\qquad", "\\hskip2em\\relax"); // \tag@in@display form of \tag
  13685. defineMacro("\\tag", "\\@ifstar\\tag@literal\\tag@paren");
  13686. defineMacro("\\tag@paren", "\\tag@literal{({#1})}");
  13687. defineMacro("\\tag@literal", context => {
  13688. if (context.macros.get("\\df@tag")) {
  13689. throw new ParseError("Multiple \\tag");
  13690. }
  13691. return "\\gdef\\df@tag{\\text{#1}}";
  13692. }); // \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
  13693. // {\operator@font mod}\penalty900
  13694. // \mkern5mu\nonscript\mskip-\medmuskip}
  13695. // \newcommand{\pod}[1]{\allowbreak
  13696. // \if@display\mkern18mu\else\mkern8mu\fi(#1)}
  13697. // \renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}
  13698. // \newcommand{\mod}[1]{\allowbreak\if@display\mkern18mu
  13699. // \else\mkern12mu\fi{\operator@font mod}\,\,#1}
  13700. // TODO: math mode should use \medmuskip = 4mu plus 2mu minus 4mu
  13701. defineMacro("\\bmod", "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}" + "\\mathbin{\\rm mod}" + "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}");
  13702. defineMacro("\\pod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");
  13703. defineMacro("\\pmod", "\\pod{{\\rm mod}\\mkern6mu#1}");
  13704. defineMacro("\\mod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}" + "{\\rm mod}\\,\\,#1"); //////////////////////////////////////////////////////////////////////
  13705. // LaTeX source2e
  13706. // \expandafter\let\expandafter\@normalcr
  13707. // \csname\expandafter\@gobble\string\\ \endcsname
  13708. // \DeclareRobustCommand\newline{\@normalcr\relax}
  13709. defineMacro("\\newline", "\\\\\\relax"); // \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
  13710. // TODO: Doesn't normally work in math mode because \@ fails. KaTeX doesn't
  13711. // support \@ yet, so that's omitted, and we add \text so that the result
  13712. // doesn't look funny in math mode.
  13713. defineMacro("\\TeX", "\\textrm{\\html@mathml{" + "T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX" + "}{TeX}}"); // \DeclareRobustCommand{\LaTeX}{L\kern-.36em%
  13714. // {\sbox\z@ T%
  13715. // \vbox to\ht\z@{\hbox{\check@mathfonts
  13716. // \fontsize\sf@size\z@
  13717. // \math@fontsfalse\selectfont
  13718. // A}%
  13719. // \vss}%
  13720. // }%
  13721. // \kern-.15em%
  13722. // \TeX}
  13723. // This code aligns the top of the A with the T (from the perspective of TeX's
  13724. // boxes, though visually the A appears to extend above slightly).
  13725. // We compute the corresponding \raisebox when A is rendered in \normalsize
  13726. // \scriptstyle, which has a scale factor of 0.7 (see Options.js).
  13727. var latexRaiseA = makeEm(fontMetricsData['Main-Regular']["T".charCodeAt(0)][1] - 0.7 * fontMetricsData['Main-Regular']["A".charCodeAt(0)][1]);
  13728. defineMacro("\\LaTeX", "\\textrm{\\html@mathml{" + ("L\\kern-.36em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{LaTeX}}"); // New KaTeX logo based on tweaking LaTeX logo
  13729. defineMacro("\\KaTeX", "\\textrm{\\html@mathml{" + ("K\\kern-.17em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{KaTeX}}"); // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
  13730. // \def\@hspace#1{\hskip #1\relax}
  13731. // \def\@hspacer#1{\vrule \@width\z@\nobreak
  13732. // \hskip #1\hskip \z@skip}
  13733. defineMacro("\\hspace", "\\@ifstar\\@hspacer\\@hspace");
  13734. defineMacro("\\@hspace", "\\hskip #1\\relax");
  13735. defineMacro("\\@hspacer", "\\rule{0pt}{0pt}\\hskip #1\\relax"); //////////////////////////////////////////////////////////////////////
  13736. // mathtools.sty
  13737. //\providecommand\ordinarycolon{:}
  13738. defineMacro("\\ordinarycolon", ":"); //\def\vcentcolon{\mathrel{\mathop\ordinarycolon}}
  13739. //TODO(edemaine): Not yet centered. Fix via \raisebox or #726
  13740. defineMacro("\\vcentcolon", "\\mathrel{\\mathop\\ordinarycolon}"); // \providecommand*\dblcolon{\vcentcolon\mathrel{\mkern-.9mu}\vcentcolon}
  13741. defineMacro("\\dblcolon", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}" + "{\\mathop{\\char\"2237}}"); // \providecommand*\coloneqq{\vcentcolon\mathrel{\mkern-1.2mu}=}
  13742. defineMacro("\\coloneqq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2254}}"); // ≔
  13743. // \providecommand*\Coloneqq{\dblcolon\mathrel{\mkern-1.2mu}=}
  13744. defineMacro("\\Coloneqq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2237\\char\"3d}}"); // \providecommand*\coloneq{\vcentcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
  13745. defineMacro("\\coloneq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"3a\\char\"2212}}"); // \providecommand*\Coloneq{\dblcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
  13746. defineMacro("\\Coloneq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"2237\\char\"2212}}"); // \providecommand*\eqqcolon{=\mathrel{\mkern-1.2mu}\vcentcolon}
  13747. defineMacro("\\eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2255}}"); // ≕
  13748. // \providecommand*\Eqqcolon{=\mathrel{\mkern-1.2mu}\dblcolon}
  13749. defineMacro("\\Eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"3d\\char\"2237}}"); // \providecommand*\eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\vcentcolon}
  13750. defineMacro("\\eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2239}}"); // \providecommand*\Eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\dblcolon}
  13751. defineMacro("\\Eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"2212\\char\"2237}}"); // \providecommand*\colonapprox{\vcentcolon\mathrel{\mkern-1.2mu}\approx}
  13752. defineMacro("\\colonapprox", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"3a\\char\"2248}}"); // \providecommand*\Colonapprox{\dblcolon\mathrel{\mkern-1.2mu}\approx}
  13753. defineMacro("\\Colonapprox", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"2237\\char\"2248}}"); // \providecommand*\colonsim{\vcentcolon\mathrel{\mkern-1.2mu}\sim}
  13754. defineMacro("\\colonsim", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"3a\\char\"223c}}"); // \providecommand*\Colonsim{\dblcolon\mathrel{\mkern-1.2mu}\sim}
  13755. defineMacro("\\Colonsim", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"2237\\char\"223c}}"); // Some Unicode characters are implemented with macros to mathtools functions.
  13756. defineMacro("\u2237", "\\dblcolon"); // ::
  13757. defineMacro("\u2239", "\\eqcolon"); // -:
  13758. defineMacro("\u2254", "\\coloneqq"); // :=
  13759. defineMacro("\u2255", "\\eqqcolon"); // =:
  13760. defineMacro("\u2A74", "\\Coloneqq"); // ::=
  13761. //////////////////////////////////////////////////////////////////////
  13762. // colonequals.sty
  13763. // Alternate names for mathtools's macros:
  13764. defineMacro("\\ratio", "\\vcentcolon");
  13765. defineMacro("\\coloncolon", "\\dblcolon");
  13766. defineMacro("\\colonequals", "\\coloneqq");
  13767. defineMacro("\\coloncolonequals", "\\Coloneqq");
  13768. defineMacro("\\equalscolon", "\\eqqcolon");
  13769. defineMacro("\\equalscoloncolon", "\\Eqqcolon");
  13770. defineMacro("\\colonminus", "\\coloneq");
  13771. defineMacro("\\coloncolonminus", "\\Coloneq");
  13772. defineMacro("\\minuscolon", "\\eqcolon");
  13773. defineMacro("\\minuscoloncolon", "\\Eqcolon"); // \colonapprox name is same in mathtools and colonequals.
  13774. defineMacro("\\coloncolonapprox", "\\Colonapprox"); // \colonsim name is same in mathtools and colonequals.
  13775. defineMacro("\\coloncolonsim", "\\Colonsim"); // Additional macros, implemented by analogy with mathtools definitions:
  13776. defineMacro("\\simcolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
  13777. defineMacro("\\simcoloncolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}");
  13778. defineMacro("\\approxcolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
  13779. defineMacro("\\approxcoloncolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}"); // Present in newtxmath, pxfonts and txfonts
  13780. defineMacro("\\notni", "\\html@mathml{\\not\\ni}{\\mathrel{\\char`\u220C}}");
  13781. defineMacro("\\limsup", "\\DOTSB\\operatorname*{lim\\,sup}");
  13782. defineMacro("\\liminf", "\\DOTSB\\operatorname*{lim\\,inf}"); //////////////////////////////////////////////////////////////////////
  13783. // From amsopn.sty
  13784. defineMacro("\\injlim", "\\DOTSB\\operatorname*{inj\\,lim}");
  13785. defineMacro("\\projlim", "\\DOTSB\\operatorname*{proj\\,lim}");
  13786. defineMacro("\\varlimsup", "\\DOTSB\\operatorname*{\\overline{lim}}");
  13787. defineMacro("\\varliminf", "\\DOTSB\\operatorname*{\\underline{lim}}");
  13788. defineMacro("\\varinjlim", "\\DOTSB\\operatorname*{\\underrightarrow{lim}}");
  13789. defineMacro("\\varprojlim", "\\DOTSB\\operatorname*{\\underleftarrow{lim}}"); //////////////////////////////////////////////////////////////////////
  13790. // MathML alternates for KaTeX glyphs in the Unicode private area
  13791. defineMacro("\\gvertneqq", "\\html@mathml{\\@gvertneqq}{\u2269}");
  13792. defineMacro("\\lvertneqq", "\\html@mathml{\\@lvertneqq}{\u2268}");
  13793. defineMacro("\\ngeqq", "\\html@mathml{\\@ngeqq}{\u2271}");
  13794. defineMacro("\\ngeqslant", "\\html@mathml{\\@ngeqslant}{\u2271}");
  13795. defineMacro("\\nleqq", "\\html@mathml{\\@nleqq}{\u2270}");
  13796. defineMacro("\\nleqslant", "\\html@mathml{\\@nleqslant}{\u2270}");
  13797. defineMacro("\\nshortmid", "\\html@mathml{\\@nshortmid}{∤}");
  13798. defineMacro("\\nshortparallel", "\\html@mathml{\\@nshortparallel}{∦}");
  13799. defineMacro("\\nsubseteqq", "\\html@mathml{\\@nsubseteqq}{\u2288}");
  13800. defineMacro("\\nsupseteqq", "\\html@mathml{\\@nsupseteqq}{\u2289}");
  13801. defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
  13802. defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
  13803. defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
  13804. defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
  13805. defineMacro("\\imath", "\\html@mathml{\\@imath}{\u0131}");
  13806. defineMacro("\\jmath", "\\html@mathml{\\@jmath}{\u0237}"); //////////////////////////////////////////////////////////////////////
  13807. // stmaryrd and semantic
  13808. // The stmaryrd and semantic packages render the next four items by calling a
  13809. // glyph. Those glyphs do not exist in the KaTeX fonts. Hence the macros.
  13810. defineMacro("\\llbracket", "\\html@mathml{" + "\\mathopen{[\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u27e6}}");
  13811. defineMacro("\\rrbracket", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu]}}" + "{\\mathclose{\\char`\u27e7}}");
  13812. defineMacro("\u27e6", "\\llbracket"); // blackboard bold [
  13813. defineMacro("\u27e7", "\\rrbracket"); // blackboard bold ]
  13814. defineMacro("\\lBrace", "\\html@mathml{" + "\\mathopen{\\{\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u2983}}");
  13815. defineMacro("\\rBrace", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu\\}}}" + "{\\mathclose{\\char`\u2984}}");
  13816. defineMacro("\u2983", "\\lBrace"); // blackboard bold {
  13817. defineMacro("\u2984", "\\rBrace"); // blackboard bold }
  13818. // TODO: Create variable sized versions of the last two items. I believe that
  13819. // will require new font glyphs.
  13820. // The stmaryrd function `\minuso` provides a "Plimsoll" symbol that
  13821. // superimposes the characters \circ and \mathminus. Used in chemistry.
  13822. defineMacro("\\minuso", "\\mathbin{\\html@mathml{" + "{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}" + "{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}" + "{\\char`⦵}}");
  13823. defineMacro("⦵", "\\minuso"); //////////////////////////////////////////////////////////////////////
  13824. // texvc.sty
  13825. // The texvc package contains macros available in mediawiki pages.
  13826. // We omit the functions deprecated at
  13827. // https://en.wikipedia.org/wiki/Help:Displaying_a_formula#Deprecated_syntax
  13828. // We also omit texvc's \O, which conflicts with \text{\O}
  13829. defineMacro("\\darr", "\\downarrow");
  13830. defineMacro("\\dArr", "\\Downarrow");
  13831. defineMacro("\\Darr", "\\Downarrow");
  13832. defineMacro("\\lang", "\\langle");
  13833. defineMacro("\\rang", "\\rangle");
  13834. defineMacro("\\uarr", "\\uparrow");
  13835. defineMacro("\\uArr", "\\Uparrow");
  13836. defineMacro("\\Uarr", "\\Uparrow");
  13837. defineMacro("\\N", "\\mathbb{N}");
  13838. defineMacro("\\R", "\\mathbb{R}");
  13839. defineMacro("\\Z", "\\mathbb{Z}");
  13840. defineMacro("\\alef", "\\aleph");
  13841. defineMacro("\\alefsym", "\\aleph");
  13842. defineMacro("\\Alpha", "\\mathrm{A}");
  13843. defineMacro("\\Beta", "\\mathrm{B}");
  13844. defineMacro("\\bull", "\\bullet");
  13845. defineMacro("\\Chi", "\\mathrm{X}");
  13846. defineMacro("\\clubs", "\\clubsuit");
  13847. defineMacro("\\cnums", "\\mathbb{C}");
  13848. defineMacro("\\Complex", "\\mathbb{C}");
  13849. defineMacro("\\Dagger", "\\ddagger");
  13850. defineMacro("\\diamonds", "\\diamondsuit");
  13851. defineMacro("\\empty", "\\emptyset");
  13852. defineMacro("\\Epsilon", "\\mathrm{E}");
  13853. defineMacro("\\Eta", "\\mathrm{H}");
  13854. defineMacro("\\exist", "\\exists");
  13855. defineMacro("\\harr", "\\leftrightarrow");
  13856. defineMacro("\\hArr", "\\Leftrightarrow");
  13857. defineMacro("\\Harr", "\\Leftrightarrow");
  13858. defineMacro("\\hearts", "\\heartsuit");
  13859. defineMacro("\\image", "\\Im");
  13860. defineMacro("\\infin", "\\infty");
  13861. defineMacro("\\Iota", "\\mathrm{I}");
  13862. defineMacro("\\isin", "\\in");
  13863. defineMacro("\\Kappa", "\\mathrm{K}");
  13864. defineMacro("\\larr", "\\leftarrow");
  13865. defineMacro("\\lArr", "\\Leftarrow");
  13866. defineMacro("\\Larr", "\\Leftarrow");
  13867. defineMacro("\\lrarr", "\\leftrightarrow");
  13868. defineMacro("\\lrArr", "\\Leftrightarrow");
  13869. defineMacro("\\Lrarr", "\\Leftrightarrow");
  13870. defineMacro("\\Mu", "\\mathrm{M}");
  13871. defineMacro("\\natnums", "\\mathbb{N}");
  13872. defineMacro("\\Nu", "\\mathrm{N}");
  13873. defineMacro("\\Omicron", "\\mathrm{O}");
  13874. defineMacro("\\plusmn", "\\pm");
  13875. defineMacro("\\rarr", "\\rightarrow");
  13876. defineMacro("\\rArr", "\\Rightarrow");
  13877. defineMacro("\\Rarr", "\\Rightarrow");
  13878. defineMacro("\\real", "\\Re");
  13879. defineMacro("\\reals", "\\mathbb{R}");
  13880. defineMacro("\\Reals", "\\mathbb{R}");
  13881. defineMacro("\\Rho", "\\mathrm{P}");
  13882. defineMacro("\\sdot", "\\cdot");
  13883. defineMacro("\\sect", "\\S");
  13884. defineMacro("\\spades", "\\spadesuit");
  13885. defineMacro("\\sub", "\\subset");
  13886. defineMacro("\\sube", "\\subseteq");
  13887. defineMacro("\\supe", "\\supseteq");
  13888. defineMacro("\\Tau", "\\mathrm{T}");
  13889. defineMacro("\\thetasym", "\\vartheta"); // TODO: defineMacro("\\varcoppa", "\\\mbox{\\coppa}");
  13890. defineMacro("\\weierp", "\\wp");
  13891. defineMacro("\\Zeta", "\\mathrm{Z}"); //////////////////////////////////////////////////////////////////////
  13892. // statmath.sty
  13893. // https://ctan.math.illinois.edu/macros/latex/contrib/statmath/statmath.pdf
  13894. defineMacro("\\argmin", "\\DOTSB\\operatorname*{arg\\,min}");
  13895. defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
  13896. defineMacro("\\plim", "\\DOTSB\\mathop{\\operatorname{plim}}\\limits"); //////////////////////////////////////////////////////////////////////
  13897. // braket.sty
  13898. // http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
  13899. defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
  13900. defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
  13901. defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
  13902. defineMacro("\\Bra", "\\left\\langle#1\\right|");
  13903. defineMacro("\\Ket", "\\left|#1\\right\\rangle");
  13904. var braketHelper = one => context => {
  13905. var left = context.consumeArg().tokens;
  13906. var middle = context.consumeArg().tokens;
  13907. var middleDouble = context.consumeArg().tokens;
  13908. var right = context.consumeArg().tokens;
  13909. var oldMiddle = context.macros.get("|");
  13910. var oldMiddleDouble = context.macros.get("\\|");
  13911. context.macros.beginGroup();
  13912. var midMacro = double => context => {
  13913. if (one) {
  13914. // Only modify the first instance of | or \|
  13915. context.macros.set("|", oldMiddle);
  13916. if (middleDouble.length) {
  13917. context.macros.set("\\|", oldMiddleDouble);
  13918. }
  13919. }
  13920. var doubled = double;
  13921. if (!double && middleDouble.length) {
  13922. // Mimic \@ifnextchar
  13923. var nextToken = context.future();
  13924. if (nextToken.text === "|") {
  13925. context.popToken();
  13926. doubled = true;
  13927. }
  13928. }
  13929. return {
  13930. tokens: doubled ? middleDouble : middle,
  13931. numArgs: 0
  13932. };
  13933. };
  13934. context.macros.set("|", midMacro(false));
  13935. if (middleDouble.length) {
  13936. context.macros.set("\\|", midMacro(true));
  13937. }
  13938. var arg = context.consumeArg().tokens;
  13939. var expanded = context.expandTokens([...right, ...arg, ...left // reversed
  13940. ]);
  13941. context.macros.endGroup();
  13942. return {
  13943. tokens: expanded.reverse(),
  13944. numArgs: 0
  13945. };
  13946. };
  13947. defineMacro("\\bra@ket", braketHelper(false));
  13948. defineMacro("\\bra@set", braketHelper(true));
  13949. defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" + "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
  13950. defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" + "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
  13951. defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}"); // has no support for special || or \|
  13952. //////////////////////////////////////////////////////////////////////
  13953. // actuarialangle.dtx
  13954. defineMacro("\\angln", "{\\angl n}"); // Custom Khan Academy colors, should be moved to an optional package
  13955. defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
  13956. defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
  13957. defineMacro("\\pink", "\\textcolor{##ff00af}{#1}");
  13958. defineMacro("\\red", "\\textcolor{##df0030}{#1}");
  13959. defineMacro("\\green", "\\textcolor{##28ae7b}{#1}");
  13960. defineMacro("\\gray", "\\textcolor{gray}{#1}");
  13961. defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}");
  13962. defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}");
  13963. defineMacro("\\blueB", "\\textcolor{##80f6ff}{#1}");
  13964. defineMacro("\\blueC", "\\textcolor{##63d9ea}{#1}");
  13965. defineMacro("\\blueD", "\\textcolor{##11accd}{#1}");
  13966. defineMacro("\\blueE", "\\textcolor{##0c7f99}{#1}");
  13967. defineMacro("\\tealA", "\\textcolor{##94fff5}{#1}");
  13968. defineMacro("\\tealB", "\\textcolor{##26edd5}{#1}");
  13969. defineMacro("\\tealC", "\\textcolor{##01d1c1}{#1}");
  13970. defineMacro("\\tealD", "\\textcolor{##01a995}{#1}");
  13971. defineMacro("\\tealE", "\\textcolor{##208170}{#1}");
  13972. defineMacro("\\greenA", "\\textcolor{##b6ffb0}{#1}");
  13973. defineMacro("\\greenB", "\\textcolor{##8af281}{#1}");
  13974. defineMacro("\\greenC", "\\textcolor{##74cf70}{#1}");
  13975. defineMacro("\\greenD", "\\textcolor{##1fab54}{#1}");
  13976. defineMacro("\\greenE", "\\textcolor{##0d923f}{#1}");
  13977. defineMacro("\\goldA", "\\textcolor{##ffd0a9}{#1}");
  13978. defineMacro("\\goldB", "\\textcolor{##ffbb71}{#1}");
  13979. defineMacro("\\goldC", "\\textcolor{##ff9c39}{#1}");
  13980. defineMacro("\\goldD", "\\textcolor{##e07d10}{#1}");
  13981. defineMacro("\\goldE", "\\textcolor{##a75a05}{#1}");
  13982. defineMacro("\\redA", "\\textcolor{##fca9a9}{#1}");
  13983. defineMacro("\\redB", "\\textcolor{##ff8482}{#1}");
  13984. defineMacro("\\redC", "\\textcolor{##f9685d}{#1}");
  13985. defineMacro("\\redD", "\\textcolor{##e84d39}{#1}");
  13986. defineMacro("\\redE", "\\textcolor{##bc2612}{#1}");
  13987. defineMacro("\\maroonA", "\\textcolor{##ffbde0}{#1}");
  13988. defineMacro("\\maroonB", "\\textcolor{##ff92c6}{#1}");
  13989. defineMacro("\\maroonC", "\\textcolor{##ed5fa6}{#1}");
  13990. defineMacro("\\maroonD", "\\textcolor{##ca337c}{#1}");
  13991. defineMacro("\\maroonE", "\\textcolor{##9e034e}{#1}");
  13992. defineMacro("\\purpleA", "\\textcolor{##ddd7ff}{#1}");
  13993. defineMacro("\\purpleB", "\\textcolor{##c6b9fc}{#1}");
  13994. defineMacro("\\purpleC", "\\textcolor{##aa87ff}{#1}");
  13995. defineMacro("\\purpleD", "\\textcolor{##7854ab}{#1}");
  13996. defineMacro("\\purpleE", "\\textcolor{##543b78}{#1}");
  13997. defineMacro("\\mintA", "\\textcolor{##f5f9e8}{#1}");
  13998. defineMacro("\\mintB", "\\textcolor{##edf2df}{#1}");
  13999. defineMacro("\\mintC", "\\textcolor{##e0e5cc}{#1}");
  14000. defineMacro("\\grayA", "\\textcolor{##f6f7f7}{#1}");
  14001. defineMacro("\\grayB", "\\textcolor{##f0f1f2}{#1}");
  14002. defineMacro("\\grayC", "\\textcolor{##e3e5e6}{#1}");
  14003. defineMacro("\\grayD", "\\textcolor{##d6d8da}{#1}");
  14004. defineMacro("\\grayE", "\\textcolor{##babec2}{#1}");
  14005. defineMacro("\\grayF", "\\textcolor{##888d93}{#1}");
  14006. defineMacro("\\grayG", "\\textcolor{##626569}{#1}");
  14007. defineMacro("\\grayH", "\\textcolor{##3b3e40}{#1}");
  14008. defineMacro("\\grayI", "\\textcolor{##21242c}{#1}");
  14009. defineMacro("\\kaBlue", "\\textcolor{##314453}{#1}");
  14010. defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
  14011. /**
  14012. * This file contains the “gullet” where macros are expanded
  14013. * until only non-macro tokens remain.
  14014. */
  14015. // List of commands that act like macros but aren't defined as a macro,
  14016. // function, or symbol. Used in `isDefined`.
  14017. var implicitCommands = {
  14018. "^": true,
  14019. // Parser.js
  14020. "_": true,
  14021. // Parser.js
  14022. "\\limits": true,
  14023. // Parser.js
  14024. "\\nolimits": true // Parser.js
  14025. };
  14026. class MacroExpander {
  14027. constructor(input, settings, mode) {
  14028. this.settings = void 0;
  14029. this.expansionCount = void 0;
  14030. this.lexer = void 0;
  14031. this.macros = void 0;
  14032. this.stack = void 0;
  14033. this.mode = void 0;
  14034. this.settings = settings;
  14035. this.expansionCount = 0;
  14036. this.feed(input); // Make new global namespace
  14037. this.macros = new Namespace(macros, settings.macros);
  14038. this.mode = mode;
  14039. this.stack = []; // contains tokens in REVERSE order
  14040. }
  14041. /**
  14042. * Feed a new input string to the same MacroExpander
  14043. * (with existing macros etc.).
  14044. */
  14045. feed(input) {
  14046. this.lexer = new Lexer(input, this.settings);
  14047. }
  14048. /**
  14049. * Switches between "text" and "math" modes.
  14050. */
  14051. switchMode(newMode) {
  14052. this.mode = newMode;
  14053. }
  14054. /**
  14055. * Start a new group nesting within all namespaces.
  14056. */
  14057. beginGroup() {
  14058. this.macros.beginGroup();
  14059. }
  14060. /**
  14061. * End current group nesting within all namespaces.
  14062. */
  14063. endGroup() {
  14064. this.macros.endGroup();
  14065. }
  14066. /**
  14067. * Ends all currently nested groups (if any), restoring values before the
  14068. * groups began. Useful in case of an error in the middle of parsing.
  14069. */
  14070. endGroups() {
  14071. this.macros.endGroups();
  14072. }
  14073. /**
  14074. * Returns the topmost token on the stack, without expanding it.
  14075. * Similar in behavior to TeX's `\futurelet`.
  14076. */
  14077. future() {
  14078. if (this.stack.length === 0) {
  14079. this.pushToken(this.lexer.lex());
  14080. }
  14081. return this.stack[this.stack.length - 1];
  14082. }
  14083. /**
  14084. * Remove and return the next unexpanded token.
  14085. */
  14086. popToken() {
  14087. this.future(); // ensure non-empty stack
  14088. return this.stack.pop();
  14089. }
  14090. /**
  14091. * Add a given token to the token stack. In particular, this get be used
  14092. * to put back a token returned from one of the other methods.
  14093. */
  14094. pushToken(token) {
  14095. this.stack.push(token);
  14096. }
  14097. /**
  14098. * Append an array of tokens to the token stack.
  14099. */
  14100. pushTokens(tokens) {
  14101. this.stack.push(...tokens);
  14102. }
  14103. /**
  14104. * Find an macro argument without expanding tokens and append the array of
  14105. * tokens to the token stack. Uses Token as a container for the result.
  14106. */
  14107. scanArgument(isOptional) {
  14108. var start;
  14109. var end;
  14110. var tokens;
  14111. if (isOptional) {
  14112. this.consumeSpaces(); // \@ifnextchar gobbles any space following it
  14113. if (this.future().text !== "[") {
  14114. return null;
  14115. }
  14116. start = this.popToken(); // don't include [ in tokens
  14117. ({
  14118. tokens,
  14119. end
  14120. } = this.consumeArg(["]"]));
  14121. } else {
  14122. ({
  14123. tokens,
  14124. start,
  14125. end
  14126. } = this.consumeArg());
  14127. } // indicate the end of an argument
  14128. this.pushToken(new Token("EOF", end.loc));
  14129. this.pushTokens(tokens);
  14130. return start.range(end, "");
  14131. }
  14132. /**
  14133. * Consume all following space tokens, without expansion.
  14134. */
  14135. consumeSpaces() {
  14136. for (;;) {
  14137. var token = this.future();
  14138. if (token.text === " ") {
  14139. this.stack.pop();
  14140. } else {
  14141. break;
  14142. }
  14143. }
  14144. }
  14145. /**
  14146. * Consume an argument from the token stream, and return the resulting array
  14147. * of tokens and start/end token.
  14148. */
  14149. consumeArg(delims) {
  14150. // The argument for a delimited parameter is the shortest (possibly
  14151. // empty) sequence of tokens with properly nested {...} groups that is
  14152. // followed ... by this particular list of non-parameter tokens.
  14153. // The argument for an undelimited parameter is the next nonblank
  14154. // token, unless that token is ‘{’, when the argument will be the
  14155. // entire {...} group that follows.
  14156. var tokens = [];
  14157. var isDelimited = delims && delims.length > 0;
  14158. if (!isDelimited) {
  14159. // Ignore spaces between arguments. As the TeXbook says:
  14160. // "After you have said ‘\def\row#1#2{...}’, you are allowed to
  14161. // put spaces between the arguments (e.g., ‘\row x n’), because
  14162. // TeX doesn’t use single spaces as undelimited arguments."
  14163. this.consumeSpaces();
  14164. }
  14165. var start = this.future();
  14166. var tok;
  14167. var depth = 0;
  14168. var match = 0;
  14169. do {
  14170. tok = this.popToken();
  14171. tokens.push(tok);
  14172. if (tok.text === "{") {
  14173. ++depth;
  14174. } else if (tok.text === "}") {
  14175. --depth;
  14176. if (depth === -1) {
  14177. throw new ParseError("Extra }", tok);
  14178. }
  14179. } else if (tok.text === "EOF") {
  14180. throw new ParseError("Unexpected end of input in a macro argument" + ", expected '" + (delims && isDelimited ? delims[match] : "}") + "'", tok);
  14181. }
  14182. if (delims && isDelimited) {
  14183. if ((depth === 0 || depth === 1 && delims[match] === "{") && tok.text === delims[match]) {
  14184. ++match;
  14185. if (match === delims.length) {
  14186. // don't include delims in tokens
  14187. tokens.splice(-match, match);
  14188. break;
  14189. }
  14190. } else {
  14191. match = 0;
  14192. }
  14193. }
  14194. } while (depth !== 0 || isDelimited); // If the argument found ... has the form ‘{<nested tokens>}’,
  14195. // ... the outermost braces enclosing the argument are removed
  14196. if (start.text === "{" && tokens[tokens.length - 1].text === "}") {
  14197. tokens.pop();
  14198. tokens.shift();
  14199. }
  14200. tokens.reverse(); // to fit in with stack order
  14201. return {
  14202. tokens,
  14203. start,
  14204. end: tok
  14205. };
  14206. }
  14207. /**
  14208. * Consume the specified number of (delimited) arguments from the token
  14209. * stream and return the resulting array of arguments.
  14210. */
  14211. consumeArgs(numArgs, delimiters) {
  14212. if (delimiters) {
  14213. if (delimiters.length !== numArgs + 1) {
  14214. throw new ParseError("The length of delimiters doesn't match the number of args!");
  14215. }
  14216. var delims = delimiters[0];
  14217. for (var i = 0; i < delims.length; i++) {
  14218. var tok = this.popToken();
  14219. if (delims[i] !== tok.text) {
  14220. throw new ParseError("Use of the macro doesn't match its definition", tok);
  14221. }
  14222. }
  14223. }
  14224. var args = [];
  14225. for (var _i = 0; _i < numArgs; _i++) {
  14226. args.push(this.consumeArg(delimiters && delimiters[_i + 1]).tokens);
  14227. }
  14228. return args;
  14229. }
  14230. /**
  14231. * Expand the next token only once if possible.
  14232. *
  14233. * If the token is expanded, the resulting tokens will be pushed onto
  14234. * the stack in reverse order and will be returned as an array,
  14235. * also in reverse order.
  14236. *
  14237. * If not, the next token will be returned without removing it
  14238. * from the stack. This case can be detected by a `Token` return value
  14239. * instead of an `Array` return value.
  14240. *
  14241. * In either case, the next token will be on the top of the stack,
  14242. * or the stack will be empty.
  14243. *
  14244. * Used to implement `expandAfterFuture` and `expandNextToken`.
  14245. *
  14246. * If expandableOnly, only expandable tokens are expanded and
  14247. * an undefined control sequence results in an error.
  14248. */
  14249. expandOnce(expandableOnly) {
  14250. var topToken = this.popToken();
  14251. var name = topToken.text;
  14252. var expansion = !topToken.noexpand ? this._getExpansion(name) : null;
  14253. if (expansion == null || expandableOnly && expansion.unexpandable) {
  14254. if (expandableOnly && expansion == null && name[0] === "\\" && !this.isDefined(name)) {
  14255. throw new ParseError("Undefined control sequence: " + name);
  14256. }
  14257. this.pushToken(topToken);
  14258. return topToken;
  14259. }
  14260. this.expansionCount++;
  14261. if (this.expansionCount > this.settings.maxExpand) {
  14262. throw new ParseError("Too many expansions: infinite loop or " + "need to increase maxExpand setting");
  14263. }
  14264. var tokens = expansion.tokens;
  14265. var args = this.consumeArgs(expansion.numArgs, expansion.delimiters);
  14266. if (expansion.numArgs) {
  14267. // paste arguments in place of the placeholders
  14268. tokens = tokens.slice(); // make a shallow copy
  14269. for (var i = tokens.length - 1; i >= 0; --i) {
  14270. var tok = tokens[i];
  14271. if (tok.text === "#") {
  14272. if (i === 0) {
  14273. throw new ParseError("Incomplete placeholder at end of macro body", tok);
  14274. }
  14275. tok = tokens[--i]; // next token on stack
  14276. if (tok.text === "#") {
  14277. // ## → #
  14278. tokens.splice(i + 1, 1); // drop first #
  14279. } else if (/^[1-9]$/.test(tok.text)) {
  14280. // replace the placeholder with the indicated argument
  14281. tokens.splice(i, 2, ...args[+tok.text - 1]);
  14282. } else {
  14283. throw new ParseError("Not a valid argument number", tok);
  14284. }
  14285. }
  14286. }
  14287. } // Concatenate expansion onto top of stack.
  14288. this.pushTokens(tokens);
  14289. return tokens;
  14290. }
  14291. /**
  14292. * Expand the next token only once (if possible), and return the resulting
  14293. * top token on the stack (without removing anything from the stack).
  14294. * Similar in behavior to TeX's `\expandafter\futurelet`.
  14295. * Equivalent to expandOnce() followed by future().
  14296. */
  14297. expandAfterFuture() {
  14298. this.expandOnce();
  14299. return this.future();
  14300. }
  14301. /**
  14302. * Recursively expand first token, then return first non-expandable token.
  14303. */
  14304. expandNextToken() {
  14305. for (;;) {
  14306. var expanded = this.expandOnce(); // expandOnce returns Token if and only if it's fully expanded.
  14307. if (expanded instanceof Token) {
  14308. // the token after \noexpand is interpreted as if its meaning
  14309. // were ‘\relax’
  14310. if (expanded.treatAsRelax) {
  14311. expanded.text = "\\relax";
  14312. }
  14313. return this.stack.pop(); // === expanded
  14314. }
  14315. } // Flow unable to figure out that this pathway is impossible.
  14316. // https://github.com/facebook/flow/issues/4808
  14317. throw new Error(); // eslint-disable-line no-unreachable
  14318. }
  14319. /**
  14320. * Fully expand the given macro name and return the resulting list of
  14321. * tokens, or return `undefined` if no such macro is defined.
  14322. */
  14323. expandMacro(name) {
  14324. return this.macros.has(name) ? this.expandTokens([new Token(name)]) : undefined;
  14325. }
  14326. /**
  14327. * Fully expand the given token stream and return the resulting list of
  14328. * tokens. Note that the input tokens are in reverse order, but the
  14329. * output tokens are in forward order.
  14330. */
  14331. expandTokens(tokens) {
  14332. var output = [];
  14333. var oldStackLength = this.stack.length;
  14334. this.pushTokens(tokens);
  14335. while (this.stack.length > oldStackLength) {
  14336. var expanded = this.expandOnce(true); // expand only expandable tokens
  14337. // expandOnce returns Token if and only if it's fully expanded.
  14338. if (expanded instanceof Token) {
  14339. if (expanded.treatAsRelax) {
  14340. // the expansion of \noexpand is the token itself
  14341. expanded.noexpand = false;
  14342. expanded.treatAsRelax = false;
  14343. }
  14344. output.push(this.stack.pop());
  14345. }
  14346. }
  14347. return output;
  14348. }
  14349. /**
  14350. * Fully expand the given macro name and return the result as a string,
  14351. * or return `undefined` if no such macro is defined.
  14352. */
  14353. expandMacroAsText(name) {
  14354. var tokens = this.expandMacro(name);
  14355. if (tokens) {
  14356. return tokens.map(token => token.text).join("");
  14357. } else {
  14358. return tokens;
  14359. }
  14360. }
  14361. /**
  14362. * Returns the expanded macro as a reversed array of tokens and a macro
  14363. * argument count. Or returns `null` if no such macro.
  14364. */
  14365. _getExpansion(name) {
  14366. var definition = this.macros.get(name);
  14367. if (definition == null) {
  14368. // mainly checking for undefined here
  14369. return definition;
  14370. } // If a single character has an associated catcode other than 13
  14371. // (active character), then don't expand it.
  14372. if (name.length === 1) {
  14373. var catcode = this.lexer.catcodes[name];
  14374. if (catcode != null && catcode !== 13) {
  14375. return;
  14376. }
  14377. }
  14378. var expansion = typeof definition === "function" ? definition(this) : definition;
  14379. if (typeof expansion === "string") {
  14380. var numArgs = 0;
  14381. if (expansion.indexOf("#") !== -1) {
  14382. var stripped = expansion.replace(/##/g, "");
  14383. while (stripped.indexOf("#" + (numArgs + 1)) !== -1) {
  14384. ++numArgs;
  14385. }
  14386. }
  14387. var bodyLexer = new Lexer(expansion, this.settings);
  14388. var tokens = [];
  14389. var tok = bodyLexer.lex();
  14390. while (tok.text !== "EOF") {
  14391. tokens.push(tok);
  14392. tok = bodyLexer.lex();
  14393. }
  14394. tokens.reverse(); // to fit in with stack using push and pop
  14395. var expanded = {
  14396. tokens,
  14397. numArgs
  14398. };
  14399. return expanded;
  14400. }
  14401. return expansion;
  14402. }
  14403. /**
  14404. * Determine whether a command is currently "defined" (has some
  14405. * functionality), meaning that it's a macro (in the current group),
  14406. * a function, a symbol, or one of the special commands listed in
  14407. * `implicitCommands`.
  14408. */
  14409. isDefined(name) {
  14410. return this.macros.has(name) || functions.hasOwnProperty(name) || symbols.math.hasOwnProperty(name) || symbols.text.hasOwnProperty(name) || implicitCommands.hasOwnProperty(name);
  14411. }
  14412. /**
  14413. * Determine whether a command is expandable.
  14414. */
  14415. isExpandable(name) {
  14416. var macro = this.macros.get(name);
  14417. return macro != null ? typeof macro === "string" || typeof macro === "function" || !macro.unexpandable : functions.hasOwnProperty(name) && !functions[name].primitive;
  14418. }
  14419. }
  14420. // Helpers for Parser.js handling of Unicode (sub|super)script characters.
  14421. var unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
  14422. var uSubsAndSups = Object.freeze({
  14423. '₊': '+',
  14424. '₋': '-',
  14425. '₌': '=',
  14426. '₍': '(',
  14427. '₎': ')',
  14428. '₀': '0',
  14429. '₁': '1',
  14430. '₂': '2',
  14431. '₃': '3',
  14432. '₄': '4',
  14433. '₅': '5',
  14434. '₆': '6',
  14435. '₇': '7',
  14436. '₈': '8',
  14437. '₉': '9',
  14438. '\u2090': 'a',
  14439. '\u2091': 'e',
  14440. '\u2095': 'h',
  14441. '\u1D62': 'i',
  14442. '\u2C7C': 'j',
  14443. '\u2096': 'k',
  14444. '\u2097': 'l',
  14445. '\u2098': 'm',
  14446. '\u2099': 'n',
  14447. '\u2092': 'o',
  14448. '\u209A': 'p',
  14449. '\u1D63': 'r',
  14450. '\u209B': 's',
  14451. '\u209C': 't',
  14452. '\u1D64': 'u',
  14453. '\u1D65': 'v',
  14454. '\u2093': 'x',
  14455. '\u1D66': 'β',
  14456. '\u1D67': 'γ',
  14457. '\u1D68': 'ρ',
  14458. '\u1D69': '\u03d5',
  14459. '\u1D6A': 'χ',
  14460. '⁺': '+',
  14461. '⁻': '-',
  14462. '⁼': '=',
  14463. '⁽': '(',
  14464. '⁾': ')',
  14465. '⁰': '0',
  14466. '¹': '1',
  14467. '²': '2',
  14468. '³': '3',
  14469. '⁴': '4',
  14470. '⁵': '5',
  14471. '⁶': '6',
  14472. '⁷': '7',
  14473. '⁸': '8',
  14474. '⁹': '9',
  14475. '\u1D2C': 'A',
  14476. '\u1D2E': 'B',
  14477. '\u1D30': 'D',
  14478. '\u1D31': 'E',
  14479. '\u1D33': 'G',
  14480. '\u1D34': 'H',
  14481. '\u1D35': 'I',
  14482. '\u1D36': 'J',
  14483. '\u1D37': 'K',
  14484. '\u1D38': 'L',
  14485. '\u1D39': 'M',
  14486. '\u1D3A': 'N',
  14487. '\u1D3C': 'O',
  14488. '\u1D3E': 'P',
  14489. '\u1D3F': 'R',
  14490. '\u1D40': 'T',
  14491. '\u1D41': 'U',
  14492. '\u2C7D': 'V',
  14493. '\u1D42': 'W',
  14494. '\u1D43': 'a',
  14495. '\u1D47': 'b',
  14496. '\u1D9C': 'c',
  14497. '\u1D48': 'd',
  14498. '\u1D49': 'e',
  14499. '\u1DA0': 'f',
  14500. '\u1D4D': 'g',
  14501. '\u02B0': 'h',
  14502. '\u2071': 'i',
  14503. '\u02B2': 'j',
  14504. '\u1D4F': 'k',
  14505. '\u02E1': 'l',
  14506. '\u1D50': 'm',
  14507. '\u207F': 'n',
  14508. '\u1D52': 'o',
  14509. '\u1D56': 'p',
  14510. '\u02B3': 'r',
  14511. '\u02E2': 's',
  14512. '\u1D57': 't',
  14513. '\u1D58': 'u',
  14514. '\u1D5B': 'v',
  14515. '\u02B7': 'w',
  14516. '\u02E3': 'x',
  14517. '\u02B8': 'y',
  14518. '\u1DBB': 'z',
  14519. '\u1D5D': 'β',
  14520. '\u1D5E': 'γ',
  14521. '\u1D5F': 'δ',
  14522. '\u1D60': '\u03d5',
  14523. '\u1D61': 'χ',
  14524. '\u1DBF': 'θ'
  14525. });
  14526. /* eslint no-constant-condition:0 */
  14527. var unicodeAccents = {
  14528. "́": {
  14529. "text": "\\'",
  14530. "math": "\\acute"
  14531. },
  14532. "̀": {
  14533. "text": "\\`",
  14534. "math": "\\grave"
  14535. },
  14536. "̈": {
  14537. "text": "\\\"",
  14538. "math": "\\ddot"
  14539. },
  14540. "̃": {
  14541. "text": "\\~",
  14542. "math": "\\tilde"
  14543. },
  14544. "̄": {
  14545. "text": "\\=",
  14546. "math": "\\bar"
  14547. },
  14548. "̆": {
  14549. "text": "\\u",
  14550. "math": "\\breve"
  14551. },
  14552. "̌": {
  14553. "text": "\\v",
  14554. "math": "\\check"
  14555. },
  14556. "̂": {
  14557. "text": "\\^",
  14558. "math": "\\hat"
  14559. },
  14560. "̇": {
  14561. "text": "\\.",
  14562. "math": "\\dot"
  14563. },
  14564. "̊": {
  14565. "text": "\\r",
  14566. "math": "\\mathring"
  14567. },
  14568. "̋": {
  14569. "text": "\\H"
  14570. },
  14571. "̧": {
  14572. "text": "\\c"
  14573. }
  14574. };
  14575. var unicodeSymbols = {
  14576. "á": "á",
  14577. "à": "à",
  14578. "ä": "ä",
  14579. "ǟ": "ǟ",
  14580. "ã": "ã",
  14581. "ā": "ā",
  14582. "ă": "ă",
  14583. "ắ": "ắ",
  14584. "ằ": "ằ",
  14585. "ẵ": "ẵ",
  14586. "ǎ": "ǎ",
  14587. "â": "â",
  14588. "ấ": "ấ",
  14589. "ầ": "ầ",
  14590. "ẫ": "ẫ",
  14591. "ȧ": "ȧ",
  14592. "ǡ": "ǡ",
  14593. "å": "å",
  14594. "ǻ": "ǻ",
  14595. "ḃ": "ḃ",
  14596. "ć": "ć",
  14597. "ḉ": "ḉ",
  14598. "č": "č",
  14599. "ĉ": "ĉ",
  14600. "ċ": "ċ",
  14601. "ç": "ç",
  14602. "ď": "ď",
  14603. "ḋ": "ḋ",
  14604. "ḑ": "ḑ",
  14605. "é": "é",
  14606. "è": "è",
  14607. "ë": "ë",
  14608. "ẽ": "ẽ",
  14609. "ē": "ē",
  14610. "ḗ": "ḗ",
  14611. "ḕ": "ḕ",
  14612. "ĕ": "ĕ",
  14613. "ḝ": "ḝ",
  14614. "ě": "ě",
  14615. "ê": "ê",
  14616. "ế": "ế",
  14617. "ề": "ề",
  14618. "ễ": "ễ",
  14619. "ė": "ė",
  14620. "ȩ": "ȩ",
  14621. "ḟ": "ḟ",
  14622. "ǵ": "ǵ",
  14623. "ḡ": "ḡ",
  14624. "ğ": "ğ",
  14625. "ǧ": "ǧ",
  14626. "ĝ": "ĝ",
  14627. "ġ": "ġ",
  14628. "ģ": "ģ",
  14629. "ḧ": "ḧ",
  14630. "ȟ": "ȟ",
  14631. "ĥ": "ĥ",
  14632. "ḣ": "ḣ",
  14633. "ḩ": "ḩ",
  14634. "í": "í",
  14635. "ì": "ì",
  14636. "ï": "ï",
  14637. "ḯ": "ḯ",
  14638. "ĩ": "ĩ",
  14639. "ī": "ī",
  14640. "ĭ": "ĭ",
  14641. "ǐ": "ǐ",
  14642. "î": "î",
  14643. "ǰ": "ǰ",
  14644. "ĵ": "ĵ",
  14645. "ḱ": "ḱ",
  14646. "ǩ": "ǩ",
  14647. "ķ": "ķ",
  14648. "ĺ": "ĺ",
  14649. "ľ": "ľ",
  14650. "ļ": "ļ",
  14651. "ḿ": "ḿ",
  14652. "ṁ": "ṁ",
  14653. "ń": "ń",
  14654. "ǹ": "ǹ",
  14655. "ñ": "ñ",
  14656. "ň": "ň",
  14657. "ṅ": "ṅ",
  14658. "ņ": "ņ",
  14659. "ó": "ó",
  14660. "ò": "ò",
  14661. "ö": "ö",
  14662. "ȫ": "ȫ",
  14663. "õ": "õ",
  14664. "ṍ": "ṍ",
  14665. "ṏ": "ṏ",
  14666. "ȭ": "ȭ",
  14667. "ō": "ō",
  14668. "ṓ": "ṓ",
  14669. "ṑ": "ṑ",
  14670. "ŏ": "ŏ",
  14671. "ǒ": "ǒ",
  14672. "ô": "ô",
  14673. "ố": "ố",
  14674. "ồ": "ồ",
  14675. "ỗ": "ỗ",
  14676. "ȯ": "ȯ",
  14677. "ȱ": "ȱ",
  14678. "ő": "ő",
  14679. "ṕ": "ṕ",
  14680. "ṗ": "ṗ",
  14681. "ŕ": "ŕ",
  14682. "ř": "ř",
  14683. "ṙ": "ṙ",
  14684. "ŗ": "ŗ",
  14685. "ś": "ś",
  14686. "ṥ": "ṥ",
  14687. "š": "š",
  14688. "ṧ": "ṧ",
  14689. "ŝ": "ŝ",
  14690. "ṡ": "ṡ",
  14691. "ş": "ş",
  14692. "ẗ": "ẗ",
  14693. "ť": "ť",
  14694. "ṫ": "ṫ",
  14695. "ţ": "ţ",
  14696. "ú": "ú",
  14697. "ù": "ù",
  14698. "ü": "ü",
  14699. "ǘ": "ǘ",
  14700. "ǜ": "ǜ",
  14701. "ǖ": "ǖ",
  14702. "ǚ": "ǚ",
  14703. "ũ": "ũ",
  14704. "ṹ": "ṹ",
  14705. "ū": "ū",
  14706. "ṻ": "ṻ",
  14707. "ŭ": "ŭ",
  14708. "ǔ": "ǔ",
  14709. "û": "û",
  14710. "ů": "ů",
  14711. "ű": "ű",
  14712. "ṽ": "ṽ",
  14713. "ẃ": "ẃ",
  14714. "ẁ": "ẁ",
  14715. "ẅ": "ẅ",
  14716. "ŵ": "ŵ",
  14717. "ẇ": "ẇ",
  14718. "ẘ": "ẘ",
  14719. "ẍ": "ẍ",
  14720. "ẋ": "ẋ",
  14721. "ý": "ý",
  14722. "ỳ": "ỳ",
  14723. "ÿ": "ÿ",
  14724. "ỹ": "ỹ",
  14725. "ȳ": "ȳ",
  14726. "ŷ": "ŷ",
  14727. "ẏ": "ẏ",
  14728. "ẙ": "ẙ",
  14729. "ź": "ź",
  14730. "ž": "ž",
  14731. "ẑ": "ẑ",
  14732. "ż": "ż",
  14733. "Á": "Á",
  14734. "À": "À",
  14735. "Ä": "Ä",
  14736. "Ǟ": "Ǟ",
  14737. "Ã": "Ã",
  14738. "Ā": "Ā",
  14739. "Ă": "Ă",
  14740. "Ắ": "Ắ",
  14741. "Ằ": "Ằ",
  14742. "Ẵ": "Ẵ",
  14743. "Ǎ": "Ǎ",
  14744. "Â": "Â",
  14745. "Ấ": "Ấ",
  14746. "Ầ": "Ầ",
  14747. "Ẫ": "Ẫ",
  14748. "Ȧ": "Ȧ",
  14749. "Ǡ": "Ǡ",
  14750. "Å": "Å",
  14751. "Ǻ": "Ǻ",
  14752. "Ḃ": "Ḃ",
  14753. "Ć": "Ć",
  14754. "Ḉ": "Ḉ",
  14755. "Č": "Č",
  14756. "Ĉ": "Ĉ",
  14757. "Ċ": "Ċ",
  14758. "Ç": "Ç",
  14759. "Ď": "Ď",
  14760. "Ḋ": "Ḋ",
  14761. "Ḑ": "Ḑ",
  14762. "É": "É",
  14763. "È": "È",
  14764. "Ë": "Ë",
  14765. "Ẽ": "Ẽ",
  14766. "Ē": "Ē",
  14767. "Ḗ": "Ḗ",
  14768. "Ḕ": "Ḕ",
  14769. "Ĕ": "Ĕ",
  14770. "Ḝ": "Ḝ",
  14771. "Ě": "Ě",
  14772. "Ê": "Ê",
  14773. "Ế": "Ế",
  14774. "Ề": "Ề",
  14775. "Ễ": "Ễ",
  14776. "Ė": "Ė",
  14777. "Ȩ": "Ȩ",
  14778. "Ḟ": "Ḟ",
  14779. "Ǵ": "Ǵ",
  14780. "Ḡ": "Ḡ",
  14781. "Ğ": "Ğ",
  14782. "Ǧ": "Ǧ",
  14783. "Ĝ": "Ĝ",
  14784. "Ġ": "Ġ",
  14785. "Ģ": "Ģ",
  14786. "Ḧ": "Ḧ",
  14787. "Ȟ": "Ȟ",
  14788. "Ĥ": "Ĥ",
  14789. "Ḣ": "Ḣ",
  14790. "Ḩ": "Ḩ",
  14791. "Í": "Í",
  14792. "Ì": "Ì",
  14793. "Ï": "Ï",
  14794. "Ḯ": "Ḯ",
  14795. "Ĩ": "Ĩ",
  14796. "Ī": "Ī",
  14797. "Ĭ": "Ĭ",
  14798. "Ǐ": "Ǐ",
  14799. "Î": "Î",
  14800. "İ": "İ",
  14801. "Ĵ": "Ĵ",
  14802. "Ḱ": "Ḱ",
  14803. "Ǩ": "Ǩ",
  14804. "Ķ": "Ķ",
  14805. "Ĺ": "Ĺ",
  14806. "Ľ": "Ľ",
  14807. "Ļ": "Ļ",
  14808. "Ḿ": "Ḿ",
  14809. "Ṁ": "Ṁ",
  14810. "Ń": "Ń",
  14811. "Ǹ": "Ǹ",
  14812. "Ñ": "Ñ",
  14813. "Ň": "Ň",
  14814. "Ṅ": "Ṅ",
  14815. "Ņ": "Ņ",
  14816. "Ó": "Ó",
  14817. "Ò": "Ò",
  14818. "Ö": "Ö",
  14819. "Ȫ": "Ȫ",
  14820. "Õ": "Õ",
  14821. "Ṍ": "Ṍ",
  14822. "Ṏ": "Ṏ",
  14823. "Ȭ": "Ȭ",
  14824. "Ō": "Ō",
  14825. "Ṓ": "Ṓ",
  14826. "Ṑ": "Ṑ",
  14827. "Ŏ": "Ŏ",
  14828. "Ǒ": "Ǒ",
  14829. "Ô": "Ô",
  14830. "Ố": "Ố",
  14831. "Ồ": "Ồ",
  14832. "Ỗ": "Ỗ",
  14833. "Ȯ": "Ȯ",
  14834. "Ȱ": "Ȱ",
  14835. "Ő": "Ő",
  14836. "Ṕ": "Ṕ",
  14837. "Ṗ": "Ṗ",
  14838. "Ŕ": "Ŕ",
  14839. "Ř": "Ř",
  14840. "Ṙ": "Ṙ",
  14841. "Ŗ": "Ŗ",
  14842. "Ś": "Ś",
  14843. "Ṥ": "Ṥ",
  14844. "Š": "Š",
  14845. "Ṧ": "Ṧ",
  14846. "Ŝ": "Ŝ",
  14847. "Ṡ": "Ṡ",
  14848. "Ş": "Ş",
  14849. "Ť": "Ť",
  14850. "Ṫ": "Ṫ",
  14851. "Ţ": "Ţ",
  14852. "Ú": "Ú",
  14853. "Ù": "Ù",
  14854. "Ü": "Ü",
  14855. "Ǘ": "Ǘ",
  14856. "Ǜ": "Ǜ",
  14857. "Ǖ": "Ǖ",
  14858. "Ǚ": "Ǚ",
  14859. "Ũ": "Ũ",
  14860. "Ṹ": "Ṹ",
  14861. "Ū": "Ū",
  14862. "Ṻ": "Ṻ",
  14863. "Ŭ": "Ŭ",
  14864. "Ǔ": "Ǔ",
  14865. "Û": "Û",
  14866. "Ů": "Ů",
  14867. "Ű": "Ű",
  14868. "Ṽ": "Ṽ",
  14869. "Ẃ": "Ẃ",
  14870. "Ẁ": "Ẁ",
  14871. "Ẅ": "Ẅ",
  14872. "Ŵ": "Ŵ",
  14873. "Ẇ": "Ẇ",
  14874. "Ẍ": "Ẍ",
  14875. "Ẋ": "Ẋ",
  14876. "Ý": "Ý",
  14877. "Ỳ": "Ỳ",
  14878. "Ÿ": "Ÿ",
  14879. "Ỹ": "Ỹ",
  14880. "Ȳ": "Ȳ",
  14881. "Ŷ": "Ŷ",
  14882. "Ẏ": "Ẏ",
  14883. "Ź": "Ź",
  14884. "Ž": "Ž",
  14885. "Ẑ": "Ẑ",
  14886. "Ż": "Ż",
  14887. "ά": "ά",
  14888. "ὰ": "ὰ",
  14889. "ᾱ": "ᾱ",
  14890. "ᾰ": "ᾰ",
  14891. "έ": "έ",
  14892. "ὲ": "ὲ",
  14893. "ή": "ή",
  14894. "ὴ": "ὴ",
  14895. "ί": "ί",
  14896. "ὶ": "ὶ",
  14897. "ϊ": "ϊ",
  14898. "ΐ": "ΐ",
  14899. "ῒ": "ῒ",
  14900. "ῑ": "ῑ",
  14901. "ῐ": "ῐ",
  14902. "ό": "ό",
  14903. "ὸ": "ὸ",
  14904. "ύ": "ύ",
  14905. "ὺ": "ὺ",
  14906. "ϋ": "ϋ",
  14907. "ΰ": "ΰ",
  14908. "ῢ": "ῢ",
  14909. "ῡ": "ῡ",
  14910. "ῠ": "ῠ",
  14911. "ώ": "ώ",
  14912. "ὼ": "ὼ",
  14913. "Ύ": "Ύ",
  14914. "Ὺ": "Ὺ",
  14915. "Ϋ": "Ϋ",
  14916. "Ῡ": "Ῡ",
  14917. "Ῠ": "Ῠ",
  14918. "Ώ": "Ώ",
  14919. "Ὼ": "Ὼ"
  14920. };
  14921. /**
  14922. * This file contains the parser used to parse out a TeX expression from the
  14923. * input. Since TeX isn't context-free, standard parsers don't work particularly
  14924. * well.
  14925. *
  14926. * The strategy of this parser is as such:
  14927. *
  14928. * The main functions (the `.parse...` ones) take a position in the current
  14929. * parse string to parse tokens from. The lexer (found in Lexer.js, stored at
  14930. * this.gullet.lexer) also supports pulling out tokens at arbitrary places. When
  14931. * individual tokens are needed at a position, the lexer is called to pull out a
  14932. * token, which is then used.
  14933. *
  14934. * The parser has a property called "mode" indicating the mode that
  14935. * the parser is currently in. Currently it has to be one of "math" or
  14936. * "text", which denotes whether the current environment is a math-y
  14937. * one or a text-y one (e.g. inside \text). Currently, this serves to
  14938. * limit the functions which can be used in text mode.
  14939. *
  14940. * The main functions then return an object which contains the useful data that
  14941. * was parsed at its given point, and a new position at the end of the parsed
  14942. * data. The main functions can call each other and continue the parsing by
  14943. * using the returned position as a new starting point.
  14944. *
  14945. * There are also extra `.handle...` functions, which pull out some reused
  14946. * functionality into self-contained functions.
  14947. *
  14948. * The functions return ParseNodes.
  14949. */
  14950. class Parser {
  14951. constructor(input, settings) {
  14952. this.mode = void 0;
  14953. this.gullet = void 0;
  14954. this.settings = void 0;
  14955. this.leftrightDepth = void 0;
  14956. this.nextToken = void 0;
  14957. // Start in math mode
  14958. this.mode = "math"; // Create a new macro expander (gullet) and (indirectly via that) also a
  14959. // new lexer (mouth) for this parser (stomach, in the language of TeX)
  14960. this.gullet = new MacroExpander(input, settings, this.mode); // Store the settings for use in parsing
  14961. this.settings = settings; // Count leftright depth (for \middle errors)
  14962. this.leftrightDepth = 0;
  14963. }
  14964. /**
  14965. * Checks a result to make sure it has the right type, and throws an
  14966. * appropriate error otherwise.
  14967. */
  14968. expect(text, consume) {
  14969. if (consume === void 0) {
  14970. consume = true;
  14971. }
  14972. if (this.fetch().text !== text) {
  14973. throw new ParseError("Expected '" + text + "', got '" + this.fetch().text + "'", this.fetch());
  14974. }
  14975. if (consume) {
  14976. this.consume();
  14977. }
  14978. }
  14979. /**
  14980. * Discards the current lookahead token, considering it consumed.
  14981. */
  14982. consume() {
  14983. this.nextToken = null;
  14984. }
  14985. /**
  14986. * Return the current lookahead token, or if there isn't one (at the
  14987. * beginning, or if the previous lookahead token was consume()d),
  14988. * fetch the next token as the new lookahead token and return it.
  14989. */
  14990. fetch() {
  14991. if (this.nextToken == null) {
  14992. this.nextToken = this.gullet.expandNextToken();
  14993. }
  14994. return this.nextToken;
  14995. }
  14996. /**
  14997. * Switches between "text" and "math" modes.
  14998. */
  14999. switchMode(newMode) {
  15000. this.mode = newMode;
  15001. this.gullet.switchMode(newMode);
  15002. }
  15003. /**
  15004. * Main parsing function, which parses an entire input.
  15005. */
  15006. parse() {
  15007. if (!this.settings.globalGroup) {
  15008. // Create a group namespace for the math expression.
  15009. // (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
  15010. this.gullet.beginGroup();
  15011. } // Use old \color behavior (same as LaTeX's \textcolor) if requested.
  15012. // We do this within the group for the math expression, so it doesn't
  15013. // pollute settings.macros.
  15014. if (this.settings.colorIsTextColor) {
  15015. this.gullet.macros.set("\\color", "\\textcolor");
  15016. }
  15017. try {
  15018. // Try to parse the input
  15019. var parse = this.parseExpression(false); // If we succeeded, make sure there's an EOF at the end
  15020. this.expect("EOF"); // End the group namespace for the expression
  15021. if (!this.settings.globalGroup) {
  15022. this.gullet.endGroup();
  15023. }
  15024. return parse; // Close any leftover groups in case of a parse error.
  15025. } finally {
  15026. this.gullet.endGroups();
  15027. }
  15028. }
  15029. /**
  15030. * Fully parse a separate sequence of tokens as a separate job.
  15031. * Tokens should be specified in reverse order, as in a MacroDefinition.
  15032. */
  15033. subparse(tokens) {
  15034. // Save the next token from the current job.
  15035. var oldToken = this.nextToken;
  15036. this.consume(); // Run the new job, terminating it with an excess '}'
  15037. this.gullet.pushToken(new Token("}"));
  15038. this.gullet.pushTokens(tokens);
  15039. var parse = this.parseExpression(false);
  15040. this.expect("}"); // Restore the next token from the current job.
  15041. this.nextToken = oldToken;
  15042. return parse;
  15043. }
  15044. /**
  15045. * Parses an "expression", which is a list of atoms.
  15046. *
  15047. * `breakOnInfix`: Should the parsing stop when we hit infix nodes? This
  15048. * happens when functions have higher precendence han infix
  15049. * nodes in implicit parses.
  15050. *
  15051. * `breakOnTokenText`: The text of the token that the expression should end
  15052. * with, or `null` if something else should end the
  15053. * expression.
  15054. */
  15055. parseExpression(breakOnInfix, breakOnTokenText) {
  15056. var body = []; // Keep adding atoms to the body until we can't parse any more atoms (either
  15057. // we reached the end, a }, or a \right)
  15058. while (true) {
  15059. // Ignore spaces in math mode
  15060. if (this.mode === "math") {
  15061. this.consumeSpaces();
  15062. }
  15063. var lex = this.fetch();
  15064. if (Parser.endOfExpression.indexOf(lex.text) !== -1) {
  15065. break;
  15066. }
  15067. if (breakOnTokenText && lex.text === breakOnTokenText) {
  15068. break;
  15069. }
  15070. if (breakOnInfix && functions[lex.text] && functions[lex.text].infix) {
  15071. break;
  15072. }
  15073. var atom = this.parseAtom(breakOnTokenText);
  15074. if (!atom) {
  15075. break;
  15076. } else if (atom.type === "internal") {
  15077. continue;
  15078. }
  15079. body.push(atom);
  15080. }
  15081. if (this.mode === "text") {
  15082. this.formLigatures(body);
  15083. }
  15084. return this.handleInfixNodes(body);
  15085. }
  15086. /**
  15087. * Rewrites infix operators such as \over with corresponding commands such
  15088. * as \frac.
  15089. *
  15090. * There can only be one infix operator per group. If there's more than one
  15091. * then the expression is ambiguous. This can be resolved by adding {}.
  15092. */
  15093. handleInfixNodes(body) {
  15094. var overIndex = -1;
  15095. var funcName;
  15096. for (var i = 0; i < body.length; i++) {
  15097. if (body[i].type === "infix") {
  15098. if (overIndex !== -1) {
  15099. throw new ParseError("only one infix operator per group", body[i].token);
  15100. }
  15101. overIndex = i;
  15102. funcName = body[i].replaceWith;
  15103. }
  15104. }
  15105. if (overIndex !== -1 && funcName) {
  15106. var numerNode;
  15107. var denomNode;
  15108. var numerBody = body.slice(0, overIndex);
  15109. var denomBody = body.slice(overIndex + 1);
  15110. if (numerBody.length === 1 && numerBody[0].type === "ordgroup") {
  15111. numerNode = numerBody[0];
  15112. } else {
  15113. numerNode = {
  15114. type: "ordgroup",
  15115. mode: this.mode,
  15116. body: numerBody
  15117. };
  15118. }
  15119. if (denomBody.length === 1 && denomBody[0].type === "ordgroup") {
  15120. denomNode = denomBody[0];
  15121. } else {
  15122. denomNode = {
  15123. type: "ordgroup",
  15124. mode: this.mode,
  15125. body: denomBody
  15126. };
  15127. }
  15128. var node;
  15129. if (funcName === "\\\\abovefrac") {
  15130. node = this.callFunction(funcName, [numerNode, body[overIndex], denomNode], []);
  15131. } else {
  15132. node = this.callFunction(funcName, [numerNode, denomNode], []);
  15133. }
  15134. return [node];
  15135. } else {
  15136. return body;
  15137. }
  15138. }
  15139. /**
  15140. * Handle a subscript or superscript with nice errors.
  15141. */
  15142. handleSupSubscript(name // For error reporting.
  15143. ) {
  15144. var symbolToken = this.fetch();
  15145. var symbol = symbolToken.text;
  15146. this.consume();
  15147. this.consumeSpaces(); // ignore spaces before sup/subscript argument
  15148. var group = this.parseGroup(name);
  15149. if (!group) {
  15150. throw new ParseError("Expected group after '" + symbol + "'", symbolToken);
  15151. }
  15152. return group;
  15153. }
  15154. /**
  15155. * Converts the textual input of an unsupported command into a text node
  15156. * contained within a color node whose color is determined by errorColor
  15157. */
  15158. formatUnsupportedCmd(text) {
  15159. var textordArray = [];
  15160. for (var i = 0; i < text.length; i++) {
  15161. textordArray.push({
  15162. type: "textord",
  15163. mode: "text",
  15164. text: text[i]
  15165. });
  15166. }
  15167. var textNode = {
  15168. type: "text",
  15169. mode: this.mode,
  15170. body: textordArray
  15171. };
  15172. var colorNode = {
  15173. type: "color",
  15174. mode: this.mode,
  15175. color: this.settings.errorColor,
  15176. body: [textNode]
  15177. };
  15178. return colorNode;
  15179. }
  15180. /**
  15181. * Parses a group with optional super/subscripts.
  15182. */
  15183. parseAtom(breakOnTokenText) {
  15184. // The body of an atom is an implicit group, so that things like
  15185. // \left(x\right)^2 work correctly.
  15186. var base = this.parseGroup("atom", breakOnTokenText); // In text mode, we don't have superscripts or subscripts
  15187. if (this.mode === "text") {
  15188. return base;
  15189. } // Note that base may be empty (i.e. null) at this point.
  15190. var superscript;
  15191. var subscript;
  15192. while (true) {
  15193. // Guaranteed in math mode, so eat any spaces first.
  15194. this.consumeSpaces(); // Lex the first token
  15195. var lex = this.fetch();
  15196. if (lex.text === "\\limits" || lex.text === "\\nolimits") {
  15197. // We got a limit control
  15198. if (base && base.type === "op") {
  15199. var limits = lex.text === "\\limits";
  15200. base.limits = limits;
  15201. base.alwaysHandleSupSub = true;
  15202. } else if (base && base.type === "operatorname") {
  15203. if (base.alwaysHandleSupSub) {
  15204. base.limits = lex.text === "\\limits";
  15205. }
  15206. } else {
  15207. throw new ParseError("Limit controls must follow a math operator", lex);
  15208. }
  15209. this.consume();
  15210. } else if (lex.text === "^") {
  15211. // We got a superscript start
  15212. if (superscript) {
  15213. throw new ParseError("Double superscript", lex);
  15214. }
  15215. superscript = this.handleSupSubscript("superscript");
  15216. } else if (lex.text === "_") {
  15217. // We got a subscript start
  15218. if (subscript) {
  15219. throw new ParseError("Double subscript", lex);
  15220. }
  15221. subscript = this.handleSupSubscript("subscript");
  15222. } else if (lex.text === "'") {
  15223. // We got a prime
  15224. if (superscript) {
  15225. throw new ParseError("Double superscript", lex);
  15226. }
  15227. var prime = {
  15228. type: "textord",
  15229. mode: this.mode,
  15230. text: "\\prime"
  15231. }; // Many primes can be grouped together, so we handle this here
  15232. var primes = [prime];
  15233. this.consume(); // Keep lexing tokens until we get something that's not a prime
  15234. while (this.fetch().text === "'") {
  15235. // For each one, add another prime to the list
  15236. primes.push(prime);
  15237. this.consume();
  15238. } // If there's a superscript following the primes, combine that
  15239. // superscript in with the primes.
  15240. if (this.fetch().text === "^") {
  15241. primes.push(this.handleSupSubscript("superscript"));
  15242. } // Put everything into an ordgroup as the superscript
  15243. superscript = {
  15244. type: "ordgroup",
  15245. mode: this.mode,
  15246. body: primes
  15247. };
  15248. } else if (uSubsAndSups[lex.text]) {
  15249. // A Unicode subscript or superscript character.
  15250. // We treat these similarly to the unicode-math package.
  15251. // So we render a string of Unicode (sub|super)scripts the
  15252. // same as a (sub|super)script of regular characters.
  15253. var str = uSubsAndSups[lex.text];
  15254. var isSub = unicodeSubRegEx.test(lex.text);
  15255. this.consume(); // Continue fetching tokens to fill out the string.
  15256. while (true) {
  15257. var token = this.fetch().text;
  15258. if (!uSubsAndSups[token]) {
  15259. break;
  15260. }
  15261. if (unicodeSubRegEx.test(token) !== isSub) {
  15262. break;
  15263. }
  15264. this.consume();
  15265. str += uSubsAndSups[token];
  15266. } // Now create a (sub|super)script.
  15267. var body = new Parser(str, this.settings).parse();
  15268. if (isSub) {
  15269. subscript = {
  15270. type: "ordgroup",
  15271. mode: "math",
  15272. body
  15273. };
  15274. } else {
  15275. superscript = {
  15276. type: "ordgroup",
  15277. mode: "math",
  15278. body
  15279. };
  15280. }
  15281. } else {
  15282. // If it wasn't ^, _, or ', stop parsing super/subscripts
  15283. break;
  15284. }
  15285. } // Base must be set if superscript or subscript are set per logic above,
  15286. // but need to check here for type check to pass.
  15287. if (superscript || subscript) {
  15288. // If we got either a superscript or subscript, create a supsub
  15289. return {
  15290. type: "supsub",
  15291. mode: this.mode,
  15292. base: base,
  15293. sup: superscript,
  15294. sub: subscript
  15295. };
  15296. } else {
  15297. // Otherwise return the original body
  15298. return base;
  15299. }
  15300. }
  15301. /**
  15302. * Parses an entire function, including its base and all of its arguments.
  15303. */
  15304. parseFunction(breakOnTokenText, name // For determining its context
  15305. ) {
  15306. var token = this.fetch();
  15307. var func = token.text;
  15308. var funcData = functions[func];
  15309. if (!funcData) {
  15310. return null;
  15311. }
  15312. this.consume(); // consume command token
  15313. if (name && name !== "atom" && !funcData.allowedInArgument) {
  15314. throw new ParseError("Got function '" + func + "' with no arguments" + (name ? " as " + name : ""), token);
  15315. } else if (this.mode === "text" && !funcData.allowedInText) {
  15316. throw new ParseError("Can't use function '" + func + "' in text mode", token);
  15317. } else if (this.mode === "math" && funcData.allowedInMath === false) {
  15318. throw new ParseError("Can't use function '" + func + "' in math mode", token);
  15319. }
  15320. var {
  15321. args,
  15322. optArgs
  15323. } = this.parseArguments(func, funcData);
  15324. return this.callFunction(func, args, optArgs, token, breakOnTokenText);
  15325. }
  15326. /**
  15327. * Call a function handler with a suitable context and arguments.
  15328. */
  15329. callFunction(name, args, optArgs, token, breakOnTokenText) {
  15330. var context = {
  15331. funcName: name,
  15332. parser: this,
  15333. token,
  15334. breakOnTokenText
  15335. };
  15336. var func = functions[name];
  15337. if (func && func.handler) {
  15338. return func.handler(context, args, optArgs);
  15339. } else {
  15340. throw new ParseError("No function handler for " + name);
  15341. }
  15342. }
  15343. /**
  15344. * Parses the arguments of a function or environment
  15345. */
  15346. parseArguments(func, // Should look like "\name" or "\begin{name}".
  15347. funcData) {
  15348. var totalArgs = funcData.numArgs + funcData.numOptionalArgs;
  15349. if (totalArgs === 0) {
  15350. return {
  15351. args: [],
  15352. optArgs: []
  15353. };
  15354. }
  15355. var args = [];
  15356. var optArgs = [];
  15357. for (var i = 0; i < totalArgs; i++) {
  15358. var argType = funcData.argTypes && funcData.argTypes[i];
  15359. var isOptional = i < funcData.numOptionalArgs;
  15360. if (funcData.primitive && argType == null || // \sqrt expands into primitive if optional argument doesn't exist
  15361. funcData.type === "sqrt" && i === 1 && optArgs[0] == null) {
  15362. argType = "primitive";
  15363. }
  15364. var arg = this.parseGroupOfType("argument to '" + func + "'", argType, isOptional);
  15365. if (isOptional) {
  15366. optArgs.push(arg);
  15367. } else if (arg != null) {
  15368. args.push(arg);
  15369. } else {
  15370. // should be unreachable
  15371. throw new ParseError("Null argument, please report this as a bug");
  15372. }
  15373. }
  15374. return {
  15375. args,
  15376. optArgs
  15377. };
  15378. }
  15379. /**
  15380. * Parses a group when the mode is changing.
  15381. */
  15382. parseGroupOfType(name, type, optional) {
  15383. switch (type) {
  15384. case "color":
  15385. return this.parseColorGroup(optional);
  15386. case "size":
  15387. return this.parseSizeGroup(optional);
  15388. case "url":
  15389. return this.parseUrlGroup(optional);
  15390. case "math":
  15391. case "text":
  15392. return this.parseArgumentGroup(optional, type);
  15393. case "hbox":
  15394. {
  15395. // hbox argument type wraps the argument in the equivalent of
  15396. // \hbox, which is like \text but switching to \textstyle size.
  15397. var group = this.parseArgumentGroup(optional, "text");
  15398. return group != null ? {
  15399. type: "styling",
  15400. mode: group.mode,
  15401. body: [group],
  15402. style: "text" // simulate \textstyle
  15403. } : null;
  15404. }
  15405. case "raw":
  15406. {
  15407. var token = this.parseStringGroup("raw", optional);
  15408. return token != null ? {
  15409. type: "raw",
  15410. mode: "text",
  15411. string: token.text
  15412. } : null;
  15413. }
  15414. case "primitive":
  15415. {
  15416. if (optional) {
  15417. throw new ParseError("A primitive argument cannot be optional");
  15418. }
  15419. var _group = this.parseGroup(name);
  15420. if (_group == null) {
  15421. throw new ParseError("Expected group as " + name, this.fetch());
  15422. }
  15423. return _group;
  15424. }
  15425. case "original":
  15426. case null:
  15427. case undefined:
  15428. return this.parseArgumentGroup(optional);
  15429. default:
  15430. throw new ParseError("Unknown group type as " + name, this.fetch());
  15431. }
  15432. }
  15433. /**
  15434. * Discard any space tokens, fetching the next non-space token.
  15435. */
  15436. consumeSpaces() {
  15437. while (this.fetch().text === " ") {
  15438. this.consume();
  15439. }
  15440. }
  15441. /**
  15442. * Parses a group, essentially returning the string formed by the
  15443. * brace-enclosed tokens plus some position information.
  15444. */
  15445. parseStringGroup(modeName, // Used to describe the mode in error messages.
  15446. optional) {
  15447. var argToken = this.gullet.scanArgument(optional);
  15448. if (argToken == null) {
  15449. return null;
  15450. }
  15451. var str = "";
  15452. var nextToken;
  15453. while ((nextToken = this.fetch()).text !== "EOF") {
  15454. str += nextToken.text;
  15455. this.consume();
  15456. }
  15457. this.consume(); // consume the end of the argument
  15458. argToken.text = str;
  15459. return argToken;
  15460. }
  15461. /**
  15462. * Parses a regex-delimited group: the largest sequence of tokens
  15463. * whose concatenated strings match `regex`. Returns the string
  15464. * formed by the tokens plus some position information.
  15465. */
  15466. parseRegexGroup(regex, modeName // Used to describe the mode in error messages.
  15467. ) {
  15468. var firstToken = this.fetch();
  15469. var lastToken = firstToken;
  15470. var str = "";
  15471. var nextToken;
  15472. while ((nextToken = this.fetch()).text !== "EOF" && regex.test(str + nextToken.text)) {
  15473. lastToken = nextToken;
  15474. str += lastToken.text;
  15475. this.consume();
  15476. }
  15477. if (str === "") {
  15478. throw new ParseError("Invalid " + modeName + ": '" + firstToken.text + "'", firstToken);
  15479. }
  15480. return firstToken.range(lastToken, str);
  15481. }
  15482. /**
  15483. * Parses a color description.
  15484. */
  15485. parseColorGroup(optional) {
  15486. var res = this.parseStringGroup("color", optional);
  15487. if (res == null) {
  15488. return null;
  15489. }
  15490. var match = /^(#[a-f0-9]{3}|#?[a-f0-9]{6}|[a-z]+)$/i.exec(res.text);
  15491. if (!match) {
  15492. throw new ParseError("Invalid color: '" + res.text + "'", res);
  15493. }
  15494. var color = match[0];
  15495. if (/^[0-9a-f]{6}$/i.test(color)) {
  15496. // We allow a 6-digit HTML color spec without a leading "#".
  15497. // This follows the xcolor package's HTML color model.
  15498. // Predefined color names are all missed by this RegEx pattern.
  15499. color = "#" + color;
  15500. }
  15501. return {
  15502. type: "color-token",
  15503. mode: this.mode,
  15504. color
  15505. };
  15506. }
  15507. /**
  15508. * Parses a size specification, consisting of magnitude and unit.
  15509. */
  15510. parseSizeGroup(optional) {
  15511. var res;
  15512. var isBlank = false; // don't expand before parseStringGroup
  15513. this.gullet.consumeSpaces();
  15514. if (!optional && this.gullet.future().text !== "{") {
  15515. res = this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size");
  15516. } else {
  15517. res = this.parseStringGroup("size", optional);
  15518. }
  15519. if (!res) {
  15520. return null;
  15521. }
  15522. if (!optional && res.text.length === 0) {
  15523. // Because we've tested for what is !optional, this block won't
  15524. // affect \kern, \hspace, etc. It will capture the mandatory arguments
  15525. // to \genfrac and \above.
  15526. res.text = "0pt"; // Enable \above{}
  15527. isBlank = true; // This is here specifically for \genfrac
  15528. }
  15529. var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(res.text);
  15530. if (!match) {
  15531. throw new ParseError("Invalid size: '" + res.text + "'", res);
  15532. }
  15533. var data = {
  15534. number: +(match[1] + match[2]),
  15535. // sign + magnitude, cast to number
  15536. unit: match[3]
  15537. };
  15538. if (!validUnit(data)) {
  15539. throw new ParseError("Invalid unit: '" + data.unit + "'", res);
  15540. }
  15541. return {
  15542. type: "size",
  15543. mode: this.mode,
  15544. value: data,
  15545. isBlank
  15546. };
  15547. }
  15548. /**
  15549. * Parses an URL, checking escaped letters and allowed protocols,
  15550. * and setting the catcode of % as an active character (as in \hyperref).
  15551. */
  15552. parseUrlGroup(optional) {
  15553. this.gullet.lexer.setCatcode("%", 13); // active character
  15554. this.gullet.lexer.setCatcode("~", 12); // other character
  15555. var res = this.parseStringGroup("url", optional);
  15556. this.gullet.lexer.setCatcode("%", 14); // comment character
  15557. this.gullet.lexer.setCatcode("~", 13); // active character
  15558. if (res == null) {
  15559. return null;
  15560. } // hyperref package allows backslashes alone in href, but doesn't
  15561. // generate valid links in such cases; we interpret this as
  15562. // "undefined" behaviour, and keep them as-is. Some browser will
  15563. // replace backslashes with forward slashes.
  15564. var url = res.text.replace(/\\([#$%&~_^{}])/g, '$1');
  15565. return {
  15566. type: "url",
  15567. mode: this.mode,
  15568. url
  15569. };
  15570. }
  15571. /**
  15572. * Parses an argument with the mode specified.
  15573. */
  15574. parseArgumentGroup(optional, mode) {
  15575. var argToken = this.gullet.scanArgument(optional);
  15576. if (argToken == null) {
  15577. return null;
  15578. }
  15579. var outerMode = this.mode;
  15580. if (mode) {
  15581. // Switch to specified mode
  15582. this.switchMode(mode);
  15583. }
  15584. this.gullet.beginGroup();
  15585. var expression = this.parseExpression(false, "EOF"); // TODO: find an alternative way to denote the end
  15586. this.expect("EOF"); // expect the end of the argument
  15587. this.gullet.endGroup();
  15588. var result = {
  15589. type: "ordgroup",
  15590. mode: this.mode,
  15591. loc: argToken.loc,
  15592. body: expression
  15593. };
  15594. if (mode) {
  15595. // Switch mode back
  15596. this.switchMode(outerMode);
  15597. }
  15598. return result;
  15599. }
  15600. /**
  15601. * Parses an ordinary group, which is either a single nucleus (like "x")
  15602. * or an expression in braces (like "{x+y}") or an implicit group, a group
  15603. * that starts at the current position, and ends right before a higher explicit
  15604. * group ends, or at EOF.
  15605. */
  15606. parseGroup(name, // For error reporting.
  15607. breakOnTokenText) {
  15608. var firstToken = this.fetch();
  15609. var text = firstToken.text;
  15610. var result; // Try to parse an open brace or \begingroup
  15611. if (text === "{" || text === "\\begingroup") {
  15612. this.consume();
  15613. var groupEnd = text === "{" ? "}" : "\\endgroup";
  15614. this.gullet.beginGroup(); // If we get a brace, parse an expression
  15615. var expression = this.parseExpression(false, groupEnd);
  15616. var lastToken = this.fetch();
  15617. this.expect(groupEnd); // Check that we got a matching closing brace
  15618. this.gullet.endGroup();
  15619. result = {
  15620. type: "ordgroup",
  15621. mode: this.mode,
  15622. loc: SourceLocation.range(firstToken, lastToken),
  15623. body: expression,
  15624. // A group formed by \begingroup...\endgroup is a semi-simple group
  15625. // which doesn't affect spacing in math mode, i.e., is transparent.
  15626. // https://tex.stackexchange.com/questions/1930/when-should-one-
  15627. // use-begingroup-instead-of-bgroup
  15628. semisimple: text === "\\begingroup" || undefined
  15629. };
  15630. } else {
  15631. // If there exists a function with this name, parse the function.
  15632. // Otherwise, just return a nucleus
  15633. result = this.parseFunction(breakOnTokenText, name) || this.parseSymbol();
  15634. if (result == null && text[0] === "\\" && !implicitCommands.hasOwnProperty(text)) {
  15635. if (this.settings.throwOnError) {
  15636. throw new ParseError("Undefined control sequence: " + text, firstToken);
  15637. }
  15638. result = this.formatUnsupportedCmd(text);
  15639. this.consume();
  15640. }
  15641. }
  15642. return result;
  15643. }
  15644. /**
  15645. * Form ligature-like combinations of characters for text mode.
  15646. * This includes inputs like "--", "---", "``" and "''".
  15647. * The result will simply replace multiple textord nodes with a single
  15648. * character in each value by a single textord node having multiple
  15649. * characters in its value. The representation is still ASCII source.
  15650. * The group will be modified in place.
  15651. */
  15652. formLigatures(group) {
  15653. var n = group.length - 1;
  15654. for (var i = 0; i < n; ++i) {
  15655. var a = group[i]; // $FlowFixMe: Not every node type has a `text` property.
  15656. var v = a.text;
  15657. if (v === "-" && group[i + 1].text === "-") {
  15658. if (i + 1 < n && group[i + 2].text === "-") {
  15659. group.splice(i, 3, {
  15660. type: "textord",
  15661. mode: "text",
  15662. loc: SourceLocation.range(a, group[i + 2]),
  15663. text: "---"
  15664. });
  15665. n -= 2;
  15666. } else {
  15667. group.splice(i, 2, {
  15668. type: "textord",
  15669. mode: "text",
  15670. loc: SourceLocation.range(a, group[i + 1]),
  15671. text: "--"
  15672. });
  15673. n -= 1;
  15674. }
  15675. }
  15676. if ((v === "'" || v === "`") && group[i + 1].text === v) {
  15677. group.splice(i, 2, {
  15678. type: "textord",
  15679. mode: "text",
  15680. loc: SourceLocation.range(a, group[i + 1]),
  15681. text: v + v
  15682. });
  15683. n -= 1;
  15684. }
  15685. }
  15686. }
  15687. /**
  15688. * Parse a single symbol out of the string. Here, we handle single character
  15689. * symbols and special functions like \verb.
  15690. */
  15691. parseSymbol() {
  15692. var nucleus = this.fetch();
  15693. var text = nucleus.text;
  15694. if (/^\\verb[^a-zA-Z]/.test(text)) {
  15695. this.consume();
  15696. var arg = text.slice(5);
  15697. var star = arg.charAt(0) === "*";
  15698. if (star) {
  15699. arg = arg.slice(1);
  15700. } // Lexer's tokenRegex is constructed to always have matching
  15701. // first/last characters.
  15702. if (arg.length < 2 || arg.charAt(0) !== arg.slice(-1)) {
  15703. throw new ParseError("\\verb assertion failed --\n please report what input caused this bug");
  15704. }
  15705. arg = arg.slice(1, -1); // remove first and last char
  15706. return {
  15707. type: "verb",
  15708. mode: "text",
  15709. body: arg,
  15710. star
  15711. };
  15712. } // At this point, we should have a symbol, possibly with accents.
  15713. // First expand any accented base symbol according to unicodeSymbols.
  15714. if (unicodeSymbols.hasOwnProperty(text[0]) && !symbols[this.mode][text[0]]) {
  15715. // This behavior is not strict (XeTeX-compatible) in math mode.
  15716. if (this.settings.strict && this.mode === "math") {
  15717. this.settings.reportNonstrict("unicodeTextInMathMode", "Accented Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
  15718. }
  15719. text = unicodeSymbols[text[0]] + text.slice(1);
  15720. } // Strip off any combining characters
  15721. var match = combiningDiacriticalMarksEndRegex.exec(text);
  15722. if (match) {
  15723. text = text.substring(0, match.index);
  15724. if (text === 'i') {
  15725. text = '\u0131'; // dotless i, in math and text mode
  15726. } else if (text === 'j') {
  15727. text = '\u0237'; // dotless j, in math and text mode
  15728. }
  15729. } // Recognize base symbol
  15730. var symbol;
  15731. if (symbols[this.mode][text]) {
  15732. if (this.settings.strict && this.mode === 'math' && extraLatin.indexOf(text) >= 0) {
  15733. this.settings.reportNonstrict("unicodeTextInMathMode", "Latin-1/Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
  15734. }
  15735. var group = symbols[this.mode][text].group;
  15736. var loc = SourceLocation.range(nucleus);
  15737. var s;
  15738. if (ATOMS.hasOwnProperty(group)) {
  15739. // $FlowFixMe
  15740. var family = group;
  15741. s = {
  15742. type: "atom",
  15743. mode: this.mode,
  15744. family,
  15745. loc,
  15746. text
  15747. };
  15748. } else {
  15749. // $FlowFixMe
  15750. s = {
  15751. type: group,
  15752. mode: this.mode,
  15753. loc,
  15754. text
  15755. };
  15756. } // $FlowFixMe
  15757. symbol = s;
  15758. } else if (text.charCodeAt(0) >= 0x80) {
  15759. // no symbol for e.g. ^
  15760. if (this.settings.strict) {
  15761. if (!supportedCodepoint(text.charCodeAt(0))) {
  15762. this.settings.reportNonstrict("unknownSymbol", "Unrecognized Unicode character \"" + text[0] + "\"" + (" (" + text.charCodeAt(0) + ")"), nucleus);
  15763. } else if (this.mode === "math") {
  15764. this.settings.reportNonstrict("unicodeTextInMathMode", "Unicode text character \"" + text[0] + "\" used in math mode", nucleus);
  15765. }
  15766. } // All nonmathematical Unicode characters are rendered as if they
  15767. // are in text mode (wrapped in \text) because that's what it
  15768. // takes to render them in LaTeX. Setting `mode: this.mode` is
  15769. // another natural choice (the user requested math mode), but
  15770. // this makes it more difficult for getCharacterMetrics() to
  15771. // distinguish Unicode characters without metrics and those for
  15772. // which we want to simulate the letter M.
  15773. symbol = {
  15774. type: "textord",
  15775. mode: "text",
  15776. loc: SourceLocation.range(nucleus),
  15777. text
  15778. };
  15779. } else {
  15780. return null; // EOF, ^, _, {, }, etc.
  15781. }
  15782. this.consume(); // Transform combining characters into accents
  15783. if (match) {
  15784. for (var i = 0; i < match[0].length; i++) {
  15785. var accent = match[0][i];
  15786. if (!unicodeAccents[accent]) {
  15787. throw new ParseError("Unknown accent ' " + accent + "'", nucleus);
  15788. }
  15789. var command = unicodeAccents[accent][this.mode] || unicodeAccents[accent].text;
  15790. if (!command) {
  15791. throw new ParseError("Accent " + accent + " unsupported in " + this.mode + " mode", nucleus);
  15792. }
  15793. symbol = {
  15794. type: "accent",
  15795. mode: this.mode,
  15796. loc: SourceLocation.range(nucleus),
  15797. label: command,
  15798. isStretchy: false,
  15799. isShifty: true,
  15800. // $FlowFixMe
  15801. base: symbol
  15802. };
  15803. }
  15804. } // $FlowFixMe
  15805. return symbol;
  15806. }
  15807. }
  15808. Parser.endOfExpression = ["}", "\\endgroup", "\\end", "\\right", "&"];
  15809. /**
  15810. * Provides a single function for parsing an expression using a Parser
  15811. * TODO(emily): Remove this
  15812. */
  15813. /**
  15814. * Parses an expression using a Parser, then returns the parsed result.
  15815. */
  15816. var parseTree = function parseTree(toParse, settings) {
  15817. if (!(typeof toParse === 'string' || toParse instanceof String)) {
  15818. throw new TypeError('KaTeX can only parse string typed expression');
  15819. }
  15820. var parser = new Parser(toParse, settings); // Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
  15821. delete parser.gullet.macros.current["\\df@tag"];
  15822. var tree = parser.parse(); // Prevent a color definition from persisting between calls to katex.render().
  15823. delete parser.gullet.macros.current["\\current@color"];
  15824. delete parser.gullet.macros.current["\\color"]; // If the input used \tag, it will set the \df@tag macro to the tag.
  15825. // In this case, we separately parse the tag and wrap the tree.
  15826. if (parser.gullet.macros.get("\\df@tag")) {
  15827. if (!settings.displayMode) {
  15828. throw new ParseError("\\tag works only in display equations");
  15829. }
  15830. tree = [{
  15831. type: "tag",
  15832. mode: "text",
  15833. body: tree,
  15834. tag: parser.subparse([new Token("\\df@tag")])
  15835. }];
  15836. }
  15837. return tree;
  15838. };
  15839. /* eslint no-console:0 */
  15840. /**
  15841. * Parse and build an expression, and place that expression in the DOM node
  15842. * given.
  15843. */
  15844. var render = function render(expression, baseNode, options) {
  15845. baseNode.textContent = "";
  15846. var node = renderToDomTree(expression, options).toNode();
  15847. baseNode.appendChild(node);
  15848. }; // KaTeX's styles don't work properly in quirks mode. Print out an error, and
  15849. // disable rendering.
  15850. if (typeof document !== "undefined") {
  15851. if (document.compatMode !== "CSS1Compat") {
  15852. typeof console !== "undefined" && console.warn("Warning: KaTeX doesn't work in quirks mode. Make sure your " + "website has a suitable doctype.");
  15853. render = function render() {
  15854. throw new ParseError("KaTeX doesn't work in quirks mode.");
  15855. };
  15856. }
  15857. }
  15858. /**
  15859. * Parse and build an expression, and return the markup for that.
  15860. */
  15861. var renderToString = function renderToString(expression, options) {
  15862. var markup = renderToDomTree(expression, options).toMarkup();
  15863. return markup;
  15864. };
  15865. /**
  15866. * Parse an expression and return the parse tree.
  15867. */
  15868. var generateParseTree = function generateParseTree(expression, options) {
  15869. var settings = new Settings(options);
  15870. return parseTree(expression, settings);
  15871. };
  15872. /**
  15873. * If the given error is a KaTeX ParseError and options.throwOnError is false,
  15874. * renders the invalid LaTeX as a span with hover title giving the KaTeX
  15875. * error message. Otherwise, simply throws the error.
  15876. */
  15877. var renderError = function renderError(error, expression, options) {
  15878. if (options.throwOnError || !(error instanceof ParseError)) {
  15879. throw error;
  15880. }
  15881. var node = buildCommon.makeSpan(["katex-error"], [new SymbolNode(expression)]);
  15882. node.setAttribute("title", error.toString());
  15883. node.setAttribute("style", "color:" + options.errorColor);
  15884. return node;
  15885. };
  15886. /**
  15887. * Generates and returns the katex build tree. This is used for advanced
  15888. * use cases (like rendering to custom output).
  15889. */
  15890. var renderToDomTree = function renderToDomTree(expression, options) {
  15891. var settings = new Settings(options);
  15892. try {
  15893. var tree = parseTree(expression, settings);
  15894. return buildTree(tree, expression, settings);
  15895. } catch (error) {
  15896. return renderError(error, expression, settings);
  15897. }
  15898. };
  15899. /**
  15900. * Generates and returns the katex build tree, with just HTML (no MathML).
  15901. * This is used for advanced use cases (like rendering to custom output).
  15902. */
  15903. var renderToHTMLTree = function renderToHTMLTree(expression, options) {
  15904. var settings = new Settings(options);
  15905. try {
  15906. var tree = parseTree(expression, settings);
  15907. return buildHTMLTree(tree, expression, settings);
  15908. } catch (error) {
  15909. return renderError(error, expression, settings);
  15910. }
  15911. };
  15912. var katex = {
  15913. /**
  15914. * Current KaTeX version
  15915. */
  15916. version: "0.16.2",
  15917. /**
  15918. * Renders the given LaTeX into an HTML+MathML combination, and adds
  15919. * it as a child to the specified DOM node.
  15920. */
  15921. render,
  15922. /**
  15923. * Renders the given LaTeX into an HTML+MathML combination string,
  15924. * for sending to the client.
  15925. */
  15926. renderToString,
  15927. /**
  15928. * KaTeX error, usually during parsing.
  15929. */
  15930. ParseError,
  15931. /**
  15932. * The shema of Settings
  15933. */
  15934. SETTINGS_SCHEMA,
  15935. /**
  15936. * Parses the given LaTeX into KaTeX's internal parse tree structure,
  15937. * without rendering to HTML or MathML.
  15938. *
  15939. * NOTE: This method is not currently recommended for public use.
  15940. * The internal tree representation is unstable and is very likely
  15941. * to change. Use at your own risk.
  15942. */
  15943. __parse: generateParseTree,
  15944. /**
  15945. * Renders the given LaTeX into an HTML+MathML internal DOM tree
  15946. * representation, without flattening that representation to a string.
  15947. *
  15948. * NOTE: This method is not currently recommended for public use.
  15949. * The internal tree representation is unstable and is very likely
  15950. * to change. Use at your own risk.
  15951. */
  15952. __renderToDomTree: renderToDomTree,
  15953. /**
  15954. * Renders the given LaTeX into an HTML internal DOM tree representation,
  15955. * without MathML and without flattening that representation to a string.
  15956. *
  15957. * NOTE: This method is not currently recommended for public use.
  15958. * The internal tree representation is unstable and is very likely
  15959. * to change. Use at your own risk.
  15960. */
  15961. __renderToHTMLTree: renderToHTMLTree,
  15962. /**
  15963. * extends internal font metrics object with a new object
  15964. * each key in the new object represents a font name
  15965. */
  15966. __setFontMetrics: setFontMetrics,
  15967. /**
  15968. * adds a new symbol to builtin symbols table
  15969. */
  15970. __defineSymbol: defineSymbol,
  15971. /**
  15972. * adds a new macro to builtin macro list
  15973. */
  15974. __defineMacro: defineMacro,
  15975. /**
  15976. * Expose the dom tree node types, which can be useful for type checking nodes.
  15977. *
  15978. * NOTE: This method is not currently recommended for public use.
  15979. * The internal tree representation is unstable and is very likely
  15980. * to change. Use at your own risk.
  15981. */
  15982. __domTree: {
  15983. Span,
  15984. Anchor,
  15985. SymbolNode,
  15986. SvgNode,
  15987. PathNode,
  15988. LineNode
  15989. }
  15990. };
  15991. export { katex as default };