katex.js 599 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["katex"] = factory();
  8. else
  9. root["katex"] = factory();
  10. })((typeof self !== 'undefined' ? self : this), function() {
  11. return /******/ (function() { // webpackBootstrap
  12. /******/ "use strict";
  13. /******/ // The require scope
  14. /******/ var __webpack_require__ = {};
  15. /******/
  16. /************************************************************************/
  17. /******/ /* webpack/runtime/define property getters */
  18. /******/ !function() {
  19. /******/ // define getter functions for harmony exports
  20. /******/ __webpack_require__.d = function(exports, definition) {
  21. /******/ for(var key in definition) {
  22. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  23. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  24. /******/ }
  25. /******/ }
  26. /******/ };
  27. /******/ }();
  28. /******/
  29. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  30. /******/ !function() {
  31. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  32. /******/ }();
  33. /******/
  34. /************************************************************************/
  35. var __webpack_exports__ = {};
  36. // EXPORTS
  37. __webpack_require__.d(__webpack_exports__, {
  38. "default": function() { return /* binding */ katex_webpack; }
  39. });
  40. ;// ./src/ParseError.ts
  41. /**
  42. * This is the ParseError class, which is the main error thrown by KaTeX
  43. * functions when something has gone wrong. This is used to distinguish internal
  44. * errors from errors in the expression that the user provided.
  45. *
  46. * If possible, a caller should provide a Token or ParseNode with information
  47. * about where in the source string the problem occurred.
  48. */
  49. class ParseError extends Error {
  50. // Error start position based on passed-in Token or ParseNode.
  51. // Length of affected text based on passed-in Token or ParseNode.
  52. // The underlying error message without any context added.
  53. constructor(message,
  54. // The error message
  55. token) {
  56. let error = "KaTeX parse error: " + message;
  57. let start;
  58. let end;
  59. const loc = token && token.loc;
  60. if (loc && loc.start <= loc.end) {
  61. // If we have the input and a position, make the error a bit fancier
  62. // Get the input
  63. const input = loc.lexer.input;
  64. // Prepend some information
  65. start = loc.start;
  66. end = loc.end;
  67. if (start === input.length) {
  68. error += " at end of input: ";
  69. } else {
  70. error += " at position " + (start + 1) + ": ";
  71. }
  72. // Underline token in question using combining underscores
  73. const underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332");
  74. // Extract some context from the input and add it to the error
  75. let left;
  76. if (start > 15) {
  77. left = "…" + input.slice(start - 15, start);
  78. } else {
  79. left = input.slice(0, start);
  80. }
  81. let right;
  82. if (end + 15 < input.length) {
  83. right = input.slice(end, end + 15) + "…";
  84. } else {
  85. right = input.slice(end);
  86. }
  87. error += left + underlined + right;
  88. }
  89. super(error);
  90. this.name = "ParseError";
  91. Object.setPrototypeOf(this, ParseError.prototype);
  92. this.position = start;
  93. if (start != null && end != null) {
  94. this.length = end - start;
  95. }
  96. this.rawMessage = message;
  97. }
  98. }
  99. /* harmony default export */ var src_ParseError = (ParseError);
  100. ;// ./src/utils.ts
  101. /**
  102. * This file contains a list of utility functions which are useful in other
  103. * files.
  104. */
  105. // hyphenate and escape adapted from Facebook's React under Apache 2 license
  106. const uppercase = /([A-Z])/g;
  107. const hyphenate = str => str.replace(uppercase, "-$1").toLowerCase();
  108. const ESCAPE_LOOKUP = {
  109. "&": "&amp;",
  110. ">": "&gt;",
  111. "<": "&lt;",
  112. "\"": "&quot;",
  113. "'": "&#x27;"
  114. };
  115. const ESCAPE_REGEX = /[&><"']/g;
  116. /**
  117. * Escapes text to prevent scripting attacks.
  118. */
  119. const utils_escape = text => String(text).replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
  120. /**
  121. * Sometimes we want to pull out the innermost element of a group. In most
  122. * cases, this will just be the group itself, but when ordgroups and colors have
  123. * a single element, we want to pull that out.
  124. */
  125. const getBaseElem = group => {
  126. if (group.type === "ordgroup") {
  127. if (group.body.length === 1) {
  128. return getBaseElem(group.body[0]);
  129. } else {
  130. return group;
  131. }
  132. } else if (group.type === "color") {
  133. if (group.body.length === 1) {
  134. return getBaseElem(group.body[0]);
  135. } else {
  136. return group;
  137. }
  138. } else if (group.type === "font") {
  139. return getBaseElem(group.body);
  140. } else {
  141. return group;
  142. }
  143. };
  144. const characterNodesTypes = new Set(["mathord", "textord", "atom"]);
  145. /**
  146. * TeXbook algorithms often reference "character boxes", which are simply groups
  147. * with a single character in them. To decide if something is a character box,
  148. * we find its innermost group, and see if it is a single character.
  149. */
  150. const isCharacterBox = group => characterNodesTypes.has(getBaseElem(group).type);
  151. /**
  152. * Return the protocol of a URL, or "_relative" if the URL does not specify a
  153. * protocol (and thus is relative), or `null` if URL has invalid protocol
  154. * (so should be outright rejected).
  155. */
  156. const protocolFromUrl = url => {
  157. // Check for possible leading protocol.
  158. // https://url.spec.whatwg.org/#url-parsing strips leading whitespace
  159. // (U+20) or C0 control (U+00-U+1F) characters.
  160. // eslint-disable-next-line no-control-regex
  161. const protocol = /^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(url);
  162. if (!protocol) {
  163. return "_relative";
  164. }
  165. // Reject weird colons
  166. if (protocol[2] !== ":") {
  167. return null;
  168. }
  169. // Reject invalid characters in scheme according to
  170. // https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
  171. if (!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(protocol[1])) {
  172. return null;
  173. }
  174. // Lowercase the protocol
  175. return protocol[1].toLowerCase();
  176. };
  177. ;// ./src/Settings.ts
  178. /* eslint no-console:0 */
  179. /**
  180. * This is a module for storing settings passed into KaTeX. It correctly handles
  181. * default settings.
  182. */
  183. // TODO: automatically generate documentation
  184. // TODO: check all properties on Settings exist
  185. // TODO: check the type of a property on Settings matches
  186. const SETTINGS_SCHEMA = {
  187. displayMode: {
  188. type: "boolean",
  189. 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.",
  190. cli: "-d, --display-mode"
  191. },
  192. output: {
  193. type: {
  194. enum: ["htmlAndMathml", "html", "mathml"]
  195. },
  196. description: "Determines the markup language of the output.",
  197. cli: "-F, --format <type>"
  198. },
  199. leqno: {
  200. type: "boolean",
  201. description: "Render display math in leqno style (left-justified tags)."
  202. },
  203. fleqn: {
  204. type: "boolean",
  205. description: "Render display math flush left."
  206. },
  207. throwOnError: {
  208. type: "boolean",
  209. default: true,
  210. cli: "-t, --no-throw-on-error",
  211. cliDescription: "Render errors (in the color given by --error-color) ins" + "tead of throwing a ParseError exception when encountering an error."
  212. },
  213. errorColor: {
  214. type: "string",
  215. default: "#cc0000",
  216. cli: "-c, --error-color <color>",
  217. cliDescription: "A color string given in the format 'rgb' or 'rrggbb' " + "(no #). This option determines the color of errors rendered by the " + "-t option.",
  218. cliProcessor: color => "#" + color
  219. },
  220. macros: {
  221. type: "object",
  222. cli: "-m, --macro <def>",
  223. cliDescription: "Define custom macro of the form '\\foo:expansion' (use " + "multiple -m arguments for multiple macros).",
  224. cliDefault: [],
  225. cliProcessor: (def, defs) => {
  226. defs.push(def);
  227. return defs;
  228. }
  229. },
  230. minRuleThickness: {
  231. type: "number",
  232. 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`.",
  233. processor: t => Math.max(0, t),
  234. cli: "--min-rule-thickness <size>",
  235. cliProcessor: parseFloat
  236. },
  237. colorIsTextColor: {
  238. type: "boolean",
  239. description: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " + "instead of LaTeX's one-argument \\color mode change.",
  240. cli: "-b, --color-is-text-color"
  241. },
  242. strict: {
  243. type: [{
  244. enum: ["warn", "ignore", "error"]
  245. }, "boolean", "function"],
  246. description: "Turn on strict / LaTeX faithfulness mode, which throws an " + "error if the input uses features that are not supported by LaTeX.",
  247. cli: "-S, --strict",
  248. cliDefault: false
  249. },
  250. trust: {
  251. type: ["boolean", "function"],
  252. description: "Trust the input, enabling all HTML features such as \\url.",
  253. cli: "-T, --trust"
  254. },
  255. maxSize: {
  256. type: "number",
  257. default: Infinity,
  258. 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",
  259. processor: s => Math.max(0, s),
  260. cli: "-s, --max-size <n>",
  261. cliProcessor: parseInt
  262. },
  263. maxExpand: {
  264. type: "number",
  265. default: 1000,
  266. 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.",
  267. processor: n => Math.max(0, n),
  268. cli: "-e, --max-expand <n>",
  269. cliProcessor: n => n === "Infinity" ? Infinity : parseInt(n)
  270. },
  271. globalGroup: {
  272. type: "boolean",
  273. cli: false
  274. }
  275. };
  276. function getDefaultValue(schema) {
  277. if ("default" in schema) {
  278. return schema.default;
  279. }
  280. const type = schema.type;
  281. const defaultType = Array.isArray(type) ? type[0] : type;
  282. if (typeof defaultType !== 'string') {
  283. return defaultType.enum[0];
  284. }
  285. switch (defaultType) {
  286. case 'boolean':
  287. return false;
  288. case 'string':
  289. return '';
  290. case 'number':
  291. return 0;
  292. case 'object':
  293. return {};
  294. }
  295. }
  296. /**
  297. * The main Settings object
  298. *
  299. * The current options stored are:
  300. * - displayMode: Whether the expression should be typeset as inline math
  301. * (false, the default), meaning that the math starts in
  302. * \textstyle and is placed in an inline-block); or as display
  303. * math (true), meaning that the math starts in \displaystyle
  304. * and is placed in a block with vertical margin.
  305. */
  306. class Settings {
  307. constructor(options) {
  308. if (options === void 0) {
  309. options = {};
  310. }
  311. // allow null options
  312. options = options || {};
  313. for (const prop of Object.keys(SETTINGS_SCHEMA)) {
  314. const schema = SETTINGS_SCHEMA[prop];
  315. const optionValue = options[prop];
  316. // TODO: validate options
  317. this[prop] = optionValue !== undefined ? schema.processor ? schema.processor(optionValue) : optionValue : getDefaultValue(schema);
  318. }
  319. }
  320. /**
  321. * Report nonstrict (non-LaTeX-compatible) input.
  322. * Can safely not be called if `this.strict` is false in JavaScript.
  323. */
  324. reportNonstrict(errorCode, errorMsg, token) {
  325. let strict = this.strict;
  326. if (typeof strict === "function") {
  327. // Allow return value of strict function to be boolean or string
  328. // (or null/undefined, meaning no further processing).
  329. strict = strict(errorCode, errorMsg, token);
  330. }
  331. if (!strict || strict === "ignore") {
  332. return;
  333. } else if (strict === true || strict === "error") {
  334. throw new src_ParseError("LaTeX-incompatible input and strict mode is set to 'error': " + (errorMsg + " [" + errorCode + "]"), token);
  335. } else if (strict === "warn") {
  336. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to 'warn': " + (errorMsg + " [" + errorCode + "]"));
  337. } else {
  338. // won't happen in type-safe code
  339. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to " + ("unrecognized '" + strict + "': " + errorMsg + " [" + errorCode + "]"));
  340. }
  341. }
  342. /**
  343. * Check whether to apply strict (LaTeX-adhering) behavior for unusual
  344. * input (like `\\`). Unlike `nonstrict`, will not throw an error;
  345. * instead, "error" translates to a return value of `true`, while "ignore"
  346. * translates to a return value of `false`. May still print a warning:
  347. * "warn" prints a warning and returns `false`.
  348. * This is for the second category of `errorCode`s listed in the README.
  349. */
  350. useStrictBehavior(errorCode, errorMsg, token) {
  351. let strict = this.strict;
  352. if (typeof strict === "function") {
  353. // Allow return value of strict function to be boolean or string
  354. // (or null/undefined, meaning no further processing).
  355. // But catch any exceptions thrown by function, treating them
  356. // like "error".
  357. try {
  358. strict = strict(errorCode, errorMsg, token);
  359. } catch (error) {
  360. strict = "error";
  361. }
  362. }
  363. if (!strict || strict === "ignore") {
  364. return false;
  365. } else if (strict === true || strict === "error") {
  366. return true;
  367. } else if (strict === "warn") {
  368. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to 'warn': " + (errorMsg + " [" + errorCode + "]"));
  369. return false;
  370. } else {
  371. // won't happen in type-safe code
  372. typeof console !== "undefined" && console.warn("LaTeX-incompatible input and strict mode is set to " + ("unrecognized '" + strict + "': " + errorMsg + " [" + errorCode + "]"));
  373. return false;
  374. }
  375. }
  376. /**
  377. * Check whether to test potentially dangerous input, and return
  378. * `true` (trusted) or `false` (untrusted). The sole argument `context`
  379. * should be an object with `command` field specifying the relevant LaTeX
  380. * command (as a string starting with `\`), and any other arguments, etc.
  381. * If `context` has a `url` field, a `protocol` field will automatically
  382. * get added by this function (changing the specified object).
  383. */
  384. isTrusted(context) {
  385. if ("url" in context && context.url && !context.protocol) {
  386. const protocol = protocolFromUrl(context.url);
  387. if (protocol == null) {
  388. return false;
  389. }
  390. context.protocol = protocol;
  391. }
  392. const trust = typeof this.trust === "function" ? this.trust(context) : this.trust;
  393. return Boolean(trust);
  394. }
  395. }
  396. ;// ./src/Style.ts
  397. /**
  398. * This file contains information and classes for the various kinds of styles
  399. * used in TeX. It provides a generic `Style` class, which holds information
  400. * about a specific style. It then provides instances of all the different kinds
  401. * of styles possible, and provides functions to move between them and get
  402. * information about them.
  403. */
  404. /**
  405. * The main style class. Contains a unique id for the style, a size (which is
  406. * the same for cramped and uncramped version of a style), and a cramped flag.
  407. */
  408. class Style {
  409. constructor(id, size, cramped) {
  410. this.id = id;
  411. this.size = size;
  412. this.cramped = cramped;
  413. }
  414. /**
  415. * Get the style of a superscript given a base in the current style.
  416. */
  417. sup() {
  418. return styles[sup[this.id]];
  419. }
  420. /**
  421. * Get the style of a subscript given a base in the current style.
  422. */
  423. sub() {
  424. return styles[sub[this.id]];
  425. }
  426. /**
  427. * Get the style of a fraction numerator given the fraction in the current
  428. * style.
  429. */
  430. fracNum() {
  431. return styles[fracNum[this.id]];
  432. }
  433. /**
  434. * Get the style of a fraction denominator given the fraction in the current
  435. * style.
  436. */
  437. fracDen() {
  438. return styles[fracDen[this.id]];
  439. }
  440. /**
  441. * Get the cramped version of a style (in particular, cramping a cramped style
  442. * doesn't change the style).
  443. */
  444. cramp() {
  445. return styles[cramp[this.id]];
  446. }
  447. /**
  448. * Get a text or display version of this style.
  449. */
  450. text() {
  451. return styles[Style_text[this.id]];
  452. }
  453. /**
  454. * Return true if this style is tightly spaced (scriptstyle/scriptscriptstyle)
  455. */
  456. isTight() {
  457. return this.size >= 2;
  458. }
  459. }
  460. // Export an interface for type checking, but don't expose the implementation.
  461. // This way, no more styles can be generated.
  462. // IDs of the different styles
  463. const D = 0;
  464. const Dc = 1;
  465. const T = 2;
  466. const Tc = 3;
  467. const S = 4;
  468. const Sc = 5;
  469. const SS = 6;
  470. const SSc = 7;
  471. // Instances of the different styles
  472. const 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)];
  473. // Lookup tables for switching from one style to another
  474. const sup = [S, Sc, S, Sc, SS, SSc, SS, SSc];
  475. const sub = [Sc, Sc, Sc, Sc, SSc, SSc, SSc, SSc];
  476. const fracNum = [T, Tc, S, Sc, SS, SSc, SS, SSc];
  477. const fracDen = [Tc, Tc, Sc, Sc, SSc, SSc, SSc, SSc];
  478. const cramp = [Dc, Dc, Tc, Tc, Sc, Sc, SSc, SSc];
  479. const Style_text = [D, Dc, T, Tc, T, Tc, T, Tc];
  480. // We only export some of the styles.
  481. /* harmony default export */ var src_Style = ({
  482. DISPLAY: styles[D],
  483. TEXT: styles[T],
  484. SCRIPT: styles[S],
  485. SCRIPTSCRIPT: styles[SS]
  486. });
  487. ;// ./src/unicodeScripts.ts
  488. /*
  489. * This file defines the Unicode scripts and script families that we
  490. * support. To add new scripts or families, just add a new entry to the
  491. * scriptData array below. Adding scripts to the scriptData array allows
  492. * characters from that script to appear in \text{} environments.
  493. */
  494. /**
  495. * Each script or script family has a name and an array of blocks.
  496. * Each block is an array of two numbers which specify the start and
  497. * end points (inclusive) of a block of Unicode codepoints.
  498. */
  499. /**
  500. * Unicode block data for the families of scripts we support in \text{}.
  501. * Scripts only need to appear here if they do not have font metrics.
  502. */
  503. const scriptData = [{
  504. // Latin characters beyond the Latin-1 characters we have metrics for.
  505. // Needed for Czech, Hungarian and Turkish text, for example.
  506. name: 'latin',
  507. blocks: [[0x0100, 0x024f],
  508. // Latin Extended-A and Latin Extended-B
  509. [0x0300, 0x036f] // Combining Diacritical marks
  510. ]
  511. }, {
  512. // The Cyrillic script used by Russian and related languages.
  513. // A Cyrillic subset used to be supported as explicitly defined
  514. // symbols in symbols.js
  515. name: 'cyrillic',
  516. blocks: [[0x0400, 0x04ff]]
  517. }, {
  518. // Armenian
  519. name: 'armenian',
  520. blocks: [[0x0530, 0x058F]]
  521. }, {
  522. // The Brahmic scripts of South and Southeast Asia
  523. // Devanagari (0900–097F)
  524. // Bengali (0980–09FF)
  525. // Gurmukhi (0A00–0A7F)
  526. // Gujarati (0A80–0AFF)
  527. // Oriya (0B00–0B7F)
  528. // Tamil (0B80–0BFF)
  529. // Telugu (0C00–0C7F)
  530. // Kannada (0C80–0CFF)
  531. // Malayalam (0D00–0D7F)
  532. // Sinhala (0D80–0DFF)
  533. // Thai (0E00–0E7F)
  534. // Lao (0E80–0EFF)
  535. // Tibetan (0F00–0FFF)
  536. // Myanmar (1000–109F)
  537. name: 'brahmic',
  538. blocks: [[0x0900, 0x109F]]
  539. }, {
  540. name: 'georgian',
  541. blocks: [[0x10A0, 0x10ff]]
  542. }, {
  543. // Chinese and Japanese.
  544. // The "k" in cjk is for Korean, but we've separated Korean out
  545. name: "cjk",
  546. blocks: [[0x3000, 0x30FF],
  547. // CJK symbols and punctuation, Hiragana, Katakana
  548. [0x4E00, 0x9FAF],
  549. // CJK ideograms
  550. [0xFF00, 0xFF60] // Fullwidth punctuation
  551. // TODO: add halfwidth Katakana and Romanji glyphs
  552. ]
  553. }, {
  554. // Korean
  555. name: 'hangul',
  556. blocks: [[0xAC00, 0xD7AF]]
  557. }];
  558. /**
  559. * Given a codepoint, return the name of the script or script family
  560. * it is from, or null if it is not part of a known block
  561. */
  562. function scriptFromCodepoint(codepoint) {
  563. for (let i = 0; i < scriptData.length; i++) {
  564. const script = scriptData[i];
  565. for (let i = 0; i < script.blocks.length; i++) {
  566. const block = script.blocks[i];
  567. if (codepoint >= block[0] && codepoint <= block[1]) {
  568. return script.name;
  569. }
  570. }
  571. }
  572. return null;
  573. }
  574. /**
  575. * A flattened version of all the supported blocks in a single array.
  576. * This is an optimization to make supportedCodepoint() fast.
  577. */
  578. const allBlocks = [];
  579. scriptData.forEach(s => s.blocks.forEach(b => allBlocks.push(...b)));
  580. /**
  581. * Given a codepoint, return true if it falls within one of the
  582. * scripts or script families defined above and false otherwise.
  583. *
  584. * Micro benchmarks shows that this is faster than
  585. * /[\u3000-\u30FF\u4E00-\u9FAF\uFF00-\uFF60\uAC00-\uD7AF\u0900-\u109F]/.test()
  586. * in Firefox, Chrome and Node.
  587. */
  588. function supportedCodepoint(codepoint) {
  589. for (let i = 0; i < allBlocks.length; i += 2) {
  590. if (codepoint >= allBlocks[i] && codepoint <= allBlocks[i + 1]) {
  591. return true;
  592. }
  593. }
  594. return false;
  595. }
  596. ;// ./src/svgGeometry.ts
  597. /**
  598. * This file provides support to domTree.js and delimiter.js.
  599. * It's a storehouse of path geometry for SVG images.
  600. */
  601. // In all paths below, the viewBox-to-em scale is 1000:1.
  602. const hLinePad = 80; // padding above a sqrt vinculum. Prevents image cropping.
  603. // The vinculum of a \sqrt can be made thicker by a KaTeX rendering option.
  604. // Think of variable extraVinculum as two detours in the SVG path.
  605. // The detour begins at the lower left of the area labeled extraVinculum below.
  606. // The detour proceeds one extraVinculum distance up and slightly to the right,
  607. // displacing the radiused corner between surd and vinculum. The radius is
  608. // traversed as usual, then the detour resumes. It goes right, to the end of
  609. // the very long vinculum, then down one extraVinculum distance,
  610. // after which it resumes regular path geometry for the radical.
  611. /* vinculum
  612. /
  613. /▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒←extraVinculum
  614. / █████████████████████←0.04em (40 unit) std vinculum thickness
  615. / /
  616. / /
  617. / /\
  618. / / surd
  619. */
  620. const sqrtMain = function (extraVinculum, hLinePad) {
  621. // sqrtMain path geometry is from glyph U221A in the font KaTeX Main
  622. return "M95," + (622 + extraVinculum + 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" + extraVinculum / 2.075 + " -" + extraVinculum + "\nc5.3,-9.3,12,-14,20,-14\nH400000v" + (40 + extraVinculum) + "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 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
  623. };
  624. const sqrtSize1 = function (extraVinculum, hLinePad) {
  625. // size1 is from glyph U221A in the font KaTeX_Size1-Regular
  626. return "M263," + (601 + extraVinculum + 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" + extraVinculum / 2.084 + " -" + extraVinculum + "\nc4.7,-7.3,11,-11,19,-11\nH40000v" + (40 + extraVinculum) + "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 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
  627. };
  628. const sqrtSize2 = function (extraVinculum, hLinePad) {
  629. // size2 is from glyph U221A in the font KaTeX_Size2-Regular
  630. return "M983 " + (10 + extraVinculum + hLinePad) + "\nl" + extraVinculum / 3.13 + " -" + extraVinculum + "\nc4,-6.7,10,-10,18,-10 H400000v" + (40 + extraVinculum) + "\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 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "h-400000z";
  631. };
  632. const sqrtSize3 = function (extraVinculum, hLinePad) {
  633. // size3 is from glyph U221A in the font KaTeX_Size3-Regular
  634. return "M424," + (2398 + extraVinculum + 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" + extraVinculum / 4.223 + " -" + extraVinculum + "c4,-6.7,10,-10,18,-10 H400000\nv" + (40 + extraVinculum) + "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 + extraVinculum) + " " + hLinePad + "\nh400000v" + (40 + extraVinculum) + "h-400000z";
  635. };
  636. const sqrtSize4 = function (extraVinculum, hLinePad) {
  637. // size4 is from glyph U221A in the font KaTeX_Size4-Regular
  638. return "M473," + (2713 + extraVinculum + hLinePad) + "\nc339.3,-1799.3,509.3,-2700,510,-2702 l" + extraVinculum / 5.298 + " -" + extraVinculum + "\nc3.3,-7.3,9.3,-11,18,-11 H400000v" + (40 + extraVinculum) + "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 + extraVinculum) + " " + hLinePad + "h400000v" + (40 + extraVinculum) + "H1017.7z";
  639. };
  640. const phasePath = function (y) {
  641. const x = y / 2; // x coordinate at top of angle
  642. return "M400000 " + y + " H0 L" + x + " 0 l65 45 L145 " + (y - 80) + " H400000z";
  643. };
  644. const sqrtTall = function (extraVinculum, hLinePad, viewBoxHeight) {
  645. // sqrtTall is from glyph U23B7 in the font KaTeX_Size4-Regular
  646. // One path edge has a variable length. It runs vertically from the vinculum
  647. // to a point near (14 units) the bottom of the surd. The vinculum
  648. // is normally 40 units thick. So the length of the line in question is:
  649. const vertSegment = viewBoxHeight - 54 - hLinePad - extraVinculum;
  650. return "M702 " + (extraVinculum + hLinePad) + "H400000" + (40 + extraVinculum) + "\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 + extraVinculum) + "H742z";
  651. };
  652. const sqrtPath = function (size, extraVinculum, viewBoxHeight) {
  653. extraVinculum = 1000 * extraVinculum; // Convert from document ems to viewBox.
  654. let path = "";
  655. switch (size) {
  656. case "sqrtMain":
  657. path = sqrtMain(extraVinculum, hLinePad);
  658. break;
  659. case "sqrtSize1":
  660. path = sqrtSize1(extraVinculum, hLinePad);
  661. break;
  662. case "sqrtSize2":
  663. path = sqrtSize2(extraVinculum, hLinePad);
  664. break;
  665. case "sqrtSize3":
  666. path = sqrtSize3(extraVinculum, hLinePad);
  667. break;
  668. case "sqrtSize4":
  669. path = sqrtSize4(extraVinculum, hLinePad);
  670. break;
  671. case "sqrtTall":
  672. path = sqrtTall(extraVinculum, hLinePad, viewBoxHeight);
  673. }
  674. return path;
  675. };
  676. const innerPath = function (name, height) {
  677. // The inner part of stretchy tall delimiters
  678. switch (name) {
  679. case "\u239c":
  680. return "M291 0 H417 V" + height + " H291z M291 0 H417 V" + height + " H291z";
  681. case "\u2223":
  682. return "M145 0 H188 V" + height + " H145z M145 0 H188 V" + height + " H145z";
  683. case "\u2225":
  684. 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");
  685. case "\u239f":
  686. return "M457 0 H583 V" + height + " H457z M457 0 H583 V" + height + " H457z";
  687. case "\u23a2":
  688. return "M319 0 H403 V" + height + " H319z M319 0 H403 V" + height + " H319z";
  689. case "\u23a5":
  690. return "M263 0 H347 V" + height + " H263z M263 0 H347 V" + height + " H263z";
  691. case "\u23aa":
  692. return "M384 0 H504 V" + height + " H384z M384 0 H504 V" + height + " H384z";
  693. case "\u23d0":
  694. return "M312 0 H355 V" + height + " H312z M312 0 H355 V" + height + " H312z";
  695. case "\u2016":
  696. 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");
  697. default:
  698. return "";
  699. }
  700. };
  701. const path = {
  702. // The doubleleftarrow geometry is from glyph U+21D0 in the font KaTeX Main
  703. 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",
  704. // doublerightarrow is from glyph U+21D2 in font KaTeX Main
  705. 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",
  706. // leftarrow is from glyph U+2190 in font KaTeX Main
  707. 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",
  708. // overbrace is from glyphs U+23A9/23A8/23A7 in font KaTeX_Size4-Regular
  709. 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",
  710. 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",
  711. // overgroup is from the MnSymbol package (public domain)
  712. 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",
  713. 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",
  714. // Harpoons are from glyph U+21BD in font KaTeX Main
  715. 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",
  716. 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",
  717. 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",
  718. 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",
  719. // hook is from glyph U+21A9 in font KaTeX Main
  720. 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",
  721. leftlinesegment: "M40 281 V428 H0 V94 H40 V241 H400000 v40z\nM40 281 V428 H0 V94 H40 V241 H400000 v40z",
  722. leftbracketunder: "M0 0 h120 V290 H399995 v120 H0z\nM0 0 h120 V290 H399995 v120 H0z",
  723. leftbracketover: "M0 440 h120 V150 H399995 v-120 H0z\nM0 440 h120 V150 H399995 v-120 H0z",
  724. leftmapsto: "M40 281 V448H0V74H40V241H400000v40z\nM40 281 V448H0V74H40V241H400000v40z",
  725. // tofrom is from glyph U+21C4 in font KaTeX AMS Regular
  726. 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",
  727. longequal: "M0 50 h400000 v40H0z m0 194h40000v40H0z\nM0 50 h400000 v40H0z m0 194h40000v40H0z",
  728. 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",
  729. 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",
  730. 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",
  731. 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",
  732. 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",
  733. 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",
  734. 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",
  735. 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",
  736. 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",
  737. 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",
  738. 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",
  739. 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",
  740. 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",
  741. 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",
  742. 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",
  743. 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",
  744. rightlinesegment: "M399960 241 V94 h40 V428 h-40 V281 H0 v-40z\nM399960 241 V94 h40 V428 h-40 V281 H0 v-40z",
  745. rightbracketunder: "M399995 0 h-120 V290 H0 v120 H400000z\nM399995 0 h-120 V290 H0 v120 H400000z",
  746. rightbracketover: "M399995 440 h-120 V150 H0 v-120 H399995z\nM399995 440 h-120 V150 H0 v-120 H399995z",
  747. 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",
  748. // twoheadleftarrow is from glyph U+219E in font KaTeX AMS Regular
  749. 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",
  750. 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",
  751. // tilde1 is a modified version of a glyph from the MnSymbol package
  752. 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",
  753. // ditto tilde2, tilde3, & tilde4
  754. 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",
  755. 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",
  756. 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",
  757. // vec is from glyph U+20D7 in font KaTeX Main
  758. 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",
  759. // widehat1 is a modified version of a glyph from the MnSymbol package
  760. 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",
  761. // ditto widehat2, widehat3, & widehat4
  762. 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",
  763. 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",
  764. 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",
  765. // widecheck paths are all inverted versions of widehat
  766. 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",
  767. 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",
  768. 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",
  769. 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",
  770. // The next ten paths support reaction arrows from the mhchem package.
  771. // Arrows for \ce{<-->} are offset from xAxis by 0.22ex, per mhchem in LaTeX
  772. // baraboveleftarrow is mostly from glyph U+2190 in font KaTeX Main
  773. 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",
  774. // rightarrowabovebar is mostly from glyph U+2192, KaTeX Main
  775. 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",
  776. // The short left harpoon has 0.5em (i.e. 500 units) kern on the left end.
  777. // Ref from mhchem.sty: \rlap{\raisebox{-.22ex}{$\kern0.5em
  778. 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",
  779. 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",
  780. 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",
  781. 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"
  782. };
  783. const tallDelim = function (label, midHeight) {
  784. switch (label) {
  785. case "lbrack":
  786. return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v1759 h347 v-84\nH403z M403 1759 V0 H319 V1759 v" + midHeight + " v1759 h84z";
  787. case "rbrack":
  788. return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v1759 H0 v84 H347z\nM347 1759 V0 H263 V1759 v" + midHeight + " v1759 h84z";
  789. case "vert":
  790. 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";
  791. case "doublevert":
  792. 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";
  793. case "lfloor":
  794. return "M319 602 V0 H403 V602 v" + midHeight + " v1715 h263 v84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
  795. case "rfloor":
  796. return "M319 602 V0 H403 V602 v" + midHeight + " v1799 H0 v-84 H319z\nMM319 602 V0 H403 V602 v" + midHeight + " v1715 H319z";
  797. case "lceil":
  798. return "M403 1759 V84 H666 V0 H319 V1759 v" + midHeight + " v602 h84z\nM403 1759 V0 H319 V1759 v" + midHeight + " v602 h84z";
  799. case "rceil":
  800. return "M347 1759 V0 H0 V84 H263 V1759 v" + midHeight + " v602 h84z\nM347 1759 V0 h-84 V1759 v" + midHeight + " v602 h84z";
  801. case "lparen":
  802. 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";
  803. case "rparen":
  804. 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";
  805. default:
  806. // We should not ever get here.
  807. throw new Error("Unknown stretchy delimiter.");
  808. }
  809. };
  810. ;// ./src/tree.ts
  811. // To ensure that all nodes have compatible signatures for these methods.
  812. /**
  813. * This node represents a document fragment, which contains elements, but when
  814. * placed into the DOM doesn't have any representation itself. It only contains
  815. * children and doesn't have any DOM node properties.
  816. */
  817. class DocumentFragment {
  818. // Never used; needed for satisfying interface.
  819. constructor(children) {
  820. this.children = children;
  821. this.classes = [];
  822. this.height = 0;
  823. this.depth = 0;
  824. this.maxFontSize = 0;
  825. this.style = {};
  826. }
  827. hasClass(className) {
  828. return this.classes.includes(className);
  829. }
  830. /** Convert the fragment into a node. */
  831. toNode() {
  832. const frag = document.createDocumentFragment();
  833. for (let i = 0; i < this.children.length; i++) {
  834. frag.appendChild(this.children[i].toNode());
  835. }
  836. return frag;
  837. }
  838. /** Convert the fragment into HTML markup. */
  839. toMarkup() {
  840. let markup = "";
  841. // Simply concatenate the markup for the children together.
  842. for (let i = 0; i < this.children.length; i++) {
  843. markup += this.children[i].toMarkup();
  844. }
  845. return markup;
  846. }
  847. /**
  848. * Converts the math node into a string, similar to innerText. Applies to
  849. * MathDomNode's only.
  850. */
  851. toText() {
  852. // To avoid this, we would subclass documentFragment separately for
  853. // MathML, but polyfills for subclassing is expensive per PR 1469.
  854. // TODO(ts): Only works for ChildType = MathDomNode.
  855. const toText = child => child.toText();
  856. return this.children.map(toText).join("");
  857. }
  858. }
  859. ;// ./src/units.ts
  860. /**
  861. * This file does conversion between units. In particular, it provides
  862. * calculateSize to convert other units into ems.
  863. */
  864. // This table gives the number of TeX pts in one of each *absolute* TeX unit.
  865. // Thus, multiplying a length by this number converts the length from units
  866. // into pts. Dividing the result by ptPerEm gives the number of ems
  867. // *assuming* a font size of ptPerEm (normal size, normal style).
  868. const ptPerUnit = {
  869. // https://en.wikibooks.org/wiki/LaTeX/Lengths and
  870. // https://tex.stackexchange.com/a/8263
  871. "pt": 1,
  872. // TeX point
  873. "mm": 7227 / 2540,
  874. // millimeter
  875. "cm": 7227 / 254,
  876. // centimeter
  877. "in": 72.27,
  878. // inch
  879. "bp": 803 / 800,
  880. // big (PostScript) points
  881. "pc": 12,
  882. // pica
  883. "dd": 1238 / 1157,
  884. // didot
  885. "cc": 14856 / 1157,
  886. // cicero (12 didot)
  887. "nd": 685 / 642,
  888. // new didot
  889. "nc": 1370 / 107,
  890. // new cicero (12 new didot)
  891. "sp": 1 / 65536,
  892. // scaled point (TeX's internal smallest unit)
  893. // https://tex.stackexchange.com/a/41371
  894. "px": 803 / 800 // \pdfpxdimen defaults to 1 bp in pdfTeX and LuaTeX
  895. };
  896. // Dictionary of relative units, for fast validity testing.
  897. const relativeUnit = {
  898. "ex": true,
  899. "em": true,
  900. "mu": true
  901. };
  902. /**
  903. * Determine whether the specified unit (either a string defining the unit
  904. * or a "size" parse node containing a unit field) is valid.
  905. */
  906. const validUnit = function (unit) {
  907. if (typeof unit !== "string") {
  908. unit = unit.unit;
  909. }
  910. return unit in ptPerUnit || unit in relativeUnit || unit === "ex";
  911. };
  912. /*
  913. * Convert a "size" parse node (with numeric "number" and string "unit" fields,
  914. * as parsed by functions.js argType "size") into a CSS em value for the
  915. * current style/scale. `options` gives the current options.
  916. */
  917. const calculateSize = function (sizeValue, options) {
  918. let scale;
  919. if (sizeValue.unit in ptPerUnit) {
  920. // Absolute units
  921. scale = ptPerUnit[sizeValue.unit] // Convert unit to pt
  922. / options.fontMetrics().ptPerEm // Convert pt to CSS em
  923. / options.sizeMultiplier; // Unscale to make absolute units
  924. } else if (sizeValue.unit === "mu") {
  925. // `mu` units scale with scriptstyle/scriptscriptstyle.
  926. scale = options.fontMetrics().cssEmPerMu;
  927. } else {
  928. // Other relative units always refer to the *textstyle* font
  929. // in the current size.
  930. let unitOptions;
  931. if (options.style.isTight()) {
  932. // isTight() means current style is script/scriptscript.
  933. unitOptions = options.havingStyle(options.style.text());
  934. } else {
  935. unitOptions = options;
  936. }
  937. // TODO: In TeX these units are relative to the quad of the current
  938. // *text* font, e.g. cmr10. KaTeX instead uses values from the
  939. // comparably-sized *Computer Modern symbol* font. At 10pt, these
  940. // match. At 7pt and 5pt, they differ: cmr7=1.138894, cmsy7=1.170641;
  941. // cmr5=1.361133, cmsy5=1.472241. Consider $\scriptsize a\kern1emb$.
  942. // TeX \showlists shows a kern of 1.13889 * fontsize;
  943. // KaTeX shows a kern of 1.171 * fontsize.
  944. if (sizeValue.unit === "ex") {
  945. scale = unitOptions.fontMetrics().xHeight;
  946. } else if (sizeValue.unit === "em") {
  947. scale = unitOptions.fontMetrics().quad;
  948. } else {
  949. throw new src_ParseError("Invalid unit: '" + sizeValue.unit + "'");
  950. }
  951. if (unitOptions !== options) {
  952. scale *= unitOptions.sizeMultiplier / options.sizeMultiplier;
  953. }
  954. }
  955. return Math.min(sizeValue.number * scale, options.maxSize);
  956. };
  957. /**
  958. * Round `n` to 4 decimal places, or to the nearest 1/10,000th em. See
  959. * https://github.com/KaTeX/KaTeX/pull/2460.
  960. */
  961. const makeEm = function (n) {
  962. return +n.toFixed(4) + "em";
  963. };
  964. ;// ./src/domTree.ts
  965. /**
  966. * These objects store the data about the DOM nodes we create, as well as some
  967. * extra data. They can then be transformed into real DOM nodes with the
  968. * `toNode` function or HTML markup using `toMarkup`. They are useful for both
  969. * storing extra properties on the nodes, as well as providing a way to easily
  970. * work with the DOM.
  971. *
  972. * Similar functions for working with MathML nodes exist in mathMLTree.js.
  973. *
  974. * TODO: refactor `span` and `anchor` into common superclass when
  975. * target environments support class inheritance
  976. */
  977. /**
  978. * Create an HTML className based on a list of classes. In addition to joining
  979. * with spaces, we also remove empty classes.
  980. */
  981. const createClass = function (classes) {
  982. return classes.filter(cls => cls).join(" ");
  983. };
  984. const initNode = function (classes, options, style) {
  985. this.classes = classes || [];
  986. this.attributes = {};
  987. this.height = 0;
  988. this.depth = 0;
  989. this.maxFontSize = 0;
  990. this.style = style || {};
  991. if (options) {
  992. if (options.style.isTight()) {
  993. this.classes.push("mtight");
  994. }
  995. const color = options.getColor();
  996. if (color) {
  997. this.style.color = color;
  998. }
  999. }
  1000. };
  1001. /**
  1002. * Convert into an HTML node
  1003. */
  1004. const toNode = function (tagName) {
  1005. const node = document.createElement(tagName);
  1006. // Apply the class
  1007. node.className = createClass(this.classes);
  1008. // Apply inline styles
  1009. for (const key of Object.keys(this.style)) {
  1010. node.style[key] = this.style[key];
  1011. }
  1012. // Apply attributes
  1013. for (const attr of Object.keys(this.attributes)) {
  1014. node.setAttribute(attr, this.attributes[attr]);
  1015. }
  1016. // Append the children, also as HTML nodes
  1017. for (let i = 0; i < this.children.length; i++) {
  1018. node.appendChild(this.children[i].toNode());
  1019. }
  1020. return node;
  1021. };
  1022. /**
  1023. * https://w3c.github.io/html-reference/syntax.html#syntax-attributes
  1024. *
  1025. * > Attribute Names must consist of one or more characters
  1026. * other than the space characters, U+0000 NULL,
  1027. * '"', "'", ">", "/", "=", the control characters,
  1028. * and any characters that are not defined by Unicode.
  1029. */
  1030. const invalidAttributeNameRegex = /[\s"'>/=\x00-\x1f]/;
  1031. /**
  1032. * Convert into an HTML markup string
  1033. */
  1034. const toMarkup = function (tagName) {
  1035. let markup = "<" + tagName;
  1036. // Add the class
  1037. if (this.classes.length) {
  1038. markup += " class=\"" + utils_escape(createClass(this.classes)) + "\"";
  1039. }
  1040. let styles = "";
  1041. // Add the styles, after hyphenation
  1042. for (const key of Object.keys(this.style)) {
  1043. styles += hyphenate(key) + ":" + this.style[key] + ";";
  1044. }
  1045. if (styles) {
  1046. markup += " style=\"" + utils_escape(styles) + "\"";
  1047. }
  1048. // Add the attributes
  1049. for (const attr of Object.keys(this.attributes)) {
  1050. if (invalidAttributeNameRegex.test(attr)) {
  1051. throw new src_ParseError("Invalid attribute name '" + attr + "'");
  1052. }
  1053. markup += " " + attr + "=\"" + utils_escape(this.attributes[attr]) + "\"";
  1054. }
  1055. markup += ">";
  1056. // Add the markup of the children, also as markup
  1057. for (let i = 0; i < this.children.length; i++) {
  1058. markup += this.children[i].toMarkup();
  1059. }
  1060. markup += "</" + tagName + ">";
  1061. return markup;
  1062. };
  1063. // Making the type below exact with all optional fields doesn't work due to
  1064. // - https://github.com/facebook/flow/issues/4582
  1065. // - https://github.com/facebook/flow/issues/5688
  1066. // However, since *all* fields are optional, $Shape<> works as suggested in 5688
  1067. // above.
  1068. // This type does not include all CSS properties. Additional properties should
  1069. // be added as needed.
  1070. // Span wrapping other DOM nodes.
  1071. // Span wrapping an SVG node.
  1072. /**
  1073. * This node represents a span node, with a className, a list of children, and
  1074. * an inline style. It also contains information about its height, depth, and
  1075. * maxFontSize.
  1076. *
  1077. * Represents two types with different uses: SvgSpan to wrap an SVG and DomSpan
  1078. * otherwise. This typesafety is important when HTML builders access a span's
  1079. * children.
  1080. */
  1081. class Span {
  1082. constructor(classes, children, options, style) {
  1083. initNode.call(this, classes, options, style);
  1084. this.children = children || [];
  1085. }
  1086. /**
  1087. * Sets an arbitrary attribute on the span. Warning: use this wisely. Not
  1088. * all browsers support attributes the same, and having too many custom
  1089. * attributes is probably bad.
  1090. */
  1091. setAttribute(attribute, value) {
  1092. this.attributes[attribute] = value;
  1093. }
  1094. hasClass(className) {
  1095. return this.classes.includes(className);
  1096. }
  1097. toNode() {
  1098. return toNode.call(this, "span");
  1099. }
  1100. toMarkup() {
  1101. return toMarkup.call(this, "span");
  1102. }
  1103. }
  1104. /**
  1105. * This node represents an anchor (<a>) element with a hyperlink. See `span`
  1106. * for further details.
  1107. */
  1108. class Anchor {
  1109. constructor(href, classes, children, options) {
  1110. initNode.call(this, classes, options);
  1111. this.children = children || [];
  1112. this.setAttribute('href', href);
  1113. }
  1114. setAttribute(attribute, value) {
  1115. this.attributes[attribute] = value;
  1116. }
  1117. hasClass(className) {
  1118. return this.classes.includes(className);
  1119. }
  1120. toNode() {
  1121. return toNode.call(this, "a");
  1122. }
  1123. toMarkup() {
  1124. return toMarkup.call(this, "a");
  1125. }
  1126. }
  1127. /**
  1128. * This node represents an image embed (<img>) element.
  1129. */
  1130. class Img {
  1131. constructor(src, alt, style) {
  1132. this.alt = alt;
  1133. this.src = src;
  1134. this.classes = ["mord"];
  1135. this.height = 0;
  1136. this.depth = 0;
  1137. this.maxFontSize = 0;
  1138. this.style = style;
  1139. }
  1140. hasClass(className) {
  1141. return this.classes.includes(className);
  1142. }
  1143. toNode() {
  1144. const node = document.createElement("img");
  1145. node.src = this.src;
  1146. node.alt = this.alt;
  1147. node.className = "mord";
  1148. // Apply inline styles
  1149. for (const key of Object.keys(this.style)) {
  1150. node.style[key] = this.style[key];
  1151. }
  1152. return node;
  1153. }
  1154. toMarkup() {
  1155. let markup = "<img src=\"" + utils_escape(this.src) + "\"" + (" alt=\"" + utils_escape(this.alt) + "\"");
  1156. // Add the styles, after hyphenation
  1157. let styles = "";
  1158. for (const key of Object.keys(this.style)) {
  1159. styles += hyphenate(key) + ":" + this.style[key] + ";";
  1160. }
  1161. if (styles) {
  1162. markup += " style=\"" + utils_escape(styles) + "\"";
  1163. }
  1164. markup += "'/>";
  1165. return markup;
  1166. }
  1167. }
  1168. const iCombinations = {
  1169. 'î': '\u0131\u0302',
  1170. 'ï': '\u0131\u0308',
  1171. 'í': '\u0131\u0301',
  1172. // 'ī': '\u0131\u0304', // enable when we add Extended Latin
  1173. 'ì': '\u0131\u0300'
  1174. };
  1175. /**
  1176. * A symbol node contains information about a single symbol. It either renders
  1177. * to a single text node, or a span with a single text node in it, depending on
  1178. * whether it has CSS classes, styles, or needs italic correction.
  1179. */
  1180. class SymbolNode {
  1181. constructor(text, height, depth, italic, skew, width, classes, style) {
  1182. this.text = text;
  1183. this.height = height || 0;
  1184. this.depth = depth || 0;
  1185. this.italic = italic || 0;
  1186. this.skew = skew || 0;
  1187. this.width = width || 0;
  1188. this.classes = classes || [];
  1189. this.style = style || {};
  1190. this.maxFontSize = 0;
  1191. // Mark text from non-Latin scripts with specific classes so that we
  1192. // can specify which fonts to use. This allows us to render these
  1193. // characters with a serif font in situations where the browser would
  1194. // either default to a sans serif or render a placeholder character.
  1195. // We use CSS class names like cjk_fallback, hangul_fallback and
  1196. // brahmic_fallback. See ./unicodeScripts.js for the set of possible
  1197. // script names
  1198. const script = scriptFromCodepoint(this.text.charCodeAt(0));
  1199. if (script) {
  1200. this.classes.push(script + "_fallback");
  1201. }
  1202. if (/[îïíì]/.test(this.text)) {
  1203. // add ī when we add Extended Latin
  1204. this.text = iCombinations[this.text];
  1205. }
  1206. }
  1207. hasClass(className) {
  1208. return this.classes.includes(className);
  1209. }
  1210. /**
  1211. * Creates a text node or span from a symbol node. Note that a span is only
  1212. * created if it is needed.
  1213. */
  1214. toNode() {
  1215. const node = document.createTextNode(this.text);
  1216. let span = null;
  1217. if (this.italic > 0) {
  1218. span = document.createElement("span");
  1219. span.style.marginRight = makeEm(this.italic);
  1220. }
  1221. if (this.classes.length > 0) {
  1222. span = span || document.createElement("span");
  1223. span.className = createClass(this.classes);
  1224. }
  1225. for (const key of Object.keys(this.style)) {
  1226. span = span || document.createElement("span");
  1227. span.style[key] = this.style[key];
  1228. }
  1229. if (span) {
  1230. span.appendChild(node);
  1231. return span;
  1232. } else {
  1233. return node;
  1234. }
  1235. }
  1236. /**
  1237. * Creates markup for a symbol node.
  1238. */
  1239. toMarkup() {
  1240. // TODO(alpert): More duplication than I'd like from
  1241. // span.prototype.toMarkup and symbolNode.prototype.toNode...
  1242. let needsSpan = false;
  1243. let markup = "<span";
  1244. if (this.classes.length) {
  1245. needsSpan = true;
  1246. markup += " class=\"";
  1247. markup += utils_escape(createClass(this.classes));
  1248. markup += "\"";
  1249. }
  1250. let styles = "";
  1251. if (this.italic > 0) {
  1252. styles += "margin-right:" + makeEm(this.italic) + ";";
  1253. }
  1254. for (const key of Object.keys(this.style)) {
  1255. styles += hyphenate(key) + ":" + this.style[key] + ";";
  1256. }
  1257. if (styles) {
  1258. needsSpan = true;
  1259. markup += " style=\"" + utils_escape(styles) + "\"";
  1260. }
  1261. const escaped = utils_escape(this.text);
  1262. if (needsSpan) {
  1263. markup += ">";
  1264. markup += escaped;
  1265. markup += "</span>";
  1266. return markup;
  1267. } else {
  1268. return escaped;
  1269. }
  1270. }
  1271. }
  1272. /**
  1273. * SVG nodes are used to render stretchy wide elements.
  1274. */
  1275. class SvgNode {
  1276. constructor(children, attributes) {
  1277. this.children = children || [];
  1278. this.attributes = attributes || {};
  1279. }
  1280. toNode() {
  1281. const svgNS = "http://www.w3.org/2000/svg";
  1282. const node = document.createElementNS(svgNS, "svg");
  1283. // Apply attributes
  1284. for (const attr of Object.keys(this.attributes)) {
  1285. node.setAttribute(attr, this.attributes[attr]);
  1286. }
  1287. for (let i = 0; i < this.children.length; i++) {
  1288. node.appendChild(this.children[i].toNode());
  1289. }
  1290. return node;
  1291. }
  1292. toMarkup() {
  1293. let markup = "<svg xmlns=\"http://www.w3.org/2000/svg\"";
  1294. // Apply attributes
  1295. for (const attr of Object.keys(this.attributes)) {
  1296. markup += " " + attr + "=\"" + utils_escape(this.attributes[attr]) + "\"";
  1297. }
  1298. markup += ">";
  1299. for (let i = 0; i < this.children.length; i++) {
  1300. markup += this.children[i].toMarkup();
  1301. }
  1302. markup += "</svg>";
  1303. return markup;
  1304. }
  1305. }
  1306. class PathNode {
  1307. constructor(pathName, alternate) {
  1308. this.pathName = pathName;
  1309. this.alternate = alternate; // Used only for \sqrt, \phase, & tall delims
  1310. }
  1311. toNode() {
  1312. const svgNS = "http://www.w3.org/2000/svg";
  1313. const node = document.createElementNS(svgNS, "path");
  1314. if (this.alternate) {
  1315. node.setAttribute("d", this.alternate);
  1316. } else {
  1317. node.setAttribute("d", path[this.pathName]);
  1318. }
  1319. return node;
  1320. }
  1321. toMarkup() {
  1322. if (this.alternate) {
  1323. return "<path d=\"" + utils_escape(this.alternate) + "\"/>";
  1324. } else {
  1325. return "<path d=\"" + utils_escape(path[this.pathName]) + "\"/>";
  1326. }
  1327. }
  1328. }
  1329. class LineNode {
  1330. constructor(attributes) {
  1331. this.attributes = attributes || {};
  1332. }
  1333. toNode() {
  1334. const svgNS = "http://www.w3.org/2000/svg";
  1335. const node = document.createElementNS(svgNS, "line");
  1336. // Apply attributes
  1337. for (const attr of Object.keys(this.attributes)) {
  1338. node.setAttribute(attr, this.attributes[attr]);
  1339. }
  1340. return node;
  1341. }
  1342. toMarkup() {
  1343. let markup = "<line";
  1344. for (const attr of Object.keys(this.attributes)) {
  1345. markup += " " + attr + "=\"" + utils_escape(this.attributes[attr]) + "\"";
  1346. }
  1347. markup += "/>";
  1348. return markup;
  1349. }
  1350. }
  1351. function assertSymbolDomNode(group) {
  1352. if (group instanceof SymbolNode) {
  1353. return group;
  1354. } else {
  1355. throw new Error("Expected symbolNode but got " + String(group) + ".");
  1356. }
  1357. }
  1358. function assertSpan(group) {
  1359. if (group instanceof Span) {
  1360. return group;
  1361. } else {
  1362. throw new Error("Expected span<HtmlDomNode> but got " + String(group) + ".");
  1363. }
  1364. }
  1365. /**
  1366. * Whether an HtmlDomNode has HtmlDomNode children.
  1367. * HtmlDomNode is a base type representing a union of
  1368. * SymbolNode, SvgSpan, DomSpan, Anchor, and documentFragment.
  1369. * In the last three cases, the children are HtmlDomNode[].
  1370. */
  1371. const hasHtmlDomChildren = node => node instanceof Span || node instanceof Anchor || node instanceof DocumentFragment;
  1372. ;// ./src/fontMetricsData.js
  1373. // This file is GENERATED by buildMetrics.sh. DO NOT MODIFY.
  1374. /* harmony default export */ var fontMetricsData = ({
  1375. "AMS-Regular": {
  1376. "32": [0, 0, 0, 0, 0.25],
  1377. "65": [0, 0.68889, 0, 0, 0.72222],
  1378. "66": [0, 0.68889, 0, 0, 0.66667],
  1379. "67": [0, 0.68889, 0, 0, 0.72222],
  1380. "68": [0, 0.68889, 0, 0, 0.72222],
  1381. "69": [0, 0.68889, 0, 0, 0.66667],
  1382. "70": [0, 0.68889, 0, 0, 0.61111],
  1383. "71": [0, 0.68889, 0, 0, 0.77778],
  1384. "72": [0, 0.68889, 0, 0, 0.77778],
  1385. "73": [0, 0.68889, 0, 0, 0.38889],
  1386. "74": [0.16667, 0.68889, 0, 0, 0.5],
  1387. "75": [0, 0.68889, 0, 0, 0.77778],
  1388. "76": [0, 0.68889, 0, 0, 0.66667],
  1389. "77": [0, 0.68889, 0, 0, 0.94445],
  1390. "78": [0, 0.68889, 0, 0, 0.72222],
  1391. "79": [0.16667, 0.68889, 0, 0, 0.77778],
  1392. "80": [0, 0.68889, 0, 0, 0.61111],
  1393. "81": [0.16667, 0.68889, 0, 0, 0.77778],
  1394. "82": [0, 0.68889, 0, 0, 0.72222],
  1395. "83": [0, 0.68889, 0, 0, 0.55556],
  1396. "84": [0, 0.68889, 0, 0, 0.66667],
  1397. "85": [0, 0.68889, 0, 0, 0.72222],
  1398. "86": [0, 0.68889, 0, 0, 0.72222],
  1399. "87": [0, 0.68889, 0, 0, 1.0],
  1400. "88": [0, 0.68889, 0, 0, 0.72222],
  1401. "89": [0, 0.68889, 0, 0, 0.72222],
  1402. "90": [0, 0.68889, 0, 0, 0.66667],
  1403. "107": [0, 0.68889, 0, 0, 0.55556],
  1404. "160": [0, 0, 0, 0, 0.25],
  1405. "165": [0, 0.675, 0.025, 0, 0.75],
  1406. "174": [0.15559, 0.69224, 0, 0, 0.94666],
  1407. "240": [0, 0.68889, 0, 0, 0.55556],
  1408. "295": [0, 0.68889, 0, 0, 0.54028],
  1409. "710": [0, 0.825, 0, 0, 2.33334],
  1410. "732": [0, 0.9, 0, 0, 2.33334],
  1411. "770": [0, 0.825, 0, 0, 2.33334],
  1412. "771": [0, 0.9, 0, 0, 2.33334],
  1413. "989": [0.08167, 0.58167, 0, 0, 0.77778],
  1414. "1008": [0, 0.43056, 0.04028, 0, 0.66667],
  1415. "8245": [0, 0.54986, 0, 0, 0.275],
  1416. "8463": [0, 0.68889, 0, 0, 0.54028],
  1417. "8487": [0, 0.68889, 0, 0, 0.72222],
  1418. "8498": [0, 0.68889, 0, 0, 0.55556],
  1419. "8502": [0, 0.68889, 0, 0, 0.66667],
  1420. "8503": [0, 0.68889, 0, 0, 0.44445],
  1421. "8504": [0, 0.68889, 0, 0, 0.66667],
  1422. "8513": [0, 0.68889, 0, 0, 0.63889],
  1423. "8592": [-0.03598, 0.46402, 0, 0, 0.5],
  1424. "8594": [-0.03598, 0.46402, 0, 0, 0.5],
  1425. "8602": [-0.13313, 0.36687, 0, 0, 1.0],
  1426. "8603": [-0.13313, 0.36687, 0, 0, 1.0],
  1427. "8606": [0.01354, 0.52239, 0, 0, 1.0],
  1428. "8608": [0.01354, 0.52239, 0, 0, 1.0],
  1429. "8610": [0.01354, 0.52239, 0, 0, 1.11111],
  1430. "8611": [0.01354, 0.52239, 0, 0, 1.11111],
  1431. "8619": [0, 0.54986, 0, 0, 1.0],
  1432. "8620": [0, 0.54986, 0, 0, 1.0],
  1433. "8621": [-0.13313, 0.37788, 0, 0, 1.38889],
  1434. "8622": [-0.13313, 0.36687, 0, 0, 1.0],
  1435. "8624": [0, 0.69224, 0, 0, 0.5],
  1436. "8625": [0, 0.69224, 0, 0, 0.5],
  1437. "8630": [0, 0.43056, 0, 0, 1.0],
  1438. "8631": [0, 0.43056, 0, 0, 1.0],
  1439. "8634": [0.08198, 0.58198, 0, 0, 0.77778],
  1440. "8635": [0.08198, 0.58198, 0, 0, 0.77778],
  1441. "8638": [0.19444, 0.69224, 0, 0, 0.41667],
  1442. "8639": [0.19444, 0.69224, 0, 0, 0.41667],
  1443. "8642": [0.19444, 0.69224, 0, 0, 0.41667],
  1444. "8643": [0.19444, 0.69224, 0, 0, 0.41667],
  1445. "8644": [0.1808, 0.675, 0, 0, 1.0],
  1446. "8646": [0.1808, 0.675, 0, 0, 1.0],
  1447. "8647": [0.1808, 0.675, 0, 0, 1.0],
  1448. "8648": [0.19444, 0.69224, 0, 0, 0.83334],
  1449. "8649": [0.1808, 0.675, 0, 0, 1.0],
  1450. "8650": [0.19444, 0.69224, 0, 0, 0.83334],
  1451. "8651": [0.01354, 0.52239, 0, 0, 1.0],
  1452. "8652": [0.01354, 0.52239, 0, 0, 1.0],
  1453. "8653": [-0.13313, 0.36687, 0, 0, 1.0],
  1454. "8654": [-0.13313, 0.36687, 0, 0, 1.0],
  1455. "8655": [-0.13313, 0.36687, 0, 0, 1.0],
  1456. "8666": [0.13667, 0.63667, 0, 0, 1.0],
  1457. "8667": [0.13667, 0.63667, 0, 0, 1.0],
  1458. "8669": [-0.13313, 0.37788, 0, 0, 1.0],
  1459. "8672": [-0.064, 0.437, 0, 0, 1.334],
  1460. "8674": [-0.064, 0.437, 0, 0, 1.334],
  1461. "8705": [0, 0.825, 0, 0, 0.5],
  1462. "8708": [0, 0.68889, 0, 0, 0.55556],
  1463. "8709": [0.08167, 0.58167, 0, 0, 0.77778],
  1464. "8717": [0, 0.43056, 0, 0, 0.42917],
  1465. "8722": [-0.03598, 0.46402, 0, 0, 0.5],
  1466. "8724": [0.08198, 0.69224, 0, 0, 0.77778],
  1467. "8726": [0.08167, 0.58167, 0, 0, 0.77778],
  1468. "8733": [0, 0.69224, 0, 0, 0.77778],
  1469. "8736": [0, 0.69224, 0, 0, 0.72222],
  1470. "8737": [0, 0.69224, 0, 0, 0.72222],
  1471. "8738": [0.03517, 0.52239, 0, 0, 0.72222],
  1472. "8739": [0.08167, 0.58167, 0, 0, 0.22222],
  1473. "8740": [0.25142, 0.74111, 0, 0, 0.27778],
  1474. "8741": [0.08167, 0.58167, 0, 0, 0.38889],
  1475. "8742": [0.25142, 0.74111, 0, 0, 0.5],
  1476. "8756": [0, 0.69224, 0, 0, 0.66667],
  1477. "8757": [0, 0.69224, 0, 0, 0.66667],
  1478. "8764": [-0.13313, 0.36687, 0, 0, 0.77778],
  1479. "8765": [-0.13313, 0.37788, 0, 0, 0.77778],
  1480. "8769": [-0.13313, 0.36687, 0, 0, 0.77778],
  1481. "8770": [-0.03625, 0.46375, 0, 0, 0.77778],
  1482. "8774": [0.30274, 0.79383, 0, 0, 0.77778],
  1483. "8776": [-0.01688, 0.48312, 0, 0, 0.77778],
  1484. "8778": [0.08167, 0.58167, 0, 0, 0.77778],
  1485. "8782": [0.06062, 0.54986, 0, 0, 0.77778],
  1486. "8783": [0.06062, 0.54986, 0, 0, 0.77778],
  1487. "8785": [0.08198, 0.58198, 0, 0, 0.77778],
  1488. "8786": [0.08198, 0.58198, 0, 0, 0.77778],
  1489. "8787": [0.08198, 0.58198, 0, 0, 0.77778],
  1490. "8790": [0, 0.69224, 0, 0, 0.77778],
  1491. "8791": [0.22958, 0.72958, 0, 0, 0.77778],
  1492. "8796": [0.08198, 0.91667, 0, 0, 0.77778],
  1493. "8806": [0.25583, 0.75583, 0, 0, 0.77778],
  1494. "8807": [0.25583, 0.75583, 0, 0, 0.77778],
  1495. "8808": [0.25142, 0.75726, 0, 0, 0.77778],
  1496. "8809": [0.25142, 0.75726, 0, 0, 0.77778],
  1497. "8812": [0.25583, 0.75583, 0, 0, 0.5],
  1498. "8814": [0.20576, 0.70576, 0, 0, 0.77778],
  1499. "8815": [0.20576, 0.70576, 0, 0, 0.77778],
  1500. "8816": [0.30274, 0.79383, 0, 0, 0.77778],
  1501. "8817": [0.30274, 0.79383, 0, 0, 0.77778],
  1502. "8818": [0.22958, 0.72958, 0, 0, 0.77778],
  1503. "8819": [0.22958, 0.72958, 0, 0, 0.77778],
  1504. "8822": [0.1808, 0.675, 0, 0, 0.77778],
  1505. "8823": [0.1808, 0.675, 0, 0, 0.77778],
  1506. "8828": [0.13667, 0.63667, 0, 0, 0.77778],
  1507. "8829": [0.13667, 0.63667, 0, 0, 0.77778],
  1508. "8830": [0.22958, 0.72958, 0, 0, 0.77778],
  1509. "8831": [0.22958, 0.72958, 0, 0, 0.77778],
  1510. "8832": [0.20576, 0.70576, 0, 0, 0.77778],
  1511. "8833": [0.20576, 0.70576, 0, 0, 0.77778],
  1512. "8840": [0.30274, 0.79383, 0, 0, 0.77778],
  1513. "8841": [0.30274, 0.79383, 0, 0, 0.77778],
  1514. "8842": [0.13597, 0.63597, 0, 0, 0.77778],
  1515. "8843": [0.13597, 0.63597, 0, 0, 0.77778],
  1516. "8847": [0.03517, 0.54986, 0, 0, 0.77778],
  1517. "8848": [0.03517, 0.54986, 0, 0, 0.77778],
  1518. "8858": [0.08198, 0.58198, 0, 0, 0.77778],
  1519. "8859": [0.08198, 0.58198, 0, 0, 0.77778],
  1520. "8861": [0.08198, 0.58198, 0, 0, 0.77778],
  1521. "8862": [0, 0.675, 0, 0, 0.77778],
  1522. "8863": [0, 0.675, 0, 0, 0.77778],
  1523. "8864": [0, 0.675, 0, 0, 0.77778],
  1524. "8865": [0, 0.675, 0, 0, 0.77778],
  1525. "8872": [0, 0.69224, 0, 0, 0.61111],
  1526. "8873": [0, 0.69224, 0, 0, 0.72222],
  1527. "8874": [0, 0.69224, 0, 0, 0.88889],
  1528. "8876": [0, 0.68889, 0, 0, 0.61111],
  1529. "8877": [0, 0.68889, 0, 0, 0.61111],
  1530. "8878": [0, 0.68889, 0, 0, 0.72222],
  1531. "8879": [0, 0.68889, 0, 0, 0.72222],
  1532. "8882": [0.03517, 0.54986, 0, 0, 0.77778],
  1533. "8883": [0.03517, 0.54986, 0, 0, 0.77778],
  1534. "8884": [0.13667, 0.63667, 0, 0, 0.77778],
  1535. "8885": [0.13667, 0.63667, 0, 0, 0.77778],
  1536. "8888": [0, 0.54986, 0, 0, 1.11111],
  1537. "8890": [0.19444, 0.43056, 0, 0, 0.55556],
  1538. "8891": [0.19444, 0.69224, 0, 0, 0.61111],
  1539. "8892": [0.19444, 0.69224, 0, 0, 0.61111],
  1540. "8901": [0, 0.54986, 0, 0, 0.27778],
  1541. "8903": [0.08167, 0.58167, 0, 0, 0.77778],
  1542. "8905": [0.08167, 0.58167, 0, 0, 0.77778],
  1543. "8906": [0.08167, 0.58167, 0, 0, 0.77778],
  1544. "8907": [0, 0.69224, 0, 0, 0.77778],
  1545. "8908": [0, 0.69224, 0, 0, 0.77778],
  1546. "8909": [-0.03598, 0.46402, 0, 0, 0.77778],
  1547. "8910": [0, 0.54986, 0, 0, 0.76042],
  1548. "8911": [0, 0.54986, 0, 0, 0.76042],
  1549. "8912": [0.03517, 0.54986, 0, 0, 0.77778],
  1550. "8913": [0.03517, 0.54986, 0, 0, 0.77778],
  1551. "8914": [0, 0.54986, 0, 0, 0.66667],
  1552. "8915": [0, 0.54986, 0, 0, 0.66667],
  1553. "8916": [0, 0.69224, 0, 0, 0.66667],
  1554. "8918": [0.0391, 0.5391, 0, 0, 0.77778],
  1555. "8919": [0.0391, 0.5391, 0, 0, 0.77778],
  1556. "8920": [0.03517, 0.54986, 0, 0, 1.33334],
  1557. "8921": [0.03517, 0.54986, 0, 0, 1.33334],
  1558. "8922": [0.38569, 0.88569, 0, 0, 0.77778],
  1559. "8923": [0.38569, 0.88569, 0, 0, 0.77778],
  1560. "8926": [0.13667, 0.63667, 0, 0, 0.77778],
  1561. "8927": [0.13667, 0.63667, 0, 0, 0.77778],
  1562. "8928": [0.30274, 0.79383, 0, 0, 0.77778],
  1563. "8929": [0.30274, 0.79383, 0, 0, 0.77778],
  1564. "8934": [0.23222, 0.74111, 0, 0, 0.77778],
  1565. "8935": [0.23222, 0.74111, 0, 0, 0.77778],
  1566. "8936": [0.23222, 0.74111, 0, 0, 0.77778],
  1567. "8937": [0.23222, 0.74111, 0, 0, 0.77778],
  1568. "8938": [0.20576, 0.70576, 0, 0, 0.77778],
  1569. "8939": [0.20576, 0.70576, 0, 0, 0.77778],
  1570. "8940": [0.30274, 0.79383, 0, 0, 0.77778],
  1571. "8941": [0.30274, 0.79383, 0, 0, 0.77778],
  1572. "8994": [0.19444, 0.69224, 0, 0, 0.77778],
  1573. "8995": [0.19444, 0.69224, 0, 0, 0.77778],
  1574. "9416": [0.15559, 0.69224, 0, 0, 0.90222],
  1575. "9484": [0, 0.69224, 0, 0, 0.5],
  1576. "9488": [0, 0.69224, 0, 0, 0.5],
  1577. "9492": [0, 0.37788, 0, 0, 0.5],
  1578. "9496": [0, 0.37788, 0, 0, 0.5],
  1579. "9585": [0.19444, 0.68889, 0, 0, 0.88889],
  1580. "9586": [0.19444, 0.74111, 0, 0, 0.88889],
  1581. "9632": [0, 0.675, 0, 0, 0.77778],
  1582. "9633": [0, 0.675, 0, 0, 0.77778],
  1583. "9650": [0, 0.54986, 0, 0, 0.72222],
  1584. "9651": [0, 0.54986, 0, 0, 0.72222],
  1585. "9654": [0.03517, 0.54986, 0, 0, 0.77778],
  1586. "9660": [0, 0.54986, 0, 0, 0.72222],
  1587. "9661": [0, 0.54986, 0, 0, 0.72222],
  1588. "9664": [0.03517, 0.54986, 0, 0, 0.77778],
  1589. "9674": [0.11111, 0.69224, 0, 0, 0.66667],
  1590. "9733": [0.19444, 0.69224, 0, 0, 0.94445],
  1591. "10003": [0, 0.69224, 0, 0, 0.83334],
  1592. "10016": [0, 0.69224, 0, 0, 0.83334],
  1593. "10731": [0.11111, 0.69224, 0, 0, 0.66667],
  1594. "10846": [0.19444, 0.75583, 0, 0, 0.61111],
  1595. "10877": [0.13667, 0.63667, 0, 0, 0.77778],
  1596. "10878": [0.13667, 0.63667, 0, 0, 0.77778],
  1597. "10885": [0.25583, 0.75583, 0, 0, 0.77778],
  1598. "10886": [0.25583, 0.75583, 0, 0, 0.77778],
  1599. "10887": [0.13597, 0.63597, 0, 0, 0.77778],
  1600. "10888": [0.13597, 0.63597, 0, 0, 0.77778],
  1601. "10889": [0.26167, 0.75726, 0, 0, 0.77778],
  1602. "10890": [0.26167, 0.75726, 0, 0, 0.77778],
  1603. "10891": [0.48256, 0.98256, 0, 0, 0.77778],
  1604. "10892": [0.48256, 0.98256, 0, 0, 0.77778],
  1605. "10901": [0.13667, 0.63667, 0, 0, 0.77778],
  1606. "10902": [0.13667, 0.63667, 0, 0, 0.77778],
  1607. "10933": [0.25142, 0.75726, 0, 0, 0.77778],
  1608. "10934": [0.25142, 0.75726, 0, 0, 0.77778],
  1609. "10935": [0.26167, 0.75726, 0, 0, 0.77778],
  1610. "10936": [0.26167, 0.75726, 0, 0, 0.77778],
  1611. "10937": [0.26167, 0.75726, 0, 0, 0.77778],
  1612. "10938": [0.26167, 0.75726, 0, 0, 0.77778],
  1613. "10949": [0.25583, 0.75583, 0, 0, 0.77778],
  1614. "10950": [0.25583, 0.75583, 0, 0, 0.77778],
  1615. "10955": [0.28481, 0.79383, 0, 0, 0.77778],
  1616. "10956": [0.28481, 0.79383, 0, 0, 0.77778],
  1617. "57350": [0.08167, 0.58167, 0, 0, 0.22222],
  1618. "57351": [0.08167, 0.58167, 0, 0, 0.38889],
  1619. "57352": [0.08167, 0.58167, 0, 0, 0.77778],
  1620. "57353": [0, 0.43056, 0.04028, 0, 0.66667],
  1621. "57356": [0.25142, 0.75726, 0, 0, 0.77778],
  1622. "57357": [0.25142, 0.75726, 0, 0, 0.77778],
  1623. "57358": [0.41951, 0.91951, 0, 0, 0.77778],
  1624. "57359": [0.30274, 0.79383, 0, 0, 0.77778],
  1625. "57360": [0.30274, 0.79383, 0, 0, 0.77778],
  1626. "57361": [0.41951, 0.91951, 0, 0, 0.77778],
  1627. "57366": [0.25142, 0.75726, 0, 0, 0.77778],
  1628. "57367": [0.25142, 0.75726, 0, 0, 0.77778],
  1629. "57368": [0.25142, 0.75726, 0, 0, 0.77778],
  1630. "57369": [0.25142, 0.75726, 0, 0, 0.77778],
  1631. "57370": [0.13597, 0.63597, 0, 0, 0.77778],
  1632. "57371": [0.13597, 0.63597, 0, 0, 0.77778]
  1633. },
  1634. "Caligraphic-Regular": {
  1635. "32": [0, 0, 0, 0, 0.25],
  1636. "65": [0, 0.68333, 0, 0.19445, 0.79847],
  1637. "66": [0, 0.68333, 0.03041, 0.13889, 0.65681],
  1638. "67": [0, 0.68333, 0.05834, 0.13889, 0.52653],
  1639. "68": [0, 0.68333, 0.02778, 0.08334, 0.77139],
  1640. "69": [0, 0.68333, 0.08944, 0.11111, 0.52778],
  1641. "70": [0, 0.68333, 0.09931, 0.11111, 0.71875],
  1642. "71": [0.09722, 0.68333, 0.0593, 0.11111, 0.59487],
  1643. "72": [0, 0.68333, 0.00965, 0.11111, 0.84452],
  1644. "73": [0, 0.68333, 0.07382, 0, 0.54452],
  1645. "74": [0.09722, 0.68333, 0.18472, 0.16667, 0.67778],
  1646. "75": [0, 0.68333, 0.01445, 0.05556, 0.76195],
  1647. "76": [0, 0.68333, 0, 0.13889, 0.68972],
  1648. "77": [0, 0.68333, 0, 0.13889, 1.2009],
  1649. "78": [0, 0.68333, 0.14736, 0.08334, 0.82049],
  1650. "79": [0, 0.68333, 0.02778, 0.11111, 0.79611],
  1651. "80": [0, 0.68333, 0.08222, 0.08334, 0.69556],
  1652. "81": [0.09722, 0.68333, 0, 0.11111, 0.81667],
  1653. "82": [0, 0.68333, 0, 0.08334, 0.8475],
  1654. "83": [0, 0.68333, 0.075, 0.13889, 0.60556],
  1655. "84": [0, 0.68333, 0.25417, 0, 0.54464],
  1656. "85": [0, 0.68333, 0.09931, 0.08334, 0.62583],
  1657. "86": [0, 0.68333, 0.08222, 0, 0.61278],
  1658. "87": [0, 0.68333, 0.08222, 0.08334, 0.98778],
  1659. "88": [0, 0.68333, 0.14643, 0.13889, 0.7133],
  1660. "89": [0.09722, 0.68333, 0.08222, 0.08334, 0.66834],
  1661. "90": [0, 0.68333, 0.07944, 0.13889, 0.72473],
  1662. "160": [0, 0, 0, 0, 0.25]
  1663. },
  1664. "Fraktur-Regular": {
  1665. "32": [0, 0, 0, 0, 0.25],
  1666. "33": [0, 0.69141, 0, 0, 0.29574],
  1667. "34": [0, 0.69141, 0, 0, 0.21471],
  1668. "38": [0, 0.69141, 0, 0, 0.73786],
  1669. "39": [0, 0.69141, 0, 0, 0.21201],
  1670. "40": [0.24982, 0.74947, 0, 0, 0.38865],
  1671. "41": [0.24982, 0.74947, 0, 0, 0.38865],
  1672. "42": [0, 0.62119, 0, 0, 0.27764],
  1673. "43": [0.08319, 0.58283, 0, 0, 0.75623],
  1674. "44": [0, 0.10803, 0, 0, 0.27764],
  1675. "45": [0.08319, 0.58283, 0, 0, 0.75623],
  1676. "46": [0, 0.10803, 0, 0, 0.27764],
  1677. "47": [0.24982, 0.74947, 0, 0, 0.50181],
  1678. "48": [0, 0.47534, 0, 0, 0.50181],
  1679. "49": [0, 0.47534, 0, 0, 0.50181],
  1680. "50": [0, 0.47534, 0, 0, 0.50181],
  1681. "51": [0.18906, 0.47534, 0, 0, 0.50181],
  1682. "52": [0.18906, 0.47534, 0, 0, 0.50181],
  1683. "53": [0.18906, 0.47534, 0, 0, 0.50181],
  1684. "54": [0, 0.69141, 0, 0, 0.50181],
  1685. "55": [0.18906, 0.47534, 0, 0, 0.50181],
  1686. "56": [0, 0.69141, 0, 0, 0.50181],
  1687. "57": [0.18906, 0.47534, 0, 0, 0.50181],
  1688. "58": [0, 0.47534, 0, 0, 0.21606],
  1689. "59": [0.12604, 0.47534, 0, 0, 0.21606],
  1690. "61": [-0.13099, 0.36866, 0, 0, 0.75623],
  1691. "63": [0, 0.69141, 0, 0, 0.36245],
  1692. "65": [0, 0.69141, 0, 0, 0.7176],
  1693. "66": [0, 0.69141, 0, 0, 0.88397],
  1694. "67": [0, 0.69141, 0, 0, 0.61254],
  1695. "68": [0, 0.69141, 0, 0, 0.83158],
  1696. "69": [0, 0.69141, 0, 0, 0.66278],
  1697. "70": [0.12604, 0.69141, 0, 0, 0.61119],
  1698. "71": [0, 0.69141, 0, 0, 0.78539],
  1699. "72": [0.06302, 0.69141, 0, 0, 0.7203],
  1700. "73": [0, 0.69141, 0, 0, 0.55448],
  1701. "74": [0.12604, 0.69141, 0, 0, 0.55231],
  1702. "75": [0, 0.69141, 0, 0, 0.66845],
  1703. "76": [0, 0.69141, 0, 0, 0.66602],
  1704. "77": [0, 0.69141, 0, 0, 1.04953],
  1705. "78": [0, 0.69141, 0, 0, 0.83212],
  1706. "79": [0, 0.69141, 0, 0, 0.82699],
  1707. "80": [0.18906, 0.69141, 0, 0, 0.82753],
  1708. "81": [0.03781, 0.69141, 0, 0, 0.82699],
  1709. "82": [0, 0.69141, 0, 0, 0.82807],
  1710. "83": [0, 0.69141, 0, 0, 0.82861],
  1711. "84": [0, 0.69141, 0, 0, 0.66899],
  1712. "85": [0, 0.69141, 0, 0, 0.64576],
  1713. "86": [0, 0.69141, 0, 0, 0.83131],
  1714. "87": [0, 0.69141, 0, 0, 1.04602],
  1715. "88": [0, 0.69141, 0, 0, 0.71922],
  1716. "89": [0.18906, 0.69141, 0, 0, 0.83293],
  1717. "90": [0.12604, 0.69141, 0, 0, 0.60201],
  1718. "91": [0.24982, 0.74947, 0, 0, 0.27764],
  1719. "93": [0.24982, 0.74947, 0, 0, 0.27764],
  1720. "94": [0, 0.69141, 0, 0, 0.49965],
  1721. "97": [0, 0.47534, 0, 0, 0.50046],
  1722. "98": [0, 0.69141, 0, 0, 0.51315],
  1723. "99": [0, 0.47534, 0, 0, 0.38946],
  1724. "100": [0, 0.62119, 0, 0, 0.49857],
  1725. "101": [0, 0.47534, 0, 0, 0.40053],
  1726. "102": [0.18906, 0.69141, 0, 0, 0.32626],
  1727. "103": [0.18906, 0.47534, 0, 0, 0.5037],
  1728. "104": [0.18906, 0.69141, 0, 0, 0.52126],
  1729. "105": [0, 0.69141, 0, 0, 0.27899],
  1730. "106": [0, 0.69141, 0, 0, 0.28088],
  1731. "107": [0, 0.69141, 0, 0, 0.38946],
  1732. "108": [0, 0.69141, 0, 0, 0.27953],
  1733. "109": [0, 0.47534, 0, 0, 0.76676],
  1734. "110": [0, 0.47534, 0, 0, 0.52666],
  1735. "111": [0, 0.47534, 0, 0, 0.48885],
  1736. "112": [0.18906, 0.52396, 0, 0, 0.50046],
  1737. "113": [0.18906, 0.47534, 0, 0, 0.48912],
  1738. "114": [0, 0.47534, 0, 0, 0.38919],
  1739. "115": [0, 0.47534, 0, 0, 0.44266],
  1740. "116": [0, 0.62119, 0, 0, 0.33301],
  1741. "117": [0, 0.47534, 0, 0, 0.5172],
  1742. "118": [0, 0.52396, 0, 0, 0.5118],
  1743. "119": [0, 0.52396, 0, 0, 0.77351],
  1744. "120": [0.18906, 0.47534, 0, 0, 0.38865],
  1745. "121": [0.18906, 0.47534, 0, 0, 0.49884],
  1746. "122": [0.18906, 0.47534, 0, 0, 0.39054],
  1747. "160": [0, 0, 0, 0, 0.25],
  1748. "8216": [0, 0.69141, 0, 0, 0.21471],
  1749. "8217": [0, 0.69141, 0, 0, 0.21471],
  1750. "58112": [0, 0.62119, 0, 0, 0.49749],
  1751. "58113": [0, 0.62119, 0, 0, 0.4983],
  1752. "58114": [0.18906, 0.69141, 0, 0, 0.33328],
  1753. "58115": [0.18906, 0.69141, 0, 0, 0.32923],
  1754. "58116": [0.18906, 0.47534, 0, 0, 0.50343],
  1755. "58117": [0, 0.69141, 0, 0, 0.33301],
  1756. "58118": [0, 0.62119, 0, 0, 0.33409],
  1757. "58119": [0, 0.47534, 0, 0, 0.50073]
  1758. },
  1759. "Main-Bold": {
  1760. "32": [0, 0, 0, 0, 0.25],
  1761. "33": [0, 0.69444, 0, 0, 0.35],
  1762. "34": [0, 0.69444, 0, 0, 0.60278],
  1763. "35": [0.19444, 0.69444, 0, 0, 0.95833],
  1764. "36": [0.05556, 0.75, 0, 0, 0.575],
  1765. "37": [0.05556, 0.75, 0, 0, 0.95833],
  1766. "38": [0, 0.69444, 0, 0, 0.89444],
  1767. "39": [0, 0.69444, 0, 0, 0.31944],
  1768. "40": [0.25, 0.75, 0, 0, 0.44722],
  1769. "41": [0.25, 0.75, 0, 0, 0.44722],
  1770. "42": [0, 0.75, 0, 0, 0.575],
  1771. "43": [0.13333, 0.63333, 0, 0, 0.89444],
  1772. "44": [0.19444, 0.15556, 0, 0, 0.31944],
  1773. "45": [0, 0.44444, 0, 0, 0.38333],
  1774. "46": [0, 0.15556, 0, 0, 0.31944],
  1775. "47": [0.25, 0.75, 0, 0, 0.575],
  1776. "48": [0, 0.64444, 0, 0, 0.575],
  1777. "49": [0, 0.64444, 0, 0, 0.575],
  1778. "50": [0, 0.64444, 0, 0, 0.575],
  1779. "51": [0, 0.64444, 0, 0, 0.575],
  1780. "52": [0, 0.64444, 0, 0, 0.575],
  1781. "53": [0, 0.64444, 0, 0, 0.575],
  1782. "54": [0, 0.64444, 0, 0, 0.575],
  1783. "55": [0, 0.64444, 0, 0, 0.575],
  1784. "56": [0, 0.64444, 0, 0, 0.575],
  1785. "57": [0, 0.64444, 0, 0, 0.575],
  1786. "58": [0, 0.44444, 0, 0, 0.31944],
  1787. "59": [0.19444, 0.44444, 0, 0, 0.31944],
  1788. "60": [0.08556, 0.58556, 0, 0, 0.89444],
  1789. "61": [-0.10889, 0.39111, 0, 0, 0.89444],
  1790. "62": [0.08556, 0.58556, 0, 0, 0.89444],
  1791. "63": [0, 0.69444, 0, 0, 0.54305],
  1792. "64": [0, 0.69444, 0, 0, 0.89444],
  1793. "65": [0, 0.68611, 0, 0, 0.86944],
  1794. "66": [0, 0.68611, 0, 0, 0.81805],
  1795. "67": [0, 0.68611, 0, 0, 0.83055],
  1796. "68": [0, 0.68611, 0, 0, 0.88194],
  1797. "69": [0, 0.68611, 0, 0, 0.75555],
  1798. "70": [0, 0.68611, 0, 0, 0.72361],
  1799. "71": [0, 0.68611, 0, 0, 0.90416],
  1800. "72": [0, 0.68611, 0, 0, 0.9],
  1801. "73": [0, 0.68611, 0, 0, 0.43611],
  1802. "74": [0, 0.68611, 0, 0, 0.59444],
  1803. "75": [0, 0.68611, 0, 0, 0.90138],
  1804. "76": [0, 0.68611, 0, 0, 0.69166],
  1805. "77": [0, 0.68611, 0, 0, 1.09166],
  1806. "78": [0, 0.68611, 0, 0, 0.9],
  1807. "79": [0, 0.68611, 0, 0, 0.86388],
  1808. "80": [0, 0.68611, 0, 0, 0.78611],
  1809. "81": [0.19444, 0.68611, 0, 0, 0.86388],
  1810. "82": [0, 0.68611, 0, 0, 0.8625],
  1811. "83": [0, 0.68611, 0, 0, 0.63889],
  1812. "84": [0, 0.68611, 0, 0, 0.8],
  1813. "85": [0, 0.68611, 0, 0, 0.88472],
  1814. "86": [0, 0.68611, 0.01597, 0, 0.86944],
  1815. "87": [0, 0.68611, 0.01597, 0, 1.18888],
  1816. "88": [0, 0.68611, 0, 0, 0.86944],
  1817. "89": [0, 0.68611, 0.02875, 0, 0.86944],
  1818. "90": [0, 0.68611, 0, 0, 0.70277],
  1819. "91": [0.25, 0.75, 0, 0, 0.31944],
  1820. "92": [0.25, 0.75, 0, 0, 0.575],
  1821. "93": [0.25, 0.75, 0, 0, 0.31944],
  1822. "94": [0, 0.69444, 0, 0, 0.575],
  1823. "95": [0.31, 0.13444, 0.03194, 0, 0.575],
  1824. "97": [0, 0.44444, 0, 0, 0.55902],
  1825. "98": [0, 0.69444, 0, 0, 0.63889],
  1826. "99": [0, 0.44444, 0, 0, 0.51111],
  1827. "100": [0, 0.69444, 0, 0, 0.63889],
  1828. "101": [0, 0.44444, 0, 0, 0.52708],
  1829. "102": [0, 0.69444, 0.10903, 0, 0.35139],
  1830. "103": [0.19444, 0.44444, 0.01597, 0, 0.575],
  1831. "104": [0, 0.69444, 0, 0, 0.63889],
  1832. "105": [0, 0.69444, 0, 0, 0.31944],
  1833. "106": [0.19444, 0.69444, 0, 0, 0.35139],
  1834. "107": [0, 0.69444, 0, 0, 0.60694],
  1835. "108": [0, 0.69444, 0, 0, 0.31944],
  1836. "109": [0, 0.44444, 0, 0, 0.95833],
  1837. "110": [0, 0.44444, 0, 0, 0.63889],
  1838. "111": [0, 0.44444, 0, 0, 0.575],
  1839. "112": [0.19444, 0.44444, 0, 0, 0.63889],
  1840. "113": [0.19444, 0.44444, 0, 0, 0.60694],
  1841. "114": [0, 0.44444, 0, 0, 0.47361],
  1842. "115": [0, 0.44444, 0, 0, 0.45361],
  1843. "116": [0, 0.63492, 0, 0, 0.44722],
  1844. "117": [0, 0.44444, 0, 0, 0.63889],
  1845. "118": [0, 0.44444, 0.01597, 0, 0.60694],
  1846. "119": [0, 0.44444, 0.01597, 0, 0.83055],
  1847. "120": [0, 0.44444, 0, 0, 0.60694],
  1848. "121": [0.19444, 0.44444, 0.01597, 0, 0.60694],
  1849. "122": [0, 0.44444, 0, 0, 0.51111],
  1850. "123": [0.25, 0.75, 0, 0, 0.575],
  1851. "124": [0.25, 0.75, 0, 0, 0.31944],
  1852. "125": [0.25, 0.75, 0, 0, 0.575],
  1853. "126": [0.35, 0.34444, 0, 0, 0.575],
  1854. "160": [0, 0, 0, 0, 0.25],
  1855. "163": [0, 0.69444, 0, 0, 0.86853],
  1856. "168": [0, 0.69444, 0, 0, 0.575],
  1857. "172": [0, 0.44444, 0, 0, 0.76666],
  1858. "176": [0, 0.69444, 0, 0, 0.86944],
  1859. "177": [0.13333, 0.63333, 0, 0, 0.89444],
  1860. "184": [0.17014, 0, 0, 0, 0.51111],
  1861. "198": [0, 0.68611, 0, 0, 1.04166],
  1862. "215": [0.13333, 0.63333, 0, 0, 0.89444],
  1863. "216": [0.04861, 0.73472, 0, 0, 0.89444],
  1864. "223": [0, 0.69444, 0, 0, 0.59722],
  1865. "230": [0, 0.44444, 0, 0, 0.83055],
  1866. "247": [0.13333, 0.63333, 0, 0, 0.89444],
  1867. "248": [0.09722, 0.54167, 0, 0, 0.575],
  1868. "305": [0, 0.44444, 0, 0, 0.31944],
  1869. "338": [0, 0.68611, 0, 0, 1.16944],
  1870. "339": [0, 0.44444, 0, 0, 0.89444],
  1871. "567": [0.19444, 0.44444, 0, 0, 0.35139],
  1872. "710": [0, 0.69444, 0, 0, 0.575],
  1873. "711": [0, 0.63194, 0, 0, 0.575],
  1874. "713": [0, 0.59611, 0, 0, 0.575],
  1875. "714": [0, 0.69444, 0, 0, 0.575],
  1876. "715": [0, 0.69444, 0, 0, 0.575],
  1877. "728": [0, 0.69444, 0, 0, 0.575],
  1878. "729": [0, 0.69444, 0, 0, 0.31944],
  1879. "730": [0, 0.69444, 0, 0, 0.86944],
  1880. "732": [0, 0.69444, 0, 0, 0.575],
  1881. "733": [0, 0.69444, 0, 0, 0.575],
  1882. "915": [0, 0.68611, 0, 0, 0.69166],
  1883. "916": [0, 0.68611, 0, 0, 0.95833],
  1884. "920": [0, 0.68611, 0, 0, 0.89444],
  1885. "923": [0, 0.68611, 0, 0, 0.80555],
  1886. "926": [0, 0.68611, 0, 0, 0.76666],
  1887. "928": [0, 0.68611, 0, 0, 0.9],
  1888. "931": [0, 0.68611, 0, 0, 0.83055],
  1889. "933": [0, 0.68611, 0, 0, 0.89444],
  1890. "934": [0, 0.68611, 0, 0, 0.83055],
  1891. "936": [0, 0.68611, 0, 0, 0.89444],
  1892. "937": [0, 0.68611, 0, 0, 0.83055],
  1893. "8211": [0, 0.44444, 0.03194, 0, 0.575],
  1894. "8212": [0, 0.44444, 0.03194, 0, 1.14999],
  1895. "8216": [0, 0.69444, 0, 0, 0.31944],
  1896. "8217": [0, 0.69444, 0, 0, 0.31944],
  1897. "8220": [0, 0.69444, 0, 0, 0.60278],
  1898. "8221": [0, 0.69444, 0, 0, 0.60278],
  1899. "8224": [0.19444, 0.69444, 0, 0, 0.51111],
  1900. "8225": [0.19444, 0.69444, 0, 0, 0.51111],
  1901. "8242": [0, 0.55556, 0, 0, 0.34444],
  1902. "8407": [0, 0.72444, 0.15486, 0, 0.575],
  1903. "8463": [0, 0.69444, 0, 0, 0.66759],
  1904. "8465": [0, 0.69444, 0, 0, 0.83055],
  1905. "8467": [0, 0.69444, 0, 0, 0.47361],
  1906. "8472": [0.19444, 0.44444, 0, 0, 0.74027],
  1907. "8476": [0, 0.69444, 0, 0, 0.83055],
  1908. "8501": [0, 0.69444, 0, 0, 0.70277],
  1909. "8592": [-0.10889, 0.39111, 0, 0, 1.14999],
  1910. "8593": [0.19444, 0.69444, 0, 0, 0.575],
  1911. "8594": [-0.10889, 0.39111, 0, 0, 1.14999],
  1912. "8595": [0.19444, 0.69444, 0, 0, 0.575],
  1913. "8596": [-0.10889, 0.39111, 0, 0, 1.14999],
  1914. "8597": [0.25, 0.75, 0, 0, 0.575],
  1915. "8598": [0.19444, 0.69444, 0, 0, 1.14999],
  1916. "8599": [0.19444, 0.69444, 0, 0, 1.14999],
  1917. "8600": [0.19444, 0.69444, 0, 0, 1.14999],
  1918. "8601": [0.19444, 0.69444, 0, 0, 1.14999],
  1919. "8636": [-0.10889, 0.39111, 0, 0, 1.14999],
  1920. "8637": [-0.10889, 0.39111, 0, 0, 1.14999],
  1921. "8640": [-0.10889, 0.39111, 0, 0, 1.14999],
  1922. "8641": [-0.10889, 0.39111, 0, 0, 1.14999],
  1923. "8656": [-0.10889, 0.39111, 0, 0, 1.14999],
  1924. "8657": [0.19444, 0.69444, 0, 0, 0.70277],
  1925. "8658": [-0.10889, 0.39111, 0, 0, 1.14999],
  1926. "8659": [0.19444, 0.69444, 0, 0, 0.70277],
  1927. "8660": [-0.10889, 0.39111, 0, 0, 1.14999],
  1928. "8661": [0.25, 0.75, 0, 0, 0.70277],
  1929. "8704": [0, 0.69444, 0, 0, 0.63889],
  1930. "8706": [0, 0.69444, 0.06389, 0, 0.62847],
  1931. "8707": [0, 0.69444, 0, 0, 0.63889],
  1932. "8709": [0.05556, 0.75, 0, 0, 0.575],
  1933. "8711": [0, 0.68611, 0, 0, 0.95833],
  1934. "8712": [0.08556, 0.58556, 0, 0, 0.76666],
  1935. "8715": [0.08556, 0.58556, 0, 0, 0.76666],
  1936. "8722": [0.13333, 0.63333, 0, 0, 0.89444],
  1937. "8723": [0.13333, 0.63333, 0, 0, 0.89444],
  1938. "8725": [0.25, 0.75, 0, 0, 0.575],
  1939. "8726": [0.25, 0.75, 0, 0, 0.575],
  1940. "8727": [-0.02778, 0.47222, 0, 0, 0.575],
  1941. "8728": [-0.02639, 0.47361, 0, 0, 0.575],
  1942. "8729": [-0.02639, 0.47361, 0, 0, 0.575],
  1943. "8730": [0.18, 0.82, 0, 0, 0.95833],
  1944. "8733": [0, 0.44444, 0, 0, 0.89444],
  1945. "8734": [0, 0.44444, 0, 0, 1.14999],
  1946. "8736": [0, 0.69224, 0, 0, 0.72222],
  1947. "8739": [0.25, 0.75, 0, 0, 0.31944],
  1948. "8741": [0.25, 0.75, 0, 0, 0.575],
  1949. "8743": [0, 0.55556, 0, 0, 0.76666],
  1950. "8744": [0, 0.55556, 0, 0, 0.76666],
  1951. "8745": [0, 0.55556, 0, 0, 0.76666],
  1952. "8746": [0, 0.55556, 0, 0, 0.76666],
  1953. "8747": [0.19444, 0.69444, 0.12778, 0, 0.56875],
  1954. "8764": [-0.10889, 0.39111, 0, 0, 0.89444],
  1955. "8768": [0.19444, 0.69444, 0, 0, 0.31944],
  1956. "8771": [0.00222, 0.50222, 0, 0, 0.89444],
  1957. "8773": [0.027, 0.638, 0, 0, 0.894],
  1958. "8776": [0.02444, 0.52444, 0, 0, 0.89444],
  1959. "8781": [0.00222, 0.50222, 0, 0, 0.89444],
  1960. "8801": [0.00222, 0.50222, 0, 0, 0.89444],
  1961. "8804": [0.19667, 0.69667, 0, 0, 0.89444],
  1962. "8805": [0.19667, 0.69667, 0, 0, 0.89444],
  1963. "8810": [0.08556, 0.58556, 0, 0, 1.14999],
  1964. "8811": [0.08556, 0.58556, 0, 0, 1.14999],
  1965. "8826": [0.08556, 0.58556, 0, 0, 0.89444],
  1966. "8827": [0.08556, 0.58556, 0, 0, 0.89444],
  1967. "8834": [0.08556, 0.58556, 0, 0, 0.89444],
  1968. "8835": [0.08556, 0.58556, 0, 0, 0.89444],
  1969. "8838": [0.19667, 0.69667, 0, 0, 0.89444],
  1970. "8839": [0.19667, 0.69667, 0, 0, 0.89444],
  1971. "8846": [0, 0.55556, 0, 0, 0.76666],
  1972. "8849": [0.19667, 0.69667, 0, 0, 0.89444],
  1973. "8850": [0.19667, 0.69667, 0, 0, 0.89444],
  1974. "8851": [0, 0.55556, 0, 0, 0.76666],
  1975. "8852": [0, 0.55556, 0, 0, 0.76666],
  1976. "8853": [0.13333, 0.63333, 0, 0, 0.89444],
  1977. "8854": [0.13333, 0.63333, 0, 0, 0.89444],
  1978. "8855": [0.13333, 0.63333, 0, 0, 0.89444],
  1979. "8856": [0.13333, 0.63333, 0, 0, 0.89444],
  1980. "8857": [0.13333, 0.63333, 0, 0, 0.89444],
  1981. "8866": [0, 0.69444, 0, 0, 0.70277],
  1982. "8867": [0, 0.69444, 0, 0, 0.70277],
  1983. "8868": [0, 0.69444, 0, 0, 0.89444],
  1984. "8869": [0, 0.69444, 0, 0, 0.89444],
  1985. "8900": [-0.02639, 0.47361, 0, 0, 0.575],
  1986. "8901": [-0.02639, 0.47361, 0, 0, 0.31944],
  1987. "8902": [-0.02778, 0.47222, 0, 0, 0.575],
  1988. "8968": [0.25, 0.75, 0, 0, 0.51111],
  1989. "8969": [0.25, 0.75, 0, 0, 0.51111],
  1990. "8970": [0.25, 0.75, 0, 0, 0.51111],
  1991. "8971": [0.25, 0.75, 0, 0, 0.51111],
  1992. "8994": [-0.13889, 0.36111, 0, 0, 1.14999],
  1993. "8995": [-0.13889, 0.36111, 0, 0, 1.14999],
  1994. "9651": [0.19444, 0.69444, 0, 0, 1.02222],
  1995. "9657": [-0.02778, 0.47222, 0, 0, 0.575],
  1996. "9661": [0.19444, 0.69444, 0, 0, 1.02222],
  1997. "9667": [-0.02778, 0.47222, 0, 0, 0.575],
  1998. "9711": [0.19444, 0.69444, 0, 0, 1.14999],
  1999. "9824": [0.12963, 0.69444, 0, 0, 0.89444],
  2000. "9825": [0.12963, 0.69444, 0, 0, 0.89444],
  2001. "9826": [0.12963, 0.69444, 0, 0, 0.89444],
  2002. "9827": [0.12963, 0.69444, 0, 0, 0.89444],
  2003. "9837": [0, 0.75, 0, 0, 0.44722],
  2004. "9838": [0.19444, 0.69444, 0, 0, 0.44722],
  2005. "9839": [0.19444, 0.69444, 0, 0, 0.44722],
  2006. "10216": [0.25, 0.75, 0, 0, 0.44722],
  2007. "10217": [0.25, 0.75, 0, 0, 0.44722],
  2008. "10815": [0, 0.68611, 0, 0, 0.9],
  2009. "10927": [0.19667, 0.69667, 0, 0, 0.89444],
  2010. "10928": [0.19667, 0.69667, 0, 0, 0.89444],
  2011. "57376": [0.19444, 0.69444, 0, 0, 0]
  2012. },
  2013. "Main-BoldItalic": {
  2014. "32": [0, 0, 0, 0, 0.25],
  2015. "33": [0, 0.69444, 0.11417, 0, 0.38611],
  2016. "34": [0, 0.69444, 0.07939, 0, 0.62055],
  2017. "35": [0.19444, 0.69444, 0.06833, 0, 0.94444],
  2018. "37": [0.05556, 0.75, 0.12861, 0, 0.94444],
  2019. "38": [0, 0.69444, 0.08528, 0, 0.88555],
  2020. "39": [0, 0.69444, 0.12945, 0, 0.35555],
  2021. "40": [0.25, 0.75, 0.15806, 0, 0.47333],
  2022. "41": [0.25, 0.75, 0.03306, 0, 0.47333],
  2023. "42": [0, 0.75, 0.14333, 0, 0.59111],
  2024. "43": [0.10333, 0.60333, 0.03306, 0, 0.88555],
  2025. "44": [0.19444, 0.14722, 0, 0, 0.35555],
  2026. "45": [0, 0.44444, 0.02611, 0, 0.41444],
  2027. "46": [0, 0.14722, 0, 0, 0.35555],
  2028. "47": [0.25, 0.75, 0.15806, 0, 0.59111],
  2029. "48": [0, 0.64444, 0.13167, 0, 0.59111],
  2030. "49": [0, 0.64444, 0.13167, 0, 0.59111],
  2031. "50": [0, 0.64444, 0.13167, 0, 0.59111],
  2032. "51": [0, 0.64444, 0.13167, 0, 0.59111],
  2033. "52": [0.19444, 0.64444, 0.13167, 0, 0.59111],
  2034. "53": [0, 0.64444, 0.13167, 0, 0.59111],
  2035. "54": [0, 0.64444, 0.13167, 0, 0.59111],
  2036. "55": [0.19444, 0.64444, 0.13167, 0, 0.59111],
  2037. "56": [0, 0.64444, 0.13167, 0, 0.59111],
  2038. "57": [0, 0.64444, 0.13167, 0, 0.59111],
  2039. "58": [0, 0.44444, 0.06695, 0, 0.35555],
  2040. "59": [0.19444, 0.44444, 0.06695, 0, 0.35555],
  2041. "61": [-0.10889, 0.39111, 0.06833, 0, 0.88555],
  2042. "63": [0, 0.69444, 0.11472, 0, 0.59111],
  2043. "64": [0, 0.69444, 0.09208, 0, 0.88555],
  2044. "65": [0, 0.68611, 0, 0, 0.86555],
  2045. "66": [0, 0.68611, 0.0992, 0, 0.81666],
  2046. "67": [0, 0.68611, 0.14208, 0, 0.82666],
  2047. "68": [0, 0.68611, 0.09062, 0, 0.87555],
  2048. "69": [0, 0.68611, 0.11431, 0, 0.75666],
  2049. "70": [0, 0.68611, 0.12903, 0, 0.72722],
  2050. "71": [0, 0.68611, 0.07347, 0, 0.89527],
  2051. "72": [0, 0.68611, 0.17208, 0, 0.8961],
  2052. "73": [0, 0.68611, 0.15681, 0, 0.47166],
  2053. "74": [0, 0.68611, 0.145, 0, 0.61055],
  2054. "75": [0, 0.68611, 0.14208, 0, 0.89499],
  2055. "76": [0, 0.68611, 0, 0, 0.69777],
  2056. "77": [0, 0.68611, 0.17208, 0, 1.07277],
  2057. "78": [0, 0.68611, 0.17208, 0, 0.8961],
  2058. "79": [0, 0.68611, 0.09062, 0, 0.85499],
  2059. "80": [0, 0.68611, 0.0992, 0, 0.78721],
  2060. "81": [0.19444, 0.68611, 0.09062, 0, 0.85499],
  2061. "82": [0, 0.68611, 0.02559, 0, 0.85944],
  2062. "83": [0, 0.68611, 0.11264, 0, 0.64999],
  2063. "84": [0, 0.68611, 0.12903, 0, 0.7961],
  2064. "85": [0, 0.68611, 0.17208, 0, 0.88083],
  2065. "86": [0, 0.68611, 0.18625, 0, 0.86555],
  2066. "87": [0, 0.68611, 0.18625, 0, 1.15999],
  2067. "88": [0, 0.68611, 0.15681, 0, 0.86555],
  2068. "89": [0, 0.68611, 0.19803, 0, 0.86555],
  2069. "90": [0, 0.68611, 0.14208, 0, 0.70888],
  2070. "91": [0.25, 0.75, 0.1875, 0, 0.35611],
  2071. "93": [0.25, 0.75, 0.09972, 0, 0.35611],
  2072. "94": [0, 0.69444, 0.06709, 0, 0.59111],
  2073. "95": [0.31, 0.13444, 0.09811, 0, 0.59111],
  2074. "97": [0, 0.44444, 0.09426, 0, 0.59111],
  2075. "98": [0, 0.69444, 0.07861, 0, 0.53222],
  2076. "99": [0, 0.44444, 0.05222, 0, 0.53222],
  2077. "100": [0, 0.69444, 0.10861, 0, 0.59111],
  2078. "101": [0, 0.44444, 0.085, 0, 0.53222],
  2079. "102": [0.19444, 0.69444, 0.21778, 0, 0.4],
  2080. "103": [0.19444, 0.44444, 0.105, 0, 0.53222],
  2081. "104": [0, 0.69444, 0.09426, 0, 0.59111],
  2082. "105": [0, 0.69326, 0.11387, 0, 0.35555],
  2083. "106": [0.19444, 0.69326, 0.1672, 0, 0.35555],
  2084. "107": [0, 0.69444, 0.11111, 0, 0.53222],
  2085. "108": [0, 0.69444, 0.10861, 0, 0.29666],
  2086. "109": [0, 0.44444, 0.09426, 0, 0.94444],
  2087. "110": [0, 0.44444, 0.09426, 0, 0.64999],
  2088. "111": [0, 0.44444, 0.07861, 0, 0.59111],
  2089. "112": [0.19444, 0.44444, 0.07861, 0, 0.59111],
  2090. "113": [0.19444, 0.44444, 0.105, 0, 0.53222],
  2091. "114": [0, 0.44444, 0.11111, 0, 0.50167],
  2092. "115": [0, 0.44444, 0.08167, 0, 0.48694],
  2093. "116": [0, 0.63492, 0.09639, 0, 0.385],
  2094. "117": [0, 0.44444, 0.09426, 0, 0.62055],
  2095. "118": [0, 0.44444, 0.11111, 0, 0.53222],
  2096. "119": [0, 0.44444, 0.11111, 0, 0.76777],
  2097. "120": [0, 0.44444, 0.12583, 0, 0.56055],
  2098. "121": [0.19444, 0.44444, 0.105, 0, 0.56166],
  2099. "122": [0, 0.44444, 0.13889, 0, 0.49055],
  2100. "126": [0.35, 0.34444, 0.11472, 0, 0.59111],
  2101. "160": [0, 0, 0, 0, 0.25],
  2102. "168": [0, 0.69444, 0.11473, 0, 0.59111],
  2103. "176": [0, 0.69444, 0, 0, 0.94888],
  2104. "184": [0.17014, 0, 0, 0, 0.53222],
  2105. "198": [0, 0.68611, 0.11431, 0, 1.02277],
  2106. "216": [0.04861, 0.73472, 0.09062, 0, 0.88555],
  2107. "223": [0.19444, 0.69444, 0.09736, 0, 0.665],
  2108. "230": [0, 0.44444, 0.085, 0, 0.82666],
  2109. "248": [0.09722, 0.54167, 0.09458, 0, 0.59111],
  2110. "305": [0, 0.44444, 0.09426, 0, 0.35555],
  2111. "338": [0, 0.68611, 0.11431, 0, 1.14054],
  2112. "339": [0, 0.44444, 0.085, 0, 0.82666],
  2113. "567": [0.19444, 0.44444, 0.04611, 0, 0.385],
  2114. "710": [0, 0.69444, 0.06709, 0, 0.59111],
  2115. "711": [0, 0.63194, 0.08271, 0, 0.59111],
  2116. "713": [0, 0.59444, 0.10444, 0, 0.59111],
  2117. "714": [0, 0.69444, 0.08528, 0, 0.59111],
  2118. "715": [0, 0.69444, 0, 0, 0.59111],
  2119. "728": [0, 0.69444, 0.10333, 0, 0.59111],
  2120. "729": [0, 0.69444, 0.12945, 0, 0.35555],
  2121. "730": [0, 0.69444, 0, 0, 0.94888],
  2122. "732": [0, 0.69444, 0.11472, 0, 0.59111],
  2123. "733": [0, 0.69444, 0.11472, 0, 0.59111],
  2124. "915": [0, 0.68611, 0.12903, 0, 0.69777],
  2125. "916": [0, 0.68611, 0, 0, 0.94444],
  2126. "920": [0, 0.68611, 0.09062, 0, 0.88555],
  2127. "923": [0, 0.68611, 0, 0, 0.80666],
  2128. "926": [0, 0.68611, 0.15092, 0, 0.76777],
  2129. "928": [0, 0.68611, 0.17208, 0, 0.8961],
  2130. "931": [0, 0.68611, 0.11431, 0, 0.82666],
  2131. "933": [0, 0.68611, 0.10778, 0, 0.88555],
  2132. "934": [0, 0.68611, 0.05632, 0, 0.82666],
  2133. "936": [0, 0.68611, 0.10778, 0, 0.88555],
  2134. "937": [0, 0.68611, 0.0992, 0, 0.82666],
  2135. "8211": [0, 0.44444, 0.09811, 0, 0.59111],
  2136. "8212": [0, 0.44444, 0.09811, 0, 1.18221],
  2137. "8216": [0, 0.69444, 0.12945, 0, 0.35555],
  2138. "8217": [0, 0.69444, 0.12945, 0, 0.35555],
  2139. "8220": [0, 0.69444, 0.16772, 0, 0.62055],
  2140. "8221": [0, 0.69444, 0.07939, 0, 0.62055]
  2141. },
  2142. "Main-Italic": {
  2143. "32": [0, 0, 0, 0, 0.25],
  2144. "33": [0, 0.69444, 0.12417, 0, 0.30667],
  2145. "34": [0, 0.69444, 0.06961, 0, 0.51444],
  2146. "35": [0.19444, 0.69444, 0.06616, 0, 0.81777],
  2147. "37": [0.05556, 0.75, 0.13639, 0, 0.81777],
  2148. "38": [0, 0.69444, 0.09694, 0, 0.76666],
  2149. "39": [0, 0.69444, 0.12417, 0, 0.30667],
  2150. "40": [0.25, 0.75, 0.16194, 0, 0.40889],
  2151. "41": [0.25, 0.75, 0.03694, 0, 0.40889],
  2152. "42": [0, 0.75, 0.14917, 0, 0.51111],
  2153. "43": [0.05667, 0.56167, 0.03694, 0, 0.76666],
  2154. "44": [0.19444, 0.10556, 0, 0, 0.30667],
  2155. "45": [0, 0.43056, 0.02826, 0, 0.35778],
  2156. "46": [0, 0.10556, 0, 0, 0.30667],
  2157. "47": [0.25, 0.75, 0.16194, 0, 0.51111],
  2158. "48": [0, 0.64444, 0.13556, 0, 0.51111],
  2159. "49": [0, 0.64444, 0.13556, 0, 0.51111],
  2160. "50": [0, 0.64444, 0.13556, 0, 0.51111],
  2161. "51": [0, 0.64444, 0.13556, 0, 0.51111],
  2162. "52": [0.19444, 0.64444, 0.13556, 0, 0.51111],
  2163. "53": [0, 0.64444, 0.13556, 0, 0.51111],
  2164. "54": [0, 0.64444, 0.13556, 0, 0.51111],
  2165. "55": [0.19444, 0.64444, 0.13556, 0, 0.51111],
  2166. "56": [0, 0.64444, 0.13556, 0, 0.51111],
  2167. "57": [0, 0.64444, 0.13556, 0, 0.51111],
  2168. "58": [0, 0.43056, 0.0582, 0, 0.30667],
  2169. "59": [0.19444, 0.43056, 0.0582, 0, 0.30667],
  2170. "61": [-0.13313, 0.36687, 0.06616, 0, 0.76666],
  2171. "63": [0, 0.69444, 0.1225, 0, 0.51111],
  2172. "64": [0, 0.69444, 0.09597, 0, 0.76666],
  2173. "65": [0, 0.68333, 0, 0, 0.74333],
  2174. "66": [0, 0.68333, 0.10257, 0, 0.70389],
  2175. "67": [0, 0.68333, 0.14528, 0, 0.71555],
  2176. "68": [0, 0.68333, 0.09403, 0, 0.755],
  2177. "69": [0, 0.68333, 0.12028, 0, 0.67833],
  2178. "70": [0, 0.68333, 0.13305, 0, 0.65277],
  2179. "71": [0, 0.68333, 0.08722, 0, 0.77361],
  2180. "72": [0, 0.68333, 0.16389, 0, 0.74333],
  2181. "73": [0, 0.68333, 0.15806, 0, 0.38555],
  2182. "74": [0, 0.68333, 0.14028, 0, 0.525],
  2183. "75": [0, 0.68333, 0.14528, 0, 0.76888],
  2184. "76": [0, 0.68333, 0, 0, 0.62722],
  2185. "77": [0, 0.68333, 0.16389, 0, 0.89666],
  2186. "78": [0, 0.68333, 0.16389, 0, 0.74333],
  2187. "79": [0, 0.68333, 0.09403, 0, 0.76666],
  2188. "80": [0, 0.68333, 0.10257, 0, 0.67833],
  2189. "81": [0.19444, 0.68333, 0.09403, 0, 0.76666],
  2190. "82": [0, 0.68333, 0.03868, 0, 0.72944],
  2191. "83": [0, 0.68333, 0.11972, 0, 0.56222],
  2192. "84": [0, 0.68333, 0.13305, 0, 0.71555],
  2193. "85": [0, 0.68333, 0.16389, 0, 0.74333],
  2194. "86": [0, 0.68333, 0.18361, 0, 0.74333],
  2195. "87": [0, 0.68333, 0.18361, 0, 0.99888],
  2196. "88": [0, 0.68333, 0.15806, 0, 0.74333],
  2197. "89": [0, 0.68333, 0.19383, 0, 0.74333],
  2198. "90": [0, 0.68333, 0.14528, 0, 0.61333],
  2199. "91": [0.25, 0.75, 0.1875, 0, 0.30667],
  2200. "93": [0.25, 0.75, 0.10528, 0, 0.30667],
  2201. "94": [0, 0.69444, 0.06646, 0, 0.51111],
  2202. "95": [0.31, 0.12056, 0.09208, 0, 0.51111],
  2203. "97": [0, 0.43056, 0.07671, 0, 0.51111],
  2204. "98": [0, 0.69444, 0.06312, 0, 0.46],
  2205. "99": [0, 0.43056, 0.05653, 0, 0.46],
  2206. "100": [0, 0.69444, 0.10333, 0, 0.51111],
  2207. "101": [0, 0.43056, 0.07514, 0, 0.46],
  2208. "102": [0.19444, 0.69444, 0.21194, 0, 0.30667],
  2209. "103": [0.19444, 0.43056, 0.08847, 0, 0.46],
  2210. "104": [0, 0.69444, 0.07671, 0, 0.51111],
  2211. "105": [0, 0.65536, 0.1019, 0, 0.30667],
  2212. "106": [0.19444, 0.65536, 0.14467, 0, 0.30667],
  2213. "107": [0, 0.69444, 0.10764, 0, 0.46],
  2214. "108": [0, 0.69444, 0.10333, 0, 0.25555],
  2215. "109": [0, 0.43056, 0.07671, 0, 0.81777],
  2216. "110": [0, 0.43056, 0.07671, 0, 0.56222],
  2217. "111": [0, 0.43056, 0.06312, 0, 0.51111],
  2218. "112": [0.19444, 0.43056, 0.06312, 0, 0.51111],
  2219. "113": [0.19444, 0.43056, 0.08847, 0, 0.46],
  2220. "114": [0, 0.43056, 0.10764, 0, 0.42166],
  2221. "115": [0, 0.43056, 0.08208, 0, 0.40889],
  2222. "116": [0, 0.61508, 0.09486, 0, 0.33222],
  2223. "117": [0, 0.43056, 0.07671, 0, 0.53666],
  2224. "118": [0, 0.43056, 0.10764, 0, 0.46],
  2225. "119": [0, 0.43056, 0.10764, 0, 0.66444],
  2226. "120": [0, 0.43056, 0.12042, 0, 0.46389],
  2227. "121": [0.19444, 0.43056, 0.08847, 0, 0.48555],
  2228. "122": [0, 0.43056, 0.12292, 0, 0.40889],
  2229. "126": [0.35, 0.31786, 0.11585, 0, 0.51111],
  2230. "160": [0, 0, 0, 0, 0.25],
  2231. "168": [0, 0.66786, 0.10474, 0, 0.51111],
  2232. "176": [0, 0.69444, 0, 0, 0.83129],
  2233. "184": [0.17014, 0, 0, 0, 0.46],
  2234. "198": [0, 0.68333, 0.12028, 0, 0.88277],
  2235. "216": [0.04861, 0.73194, 0.09403, 0, 0.76666],
  2236. "223": [0.19444, 0.69444, 0.10514, 0, 0.53666],
  2237. "230": [0, 0.43056, 0.07514, 0, 0.71555],
  2238. "248": [0.09722, 0.52778, 0.09194, 0, 0.51111],
  2239. "338": [0, 0.68333, 0.12028, 0, 0.98499],
  2240. "339": [0, 0.43056, 0.07514, 0, 0.71555],
  2241. "710": [0, 0.69444, 0.06646, 0, 0.51111],
  2242. "711": [0, 0.62847, 0.08295, 0, 0.51111],
  2243. "713": [0, 0.56167, 0.10333, 0, 0.51111],
  2244. "714": [0, 0.69444, 0.09694, 0, 0.51111],
  2245. "715": [0, 0.69444, 0, 0, 0.51111],
  2246. "728": [0, 0.69444, 0.10806, 0, 0.51111],
  2247. "729": [0, 0.66786, 0.11752, 0, 0.30667],
  2248. "730": [0, 0.69444, 0, 0, 0.83129],
  2249. "732": [0, 0.66786, 0.11585, 0, 0.51111],
  2250. "733": [0, 0.69444, 0.1225, 0, 0.51111],
  2251. "915": [0, 0.68333, 0.13305, 0, 0.62722],
  2252. "916": [0, 0.68333, 0, 0, 0.81777],
  2253. "920": [0, 0.68333, 0.09403, 0, 0.76666],
  2254. "923": [0, 0.68333, 0, 0, 0.69222],
  2255. "926": [0, 0.68333, 0.15294, 0, 0.66444],
  2256. "928": [0, 0.68333, 0.16389, 0, 0.74333],
  2257. "931": [0, 0.68333, 0.12028, 0, 0.71555],
  2258. "933": [0, 0.68333, 0.11111, 0, 0.76666],
  2259. "934": [0, 0.68333, 0.05986, 0, 0.71555],
  2260. "936": [0, 0.68333, 0.11111, 0, 0.76666],
  2261. "937": [0, 0.68333, 0.10257, 0, 0.71555],
  2262. "8211": [0, 0.43056, 0.09208, 0, 0.51111],
  2263. "8212": [0, 0.43056, 0.09208, 0, 1.02222],
  2264. "8216": [0, 0.69444, 0.12417, 0, 0.30667],
  2265. "8217": [0, 0.69444, 0.12417, 0, 0.30667],
  2266. "8220": [0, 0.69444, 0.1685, 0, 0.51444],
  2267. "8221": [0, 0.69444, 0.06961, 0, 0.51444],
  2268. "8463": [0, 0.68889, 0, 0, 0.54028]
  2269. },
  2270. "Main-Regular": {
  2271. "32": [0, 0, 0, 0, 0.25],
  2272. "33": [0, 0.69444, 0, 0, 0.27778],
  2273. "34": [0, 0.69444, 0, 0, 0.5],
  2274. "35": [0.19444, 0.69444, 0, 0, 0.83334],
  2275. "36": [0.05556, 0.75, 0, 0, 0.5],
  2276. "37": [0.05556, 0.75, 0, 0, 0.83334],
  2277. "38": [0, 0.69444, 0, 0, 0.77778],
  2278. "39": [0, 0.69444, 0, 0, 0.27778],
  2279. "40": [0.25, 0.75, 0, 0, 0.38889],
  2280. "41": [0.25, 0.75, 0, 0, 0.38889],
  2281. "42": [0, 0.75, 0, 0, 0.5],
  2282. "43": [0.08333, 0.58333, 0, 0, 0.77778],
  2283. "44": [0.19444, 0.10556, 0, 0, 0.27778],
  2284. "45": [0, 0.43056, 0, 0, 0.33333],
  2285. "46": [0, 0.10556, 0, 0, 0.27778],
  2286. "47": [0.25, 0.75, 0, 0, 0.5],
  2287. "48": [0, 0.64444, 0, 0, 0.5],
  2288. "49": [0, 0.64444, 0, 0, 0.5],
  2289. "50": [0, 0.64444, 0, 0, 0.5],
  2290. "51": [0, 0.64444, 0, 0, 0.5],
  2291. "52": [0, 0.64444, 0, 0, 0.5],
  2292. "53": [0, 0.64444, 0, 0, 0.5],
  2293. "54": [0, 0.64444, 0, 0, 0.5],
  2294. "55": [0, 0.64444, 0, 0, 0.5],
  2295. "56": [0, 0.64444, 0, 0, 0.5],
  2296. "57": [0, 0.64444, 0, 0, 0.5],
  2297. "58": [0, 0.43056, 0, 0, 0.27778],
  2298. "59": [0.19444, 0.43056, 0, 0, 0.27778],
  2299. "60": [0.0391, 0.5391, 0, 0, 0.77778],
  2300. "61": [-0.13313, 0.36687, 0, 0, 0.77778],
  2301. "62": [0.0391, 0.5391, 0, 0, 0.77778],
  2302. "63": [0, 0.69444, 0, 0, 0.47222],
  2303. "64": [0, 0.69444, 0, 0, 0.77778],
  2304. "65": [0, 0.68333, 0, 0, 0.75],
  2305. "66": [0, 0.68333, 0, 0, 0.70834],
  2306. "67": [0, 0.68333, 0, 0, 0.72222],
  2307. "68": [0, 0.68333, 0, 0, 0.76389],
  2308. "69": [0, 0.68333, 0, 0, 0.68056],
  2309. "70": [0, 0.68333, 0, 0, 0.65278],
  2310. "71": [0, 0.68333, 0, 0, 0.78472],
  2311. "72": [0, 0.68333, 0, 0, 0.75],
  2312. "73": [0, 0.68333, 0, 0, 0.36111],
  2313. "74": [0, 0.68333, 0, 0, 0.51389],
  2314. "75": [0, 0.68333, 0, 0, 0.77778],
  2315. "76": [0, 0.68333, 0, 0, 0.625],
  2316. "77": [0, 0.68333, 0, 0, 0.91667],
  2317. "78": [0, 0.68333, 0, 0, 0.75],
  2318. "79": [0, 0.68333, 0, 0, 0.77778],
  2319. "80": [0, 0.68333, 0, 0, 0.68056],
  2320. "81": [0.19444, 0.68333, 0, 0, 0.77778],
  2321. "82": [0, 0.68333, 0, 0, 0.73611],
  2322. "83": [0, 0.68333, 0, 0, 0.55556],
  2323. "84": [0, 0.68333, 0, 0, 0.72222],
  2324. "85": [0, 0.68333, 0, 0, 0.75],
  2325. "86": [0, 0.68333, 0.01389, 0, 0.75],
  2326. "87": [0, 0.68333, 0.01389, 0, 1.02778],
  2327. "88": [0, 0.68333, 0, 0, 0.75],
  2328. "89": [0, 0.68333, 0.025, 0, 0.75],
  2329. "90": [0, 0.68333, 0, 0, 0.61111],
  2330. "91": [0.25, 0.75, 0, 0, 0.27778],
  2331. "92": [0.25, 0.75, 0, 0, 0.5],
  2332. "93": [0.25, 0.75, 0, 0, 0.27778],
  2333. "94": [0, 0.69444, 0, 0, 0.5],
  2334. "95": [0.31, 0.12056, 0.02778, 0, 0.5],
  2335. "97": [0, 0.43056, 0, 0, 0.5],
  2336. "98": [0, 0.69444, 0, 0, 0.55556],
  2337. "99": [0, 0.43056, 0, 0, 0.44445],
  2338. "100": [0, 0.69444, 0, 0, 0.55556],
  2339. "101": [0, 0.43056, 0, 0, 0.44445],
  2340. "102": [0, 0.69444, 0.07778, 0, 0.30556],
  2341. "103": [0.19444, 0.43056, 0.01389, 0, 0.5],
  2342. "104": [0, 0.69444, 0, 0, 0.55556],
  2343. "105": [0, 0.66786, 0, 0, 0.27778],
  2344. "106": [0.19444, 0.66786, 0, 0, 0.30556],
  2345. "107": [0, 0.69444, 0, 0, 0.52778],
  2346. "108": [0, 0.69444, 0, 0, 0.27778],
  2347. "109": [0, 0.43056, 0, 0, 0.83334],
  2348. "110": [0, 0.43056, 0, 0, 0.55556],
  2349. "111": [0, 0.43056, 0, 0, 0.5],
  2350. "112": [0.19444, 0.43056, 0, 0, 0.55556],
  2351. "113": [0.19444, 0.43056, 0, 0, 0.52778],
  2352. "114": [0, 0.43056, 0, 0, 0.39167],
  2353. "115": [0, 0.43056, 0, 0, 0.39445],
  2354. "116": [0, 0.61508, 0, 0, 0.38889],
  2355. "117": [0, 0.43056, 0, 0, 0.55556],
  2356. "118": [0, 0.43056, 0.01389, 0, 0.52778],
  2357. "119": [0, 0.43056, 0.01389, 0, 0.72222],
  2358. "120": [0, 0.43056, 0, 0, 0.52778],
  2359. "121": [0.19444, 0.43056, 0.01389, 0, 0.52778],
  2360. "122": [0, 0.43056, 0, 0, 0.44445],
  2361. "123": [0.25, 0.75, 0, 0, 0.5],
  2362. "124": [0.25, 0.75, 0, 0, 0.27778],
  2363. "125": [0.25, 0.75, 0, 0, 0.5],
  2364. "126": [0.35, 0.31786, 0, 0, 0.5],
  2365. "160": [0, 0, 0, 0, 0.25],
  2366. "163": [0, 0.69444, 0, 0, 0.76909],
  2367. "167": [0.19444, 0.69444, 0, 0, 0.44445],
  2368. "168": [0, 0.66786, 0, 0, 0.5],
  2369. "172": [0, 0.43056, 0, 0, 0.66667],
  2370. "176": [0, 0.69444, 0, 0, 0.75],
  2371. "177": [0.08333, 0.58333, 0, 0, 0.77778],
  2372. "182": [0.19444, 0.69444, 0, 0, 0.61111],
  2373. "184": [0.17014, 0, 0, 0, 0.44445],
  2374. "198": [0, 0.68333, 0, 0, 0.90278],
  2375. "215": [0.08333, 0.58333, 0, 0, 0.77778],
  2376. "216": [0.04861, 0.73194, 0, 0, 0.77778],
  2377. "223": [0, 0.69444, 0, 0, 0.5],
  2378. "230": [0, 0.43056, 0, 0, 0.72222],
  2379. "247": [0.08333, 0.58333, 0, 0, 0.77778],
  2380. "248": [0.09722, 0.52778, 0, 0, 0.5],
  2381. "305": [0, 0.43056, 0, 0, 0.27778],
  2382. "338": [0, 0.68333, 0, 0, 1.01389],
  2383. "339": [0, 0.43056, 0, 0, 0.77778],
  2384. "567": [0.19444, 0.43056, 0, 0, 0.30556],
  2385. "710": [0, 0.69444, 0, 0, 0.5],
  2386. "711": [0, 0.62847, 0, 0, 0.5],
  2387. "713": [0, 0.56778, 0, 0, 0.5],
  2388. "714": [0, 0.69444, 0, 0, 0.5],
  2389. "715": [0, 0.69444, 0, 0, 0.5],
  2390. "728": [0, 0.69444, 0, 0, 0.5],
  2391. "729": [0, 0.66786, 0, 0, 0.27778],
  2392. "730": [0, 0.69444, 0, 0, 0.75],
  2393. "732": [0, 0.66786, 0, 0, 0.5],
  2394. "733": [0, 0.69444, 0, 0, 0.5],
  2395. "915": [0, 0.68333, 0, 0, 0.625],
  2396. "916": [0, 0.68333, 0, 0, 0.83334],
  2397. "920": [0, 0.68333, 0, 0, 0.77778],
  2398. "923": [0, 0.68333, 0, 0, 0.69445],
  2399. "926": [0, 0.68333, 0, 0, 0.66667],
  2400. "928": [0, 0.68333, 0, 0, 0.75],
  2401. "931": [0, 0.68333, 0, 0, 0.72222],
  2402. "933": [0, 0.68333, 0, 0, 0.77778],
  2403. "934": [0, 0.68333, 0, 0, 0.72222],
  2404. "936": [0, 0.68333, 0, 0, 0.77778],
  2405. "937": [0, 0.68333, 0, 0, 0.72222],
  2406. "8211": [0, 0.43056, 0.02778, 0, 0.5],
  2407. "8212": [0, 0.43056, 0.02778, 0, 1.0],
  2408. "8216": [0, 0.69444, 0, 0, 0.27778],
  2409. "8217": [0, 0.69444, 0, 0, 0.27778],
  2410. "8220": [0, 0.69444, 0, 0, 0.5],
  2411. "8221": [0, 0.69444, 0, 0, 0.5],
  2412. "8224": [0.19444, 0.69444, 0, 0, 0.44445],
  2413. "8225": [0.19444, 0.69444, 0, 0, 0.44445],
  2414. "8230": [0, 0.123, 0, 0, 1.172],
  2415. "8242": [0, 0.55556, 0, 0, 0.275],
  2416. "8407": [0, 0.71444, 0.15382, 0, 0.5],
  2417. "8463": [0, 0.68889, 0, 0, 0.54028],
  2418. "8465": [0, 0.69444, 0, 0, 0.72222],
  2419. "8467": [0, 0.69444, 0, 0.11111, 0.41667],
  2420. "8472": [0.19444, 0.43056, 0, 0.11111, 0.63646],
  2421. "8476": [0, 0.69444, 0, 0, 0.72222],
  2422. "8501": [0, 0.69444, 0, 0, 0.61111],
  2423. "8592": [-0.13313, 0.36687, 0, 0, 1.0],
  2424. "8593": [0.19444, 0.69444, 0, 0, 0.5],
  2425. "8594": [-0.13313, 0.36687, 0, 0, 1.0],
  2426. "8595": [0.19444, 0.69444, 0, 0, 0.5],
  2427. "8596": [-0.13313, 0.36687, 0, 0, 1.0],
  2428. "8597": [0.25, 0.75, 0, 0, 0.5],
  2429. "8598": [0.19444, 0.69444, 0, 0, 1.0],
  2430. "8599": [0.19444, 0.69444, 0, 0, 1.0],
  2431. "8600": [0.19444, 0.69444, 0, 0, 1.0],
  2432. "8601": [0.19444, 0.69444, 0, 0, 1.0],
  2433. "8614": [0.011, 0.511, 0, 0, 1.0],
  2434. "8617": [0.011, 0.511, 0, 0, 1.126],
  2435. "8618": [0.011, 0.511, 0, 0, 1.126],
  2436. "8636": [-0.13313, 0.36687, 0, 0, 1.0],
  2437. "8637": [-0.13313, 0.36687, 0, 0, 1.0],
  2438. "8640": [-0.13313, 0.36687, 0, 0, 1.0],
  2439. "8641": [-0.13313, 0.36687, 0, 0, 1.0],
  2440. "8652": [0.011, 0.671, 0, 0, 1.0],
  2441. "8656": [-0.13313, 0.36687, 0, 0, 1.0],
  2442. "8657": [0.19444, 0.69444, 0, 0, 0.61111],
  2443. "8658": [-0.13313, 0.36687, 0, 0, 1.0],
  2444. "8659": [0.19444, 0.69444, 0, 0, 0.61111],
  2445. "8660": [-0.13313, 0.36687, 0, 0, 1.0],
  2446. "8661": [0.25, 0.75, 0, 0, 0.61111],
  2447. "8704": [0, 0.69444, 0, 0, 0.55556],
  2448. "8706": [0, 0.69444, 0.05556, 0.08334, 0.5309],
  2449. "8707": [0, 0.69444, 0, 0, 0.55556],
  2450. "8709": [0.05556, 0.75, 0, 0, 0.5],
  2451. "8711": [0, 0.68333, 0, 0, 0.83334],
  2452. "8712": [0.0391, 0.5391, 0, 0, 0.66667],
  2453. "8715": [0.0391, 0.5391, 0, 0, 0.66667],
  2454. "8722": [0.08333, 0.58333, 0, 0, 0.77778],
  2455. "8723": [0.08333, 0.58333, 0, 0, 0.77778],
  2456. "8725": [0.25, 0.75, 0, 0, 0.5],
  2457. "8726": [0.25, 0.75, 0, 0, 0.5],
  2458. "8727": [-0.03472, 0.46528, 0, 0, 0.5],
  2459. "8728": [-0.05555, 0.44445, 0, 0, 0.5],
  2460. "8729": [-0.05555, 0.44445, 0, 0, 0.5],
  2461. "8730": [0.2, 0.8, 0, 0, 0.83334],
  2462. "8733": [0, 0.43056, 0, 0, 0.77778],
  2463. "8734": [0, 0.43056, 0, 0, 1.0],
  2464. "8736": [0, 0.69224, 0, 0, 0.72222],
  2465. "8739": [0.25, 0.75, 0, 0, 0.27778],
  2466. "8741": [0.25, 0.75, 0, 0, 0.5],
  2467. "8743": [0, 0.55556, 0, 0, 0.66667],
  2468. "8744": [0, 0.55556, 0, 0, 0.66667],
  2469. "8745": [0, 0.55556, 0, 0, 0.66667],
  2470. "8746": [0, 0.55556, 0, 0, 0.66667],
  2471. "8747": [0.19444, 0.69444, 0.11111, 0, 0.41667],
  2472. "8764": [-0.13313, 0.36687, 0, 0, 0.77778],
  2473. "8768": [0.19444, 0.69444, 0, 0, 0.27778],
  2474. "8771": [-0.03625, 0.46375, 0, 0, 0.77778],
  2475. "8773": [-0.022, 0.589, 0, 0, 0.778],
  2476. "8776": [-0.01688, 0.48312, 0, 0, 0.77778],
  2477. "8781": [-0.03625, 0.46375, 0, 0, 0.77778],
  2478. "8784": [-0.133, 0.673, 0, 0, 0.778],
  2479. "8801": [-0.03625, 0.46375, 0, 0, 0.77778],
  2480. "8804": [0.13597, 0.63597, 0, 0, 0.77778],
  2481. "8805": [0.13597, 0.63597, 0, 0, 0.77778],
  2482. "8810": [0.0391, 0.5391, 0, 0, 1.0],
  2483. "8811": [0.0391, 0.5391, 0, 0, 1.0],
  2484. "8826": [0.0391, 0.5391, 0, 0, 0.77778],
  2485. "8827": [0.0391, 0.5391, 0, 0, 0.77778],
  2486. "8834": [0.0391, 0.5391, 0, 0, 0.77778],
  2487. "8835": [0.0391, 0.5391, 0, 0, 0.77778],
  2488. "8838": [0.13597, 0.63597, 0, 0, 0.77778],
  2489. "8839": [0.13597, 0.63597, 0, 0, 0.77778],
  2490. "8846": [0, 0.55556, 0, 0, 0.66667],
  2491. "8849": [0.13597, 0.63597, 0, 0, 0.77778],
  2492. "8850": [0.13597, 0.63597, 0, 0, 0.77778],
  2493. "8851": [0, 0.55556, 0, 0, 0.66667],
  2494. "8852": [0, 0.55556, 0, 0, 0.66667],
  2495. "8853": [0.08333, 0.58333, 0, 0, 0.77778],
  2496. "8854": [0.08333, 0.58333, 0, 0, 0.77778],
  2497. "8855": [0.08333, 0.58333, 0, 0, 0.77778],
  2498. "8856": [0.08333, 0.58333, 0, 0, 0.77778],
  2499. "8857": [0.08333, 0.58333, 0, 0, 0.77778],
  2500. "8866": [0, 0.69444, 0, 0, 0.61111],
  2501. "8867": [0, 0.69444, 0, 0, 0.61111],
  2502. "8868": [0, 0.69444, 0, 0, 0.77778],
  2503. "8869": [0, 0.69444, 0, 0, 0.77778],
  2504. "8872": [0.249, 0.75, 0, 0, 0.867],
  2505. "8900": [-0.05555, 0.44445, 0, 0, 0.5],
  2506. "8901": [-0.05555, 0.44445, 0, 0, 0.27778],
  2507. "8902": [-0.03472, 0.46528, 0, 0, 0.5],
  2508. "8904": [0.005, 0.505, 0, 0, 0.9],
  2509. "8942": [0.03, 0.903, 0, 0, 0.278],
  2510. "8943": [-0.19, 0.313, 0, 0, 1.172],
  2511. "8945": [-0.1, 0.823, 0, 0, 1.282],
  2512. "8968": [0.25, 0.75, 0, 0, 0.44445],
  2513. "8969": [0.25, 0.75, 0, 0, 0.44445],
  2514. "8970": [0.25, 0.75, 0, 0, 0.44445],
  2515. "8971": [0.25, 0.75, 0, 0, 0.44445],
  2516. "8994": [-0.14236, 0.35764, 0, 0, 1.0],
  2517. "8995": [-0.14236, 0.35764, 0, 0, 1.0],
  2518. "9136": [0.244, 0.744, 0, 0, 0.412],
  2519. "9137": [0.244, 0.745, 0, 0, 0.412],
  2520. "9651": [0.19444, 0.69444, 0, 0, 0.88889],
  2521. "9657": [-0.03472, 0.46528, 0, 0, 0.5],
  2522. "9661": [0.19444, 0.69444, 0, 0, 0.88889],
  2523. "9667": [-0.03472, 0.46528, 0, 0, 0.5],
  2524. "9711": [0.19444, 0.69444, 0, 0, 1.0],
  2525. "9824": [0.12963, 0.69444, 0, 0, 0.77778],
  2526. "9825": [0.12963, 0.69444, 0, 0, 0.77778],
  2527. "9826": [0.12963, 0.69444, 0, 0, 0.77778],
  2528. "9827": [0.12963, 0.69444, 0, 0, 0.77778],
  2529. "9837": [0, 0.75, 0, 0, 0.38889],
  2530. "9838": [0.19444, 0.69444, 0, 0, 0.38889],
  2531. "9839": [0.19444, 0.69444, 0, 0, 0.38889],
  2532. "10216": [0.25, 0.75, 0, 0, 0.38889],
  2533. "10217": [0.25, 0.75, 0, 0, 0.38889],
  2534. "10222": [0.244, 0.744, 0, 0, 0.412],
  2535. "10223": [0.244, 0.745, 0, 0, 0.412],
  2536. "10229": [0.011, 0.511, 0, 0, 1.609],
  2537. "10230": [0.011, 0.511, 0, 0, 1.638],
  2538. "10231": [0.011, 0.511, 0, 0, 1.859],
  2539. "10232": [0.024, 0.525, 0, 0, 1.609],
  2540. "10233": [0.024, 0.525, 0, 0, 1.638],
  2541. "10234": [0.024, 0.525, 0, 0, 1.858],
  2542. "10236": [0.011, 0.511, 0, 0, 1.638],
  2543. "10815": [0, 0.68333, 0, 0, 0.75],
  2544. "10927": [0.13597, 0.63597, 0, 0, 0.77778],
  2545. "10928": [0.13597, 0.63597, 0, 0, 0.77778],
  2546. "57376": [0.19444, 0.69444, 0, 0, 0]
  2547. },
  2548. "Math-BoldItalic": {
  2549. "32": [0, 0, 0, 0, 0.25],
  2550. "48": [0, 0.44444, 0, 0, 0.575],
  2551. "49": [0, 0.44444, 0, 0, 0.575],
  2552. "50": [0, 0.44444, 0, 0, 0.575],
  2553. "51": [0.19444, 0.44444, 0, 0, 0.575],
  2554. "52": [0.19444, 0.44444, 0, 0, 0.575],
  2555. "53": [0.19444, 0.44444, 0, 0, 0.575],
  2556. "54": [0, 0.64444, 0, 0, 0.575],
  2557. "55": [0.19444, 0.44444, 0, 0, 0.575],
  2558. "56": [0, 0.64444, 0, 0, 0.575],
  2559. "57": [0.19444, 0.44444, 0, 0, 0.575],
  2560. "65": [0, 0.68611, 0, 0, 0.86944],
  2561. "66": [0, 0.68611, 0.04835, 0, 0.8664],
  2562. "67": [0, 0.68611, 0.06979, 0, 0.81694],
  2563. "68": [0, 0.68611, 0.03194, 0, 0.93812],
  2564. "69": [0, 0.68611, 0.05451, 0, 0.81007],
  2565. "70": [0, 0.68611, 0.15972, 0, 0.68889],
  2566. "71": [0, 0.68611, 0, 0, 0.88673],
  2567. "72": [0, 0.68611, 0.08229, 0, 0.98229],
  2568. "73": [0, 0.68611, 0.07778, 0, 0.51111],
  2569. "74": [0, 0.68611, 0.10069, 0, 0.63125],
  2570. "75": [0, 0.68611, 0.06979, 0, 0.97118],
  2571. "76": [0, 0.68611, 0, 0, 0.75555],
  2572. "77": [0, 0.68611, 0.11424, 0, 1.14201],
  2573. "78": [0, 0.68611, 0.11424, 0, 0.95034],
  2574. "79": [0, 0.68611, 0.03194, 0, 0.83666],
  2575. "80": [0, 0.68611, 0.15972, 0, 0.72309],
  2576. "81": [0.19444, 0.68611, 0, 0, 0.86861],
  2577. "82": [0, 0.68611, 0.00421, 0, 0.87235],
  2578. "83": [0, 0.68611, 0.05382, 0, 0.69271],
  2579. "84": [0, 0.68611, 0.15972, 0, 0.63663],
  2580. "85": [0, 0.68611, 0.11424, 0, 0.80027],
  2581. "86": [0, 0.68611, 0.25555, 0, 0.67778],
  2582. "87": [0, 0.68611, 0.15972, 0, 1.09305],
  2583. "88": [0, 0.68611, 0.07778, 0, 0.94722],
  2584. "89": [0, 0.68611, 0.25555, 0, 0.67458],
  2585. "90": [0, 0.68611, 0.06979, 0, 0.77257],
  2586. "97": [0, 0.44444, 0, 0, 0.63287],
  2587. "98": [0, 0.69444, 0, 0, 0.52083],
  2588. "99": [0, 0.44444, 0, 0, 0.51342],
  2589. "100": [0, 0.69444, 0, 0, 0.60972],
  2590. "101": [0, 0.44444, 0, 0, 0.55361],
  2591. "102": [0.19444, 0.69444, 0.11042, 0, 0.56806],
  2592. "103": [0.19444, 0.44444, 0.03704, 0, 0.5449],
  2593. "104": [0, 0.69444, 0, 0, 0.66759],
  2594. "105": [0, 0.69326, 0, 0, 0.4048],
  2595. "106": [0.19444, 0.69326, 0.0622, 0, 0.47083],
  2596. "107": [0, 0.69444, 0.01852, 0, 0.6037],
  2597. "108": [0, 0.69444, 0.0088, 0, 0.34815],
  2598. "109": [0, 0.44444, 0, 0, 1.0324],
  2599. "110": [0, 0.44444, 0, 0, 0.71296],
  2600. "111": [0, 0.44444, 0, 0, 0.58472],
  2601. "112": [0.19444, 0.44444, 0, 0, 0.60092],
  2602. "113": [0.19444, 0.44444, 0.03704, 0, 0.54213],
  2603. "114": [0, 0.44444, 0.03194, 0, 0.5287],
  2604. "115": [0, 0.44444, 0, 0, 0.53125],
  2605. "116": [0, 0.63492, 0, 0, 0.41528],
  2606. "117": [0, 0.44444, 0, 0, 0.68102],
  2607. "118": [0, 0.44444, 0.03704, 0, 0.56666],
  2608. "119": [0, 0.44444, 0.02778, 0, 0.83148],
  2609. "120": [0, 0.44444, 0, 0, 0.65903],
  2610. "121": [0.19444, 0.44444, 0.03704, 0, 0.59028],
  2611. "122": [0, 0.44444, 0.04213, 0, 0.55509],
  2612. "160": [0, 0, 0, 0, 0.25],
  2613. "915": [0, 0.68611, 0.15972, 0, 0.65694],
  2614. "916": [0, 0.68611, 0, 0, 0.95833],
  2615. "920": [0, 0.68611, 0.03194, 0, 0.86722],
  2616. "923": [0, 0.68611, 0, 0, 0.80555],
  2617. "926": [0, 0.68611, 0.07458, 0, 0.84125],
  2618. "928": [0, 0.68611, 0.08229, 0, 0.98229],
  2619. "931": [0, 0.68611, 0.05451, 0, 0.88507],
  2620. "933": [0, 0.68611, 0.15972, 0, 0.67083],
  2621. "934": [0, 0.68611, 0, 0, 0.76666],
  2622. "936": [0, 0.68611, 0.11653, 0, 0.71402],
  2623. "937": [0, 0.68611, 0.04835, 0, 0.8789],
  2624. "945": [0, 0.44444, 0, 0, 0.76064],
  2625. "946": [0.19444, 0.69444, 0.03403, 0, 0.65972],
  2626. "947": [0.19444, 0.44444, 0.06389, 0, 0.59003],
  2627. "948": [0, 0.69444, 0.03819, 0, 0.52222],
  2628. "949": [0, 0.44444, 0, 0, 0.52882],
  2629. "950": [0.19444, 0.69444, 0.06215, 0, 0.50833],
  2630. "951": [0.19444, 0.44444, 0.03704, 0, 0.6],
  2631. "952": [0, 0.69444, 0.03194, 0, 0.5618],
  2632. "953": [0, 0.44444, 0, 0, 0.41204],
  2633. "954": [0, 0.44444, 0, 0, 0.66759],
  2634. "955": [0, 0.69444, 0, 0, 0.67083],
  2635. "956": [0.19444, 0.44444, 0, 0, 0.70787],
  2636. "957": [0, 0.44444, 0.06898, 0, 0.57685],
  2637. "958": [0.19444, 0.69444, 0.03021, 0, 0.50833],
  2638. "959": [0, 0.44444, 0, 0, 0.58472],
  2639. "960": [0, 0.44444, 0.03704, 0, 0.68241],
  2640. "961": [0.19444, 0.44444, 0, 0, 0.6118],
  2641. "962": [0.09722, 0.44444, 0.07917, 0, 0.42361],
  2642. "963": [0, 0.44444, 0.03704, 0, 0.68588],
  2643. "964": [0, 0.44444, 0.13472, 0, 0.52083],
  2644. "965": [0, 0.44444, 0.03704, 0, 0.63055],
  2645. "966": [0.19444, 0.44444, 0, 0, 0.74722],
  2646. "967": [0.19444, 0.44444, 0, 0, 0.71805],
  2647. "968": [0.19444, 0.69444, 0.03704, 0, 0.75833],
  2648. "969": [0, 0.44444, 0.03704, 0, 0.71782],
  2649. "977": [0, 0.69444, 0, 0, 0.69155],
  2650. "981": [0.19444, 0.69444, 0, 0, 0.7125],
  2651. "982": [0, 0.44444, 0.03194, 0, 0.975],
  2652. "1009": [0.19444, 0.44444, 0, 0, 0.6118],
  2653. "1013": [0, 0.44444, 0, 0, 0.48333],
  2654. "57649": [0, 0.44444, 0, 0, 0.39352],
  2655. "57911": [0.19444, 0.44444, 0, 0, 0.43889]
  2656. },
  2657. "Math-Italic": {
  2658. "32": [0, 0, 0, 0, 0.25],
  2659. "48": [0, 0.43056, 0, 0, 0.5],
  2660. "49": [0, 0.43056, 0, 0, 0.5],
  2661. "50": [0, 0.43056, 0, 0, 0.5],
  2662. "51": [0.19444, 0.43056, 0, 0, 0.5],
  2663. "52": [0.19444, 0.43056, 0, 0, 0.5],
  2664. "53": [0.19444, 0.43056, 0, 0, 0.5],
  2665. "54": [0, 0.64444, 0, 0, 0.5],
  2666. "55": [0.19444, 0.43056, 0, 0, 0.5],
  2667. "56": [0, 0.64444, 0, 0, 0.5],
  2668. "57": [0.19444, 0.43056, 0, 0, 0.5],
  2669. "65": [0, 0.68333, 0, 0.13889, 0.75],
  2670. "66": [0, 0.68333, 0.05017, 0.08334, 0.75851],
  2671. "67": [0, 0.68333, 0.07153, 0.08334, 0.71472],
  2672. "68": [0, 0.68333, 0.02778, 0.05556, 0.82792],
  2673. "69": [0, 0.68333, 0.05764, 0.08334, 0.7382],
  2674. "70": [0, 0.68333, 0.13889, 0.08334, 0.64306],
  2675. "71": [0, 0.68333, 0, 0.08334, 0.78625],
  2676. "72": [0, 0.68333, 0.08125, 0.05556, 0.83125],
  2677. "73": [0, 0.68333, 0.07847, 0.11111, 0.43958],
  2678. "74": [0, 0.68333, 0.09618, 0.16667, 0.55451],
  2679. "75": [0, 0.68333, 0.07153, 0.05556, 0.84931],
  2680. "76": [0, 0.68333, 0, 0.02778, 0.68056],
  2681. "77": [0, 0.68333, 0.10903, 0.08334, 0.97014],
  2682. "78": [0, 0.68333, 0.10903, 0.08334, 0.80347],
  2683. "79": [0, 0.68333, 0.02778, 0.08334, 0.76278],
  2684. "80": [0, 0.68333, 0.13889, 0.08334, 0.64201],
  2685. "81": [0.19444, 0.68333, 0, 0.08334, 0.79056],
  2686. "82": [0, 0.68333, 0.00773, 0.08334, 0.75929],
  2687. "83": [0, 0.68333, 0.05764, 0.08334, 0.6132],
  2688. "84": [0, 0.68333, 0.13889, 0.08334, 0.58438],
  2689. "85": [0, 0.68333, 0.10903, 0.02778, 0.68278],
  2690. "86": [0, 0.68333, 0.22222, 0, 0.58333],
  2691. "87": [0, 0.68333, 0.13889, 0, 0.94445],
  2692. "88": [0, 0.68333, 0.07847, 0.08334, 0.82847],
  2693. "89": [0, 0.68333, 0.22222, 0, 0.58056],
  2694. "90": [0, 0.68333, 0.07153, 0.08334, 0.68264],
  2695. "97": [0, 0.43056, 0, 0, 0.52859],
  2696. "98": [0, 0.69444, 0, 0, 0.42917],
  2697. "99": [0, 0.43056, 0, 0.05556, 0.43276],
  2698. "100": [0, 0.69444, 0, 0.16667, 0.52049],
  2699. "101": [0, 0.43056, 0, 0.05556, 0.46563],
  2700. "102": [0.19444, 0.69444, 0.10764, 0.16667, 0.48959],
  2701. "103": [0.19444, 0.43056, 0.03588, 0.02778, 0.47697],
  2702. "104": [0, 0.69444, 0, 0, 0.57616],
  2703. "105": [0, 0.65952, 0, 0, 0.34451],
  2704. "106": [0.19444, 0.65952, 0.05724, 0, 0.41181],
  2705. "107": [0, 0.69444, 0.03148, 0, 0.5206],
  2706. "108": [0, 0.69444, 0.01968, 0.08334, 0.29838],
  2707. "109": [0, 0.43056, 0, 0, 0.87801],
  2708. "110": [0, 0.43056, 0, 0, 0.60023],
  2709. "111": [0, 0.43056, 0, 0.05556, 0.48472],
  2710. "112": [0.19444, 0.43056, 0, 0.08334, 0.50313],
  2711. "113": [0.19444, 0.43056, 0.03588, 0.08334, 0.44641],
  2712. "114": [0, 0.43056, 0.02778, 0.05556, 0.45116],
  2713. "115": [0, 0.43056, 0, 0.05556, 0.46875],
  2714. "116": [0, 0.61508, 0, 0.08334, 0.36111],
  2715. "117": [0, 0.43056, 0, 0.02778, 0.57246],
  2716. "118": [0, 0.43056, 0.03588, 0.02778, 0.48472],
  2717. "119": [0, 0.43056, 0.02691, 0.08334, 0.71592],
  2718. "120": [0, 0.43056, 0, 0.02778, 0.57153],
  2719. "121": [0.19444, 0.43056, 0.03588, 0.05556, 0.49028],
  2720. "122": [0, 0.43056, 0.04398, 0.05556, 0.46505],
  2721. "160": [0, 0, 0, 0, 0.25],
  2722. "915": [0, 0.68333, 0.13889, 0.08334, 0.61528],
  2723. "916": [0, 0.68333, 0, 0.16667, 0.83334],
  2724. "920": [0, 0.68333, 0.02778, 0.08334, 0.76278],
  2725. "923": [0, 0.68333, 0, 0.16667, 0.69445],
  2726. "926": [0, 0.68333, 0.07569, 0.08334, 0.74236],
  2727. "928": [0, 0.68333, 0.08125, 0.05556, 0.83125],
  2728. "931": [0, 0.68333, 0.05764, 0.08334, 0.77986],
  2729. "933": [0, 0.68333, 0.13889, 0.05556, 0.58333],
  2730. "934": [0, 0.68333, 0, 0.08334, 0.66667],
  2731. "936": [0, 0.68333, 0.11, 0.05556, 0.61222],
  2732. "937": [0, 0.68333, 0.05017, 0.08334, 0.7724],
  2733. "945": [0, 0.43056, 0.0037, 0.02778, 0.6397],
  2734. "946": [0.19444, 0.69444, 0.05278, 0.08334, 0.56563],
  2735. "947": [0.19444, 0.43056, 0.05556, 0, 0.51773],
  2736. "948": [0, 0.69444, 0.03785, 0.05556, 0.44444],
  2737. "949": [0, 0.43056, 0, 0.08334, 0.46632],
  2738. "950": [0.19444, 0.69444, 0.07378, 0.08334, 0.4375],
  2739. "951": [0.19444, 0.43056, 0.03588, 0.05556, 0.49653],
  2740. "952": [0, 0.69444, 0.02778, 0.08334, 0.46944],
  2741. "953": [0, 0.43056, 0, 0.05556, 0.35394],
  2742. "954": [0, 0.43056, 0, 0, 0.57616],
  2743. "955": [0, 0.69444, 0, 0, 0.58334],
  2744. "956": [0.19444, 0.43056, 0, 0.02778, 0.60255],
  2745. "957": [0, 0.43056, 0.06366, 0.02778, 0.49398],
  2746. "958": [0.19444, 0.69444, 0.04601, 0.11111, 0.4375],
  2747. "959": [0, 0.43056, 0, 0.05556, 0.48472],
  2748. "960": [0, 0.43056, 0.03588, 0, 0.57003],
  2749. "961": [0.19444, 0.43056, 0, 0.08334, 0.51702],
  2750. "962": [0.09722, 0.43056, 0.07986, 0.08334, 0.36285],
  2751. "963": [0, 0.43056, 0.03588, 0, 0.57141],
  2752. "964": [0, 0.43056, 0.1132, 0.02778, 0.43715],
  2753. "965": [0, 0.43056, 0.03588, 0.02778, 0.54028],
  2754. "966": [0.19444, 0.43056, 0, 0.08334, 0.65417],
  2755. "967": [0.19444, 0.43056, 0, 0.05556, 0.62569],
  2756. "968": [0.19444, 0.69444, 0.03588, 0.11111, 0.65139],
  2757. "969": [0, 0.43056, 0.03588, 0, 0.62245],
  2758. "977": [0, 0.69444, 0, 0.08334, 0.59144],
  2759. "981": [0.19444, 0.69444, 0, 0.08334, 0.59583],
  2760. "982": [0, 0.43056, 0.02778, 0, 0.82813],
  2761. "1009": [0.19444, 0.43056, 0, 0.08334, 0.51702],
  2762. "1013": [0, 0.43056, 0, 0.05556, 0.4059],
  2763. "57649": [0, 0.43056, 0, 0.02778, 0.32246],
  2764. "57911": [0.19444, 0.43056, 0, 0.08334, 0.38403]
  2765. },
  2766. "SansSerif-Bold": {
  2767. "32": [0, 0, 0, 0, 0.25],
  2768. "33": [0, 0.69444, 0, 0, 0.36667],
  2769. "34": [0, 0.69444, 0, 0, 0.55834],
  2770. "35": [0.19444, 0.69444, 0, 0, 0.91667],
  2771. "36": [0.05556, 0.75, 0, 0, 0.55],
  2772. "37": [0.05556, 0.75, 0, 0, 1.02912],
  2773. "38": [0, 0.69444, 0, 0, 0.83056],
  2774. "39": [0, 0.69444, 0, 0, 0.30556],
  2775. "40": [0.25, 0.75, 0, 0, 0.42778],
  2776. "41": [0.25, 0.75, 0, 0, 0.42778],
  2777. "42": [0, 0.75, 0, 0, 0.55],
  2778. "43": [0.11667, 0.61667, 0, 0, 0.85556],
  2779. "44": [0.10556, 0.13056, 0, 0, 0.30556],
  2780. "45": [0, 0.45833, 0, 0, 0.36667],
  2781. "46": [0, 0.13056, 0, 0, 0.30556],
  2782. "47": [0.25, 0.75, 0, 0, 0.55],
  2783. "48": [0, 0.69444, 0, 0, 0.55],
  2784. "49": [0, 0.69444, 0, 0, 0.55],
  2785. "50": [0, 0.69444, 0, 0, 0.55],
  2786. "51": [0, 0.69444, 0, 0, 0.55],
  2787. "52": [0, 0.69444, 0, 0, 0.55],
  2788. "53": [0, 0.69444, 0, 0, 0.55],
  2789. "54": [0, 0.69444, 0, 0, 0.55],
  2790. "55": [0, 0.69444, 0, 0, 0.55],
  2791. "56": [0, 0.69444, 0, 0, 0.55],
  2792. "57": [0, 0.69444, 0, 0, 0.55],
  2793. "58": [0, 0.45833, 0, 0, 0.30556],
  2794. "59": [0.10556, 0.45833, 0, 0, 0.30556],
  2795. "61": [-0.09375, 0.40625, 0, 0, 0.85556],
  2796. "63": [0, 0.69444, 0, 0, 0.51945],
  2797. "64": [0, 0.69444, 0, 0, 0.73334],
  2798. "65": [0, 0.69444, 0, 0, 0.73334],
  2799. "66": [0, 0.69444, 0, 0, 0.73334],
  2800. "67": [0, 0.69444, 0, 0, 0.70278],
  2801. "68": [0, 0.69444, 0, 0, 0.79445],
  2802. "69": [0, 0.69444, 0, 0, 0.64167],
  2803. "70": [0, 0.69444, 0, 0, 0.61111],
  2804. "71": [0, 0.69444, 0, 0, 0.73334],
  2805. "72": [0, 0.69444, 0, 0, 0.79445],
  2806. "73": [0, 0.69444, 0, 0, 0.33056],
  2807. "74": [0, 0.69444, 0, 0, 0.51945],
  2808. "75": [0, 0.69444, 0, 0, 0.76389],
  2809. "76": [0, 0.69444, 0, 0, 0.58056],
  2810. "77": [0, 0.69444, 0, 0, 0.97778],
  2811. "78": [0, 0.69444, 0, 0, 0.79445],
  2812. "79": [0, 0.69444, 0, 0, 0.79445],
  2813. "80": [0, 0.69444, 0, 0, 0.70278],
  2814. "81": [0.10556, 0.69444, 0, 0, 0.79445],
  2815. "82": [0, 0.69444, 0, 0, 0.70278],
  2816. "83": [0, 0.69444, 0, 0, 0.61111],
  2817. "84": [0, 0.69444, 0, 0, 0.73334],
  2818. "85": [0, 0.69444, 0, 0, 0.76389],
  2819. "86": [0, 0.69444, 0.01528, 0, 0.73334],
  2820. "87": [0, 0.69444, 0.01528, 0, 1.03889],
  2821. "88": [0, 0.69444, 0, 0, 0.73334],
  2822. "89": [0, 0.69444, 0.0275, 0, 0.73334],
  2823. "90": [0, 0.69444, 0, 0, 0.67223],
  2824. "91": [0.25, 0.75, 0, 0, 0.34306],
  2825. "93": [0.25, 0.75, 0, 0, 0.34306],
  2826. "94": [0, 0.69444, 0, 0, 0.55],
  2827. "95": [0.35, 0.10833, 0.03056, 0, 0.55],
  2828. "97": [0, 0.45833, 0, 0, 0.525],
  2829. "98": [0, 0.69444, 0, 0, 0.56111],
  2830. "99": [0, 0.45833, 0, 0, 0.48889],
  2831. "100": [0, 0.69444, 0, 0, 0.56111],
  2832. "101": [0, 0.45833, 0, 0, 0.51111],
  2833. "102": [0, 0.69444, 0.07639, 0, 0.33611],
  2834. "103": [0.19444, 0.45833, 0.01528, 0, 0.55],
  2835. "104": [0, 0.69444, 0, 0, 0.56111],
  2836. "105": [0, 0.69444, 0, 0, 0.25556],
  2837. "106": [0.19444, 0.69444, 0, 0, 0.28611],
  2838. "107": [0, 0.69444, 0, 0, 0.53056],
  2839. "108": [0, 0.69444, 0, 0, 0.25556],
  2840. "109": [0, 0.45833, 0, 0, 0.86667],
  2841. "110": [0, 0.45833, 0, 0, 0.56111],
  2842. "111": [0, 0.45833, 0, 0, 0.55],
  2843. "112": [0.19444, 0.45833, 0, 0, 0.56111],
  2844. "113": [0.19444, 0.45833, 0, 0, 0.56111],
  2845. "114": [0, 0.45833, 0.01528, 0, 0.37222],
  2846. "115": [0, 0.45833, 0, 0, 0.42167],
  2847. "116": [0, 0.58929, 0, 0, 0.40417],
  2848. "117": [0, 0.45833, 0, 0, 0.56111],
  2849. "118": [0, 0.45833, 0.01528, 0, 0.5],
  2850. "119": [0, 0.45833, 0.01528, 0, 0.74445],
  2851. "120": [0, 0.45833, 0, 0, 0.5],
  2852. "121": [0.19444, 0.45833, 0.01528, 0, 0.5],
  2853. "122": [0, 0.45833, 0, 0, 0.47639],
  2854. "126": [0.35, 0.34444, 0, 0, 0.55],
  2855. "160": [0, 0, 0, 0, 0.25],
  2856. "168": [0, 0.69444, 0, 0, 0.55],
  2857. "176": [0, 0.69444, 0, 0, 0.73334],
  2858. "180": [0, 0.69444, 0, 0, 0.55],
  2859. "184": [0.17014, 0, 0, 0, 0.48889],
  2860. "305": [0, 0.45833, 0, 0, 0.25556],
  2861. "567": [0.19444, 0.45833, 0, 0, 0.28611],
  2862. "710": [0, 0.69444, 0, 0, 0.55],
  2863. "711": [0, 0.63542, 0, 0, 0.55],
  2864. "713": [0, 0.63778, 0, 0, 0.55],
  2865. "728": [0, 0.69444, 0, 0, 0.55],
  2866. "729": [0, 0.69444, 0, 0, 0.30556],
  2867. "730": [0, 0.69444, 0, 0, 0.73334],
  2868. "732": [0, 0.69444, 0, 0, 0.55],
  2869. "733": [0, 0.69444, 0, 0, 0.55],
  2870. "915": [0, 0.69444, 0, 0, 0.58056],
  2871. "916": [0, 0.69444, 0, 0, 0.91667],
  2872. "920": [0, 0.69444, 0, 0, 0.85556],
  2873. "923": [0, 0.69444, 0, 0, 0.67223],
  2874. "926": [0, 0.69444, 0, 0, 0.73334],
  2875. "928": [0, 0.69444, 0, 0, 0.79445],
  2876. "931": [0, 0.69444, 0, 0, 0.79445],
  2877. "933": [0, 0.69444, 0, 0, 0.85556],
  2878. "934": [0, 0.69444, 0, 0, 0.79445],
  2879. "936": [0, 0.69444, 0, 0, 0.85556],
  2880. "937": [0, 0.69444, 0, 0, 0.79445],
  2881. "8211": [0, 0.45833, 0.03056, 0, 0.55],
  2882. "8212": [0, 0.45833, 0.03056, 0, 1.10001],
  2883. "8216": [0, 0.69444, 0, 0, 0.30556],
  2884. "8217": [0, 0.69444, 0, 0, 0.30556],
  2885. "8220": [0, 0.69444, 0, 0, 0.55834],
  2886. "8221": [0, 0.69444, 0, 0, 0.55834]
  2887. },
  2888. "SansSerif-Italic": {
  2889. "32": [0, 0, 0, 0, 0.25],
  2890. "33": [0, 0.69444, 0.05733, 0, 0.31945],
  2891. "34": [0, 0.69444, 0.00316, 0, 0.5],
  2892. "35": [0.19444, 0.69444, 0.05087, 0, 0.83334],
  2893. "36": [0.05556, 0.75, 0.11156, 0, 0.5],
  2894. "37": [0.05556, 0.75, 0.03126, 0, 0.83334],
  2895. "38": [0, 0.69444, 0.03058, 0, 0.75834],
  2896. "39": [0, 0.69444, 0.07816, 0, 0.27778],
  2897. "40": [0.25, 0.75, 0.13164, 0, 0.38889],
  2898. "41": [0.25, 0.75, 0.02536, 0, 0.38889],
  2899. "42": [0, 0.75, 0.11775, 0, 0.5],
  2900. "43": [0.08333, 0.58333, 0.02536, 0, 0.77778],
  2901. "44": [0.125, 0.08333, 0, 0, 0.27778],
  2902. "45": [0, 0.44444, 0.01946, 0, 0.33333],
  2903. "46": [0, 0.08333, 0, 0, 0.27778],
  2904. "47": [0.25, 0.75, 0.13164, 0, 0.5],
  2905. "48": [0, 0.65556, 0.11156, 0, 0.5],
  2906. "49": [0, 0.65556, 0.11156, 0, 0.5],
  2907. "50": [0, 0.65556, 0.11156, 0, 0.5],
  2908. "51": [0, 0.65556, 0.11156, 0, 0.5],
  2909. "52": [0, 0.65556, 0.11156, 0, 0.5],
  2910. "53": [0, 0.65556, 0.11156, 0, 0.5],
  2911. "54": [0, 0.65556, 0.11156, 0, 0.5],
  2912. "55": [0, 0.65556, 0.11156, 0, 0.5],
  2913. "56": [0, 0.65556, 0.11156, 0, 0.5],
  2914. "57": [0, 0.65556, 0.11156, 0, 0.5],
  2915. "58": [0, 0.44444, 0.02502, 0, 0.27778],
  2916. "59": [0.125, 0.44444, 0.02502, 0, 0.27778],
  2917. "61": [-0.13, 0.37, 0.05087, 0, 0.77778],
  2918. "63": [0, 0.69444, 0.11809, 0, 0.47222],
  2919. "64": [0, 0.69444, 0.07555, 0, 0.66667],
  2920. "65": [0, 0.69444, 0, 0, 0.66667],
  2921. "66": [0, 0.69444, 0.08293, 0, 0.66667],
  2922. "67": [0, 0.69444, 0.11983, 0, 0.63889],
  2923. "68": [0, 0.69444, 0.07555, 0, 0.72223],
  2924. "69": [0, 0.69444, 0.11983, 0, 0.59722],
  2925. "70": [0, 0.69444, 0.13372, 0, 0.56945],
  2926. "71": [0, 0.69444, 0.11983, 0, 0.66667],
  2927. "72": [0, 0.69444, 0.08094, 0, 0.70834],
  2928. "73": [0, 0.69444, 0.13372, 0, 0.27778],
  2929. "74": [0, 0.69444, 0.08094, 0, 0.47222],
  2930. "75": [0, 0.69444, 0.11983, 0, 0.69445],
  2931. "76": [0, 0.69444, 0, 0, 0.54167],
  2932. "77": [0, 0.69444, 0.08094, 0, 0.875],
  2933. "78": [0, 0.69444, 0.08094, 0, 0.70834],
  2934. "79": [0, 0.69444, 0.07555, 0, 0.73611],
  2935. "80": [0, 0.69444, 0.08293, 0, 0.63889],
  2936. "81": [0.125, 0.69444, 0.07555, 0, 0.73611],
  2937. "82": [0, 0.69444, 0.08293, 0, 0.64584],
  2938. "83": [0, 0.69444, 0.09205, 0, 0.55556],
  2939. "84": [0, 0.69444, 0.13372, 0, 0.68056],
  2940. "85": [0, 0.69444, 0.08094, 0, 0.6875],
  2941. "86": [0, 0.69444, 0.1615, 0, 0.66667],
  2942. "87": [0, 0.69444, 0.1615, 0, 0.94445],
  2943. "88": [0, 0.69444, 0.13372, 0, 0.66667],
  2944. "89": [0, 0.69444, 0.17261, 0, 0.66667],
  2945. "90": [0, 0.69444, 0.11983, 0, 0.61111],
  2946. "91": [0.25, 0.75, 0.15942, 0, 0.28889],
  2947. "93": [0.25, 0.75, 0.08719, 0, 0.28889],
  2948. "94": [0, 0.69444, 0.0799, 0, 0.5],
  2949. "95": [0.35, 0.09444, 0.08616, 0, 0.5],
  2950. "97": [0, 0.44444, 0.00981, 0, 0.48056],
  2951. "98": [0, 0.69444, 0.03057, 0, 0.51667],
  2952. "99": [0, 0.44444, 0.08336, 0, 0.44445],
  2953. "100": [0, 0.69444, 0.09483, 0, 0.51667],
  2954. "101": [0, 0.44444, 0.06778, 0, 0.44445],
  2955. "102": [0, 0.69444, 0.21705, 0, 0.30556],
  2956. "103": [0.19444, 0.44444, 0.10836, 0, 0.5],
  2957. "104": [0, 0.69444, 0.01778, 0, 0.51667],
  2958. "105": [0, 0.67937, 0.09718, 0, 0.23889],
  2959. "106": [0.19444, 0.67937, 0.09162, 0, 0.26667],
  2960. "107": [0, 0.69444, 0.08336, 0, 0.48889],
  2961. "108": [0, 0.69444, 0.09483, 0, 0.23889],
  2962. "109": [0, 0.44444, 0.01778, 0, 0.79445],
  2963. "110": [0, 0.44444, 0.01778, 0, 0.51667],
  2964. "111": [0, 0.44444, 0.06613, 0, 0.5],
  2965. "112": [0.19444, 0.44444, 0.0389, 0, 0.51667],
  2966. "113": [0.19444, 0.44444, 0.04169, 0, 0.51667],
  2967. "114": [0, 0.44444, 0.10836, 0, 0.34167],
  2968. "115": [0, 0.44444, 0.0778, 0, 0.38333],
  2969. "116": [0, 0.57143, 0.07225, 0, 0.36111],
  2970. "117": [0, 0.44444, 0.04169, 0, 0.51667],
  2971. "118": [0, 0.44444, 0.10836, 0, 0.46111],
  2972. "119": [0, 0.44444, 0.10836, 0, 0.68334],
  2973. "120": [0, 0.44444, 0.09169, 0, 0.46111],
  2974. "121": [0.19444, 0.44444, 0.10836, 0, 0.46111],
  2975. "122": [0, 0.44444, 0.08752, 0, 0.43472],
  2976. "126": [0.35, 0.32659, 0.08826, 0, 0.5],
  2977. "160": [0, 0, 0, 0, 0.25],
  2978. "168": [0, 0.67937, 0.06385, 0, 0.5],
  2979. "176": [0, 0.69444, 0, 0, 0.73752],
  2980. "184": [0.17014, 0, 0, 0, 0.44445],
  2981. "305": [0, 0.44444, 0.04169, 0, 0.23889],
  2982. "567": [0.19444, 0.44444, 0.04169, 0, 0.26667],
  2983. "710": [0, 0.69444, 0.0799, 0, 0.5],
  2984. "711": [0, 0.63194, 0.08432, 0, 0.5],
  2985. "713": [0, 0.60889, 0.08776, 0, 0.5],
  2986. "714": [0, 0.69444, 0.09205, 0, 0.5],
  2987. "715": [0, 0.69444, 0, 0, 0.5],
  2988. "728": [0, 0.69444, 0.09483, 0, 0.5],
  2989. "729": [0, 0.67937, 0.07774, 0, 0.27778],
  2990. "730": [0, 0.69444, 0, 0, 0.73752],
  2991. "732": [0, 0.67659, 0.08826, 0, 0.5],
  2992. "733": [0, 0.69444, 0.09205, 0, 0.5],
  2993. "915": [0, 0.69444, 0.13372, 0, 0.54167],
  2994. "916": [0, 0.69444, 0, 0, 0.83334],
  2995. "920": [0, 0.69444, 0.07555, 0, 0.77778],
  2996. "923": [0, 0.69444, 0, 0, 0.61111],
  2997. "926": [0, 0.69444, 0.12816, 0, 0.66667],
  2998. "928": [0, 0.69444, 0.08094, 0, 0.70834],
  2999. "931": [0, 0.69444, 0.11983, 0, 0.72222],
  3000. "933": [0, 0.69444, 0.09031, 0, 0.77778],
  3001. "934": [0, 0.69444, 0.04603, 0, 0.72222],
  3002. "936": [0, 0.69444, 0.09031, 0, 0.77778],
  3003. "937": [0, 0.69444, 0.08293, 0, 0.72222],
  3004. "8211": [0, 0.44444, 0.08616, 0, 0.5],
  3005. "8212": [0, 0.44444, 0.08616, 0, 1.0],
  3006. "8216": [0, 0.69444, 0.07816, 0, 0.27778],
  3007. "8217": [0, 0.69444, 0.07816, 0, 0.27778],
  3008. "8220": [0, 0.69444, 0.14205, 0, 0.5],
  3009. "8221": [0, 0.69444, 0.00316, 0, 0.5]
  3010. },
  3011. "SansSerif-Regular": {
  3012. "32": [0, 0, 0, 0, 0.25],
  3013. "33": [0, 0.69444, 0, 0, 0.31945],
  3014. "34": [0, 0.69444, 0, 0, 0.5],
  3015. "35": [0.19444, 0.69444, 0, 0, 0.83334],
  3016. "36": [0.05556, 0.75, 0, 0, 0.5],
  3017. "37": [0.05556, 0.75, 0, 0, 0.83334],
  3018. "38": [0, 0.69444, 0, 0, 0.75834],
  3019. "39": [0, 0.69444, 0, 0, 0.27778],
  3020. "40": [0.25, 0.75, 0, 0, 0.38889],
  3021. "41": [0.25, 0.75, 0, 0, 0.38889],
  3022. "42": [0, 0.75, 0, 0, 0.5],
  3023. "43": [0.08333, 0.58333, 0, 0, 0.77778],
  3024. "44": [0.125, 0.08333, 0, 0, 0.27778],
  3025. "45": [0, 0.44444, 0, 0, 0.33333],
  3026. "46": [0, 0.08333, 0, 0, 0.27778],
  3027. "47": [0.25, 0.75, 0, 0, 0.5],
  3028. "48": [0, 0.65556, 0, 0, 0.5],
  3029. "49": [0, 0.65556, 0, 0, 0.5],
  3030. "50": [0, 0.65556, 0, 0, 0.5],
  3031. "51": [0, 0.65556, 0, 0, 0.5],
  3032. "52": [0, 0.65556, 0, 0, 0.5],
  3033. "53": [0, 0.65556, 0, 0, 0.5],
  3034. "54": [0, 0.65556, 0, 0, 0.5],
  3035. "55": [0, 0.65556, 0, 0, 0.5],
  3036. "56": [0, 0.65556, 0, 0, 0.5],
  3037. "57": [0, 0.65556, 0, 0, 0.5],
  3038. "58": [0, 0.44444, 0, 0, 0.27778],
  3039. "59": [0.125, 0.44444, 0, 0, 0.27778],
  3040. "61": [-0.13, 0.37, 0, 0, 0.77778],
  3041. "63": [0, 0.69444, 0, 0, 0.47222],
  3042. "64": [0, 0.69444, 0, 0, 0.66667],
  3043. "65": [0, 0.69444, 0, 0, 0.66667],
  3044. "66": [0, 0.69444, 0, 0, 0.66667],
  3045. "67": [0, 0.69444, 0, 0, 0.63889],
  3046. "68": [0, 0.69444, 0, 0, 0.72223],
  3047. "69": [0, 0.69444, 0, 0, 0.59722],
  3048. "70": [0, 0.69444, 0, 0, 0.56945],
  3049. "71": [0, 0.69444, 0, 0, 0.66667],
  3050. "72": [0, 0.69444, 0, 0, 0.70834],
  3051. "73": [0, 0.69444, 0, 0, 0.27778],
  3052. "74": [0, 0.69444, 0, 0, 0.47222],
  3053. "75": [0, 0.69444, 0, 0, 0.69445],
  3054. "76": [0, 0.69444, 0, 0, 0.54167],
  3055. "77": [0, 0.69444, 0, 0, 0.875],
  3056. "78": [0, 0.69444, 0, 0, 0.70834],
  3057. "79": [0, 0.69444, 0, 0, 0.73611],
  3058. "80": [0, 0.69444, 0, 0, 0.63889],
  3059. "81": [0.125, 0.69444, 0, 0, 0.73611],
  3060. "82": [0, 0.69444, 0, 0, 0.64584],
  3061. "83": [0, 0.69444, 0, 0, 0.55556],
  3062. "84": [0, 0.69444, 0, 0, 0.68056],
  3063. "85": [0, 0.69444, 0, 0, 0.6875],
  3064. "86": [0, 0.69444, 0.01389, 0, 0.66667],
  3065. "87": [0, 0.69444, 0.01389, 0, 0.94445],
  3066. "88": [0, 0.69444, 0, 0, 0.66667],
  3067. "89": [0, 0.69444, 0.025, 0, 0.66667],
  3068. "90": [0, 0.69444, 0, 0, 0.61111],
  3069. "91": [0.25, 0.75, 0, 0, 0.28889],
  3070. "93": [0.25, 0.75, 0, 0, 0.28889],
  3071. "94": [0, 0.69444, 0, 0, 0.5],
  3072. "95": [0.35, 0.09444, 0.02778, 0, 0.5],
  3073. "97": [0, 0.44444, 0, 0, 0.48056],
  3074. "98": [0, 0.69444, 0, 0, 0.51667],
  3075. "99": [0, 0.44444, 0, 0, 0.44445],
  3076. "100": [0, 0.69444, 0, 0, 0.51667],
  3077. "101": [0, 0.44444, 0, 0, 0.44445],
  3078. "102": [0, 0.69444, 0.06944, 0, 0.30556],
  3079. "103": [0.19444, 0.44444, 0.01389, 0, 0.5],
  3080. "104": [0, 0.69444, 0, 0, 0.51667],
  3081. "105": [0, 0.67937, 0, 0, 0.23889],
  3082. "106": [0.19444, 0.67937, 0, 0, 0.26667],
  3083. "107": [0, 0.69444, 0, 0, 0.48889],
  3084. "108": [0, 0.69444, 0, 0, 0.23889],
  3085. "109": [0, 0.44444, 0, 0, 0.79445],
  3086. "110": [0, 0.44444, 0, 0, 0.51667],
  3087. "111": [0, 0.44444, 0, 0, 0.5],
  3088. "112": [0.19444, 0.44444, 0, 0, 0.51667],
  3089. "113": [0.19444, 0.44444, 0, 0, 0.51667],
  3090. "114": [0, 0.44444, 0.01389, 0, 0.34167],
  3091. "115": [0, 0.44444, 0, 0, 0.38333],
  3092. "116": [0, 0.57143, 0, 0, 0.36111],
  3093. "117": [0, 0.44444, 0, 0, 0.51667],
  3094. "118": [0, 0.44444, 0.01389, 0, 0.46111],
  3095. "119": [0, 0.44444, 0.01389, 0, 0.68334],
  3096. "120": [0, 0.44444, 0, 0, 0.46111],
  3097. "121": [0.19444, 0.44444, 0.01389, 0, 0.46111],
  3098. "122": [0, 0.44444, 0, 0, 0.43472],
  3099. "126": [0.35, 0.32659, 0, 0, 0.5],
  3100. "160": [0, 0, 0, 0, 0.25],
  3101. "168": [0, 0.67937, 0, 0, 0.5],
  3102. "176": [0, 0.69444, 0, 0, 0.66667],
  3103. "184": [0.17014, 0, 0, 0, 0.44445],
  3104. "305": [0, 0.44444, 0, 0, 0.23889],
  3105. "567": [0.19444, 0.44444, 0, 0, 0.26667],
  3106. "710": [0, 0.69444, 0, 0, 0.5],
  3107. "711": [0, 0.63194, 0, 0, 0.5],
  3108. "713": [0, 0.60889, 0, 0, 0.5],
  3109. "714": [0, 0.69444, 0, 0, 0.5],
  3110. "715": [0, 0.69444, 0, 0, 0.5],
  3111. "728": [0, 0.69444, 0, 0, 0.5],
  3112. "729": [0, 0.67937, 0, 0, 0.27778],
  3113. "730": [0, 0.69444, 0, 0, 0.66667],
  3114. "732": [0, 0.67659, 0, 0, 0.5],
  3115. "733": [0, 0.69444, 0, 0, 0.5],
  3116. "915": [0, 0.69444, 0, 0, 0.54167],
  3117. "916": [0, 0.69444, 0, 0, 0.83334],
  3118. "920": [0, 0.69444, 0, 0, 0.77778],
  3119. "923": [0, 0.69444, 0, 0, 0.61111],
  3120. "926": [0, 0.69444, 0, 0, 0.66667],
  3121. "928": [0, 0.69444, 0, 0, 0.70834],
  3122. "931": [0, 0.69444, 0, 0, 0.72222],
  3123. "933": [0, 0.69444, 0, 0, 0.77778],
  3124. "934": [0, 0.69444, 0, 0, 0.72222],
  3125. "936": [0, 0.69444, 0, 0, 0.77778],
  3126. "937": [0, 0.69444, 0, 0, 0.72222],
  3127. "8211": [0, 0.44444, 0.02778, 0, 0.5],
  3128. "8212": [0, 0.44444, 0.02778, 0, 1.0],
  3129. "8216": [0, 0.69444, 0, 0, 0.27778],
  3130. "8217": [0, 0.69444, 0, 0, 0.27778],
  3131. "8220": [0, 0.69444, 0, 0, 0.5],
  3132. "8221": [0, 0.69444, 0, 0, 0.5]
  3133. },
  3134. "Script-Regular": {
  3135. "32": [0, 0, 0, 0, 0.25],
  3136. "65": [0, 0.7, 0.22925, 0, 0.80253],
  3137. "66": [0, 0.7, 0.04087, 0, 0.90757],
  3138. "67": [0, 0.7, 0.1689, 0, 0.66619],
  3139. "68": [0, 0.7, 0.09371, 0, 0.77443],
  3140. "69": [0, 0.7, 0.18583, 0, 0.56162],
  3141. "70": [0, 0.7, 0.13634, 0, 0.89544],
  3142. "71": [0, 0.7, 0.17322, 0, 0.60961],
  3143. "72": [0, 0.7, 0.29694, 0, 0.96919],
  3144. "73": [0, 0.7, 0.19189, 0, 0.80907],
  3145. "74": [0.27778, 0.7, 0.19189, 0, 1.05159],
  3146. "75": [0, 0.7, 0.31259, 0, 0.91364],
  3147. "76": [0, 0.7, 0.19189, 0, 0.87373],
  3148. "77": [0, 0.7, 0.15981, 0, 1.08031],
  3149. "78": [0, 0.7, 0.3525, 0, 0.9015],
  3150. "79": [0, 0.7, 0.08078, 0, 0.73787],
  3151. "80": [0, 0.7, 0.08078, 0, 1.01262],
  3152. "81": [0, 0.7, 0.03305, 0, 0.88282],
  3153. "82": [0, 0.7, 0.06259, 0, 0.85],
  3154. "83": [0, 0.7, 0.19189, 0, 0.86767],
  3155. "84": [0, 0.7, 0.29087, 0, 0.74697],
  3156. "85": [0, 0.7, 0.25815, 0, 0.79996],
  3157. "86": [0, 0.7, 0.27523, 0, 0.62204],
  3158. "87": [0, 0.7, 0.27523, 0, 0.80532],
  3159. "88": [0, 0.7, 0.26006, 0, 0.94445],
  3160. "89": [0, 0.7, 0.2939, 0, 0.70961],
  3161. "90": [0, 0.7, 0.24037, 0, 0.8212],
  3162. "160": [0, 0, 0, 0, 0.25]
  3163. },
  3164. "Size1-Regular": {
  3165. "32": [0, 0, 0, 0, 0.25],
  3166. "40": [0.35001, 0.85, 0, 0, 0.45834],
  3167. "41": [0.35001, 0.85, 0, 0, 0.45834],
  3168. "47": [0.35001, 0.85, 0, 0, 0.57778],
  3169. "91": [0.35001, 0.85, 0, 0, 0.41667],
  3170. "92": [0.35001, 0.85, 0, 0, 0.57778],
  3171. "93": [0.35001, 0.85, 0, 0, 0.41667],
  3172. "123": [0.35001, 0.85, 0, 0, 0.58334],
  3173. "125": [0.35001, 0.85, 0, 0, 0.58334],
  3174. "160": [0, 0, 0, 0, 0.25],
  3175. "710": [0, 0.72222, 0, 0, 0.55556],
  3176. "732": [0, 0.72222, 0, 0, 0.55556],
  3177. "770": [0, 0.72222, 0, 0, 0.55556],
  3178. "771": [0, 0.72222, 0, 0, 0.55556],
  3179. "8214": [-0.00099, 0.601, 0, 0, 0.77778],
  3180. "8593": [1e-05, 0.6, 0, 0, 0.66667],
  3181. "8595": [1e-05, 0.6, 0, 0, 0.66667],
  3182. "8657": [1e-05, 0.6, 0, 0, 0.77778],
  3183. "8659": [1e-05, 0.6, 0, 0, 0.77778],
  3184. "8719": [0.25001, 0.75, 0, 0, 0.94445],
  3185. "8720": [0.25001, 0.75, 0, 0, 0.94445],
  3186. "8721": [0.25001, 0.75, 0, 0, 1.05556],
  3187. "8730": [0.35001, 0.85, 0, 0, 1.0],
  3188. "8739": [-0.00599, 0.606, 0, 0, 0.33333],
  3189. "8741": [-0.00599, 0.606, 0, 0, 0.55556],
  3190. "8747": [0.30612, 0.805, 0.19445, 0, 0.47222],
  3191. "8748": [0.306, 0.805, 0.19445, 0, 0.47222],
  3192. "8749": [0.306, 0.805, 0.19445, 0, 0.47222],
  3193. "8750": [0.30612, 0.805, 0.19445, 0, 0.47222],
  3194. "8896": [0.25001, 0.75, 0, 0, 0.83334],
  3195. "8897": [0.25001, 0.75, 0, 0, 0.83334],
  3196. "8898": [0.25001, 0.75, 0, 0, 0.83334],
  3197. "8899": [0.25001, 0.75, 0, 0, 0.83334],
  3198. "8968": [0.35001, 0.85, 0, 0, 0.47222],
  3199. "8969": [0.35001, 0.85, 0, 0, 0.47222],
  3200. "8970": [0.35001, 0.85, 0, 0, 0.47222],
  3201. "8971": [0.35001, 0.85, 0, 0, 0.47222],
  3202. "9168": [-0.00099, 0.601, 0, 0, 0.66667],
  3203. "10216": [0.35001, 0.85, 0, 0, 0.47222],
  3204. "10217": [0.35001, 0.85, 0, 0, 0.47222],
  3205. "10752": [0.25001, 0.75, 0, 0, 1.11111],
  3206. "10753": [0.25001, 0.75, 0, 0, 1.11111],
  3207. "10754": [0.25001, 0.75, 0, 0, 1.11111],
  3208. "10756": [0.25001, 0.75, 0, 0, 0.83334],
  3209. "10758": [0.25001, 0.75, 0, 0, 0.83334]
  3210. },
  3211. "Size2-Regular": {
  3212. "32": [0, 0, 0, 0, 0.25],
  3213. "40": [0.65002, 1.15, 0, 0, 0.59722],
  3214. "41": [0.65002, 1.15, 0, 0, 0.59722],
  3215. "47": [0.65002, 1.15, 0, 0, 0.81111],
  3216. "91": [0.65002, 1.15, 0, 0, 0.47222],
  3217. "92": [0.65002, 1.15, 0, 0, 0.81111],
  3218. "93": [0.65002, 1.15, 0, 0, 0.47222],
  3219. "123": [0.65002, 1.15, 0, 0, 0.66667],
  3220. "125": [0.65002, 1.15, 0, 0, 0.66667],
  3221. "160": [0, 0, 0, 0, 0.25],
  3222. "710": [0, 0.75, 0, 0, 1.0],
  3223. "732": [0, 0.75, 0, 0, 1.0],
  3224. "770": [0, 0.75, 0, 0, 1.0],
  3225. "771": [0, 0.75, 0, 0, 1.0],
  3226. "8719": [0.55001, 1.05, 0, 0, 1.27778],
  3227. "8720": [0.55001, 1.05, 0, 0, 1.27778],
  3228. "8721": [0.55001, 1.05, 0, 0, 1.44445],
  3229. "8730": [0.65002, 1.15, 0, 0, 1.0],
  3230. "8747": [0.86225, 1.36, 0.44445, 0, 0.55556],
  3231. "8748": [0.862, 1.36, 0.44445, 0, 0.55556],
  3232. "8749": [0.862, 1.36, 0.44445, 0, 0.55556],
  3233. "8750": [0.86225, 1.36, 0.44445, 0, 0.55556],
  3234. "8896": [0.55001, 1.05, 0, 0, 1.11111],
  3235. "8897": [0.55001, 1.05, 0, 0, 1.11111],
  3236. "8898": [0.55001, 1.05, 0, 0, 1.11111],
  3237. "8899": [0.55001, 1.05, 0, 0, 1.11111],
  3238. "8968": [0.65002, 1.15, 0, 0, 0.52778],
  3239. "8969": [0.65002, 1.15, 0, 0, 0.52778],
  3240. "8970": [0.65002, 1.15, 0, 0, 0.52778],
  3241. "8971": [0.65002, 1.15, 0, 0, 0.52778],
  3242. "10216": [0.65002, 1.15, 0, 0, 0.61111],
  3243. "10217": [0.65002, 1.15, 0, 0, 0.61111],
  3244. "10752": [0.55001, 1.05, 0, 0, 1.51112],
  3245. "10753": [0.55001, 1.05, 0, 0, 1.51112],
  3246. "10754": [0.55001, 1.05, 0, 0, 1.51112],
  3247. "10756": [0.55001, 1.05, 0, 0, 1.11111],
  3248. "10758": [0.55001, 1.05, 0, 0, 1.11111]
  3249. },
  3250. "Size3-Regular": {
  3251. "32": [0, 0, 0, 0, 0.25],
  3252. "40": [0.95003, 1.45, 0, 0, 0.73611],
  3253. "41": [0.95003, 1.45, 0, 0, 0.73611],
  3254. "47": [0.95003, 1.45, 0, 0, 1.04445],
  3255. "91": [0.95003, 1.45, 0, 0, 0.52778],
  3256. "92": [0.95003, 1.45, 0, 0, 1.04445],
  3257. "93": [0.95003, 1.45, 0, 0, 0.52778],
  3258. "123": [0.95003, 1.45, 0, 0, 0.75],
  3259. "125": [0.95003, 1.45, 0, 0, 0.75],
  3260. "160": [0, 0, 0, 0, 0.25],
  3261. "710": [0, 0.75, 0, 0, 1.44445],
  3262. "732": [0, 0.75, 0, 0, 1.44445],
  3263. "770": [0, 0.75, 0, 0, 1.44445],
  3264. "771": [0, 0.75, 0, 0, 1.44445],
  3265. "8730": [0.95003, 1.45, 0, 0, 1.0],
  3266. "8968": [0.95003, 1.45, 0, 0, 0.58334],
  3267. "8969": [0.95003, 1.45, 0, 0, 0.58334],
  3268. "8970": [0.95003, 1.45, 0, 0, 0.58334],
  3269. "8971": [0.95003, 1.45, 0, 0, 0.58334],
  3270. "10216": [0.95003, 1.45, 0, 0, 0.75],
  3271. "10217": [0.95003, 1.45, 0, 0, 0.75]
  3272. },
  3273. "Size4-Regular": {
  3274. "32": [0, 0, 0, 0, 0.25],
  3275. "40": [1.25003, 1.75, 0, 0, 0.79167],
  3276. "41": [1.25003, 1.75, 0, 0, 0.79167],
  3277. "47": [1.25003, 1.75, 0, 0, 1.27778],
  3278. "91": [1.25003, 1.75, 0, 0, 0.58334],
  3279. "92": [1.25003, 1.75, 0, 0, 1.27778],
  3280. "93": [1.25003, 1.75, 0, 0, 0.58334],
  3281. "123": [1.25003, 1.75, 0, 0, 0.80556],
  3282. "125": [1.25003, 1.75, 0, 0, 0.80556],
  3283. "160": [0, 0, 0, 0, 0.25],
  3284. "710": [0, 0.825, 0, 0, 1.8889],
  3285. "732": [0, 0.825, 0, 0, 1.8889],
  3286. "770": [0, 0.825, 0, 0, 1.8889],
  3287. "771": [0, 0.825, 0, 0, 1.8889],
  3288. "8730": [1.25003, 1.75, 0, 0, 1.0],
  3289. "8968": [1.25003, 1.75, 0, 0, 0.63889],
  3290. "8969": [1.25003, 1.75, 0, 0, 0.63889],
  3291. "8970": [1.25003, 1.75, 0, 0, 0.63889],
  3292. "8971": [1.25003, 1.75, 0, 0, 0.63889],
  3293. "9115": [0.64502, 1.155, 0, 0, 0.875],
  3294. "9116": [1e-05, 0.6, 0, 0, 0.875],
  3295. "9117": [0.64502, 1.155, 0, 0, 0.875],
  3296. "9118": [0.64502, 1.155, 0, 0, 0.875],
  3297. "9119": [1e-05, 0.6, 0, 0, 0.875],
  3298. "9120": [0.64502, 1.155, 0, 0, 0.875],
  3299. "9121": [0.64502, 1.155, 0, 0, 0.66667],
  3300. "9122": [-0.00099, 0.601, 0, 0, 0.66667],
  3301. "9123": [0.64502, 1.155, 0, 0, 0.66667],
  3302. "9124": [0.64502, 1.155, 0, 0, 0.66667],
  3303. "9125": [-0.00099, 0.601, 0, 0, 0.66667],
  3304. "9126": [0.64502, 1.155, 0, 0, 0.66667],
  3305. "9127": [1e-05, 0.9, 0, 0, 0.88889],
  3306. "9128": [0.65002, 1.15, 0, 0, 0.88889],
  3307. "9129": [0.90001, 0, 0, 0, 0.88889],
  3308. "9130": [0, 0.3, 0, 0, 0.88889],
  3309. "9131": [1e-05, 0.9, 0, 0, 0.88889],
  3310. "9132": [0.65002, 1.15, 0, 0, 0.88889],
  3311. "9133": [0.90001, 0, 0, 0, 0.88889],
  3312. "9143": [0.88502, 0.915, 0, 0, 1.05556],
  3313. "10216": [1.25003, 1.75, 0, 0, 0.80556],
  3314. "10217": [1.25003, 1.75, 0, 0, 0.80556],
  3315. "57344": [-0.00499, 0.605, 0, 0, 1.05556],
  3316. "57345": [-0.00499, 0.605, 0, 0, 1.05556],
  3317. "57680": [0, 0.12, 0, 0, 0.45],
  3318. "57681": [0, 0.12, 0, 0, 0.45],
  3319. "57682": [0, 0.12, 0, 0, 0.45],
  3320. "57683": [0, 0.12, 0, 0, 0.45]
  3321. },
  3322. "Typewriter-Regular": {
  3323. "32": [0, 0, 0, 0, 0.525],
  3324. "33": [0, 0.61111, 0, 0, 0.525],
  3325. "34": [0, 0.61111, 0, 0, 0.525],
  3326. "35": [0, 0.61111, 0, 0, 0.525],
  3327. "36": [0.08333, 0.69444, 0, 0, 0.525],
  3328. "37": [0.08333, 0.69444, 0, 0, 0.525],
  3329. "38": [0, 0.61111, 0, 0, 0.525],
  3330. "39": [0, 0.61111, 0, 0, 0.525],
  3331. "40": [0.08333, 0.69444, 0, 0, 0.525],
  3332. "41": [0.08333, 0.69444, 0, 0, 0.525],
  3333. "42": [0, 0.52083, 0, 0, 0.525],
  3334. "43": [-0.08056, 0.53055, 0, 0, 0.525],
  3335. "44": [0.13889, 0.125, 0, 0, 0.525],
  3336. "45": [-0.08056, 0.53055, 0, 0, 0.525],
  3337. "46": [0, 0.125, 0, 0, 0.525],
  3338. "47": [0.08333, 0.69444, 0, 0, 0.525],
  3339. "48": [0, 0.61111, 0, 0, 0.525],
  3340. "49": [0, 0.61111, 0, 0, 0.525],
  3341. "50": [0, 0.61111, 0, 0, 0.525],
  3342. "51": [0, 0.61111, 0, 0, 0.525],
  3343. "52": [0, 0.61111, 0, 0, 0.525],
  3344. "53": [0, 0.61111, 0, 0, 0.525],
  3345. "54": [0, 0.61111, 0, 0, 0.525],
  3346. "55": [0, 0.61111, 0, 0, 0.525],
  3347. "56": [0, 0.61111, 0, 0, 0.525],
  3348. "57": [0, 0.61111, 0, 0, 0.525],
  3349. "58": [0, 0.43056, 0, 0, 0.525],
  3350. "59": [0.13889, 0.43056, 0, 0, 0.525],
  3351. "60": [-0.05556, 0.55556, 0, 0, 0.525],
  3352. "61": [-0.19549, 0.41562, 0, 0, 0.525],
  3353. "62": [-0.05556, 0.55556, 0, 0, 0.525],
  3354. "63": [0, 0.61111, 0, 0, 0.525],
  3355. "64": [0, 0.61111, 0, 0, 0.525],
  3356. "65": [0, 0.61111, 0, 0, 0.525],
  3357. "66": [0, 0.61111, 0, 0, 0.525],
  3358. "67": [0, 0.61111, 0, 0, 0.525],
  3359. "68": [0, 0.61111, 0, 0, 0.525],
  3360. "69": [0, 0.61111, 0, 0, 0.525],
  3361. "70": [0, 0.61111, 0, 0, 0.525],
  3362. "71": [0, 0.61111, 0, 0, 0.525],
  3363. "72": [0, 0.61111, 0, 0, 0.525],
  3364. "73": [0, 0.61111, 0, 0, 0.525],
  3365. "74": [0, 0.61111, 0, 0, 0.525],
  3366. "75": [0, 0.61111, 0, 0, 0.525],
  3367. "76": [0, 0.61111, 0, 0, 0.525],
  3368. "77": [0, 0.61111, 0, 0, 0.525],
  3369. "78": [0, 0.61111, 0, 0, 0.525],
  3370. "79": [0, 0.61111, 0, 0, 0.525],
  3371. "80": [0, 0.61111, 0, 0, 0.525],
  3372. "81": [0.13889, 0.61111, 0, 0, 0.525],
  3373. "82": [0, 0.61111, 0, 0, 0.525],
  3374. "83": [0, 0.61111, 0, 0, 0.525],
  3375. "84": [0, 0.61111, 0, 0, 0.525],
  3376. "85": [0, 0.61111, 0, 0, 0.525],
  3377. "86": [0, 0.61111, 0, 0, 0.525],
  3378. "87": [0, 0.61111, 0, 0, 0.525],
  3379. "88": [0, 0.61111, 0, 0, 0.525],
  3380. "89": [0, 0.61111, 0, 0, 0.525],
  3381. "90": [0, 0.61111, 0, 0, 0.525],
  3382. "91": [0.08333, 0.69444, 0, 0, 0.525],
  3383. "92": [0.08333, 0.69444, 0, 0, 0.525],
  3384. "93": [0.08333, 0.69444, 0, 0, 0.525],
  3385. "94": [0, 0.61111, 0, 0, 0.525],
  3386. "95": [0.09514, 0, 0, 0, 0.525],
  3387. "96": [0, 0.61111, 0, 0, 0.525],
  3388. "97": [0, 0.43056, 0, 0, 0.525],
  3389. "98": [0, 0.61111, 0, 0, 0.525],
  3390. "99": [0, 0.43056, 0, 0, 0.525],
  3391. "100": [0, 0.61111, 0, 0, 0.525],
  3392. "101": [0, 0.43056, 0, 0, 0.525],
  3393. "102": [0, 0.61111, 0, 0, 0.525],
  3394. "103": [0.22222, 0.43056, 0, 0, 0.525],
  3395. "104": [0, 0.61111, 0, 0, 0.525],
  3396. "105": [0, 0.61111, 0, 0, 0.525],
  3397. "106": [0.22222, 0.61111, 0, 0, 0.525],
  3398. "107": [0, 0.61111, 0, 0, 0.525],
  3399. "108": [0, 0.61111, 0, 0, 0.525],
  3400. "109": [0, 0.43056, 0, 0, 0.525],
  3401. "110": [0, 0.43056, 0, 0, 0.525],
  3402. "111": [0, 0.43056, 0, 0, 0.525],
  3403. "112": [0.22222, 0.43056, 0, 0, 0.525],
  3404. "113": [0.22222, 0.43056, 0, 0, 0.525],
  3405. "114": [0, 0.43056, 0, 0, 0.525],
  3406. "115": [0, 0.43056, 0, 0, 0.525],
  3407. "116": [0, 0.55358, 0, 0, 0.525],
  3408. "117": [0, 0.43056, 0, 0, 0.525],
  3409. "118": [0, 0.43056, 0, 0, 0.525],
  3410. "119": [0, 0.43056, 0, 0, 0.525],
  3411. "120": [0, 0.43056, 0, 0, 0.525],
  3412. "121": [0.22222, 0.43056, 0, 0, 0.525],
  3413. "122": [0, 0.43056, 0, 0, 0.525],
  3414. "123": [0.08333, 0.69444, 0, 0, 0.525],
  3415. "124": [0.08333, 0.69444, 0, 0, 0.525],
  3416. "125": [0.08333, 0.69444, 0, 0, 0.525],
  3417. "126": [0, 0.61111, 0, 0, 0.525],
  3418. "127": [0, 0.61111, 0, 0, 0.525],
  3419. "160": [0, 0, 0, 0, 0.525],
  3420. "176": [0, 0.61111, 0, 0, 0.525],
  3421. "184": [0.19445, 0, 0, 0, 0.525],
  3422. "305": [0, 0.43056, 0, 0, 0.525],
  3423. "567": [0.22222, 0.43056, 0, 0, 0.525],
  3424. "711": [0, 0.56597, 0, 0, 0.525],
  3425. "713": [0, 0.56555, 0, 0, 0.525],
  3426. "714": [0, 0.61111, 0, 0, 0.525],
  3427. "715": [0, 0.61111, 0, 0, 0.525],
  3428. "728": [0, 0.61111, 0, 0, 0.525],
  3429. "730": [0, 0.61111, 0, 0, 0.525],
  3430. "770": [0, 0.61111, 0, 0, 0.525],
  3431. "771": [0, 0.61111, 0, 0, 0.525],
  3432. "776": [0, 0.61111, 0, 0, 0.525],
  3433. "915": [0, 0.61111, 0, 0, 0.525],
  3434. "916": [0, 0.61111, 0, 0, 0.525],
  3435. "920": [0, 0.61111, 0, 0, 0.525],
  3436. "923": [0, 0.61111, 0, 0, 0.525],
  3437. "926": [0, 0.61111, 0, 0, 0.525],
  3438. "928": [0, 0.61111, 0, 0, 0.525],
  3439. "931": [0, 0.61111, 0, 0, 0.525],
  3440. "933": [0, 0.61111, 0, 0, 0.525],
  3441. "934": [0, 0.61111, 0, 0, 0.525],
  3442. "936": [0, 0.61111, 0, 0, 0.525],
  3443. "937": [0, 0.61111, 0, 0, 0.525],
  3444. "8216": [0, 0.61111, 0, 0, 0.525],
  3445. "8217": [0, 0.61111, 0, 0, 0.525],
  3446. "8242": [0, 0.61111, 0, 0, 0.525],
  3447. "9251": [0.11111, 0.21944, 0, 0, 0.525]
  3448. }
  3449. });
  3450. ;// ./src/fontMetrics.ts
  3451. /**
  3452. * This file contains metrics regarding fonts and individual symbols. The sigma
  3453. * and xi variables, as well as the metricMap map contain data extracted from
  3454. * TeX, TeX font metrics, and the TTF files. These data are then exposed via the
  3455. * `metrics` variable and the getCharacterMetrics function.
  3456. */
  3457. // In TeX, there are actually three sets of dimensions, one for each of
  3458. // textstyle (size index 5 and higher: >=9pt), scriptstyle (size index 3 and 4:
  3459. // 7-8pt), and scriptscriptstyle (size index 1 and 2: 5-6pt). These are
  3460. // provided in the arrays below, in that order.
  3461. //
  3462. // The font metrics are stored in fonts cmsy10, cmsy7, and cmsy5 respectively.
  3463. // This was determined by running the following script:
  3464. //
  3465. // latex -interaction=nonstopmode \
  3466. // '\documentclass{article}\usepackage{amsmath}\begin{document}' \
  3467. // '$a$ \expandafter\show\the\textfont2' \
  3468. // '\expandafter\show\the\scriptfont2' \
  3469. // '\expandafter\show\the\scriptscriptfont2' \
  3470. // '\stop'
  3471. //
  3472. // The metrics themselves were retrieved using the following commands:
  3473. //
  3474. // tftopl cmsy10
  3475. // tftopl cmsy7
  3476. // tftopl cmsy5
  3477. //
  3478. // The output of each of these commands is quite lengthy. The only part we
  3479. // care about is the FONTDIMEN section. Each value is measured in EMs.
  3480. const sigmasAndXis = {
  3481. slant: [0.250, 0.250, 0.250],
  3482. // sigma1
  3483. space: [0.000, 0.000, 0.000],
  3484. // sigma2
  3485. stretch: [0.000, 0.000, 0.000],
  3486. // sigma3
  3487. shrink: [0.000, 0.000, 0.000],
  3488. // sigma4
  3489. xHeight: [0.431, 0.431, 0.431],
  3490. // sigma5
  3491. quad: [1.000, 1.171, 1.472],
  3492. // sigma6
  3493. extraSpace: [0.000, 0.000, 0.000],
  3494. // sigma7
  3495. num1: [0.677, 0.732, 0.925],
  3496. // sigma8
  3497. num2: [0.394, 0.384, 0.387],
  3498. // sigma9
  3499. num3: [0.444, 0.471, 0.504],
  3500. // sigma10
  3501. denom1: [0.686, 0.752, 1.025],
  3502. // sigma11
  3503. denom2: [0.345, 0.344, 0.532],
  3504. // sigma12
  3505. sup1: [0.413, 0.503, 0.504],
  3506. // sigma13
  3507. sup2: [0.363, 0.431, 0.404],
  3508. // sigma14
  3509. sup3: [0.289, 0.286, 0.294],
  3510. // sigma15
  3511. sub1: [0.150, 0.143, 0.200],
  3512. // sigma16
  3513. sub2: [0.247, 0.286, 0.400],
  3514. // sigma17
  3515. supDrop: [0.386, 0.353, 0.494],
  3516. // sigma18
  3517. subDrop: [0.050, 0.071, 0.100],
  3518. // sigma19
  3519. delim1: [2.390, 1.700, 1.980],
  3520. // sigma20
  3521. delim2: [1.010, 1.157, 1.420],
  3522. // sigma21
  3523. axisHeight: [0.250, 0.250, 0.250],
  3524. // sigma22
  3525. // These font metrics are extracted from TeX by using tftopl on cmex10.tfm;
  3526. // they correspond to the font parameters of the extension fonts (family 3).
  3527. // See the TeXbook, page 441. In AMSTeX, the extension fonts scale; to
  3528. // match cmex7, we'd use cmex7.tfm values for script and scriptscript
  3529. // values.
  3530. defaultRuleThickness: [0.04, 0.049, 0.049],
  3531. // xi8; cmex7: 0.049
  3532. bigOpSpacing1: [0.111, 0.111, 0.111],
  3533. // xi9
  3534. bigOpSpacing2: [0.166, 0.166, 0.166],
  3535. // xi10
  3536. bigOpSpacing3: [0.2, 0.2, 0.2],
  3537. // xi11
  3538. bigOpSpacing4: [0.6, 0.611, 0.611],
  3539. // xi12; cmex7: 0.611
  3540. bigOpSpacing5: [0.1, 0.143, 0.143],
  3541. // xi13; cmex7: 0.143
  3542. // The \sqrt rule width is taken from the height of the surd character.
  3543. // Since we use the same font at all sizes, this thickness doesn't scale.
  3544. sqrtRuleThickness: [0.04, 0.04, 0.04],
  3545. // This value determines how large a pt is, for metrics which are defined
  3546. // in terms of pts.
  3547. // This value is also used in katex.scss; if you change it make sure the
  3548. // values match.
  3549. ptPerEm: [10.0, 10.0, 10.0],
  3550. // The space between adjacent `|` columns in an array definition. From
  3551. // `\showthe\doublerulesep` in LaTeX. Equals 2.0 / ptPerEm.
  3552. doubleRuleSep: [0.2, 0.2, 0.2],
  3553. // The width of separator lines in {array} environments. From
  3554. // `\showthe\arrayrulewidth` in LaTeX. Equals 0.4 / ptPerEm.
  3555. arrayRuleWidth: [0.04, 0.04, 0.04],
  3556. // Two values from LaTeX source2e:
  3557. fboxsep: [0.3, 0.3, 0.3],
  3558. // 3 pt / ptPerEm
  3559. fboxrule: [0.04, 0.04, 0.04] // 0.4 pt / ptPerEm
  3560. };
  3561. // This map contains a mapping from font name and character code to character
  3562. // metrics, including height, depth, italic correction, and skew (kern from the
  3563. // character to the corresponding \skewchar)
  3564. // This map is generated via `make metrics`. It should not be changed manually.
  3565. // These are very rough approximations. We default to Times New Roman which
  3566. // should have Latin-1 and Cyrillic characters, but may not depending on the
  3567. // operating system. The metrics do not account for extra height from the
  3568. // accents. In the case of Cyrillic characters which have both ascenders and
  3569. // descenders we prefer approximations with ascenders, primarily to prevent
  3570. // the fraction bar or root line from intersecting the glyph.
  3571. // TODO(kevinb) allow union of multiple glyph metrics for better accuracy.
  3572. const extraCharacterMap = {
  3573. // Latin-1
  3574. 'Å': 'A',
  3575. 'Ð': 'D',
  3576. 'Þ': 'o',
  3577. 'å': 'a',
  3578. 'ð': 'd',
  3579. 'þ': 'o',
  3580. // Cyrillic
  3581. 'А': 'A',
  3582. 'Б': 'B',
  3583. 'В': 'B',
  3584. 'Г': 'F',
  3585. 'Д': 'A',
  3586. 'Е': 'E',
  3587. 'Ж': 'K',
  3588. 'З': '3',
  3589. 'И': 'N',
  3590. 'Й': 'N',
  3591. 'К': 'K',
  3592. 'Л': 'N',
  3593. 'М': 'M',
  3594. 'Н': 'H',
  3595. 'О': 'O',
  3596. 'П': 'N',
  3597. 'Р': 'P',
  3598. 'С': 'C',
  3599. 'Т': 'T',
  3600. 'У': 'y',
  3601. 'Ф': 'O',
  3602. 'Х': 'X',
  3603. 'Ц': 'U',
  3604. 'Ч': 'h',
  3605. 'Ш': 'W',
  3606. 'Щ': 'W',
  3607. 'Ъ': 'B',
  3608. 'Ы': 'X',
  3609. 'Ь': 'B',
  3610. 'Э': '3',
  3611. 'Ю': 'X',
  3612. 'Я': 'R',
  3613. 'а': 'a',
  3614. 'б': 'b',
  3615. 'в': 'a',
  3616. 'г': 'r',
  3617. 'д': 'y',
  3618. 'е': 'e',
  3619. 'ж': 'm',
  3620. 'з': 'e',
  3621. 'и': 'n',
  3622. 'й': 'n',
  3623. 'к': 'n',
  3624. 'л': 'n',
  3625. 'м': 'm',
  3626. 'н': 'n',
  3627. 'о': 'o',
  3628. 'п': 'n',
  3629. 'р': 'p',
  3630. 'с': 'c',
  3631. 'т': 'o',
  3632. 'у': 'y',
  3633. 'ф': 'b',
  3634. 'х': 'x',
  3635. 'ц': 'n',
  3636. 'ч': 'n',
  3637. 'ш': 'w',
  3638. 'щ': 'w',
  3639. 'ъ': 'a',
  3640. 'ы': 'm',
  3641. 'ь': 'a',
  3642. 'э': 'e',
  3643. 'ю': 'm',
  3644. 'я': 'r'
  3645. };
  3646. /**
  3647. * This function adds new font metrics to default metricMap
  3648. * It can also override existing metrics
  3649. */
  3650. function setFontMetrics(fontName, metrics) {
  3651. fontMetricsData[fontName] = metrics;
  3652. }
  3653. /**
  3654. * This function is a convenience function for looking up information in the
  3655. * metricMap table. It takes a character as a string, and a font.
  3656. *
  3657. * Note: the `width` property may be undefined if fontMetricsData.js wasn't
  3658. * built using `Make extended_metrics`.
  3659. */
  3660. function getCharacterMetrics(character, font, mode) {
  3661. if (!fontMetricsData[font]) {
  3662. throw new Error("Font metrics not found for font: " + font + ".");
  3663. }
  3664. let ch = character.charCodeAt(0);
  3665. let metrics = fontMetricsData[font][ch];
  3666. if (!metrics && character[0] in extraCharacterMap) {
  3667. ch = extraCharacterMap[character[0]].charCodeAt(0);
  3668. metrics = fontMetricsData[font][ch];
  3669. }
  3670. if (!metrics && mode === 'text') {
  3671. // We don't typically have font metrics for Asian scripts.
  3672. // But since we support them in text mode, we need to return
  3673. // some sort of metrics.
  3674. // So if the character is in a script we support but we
  3675. // don't have metrics for it, just use the metrics for
  3676. // the Latin capital letter M. This is close enough because
  3677. // we (currently) only care about the height of the glyph
  3678. // not its width.
  3679. if (supportedCodepoint(ch)) {
  3680. metrics = fontMetricsData[font][77]; // 77 is the charcode for 'M'
  3681. }
  3682. }
  3683. if (metrics) {
  3684. return {
  3685. depth: metrics[0],
  3686. height: metrics[1],
  3687. italic: metrics[2],
  3688. skew: metrics[3],
  3689. width: metrics[4]
  3690. };
  3691. }
  3692. }
  3693. const fontMetricsBySizeIndex = {};
  3694. /**
  3695. * Get the font metrics for a given size.
  3696. */
  3697. function getGlobalMetrics(size) {
  3698. let sizeIndex;
  3699. if (size >= 5) {
  3700. sizeIndex = 0;
  3701. } else if (size >= 3) {
  3702. sizeIndex = 1;
  3703. } else {
  3704. sizeIndex = 2;
  3705. }
  3706. if (!fontMetricsBySizeIndex[sizeIndex]) {
  3707. const metrics = fontMetricsBySizeIndex[sizeIndex] = {
  3708. cssEmPerMu: sigmasAndXis.quad[sizeIndex] / 18
  3709. };
  3710. for (const key in sigmasAndXis) {
  3711. if (sigmasAndXis.hasOwnProperty(key)) {
  3712. metrics[key] = sigmasAndXis[key][sizeIndex];
  3713. }
  3714. }
  3715. }
  3716. return fontMetricsBySizeIndex[sizeIndex];
  3717. }
  3718. ;// ./src/symbols.ts
  3719. /**
  3720. * This file holds a list of all no-argument functions and single-character
  3721. * symbols (like 'a' or ';').
  3722. *
  3723. * For each of the symbols, there are three properties they can have:
  3724. * - font (required): the font to be used for this symbol. Either "main" (the
  3725. normal font), or "ams" (the ams fonts).
  3726. * - group (required): the ParseNode group type the symbol should have (i.e.
  3727. "textord", "mathord", etc).
  3728. See https://github.com/KaTeX/KaTeX/wiki/Examining-TeX#group-types
  3729. * - replace: the character that this symbol or function should be
  3730. * replaced with (i.e. "\phi" has a replace value of "\u03d5", the phi
  3731. * character in the main font).
  3732. *
  3733. * The outermost map in the table indicates what mode the symbols should be
  3734. * accepted in (e.g. "math" or "text").
  3735. */
  3736. // Some of these have a "-token" suffix since these are also used as `ParseNode`
  3737. // types for raw text tokens, and we want to avoid conflicts with higher-level
  3738. // `ParseNode` types. These `ParseNode`s are constructed within `Parser` by
  3739. // looking up the `symbols` map.
  3740. const ATOMS = {
  3741. "bin": 1,
  3742. "close": 1,
  3743. "inner": 1,
  3744. "open": 1,
  3745. "punct": 1,
  3746. "rel": 1
  3747. };
  3748. const NON_ATOMS = {
  3749. "accent-token": 1,
  3750. "mathord": 1,
  3751. "op-token": 1,
  3752. "spacing": 1,
  3753. "textord": 1
  3754. };
  3755. const symbols = {
  3756. "math": {},
  3757. "text": {}
  3758. };
  3759. /* harmony default export */ var src_symbols = (symbols);
  3760. /** `acceptUnicodeChar = true` is only applicable if `replace` is set. */
  3761. function defineSymbol(mode, font, group, replace, name, acceptUnicodeChar) {
  3762. symbols[mode][name] = {
  3763. font,
  3764. group,
  3765. replace
  3766. };
  3767. if (acceptUnicodeChar && replace) {
  3768. symbols[mode][replace] = symbols[mode][name];
  3769. }
  3770. }
  3771. // Some abbreviations for commonly used strings.
  3772. // This helps minify the code, and also spotting typos using jshint.
  3773. // modes:
  3774. const math = "math";
  3775. const symbols_text = "text";
  3776. // fonts:
  3777. const main = "main";
  3778. const ams = "ams";
  3779. // groups:
  3780. const accent = "accent-token";
  3781. const bin = "bin";
  3782. const symbols_close = "close";
  3783. const inner = "inner";
  3784. const mathord = "mathord";
  3785. const op = "op-token";
  3786. const symbols_open = "open";
  3787. const punct = "punct";
  3788. const rel = "rel";
  3789. const spacing = "spacing";
  3790. const textord = "textord";
  3791. // Now comes the symbol table
  3792. // Relation Symbols
  3793. defineSymbol(math, main, rel, "\u2261", "\\equiv", true);
  3794. defineSymbol(math, main, rel, "\u227a", "\\prec", true);
  3795. defineSymbol(math, main, rel, "\u227b", "\\succ", true);
  3796. defineSymbol(math, main, rel, "\u223c", "\\sim", true);
  3797. defineSymbol(math, main, rel, "\u22a5", "\\perp");
  3798. defineSymbol(math, main, rel, "\u2aaf", "\\preceq", true);
  3799. defineSymbol(math, main, rel, "\u2ab0", "\\succeq", true);
  3800. defineSymbol(math, main, rel, "\u2243", "\\simeq", true);
  3801. defineSymbol(math, main, rel, "\u2223", "\\mid", true);
  3802. defineSymbol(math, main, rel, "\u226a", "\\ll", true);
  3803. defineSymbol(math, main, rel, "\u226b", "\\gg", true);
  3804. defineSymbol(math, main, rel, "\u224d", "\\asymp", true);
  3805. defineSymbol(math, main, rel, "\u2225", "\\parallel");
  3806. defineSymbol(math, main, rel, "\u22c8", "\\bowtie", true);
  3807. defineSymbol(math, main, rel, "\u2323", "\\smile", true);
  3808. defineSymbol(math, main, rel, "\u2291", "\\sqsubseteq", true);
  3809. defineSymbol(math, main, rel, "\u2292", "\\sqsupseteq", true);
  3810. defineSymbol(math, main, rel, "\u2250", "\\doteq", true);
  3811. defineSymbol(math, main, rel, "\u2322", "\\frown", true);
  3812. defineSymbol(math, main, rel, "\u220b", "\\ni", true);
  3813. defineSymbol(math, main, rel, "\u221d", "\\propto", true);
  3814. defineSymbol(math, main, rel, "\u22a2", "\\vdash", true);
  3815. defineSymbol(math, main, rel, "\u22a3", "\\dashv", true);
  3816. defineSymbol(math, main, rel, "\u220b", "\\owns");
  3817. // Punctuation
  3818. defineSymbol(math, main, punct, "\u002e", "\\ldotp");
  3819. defineSymbol(math, main, punct, "\u22c5", "\\cdotp");
  3820. // The KaTeX fonts do not contain U+00B7. Use the centered dot glyph at U+22C5
  3821. // in both modes, but keep math-mode punctuation spacing only in math mode.
  3822. defineSymbol(math, main, punct, "\u22c5", "\u00b7");
  3823. defineSymbol(symbols_text, main, textord, "\u22c5", "\u00b7");
  3824. // Misc Symbols
  3825. defineSymbol(math, main, textord, "\u0023", "\\#");
  3826. defineSymbol(symbols_text, main, textord, "\u0023", "\\#");
  3827. defineSymbol(math, main, textord, "\u0026", "\\&");
  3828. defineSymbol(symbols_text, main, textord, "\u0026", "\\&");
  3829. defineSymbol(math, main, textord, "\u2135", "\\aleph", true);
  3830. defineSymbol(math, main, textord, "\u2200", "\\forall", true);
  3831. defineSymbol(math, main, textord, "\u210f", "\\hbar", true);
  3832. defineSymbol(math, main, textord, "\u2203", "\\exists", true);
  3833. defineSymbol(math, main, textord, "\u2207", "\\nabla", true);
  3834. defineSymbol(math, main, textord, "\u266d", "\\flat", true);
  3835. defineSymbol(math, main, textord, "\u2113", "\\ell", true);
  3836. defineSymbol(math, main, textord, "\u266e", "\\natural", true);
  3837. defineSymbol(math, main, textord, "\u2663", "\\clubsuit", true);
  3838. defineSymbol(math, main, textord, "\u2118", "\\wp", true);
  3839. defineSymbol(math, main, textord, "\u266f", "\\sharp", true);
  3840. defineSymbol(math, main, textord, "\u2662", "\\diamondsuit", true);
  3841. defineSymbol(math, main, textord, "\u211c", "\\Re", true);
  3842. defineSymbol(math, main, textord, "\u2661", "\\heartsuit", true);
  3843. defineSymbol(math, main, textord, "\u2111", "\\Im", true);
  3844. defineSymbol(math, main, textord, "\u2660", "\\spadesuit", true);
  3845. defineSymbol(math, main, textord, "\u00a7", "\\S", true);
  3846. defineSymbol(symbols_text, main, textord, "\u00a7", "\\S");
  3847. defineSymbol(math, main, textord, "\u00b6", "\\P", true);
  3848. defineSymbol(symbols_text, main, textord, "\u00b6", "\\P");
  3849. // Math and Text
  3850. defineSymbol(math, main, textord, "\u2020", "\\dag");
  3851. defineSymbol(symbols_text, main, textord, "\u2020", "\\dag");
  3852. defineSymbol(symbols_text, main, textord, "\u2020", "\\textdagger");
  3853. defineSymbol(math, main, textord, "\u2021", "\\ddag");
  3854. defineSymbol(symbols_text, main, textord, "\u2021", "\\ddag");
  3855. defineSymbol(symbols_text, main, textord, "\u2021", "\\textdaggerdbl");
  3856. // Large Delimiters
  3857. defineSymbol(math, main, symbols_close, "\u23b1", "\\rmoustache", true);
  3858. defineSymbol(math, main, symbols_open, "\u23b0", "\\lmoustache", true);
  3859. defineSymbol(math, main, symbols_close, "\u27ef", "\\rgroup", true);
  3860. defineSymbol(math, main, symbols_open, "\u27ee", "\\lgroup", true);
  3861. // Binary Operators
  3862. defineSymbol(math, main, bin, "\u2213", "\\mp", true);
  3863. defineSymbol(math, main, bin, "\u2296", "\\ominus", true);
  3864. defineSymbol(math, main, bin, "\u228e", "\\uplus", true);
  3865. defineSymbol(math, main, bin, "\u2293", "\\sqcap", true);
  3866. defineSymbol(math, main, bin, "\u2217", "\\ast");
  3867. defineSymbol(math, main, bin, "\u2294", "\\sqcup", true);
  3868. defineSymbol(math, main, bin, "\u25ef", "\\bigcirc", true);
  3869. defineSymbol(math, main, bin, "\u2219", "\\bullet", true);
  3870. defineSymbol(math, main, bin, "\u2021", "\\ddagger");
  3871. defineSymbol(math, main, bin, "\u2240", "\\wr", true);
  3872. defineSymbol(math, main, bin, "\u2a3f", "\\amalg");
  3873. defineSymbol(math, main, bin, "\u0026", "\\And"); // from amsmath
  3874. // Arrow Symbols
  3875. defineSymbol(math, main, rel, "\u27f5", "\\longleftarrow", true);
  3876. defineSymbol(math, main, rel, "\u21d0", "\\Leftarrow", true);
  3877. defineSymbol(math, main, rel, "\u27f8", "\\Longleftarrow", true);
  3878. defineSymbol(math, main, rel, "\u27f6", "\\longrightarrow", true);
  3879. defineSymbol(math, main, rel, "\u21d2", "\\Rightarrow", true);
  3880. defineSymbol(math, main, rel, "\u27f9", "\\Longrightarrow", true);
  3881. defineSymbol(math, main, rel, "\u2194", "\\leftrightarrow", true);
  3882. defineSymbol(math, main, rel, "\u27f7", "\\longleftrightarrow", true);
  3883. defineSymbol(math, main, rel, "\u21d4", "\\Leftrightarrow", true);
  3884. defineSymbol(math, main, rel, "\u27fa", "\\Longleftrightarrow", true);
  3885. defineSymbol(math, main, rel, "\u21a6", "\\mapsto", true);
  3886. defineSymbol(math, main, rel, "\u27fc", "\\longmapsto", true);
  3887. defineSymbol(math, main, rel, "\u2197", "\\nearrow", true);
  3888. defineSymbol(math, main, rel, "\u21a9", "\\hookleftarrow", true);
  3889. defineSymbol(math, main, rel, "\u21aa", "\\hookrightarrow", true);
  3890. defineSymbol(math, main, rel, "\u2198", "\\searrow", true);
  3891. defineSymbol(math, main, rel, "\u21bc", "\\leftharpoonup", true);
  3892. defineSymbol(math, main, rel, "\u21c0", "\\rightharpoonup", true);
  3893. defineSymbol(math, main, rel, "\u2199", "\\swarrow", true);
  3894. defineSymbol(math, main, rel, "\u21bd", "\\leftharpoondown", true);
  3895. defineSymbol(math, main, rel, "\u21c1", "\\rightharpoondown", true);
  3896. defineSymbol(math, main, rel, "\u2196", "\\nwarrow", true);
  3897. defineSymbol(math, main, rel, "\u21cc", "\\rightleftharpoons", true);
  3898. // AMS Negated Binary Relations
  3899. defineSymbol(math, ams, rel, "\u226e", "\\nless", true);
  3900. // Symbol names preceded by "@" each have a corresponding macro.
  3901. defineSymbol(math, ams, rel, "\ue010", "\\@nleqslant");
  3902. defineSymbol(math, ams, rel, "\ue011", "\\@nleqq");
  3903. defineSymbol(math, ams, rel, "\u2a87", "\\lneq", true);
  3904. defineSymbol(math, ams, rel, "\u2268", "\\lneqq", true);
  3905. defineSymbol(math, ams, rel, "\ue00c", "\\@lvertneqq");
  3906. defineSymbol(math, ams, rel, "\u22e6", "\\lnsim", true);
  3907. defineSymbol(math, ams, rel, "\u2a89", "\\lnapprox", true);
  3908. defineSymbol(math, ams, rel, "\u2280", "\\nprec", true);
  3909. // unicode-math maps \u22e0 to \npreccurlyeq. We'll use the AMS synonym.
  3910. defineSymbol(math, ams, rel, "\u22e0", "\\npreceq", true);
  3911. defineSymbol(math, ams, rel, "\u22e8", "\\precnsim", true);
  3912. defineSymbol(math, ams, rel, "\u2ab9", "\\precnapprox", true);
  3913. defineSymbol(math, ams, rel, "\u2241", "\\nsim", true);
  3914. defineSymbol(math, ams, rel, "\ue006", "\\@nshortmid");
  3915. defineSymbol(math, ams, rel, "\u2224", "\\nmid", true);
  3916. defineSymbol(math, ams, rel, "\u22ac", "\\nvdash", true);
  3917. defineSymbol(math, ams, rel, "\u22ad", "\\nvDash", true);
  3918. defineSymbol(math, ams, rel, "\u22ea", "\\ntriangleleft");
  3919. defineSymbol(math, ams, rel, "\u22ec", "\\ntrianglelefteq", true);
  3920. defineSymbol(math, ams, rel, "\u228a", "\\subsetneq", true);
  3921. defineSymbol(math, ams, rel, "\ue01a", "\\@varsubsetneq");
  3922. defineSymbol(math, ams, rel, "\u2acb", "\\subsetneqq", true);
  3923. defineSymbol(math, ams, rel, "\ue017", "\\@varsubsetneqq");
  3924. defineSymbol(math, ams, rel, "\u226f", "\\ngtr", true);
  3925. defineSymbol(math, ams, rel, "\ue00f", "\\@ngeqslant");
  3926. defineSymbol(math, ams, rel, "\ue00e", "\\@ngeqq");
  3927. defineSymbol(math, ams, rel, "\u2a88", "\\gneq", true);
  3928. defineSymbol(math, ams, rel, "\u2269", "\\gneqq", true);
  3929. defineSymbol(math, ams, rel, "\ue00d", "\\@gvertneqq");
  3930. defineSymbol(math, ams, rel, "\u22e7", "\\gnsim", true);
  3931. defineSymbol(math, ams, rel, "\u2a8a", "\\gnapprox", true);
  3932. defineSymbol(math, ams, rel, "\u2281", "\\nsucc", true);
  3933. // unicode-math maps \u22e1 to \nsucccurlyeq. We'll use the AMS synonym.
  3934. defineSymbol(math, ams, rel, "\u22e1", "\\nsucceq", true);
  3935. defineSymbol(math, ams, rel, "\u22e9", "\\succnsim", true);
  3936. defineSymbol(math, ams, rel, "\u2aba", "\\succnapprox", true);
  3937. // unicode-math maps \u2246 to \simneqq. We'll use the AMS synonym.
  3938. defineSymbol(math, ams, rel, "\u2246", "\\ncong", true);
  3939. defineSymbol(math, ams, rel, "\ue007", "\\@nshortparallel");
  3940. defineSymbol(math, ams, rel, "\u2226", "\\nparallel", true);
  3941. defineSymbol(math, ams, rel, "\u22af", "\\nVDash", true);
  3942. defineSymbol(math, ams, rel, "\u22eb", "\\ntriangleright");
  3943. defineSymbol(math, ams, rel, "\u22ed", "\\ntrianglerighteq", true);
  3944. defineSymbol(math, ams, rel, "\ue018", "\\@nsupseteqq");
  3945. defineSymbol(math, ams, rel, "\u228b", "\\supsetneq", true);
  3946. defineSymbol(math, ams, rel, "\ue01b", "\\@varsupsetneq");
  3947. defineSymbol(math, ams, rel, "\u2acc", "\\supsetneqq", true);
  3948. defineSymbol(math, ams, rel, "\ue019", "\\@varsupsetneqq");
  3949. defineSymbol(math, ams, rel, "\u22ae", "\\nVdash", true);
  3950. defineSymbol(math, ams, rel, "\u2ab5", "\\precneqq", true);
  3951. defineSymbol(math, ams, rel, "\u2ab6", "\\succneqq", true);
  3952. defineSymbol(math, ams, rel, "\ue016", "\\@nsubseteqq");
  3953. defineSymbol(math, ams, bin, "\u22b4", "\\unlhd");
  3954. defineSymbol(math, ams, bin, "\u22b5", "\\unrhd");
  3955. // AMS Negated Arrows
  3956. defineSymbol(math, ams, rel, "\u219a", "\\nleftarrow", true);
  3957. defineSymbol(math, ams, rel, "\u219b", "\\nrightarrow", true);
  3958. defineSymbol(math, ams, rel, "\u21cd", "\\nLeftarrow", true);
  3959. defineSymbol(math, ams, rel, "\u21cf", "\\nRightarrow", true);
  3960. defineSymbol(math, ams, rel, "\u21ae", "\\nleftrightarrow", true);
  3961. defineSymbol(math, ams, rel, "\u21ce", "\\nLeftrightarrow", true);
  3962. // AMS Misc
  3963. defineSymbol(math, ams, rel, "\u25b3", "\\vartriangle");
  3964. defineSymbol(math, ams, textord, "\u210f", "\\hslash");
  3965. defineSymbol(math, ams, textord, "\u25bd", "\\triangledown");
  3966. defineSymbol(math, ams, textord, "\u25ca", "\\lozenge");
  3967. defineSymbol(math, ams, textord, "\u24c8", "\\circledS");
  3968. defineSymbol(math, ams, textord, "\u00ae", "\\circledR");
  3969. defineSymbol(symbols_text, ams, textord, "\u00ae", "\\circledR");
  3970. defineSymbol(math, ams, textord, "\u2221", "\\measuredangle", true);
  3971. defineSymbol(math, ams, textord, "\u2204", "\\nexists");
  3972. defineSymbol(math, ams, textord, "\u2127", "\\mho");
  3973. defineSymbol(math, ams, textord, "\u2132", "\\Finv", true);
  3974. defineSymbol(math, ams, textord, "\u2141", "\\Game", true);
  3975. defineSymbol(math, ams, textord, "\u2035", "\\backprime");
  3976. defineSymbol(math, ams, textord, "\u25b2", "\\blacktriangle");
  3977. defineSymbol(math, ams, textord, "\u25bc", "\\blacktriangledown");
  3978. defineSymbol(math, ams, textord, "\u25a0", "\\blacksquare");
  3979. defineSymbol(math, ams, textord, "\u29eb", "\\blacklozenge");
  3980. defineSymbol(math, ams, textord, "\u2605", "\\bigstar");
  3981. defineSymbol(math, ams, textord, "\u2222", "\\sphericalangle", true);
  3982. defineSymbol(math, ams, textord, "\u2201", "\\complement", true);
  3983. // unicode-math maps U+F0 to \matheth. We map to AMS function \eth
  3984. defineSymbol(math, ams, textord, "\u00f0", "\\eth", true);
  3985. defineSymbol(symbols_text, main, textord, "\u00f0", "\u00f0");
  3986. defineSymbol(math, ams, textord, "\u2571", "\\diagup");
  3987. defineSymbol(math, ams, textord, "\u2572", "\\diagdown");
  3988. defineSymbol(math, ams, textord, "\u25a1", "\\square");
  3989. defineSymbol(math, ams, textord, "\u25a1", "\\Box");
  3990. defineSymbol(math, ams, textord, "\u25ca", "\\Diamond");
  3991. // unicode-math maps U+A5 to \mathyen. We map to AMS function \yen
  3992. defineSymbol(math, ams, textord, "\u00a5", "\\yen", true);
  3993. defineSymbol(symbols_text, ams, textord, "\u00a5", "\\yen", true);
  3994. defineSymbol(math, ams, textord, "\u2713", "\\checkmark", true);
  3995. defineSymbol(symbols_text, ams, textord, "\u2713", "\\checkmark");
  3996. // AMS Hebrew
  3997. defineSymbol(math, ams, textord, "\u2136", "\\beth", true);
  3998. defineSymbol(math, ams, textord, "\u2138", "\\daleth", true);
  3999. defineSymbol(math, ams, textord, "\u2137", "\\gimel", true);
  4000. // AMS Greek
  4001. defineSymbol(math, ams, textord, "\u03dd", "\\digamma", true);
  4002. defineSymbol(math, ams, textord, "\u03f0", "\\varkappa");
  4003. // AMS Delimiters
  4004. defineSymbol(math, ams, symbols_open, "\u250c", "\\@ulcorner", true);
  4005. defineSymbol(math, ams, symbols_close, "\u2510", "\\@urcorner", true);
  4006. defineSymbol(math, ams, symbols_open, "\u2514", "\\@llcorner", true);
  4007. defineSymbol(math, ams, symbols_close, "\u2518", "\\@lrcorner", true);
  4008. // AMS Binary Relations
  4009. defineSymbol(math, ams, rel, "\u2266", "\\leqq", true);
  4010. defineSymbol(math, ams, rel, "\u2a7d", "\\leqslant", true);
  4011. defineSymbol(math, ams, rel, "\u2a95", "\\eqslantless", true);
  4012. defineSymbol(math, ams, rel, "\u2272", "\\lesssim", true);
  4013. defineSymbol(math, ams, rel, "\u2a85", "\\lessapprox", true);
  4014. defineSymbol(math, ams, rel, "\u224a", "\\approxeq", true);
  4015. defineSymbol(math, ams, bin, "\u22d6", "\\lessdot");
  4016. defineSymbol(math, ams, rel, "\u22d8", "\\lll", true);
  4017. defineSymbol(math, ams, rel, "\u2276", "\\lessgtr", true);
  4018. defineSymbol(math, ams, rel, "\u22da", "\\lesseqgtr", true);
  4019. defineSymbol(math, ams, rel, "\u2a8b", "\\lesseqqgtr", true);
  4020. defineSymbol(math, ams, rel, "\u2251", "\\doteqdot");
  4021. defineSymbol(math, ams, rel, "\u2253", "\\risingdotseq", true);
  4022. defineSymbol(math, ams, rel, "\u2252", "\\fallingdotseq", true);
  4023. defineSymbol(math, ams, rel, "\u223d", "\\backsim", true);
  4024. defineSymbol(math, ams, rel, "\u22cd", "\\backsimeq", true);
  4025. defineSymbol(math, ams, rel, "\u2ac5", "\\subseteqq", true);
  4026. defineSymbol(math, ams, rel, "\u22d0", "\\Subset", true);
  4027. defineSymbol(math, ams, rel, "\u228f", "\\sqsubset", true);
  4028. defineSymbol(math, ams, rel, "\u227c", "\\preccurlyeq", true);
  4029. defineSymbol(math, ams, rel, "\u22de", "\\curlyeqprec", true);
  4030. defineSymbol(math, ams, rel, "\u227e", "\\precsim", true);
  4031. defineSymbol(math, ams, rel, "\u2ab7", "\\precapprox", true);
  4032. defineSymbol(math, ams, rel, "\u22b2", "\\vartriangleleft");
  4033. defineSymbol(math, ams, rel, "\u22b4", "\\trianglelefteq");
  4034. defineSymbol(math, ams, rel, "\u22a8", "\\vDash", true);
  4035. defineSymbol(math, ams, rel, "\u22aa", "\\Vvdash", true);
  4036. defineSymbol(math, ams, rel, "\u2323", "\\smallsmile");
  4037. defineSymbol(math, ams, rel, "\u2322", "\\smallfrown");
  4038. defineSymbol(math, ams, rel, "\u224f", "\\bumpeq", true);
  4039. defineSymbol(math, ams, rel, "\u224e", "\\Bumpeq", true);
  4040. defineSymbol(math, ams, rel, "\u2267", "\\geqq", true);
  4041. defineSymbol(math, ams, rel, "\u2a7e", "\\geqslant", true);
  4042. defineSymbol(math, ams, rel, "\u2a96", "\\eqslantgtr", true);
  4043. defineSymbol(math, ams, rel, "\u2273", "\\gtrsim", true);
  4044. defineSymbol(math, ams, rel, "\u2a86", "\\gtrapprox", true);
  4045. defineSymbol(math, ams, bin, "\u22d7", "\\gtrdot");
  4046. defineSymbol(math, ams, rel, "\u22d9", "\\ggg", true);
  4047. defineSymbol(math, ams, rel, "\u2277", "\\gtrless", true);
  4048. defineSymbol(math, ams, rel, "\u22db", "\\gtreqless", true);
  4049. defineSymbol(math, ams, rel, "\u2a8c", "\\gtreqqless", true);
  4050. defineSymbol(math, ams, rel, "\u2256", "\\eqcirc", true);
  4051. defineSymbol(math, ams, rel, "\u2257", "\\circeq", true);
  4052. defineSymbol(math, ams, rel, "\u225c", "\\triangleq", true);
  4053. defineSymbol(math, ams, rel, "\u223c", "\\thicksim");
  4054. defineSymbol(math, ams, rel, "\u2248", "\\thickapprox");
  4055. defineSymbol(math, ams, rel, "\u2ac6", "\\supseteqq", true);
  4056. defineSymbol(math, ams, rel, "\u22d1", "\\Supset", true);
  4057. defineSymbol(math, ams, rel, "\u2290", "\\sqsupset", true);
  4058. defineSymbol(math, ams, rel, "\u227d", "\\succcurlyeq", true);
  4059. defineSymbol(math, ams, rel, "\u22df", "\\curlyeqsucc", true);
  4060. defineSymbol(math, ams, rel, "\u227f", "\\succsim", true);
  4061. defineSymbol(math, ams, rel, "\u2ab8", "\\succapprox", true);
  4062. defineSymbol(math, ams, rel, "\u22b3", "\\vartriangleright");
  4063. defineSymbol(math, ams, rel, "\u22b5", "\\trianglerighteq");
  4064. defineSymbol(math, ams, rel, "\u22a9", "\\Vdash", true);
  4065. defineSymbol(math, ams, rel, "\u2223", "\\shortmid");
  4066. defineSymbol(math, ams, rel, "\u2225", "\\shortparallel");
  4067. defineSymbol(math, ams, rel, "\u226c", "\\between", true);
  4068. defineSymbol(math, ams, rel, "\u22d4", "\\pitchfork", true);
  4069. defineSymbol(math, ams, rel, "\u221d", "\\varpropto");
  4070. defineSymbol(math, ams, rel, "\u25c0", "\\blacktriangleleft");
  4071. // unicode-math says that \therefore is a mathord atom.
  4072. // We kept the amssymb atom type, which is rel.
  4073. defineSymbol(math, ams, rel, "\u2234", "\\therefore", true);
  4074. defineSymbol(math, ams, rel, "\u220d", "\\backepsilon");
  4075. defineSymbol(math, ams, rel, "\u25b6", "\\blacktriangleright");
  4076. // unicode-math says that \because is a mathord atom.
  4077. // We kept the amssymb atom type, which is rel.
  4078. defineSymbol(math, ams, rel, "\u2235", "\\because", true);
  4079. defineSymbol(math, ams, rel, "\u22d8", "\\llless");
  4080. defineSymbol(math, ams, rel, "\u22d9", "\\gggtr");
  4081. defineSymbol(math, ams, bin, "\u22b2", "\\lhd");
  4082. defineSymbol(math, ams, bin, "\u22b3", "\\rhd");
  4083. defineSymbol(math, ams, rel, "\u2242", "\\eqsim", true);
  4084. defineSymbol(math, main, rel, "\u22c8", "\\Join");
  4085. defineSymbol(math, ams, rel, "\u2251", "\\Doteq", true);
  4086. // AMS Binary Operators
  4087. defineSymbol(math, ams, bin, "\u2214", "\\dotplus", true);
  4088. defineSymbol(math, ams, bin, "\u2216", "\\smallsetminus");
  4089. defineSymbol(math, ams, bin, "\u22d2", "\\Cap", true);
  4090. defineSymbol(math, ams, bin, "\u22d3", "\\Cup", true);
  4091. defineSymbol(math, ams, bin, "\u2a5e", "\\doublebarwedge", true);
  4092. defineSymbol(math, ams, bin, "\u229f", "\\boxminus", true);
  4093. defineSymbol(math, ams, bin, "\u229e", "\\boxplus", true);
  4094. defineSymbol(math, ams, bin, "\u22c7", "\\divideontimes", true);
  4095. defineSymbol(math, ams, bin, "\u22c9", "\\ltimes", true);
  4096. defineSymbol(math, ams, bin, "\u22ca", "\\rtimes", true);
  4097. defineSymbol(math, ams, bin, "\u22cb", "\\leftthreetimes", true);
  4098. defineSymbol(math, ams, bin, "\u22cc", "\\rightthreetimes", true);
  4099. defineSymbol(math, ams, bin, "\u22cf", "\\curlywedge", true);
  4100. defineSymbol(math, ams, bin, "\u22ce", "\\curlyvee", true);
  4101. defineSymbol(math, ams, bin, "\u229d", "\\circleddash", true);
  4102. defineSymbol(math, ams, bin, "\u229b", "\\circledast", true);
  4103. defineSymbol(math, ams, bin, "\u22c5", "\\centerdot");
  4104. defineSymbol(math, ams, bin, "\u22ba", "\\intercal", true);
  4105. defineSymbol(math, ams, bin, "\u22d2", "\\doublecap");
  4106. defineSymbol(math, ams, bin, "\u22d3", "\\doublecup");
  4107. defineSymbol(math, ams, bin, "\u22a0", "\\boxtimes", true);
  4108. // AMS Arrows
  4109. // Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
  4110. // We'll map it to AMS function \dashrightarrow. It produces the same atom.
  4111. defineSymbol(math, ams, rel, "\u21e2", "\\dashrightarrow", true);
  4112. // unicode-math maps \u21e0 to \leftdasharrow. We'll use the AMS synonym.
  4113. defineSymbol(math, ams, rel, "\u21e0", "\\dashleftarrow", true);
  4114. defineSymbol(math, ams, rel, "\u21c7", "\\leftleftarrows", true);
  4115. defineSymbol(math, ams, rel, "\u21c6", "\\leftrightarrows", true);
  4116. defineSymbol(math, ams, rel, "\u21da", "\\Lleftarrow", true);
  4117. defineSymbol(math, ams, rel, "\u219e", "\\twoheadleftarrow", true);
  4118. defineSymbol(math, ams, rel, "\u21a2", "\\leftarrowtail", true);
  4119. defineSymbol(math, ams, rel, "\u21ab", "\\looparrowleft", true);
  4120. defineSymbol(math, ams, rel, "\u21cb", "\\leftrightharpoons", true);
  4121. defineSymbol(math, ams, rel, "\u21b6", "\\curvearrowleft", true);
  4122. // unicode-math maps \u21ba to \acwopencirclearrow. We'll use the AMS synonym.
  4123. defineSymbol(math, ams, rel, "\u21ba", "\\circlearrowleft", true);
  4124. defineSymbol(math, ams, rel, "\u21b0", "\\Lsh", true);
  4125. defineSymbol(math, ams, rel, "\u21c8", "\\upuparrows", true);
  4126. defineSymbol(math, ams, rel, "\u21bf", "\\upharpoonleft", true);
  4127. defineSymbol(math, ams, rel, "\u21c3", "\\downharpoonleft", true);
  4128. defineSymbol(math, main, rel, "\u22b6", "\\origof", true); // not in font
  4129. defineSymbol(math, main, rel, "\u22b7", "\\imageof", true); // not in font
  4130. defineSymbol(math, ams, rel, "\u22b8", "\\multimap", true);
  4131. defineSymbol(math, ams, rel, "\u21ad", "\\leftrightsquigarrow", true);
  4132. defineSymbol(math, ams, rel, "\u21c9", "\\rightrightarrows", true);
  4133. defineSymbol(math, ams, rel, "\u21c4", "\\rightleftarrows", true);
  4134. defineSymbol(math, ams, rel, "\u21a0", "\\twoheadrightarrow", true);
  4135. defineSymbol(math, ams, rel, "\u21a3", "\\rightarrowtail", true);
  4136. defineSymbol(math, ams, rel, "\u21ac", "\\looparrowright", true);
  4137. defineSymbol(math, ams, rel, "\u21b7", "\\curvearrowright", true);
  4138. // unicode-math maps \u21bb to \cwopencirclearrow. We'll use the AMS synonym.
  4139. defineSymbol(math, ams, rel, "\u21bb", "\\circlearrowright", true);
  4140. defineSymbol(math, ams, rel, "\u21b1", "\\Rsh", true);
  4141. defineSymbol(math, ams, rel, "\u21ca", "\\downdownarrows", true);
  4142. defineSymbol(math, ams, rel, "\u21be", "\\upharpoonright", true);
  4143. defineSymbol(math, ams, rel, "\u21c2", "\\downharpoonright", true);
  4144. defineSymbol(math, ams, rel, "\u21dd", "\\rightsquigarrow", true);
  4145. defineSymbol(math, ams, rel, "\u21dd", "\\leadsto");
  4146. defineSymbol(math, ams, rel, "\u21db", "\\Rrightarrow", true);
  4147. defineSymbol(math, ams, rel, "\u21be", "\\restriction");
  4148. defineSymbol(math, main, textord, "\u2018", "`");
  4149. defineSymbol(math, main, textord, "$", "\\$");
  4150. defineSymbol(symbols_text, main, textord, "$", "\\$");
  4151. defineSymbol(symbols_text, main, textord, "$", "\\textdollar");
  4152. defineSymbol(math, main, textord, "%", "\\%");
  4153. defineSymbol(symbols_text, main, textord, "%", "\\%");
  4154. defineSymbol(math, main, textord, "_", "\\_");
  4155. defineSymbol(symbols_text, main, textord, "_", "\\_");
  4156. defineSymbol(symbols_text, main, textord, "_", "\\textunderscore");
  4157. defineSymbol(math, main, textord, "\u2220", "\\angle", true);
  4158. defineSymbol(math, main, textord, "\u221e", "\\infty", true);
  4159. defineSymbol(math, main, textord, "\u2032", "\\prime");
  4160. defineSymbol(math, main, textord, "\u25b3", "\\triangle");
  4161. defineSymbol(math, main, textord, "\u0393", "\\Gamma", true);
  4162. defineSymbol(math, main, textord, "\u0394", "\\Delta", true);
  4163. defineSymbol(math, main, textord, "\u0398", "\\Theta", true);
  4164. defineSymbol(math, main, textord, "\u039b", "\\Lambda", true);
  4165. defineSymbol(math, main, textord, "\u039e", "\\Xi", true);
  4166. defineSymbol(math, main, textord, "\u03a0", "\\Pi", true);
  4167. defineSymbol(math, main, textord, "\u03a3", "\\Sigma", true);
  4168. defineSymbol(math, main, textord, "\u03a5", "\\Upsilon", true);
  4169. defineSymbol(math, main, textord, "\u03a6", "\\Phi", true);
  4170. defineSymbol(math, main, textord, "\u03a8", "\\Psi", true);
  4171. defineSymbol(math, main, textord, "\u03a9", "\\Omega", true);
  4172. defineSymbol(math, main, textord, "A", "\u0391");
  4173. defineSymbol(math, main, textord, "B", "\u0392");
  4174. defineSymbol(math, main, textord, "E", "\u0395");
  4175. defineSymbol(math, main, textord, "Z", "\u0396");
  4176. defineSymbol(math, main, textord, "H", "\u0397");
  4177. defineSymbol(math, main, textord, "I", "\u0399");
  4178. defineSymbol(math, main, textord, "K", "\u039A");
  4179. defineSymbol(math, main, textord, "M", "\u039C");
  4180. defineSymbol(math, main, textord, "N", "\u039D");
  4181. defineSymbol(math, main, textord, "O", "\u039F");
  4182. defineSymbol(math, main, textord, "P", "\u03A1");
  4183. defineSymbol(math, main, textord, "T", "\u03A4");
  4184. defineSymbol(math, main, textord, "X", "\u03A7");
  4185. defineSymbol(math, main, textord, "\u00ac", "\\neg", true);
  4186. defineSymbol(math, main, textord, "\u00ac", "\\lnot");
  4187. defineSymbol(math, main, textord, "\u22a4", "\\top");
  4188. defineSymbol(math, main, textord, "\u22a5", "\\bot");
  4189. defineSymbol(math, main, textord, "\u2205", "\\emptyset");
  4190. defineSymbol(math, ams, textord, "\u2205", "\\varnothing");
  4191. defineSymbol(math, main, mathord, "\u03b1", "\\alpha", true);
  4192. defineSymbol(math, main, mathord, "\u03b2", "\\beta", true);
  4193. defineSymbol(math, main, mathord, "\u03b3", "\\gamma", true);
  4194. defineSymbol(math, main, mathord, "\u03b4", "\\delta", true);
  4195. defineSymbol(math, main, mathord, "\u03f5", "\\epsilon", true);
  4196. defineSymbol(math, main, mathord, "\u03b6", "\\zeta", true);
  4197. defineSymbol(math, main, mathord, "\u03b7", "\\eta", true);
  4198. defineSymbol(math, main, mathord, "\u03b8", "\\theta", true);
  4199. defineSymbol(math, main, mathord, "\u03b9", "\\iota", true);
  4200. defineSymbol(math, main, mathord, "\u03ba", "\\kappa", true);
  4201. defineSymbol(math, main, mathord, "\u03bb", "\\lambda", true);
  4202. defineSymbol(math, main, mathord, "\u03bc", "\\mu", true);
  4203. defineSymbol(math, main, mathord, "\u03bd", "\\nu", true);
  4204. defineSymbol(math, main, mathord, "\u03be", "\\xi", true);
  4205. defineSymbol(math, main, mathord, "\u03bf", "\\omicron", true);
  4206. defineSymbol(math, main, mathord, "\u03c0", "\\pi", true);
  4207. defineSymbol(math, main, mathord, "\u03c1", "\\rho", true);
  4208. defineSymbol(math, main, mathord, "\u03c3", "\\sigma", true);
  4209. defineSymbol(math, main, mathord, "\u03c4", "\\tau", true);
  4210. defineSymbol(math, main, mathord, "\u03c5", "\\upsilon", true);
  4211. defineSymbol(math, main, mathord, "\u03d5", "\\phi", true);
  4212. defineSymbol(math, main, mathord, "\u03c7", "\\chi", true);
  4213. defineSymbol(math, main, mathord, "\u03c8", "\\psi", true);
  4214. defineSymbol(math, main, mathord, "\u03c9", "\\omega", true);
  4215. defineSymbol(math, main, mathord, "\u03b5", "\\varepsilon", true);
  4216. defineSymbol(math, main, mathord, "\u03d1", "\\vartheta", true);
  4217. defineSymbol(math, main, mathord, "\u03d6", "\\varpi", true);
  4218. defineSymbol(math, main, mathord, "\u03f1", "\\varrho", true);
  4219. defineSymbol(math, main, mathord, "\u03c2", "\\varsigma", true);
  4220. defineSymbol(math, main, mathord, "\u03c6", "\\varphi", true);
  4221. defineSymbol(math, main, bin, "\u2217", "*", true);
  4222. defineSymbol(math, main, bin, "+", "+");
  4223. defineSymbol(math, main, bin, "\u2212", "-", true);
  4224. defineSymbol(math, main, bin, "\u22c5", "\\cdot", true);
  4225. defineSymbol(math, main, bin, "\u2218", "\\circ", true);
  4226. defineSymbol(math, main, bin, "\u00f7", "\\div", true);
  4227. defineSymbol(math, main, bin, "\u00b1", "\\pm", true);
  4228. defineSymbol(math, main, bin, "\u00d7", "\\times", true);
  4229. defineSymbol(math, main, bin, "\u2229", "\\cap", true);
  4230. defineSymbol(math, main, bin, "\u222a", "\\cup", true);
  4231. defineSymbol(math, main, bin, "\u2216", "\\setminus", true);
  4232. defineSymbol(math, main, bin, "\u2227", "\\land");
  4233. defineSymbol(math, main, bin, "\u2228", "\\lor");
  4234. defineSymbol(math, main, bin, "\u2227", "\\wedge", true);
  4235. defineSymbol(math, main, bin, "\u2228", "\\vee", true);
  4236. defineSymbol(math, main, textord, "\u221a", "\\surd");
  4237. defineSymbol(math, main, symbols_open, "\u27e8", "\\langle", true);
  4238. defineSymbol(math, main, symbols_open, "\u2223", "\\lvert");
  4239. defineSymbol(math, main, symbols_open, "\u2225", "\\lVert");
  4240. defineSymbol(math, main, symbols_close, "?", "?");
  4241. defineSymbol(math, main, symbols_close, "!", "!");
  4242. defineSymbol(math, main, symbols_close, "\u27e9", "\\rangle", true);
  4243. defineSymbol(math, main, symbols_close, "\u2223", "\\rvert");
  4244. defineSymbol(math, main, symbols_close, "\u2225", "\\rVert");
  4245. defineSymbol(math, main, rel, "=", "=");
  4246. defineSymbol(math, main, rel, ":", ":");
  4247. defineSymbol(math, main, rel, "\u2248", "\\approx", true);
  4248. defineSymbol(math, main, rel, "\u2245", "\\cong", true);
  4249. defineSymbol(math, main, rel, "\u2265", "\\ge");
  4250. defineSymbol(math, main, rel, "\u2265", "\\geq", true);
  4251. defineSymbol(math, main, rel, "\u2190", "\\gets");
  4252. defineSymbol(math, main, rel, ">", "\\gt", true);
  4253. defineSymbol(math, main, rel, "\u2208", "\\in", true);
  4254. defineSymbol(math, main, rel, "\ue020", "\\@not");
  4255. defineSymbol(math, main, rel, "\u2282", "\\subset", true);
  4256. defineSymbol(math, main, rel, "\u2283", "\\supset", true);
  4257. defineSymbol(math, main, rel, "\u2286", "\\subseteq", true);
  4258. defineSymbol(math, main, rel, "\u2287", "\\supseteq", true);
  4259. defineSymbol(math, ams, rel, "\u2288", "\\nsubseteq", true);
  4260. defineSymbol(math, ams, rel, "\u2289", "\\nsupseteq", true);
  4261. defineSymbol(math, main, rel, "\u22a8", "\\models");
  4262. defineSymbol(math, main, rel, "\u2190", "\\leftarrow", true);
  4263. defineSymbol(math, main, rel, "\u2264", "\\le");
  4264. defineSymbol(math, main, rel, "\u2264", "\\leq", true);
  4265. defineSymbol(math, main, rel, "<", "\\lt", true);
  4266. defineSymbol(math, main, rel, "\u2192", "\\rightarrow", true);
  4267. defineSymbol(math, main, rel, "\u2192", "\\to");
  4268. defineSymbol(math, ams, rel, "\u2271", "\\ngeq", true);
  4269. defineSymbol(math, ams, rel, "\u2270", "\\nleq", true);
  4270. defineSymbol(math, main, spacing, "\u00a0", "\\ ");
  4271. defineSymbol(math, main, spacing, "\u00a0", "\\space");
  4272. // Ref: LaTeX Source 2e: \DeclareRobustCommand{\nobreakspace}{%
  4273. defineSymbol(math, main, spacing, "\u00a0", "\\nobreakspace");
  4274. defineSymbol(symbols_text, main, spacing, "\u00a0", "\\ ");
  4275. defineSymbol(symbols_text, main, spacing, "\u00a0", " ");
  4276. defineSymbol(symbols_text, main, spacing, "\u00a0", "\\space");
  4277. defineSymbol(symbols_text, main, spacing, "\u00a0", "\\nobreakspace");
  4278. defineSymbol(math, main, spacing, null, "\\nobreak");
  4279. defineSymbol(math, main, spacing, null, "\\allowbreak");
  4280. defineSymbol(math, main, punct, ",", ",");
  4281. defineSymbol(math, main, punct, ";", ";");
  4282. defineSymbol(math, ams, bin, "\u22bc", "\\barwedge", true);
  4283. defineSymbol(math, ams, bin, "\u22bb", "\\veebar", true);
  4284. defineSymbol(math, main, bin, "\u2299", "\\odot", true);
  4285. defineSymbol(math, main, bin, "\u2295", "\\oplus", true);
  4286. defineSymbol(math, main, bin, "\u2297", "\\otimes", true);
  4287. defineSymbol(math, main, textord, "\u2202", "\\partial", true);
  4288. defineSymbol(math, main, bin, "\u2298", "\\oslash", true);
  4289. defineSymbol(math, ams, bin, "\u229a", "\\circledcirc", true);
  4290. defineSymbol(math, ams, bin, "\u22a1", "\\boxdot", true);
  4291. defineSymbol(math, main, bin, "\u25b3", "\\bigtriangleup");
  4292. defineSymbol(math, main, bin, "\u25bd", "\\bigtriangledown");
  4293. defineSymbol(math, main, bin, "\u2020", "\\dagger");
  4294. defineSymbol(math, main, bin, "\u22c4", "\\diamond");
  4295. defineSymbol(math, main, bin, "\u22c6", "\\star");
  4296. defineSymbol(math, main, bin, "\u25c3", "\\triangleleft");
  4297. defineSymbol(math, main, bin, "\u25b9", "\\triangleright");
  4298. defineSymbol(math, main, symbols_open, "{", "\\{");
  4299. defineSymbol(symbols_text, main, textord, "{", "\\{");
  4300. defineSymbol(symbols_text, main, textord, "{", "\\textbraceleft");
  4301. defineSymbol(math, main, symbols_close, "}", "\\}");
  4302. defineSymbol(symbols_text, main, textord, "}", "\\}");
  4303. defineSymbol(symbols_text, main, textord, "}", "\\textbraceright");
  4304. defineSymbol(math, main, symbols_open, "{", "\\lbrace");
  4305. defineSymbol(math, main, symbols_close, "}", "\\rbrace");
  4306. defineSymbol(math, main, symbols_open, "[", "\\lbrack", true);
  4307. defineSymbol(symbols_text, main, textord, "[", "\\lbrack", true);
  4308. defineSymbol(math, main, symbols_close, "]", "\\rbrack", true);
  4309. defineSymbol(symbols_text, main, textord, "]", "\\rbrack", true);
  4310. defineSymbol(math, main, symbols_open, "(", "\\lparen", true);
  4311. defineSymbol(math, main, symbols_close, ")", "\\rparen", true);
  4312. defineSymbol(symbols_text, main, textord, "<", "\\textless", true); // in T1 fontenc
  4313. defineSymbol(symbols_text, main, textord, ">", "\\textgreater", true); // in T1 fontenc
  4314. defineSymbol(math, main, symbols_open, "\u230a", "\\lfloor", true);
  4315. defineSymbol(math, main, symbols_close, "\u230b", "\\rfloor", true);
  4316. defineSymbol(math, main, symbols_open, "\u2308", "\\lceil", true);
  4317. defineSymbol(math, main, symbols_close, "\u2309", "\\rceil", true);
  4318. defineSymbol(math, main, textord, "\\", "\\backslash");
  4319. defineSymbol(math, main, textord, "\u2223", "|");
  4320. defineSymbol(math, main, textord, "\u2223", "\\vert");
  4321. defineSymbol(symbols_text, main, textord, "|", "\\textbar", true); // in T1 fontenc
  4322. defineSymbol(math, main, textord, "\u2225", "\\|");
  4323. defineSymbol(math, main, textord, "\u2225", "\\Vert");
  4324. defineSymbol(symbols_text, main, textord, "\u2225", "\\textbardbl");
  4325. defineSymbol(symbols_text, main, textord, "~", "\\textasciitilde");
  4326. defineSymbol(symbols_text, main, textord, "\\", "\\textbackslash");
  4327. defineSymbol(symbols_text, main, textord, "^", "\\textasciicircum");
  4328. defineSymbol(math, main, rel, "\u2191", "\\uparrow", true);
  4329. defineSymbol(math, main, rel, "\u21d1", "\\Uparrow", true);
  4330. defineSymbol(math, main, rel, "\u2193", "\\downarrow", true);
  4331. defineSymbol(math, main, rel, "\u21d3", "\\Downarrow", true);
  4332. defineSymbol(math, main, rel, "\u2195", "\\updownarrow", true);
  4333. defineSymbol(math, main, rel, "\u21d5", "\\Updownarrow", true);
  4334. defineSymbol(math, main, op, "\u2210", "\\coprod");
  4335. defineSymbol(math, main, op, "\u22c1", "\\bigvee");
  4336. defineSymbol(math, main, op, "\u22c0", "\\bigwedge");
  4337. defineSymbol(math, main, op, "\u2a04", "\\biguplus");
  4338. defineSymbol(math, main, op, "\u22c2", "\\bigcap");
  4339. defineSymbol(math, main, op, "\u22c3", "\\bigcup");
  4340. defineSymbol(math, main, op, "\u222b", "\\int");
  4341. defineSymbol(math, main, op, "\u222b", "\\intop");
  4342. defineSymbol(math, main, op, "\u222c", "\\iint");
  4343. defineSymbol(math, main, op, "\u222d", "\\iiint");
  4344. defineSymbol(math, main, op, "\u220f", "\\prod");
  4345. defineSymbol(math, main, op, "\u2211", "\\sum");
  4346. defineSymbol(math, main, op, "\u2a02", "\\bigotimes");
  4347. defineSymbol(math, main, op, "\u2a01", "\\bigoplus");
  4348. defineSymbol(math, main, op, "\u2a00", "\\bigodot");
  4349. defineSymbol(math, main, op, "\u222e", "\\oint");
  4350. defineSymbol(math, main, op, "\u222f", "\\oiint");
  4351. defineSymbol(math, main, op, "\u2230", "\\oiiint");
  4352. defineSymbol(math, main, op, "\u2a06", "\\bigsqcup");
  4353. defineSymbol(math, main, op, "\u222b", "\\smallint");
  4354. defineSymbol(symbols_text, main, inner, "\u2026", "\\textellipsis");
  4355. defineSymbol(math, main, inner, "\u2026", "\\mathellipsis");
  4356. defineSymbol(symbols_text, main, inner, "\u2026", "\\ldots", true);
  4357. defineSymbol(math, main, inner, "\u2026", "\\ldots", true);
  4358. defineSymbol(math, main, inner, "\u22ef", "\\@cdots", true);
  4359. defineSymbol(math, main, inner, "\u22f1", "\\ddots", true);
  4360. // \vdots is a macro that uses one of these two symbols (with made-up names):
  4361. defineSymbol(math, main, textord, "\u22ee", "\\varvdots");
  4362. defineSymbol(symbols_text, main, textord, "\u22ee", "\\varvdots");
  4363. defineSymbol(math, main, accent, "\u02ca", "\\acute");
  4364. defineSymbol(math, main, accent, "\u02cb", "\\grave");
  4365. defineSymbol(math, main, accent, "\u00a8", "\\ddot");
  4366. defineSymbol(math, main, accent, "\u007e", "\\tilde");
  4367. defineSymbol(math, main, accent, "\u02c9", "\\bar");
  4368. defineSymbol(math, main, accent, "\u02d8", "\\breve");
  4369. defineSymbol(math, main, accent, "\u02c7", "\\check");
  4370. defineSymbol(math, main, accent, "\u005e", "\\hat");
  4371. defineSymbol(math, main, accent, "\u20d7", "\\vec");
  4372. defineSymbol(math, main, accent, "\u02d9", "\\dot");
  4373. defineSymbol(math, main, accent, "\u02da", "\\mathring");
  4374. // \imath and \jmath should be invariant to \mathrm, \mathbf, etc., so use PUA
  4375. defineSymbol(math, main, mathord, "\ue131", "\\@imath");
  4376. defineSymbol(math, main, mathord, "\ue237", "\\@jmath");
  4377. defineSymbol(math, main, textord, "\u0131", "\u0131");
  4378. defineSymbol(math, main, textord, "\u0237", "\u0237");
  4379. defineSymbol(symbols_text, main, textord, "\u0131", "\\i", true);
  4380. defineSymbol(symbols_text, main, textord, "\u0237", "\\j", true);
  4381. defineSymbol(symbols_text, main, textord, "\u00df", "\\ss", true);
  4382. defineSymbol(symbols_text, main, textord, "\u00e6", "\\ae", true);
  4383. defineSymbol(symbols_text, main, textord, "\u0153", "\\oe", true);
  4384. defineSymbol(symbols_text, main, textord, "\u00f8", "\\o", true);
  4385. defineSymbol(symbols_text, main, textord, "\u00c6", "\\AE", true);
  4386. defineSymbol(symbols_text, main, textord, "\u0152", "\\OE", true);
  4387. defineSymbol(symbols_text, main, textord, "\u00d8", "\\O", true);
  4388. defineSymbol(symbols_text, main, accent, "\u02ca", "\\'"); // acute
  4389. defineSymbol(symbols_text, main, accent, "\u02cb", "\\`"); // grave
  4390. defineSymbol(symbols_text, main, accent, "\u02c6", "\\^"); // circumflex
  4391. defineSymbol(symbols_text, main, accent, "\u02dc", "\\~"); // tilde
  4392. defineSymbol(symbols_text, main, accent, "\u02c9", "\\="); // macron
  4393. defineSymbol(symbols_text, main, accent, "\u02d8", "\\u"); // breve
  4394. defineSymbol(symbols_text, main, accent, "\u02d9", "\\."); // dot above
  4395. defineSymbol(symbols_text, main, accent, "\u00b8", "\\c"); // cedilla
  4396. defineSymbol(symbols_text, main, accent, "\u02da", "\\r"); // ring above
  4397. defineSymbol(symbols_text, main, accent, "\u02c7", "\\v"); // caron
  4398. defineSymbol(symbols_text, main, accent, "\u00a8", '\\"'); // diaeresis
  4399. defineSymbol(symbols_text, main, accent, "\u02dd", "\\H"); // double acute
  4400. defineSymbol(symbols_text, main, accent, "\u25ef", "\\textcircled"); // \bigcirc glyph
  4401. // These ligatures are detected and created in Parser.js's `formLigatures`.
  4402. const ligatures = {
  4403. "--": true,
  4404. "---": true,
  4405. "``": true,
  4406. "''": true
  4407. };
  4408. defineSymbol(symbols_text, main, textord, "\u2013", "--", true);
  4409. defineSymbol(symbols_text, main, textord, "\u2013", "\\textendash");
  4410. defineSymbol(symbols_text, main, textord, "\u2014", "---", true);
  4411. defineSymbol(symbols_text, main, textord, "\u2014", "\\textemdash");
  4412. defineSymbol(symbols_text, main, textord, "\u2018", "`", true);
  4413. defineSymbol(symbols_text, main, textord, "\u2018", "\\textquoteleft");
  4414. defineSymbol(symbols_text, main, textord, "\u2019", "'", true);
  4415. defineSymbol(symbols_text, main, textord, "\u2019", "\\textquoteright");
  4416. defineSymbol(symbols_text, main, textord, "\u201c", "``", true);
  4417. defineSymbol(symbols_text, main, textord, "\u201c", "\\textquotedblleft");
  4418. defineSymbol(symbols_text, main, textord, "\u201d", "''", true);
  4419. defineSymbol(symbols_text, main, textord, "\u201d", "\\textquotedblright");
  4420. // \degree from gensymb package
  4421. defineSymbol(math, main, textord, "\u00b0", "\\degree", true);
  4422. defineSymbol(symbols_text, main, textord, "\u00b0", "\\degree");
  4423. // \textdegree from inputenc package
  4424. defineSymbol(symbols_text, main, textord, "\u00b0", "\\textdegree", true);
  4425. // TODO: In LaTeX, \pounds can generate a different character in text and math
  4426. // mode, but among our fonts, only Main-Regular defines this character "163".
  4427. defineSymbol(math, main, textord, "\u00a3", "\\pounds");
  4428. defineSymbol(math, main, textord, "\u00a3", "\\mathsterling", true);
  4429. defineSymbol(symbols_text, main, textord, "\u00a3", "\\pounds");
  4430. defineSymbol(symbols_text, main, textord, "\u00a3", "\\textsterling", true);
  4431. defineSymbol(math, ams, textord, "\u2720", "\\maltese");
  4432. defineSymbol(symbols_text, ams, textord, "\u2720", "\\maltese");
  4433. // There are lots of symbols which are the same, so we add them in afterwards.
  4434. // All of these are textords in math mode
  4435. const mathTextSymbols = "0123456789/@.\"";
  4436. for (let i = 0; i < mathTextSymbols.length; i++) {
  4437. const ch = mathTextSymbols.charAt(i);
  4438. defineSymbol(math, main, textord, ch, ch);
  4439. }
  4440. // All of these are textords in text mode
  4441. const textSymbols = "0123456789!@*()-=+\";:?/.,";
  4442. for (let i = 0; i < textSymbols.length; i++) {
  4443. const ch = textSymbols.charAt(i);
  4444. defineSymbol(symbols_text, main, textord, ch, ch);
  4445. }
  4446. // All of these are textords in text mode, and mathords in math mode
  4447. const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  4448. for (let i = 0; i < letters.length; i++) {
  4449. const ch = letters.charAt(i);
  4450. defineSymbol(math, main, mathord, ch, ch);
  4451. defineSymbol(symbols_text, main, textord, ch, ch);
  4452. }
  4453. // Blackboard bold and script letters in Unicode range
  4454. defineSymbol(math, ams, textord, "C", "\u2102"); // blackboard bold
  4455. defineSymbol(symbols_text, ams, textord, "C", "\u2102");
  4456. defineSymbol(math, ams, textord, "H", "\u210D");
  4457. defineSymbol(symbols_text, ams, textord, "H", "\u210D");
  4458. defineSymbol(math, ams, textord, "N", "\u2115");
  4459. defineSymbol(symbols_text, ams, textord, "N", "\u2115");
  4460. defineSymbol(math, ams, textord, "P", "\u2119");
  4461. defineSymbol(symbols_text, ams, textord, "P", "\u2119");
  4462. defineSymbol(math, ams, textord, "Q", "\u211A");
  4463. defineSymbol(symbols_text, ams, textord, "Q", "\u211A");
  4464. defineSymbol(math, ams, textord, "R", "\u211D");
  4465. defineSymbol(symbols_text, ams, textord, "R", "\u211D");
  4466. defineSymbol(math, ams, textord, "Z", "\u2124");
  4467. defineSymbol(symbols_text, ams, textord, "Z", "\u2124");
  4468. defineSymbol(math, main, mathord, "h", "\u210E"); // italic h, Planck constant
  4469. defineSymbol(symbols_text, main, mathord, "h", "\u210E");
  4470. // The next loop loads wide (surrogate pair) characters.
  4471. // We support some letters in the Unicode range U+1D400 to U+1D7FF,
  4472. // Mathematical Alphanumeric Symbols.
  4473. // Some editors do not deal well with wide characters. So don't write the
  4474. // string into this file. Instead, create the string from the surrogate pair.
  4475. let wideChar = "";
  4476. for (let i = 0; i < letters.length; i++) {
  4477. const ch = letters.charAt(i);
  4478. // The hex numbers in the next line are a surrogate pair.
  4479. // 0xD835 is the high surrogate for all letters in the range we support.
  4480. // 0xDC00 is the low surrogate for bold A.
  4481. wideChar = String.fromCharCode(0xD835, 0xDC00 + i); // A-Z a-z bold
  4482. defineSymbol(math, main, mathord, ch, wideChar);
  4483. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4484. wideChar = String.fromCharCode(0xD835, 0xDC34 + i); // A-Z a-z italic
  4485. defineSymbol(math, main, mathord, ch, wideChar);
  4486. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4487. wideChar = String.fromCharCode(0xD835, 0xDC68 + i); // A-Z a-z bold italic
  4488. defineSymbol(math, main, mathord, ch, wideChar);
  4489. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4490. wideChar = String.fromCharCode(0xD835, 0xDD04 + i); // A-Z a-z Fraktur
  4491. defineSymbol(math, main, mathord, ch, wideChar);
  4492. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4493. wideChar = String.fromCharCode(0xD835, 0xDD6C + i); // A-Z a-z bold Fraktur
  4494. defineSymbol(math, main, mathord, ch, wideChar);
  4495. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4496. wideChar = String.fromCharCode(0xD835, 0xDDA0 + i); // A-Z a-z sans-serif
  4497. defineSymbol(math, main, mathord, ch, wideChar);
  4498. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4499. wideChar = String.fromCharCode(0xD835, 0xDDD4 + i); // A-Z a-z sans bold
  4500. defineSymbol(math, main, mathord, ch, wideChar);
  4501. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4502. wideChar = String.fromCharCode(0xD835, 0xDE08 + i); // A-Z a-z sans italic
  4503. defineSymbol(math, main, mathord, ch, wideChar);
  4504. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4505. wideChar = String.fromCharCode(0xD835, 0xDE70 + i); // A-Z a-z monospace
  4506. defineSymbol(math, main, mathord, ch, wideChar);
  4507. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4508. if (i < 26) {
  4509. // KaTeX fonts have only capital letters for blackboard bold and script.
  4510. // See exception for k below.
  4511. wideChar = String.fromCharCode(0xD835, 0xDD38 + i); // A-Z double struck
  4512. defineSymbol(math, main, mathord, ch, wideChar);
  4513. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4514. wideChar = String.fromCharCode(0xD835, 0xDC9C + i); // A-Z script
  4515. defineSymbol(math, main, mathord, ch, wideChar);
  4516. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4517. }
  4518. // TODO: Add bold script when it is supported by a KaTeX font.
  4519. }
  4520. // "k" is the only double struck lower case letter in the KaTeX fonts.
  4521. wideChar = String.fromCharCode(0xD835, 0xDD5C); // k double struck
  4522. defineSymbol(math, main, mathord, "k", wideChar);
  4523. defineSymbol(symbols_text, main, textord, "k", wideChar);
  4524. // Next, some wide character numerals
  4525. for (let i = 0; i < 10; i++) {
  4526. const ch = i.toString();
  4527. wideChar = String.fromCharCode(0xD835, 0xDFCE + i); // 0-9 bold
  4528. defineSymbol(math, main, mathord, ch, wideChar);
  4529. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4530. wideChar = String.fromCharCode(0xD835, 0xDFE2 + i); // 0-9 sans serif
  4531. defineSymbol(math, main, mathord, ch, wideChar);
  4532. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4533. wideChar = String.fromCharCode(0xD835, 0xDFEC + i); // 0-9 bold sans
  4534. defineSymbol(math, main, mathord, ch, wideChar);
  4535. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4536. wideChar = String.fromCharCode(0xD835, 0xDFF6 + i); // 0-9 monospace
  4537. defineSymbol(math, main, mathord, ch, wideChar);
  4538. defineSymbol(symbols_text, main, textord, ch, wideChar);
  4539. }
  4540. // We add these Latin-1 letters as symbols for backwards-compatibility,
  4541. // but they are not actually in the font, nor are they supported by the
  4542. // Unicode accent mechanism, so they fall back to Times font and look ugly.
  4543. // TODO(edemaine): Fix this.
  4544. const extraLatin = "\u00d0\u00de\u00fe";
  4545. for (let i = 0; i < extraLatin.length; i++) {
  4546. const ch = extraLatin.charAt(i);
  4547. defineSymbol(math, main, mathord, ch, ch);
  4548. defineSymbol(symbols_text, main, textord, ch, ch);
  4549. }
  4550. ;// ./src/wide-character.ts
  4551. /**
  4552. * This file provides support for Unicode range U+1D400 to U+1D7FF,
  4553. * Mathematical Alphanumeric Symbols.
  4554. *
  4555. * Function wideCharacterFont takes a wide character as input and returns
  4556. * the font information necessary to render it properly.
  4557. */
  4558. /**
  4559. * Data below is from https://www.unicode.org/charts/PDF/U1D400.pdf
  4560. * That document sorts characters into groups by font type, say bold or italic.
  4561. *
  4562. * In the arrays below, each subarray consists three elements:
  4563. * * The CSS class of that group when in math mode.
  4564. * * The CSS class of that group when in text mode.
  4565. * * The font name, so that KaTeX can get font metrics.
  4566. */
  4567. const wideLatinLetterData = [["mathbf", "textbf", "Main-Bold"],
  4568. // A-Z bold upright
  4569. ["mathbf", "textbf", "Main-Bold"],
  4570. // a-z bold upright
  4571. ["mathnormal", "textit", "Math-Italic"],
  4572. // A-Z italic
  4573. ["mathnormal", "textit", "Math-Italic"],
  4574. // a-z italic
  4575. ["boldsymbol", "boldsymbol", "Main-BoldItalic"],
  4576. // A-Z bold italic
  4577. ["boldsymbol", "boldsymbol", "Main-BoldItalic"],
  4578. // a-z bold italic
  4579. // Map fancy A-Z letters to script, not calligraphic.
  4580. // This aligns with unicode-math and math fonts (except Cambria Math).
  4581. ["mathscr", "textscr", "Script-Regular"],
  4582. // A-Z script
  4583. ["", "", ""],
  4584. // a-z script. No font
  4585. ["", "", ""],
  4586. // A-Z bold script. No font
  4587. ["", "", ""],
  4588. // a-z bold script. No font
  4589. ["mathfrak", "textfrak", "Fraktur-Regular"],
  4590. // A-Z Fraktur
  4591. ["mathfrak", "textfrak", "Fraktur-Regular"],
  4592. // a-z Fraktur
  4593. ["mathbb", "textbb", "AMS-Regular"],
  4594. // A-Z double-struck
  4595. ["mathbb", "textbb", "AMS-Regular"],
  4596. // k double-struck
  4597. // Note that we are using a bold font, but font metrics for regular Fraktur.
  4598. ["mathboldfrak", "textboldfrak", "Fraktur-Regular"],
  4599. // A-Z bold Fraktur
  4600. ["mathboldfrak", "textboldfrak", "Fraktur-Regular"],
  4601. // a-z bold Fraktur
  4602. ["mathsf", "textsf", "SansSerif-Regular"],
  4603. // A-Z sans-serif
  4604. ["mathsf", "textsf", "SansSerif-Regular"],
  4605. // a-z sans-serif
  4606. ["mathboldsf", "textboldsf", "SansSerif-Bold"],
  4607. // A-Z bold sans-serif
  4608. ["mathboldsf", "textboldsf", "SansSerif-Bold"],
  4609. // a-z bold sans-serif
  4610. ["mathitsf", "textitsf", "SansSerif-Italic"],
  4611. // A-Z italic sans-serif
  4612. ["mathitsf", "textitsf", "SansSerif-Italic"],
  4613. // a-z italic sans-serif
  4614. ["", "", ""],
  4615. // A-Z bold italic sans. No font
  4616. ["", "", ""],
  4617. // a-z bold italic sans. No font
  4618. ["mathtt", "texttt", "Typewriter-Regular"],
  4619. // A-Z monospace
  4620. ["mathtt", "texttt", "Typewriter-Regular"] // a-z monospace
  4621. ];
  4622. const wideNumeralData = [["mathbf", "textbf", "Main-Bold"],
  4623. // 0-9 bold
  4624. ["", "", ""],
  4625. // 0-9 double-struck. No KaTeX font.
  4626. ["mathsf", "textsf", "SansSerif-Regular"],
  4627. // 0-9 sans-serif
  4628. ["mathboldsf", "textboldsf", "SansSerif-Bold"],
  4629. // 0-9 bold sans-serif
  4630. ["mathtt", "texttt", "Typewriter-Regular"] // 0-9 monospace
  4631. ];
  4632. const wideCharacterFont = (wideChar, mode) => {
  4633. // IE doesn't support codePointAt(). So work with the surrogate pair.
  4634. const H = wideChar.charCodeAt(0); // high surrogate
  4635. const L = wideChar.charCodeAt(1); // low surrogate
  4636. const codePoint = (H - 0xD800) * 0x400 + (L - 0xDC00) + 0x10000;
  4637. const j = mode === "math" ? 0 : 1; // column index for CSS class.
  4638. if (0x1D400 <= codePoint && codePoint < 0x1D6A4) {
  4639. // wideLatinLetterData contains exactly 26 chars on each row.
  4640. // So we can calculate the relevant row. No traverse necessary.
  4641. const i = Math.floor((codePoint - 0x1D400) / 26);
  4642. return [wideLatinLetterData[i][2], wideLatinLetterData[i][j]];
  4643. } else if (0x1D7CE <= codePoint && codePoint <= 0x1D7FF) {
  4644. // Numerals, ten per row.
  4645. const i = Math.floor((codePoint - 0x1D7CE) / 10);
  4646. return [wideNumeralData[i][2], wideNumeralData[i][j]];
  4647. } else if (codePoint === 0x1D6A5 || codePoint === 0x1D6A6) {
  4648. // dotless i or j
  4649. return [wideLatinLetterData[0][2], wideLatinLetterData[0][j]];
  4650. } else if (0x1D6A6 < codePoint && codePoint < 0x1D7CE) {
  4651. // Greek letters. Not supported, yet.
  4652. return ["", ""];
  4653. } else {
  4654. // We don't support any wide characters outside 1D400–1D7FF.
  4655. throw new src_ParseError("Unsupported character: " + wideChar);
  4656. }
  4657. };
  4658. ;// ./src/buildCommon.ts
  4659. /* eslint no-console:0 */
  4660. /**
  4661. * This module contains general functions that can be used for building
  4662. * different kinds of domTree nodes in a consistent manner.
  4663. */
  4664. /**
  4665. * Looks up the given symbol in fontMetrics, after applying any symbol
  4666. * replacements defined in symbol.js
  4667. */
  4668. const lookupSymbol = function (value,
  4669. // TODO(#963): Use a union type for this.
  4670. fontName, mode) {
  4671. // Replace the value with its replaced value from symbol.js
  4672. if (src_symbols[mode][value]) {
  4673. const replacement = src_symbols[mode][value].replace;
  4674. if (replacement) {
  4675. value = replacement;
  4676. }
  4677. }
  4678. return {
  4679. value,
  4680. metrics: getCharacterMetrics(value, fontName, mode)
  4681. };
  4682. };
  4683. /**
  4684. * Makes a symbolNode after translation via the list of symbols in symbols.js.
  4685. * Correctly pulls out metrics for the character, and optionally takes a list of
  4686. * classes to be attached to the node.
  4687. *
  4688. * TODO: make argument order closer to makeSpan
  4689. * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
  4690. * should if present come first in `classes`.
  4691. * TODO(#953): Make `options` mandatory and always pass it in.
  4692. */
  4693. const makeSymbol = function (value, fontName, mode, options, classes) {
  4694. const lookup = lookupSymbol(value, fontName, mode);
  4695. const metrics = lookup.metrics;
  4696. value = lookup.value;
  4697. let symbolNode;
  4698. if (metrics) {
  4699. let italic = metrics.italic;
  4700. if (mode === "text" || options && options.font === "mathit") {
  4701. italic = 0;
  4702. }
  4703. symbolNode = new SymbolNode(value, metrics.height, metrics.depth, italic, metrics.skew, metrics.width, classes);
  4704. } else {
  4705. // TODO(emily): Figure out a good way to only print this in development
  4706. typeof console !== "undefined" && console.warn("No character metrics " + ("for '" + value + "' in style '" + fontName + "' and mode '" + mode + "'"));
  4707. symbolNode = new SymbolNode(value, 0, 0, 0, 0, 0, classes);
  4708. }
  4709. if (options) {
  4710. symbolNode.maxFontSize = options.sizeMultiplier;
  4711. if (options.style.isTight()) {
  4712. symbolNode.classes.push("mtight");
  4713. }
  4714. const color = options.getColor();
  4715. if (color) {
  4716. symbolNode.style.color = color;
  4717. }
  4718. }
  4719. return symbolNode;
  4720. };
  4721. /**
  4722. * Makes a symbol in Main-Regular or AMS-Regular.
  4723. * Used for rel, bin, open, close, inner, and punct.
  4724. */
  4725. const mathsym = function (value, mode, options, classes) {
  4726. if (classes === void 0) {
  4727. classes = [];
  4728. }
  4729. // Decide what font to render the symbol in by its entry in the symbols
  4730. // table.
  4731. // Have a special case for when the value = \ because the \ is used as a
  4732. // textord in unsupported command errors but cannot be parsed as a regular
  4733. // text ordinal and is therefore not present as a symbol in the symbols
  4734. // table for text, as well as a special case for boldsymbol because it
  4735. // can be used for bold + and -
  4736. if (options.font === "boldsymbol" && lookupSymbol(value, "Main-Bold", mode).metrics) {
  4737. return makeSymbol(value, "Main-Bold", mode, options, classes.concat(["mathbf"]));
  4738. } else if (value === "\\" || src_symbols[mode][value].font === "main") {
  4739. return makeSymbol(value, "Main-Regular", mode, options, classes);
  4740. } else {
  4741. return makeSymbol(value, "AMS-Regular", mode, options, classes.concat(["amsrm"]));
  4742. }
  4743. };
  4744. /**
  4745. * Determines which of the two font names (Main-Bold and Math-BoldItalic) and
  4746. * corresponding style tags (mathbf or boldsymbol) to use for font "boldsymbol",
  4747. * depending on the symbol. Use this function instead of fontMap for font
  4748. * "boldsymbol".
  4749. */
  4750. const boldsymbol = function (value, mode, options, classes, type) {
  4751. if (type !== "textord" && lookupSymbol(value, "Math-BoldItalic", mode).metrics) {
  4752. return {
  4753. fontName: "Math-BoldItalic",
  4754. fontClass: "boldsymbol"
  4755. };
  4756. } else {
  4757. // Some glyphs do not exist in Math-BoldItalic so we need to use
  4758. // Main-Bold instead.
  4759. return {
  4760. fontName: "Main-Bold",
  4761. fontClass: "mathbf"
  4762. };
  4763. }
  4764. };
  4765. /**
  4766. * Makes either a mathord or textord in the correct font and color.
  4767. */
  4768. const makeOrd = function (group, options, type) {
  4769. const mode = group.mode;
  4770. const text = group.text;
  4771. const classes = ["mord"];
  4772. // Math mode or Old font (i.e. \rm)
  4773. const isFont = mode === "math" || mode === "text" && options.font;
  4774. const fontOrFamily = isFont ? options.font : options.fontFamily;
  4775. let wideFontName = "";
  4776. let wideFontClass = "";
  4777. if (text.charCodeAt(0) === 0xD835) {
  4778. [wideFontName, wideFontClass] = wideCharacterFont(text, mode);
  4779. }
  4780. if (wideFontName.length > 0) {
  4781. // surrogate pairs get special treatment
  4782. return makeSymbol(text, wideFontName, mode, options, classes.concat(wideFontClass));
  4783. } else if (fontOrFamily) {
  4784. let fontName;
  4785. let fontClasses;
  4786. if (fontOrFamily === "boldsymbol") {
  4787. const fontData = boldsymbol(text, mode, options, classes, type);
  4788. fontName = fontData.fontName;
  4789. fontClasses = [fontData.fontClass];
  4790. } else if (isFont) {
  4791. fontName = fontMap[fontOrFamily].fontName;
  4792. fontClasses = [fontOrFamily];
  4793. } else {
  4794. fontName = retrieveTextFontName(fontOrFamily, options.fontWeight, options.fontShape);
  4795. fontClasses = [fontOrFamily, options.fontWeight, options.fontShape];
  4796. }
  4797. if (lookupSymbol(text, fontName, mode).metrics) {
  4798. return makeSymbol(text, fontName, mode, options, classes.concat(fontClasses));
  4799. } else if (ligatures.hasOwnProperty(text) && fontName.slice(0, 10) === "Typewriter") {
  4800. // Deconstruct ligatures in monospace fonts (\texttt, \tt).
  4801. const parts = [];
  4802. for (let i = 0; i < text.length; i++) {
  4803. parts.push(makeSymbol(text[i], fontName, mode, options, classes.concat(fontClasses)));
  4804. }
  4805. return makeFragment(parts);
  4806. }
  4807. }
  4808. // Makes a symbol in the default font for mathords and textords.
  4809. if (type === "mathord") {
  4810. return makeSymbol(text, "Math-Italic", mode, options, classes.concat(["mathnormal"]));
  4811. } else if (type === "textord") {
  4812. const font = src_symbols[mode][text] && src_symbols[mode][text].font;
  4813. if (font === "ams") {
  4814. const fontName = retrieveTextFontName("amsrm", options.fontWeight, options.fontShape);
  4815. return makeSymbol(text, fontName, mode, options, classes.concat("amsrm", options.fontWeight, options.fontShape));
  4816. } else if (font === "main" || !font) {
  4817. const fontName = retrieveTextFontName("textrm", options.fontWeight, options.fontShape);
  4818. return makeSymbol(text, fontName, mode, options, classes.concat(options.fontWeight, options.fontShape));
  4819. } else {
  4820. // fonts added by plugins
  4821. const fontName = retrieveTextFontName(font, options.fontWeight, options.fontShape);
  4822. // We add font name as a css class
  4823. return makeSymbol(text, fontName, mode, options, classes.concat(fontName, options.fontWeight, options.fontShape));
  4824. }
  4825. } else {
  4826. throw new Error("unexpected type: " + type + " in makeOrd");
  4827. }
  4828. };
  4829. /**
  4830. * Returns true if subsequent symbolNodes have the same classes, skew, maxFont,
  4831. * and styles. For mathnormal text, the left node must also have zero italic
  4832. * correction so we don't lose spacing between combined glyphs.
  4833. */
  4834. const canCombine = (prev, next) => {
  4835. if (createClass(prev.classes) !== createClass(next.classes) || prev.skew !== next.skew || prev.maxFontSize !== next.maxFontSize || prev.italic !== 0 && prev.hasClass("mathnormal")) {
  4836. return false;
  4837. }
  4838. // If prev and next both are just "mbin"s or "mord"s we don't combine them
  4839. // so that the proper spacing can be preserved.
  4840. if (prev.classes.length === 1) {
  4841. const cls = prev.classes[0];
  4842. if (cls === "mbin" || cls === "mord") {
  4843. return false;
  4844. }
  4845. }
  4846. for (const key of Object.keys(prev.style)) {
  4847. if (prev.style[key] !== next.style[key]) {
  4848. return false;
  4849. }
  4850. }
  4851. for (const key of Object.keys(next.style)) {
  4852. if (prev.style[key] !== next.style[key]) {
  4853. return false;
  4854. }
  4855. }
  4856. return true;
  4857. };
  4858. /**
  4859. * Combine consecutive domTree.symbolNodes into a single symbolNode.
  4860. * Note: this function mutates the argument.
  4861. */
  4862. const tryCombineChars = chars => {
  4863. for (let i = 0; i < chars.length - 1; i++) {
  4864. const prev = chars[i];
  4865. const next = chars[i + 1];
  4866. if (prev instanceof SymbolNode && next instanceof SymbolNode && canCombine(prev, next)) {
  4867. prev.text += next.text;
  4868. prev.height = Math.max(prev.height, next.height);
  4869. prev.depth = Math.max(prev.depth, next.depth);
  4870. // Use the last character's italic correction since we use
  4871. // it to add padding to the right of the span created from
  4872. // the combined characters.
  4873. prev.italic = next.italic;
  4874. chars.splice(i + 1, 1);
  4875. i--;
  4876. }
  4877. }
  4878. return chars;
  4879. };
  4880. /**
  4881. * Calculate the height, depth, and maxFontSize of an element based on its
  4882. * children.
  4883. */
  4884. const sizeElementFromChildren = function (elem) {
  4885. let height = 0;
  4886. let depth = 0;
  4887. let maxFontSize = 0;
  4888. for (let i = 0; i < elem.children.length; i++) {
  4889. const child = elem.children[i];
  4890. if (child.height > height) {
  4891. height = child.height;
  4892. }
  4893. if (child.depth > depth) {
  4894. depth = child.depth;
  4895. }
  4896. if (child.maxFontSize > maxFontSize) {
  4897. maxFontSize = child.maxFontSize;
  4898. }
  4899. }
  4900. elem.height = height;
  4901. elem.depth = depth;
  4902. elem.maxFontSize = maxFontSize;
  4903. };
  4904. /**
  4905. * Makes a span with the given list of classes, list of children, and options.
  4906. *
  4907. * TODO(#953): Ensure that `options` is always provided (currently some call
  4908. * sites don't pass it) and make the type below mandatory.
  4909. * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
  4910. * should if present come first in `classes`.
  4911. */
  4912. const makeSpan = function (classes, children, options, style) {
  4913. const span = new Span(classes, children, options, style);
  4914. sizeElementFromChildren(span);
  4915. return span;
  4916. };
  4917. // SVG one is simpler -- doesn't require height, depth, max-font setting.
  4918. // This is also a separate method for typesafety.
  4919. const makeSvgSpan = (classes, children, options, style) => new Span(classes, children, options, style);
  4920. const makeLineSpan = function (className, options, thickness) {
  4921. const line = makeSpan([className], [], options);
  4922. line.height = Math.max(thickness || options.fontMetrics().defaultRuleThickness, options.minRuleThickness);
  4923. line.style.borderBottomWidth = makeEm(line.height);
  4924. line.maxFontSize = 1.0;
  4925. return line;
  4926. };
  4927. /**
  4928. * Makes an anchor with the given href, list of classes, list of children,
  4929. * and options.
  4930. */
  4931. const makeAnchor = function (href, classes, children, options) {
  4932. const anchor = new Anchor(href, classes, children, options);
  4933. sizeElementFromChildren(anchor);
  4934. return anchor;
  4935. };
  4936. /**
  4937. * Makes a document fragment with the given list of children.
  4938. */
  4939. const makeFragment = function (children) {
  4940. const fragment = new DocumentFragment(children);
  4941. sizeElementFromChildren(fragment);
  4942. return fragment;
  4943. };
  4944. /**
  4945. * Wraps group in a span if it's a document fragment, allowing to apply classes
  4946. * and styles
  4947. */
  4948. const wrapFragment = function (group, options) {
  4949. if (group instanceof DocumentFragment) {
  4950. return makeSpan([], [group], options);
  4951. }
  4952. return group;
  4953. };
  4954. // A list of child or kern nodes to be stacked on top of each other (i.e. the
  4955. // first element will be at the bottom, and the last at the top).
  4956. // Computes the updated `children` list and the overall depth.
  4957. //
  4958. // This helper function for makeVList makes it easier to enforce type safety by
  4959. // allowing early exits (returns) in the logic.
  4960. const getVListChildrenAndDepth = function (params) {
  4961. if (params.positionType === "individualShift") {
  4962. const oldChildren = params.children;
  4963. const children = [oldChildren[0]];
  4964. // Add in kerns to the list of params.children to get each element to be
  4965. // shifted to the correct specified shift
  4966. const depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
  4967. let currPos = depth;
  4968. for (let i = 1; i < oldChildren.length; i++) {
  4969. const diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
  4970. const size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth);
  4971. currPos = currPos + diff;
  4972. children.push({
  4973. type: "kern",
  4974. size
  4975. });
  4976. children.push(oldChildren[i]);
  4977. }
  4978. return {
  4979. children,
  4980. depth
  4981. };
  4982. }
  4983. let depth;
  4984. if (params.positionType === "top") {
  4985. // We always start at the bottom, so calculate the bottom by adding up
  4986. // all the sizes
  4987. let bottom = params.positionData;
  4988. for (let i = 0; i < params.children.length; i++) {
  4989. const child = params.children[i];
  4990. bottom -= child.type === "kern" ? child.size : child.elem.height + child.elem.depth;
  4991. }
  4992. depth = bottom;
  4993. } else if (params.positionType === "bottom") {
  4994. depth = -params.positionData;
  4995. } else {
  4996. const firstChild = params.children[0];
  4997. if (firstChild.type !== "elem") {
  4998. throw new Error('First child must have type "elem".');
  4999. }
  5000. if (params.positionType === "shift") {
  5001. depth = -firstChild.elem.depth - params.positionData;
  5002. } else if (params.positionType === "firstBaseline") {
  5003. depth = -firstChild.elem.depth;
  5004. } else {
  5005. throw new Error("Invalid positionType " + params.positionType + ".");
  5006. }
  5007. }
  5008. return {
  5009. children: params.children,
  5010. depth
  5011. };
  5012. };
  5013. /**
  5014. * Makes a vertical list by stacking elements and kerns on top of each other.
  5015. * Allows for many different ways of specifying the positioning method.
  5016. *
  5017. * See VListParam documentation above.
  5018. */
  5019. const makeVList = function (params, options) {
  5020. const {
  5021. children,
  5022. depth
  5023. } = getVListChildrenAndDepth(params);
  5024. // Create a strut that is taller than any list item. The strut is added to
  5025. // each item, where it will determine the item's baseline. Since it has
  5026. // `overflow:hidden`, the strut's top edge will sit on the item's line box's
  5027. // top edge and the strut's bottom edge will sit on the item's baseline,
  5028. // with no additional line-height spacing. This allows the item baseline to
  5029. // be positioned precisely without worrying about font ascent and
  5030. // line-height.
  5031. let pstrutSize = 0;
  5032. for (let i = 0; i < children.length; i++) {
  5033. const child = children[i];
  5034. if (child.type === "elem") {
  5035. const elem = child.elem;
  5036. pstrutSize = Math.max(pstrutSize, elem.maxFontSize, elem.height);
  5037. }
  5038. }
  5039. pstrutSize += 2;
  5040. const pstrut = makeSpan(["pstrut"], []);
  5041. pstrut.style.height = makeEm(pstrutSize);
  5042. // Create a new list of actual children at the correct offsets
  5043. const realChildren = [];
  5044. let minPos = depth;
  5045. let maxPos = depth;
  5046. let currPos = depth;
  5047. for (let i = 0; i < children.length; i++) {
  5048. const child = children[i];
  5049. if (child.type === "kern") {
  5050. currPos += child.size;
  5051. } else {
  5052. const elem = child.elem;
  5053. const classes = child.wrapperClasses || [];
  5054. const style = child.wrapperStyle || {};
  5055. const childWrap = makeSpan(classes, [pstrut, elem], undefined, style);
  5056. childWrap.style.top = makeEm(-pstrutSize - currPos - elem.depth);
  5057. if (child.marginLeft) {
  5058. childWrap.style.marginLeft = child.marginLeft;
  5059. }
  5060. if (child.marginRight) {
  5061. childWrap.style.marginRight = child.marginRight;
  5062. }
  5063. realChildren.push(childWrap);
  5064. currPos += elem.height + elem.depth;
  5065. }
  5066. minPos = Math.min(minPos, currPos);
  5067. maxPos = Math.max(maxPos, currPos);
  5068. }
  5069. // The vlist contents go in a table-cell with `vertical-align:bottom`.
  5070. // This cell's bottom edge will determine the containing table's baseline
  5071. // without overly expanding the containing line-box.
  5072. const vlist = makeSpan(["vlist"], realChildren);
  5073. vlist.style.height = makeEm(maxPos);
  5074. // A second row is used if necessary to represent the vlist's depth.
  5075. let rows;
  5076. if (minPos < 0) {
  5077. // We will define depth in an empty span with display: table-cell.
  5078. // It should render with the height that we define. But Chrome, in
  5079. // contenteditable mode only, treats that span as if it contains some
  5080. // text content. And that min-height over-rides our desired height.
  5081. // So we put another empty span inside the depth strut span.
  5082. const emptySpan = makeSpan([], []);
  5083. const depthStrut = makeSpan(["vlist"], [emptySpan]);
  5084. depthStrut.style.height = makeEm(-minPos);
  5085. // Safari wants the first row to have inline content; otherwise it
  5086. // puts the bottom of the *second* row on the baseline.
  5087. const topStrut = makeSpan(["vlist-s"], [new SymbolNode("\u200b")]);
  5088. rows = [makeSpan(["vlist-r"], [vlist, topStrut]), makeSpan(["vlist-r"], [depthStrut])];
  5089. } else {
  5090. rows = [makeSpan(["vlist-r"], [vlist])];
  5091. }
  5092. const vtable = makeSpan(["vlist-t"], rows);
  5093. if (rows.length === 2) {
  5094. vtable.classes.push("vlist-t2");
  5095. }
  5096. vtable.height = maxPos;
  5097. vtable.depth = -minPos;
  5098. return vtable;
  5099. };
  5100. // Glue is a concept from TeX which is a flexible space between elements in
  5101. // either a vertical or horizontal list. In KaTeX, at least for now, it's
  5102. // static space between elements in a horizontal layout.
  5103. const makeGlue = (measurement, options) => {
  5104. // Make an empty span for the space
  5105. const rule = makeSpan(["mspace"], [], options);
  5106. const size = calculateSize(measurement, options);
  5107. rule.style.marginRight = makeEm(size);
  5108. return rule;
  5109. };
  5110. // Takes font options, and returns the appropriate fontLookup name
  5111. const retrieveTextFontName = function (fontFamily, fontWeight, fontShape) {
  5112. let baseFontName = "";
  5113. switch (fontFamily) {
  5114. case "amsrm":
  5115. baseFontName = "AMS";
  5116. break;
  5117. case "textrm":
  5118. baseFontName = "Main";
  5119. break;
  5120. case "textsf":
  5121. baseFontName = "SansSerif";
  5122. break;
  5123. case "texttt":
  5124. baseFontName = "Typewriter";
  5125. break;
  5126. default:
  5127. baseFontName = fontFamily;
  5128. // use fonts added by a plugin
  5129. }
  5130. let fontStylesName;
  5131. if (fontWeight === "textbf" && fontShape === "textit") {
  5132. fontStylesName = "BoldItalic";
  5133. } else if (fontWeight === "textbf") {
  5134. fontStylesName = "Bold";
  5135. } else if (fontWeight === "textit") {
  5136. fontStylesName = "Italic";
  5137. } else {
  5138. fontStylesName = "Regular";
  5139. }
  5140. return baseFontName + "-" + fontStylesName;
  5141. };
  5142. /**
  5143. * Maps TeX font commands to objects containing:
  5144. * - variant: string used for "mathvariant" attribute in buildMathML.js
  5145. * - fontName: the "style" parameter to fontMetrics.getCharacterMetrics
  5146. */
  5147. // A map between tex font commands an MathML mathvariant attribute values
  5148. const fontMap = {
  5149. // styles
  5150. "mathbf": {
  5151. variant: "bold",
  5152. fontName: "Main-Bold"
  5153. },
  5154. "mathrm": {
  5155. variant: "normal",
  5156. fontName: "Main-Regular"
  5157. },
  5158. "textit": {
  5159. variant: "italic",
  5160. fontName: "Main-Italic"
  5161. },
  5162. "mathit": {
  5163. variant: "italic",
  5164. fontName: "Main-Italic"
  5165. },
  5166. "mathnormal": {
  5167. variant: "italic",
  5168. fontName: "Math-Italic"
  5169. },
  5170. "mathsfit": {
  5171. variant: "sans-serif-italic",
  5172. fontName: "SansSerif-Italic"
  5173. },
  5174. // "boldsymbol" is missing because they require the use of multiple fonts:
  5175. // Math-BoldItalic and Main-Bold. This is handled by a special case in
  5176. // makeOrd which ends up calling boldsymbol.
  5177. // families
  5178. "mathbb": {
  5179. variant: "double-struck",
  5180. fontName: "AMS-Regular"
  5181. },
  5182. "mathcal": {
  5183. variant: "script",
  5184. fontName: "Caligraphic-Regular"
  5185. },
  5186. "mathfrak": {
  5187. variant: "fraktur",
  5188. fontName: "Fraktur-Regular"
  5189. },
  5190. "mathscr": {
  5191. variant: "script",
  5192. fontName: "Script-Regular"
  5193. },
  5194. "mathsf": {
  5195. variant: "sans-serif",
  5196. fontName: "SansSerif-Regular"
  5197. },
  5198. "mathtt": {
  5199. variant: "monospace",
  5200. fontName: "Typewriter-Regular"
  5201. }
  5202. };
  5203. const svgData = {
  5204. // path, width, height
  5205. vec: ["vec", 0.471, 0.714],
  5206. // values from the font glyph
  5207. oiintSize1: ["oiintSize1", 0.957, 0.499],
  5208. // oval to overlay the integrand
  5209. oiintSize2: ["oiintSize2", 1.472, 0.659],
  5210. oiiintSize1: ["oiiintSize1", 1.304, 0.499],
  5211. oiiintSize2: ["oiiintSize2", 1.98, 0.659]
  5212. };
  5213. const staticSvg = function (value, options) {
  5214. // Create a span with inline SVG for the element.
  5215. const [pathName, width, height] = svgData[value];
  5216. const path = new PathNode(pathName);
  5217. const svgNode = new SvgNode([path], {
  5218. "width": makeEm(width),
  5219. "height": makeEm(height),
  5220. // Override CSS rule `.katex svg { width: 100% }`
  5221. "style": "width:" + makeEm(width),
  5222. "viewBox": "0 0 " + 1000 * width + " " + 1000 * height,
  5223. "preserveAspectRatio": "xMinYMin"
  5224. });
  5225. const span = makeSvgSpan(["overlay"], [svgNode], options);
  5226. span.height = height;
  5227. span.style.height = makeEm(height);
  5228. span.style.width = makeEm(width);
  5229. return span;
  5230. };
  5231. ;// ./src/spacingData.ts
  5232. /**
  5233. * Describes spaces between different classes of atoms.
  5234. */
  5235. const thinspace = {
  5236. number: 3,
  5237. unit: "mu"
  5238. };
  5239. const mediumspace = {
  5240. number: 4,
  5241. unit: "mu"
  5242. };
  5243. const thickspace = {
  5244. number: 5,
  5245. unit: "mu"
  5246. };
  5247. // Making the type below exact with all optional fields doesn't work due to
  5248. // - https://github.com/facebook/flow/issues/4582
  5249. // - https://github.com/facebook/flow/issues/5688
  5250. // However, since *all* fields are optional, $Shape<> works as suggested in 5688
  5251. // above.
  5252. // Spacing relationships for display and text styles
  5253. const spacings = {
  5254. mord: {
  5255. mop: thinspace,
  5256. mbin: mediumspace,
  5257. mrel: thickspace,
  5258. minner: thinspace
  5259. },
  5260. mop: {
  5261. mord: thinspace,
  5262. mop: thinspace,
  5263. mrel: thickspace,
  5264. minner: thinspace
  5265. },
  5266. mbin: {
  5267. mord: mediumspace,
  5268. mop: mediumspace,
  5269. mopen: mediumspace,
  5270. minner: mediumspace
  5271. },
  5272. mrel: {
  5273. mord: thickspace,
  5274. mop: thickspace,
  5275. mopen: thickspace,
  5276. minner: thickspace
  5277. },
  5278. mopen: {},
  5279. mclose: {
  5280. mop: thinspace,
  5281. mbin: mediumspace,
  5282. mrel: thickspace,
  5283. minner: thinspace
  5284. },
  5285. mpunct: {
  5286. mord: thinspace,
  5287. mop: thinspace,
  5288. mrel: thickspace,
  5289. mopen: thinspace,
  5290. mclose: thinspace,
  5291. mpunct: thinspace,
  5292. minner: thinspace
  5293. },
  5294. minner: {
  5295. mord: thinspace,
  5296. mop: thinspace,
  5297. mbin: mediumspace,
  5298. mrel: thickspace,
  5299. mopen: thinspace,
  5300. mpunct: thinspace,
  5301. minner: thinspace
  5302. }
  5303. };
  5304. // Spacing relationships for script and scriptscript styles
  5305. const tightSpacings = {
  5306. mord: {
  5307. mop: thinspace
  5308. },
  5309. mop: {
  5310. mord: thinspace,
  5311. mop: thinspace
  5312. },
  5313. mbin: {},
  5314. mrel: {},
  5315. mopen: {},
  5316. mclose: {
  5317. mop: thinspace
  5318. },
  5319. mpunct: {},
  5320. minner: {
  5321. mop: thinspace
  5322. }
  5323. };
  5324. ;// ./src/defineFunction.ts
  5325. /** Context provided to function handlers for error messages. */
  5326. // Note: reverse the order of the return type union will cause a flow error.
  5327. // See https://github.com/facebook/flow/issues/3663.
  5328. // More general version of `HtmlBuilder` for nodes (e.g. \sum, accent types)
  5329. // whose presence impacts super/subscripting. In this case, ParseNode<"supsub">
  5330. // delegates its HTML building to the HtmlBuilder corresponding to these nodes.
  5331. /**
  5332. * Final function spec for use at parse time.
  5333. * This is almost identical to `FunctionPropSpec`, except it
  5334. * 1. includes the function handler, and
  5335. * 2. requires all arguments except argTypes.
  5336. * It is generated by `defineFunction()` below.
  5337. */
  5338. /**
  5339. * All registered functions.
  5340. * `functions.js` just exports this same dictionary again and makes it public.
  5341. * `Parser.js` requires this dictionary.
  5342. */
  5343. const _functions = {};
  5344. /**
  5345. * All HTML builders. Should be only used in the `define*` and the `build*ML`
  5346. * functions.
  5347. */
  5348. const _htmlGroupBuilders = {};
  5349. /**
  5350. * All MathML builders. Should be only used in the `define*` and the `build*ML`
  5351. * functions.
  5352. */
  5353. const _mathmlGroupBuilders = {};
  5354. function defineFunction(_ref) {
  5355. let {
  5356. type,
  5357. names,
  5358. props,
  5359. handler,
  5360. htmlBuilder,
  5361. mathmlBuilder
  5362. } = _ref;
  5363. // Set default values of functions
  5364. const data = {
  5365. type,
  5366. numArgs: props.numArgs,
  5367. argTypes: props.argTypes,
  5368. allowedInArgument: !!props.allowedInArgument,
  5369. allowedInText: !!props.allowedInText,
  5370. allowedInMath: props.allowedInMath === undefined ? true : props.allowedInMath,
  5371. numOptionalArgs: props.numOptionalArgs || 0,
  5372. infix: !!props.infix,
  5373. primitive: !!props.primitive,
  5374. handler
  5375. };
  5376. for (let i = 0; i < names.length; ++i) {
  5377. _functions[names[i]] = data;
  5378. }
  5379. if (type) {
  5380. if (htmlBuilder) {
  5381. _htmlGroupBuilders[type] = htmlBuilder;
  5382. }
  5383. if (mathmlBuilder) {
  5384. _mathmlGroupBuilders[type] = mathmlBuilder;
  5385. }
  5386. }
  5387. }
  5388. /**
  5389. * Use this to register only the HTML and MathML builders for a function (e.g.
  5390. * if the function's ParseNode is generated in Parser.js rather than via a
  5391. * stand-alone handler provided to `defineFunction`).
  5392. */
  5393. function defineFunctionBuilders(_ref2) {
  5394. let {
  5395. type,
  5396. htmlBuilder,
  5397. mathmlBuilder
  5398. } = _ref2;
  5399. defineFunction({
  5400. type,
  5401. names: [],
  5402. props: {
  5403. numArgs: 0
  5404. },
  5405. handler() {
  5406. throw new Error('Should never be called.');
  5407. },
  5408. htmlBuilder,
  5409. mathmlBuilder
  5410. });
  5411. }
  5412. const normalizeArgument = function (arg) {
  5413. return arg.type === "ordgroup" && arg.body.length === 1 ? arg.body[0] : arg;
  5414. };
  5415. // Since the corresponding buildHTML/buildMathML function expects a
  5416. // list of elements, we normalize for different kinds of arguments
  5417. const ordargument = function (arg) {
  5418. return arg.type === "ordgroup" ? arg.body : [arg];
  5419. };
  5420. ;// ./src/buildHTML.ts
  5421. /**
  5422. * This file does the main work of building a domTree structure from a parse
  5423. * tree. The entry point is the `buildHTML` function, which takes a parse tree.
  5424. * Then, the buildExpression, buildGroup, and various groupBuilders functions
  5425. * are called, to produce a final HTML tree.
  5426. */
  5427. // Binary atoms (first class `mbin`) change into ordinary atoms (`mord`)
  5428. // depending on their surroundings. See TeXbook pg. 442-446, Rules 5 and 6,
  5429. // and the text before Rule 19.
  5430. const binLeftCanceller = new Set(["leftmost", "mbin", "mopen", "mrel", "mop", "mpunct"]);
  5431. const binRightCanceller = new Set(["rightmost", "mrel", "mclose", "mpunct"]);
  5432. const styleMap = {
  5433. "display": src_Style.DISPLAY,
  5434. "text": src_Style.TEXT,
  5435. "script": src_Style.SCRIPT,
  5436. "scriptscript": src_Style.SCRIPTSCRIPT
  5437. };
  5438. const DomEnum = {
  5439. mord: "mord",
  5440. mop: "mop",
  5441. mbin: "mbin",
  5442. mrel: "mrel",
  5443. mopen: "mopen",
  5444. mclose: "mclose",
  5445. mpunct: "mpunct",
  5446. minner: "minner"
  5447. };
  5448. /**
  5449. * Take a list of nodes, build them in order, and return a list of the built
  5450. * nodes. documentFragments are flattened into their contents, so the
  5451. * returned list contains no fragments. `isRealGroup` is true if `expression`
  5452. * is a real group (no atoms will be added on either side), as opposed to
  5453. * a partial group (e.g. one created by \color). `surrounding` is an array
  5454. * consisting type of nodes that will be added to the left and right.
  5455. */
  5456. const buildExpression = function (expression, options, isRealGroup, surrounding) {
  5457. if (surrounding === void 0) {
  5458. surrounding = [null, null];
  5459. }
  5460. // Parse expressions into `groups`.
  5461. const groups = [];
  5462. for (let i = 0; i < expression.length; i++) {
  5463. const output = buildGroup(expression[i], options);
  5464. if (output instanceof DocumentFragment) {
  5465. const children = output.children;
  5466. groups.push(...children);
  5467. } else {
  5468. groups.push(output);
  5469. }
  5470. }
  5471. // Combine consecutive domTree.symbolNodes into a single symbolNode.
  5472. tryCombineChars(groups);
  5473. // If `expression` is a partial group, let the parent handle spacings
  5474. // to avoid processing groups multiple times.
  5475. if (!isRealGroup) {
  5476. return groups;
  5477. }
  5478. let glueOptions = options;
  5479. if (expression.length === 1) {
  5480. const node = expression[0];
  5481. if (node.type === "sizing") {
  5482. glueOptions = options.havingSize(node.size);
  5483. } else if (node.type === "styling") {
  5484. glueOptions = options.havingStyle(styleMap[node.style]);
  5485. }
  5486. }
  5487. // Dummy spans for determining spacings between surrounding atoms.
  5488. // If `expression` has no atoms on the left or right, class "leftmost"
  5489. // or "rightmost", respectively, is used to indicate it.
  5490. const dummyPrev = makeSpan([surrounding[0] || "leftmost"], [], options);
  5491. const dummyNext = makeSpan([surrounding[1] || "rightmost"], [], options);
  5492. // TODO: These code assumes that a node's math class is the first element
  5493. // of its `classes` array. A later cleanup should ensure this, for
  5494. // instance by changing the signature of `makeSpan`.
  5495. // Before determining what spaces to insert, perform bin cancellation.
  5496. // Binary operators change to ordinary symbols in some contexts.
  5497. const isRoot = isRealGroup === "root";
  5498. traverseNonSpaceNodes(groups, (node, prev) => {
  5499. const prevType = prev.classes[0];
  5500. const type = node.classes[0];
  5501. if (prevType === "mbin" && binRightCanceller.has(type)) {
  5502. prev.classes[0] = "mord";
  5503. } else if (type === "mbin" && binLeftCanceller.has(prevType)) {
  5504. node.classes[0] = "mord";
  5505. }
  5506. }, {
  5507. node: dummyPrev
  5508. }, dummyNext, isRoot);
  5509. traverseNonSpaceNodes(groups, (node, prev) => {
  5510. var _tightSpacings$prevTy, _spacings$prevType;
  5511. const prevType = getTypeOfDomTree(prev);
  5512. const type = getTypeOfDomTree(node);
  5513. // 'mtight' indicates that the node is script or scriptscript style.
  5514. const space = prevType && type ? node.hasClass("mtight") ? (_tightSpacings$prevTy = tightSpacings[prevType]) == null ? void 0 : _tightSpacings$prevTy[type] : (_spacings$prevType = spacings[prevType]) == null ? void 0 : _spacings$prevType[type] : null;
  5515. if (space) {
  5516. // Insert glue (spacing) after the `prev`.
  5517. return makeGlue(space, glueOptions);
  5518. }
  5519. }, {
  5520. node: dummyPrev
  5521. }, dummyNext, isRoot);
  5522. return groups;
  5523. };
  5524. // Depth-first traverse non-space `nodes`, calling `callback` with the current and
  5525. // previous node as arguments, optionally returning a node to insert after the
  5526. // previous node. `prev` is an object with the previous node and `insertAfter`
  5527. // function to insert after it. `next` is a node that will be added to the right.
  5528. // Used for bin cancellation and inserting spacings.
  5529. const traverseNonSpaceNodes = function (nodes, callback, prev, next, isRoot) {
  5530. if (next) {
  5531. // temporarily append the right node, if exists
  5532. nodes.push(next);
  5533. }
  5534. let i = 0;
  5535. for (; i < nodes.length; i++) {
  5536. const node = nodes[i];
  5537. const partialGroup = checkPartialGroup(node);
  5538. if (partialGroup) {
  5539. // Recursive DFS
  5540. // TODO(ts): make nodes a $ReadOnlyArray by returning a new array
  5541. traverseNonSpaceNodes(partialGroup.children, callback, prev, null, isRoot);
  5542. continue;
  5543. }
  5544. // Ignore explicit spaces (e.g., \;, \,) when determining what implicit
  5545. // spacing should go between atoms of different classes
  5546. const nonspace = !node.hasClass("mspace");
  5547. if (nonspace) {
  5548. const result = callback(node, prev.node);
  5549. if (result) {
  5550. if (prev.insertAfter) {
  5551. prev.insertAfter(result);
  5552. } else {
  5553. // insert at front
  5554. nodes.unshift(result);
  5555. i++;
  5556. }
  5557. }
  5558. }
  5559. if (nonspace) {
  5560. prev.node = node;
  5561. } else if (isRoot && node.hasClass("newline")) {
  5562. prev.node = makeSpan(["leftmost"]); // treat like beginning of line
  5563. }
  5564. prev.insertAfter = (index => n => {
  5565. nodes.splice(index + 1, 0, n);
  5566. i++;
  5567. })(i);
  5568. }
  5569. if (next) {
  5570. nodes.pop();
  5571. }
  5572. };
  5573. // Check if given node is a partial group, i.e., does not affect spacing around.
  5574. const checkPartialGroup = function (node) {
  5575. if (node instanceof DocumentFragment || node instanceof Anchor || node instanceof Span && node.hasClass("enclosing")) {
  5576. return node;
  5577. }
  5578. return null;
  5579. };
  5580. // Return the outermost node of a domTree.
  5581. const getOutermostNode = function (node, side) {
  5582. const partialGroup = checkPartialGroup(node);
  5583. if (partialGroup) {
  5584. const children = partialGroup.children;
  5585. if (children.length) {
  5586. if (side === "right") {
  5587. return getOutermostNode(children[children.length - 1], "right");
  5588. } else if (side === "left") {
  5589. return getOutermostNode(children[0], "left");
  5590. }
  5591. }
  5592. }
  5593. return node;
  5594. };
  5595. // Return math atom class (mclass) of a domTree.
  5596. // If `side` is given, it will get the type of the outermost node at given side.
  5597. const getTypeOfDomTree = function (node, side) {
  5598. if (!node) {
  5599. return null;
  5600. }
  5601. if (side) {
  5602. node = getOutermostNode(node, side);
  5603. }
  5604. // This makes a lot of assumptions as to where the type of atom
  5605. // appears. We should do a better job of enforcing this.
  5606. const className = node.classes[0];
  5607. return DomEnum[className] || null;
  5608. };
  5609. const makeNullDelimiter = function (options, classes) {
  5610. const moreClasses = ["nulldelimiter"].concat(options.baseSizingClasses());
  5611. return makeSpan(classes.concat(moreClasses));
  5612. };
  5613. /**
  5614. * buildGroup is the function that takes a group and calls the correct groupType
  5615. * function for it. It also handles the interaction of size and style changes
  5616. * between parents and children.
  5617. */
  5618. const buildGroup = function (group, options, baseOptions) {
  5619. if (!group) {
  5620. return makeSpan();
  5621. }
  5622. if (_htmlGroupBuilders[group.type]) {
  5623. // Call the groupBuilders function
  5624. // TODO(ts)
  5625. let groupNode = _htmlGroupBuilders[group.type](group, options);
  5626. // If the size changed between the parent and the current group, account
  5627. // for that size difference.
  5628. if (baseOptions && options.size !== baseOptions.size) {
  5629. groupNode = makeSpan(options.sizingClasses(baseOptions), [groupNode], options);
  5630. const multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier;
  5631. groupNode.height *= multiplier;
  5632. groupNode.depth *= multiplier;
  5633. }
  5634. return groupNode;
  5635. } else {
  5636. throw new src_ParseError("Got group of unknown type: '" + group.type + "'");
  5637. }
  5638. };
  5639. /**
  5640. * Combine an array of HTML DOM nodes (e.g., the output of `buildExpression`)
  5641. * into an unbreakable HTML node of class .base, with proper struts to
  5642. * guarantee correct vertical extent. `buildHTML` calls this repeatedly to
  5643. * make up the entire expression as a sequence of unbreakable units.
  5644. */
  5645. function buildHTMLUnbreakable(children, options) {
  5646. // Compute height and depth of this chunk.
  5647. const body = makeSpan(["base"], children, options);
  5648. // Add strut, which ensures that the top of the HTML element falls at
  5649. // the height of the expression, and the bottom of the HTML element
  5650. // falls at the depth of the expression.
  5651. const strut = makeSpan(["strut"]);
  5652. strut.style.height = makeEm(body.height + body.depth);
  5653. if (body.depth) {
  5654. strut.style.verticalAlign = makeEm(-body.depth);
  5655. }
  5656. body.children.unshift(strut);
  5657. return body;
  5658. }
  5659. /**
  5660. * Take an entire parse tree, and build it into an appropriate set of HTML
  5661. * nodes.
  5662. */
  5663. function buildHTML(tree, options) {
  5664. // Strip off outer tag wrapper for processing below.
  5665. let tag = null;
  5666. if (tree.length === 1 && tree[0].type === "tag") {
  5667. tag = tree[0].tag;
  5668. tree = tree[0].body;
  5669. }
  5670. // Build the expression contained in the tree
  5671. const expression = buildExpression(tree, options, "root");
  5672. let eqnNum;
  5673. if (expression.length === 2 && expression[1].hasClass("tag")) {
  5674. // An environment with automatic equation numbers, e.g. {gather}.
  5675. eqnNum = expression.pop();
  5676. }
  5677. const children = [];
  5678. // Create one base node for each chunk between potential line breaks.
  5679. // The TeXBook [p.173] says "A formula will be broken only after a
  5680. // relation symbol like $=$ or $<$ or $\rightarrow$, or after a binary
  5681. // operation symbol like $+$ or $-$ or $\times$, where the relation or
  5682. // binary operation is on the ``outer level'' of the formula (i.e., not
  5683. // enclosed in {...} and not part of an \over construction)."
  5684. let parts = [];
  5685. for (let i = 0; i < expression.length; i++) {
  5686. parts.push(expression[i]);
  5687. if (expression[i].hasClass("mbin") || expression[i].hasClass("mrel") || expression[i].hasClass("allowbreak")) {
  5688. // Put any post-operator glue on same line as operator.
  5689. // Watch for \nobreak along the way, and stop at \newline.
  5690. let nobreak = false;
  5691. while (i < expression.length - 1 && expression[i + 1].hasClass("mspace") && !expression[i + 1].hasClass("newline")) {
  5692. i++;
  5693. parts.push(expression[i]);
  5694. if (expression[i].hasClass("nobreak")) {
  5695. nobreak = true;
  5696. }
  5697. }
  5698. // Don't allow break if \nobreak among the post-operator glue.
  5699. if (!nobreak) {
  5700. children.push(buildHTMLUnbreakable(parts, options));
  5701. parts = [];
  5702. }
  5703. } else if (expression[i].hasClass("newline")) {
  5704. // Write the line except the newline
  5705. parts.pop();
  5706. if (parts.length > 0) {
  5707. children.push(buildHTMLUnbreakable(parts, options));
  5708. parts = [];
  5709. }
  5710. // Put the newline at the top level
  5711. children.push(expression[i]);
  5712. }
  5713. }
  5714. if (parts.length > 0) {
  5715. children.push(buildHTMLUnbreakable(parts, options));
  5716. }
  5717. // Now, if there was a tag, build it too and append it as a final child.
  5718. let tagChild;
  5719. if (tag) {
  5720. tagChild = buildHTMLUnbreakable(buildExpression(tag, options, true), options);
  5721. tagChild.classes = ["tag"];
  5722. children.push(tagChild);
  5723. } else if (eqnNum) {
  5724. children.push(eqnNum);
  5725. }
  5726. const htmlNode = makeSpan(["katex-html"], children);
  5727. htmlNode.setAttribute("aria-hidden", "true");
  5728. // Adjust the strut of the tag to be the maximum height of all children
  5729. // (the height of the enclosing htmlNode) for proper vertical alignment.
  5730. if (tagChild) {
  5731. const strut = tagChild.children[0];
  5732. strut.style.height = makeEm(htmlNode.height + htmlNode.depth);
  5733. if (htmlNode.depth) {
  5734. strut.style.verticalAlign = makeEm(-htmlNode.depth);
  5735. }
  5736. }
  5737. return htmlNode;
  5738. }
  5739. ;// ./src/mathMLTree.ts
  5740. /**
  5741. * These objects store data about MathML nodes. This is the MathML equivalent
  5742. * of the types in domTree.js. Since MathML handles its own rendering, and
  5743. * since we're mainly using MathML to improve accessibility, we don't manage
  5744. * any of the styling state that the plain DOM nodes do.
  5745. *
  5746. * The `toNode` and `toMarkup` functions work similarly to how they do in
  5747. * domTree.js, creating namespaced DOM nodes and HTML text markup respectively.
  5748. */
  5749. /**
  5750. * MathML node types used in KaTeX. For a complete list of MathML nodes, see
  5751. * https://developer.mozilla.org/en-US/docs/Web/MathML/Element.
  5752. */
  5753. function newDocumentFragment(children) {
  5754. return new DocumentFragment(children);
  5755. }
  5756. /**
  5757. * This node represents a general purpose MathML node of any type. The
  5758. * constructor requires the type of node to create (for example, `"mo"` or
  5759. * `"mspace"`, corresponding to `<mo>` and `<mspace>` tags).
  5760. */
  5761. class MathNode {
  5762. constructor(type, children, classes) {
  5763. this.type = type;
  5764. this.attributes = {};
  5765. this.children = children || [];
  5766. this.classes = classes || [];
  5767. }
  5768. /**
  5769. * Sets an attribute on a MathML node. MathML depends on attributes to convey a
  5770. * semantic content, so this is used heavily.
  5771. */
  5772. setAttribute(name, value) {
  5773. this.attributes[name] = value;
  5774. }
  5775. /**
  5776. * Gets an attribute on a MathML node.
  5777. */
  5778. getAttribute(name) {
  5779. return this.attributes[name];
  5780. }
  5781. /**
  5782. * Converts the math node into a MathML-namespaced DOM element.
  5783. */
  5784. toNode() {
  5785. const node = document.createElementNS("http://www.w3.org/1998/Math/MathML", this.type);
  5786. for (const attr in this.attributes) {
  5787. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  5788. node.setAttribute(attr, this.attributes[attr]);
  5789. }
  5790. }
  5791. if (this.classes.length > 0) {
  5792. node.className = createClass(this.classes);
  5793. }
  5794. for (let i = 0; i < this.children.length; i++) {
  5795. // Combine multiple TextNodes into one TextNode, to prevent
  5796. // screen readers from reading each as a separate word [#3995]
  5797. if (this.children[i] instanceof TextNode && this.children[i + 1] instanceof TextNode) {
  5798. let text = this.children[i].toText() + this.children[++i].toText();
  5799. while (this.children[i + 1] instanceof TextNode) {
  5800. text += this.children[++i].toText();
  5801. }
  5802. node.appendChild(new TextNode(text).toNode());
  5803. } else {
  5804. node.appendChild(this.children[i].toNode());
  5805. }
  5806. }
  5807. return node;
  5808. }
  5809. /**
  5810. * Converts the math node into an HTML markup string.
  5811. */
  5812. toMarkup() {
  5813. let markup = "<" + this.type;
  5814. // Add the attributes
  5815. for (const attr in this.attributes) {
  5816. if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
  5817. markup += " " + attr + "=\"";
  5818. markup += utils_escape(this.attributes[attr]);
  5819. markup += "\"";
  5820. }
  5821. }
  5822. if (this.classes.length > 0) {
  5823. markup += " class =\"" + utils_escape(createClass(this.classes)) + "\"";
  5824. }
  5825. markup += ">";
  5826. for (let i = 0; i < this.children.length; i++) {
  5827. markup += this.children[i].toMarkup();
  5828. }
  5829. markup += "</" + this.type + ">";
  5830. return markup;
  5831. }
  5832. /**
  5833. * Converts the math node into a string, similar to innerText, but escaped.
  5834. */
  5835. toText() {
  5836. return this.children.map(child => child.toText()).join("");
  5837. }
  5838. }
  5839. /**
  5840. * This node represents a piece of text.
  5841. */
  5842. class TextNode {
  5843. constructor(text) {
  5844. this.text = text;
  5845. }
  5846. /**
  5847. * Converts the text node into a DOM text node.
  5848. */
  5849. toNode() {
  5850. return document.createTextNode(this.text);
  5851. }
  5852. /**
  5853. * Converts the text node into escaped HTML markup
  5854. * (representing the text itself).
  5855. */
  5856. toMarkup() {
  5857. return utils_escape(this.toText());
  5858. }
  5859. /**
  5860. * Converts the text node into a string
  5861. * (representing the text itself).
  5862. */
  5863. toText() {
  5864. return this.text;
  5865. }
  5866. }
  5867. /**
  5868. * This node represents a space, but may render as <mspace.../> or as text,
  5869. * depending on the width.
  5870. */
  5871. class SpaceNode {
  5872. /**
  5873. * Create a Space node with width given in CSS ems.
  5874. */
  5875. constructor(width) {
  5876. this.width = width;
  5877. // See https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html
  5878. // for a table of space-like characters. We use Unicode
  5879. // representations instead of &LongNames; as it's not clear how to
  5880. // make the latter via document.createTextNode.
  5881. if (width >= 0.05555 && width <= 0.05556) {
  5882. this.character = "\u200a"; // &VeryThinSpace;
  5883. } else if (width >= 0.1666 && width <= 0.1667) {
  5884. this.character = "\u2009"; // &ThinSpace;
  5885. } else if (width >= 0.2222 && width <= 0.2223) {
  5886. this.character = "\u2005"; // &MediumSpace;
  5887. } else if (width >= 0.2777 && width <= 0.2778) {
  5888. this.character = "\u2005\u200a"; // &ThickSpace;
  5889. } else if (width >= -0.05556 && width <= -0.05555) {
  5890. this.character = "\u200a\u2063"; // &NegativeVeryThinSpace;
  5891. } else if (width >= -0.1667 && width <= -0.1666) {
  5892. this.character = "\u2009\u2063"; // &NegativeThinSpace;
  5893. } else if (width >= -0.2223 && width <= -0.2222) {
  5894. this.character = "\u205f\u2063"; // &NegativeMediumSpace;
  5895. } else if (width >= -0.2778 && width <= -0.2777) {
  5896. this.character = "\u2005\u2063"; // &NegativeThickSpace;
  5897. } else {
  5898. this.character = null;
  5899. }
  5900. }
  5901. /**
  5902. * Converts the math node into a MathML-namespaced DOM element.
  5903. */
  5904. toNode() {
  5905. if (this.character) {
  5906. return document.createTextNode(this.character);
  5907. } else {
  5908. const node = document.createElementNS("http://www.w3.org/1998/Math/MathML", "mspace");
  5909. node.setAttribute("width", makeEm(this.width));
  5910. return node;
  5911. }
  5912. }
  5913. /**
  5914. * Converts the math node into an HTML markup string.
  5915. */
  5916. toMarkup() {
  5917. if (this.character) {
  5918. return "<mtext>" + this.character + "</mtext>";
  5919. } else {
  5920. return "<mspace width=\"" + makeEm(this.width) + "\"/>";
  5921. }
  5922. }
  5923. /**
  5924. * Converts the math node into a string, similar to innerText.
  5925. */
  5926. toText() {
  5927. if (this.character) {
  5928. return this.character;
  5929. } else {
  5930. return " ";
  5931. }
  5932. }
  5933. }
  5934. ;// ./src/buildMathML.ts
  5935. /**
  5936. * This file converts a parse tree into a corresponding MathML tree. The main
  5937. * entry point is the `buildMathML` function, which takes a parse tree from the
  5938. * parser.
  5939. */
  5940. const noVariantSymbols = new Set(["\\imath", "\\jmath"]);
  5941. const rowLikeTypes = new Set(["mrow", "mtable"]);
  5942. /**
  5943. * Takes a symbol and converts it into a MathML text node after performing
  5944. * optional replacement from symbols.js.
  5945. */
  5946. const makeText = function (text, mode, options) {
  5947. if (src_symbols[mode][text] && src_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"))) {
  5948. text = src_symbols[mode][text].replace;
  5949. }
  5950. return new TextNode(text);
  5951. };
  5952. /**
  5953. * Wrap the given array of nodes in an <mrow> node if needed, i.e.,
  5954. * unless the array has length 1. Always returns a single node.
  5955. */
  5956. const makeRow = function (body) {
  5957. if (body.length === 1) {
  5958. return body[0];
  5959. } else {
  5960. return new MathNode("mrow", body);
  5961. }
  5962. };
  5963. /**
  5964. * Returns the math variant as a string or null if none is required.
  5965. */
  5966. const getVariant = function (group, options) {
  5967. // Handle \text... font specifiers as best we can.
  5968. // MathML has a limited list of allowable mathvariant specifiers; see
  5969. // https://www.w3.org/TR/MathML3/chapter3.html#presm.commatt
  5970. if (options.fontFamily === "texttt") {
  5971. return "monospace";
  5972. } else if (options.fontFamily === "textsf") {
  5973. if (options.fontShape === "textit" && options.fontWeight === "textbf") {
  5974. return "sans-serif-bold-italic";
  5975. } else if (options.fontShape === "textit") {
  5976. return "sans-serif-italic";
  5977. } else if (options.fontWeight === "textbf") {
  5978. return "bold-sans-serif";
  5979. } else {
  5980. return "sans-serif";
  5981. }
  5982. } else if (options.fontShape === "textit" && options.fontWeight === "textbf") {
  5983. return "bold-italic";
  5984. } else if (options.fontShape === "textit") {
  5985. return "italic";
  5986. } else if (options.fontWeight === "textbf") {
  5987. return "bold";
  5988. }
  5989. const font = options.font;
  5990. if (!font || font === "mathnormal") {
  5991. return null;
  5992. }
  5993. const mode = group.mode;
  5994. if (font === "mathit") {
  5995. return "italic";
  5996. } else if (font === "boldsymbol") {
  5997. return group.type === "textord" ? "bold" : "bold-italic";
  5998. } else if (font === "mathbf") {
  5999. return "bold";
  6000. } else if (font === "mathbb") {
  6001. return "double-struck";
  6002. } else if (font === "mathsfit") {
  6003. return "sans-serif-italic";
  6004. } else if (font === "mathfrak") {
  6005. return "fraktur";
  6006. } else if (font === "mathscr" || font === "mathcal") {
  6007. // MathML makes no distinction between script and calligraphic
  6008. return "script";
  6009. } else if (font === "mathsf") {
  6010. return "sans-serif";
  6011. } else if (font === "mathtt") {
  6012. return "monospace";
  6013. }
  6014. let text = group.text;
  6015. if (noVariantSymbols.has(text)) {
  6016. return null;
  6017. }
  6018. if (src_symbols[mode][text]) {
  6019. const replacement = src_symbols[mode][text].replace;
  6020. if (replacement) {
  6021. text = replacement;
  6022. }
  6023. }
  6024. const fontName = fontMap[font].fontName;
  6025. if (getCharacterMetrics(text, fontName, mode)) {
  6026. return fontMap[font].variant;
  6027. }
  6028. return null;
  6029. };
  6030. /**
  6031. * Check for <mi>.</mi> which is how a dot renders in MathML,
  6032. * or <mo separator="true" lspace="0em" rspace="0em">,</mo>
  6033. * which is how a braced comma {,} renders in MathML
  6034. */
  6035. function isNumberPunctuation(group) {
  6036. if (!group) {
  6037. return false;
  6038. }
  6039. if (group.type === 'mi' && group.children.length === 1) {
  6040. const child = group.children[0];
  6041. return child instanceof TextNode && child.text === '.';
  6042. } else if (group.type === 'mo' && group.children.length === 1 && group.getAttribute('separator') === 'true' && group.getAttribute('lspace') === '0em' && group.getAttribute('rspace') === '0em') {
  6043. const child = group.children[0];
  6044. return child instanceof TextNode && child.text === ',';
  6045. } else {
  6046. return false;
  6047. }
  6048. }
  6049. /**
  6050. * Takes a list of nodes, builds them, and returns a list of the generated
  6051. * MathML nodes. Also combine consecutive <mtext> outputs into a single
  6052. * <mtext> tag.
  6053. */
  6054. const buildMathML_buildExpression = function (expression, options, isOrdgroup) {
  6055. if (expression.length === 1) {
  6056. const group = buildMathML_buildGroup(expression[0], options);
  6057. if (isOrdgroup && group instanceof MathNode && group.type === "mo") {
  6058. // When TeX writers want to suppress spacing on an operator,
  6059. // they often put the operator by itself inside braces.
  6060. group.setAttribute("lspace", "0em");
  6061. group.setAttribute("rspace", "0em");
  6062. }
  6063. return [group];
  6064. }
  6065. const groups = [];
  6066. let lastGroup;
  6067. for (let i = 0; i < expression.length; i++) {
  6068. const group = buildMathML_buildGroup(expression[i], options);
  6069. if (group instanceof MathNode && lastGroup instanceof MathNode) {
  6070. // Concatenate adjacent <mtext>s
  6071. if (group.type === 'mtext' && lastGroup.type === 'mtext' && group.getAttribute('mathvariant') === lastGroup.getAttribute('mathvariant')) {
  6072. lastGroup.children.push(...group.children);
  6073. continue;
  6074. // Concatenate adjacent <mn>s
  6075. } else if (group.type === 'mn' && lastGroup.type === 'mn') {
  6076. lastGroup.children.push(...group.children);
  6077. continue;
  6078. // Concatenate <mn>...</mn> followed by <mi>.</mi>
  6079. } else if (isNumberPunctuation(group) && lastGroup.type === 'mn') {
  6080. lastGroup.children.push(...group.children);
  6081. continue;
  6082. // Concatenate <mi>.</mi> followed by <mn>...</mn>
  6083. } else if (group.type === 'mn' && isNumberPunctuation(lastGroup)) {
  6084. group.children = [...lastGroup.children, ...group.children];
  6085. groups.pop();
  6086. // Put preceding <mn>...</mn> or <mi>.</mi> inside base of
  6087. // <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
  6088. } else if ((group.type === 'msup' || group.type === 'msub') && group.children.length >= 1 && (lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))) {
  6089. const base = group.children[0];
  6090. if (base instanceof MathNode && base.type === 'mn') {
  6091. base.children = [...lastGroup.children, ...base.children];
  6092. groups.pop();
  6093. }
  6094. // \not
  6095. } else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
  6096. const lastChild = lastGroup.children[0];
  6097. if (lastChild instanceof TextNode && lastChild.text === '\u0338' && (group.type === 'mo' || group.type === 'mi' || group.type === 'mn')) {
  6098. const child = group.children[0];
  6099. if (child instanceof TextNode && child.text.length > 0) {
  6100. // Overlay with combining character long solidus
  6101. child.text = child.text.slice(0, 1) + "\u0338" + child.text.slice(1);
  6102. groups.pop();
  6103. }
  6104. }
  6105. }
  6106. }
  6107. groups.push(group);
  6108. lastGroup = group;
  6109. }
  6110. return groups;
  6111. };
  6112. /**
  6113. * Equivalent to buildExpression, but wraps the elements in an <mrow>
  6114. * if there's more than one. Returns a single node instead of an array.
  6115. */
  6116. const buildExpressionRow = function (expression, options, isOrdgroup) {
  6117. return makeRow(buildMathML_buildExpression(expression, options, isOrdgroup));
  6118. };
  6119. /**
  6120. * Takes a group from the parser and calls the appropriate groupBuilders function
  6121. * on it to produce a MathML node.
  6122. */
  6123. const buildMathML_buildGroup = function (group, options) {
  6124. if (!group) {
  6125. return new MathNode("mrow");
  6126. }
  6127. if (_mathmlGroupBuilders[group.type]) {
  6128. // Call the groupBuilders function
  6129. // TODO(ts)
  6130. const result = _mathmlGroupBuilders[group.type](group, options);
  6131. // TODO(ts)
  6132. return result;
  6133. } else {
  6134. throw new src_ParseError("Got group of unknown type: '" + group.type + "'");
  6135. }
  6136. };
  6137. /**
  6138. * Takes a full parse tree and settings and builds a MathML representation of
  6139. * it. In particular, we put the elements from building the parse tree into a
  6140. * <semantics> tag so we can also include that TeX source as an annotation.
  6141. *
  6142. * Note that we actually return a domTree element with a `<math>` inside it so
  6143. * we can do appropriate styling.
  6144. */
  6145. function buildMathML(tree, texExpression, options, isDisplayMode, forMathmlOnly) {
  6146. const expression = buildMathML_buildExpression(tree, options);
  6147. // TODO: Make a pass thru the MathML similar to buildHTML.traverseNonSpaceNodes
  6148. // and add spacing nodes. This is necessary only adjacent to math operators
  6149. // like \sin or \lim or to subsup elements that contain math operators.
  6150. // MathML takes care of the other spacing issues.
  6151. // Wrap up the expression in an mrow so it is presented in the semantics
  6152. // tag correctly, unless it's a single <mrow> or <mtable>.
  6153. let wrapper;
  6154. if (expression.length === 1 && expression[0] instanceof MathNode && rowLikeTypes.has(expression[0].type)) {
  6155. wrapper = expression[0];
  6156. } else {
  6157. wrapper = new MathNode("mrow", expression);
  6158. }
  6159. // Build a TeX annotation of the source
  6160. const annotation = new MathNode("annotation", [new TextNode(texExpression)]);
  6161. annotation.setAttribute("encoding", "application/x-tex");
  6162. const semantics = new MathNode("semantics", [wrapper, annotation]);
  6163. const math = new MathNode("math", [semantics]);
  6164. math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
  6165. if (isDisplayMode) {
  6166. math.setAttribute("display", "block");
  6167. }
  6168. // You can't style <math> nodes, so we wrap the node in a span.
  6169. // NOTE: The span class is not typed to have <math> nodes as children, and
  6170. // we don't want to make the children type more generic since the children
  6171. // of span are expected to have more fields in `buildHtml` contexts.
  6172. const wrapperClass = forMathmlOnly ? "katex" : "katex-mathml";
  6173. // TODO(ts)
  6174. return makeSpan([wrapperClass], [math]);
  6175. }
  6176. ;// ./src/Options.ts
  6177. /**
  6178. * This file contains information about the options that the Parser carries
  6179. * around with it while parsing. Data is held in an `Options` object, and when
  6180. * recursing, a new `Options` object can be created with the `.with*` and
  6181. * `.reset` functions.
  6182. */
  6183. const sizeStyleMap = [
  6184. // Each element contains [textsize, scriptsize, scriptscriptsize].
  6185. // The size mappings are taken from TeX with \normalsize=10pt.
  6186. [1, 1, 1],
  6187. // size1: [5, 5, 5] \tiny
  6188. [2, 1, 1],
  6189. // size2: [6, 5, 5]
  6190. [3, 1, 1],
  6191. // size3: [7, 5, 5] \scriptsize
  6192. [4, 2, 1],
  6193. // size4: [8, 6, 5] \footnotesize
  6194. [5, 2, 1],
  6195. // size5: [9, 6, 5] \small
  6196. [6, 3, 1],
  6197. // size6: [10, 7, 5] \normalsize
  6198. [7, 4, 2],
  6199. // size7: [12, 8, 6] \large
  6200. [8, 6, 3],
  6201. // size8: [14.4, 10, 7] \Large
  6202. [9, 7, 6],
  6203. // size9: [17.28, 12, 10] \LARGE
  6204. [10, 8, 7],
  6205. // size10: [20.74, 14.4, 12] \huge
  6206. [11, 10, 9] // size11: [24.88, 20.74, 17.28] \HUGE
  6207. ];
  6208. const sizeMultipliers = [
  6209. // fontMetrics.js:getGlobalMetrics also uses size indexes, so if
  6210. // you change size indexes, change that function.
  6211. 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.44, 1.728, 2.074, 2.488];
  6212. const sizeAtStyle = function (size, style) {
  6213. return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
  6214. };
  6215. // In these types, "" (empty string) means "no change".
  6216. /**
  6217. * This is the main options class. It contains the current style, size, color,
  6218. * and font.
  6219. *
  6220. * Options objects should not be modified. To create a new Options with
  6221. * different properties, call a `.having*` method.
  6222. */
  6223. class Options {
  6224. constructor(data) {
  6225. this.style = data.style;
  6226. this.color = data.color;
  6227. this.size = data.size || Options.BASESIZE;
  6228. this.textSize = data.textSize || this.size;
  6229. this.phantom = !!data.phantom;
  6230. this.font = data.font || "";
  6231. this.fontFamily = data.fontFamily || "";
  6232. this.fontWeight = data.fontWeight || '';
  6233. this.fontShape = data.fontShape || '';
  6234. this.sizeMultiplier = sizeMultipliers[this.size - 1];
  6235. this.maxSize = data.maxSize;
  6236. this.minRuleThickness = data.minRuleThickness;
  6237. this._fontMetrics = undefined;
  6238. }
  6239. /**
  6240. * Returns a new options object with the same properties as "this". Properties
  6241. * from "extension" will be copied to the new options object.
  6242. */
  6243. extend(extension) {
  6244. const data = {
  6245. style: this.style,
  6246. size: this.size,
  6247. textSize: this.textSize,
  6248. color: this.color,
  6249. phantom: this.phantom,
  6250. font: this.font,
  6251. fontFamily: this.fontFamily,
  6252. fontWeight: this.fontWeight,
  6253. fontShape: this.fontShape,
  6254. maxSize: this.maxSize,
  6255. minRuleThickness: this.minRuleThickness
  6256. };
  6257. Object.assign(data, extension);
  6258. return new Options(data);
  6259. }
  6260. /**
  6261. * Return an options object with the given style. If `this.style === style`,
  6262. * returns `this`.
  6263. */
  6264. havingStyle(style) {
  6265. if (this.style === style) {
  6266. return this;
  6267. } else {
  6268. return this.extend({
  6269. style: style,
  6270. size: sizeAtStyle(this.textSize, style)
  6271. });
  6272. }
  6273. }
  6274. /**
  6275. * Return an options object with a cramped version of the current style. If
  6276. * the current style is cramped, returns `this`.
  6277. */
  6278. havingCrampedStyle() {
  6279. return this.havingStyle(this.style.cramp());
  6280. }
  6281. /**
  6282. * Return an options object with the given size and in at least `\textstyle`.
  6283. * Returns `this` if appropriate.
  6284. */
  6285. havingSize(size) {
  6286. if (this.size === size && this.textSize === size) {
  6287. return this;
  6288. } else {
  6289. return this.extend({
  6290. style: this.style.text(),
  6291. size: size,
  6292. textSize: size,
  6293. sizeMultiplier: sizeMultipliers[size - 1]
  6294. });
  6295. }
  6296. }
  6297. /**
  6298. * Like `this.havingSize(BASESIZE).havingStyle(style)`. If `style` is omitted,
  6299. * changes to at least `\textstyle`.
  6300. */
  6301. havingBaseStyle(style) {
  6302. style = style || this.style.text();
  6303. const wantSize = sizeAtStyle(Options.BASESIZE, style);
  6304. if (this.size === wantSize && this.textSize === Options.BASESIZE && this.style === style) {
  6305. return this;
  6306. } else {
  6307. return this.extend({
  6308. style: style,
  6309. size: wantSize
  6310. });
  6311. }
  6312. }
  6313. /**
  6314. * Remove the effect of sizing changes such as \Huge.
  6315. * Keep the effect of the current style, such as \scriptstyle.
  6316. */
  6317. havingBaseSizing() {
  6318. let size;
  6319. switch (this.style.id) {
  6320. case 4:
  6321. case 5:
  6322. size = 3; // normalsize in scriptstyle
  6323. break;
  6324. case 6:
  6325. case 7:
  6326. size = 1; // normalsize in scriptscriptstyle
  6327. break;
  6328. default:
  6329. size = 6;
  6330. // normalsize in textstyle or displaystyle
  6331. }
  6332. return this.extend({
  6333. style: this.style.text(),
  6334. size: size
  6335. });
  6336. }
  6337. /**
  6338. * Create a new options object with the given color.
  6339. */
  6340. withColor(color) {
  6341. return this.extend({
  6342. color: color
  6343. });
  6344. }
  6345. /**
  6346. * Create a new options object with "phantom" set to true.
  6347. */
  6348. withPhantom() {
  6349. return this.extend({
  6350. phantom: true
  6351. });
  6352. }
  6353. /**
  6354. * Creates a new options object with the given math font or old text font.
  6355. * @type {[type]}
  6356. */
  6357. withFont(font) {
  6358. return this.extend({
  6359. font
  6360. });
  6361. }
  6362. /**
  6363. * Create a new options objects with the given fontFamily.
  6364. */
  6365. withTextFontFamily(fontFamily) {
  6366. return this.extend({
  6367. fontFamily,
  6368. font: ""
  6369. });
  6370. }
  6371. /**
  6372. * Creates a new options object with the given font weight
  6373. */
  6374. withTextFontWeight(fontWeight) {
  6375. return this.extend({
  6376. fontWeight,
  6377. font: ""
  6378. });
  6379. }
  6380. /**
  6381. * Creates a new options object with the given font weight
  6382. */
  6383. withTextFontShape(fontShape) {
  6384. return this.extend({
  6385. fontShape,
  6386. font: ""
  6387. });
  6388. }
  6389. /**
  6390. * Return the CSS sizing classes required to switch from enclosing options
  6391. * `oldOptions` to `this`. Returns an array of classes.
  6392. */
  6393. sizingClasses(oldOptions) {
  6394. if (oldOptions.size !== this.size) {
  6395. return ["sizing", "reset-size" + oldOptions.size, "size" + this.size];
  6396. } else {
  6397. return [];
  6398. }
  6399. }
  6400. /**
  6401. * Return the CSS sizing classes required to switch to the base size. Like
  6402. * `this.havingSize(BASESIZE).sizingClasses(this)`.
  6403. */
  6404. baseSizingClasses() {
  6405. if (this.size !== Options.BASESIZE) {
  6406. return ["sizing", "reset-size" + this.size, "size" + Options.BASESIZE];
  6407. } else {
  6408. return [];
  6409. }
  6410. }
  6411. /**
  6412. * Return the font metrics for this size.
  6413. */
  6414. fontMetrics() {
  6415. if (!this._fontMetrics) {
  6416. this._fontMetrics = getGlobalMetrics(this.size);
  6417. }
  6418. return this._fontMetrics;
  6419. }
  6420. /**
  6421. * Gets the CSS color of the current options object
  6422. */
  6423. getColor() {
  6424. if (this.phantom) {
  6425. return "transparent";
  6426. } else {
  6427. return this.color;
  6428. }
  6429. }
  6430. }
  6431. // A font family applies to a group of fonts (i.e. SansSerif), while a font
  6432. // represents a specific font (i.e. SansSerif Bold).
  6433. // See: https://tex.stackexchange.com/questions/22350/difference-between-textrm-and-mathrm
  6434. /**
  6435. * The base size index.
  6436. */
  6437. Options.BASESIZE = 6;
  6438. /* harmony default export */ var src_Options = (Options);
  6439. ;// ./src/buildTree.ts
  6440. const optionsFromSettings = function (settings) {
  6441. return new src_Options({
  6442. style: settings.displayMode ? src_Style.DISPLAY : src_Style.TEXT,
  6443. maxSize: settings.maxSize,
  6444. minRuleThickness: settings.minRuleThickness
  6445. });
  6446. };
  6447. const displayWrap = function (node, settings) {
  6448. if (settings.displayMode) {
  6449. const classes = ["katex-display"];
  6450. if (settings.leqno) {
  6451. classes.push("leqno");
  6452. }
  6453. if (settings.fleqn) {
  6454. classes.push("fleqn");
  6455. }
  6456. node = makeSpan(classes, [node]);
  6457. }
  6458. return node;
  6459. };
  6460. const buildTree = function (tree, expression, settings) {
  6461. const options = optionsFromSettings(settings);
  6462. let katexNode;
  6463. if (settings.output === "mathml") {
  6464. return buildMathML(tree, expression, options, settings.displayMode, true);
  6465. } else if (settings.output === "html") {
  6466. const htmlNode = buildHTML(tree, options);
  6467. katexNode = makeSpan(["katex"], [htmlNode]);
  6468. } else {
  6469. const mathMLNode = buildMathML(tree, expression, options, settings.displayMode, false);
  6470. const htmlNode = buildHTML(tree, options);
  6471. katexNode = makeSpan(["katex"], [mathMLNode, htmlNode]);
  6472. }
  6473. return displayWrap(katexNode, settings);
  6474. };
  6475. const buildHTMLTree = function (tree, expression, settings) {
  6476. const options = optionsFromSettings(settings);
  6477. const htmlNode = buildHTML(tree, options);
  6478. const katexNode = makeSpan(["katex"], [htmlNode]);
  6479. return displayWrap(katexNode, settings);
  6480. };
  6481. /* harmony default export */ var src_buildTree = ((/* unused pure expression or super */ null && (buildTree)));
  6482. ;// ./src/stretchy.ts
  6483. /**
  6484. * This file provides support to buildMathML.js and buildHTML.js
  6485. * for stretchy wide elements rendered from SVG files
  6486. * and other CSS trickery.
  6487. */
  6488. const stretchyCodePoint = {
  6489. widehat: "^",
  6490. widecheck: "ˇ",
  6491. widetilde: "~",
  6492. utilde: "~",
  6493. overleftarrow: "\u2190",
  6494. underleftarrow: "\u2190",
  6495. xleftarrow: "\u2190",
  6496. overrightarrow: "\u2192",
  6497. underrightarrow: "\u2192",
  6498. xrightarrow: "\u2192",
  6499. underbrace: "\u23df",
  6500. overbrace: "\u23de",
  6501. underbracket: "\u23b5",
  6502. overbracket: "\u23b4",
  6503. overgroup: "\u23e0",
  6504. undergroup: "\u23e1",
  6505. overleftrightarrow: "\u2194",
  6506. underleftrightarrow: "\u2194",
  6507. xleftrightarrow: "\u2194",
  6508. Overrightarrow: "\u21d2",
  6509. xRightarrow: "\u21d2",
  6510. overleftharpoon: "\u21bc",
  6511. xleftharpoonup: "\u21bc",
  6512. overrightharpoon: "\u21c0",
  6513. xrightharpoonup: "\u21c0",
  6514. xLeftarrow: "\u21d0",
  6515. xLeftrightarrow: "\u21d4",
  6516. xhookleftarrow: "\u21a9",
  6517. xhookrightarrow: "\u21aa",
  6518. xmapsto: "\u21a6",
  6519. xrightharpoondown: "\u21c1",
  6520. xleftharpoondown: "\u21bd",
  6521. xrightleftharpoons: "\u21cc",
  6522. xleftrightharpoons: "\u21cb",
  6523. xtwoheadleftarrow: "\u219e",
  6524. xtwoheadrightarrow: "\u21a0",
  6525. xlongequal: "=",
  6526. xtofrom: "\u21c4",
  6527. xrightleftarrows: "\u21c4",
  6528. xrightequilibrium: "\u21cc",
  6529. // Not a perfect match.
  6530. xleftequilibrium: "\u21cb",
  6531. // None better available.
  6532. "\\cdrightarrow": "\u2192",
  6533. "\\cdleftarrow": "\u2190",
  6534. "\\cdlongequal": "="
  6535. };
  6536. const stretchyMathML = function (label) {
  6537. const node = new MathNode("mo", [new TextNode(stretchyCodePoint[label.replace(/^\\/, '')])]);
  6538. node.setAttribute("stretchy", "true");
  6539. return node;
  6540. };
  6541. // Many of the KaTeX SVG images have been adapted from glyphs in KaTeX fonts.
  6542. // Copyright (c) 2009-2010, Design Science, Inc. (<www.mathjax.org>)
  6543. // Copyright (c) 2014-2017 Khan Academy (<www.khanacademy.org>)
  6544. // Licensed under the SIL Open Font License, Version 1.1.
  6545. // See \nhttp://scripts.sil.org/OFL
  6546. // Very Long SVGs
  6547. // Many of the KaTeX stretchy wide elements use a long SVG image and an
  6548. // overflow: hidden tactic to achieve a stretchy image while avoiding
  6549. // distortion of arrowheads or brace corners.
  6550. // The SVG typically contains a very long (400 em) arrow.
  6551. // The SVG is in a container span that has overflow: hidden, so the span
  6552. // acts like a window that exposes only part of the SVG.
  6553. // The SVG always has a longer, thinner aspect ratio than the container span.
  6554. // After the SVG fills 100% of the height of the container span,
  6555. // there is a long arrow shaft left over. That left-over shaft is not shown.
  6556. // Instead, it is sliced off because the span's CSS has overflow: hidden.
  6557. // Thus, the reader sees an arrow that matches the subject matter width
  6558. // without distortion.
  6559. // Some functions, such as \cancel, need to vary their aspect ratio. These
  6560. // functions do not get the overflow SVG treatment.
  6561. // Second Brush Stroke
  6562. // Low resolution monitors struggle to display images in fine detail.
  6563. // So browsers apply anti-aliasing. A long straight arrow shaft therefore
  6564. // will sometimes appear as if it has a blurred edge.
  6565. // To mitigate this, these SVG files contain a second "brush-stroke" on the
  6566. // arrow shafts. That is, a second long thin rectangular SVG path has been
  6567. // written directly on top of each arrow shaft. This reinforcement causes
  6568. // some of the screen pixels to display as black instead of the anti-aliased
  6569. // gray pixel that a single path would generate. So we get arrow shafts
  6570. // whose edges appear to be sharper.
  6571. // In the katexImagesData object just below, the dimensions all
  6572. // correspond to path geometry inside the relevant SVG.
  6573. // For example, \overrightarrow uses the same arrowhead as glyph U+2192
  6574. // from the KaTeX Main font. The scaling factor is 1000.
  6575. // That is, inside the font, that arrowhead is 522 units tall, which
  6576. // corresponds to 0.522 em inside the document.
  6577. const katexImagesData = {
  6578. // path(s), minWidth, height, align
  6579. overrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
  6580. overleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
  6581. underrightarrow: [["rightarrow"], 0.888, 522, "xMaxYMin"],
  6582. underleftarrow: [["leftarrow"], 0.888, 522, "xMinYMin"],
  6583. xrightarrow: [["rightarrow"], 1.469, 522, "xMaxYMin"],
  6584. "\\cdrightarrow": [["rightarrow"], 3.0, 522, "xMaxYMin"],
  6585. // CD minwwidth2.5pc
  6586. xleftarrow: [["leftarrow"], 1.469, 522, "xMinYMin"],
  6587. "\\cdleftarrow": [["leftarrow"], 3.0, 522, "xMinYMin"],
  6588. Overrightarrow: [["doublerightarrow"], 0.888, 560, "xMaxYMin"],
  6589. xRightarrow: [["doublerightarrow"], 1.526, 560, "xMaxYMin"],
  6590. xLeftarrow: [["doubleleftarrow"], 1.526, 560, "xMinYMin"],
  6591. overleftharpoon: [["leftharpoon"], 0.888, 522, "xMinYMin"],
  6592. xleftharpoonup: [["leftharpoon"], 0.888, 522, "xMinYMin"],
  6593. xleftharpoondown: [["leftharpoondown"], 0.888, 522, "xMinYMin"],
  6594. overrightharpoon: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
  6595. xrightharpoonup: [["rightharpoon"], 0.888, 522, "xMaxYMin"],
  6596. xrightharpoondown: [["rightharpoondown"], 0.888, 522, "xMaxYMin"],
  6597. xlongequal: [["longequal"], 0.888, 334, "xMinYMin"],
  6598. "\\cdlongequal": [["longequal"], 3.0, 334, "xMinYMin"],
  6599. xtwoheadleftarrow: [["twoheadleftarrow"], 0.888, 334, "xMinYMin"],
  6600. xtwoheadrightarrow: [["twoheadrightarrow"], 0.888, 334, "xMaxYMin"],
  6601. overleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
  6602. overbrace: [["leftbrace", "midbrace", "rightbrace"], 1.6, 548],
  6603. underbrace: [["leftbraceunder", "midbraceunder", "rightbraceunder"], 1.6, 548],
  6604. underleftrightarrow: [["leftarrow", "rightarrow"], 0.888, 522],
  6605. xleftrightarrow: [["leftarrow", "rightarrow"], 1.75, 522],
  6606. xLeftrightarrow: [["doubleleftarrow", "doublerightarrow"], 1.75, 560],
  6607. xrightleftharpoons: [["leftharpoondownplus", "rightharpoonplus"], 1.75, 716],
  6608. xleftrightharpoons: [["leftharpoonplus", "rightharpoondownplus"], 1.75, 716],
  6609. xhookleftarrow: [["leftarrow", "righthook"], 1.08, 522],
  6610. xhookrightarrow: [["lefthook", "rightarrow"], 1.08, 522],
  6611. overlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
  6612. underlinesegment: [["leftlinesegment", "rightlinesegment"], 0.888, 522],
  6613. overbracket: [["leftbracketover", "rightbracketover"], 1.6, 440],
  6614. underbracket: [["leftbracketunder", "rightbracketunder"], 1.6, 410],
  6615. overgroup: [["leftgroup", "rightgroup"], 0.888, 342],
  6616. undergroup: [["leftgroupunder", "rightgroupunder"], 0.888, 342],
  6617. xmapsto: [["leftmapsto", "rightarrow"], 1.5, 522],
  6618. xtofrom: [["leftToFrom", "rightToFrom"], 1.75, 528],
  6619. // The next three arrows are from the mhchem package.
  6620. // In mhchem.sty, min-length is 2.0em. But these arrows might appear in the
  6621. // document as \xrightarrow or \xrightleftharpoons. Those have
  6622. // min-length = 1.75em, so we set min-length on these next three to match.
  6623. xrightleftarrows: [["baraboveleftarrow", "rightarrowabovebar"], 1.75, 901],
  6624. xrightequilibrium: [["baraboveshortleftharpoon", "rightharpoonaboveshortbar"], 1.75, 716],
  6625. xleftequilibrium: [["shortbaraboveleftharpoon", "shortrightharpoonabovebar"], 1.75, 716]
  6626. };
  6627. const wideAccentLabels = new Set(["widehat", "widecheck", "widetilde", "utilde"]);
  6628. const stretchySvg = function (group, options) {
  6629. // Create a span with inline SVG for the element.
  6630. function buildSvgSpan_() {
  6631. let viewBoxWidth = 400000; // default
  6632. const label = group.label.slice(1);
  6633. if (wideAccentLabels.has(label)) {
  6634. // Each type in the `if` statement corresponds to one of the ParseNode
  6635. // types below. This narrowing is required to access `grp.base`.
  6636. // TODO(ts)
  6637. const grp = group;
  6638. // There are four SVG images available for each function.
  6639. // Choose a taller image when there are more characters.
  6640. const numChars = grp.base.type === "ordgroup" ? grp.base.body.length : 1;
  6641. let viewBoxHeight;
  6642. let pathName;
  6643. let height;
  6644. if (numChars > 5) {
  6645. if (label === "widehat" || label === "widecheck") {
  6646. viewBoxHeight = 420;
  6647. viewBoxWidth = 2364;
  6648. height = 0.42;
  6649. pathName = label + "4";
  6650. } else {
  6651. viewBoxHeight = 312;
  6652. viewBoxWidth = 2340;
  6653. height = 0.34;
  6654. pathName = "tilde4";
  6655. }
  6656. } else {
  6657. const imgIndex = [1, 1, 2, 2, 3, 3][numChars];
  6658. if (label === "widehat" || label === "widecheck") {
  6659. viewBoxWidth = [0, 1062, 2364, 2364, 2364][imgIndex];
  6660. viewBoxHeight = [0, 239, 300, 360, 420][imgIndex];
  6661. height = [0, 0.24, 0.3, 0.3, 0.36, 0.42][imgIndex];
  6662. pathName = label + imgIndex;
  6663. } else {
  6664. viewBoxWidth = [0, 600, 1033, 2339, 2340][imgIndex];
  6665. viewBoxHeight = [0, 260, 286, 306, 312][imgIndex];
  6666. height = [0, 0.26, 0.286, 0.3, 0.306, 0.34][imgIndex];
  6667. pathName = "tilde" + imgIndex;
  6668. }
  6669. }
  6670. const path = new PathNode(pathName);
  6671. const svgNode = new SvgNode([path], {
  6672. "width": "100%",
  6673. "height": makeEm(height),
  6674. "viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight,
  6675. "preserveAspectRatio": "none"
  6676. });
  6677. return {
  6678. span: makeSvgSpan([], [svgNode], options),
  6679. minWidth: 0,
  6680. height
  6681. };
  6682. } else {
  6683. const spans = [];
  6684. const data = katexImagesData[label];
  6685. const [paths, minWidth, viewBoxHeight] = data;
  6686. const height = viewBoxHeight / 1000;
  6687. const numSvgChildren = paths.length;
  6688. let widthClasses;
  6689. let aligns;
  6690. if (numSvgChildren === 1) {
  6691. // TODO(ts): All these cases must be of the 4-tuple type.
  6692. const align1 = data[3];
  6693. widthClasses = ["hide-tail"];
  6694. aligns = [align1];
  6695. } else if (numSvgChildren === 2) {
  6696. widthClasses = ["halfarrow-left", "halfarrow-right"];
  6697. aligns = ["xMinYMin", "xMaxYMin"];
  6698. } else if (numSvgChildren === 3) {
  6699. widthClasses = ["brace-left", "brace-center", "brace-right"];
  6700. aligns = ["xMinYMin", "xMidYMin", "xMaxYMin"];
  6701. } else {
  6702. throw new Error("Correct katexImagesData or update code here to support\n " + numSvgChildren + " children.");
  6703. }
  6704. for (let i = 0; i < numSvgChildren; i++) {
  6705. const path = new PathNode(paths[i]);
  6706. const svgNode = new SvgNode([path], {
  6707. "width": "400em",
  6708. "height": makeEm(height),
  6709. "viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight,
  6710. "preserveAspectRatio": aligns[i] + " slice"
  6711. });
  6712. const span = makeSvgSpan([widthClasses[i]], [svgNode], options);
  6713. if (numSvgChildren === 1) {
  6714. return {
  6715. span,
  6716. minWidth,
  6717. height
  6718. };
  6719. } else {
  6720. span.style.height = makeEm(height);
  6721. spans.push(span);
  6722. }
  6723. }
  6724. return {
  6725. span: makeSpan(["stretchy"], spans, options),
  6726. minWidth,
  6727. height
  6728. };
  6729. }
  6730. } // buildSvgSpan_()
  6731. const {
  6732. span,
  6733. minWidth,
  6734. height
  6735. } = buildSvgSpan_();
  6736. // Note that we are returning span.depth = 0.
  6737. // Any adjustments relative to the baseline must be done in buildHTML.
  6738. span.height = height;
  6739. span.style.height = makeEm(height);
  6740. if (minWidth > 0) {
  6741. span.style.minWidth = makeEm(minWidth);
  6742. }
  6743. return span;
  6744. };
  6745. const stretchyEnclose = function (inner, label, topPad, bottomPad, options) {
  6746. // Return an image span for \cancel, \bcancel, \xcancel, \fbox, or \angl
  6747. let img;
  6748. const totalHeight = inner.height + inner.depth + topPad + bottomPad;
  6749. if (/fbox|color|angl/.test(label)) {
  6750. img = makeSpan(["stretchy", label], [], options);
  6751. if (label === "fbox") {
  6752. const color = options.color && options.getColor();
  6753. if (color) {
  6754. img.style.borderColor = color;
  6755. }
  6756. }
  6757. } else {
  6758. // \cancel, \bcancel, or \xcancel
  6759. // Since \cancel's SVG is inline and it omits the viewBox attribute,
  6760. // its stroke-width will not vary with span area.
  6761. const lines = [];
  6762. if (/^[bx]cancel$/.test(label)) {
  6763. lines.push(new LineNode({
  6764. "x1": "0",
  6765. "y1": "0",
  6766. "x2": "100%",
  6767. "y2": "100%",
  6768. "stroke-width": "0.046em"
  6769. }));
  6770. }
  6771. if (/^x?cancel$/.test(label)) {
  6772. lines.push(new LineNode({
  6773. "x1": "0",
  6774. "y1": "100%",
  6775. "x2": "100%",
  6776. "y2": "0",
  6777. "stroke-width": "0.046em"
  6778. }));
  6779. }
  6780. const svgNode = new SvgNode(lines, {
  6781. "width": "100%",
  6782. "height": makeEm(totalHeight)
  6783. });
  6784. img = makeSvgSpan([], [svgNode], options);
  6785. }
  6786. img.height = totalHeight;
  6787. img.style.height = makeEm(totalHeight);
  6788. return img;
  6789. };
  6790. ;// ./src/parseNode.ts
  6791. // ParseNode's corresponding to Symbol `Group`s in symbols.js.
  6792. // ParseNode from `Parser.formatUnsupportedCmd`
  6793. // Union of all possible `ParseNode<>` types.
  6794. // Map from `NodeType` to the corresponding `ParseNode`.
  6795. /**
  6796. * Asserts that the node is of the given type and returns it with stricter
  6797. * typing. Throws if the node's type does not match.
  6798. */
  6799. function assertNodeType(node, type) {
  6800. if (!node || node.type !== type) {
  6801. throw new Error("Expected node of type " + type + ", but got " + (node ? "node of type " + node.type : String(node)));
  6802. }
  6803. return node;
  6804. }
  6805. /**
  6806. * Returns the node more strictly typed iff it is of the given type. Otherwise,
  6807. * returns null.
  6808. */
  6809. function assertSymbolNodeType(node) {
  6810. const typedNode = checkSymbolNodeType(node);
  6811. if (!typedNode) {
  6812. throw new Error("Expected node of symbol group type, but got " + (node ? "node of type " + node.type : String(node)));
  6813. }
  6814. return typedNode;
  6815. }
  6816. /**
  6817. * Returns the node more strictly typed iff it is of the given type. Otherwise,
  6818. * returns null.
  6819. */
  6820. function checkSymbolNodeType(node) {
  6821. if (node && (node.type === "atom" || NON_ATOMS.hasOwnProperty(node.type))) {
  6822. return node;
  6823. }
  6824. return null;
  6825. }
  6826. ;// ./src/functions/accent.ts
  6827. const getBaseSymbol = group => {
  6828. if (group instanceof SymbolNode) {
  6829. return group;
  6830. }
  6831. if (hasHtmlDomChildren(group) && group.children.length === 1) {
  6832. return getBaseSymbol(group.children[0]);
  6833. }
  6834. };
  6835. // NOTE: Unlike most `htmlBuilder`s, this one handles not only "accent", but
  6836. // also "supsub" since an accent can affect super/subscripting.
  6837. const htmlBuilder = (grp, options) => {
  6838. // Accents are handled in the TeXbook pg. 443, rule 12.
  6839. let base;
  6840. let group;
  6841. let supSubGroup;
  6842. if (grp && grp.type === "supsub") {
  6843. // If our base is a character box, and we have superscripts and
  6844. // subscripts, the supsub will defer to us. In particular, we want
  6845. // to attach the superscripts and subscripts to the inner body (so
  6846. // that the position of the superscripts and subscripts won't be
  6847. // affected by the height of the accent). We accomplish this by
  6848. // sticking the base of the accent into the base of the supsub, and
  6849. // rendering that, while keeping track of where the accent is.
  6850. // The real accent group is the base of the supsub group
  6851. group = assertNodeType(grp.base, "accent");
  6852. // The character box is the base of the accent group
  6853. base = group.base;
  6854. // Stick the character box into the base of the supsub group
  6855. grp.base = base;
  6856. // Rerender the supsub group with its new base, and store that
  6857. // result.
  6858. supSubGroup = assertSpan(buildGroup(grp, options));
  6859. // reset original base
  6860. grp.base = group;
  6861. } else {
  6862. group = assertNodeType(grp, "accent");
  6863. base = group.base;
  6864. }
  6865. // Build the base group
  6866. const body = buildGroup(base, options.havingCrampedStyle());
  6867. // Does the accent need to shift for the skew of a character?
  6868. const mustShift = group.isShifty && isCharacterBox(base);
  6869. // Calculate the skew of the accent. This is based on the line "If the
  6870. // nucleus is not a single character, let s = 0; otherwise set s to the
  6871. // kern amount for the nucleus followed by the \skewchar of its font."
  6872. // Note that our skew metrics are just the kern between each character
  6873. // and the skewchar.
  6874. let skew = 0;
  6875. if (mustShift) {
  6876. var _getBaseSymbol$skew, _getBaseSymbol;
  6877. // Read the skew from the rendered base symbol.
  6878. // This preserves font metrics from font wrappers like \mathbb.
  6879. skew = (_getBaseSymbol$skew = (_getBaseSymbol = getBaseSymbol(body)) == null ? void 0 : _getBaseSymbol.skew) != null ? _getBaseSymbol$skew : 0;
  6880. }
  6881. const accentBelow = group.label === "\\c";
  6882. // calculate the amount of space between the body and the accent
  6883. let clearance = accentBelow ? body.height + body.depth : Math.min(body.height, options.fontMetrics().xHeight);
  6884. // Build the accent
  6885. let accentBody;
  6886. if (!group.isStretchy) {
  6887. let accent;
  6888. let width;
  6889. if (group.label === "\\vec") {
  6890. // Before version 0.9, \vec used the combining font glyph U+20D7.
  6891. // But browsers, especially Safari, are not consistent in how they
  6892. // render combining characters when not preceded by a character.
  6893. // So now we use an SVG.
  6894. // If Safari reforms, we should consider reverting to the glyph.
  6895. accent = staticSvg("vec", options);
  6896. width = svgData.vec[1];
  6897. } else {
  6898. accent = makeOrd({
  6899. type: "textord",
  6900. mode: group.mode,
  6901. text: group.label
  6902. }, options, "textord");
  6903. accent = assertSymbolDomNode(accent);
  6904. // Remove the italic correction of the accent, because it only serves to
  6905. // shift the accent over to a place we don't want.
  6906. accent.italic = 0;
  6907. width = accent.width;
  6908. if (accentBelow) {
  6909. clearance += accent.depth;
  6910. }
  6911. }
  6912. accentBody = makeSpan(["accent-body"], [accent]);
  6913. // "Full" accents expand the width of the resulting symbol to be
  6914. // at least the width of the accent, and overlap directly onto the
  6915. // character without any vertical offset.
  6916. const accentFull = group.label === "\\textcircled";
  6917. if (accentFull) {
  6918. accentBody.classes.push('accent-full');
  6919. clearance = body.height;
  6920. }
  6921. // Shift the accent over by the skew.
  6922. let left = skew;
  6923. // CSS defines `.katex .accent .accent-body:not(.accent-full) { width: 0 }`
  6924. // so that the accent doesn't contribute to the bounding box.
  6925. // We need to shift the character by its width (effectively half
  6926. // its width) to compensate.
  6927. if (!accentFull) {
  6928. left -= width / 2;
  6929. }
  6930. accentBody.style.left = makeEm(left);
  6931. // \textcircled uses the \bigcirc glyph, so it needs some
  6932. // vertical adjustment to match LaTeX.
  6933. if (group.label === "\\textcircled") {
  6934. accentBody.style.top = ".2em";
  6935. }
  6936. accentBody = makeVList({
  6937. positionType: "firstBaseline",
  6938. children: [{
  6939. type: "elem",
  6940. elem: body
  6941. }, {
  6942. type: "kern",
  6943. size: -clearance
  6944. }, {
  6945. type: "elem",
  6946. elem: accentBody
  6947. }]
  6948. }, options);
  6949. } else {
  6950. accentBody = stretchySvg(group, options);
  6951. accentBody = makeVList({
  6952. positionType: "firstBaseline",
  6953. children: [{
  6954. type: "elem",
  6955. elem: body
  6956. }, {
  6957. type: "elem",
  6958. elem: accentBody,
  6959. wrapperClasses: ["svg-align"],
  6960. wrapperStyle: skew > 0 ? {
  6961. width: "calc(100% - " + makeEm(2 * skew) + ")",
  6962. marginLeft: makeEm(2 * skew)
  6963. } : undefined
  6964. }]
  6965. }, options);
  6966. }
  6967. const accentWrap = makeSpan(["mord", "accent"], [accentBody], options);
  6968. if (supSubGroup) {
  6969. // Here, we replace the "base" child of the supsub with our newly
  6970. // generated accent.
  6971. supSubGroup.children[0] = accentWrap;
  6972. // Since we don't rerun the height calculation after replacing the
  6973. // accent, we manually recalculate height.
  6974. supSubGroup.height = Math.max(accentWrap.height, supSubGroup.height);
  6975. // Accents should always be ords, even when their innards are not.
  6976. supSubGroup.classes[0] = "mord";
  6977. return supSubGroup;
  6978. } else {
  6979. return accentWrap;
  6980. }
  6981. };
  6982. const mathmlBuilder = (group, options) => {
  6983. const accentNode = group.isStretchy ? stretchyMathML(group.label) : new MathNode("mo", [makeText(group.label, group.mode)]);
  6984. const node = new MathNode("mover", [buildMathML_buildGroup(group.base, options), accentNode]);
  6985. node.setAttribute("accent", "true");
  6986. return node;
  6987. };
  6988. const NON_STRETCHY_ACCENT_REGEX = new RegExp(["\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve", "\\check", "\\hat", "\\vec", "\\dot", "\\mathring"].map(accent => "\\" + accent).join("|"));
  6989. // Accents
  6990. defineFunction({
  6991. type: "accent",
  6992. names: ["\\acute", "\\grave", "\\ddot", "\\tilde", "\\bar", "\\breve", "\\check", "\\hat", "\\vec", "\\dot", "\\mathring", "\\widecheck", "\\widehat", "\\widetilde", "\\overrightarrow", "\\overleftarrow", "\\Overrightarrow", "\\overleftrightarrow", "\\overgroup", "\\overlinesegment", "\\overleftharpoon", "\\overrightharpoon"],
  6993. props: {
  6994. numArgs: 1
  6995. },
  6996. handler: (context, args) => {
  6997. const base = normalizeArgument(args[0]);
  6998. const isStretchy = !NON_STRETCHY_ACCENT_REGEX.test(context.funcName);
  6999. const isShifty = !isStretchy || context.funcName === "\\widehat" || context.funcName === "\\widetilde" || context.funcName === "\\widecheck";
  7000. return {
  7001. type: "accent",
  7002. mode: context.parser.mode,
  7003. label: context.funcName,
  7004. isStretchy: isStretchy,
  7005. isShifty: isShifty,
  7006. base: base
  7007. };
  7008. },
  7009. htmlBuilder,
  7010. mathmlBuilder
  7011. });
  7012. // Text-mode accents
  7013. defineFunction({
  7014. type: "accent",
  7015. names: ["\\'", "\\`", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"', "\\c", "\\r", "\\H", "\\v", "\\textcircled"],
  7016. props: {
  7017. numArgs: 1,
  7018. allowedInText: true,
  7019. allowedInMath: true,
  7020. // unless in strict mode
  7021. argTypes: ["primitive"]
  7022. },
  7023. handler: (context, args) => {
  7024. const base = args[0];
  7025. let mode = context.parser.mode;
  7026. if (mode === "math") {
  7027. context.parser.settings.reportNonstrict("mathVsTextAccents", "LaTeX's accent " + context.funcName + " works only in text mode");
  7028. mode = "text";
  7029. }
  7030. return {
  7031. type: "accent",
  7032. mode: mode,
  7033. label: context.funcName,
  7034. isStretchy: false,
  7035. isShifty: true,
  7036. base: base
  7037. };
  7038. },
  7039. htmlBuilder,
  7040. mathmlBuilder
  7041. });
  7042. ;// ./src/functions/accentunder.ts
  7043. // Horizontal overlap functions
  7044. defineFunction({
  7045. type: "accentUnder",
  7046. names: ["\\underleftarrow", "\\underrightarrow", "\\underleftrightarrow", "\\undergroup", "\\underlinesegment", "\\utilde"],
  7047. props: {
  7048. numArgs: 1
  7049. },
  7050. handler: (_ref, args) => {
  7051. let {
  7052. parser,
  7053. funcName
  7054. } = _ref;
  7055. const base = args[0];
  7056. return {
  7057. type: "accentUnder",
  7058. mode: parser.mode,
  7059. label: funcName,
  7060. base: base
  7061. };
  7062. },
  7063. htmlBuilder: (group, options) => {
  7064. // Treat under accents much like underlines.
  7065. const innerGroup = buildGroup(group.base, options);
  7066. const accentBody = stretchySvg(group, options);
  7067. const kern = group.label === "\\utilde" ? 0.12 : 0;
  7068. // Generate the vlist, with the appropriate kerns
  7069. const vlist = makeVList({
  7070. positionType: "top",
  7071. positionData: innerGroup.height,
  7072. children: [{
  7073. type: "elem",
  7074. elem: accentBody,
  7075. wrapperClasses: ["svg-align"]
  7076. }, {
  7077. type: "kern",
  7078. size: kern
  7079. }, {
  7080. type: "elem",
  7081. elem: innerGroup
  7082. }]
  7083. }, options);
  7084. return makeSpan(["mord", "accentunder"], [vlist], options);
  7085. },
  7086. mathmlBuilder: (group, options) => {
  7087. const accentNode = stretchyMathML(group.label);
  7088. const node = new MathNode("munder", [buildMathML_buildGroup(group.base, options), accentNode]);
  7089. node.setAttribute("accentunder", "true");
  7090. return node;
  7091. }
  7092. });
  7093. ;// ./src/functions/arrow.ts
  7094. // Helper function
  7095. const paddedNode = group => {
  7096. const node = new MathNode("mpadded", group ? [group] : []);
  7097. node.setAttribute("width", "+0.6em");
  7098. node.setAttribute("lspace", "0.3em");
  7099. return node;
  7100. };
  7101. // Stretchy arrows with an optional argument
  7102. defineFunction({
  7103. type: "xArrow",
  7104. names: ["\\xleftarrow", "\\xrightarrow", "\\xLeftarrow", "\\xRightarrow", "\\xleftrightarrow", "\\xLeftrightarrow", "\\xhookleftarrow", "\\xhookrightarrow", "\\xmapsto", "\\xrightharpoondown", "\\xrightharpoonup", "\\xleftharpoondown", "\\xleftharpoonup", "\\xrightleftharpoons", "\\xleftrightharpoons", "\\xlongequal", "\\xtwoheadrightarrow", "\\xtwoheadleftarrow", "\\xtofrom",
  7105. // The next 3 functions are here to support the mhchem extension.
  7106. // Direct use of these functions is discouraged and may break someday.
  7107. "\\xrightleftarrows", "\\xrightequilibrium", "\\xleftequilibrium",
  7108. // The next 3 functions are here only to support the {CD} environment.
  7109. "\\\\cdrightarrow", "\\\\cdleftarrow", "\\\\cdlongequal"],
  7110. props: {
  7111. numArgs: 1,
  7112. numOptionalArgs: 1
  7113. },
  7114. handler(_ref, args, optArgs) {
  7115. let {
  7116. parser,
  7117. funcName
  7118. } = _ref;
  7119. return {
  7120. type: "xArrow",
  7121. mode: parser.mode,
  7122. label: funcName,
  7123. body: args[0],
  7124. below: optArgs[0]
  7125. };
  7126. },
  7127. htmlBuilder(group, options) {
  7128. const style = options.style;
  7129. // Build the argument groups in the appropriate style.
  7130. // Ref: amsmath.dtx: \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
  7131. // Some groups can return document fragments. Handle those by wrapping
  7132. // them in a span.
  7133. let newOptions = options.havingStyle(style.sup());
  7134. const upperGroup = wrapFragment(buildGroup(group.body, newOptions, options), options);
  7135. const arrowPrefix = group.label.slice(0, 2) === "\\x" ? "x" : "cd";
  7136. upperGroup.classes.push(arrowPrefix + "-arrow-pad");
  7137. let lowerGroup;
  7138. if (group.below) {
  7139. // Build the lower group
  7140. newOptions = options.havingStyle(style.sub());
  7141. lowerGroup = wrapFragment(buildGroup(group.below, newOptions, options), options);
  7142. lowerGroup.classes.push(arrowPrefix + "-arrow-pad");
  7143. }
  7144. const arrowBody = stretchySvg(group, options);
  7145. // Re shift: Note that stretchySvg returned arrowBody.depth = 0.
  7146. // The point we want on the math axis is at 0.5 * arrowBody.height.
  7147. const arrowShift = -options.fontMetrics().axisHeight + 0.5 * arrowBody.height;
  7148. // 2 mu kern. Ref: amsmath.dtx: #7\if0#2\else\mkern#2mu\fi
  7149. let upperShift = -options.fontMetrics().axisHeight - 0.5 * arrowBody.height - 0.111; // 0.111 em = 2 mu
  7150. if (upperGroup.depth > 0.25 || group.label === "\\xleftequilibrium") {
  7151. upperShift -= upperGroup.depth; // shift up if depth encroaches
  7152. }
  7153. // Generate the vlist
  7154. let vlist;
  7155. if (lowerGroup) {
  7156. const lowerShift = -options.fontMetrics().axisHeight + lowerGroup.height + 0.5 * arrowBody.height + 0.111;
  7157. vlist = makeVList({
  7158. positionType: "individualShift",
  7159. children: [{
  7160. type: "elem",
  7161. elem: upperGroup,
  7162. shift: upperShift
  7163. }, {
  7164. type: "elem",
  7165. elem: arrowBody,
  7166. shift: arrowShift
  7167. }, {
  7168. type: "elem",
  7169. elem: lowerGroup,
  7170. shift: lowerShift
  7171. }]
  7172. }, options);
  7173. } else {
  7174. vlist = makeVList({
  7175. positionType: "individualShift",
  7176. children: [{
  7177. type: "elem",
  7178. elem: upperGroup,
  7179. shift: upperShift
  7180. }, {
  7181. type: "elem",
  7182. elem: arrowBody,
  7183. shift: arrowShift
  7184. }]
  7185. }, options);
  7186. }
  7187. // TODO(ts): Replace this with passing "svg-align" into makeVList.
  7188. vlist.children[0].children[0].children[1].classes.push("svg-align");
  7189. return makeSpan(["mrel", "x-arrow"], [vlist], options);
  7190. },
  7191. mathmlBuilder(group, options) {
  7192. const arrowNode = stretchyMathML(group.label);
  7193. arrowNode.setAttribute("minsize", group.label.charAt(0) === "x" ? "1.75em" : "3.0em");
  7194. let node;
  7195. if (group.body) {
  7196. const upperNode = paddedNode(buildMathML_buildGroup(group.body, options));
  7197. if (group.below) {
  7198. const lowerNode = paddedNode(buildMathML_buildGroup(group.below, options));
  7199. node = new MathNode("munderover", [arrowNode, lowerNode, upperNode]);
  7200. } else {
  7201. node = new MathNode("mover", [arrowNode, upperNode]);
  7202. }
  7203. } else if (group.below) {
  7204. const lowerNode = paddedNode(buildMathML_buildGroup(group.below, options));
  7205. node = new MathNode("munder", [arrowNode, lowerNode]);
  7206. } else {
  7207. // This should never happen.
  7208. // Parser.js throws an error if there is no argument.
  7209. node = paddedNode();
  7210. node = new MathNode("mover", [arrowNode, node]);
  7211. }
  7212. return node;
  7213. }
  7214. });
  7215. ;// ./src/functions/mclass.ts
  7216. function mclass_htmlBuilder(group, options) {
  7217. const elements = buildExpression(group.body, options, true);
  7218. return makeSpan([group.mclass], elements, options);
  7219. }
  7220. function mclass_mathmlBuilder(group, options) {
  7221. let node;
  7222. const inner = buildMathML_buildExpression(group.body, options);
  7223. if (group.mclass === "minner") {
  7224. node = new MathNode("mpadded", inner);
  7225. } else if (group.mclass === "mord") {
  7226. if (group.isCharacterBox) {
  7227. node = inner[0];
  7228. node.type = "mi";
  7229. } else {
  7230. node = new MathNode("mi", inner);
  7231. }
  7232. } else {
  7233. if (group.isCharacterBox) {
  7234. node = inner[0];
  7235. node.type = "mo";
  7236. } else {
  7237. node = new MathNode("mo", inner);
  7238. }
  7239. // Set spacing based on what is the most likely adjacent atom type.
  7240. // See TeXbook p170.
  7241. if (group.mclass === "mbin") {
  7242. node.attributes.lspace = "0.22em"; // medium space
  7243. node.attributes.rspace = "0.22em";
  7244. } else if (group.mclass === "mpunct") {
  7245. node.attributes.lspace = "0em";
  7246. node.attributes.rspace = "0.17em"; // thinspace
  7247. } else if (group.mclass === "mopen" || group.mclass === "mclose") {
  7248. node.attributes.lspace = "0em";
  7249. node.attributes.rspace = "0em";
  7250. } else if (group.mclass === "minner") {
  7251. node.attributes.lspace = "0.0556em"; // 1 mu is the most likely option
  7252. node.attributes.width = "+0.1111em";
  7253. }
  7254. // MathML <mo> default space is 5/18 em, so <mrel> needs no action.
  7255. // Ref: https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo
  7256. }
  7257. return node;
  7258. }
  7259. // Math class commands except \mathop
  7260. defineFunction({
  7261. type: "mclass",
  7262. names: ["\\mathord", "\\mathbin", "\\mathrel", "\\mathopen", "\\mathclose", "\\mathpunct", "\\mathinner"],
  7263. props: {
  7264. numArgs: 1,
  7265. primitive: true
  7266. },
  7267. handler(_ref, args) {
  7268. let {
  7269. parser,
  7270. funcName
  7271. } = _ref;
  7272. const body = args[0];
  7273. return {
  7274. type: "mclass",
  7275. mode: parser.mode,
  7276. mclass: "m" + funcName.slice(5),
  7277. // TODO(kevinb): don't prefix with 'm'
  7278. body: ordargument(body),
  7279. isCharacterBox: isCharacterBox(body)
  7280. };
  7281. },
  7282. htmlBuilder: mclass_htmlBuilder,
  7283. mathmlBuilder: mclass_mathmlBuilder
  7284. });
  7285. const binrelClass = arg => {
  7286. // \binrel@ spacing varies with (bin|rel|ord) of the atom in the argument.
  7287. // (by rendering separately and with {}s before and after, and measuring
  7288. // the change in spacing). We'll do roughly the same by detecting the
  7289. // atom type directly.
  7290. const atom = arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg;
  7291. if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {
  7292. return "m" + atom.family;
  7293. } else {
  7294. return "mord";
  7295. }
  7296. };
  7297. // \@binrel{x}{y} renders like y but as mbin/mrel/mord if x is mbin/mrel/mord.
  7298. // This is equivalent to \binrel@{x}\binrel@@{y} in AMSTeX.
  7299. defineFunction({
  7300. type: "mclass",
  7301. names: ["\\@binrel"],
  7302. props: {
  7303. numArgs: 2
  7304. },
  7305. handler(_ref2, args) {
  7306. let {
  7307. parser
  7308. } = _ref2;
  7309. return {
  7310. type: "mclass",
  7311. mode: parser.mode,
  7312. mclass: binrelClass(args[0]),
  7313. body: ordargument(args[1]),
  7314. isCharacterBox: isCharacterBox(args[1])
  7315. };
  7316. }
  7317. });
  7318. // Build a relation or stacked op by placing one symbol on top of another
  7319. defineFunction({
  7320. type: "mclass",
  7321. names: ["\\stackrel", "\\overset", "\\underset"],
  7322. props: {
  7323. numArgs: 2
  7324. },
  7325. handler(_ref3, args) {
  7326. let {
  7327. parser,
  7328. funcName
  7329. } = _ref3;
  7330. const baseArg = args[1];
  7331. const shiftedArg = args[0];
  7332. let mclass;
  7333. if (funcName !== "\\stackrel") {
  7334. // LaTeX applies \binrel spacing to \overset and \underset.
  7335. mclass = binrelClass(baseArg);
  7336. } else {
  7337. mclass = "mrel"; // for \stackrel
  7338. }
  7339. const baseOp = {
  7340. type: "op",
  7341. mode: baseArg.mode,
  7342. limits: true,
  7343. alwaysHandleSupSub: true,
  7344. parentIsSupSub: false,
  7345. symbol: false,
  7346. suppressBaseShift: funcName !== "\\stackrel",
  7347. body: ordargument(baseArg)
  7348. };
  7349. const supsub = {
  7350. type: "supsub",
  7351. mode: shiftedArg.mode,
  7352. base: baseOp,
  7353. sup: funcName === "\\underset" ? null : shiftedArg,
  7354. sub: funcName === "\\underset" ? shiftedArg : null
  7355. };
  7356. return {
  7357. type: "mclass",
  7358. mode: parser.mode,
  7359. mclass,
  7360. body: [supsub],
  7361. isCharacterBox: isCharacterBox(supsub)
  7362. };
  7363. },
  7364. htmlBuilder: mclass_htmlBuilder,
  7365. mathmlBuilder: mclass_mathmlBuilder
  7366. });
  7367. ;// ./src/functions/pmb.ts
  7368. // \pmb is a simulation of bold font.
  7369. // The version of \pmb in ambsy.sty works by typesetting three copies
  7370. // with small offsets. We use CSS text-shadow.
  7371. // It's a hack. Not as good as a real bold font. Better than nothing.
  7372. defineFunction({
  7373. type: "pmb",
  7374. names: ["\\pmb"],
  7375. props: {
  7376. numArgs: 1,
  7377. allowedInText: true
  7378. },
  7379. handler(_ref, args) {
  7380. let {
  7381. parser
  7382. } = _ref;
  7383. return {
  7384. type: "pmb",
  7385. mode: parser.mode,
  7386. mclass: binrelClass(args[0]),
  7387. body: ordargument(args[0])
  7388. };
  7389. },
  7390. htmlBuilder(group, options) {
  7391. const elements = buildExpression(group.body, options, true);
  7392. const node = makeSpan([group.mclass], elements, options);
  7393. node.style.textShadow = "0.02em 0.01em 0.04px";
  7394. return node;
  7395. },
  7396. mathmlBuilder(group, style) {
  7397. const inner = buildMathML_buildExpression(group.body, style);
  7398. // Wrap with an <mstyle> element.
  7399. const node = new MathNode("mstyle", inner);
  7400. node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px");
  7401. return node;
  7402. }
  7403. });
  7404. ;// ./src/environments/cd.ts
  7405. const cdArrowFunctionName = {
  7406. ">": "\\\\cdrightarrow",
  7407. "<": "\\\\cdleftarrow",
  7408. "=": "\\\\cdlongequal",
  7409. "A": "\\uparrow",
  7410. "V": "\\downarrow",
  7411. "|": "\\Vert",
  7412. ".": "no arrow"
  7413. };
  7414. const newCell = () => {
  7415. // Create an empty cell, to be filled below with parse nodes.
  7416. // The parseTree from this module must be constructed like the
  7417. // one created by parseArray(), so an empty CD cell must
  7418. // be a ParseNode<"styling">. And CD is always displaystyle.
  7419. return {
  7420. type: "styling",
  7421. body: [],
  7422. mode: "math",
  7423. style: "display"
  7424. };
  7425. };
  7426. const isStartOfArrow = node => {
  7427. return node.type === "textord" && node.text === "@";
  7428. };
  7429. const isLabelEnd = (node, endChar) => {
  7430. return (node.type === "mathord" || node.type === "atom") && node.text === endChar;
  7431. };
  7432. function cdArrow(arrowChar, labels, parser) {
  7433. // Return a parse tree of an arrow and its labels.
  7434. // This acts in a way similar to a macro expansion.
  7435. const funcName = cdArrowFunctionName[arrowChar];
  7436. switch (funcName) {
  7437. case "\\\\cdrightarrow":
  7438. case "\\\\cdleftarrow":
  7439. return parser.callFunction(funcName, [labels[0]], [labels[1]]);
  7440. case "\\uparrow":
  7441. case "\\downarrow":
  7442. {
  7443. const leftLabel = parser.callFunction("\\\\cdleft", [labels[0]], []);
  7444. const bareArrow = {
  7445. type: "atom",
  7446. text: funcName,
  7447. mode: "math",
  7448. family: "rel"
  7449. };
  7450. const sizedArrow = parser.callFunction("\\Big", [bareArrow], []);
  7451. const rightLabel = parser.callFunction("\\\\cdright", [labels[1]], []);
  7452. const arrowGroup = {
  7453. type: "ordgroup",
  7454. mode: "math",
  7455. body: [leftLabel, sizedArrow, rightLabel]
  7456. };
  7457. return parser.callFunction("\\\\cdparent", [arrowGroup], []);
  7458. }
  7459. case "\\\\cdlongequal":
  7460. return parser.callFunction("\\\\cdlongequal", [], []);
  7461. case "\\Vert":
  7462. {
  7463. const arrow = {
  7464. type: "textord",
  7465. text: "\\Vert",
  7466. mode: "math"
  7467. };
  7468. return parser.callFunction("\\Big", [arrow], []);
  7469. }
  7470. default:
  7471. return {
  7472. type: "textord",
  7473. text: " ",
  7474. mode: "math"
  7475. };
  7476. }
  7477. }
  7478. function parseCD(parser) {
  7479. // Get the array's parse nodes with \\ temporarily mapped to \cr.
  7480. const parsedRows = [];
  7481. parser.gullet.beginGroup();
  7482. parser.gullet.macros.set("\\cr", "\\\\\\relax");
  7483. parser.gullet.beginGroup();
  7484. while (true) {
  7485. // eslint-disable-line no-constant-condition
  7486. // Get the parse nodes for the next row.
  7487. parsedRows.push(parser.parseExpression(false, "\\\\"));
  7488. parser.gullet.endGroup();
  7489. parser.gullet.beginGroup();
  7490. const next = parser.fetch().text;
  7491. if (next === "&" || next === "\\\\") {
  7492. parser.consume();
  7493. } else if (next === "\\end") {
  7494. if (parsedRows[parsedRows.length - 1].length === 0) {
  7495. parsedRows.pop(); // final row ended in \\
  7496. }
  7497. break;
  7498. } else {
  7499. throw new src_ParseError("Expected \\\\ or \\cr or \\end", parser.nextToken);
  7500. }
  7501. }
  7502. let row = [];
  7503. const body = [row];
  7504. // Loop thru the parse nodes. Collect them into cells and arrows.
  7505. for (let i = 0; i < parsedRows.length; i++) {
  7506. // Start a new row.
  7507. const rowNodes = parsedRows[i];
  7508. // Create the first cell.
  7509. let cell = newCell();
  7510. for (let j = 0; j < rowNodes.length; j++) {
  7511. if (!isStartOfArrow(rowNodes[j])) {
  7512. // If a parseNode is not an arrow, it goes into a cell.
  7513. cell.body.push(rowNodes[j]);
  7514. } else {
  7515. // Parse node j is an "@", the start of an arrow.
  7516. // Before starting on the arrow, push the cell into `row`.
  7517. row.push(cell);
  7518. // Now collect parseNodes into an arrow.
  7519. // The character after "@" defines the arrow type.
  7520. j += 1;
  7521. const arrowChar = assertSymbolNodeType(rowNodes[j]).text;
  7522. // Create two empty label nodes. We may or may not use them.
  7523. const labels = new Array(2);
  7524. labels[0] = {
  7525. type: "ordgroup",
  7526. mode: "math",
  7527. body: []
  7528. };
  7529. labels[1] = {
  7530. type: "ordgroup",
  7531. mode: "math",
  7532. body: []
  7533. };
  7534. // Process the arrow.
  7535. if ("=|.".includes(arrowChar)) {
  7536. // Three "arrows", ``@=`, `@|`, and `@.`, do not take labels.
  7537. // Do nothing here.
  7538. } else if ("<>AV".includes(arrowChar)) {
  7539. // Four arrows, `@>>>`, `@<<<`, `@AAA`, and `@VVV`, each take
  7540. // two optional labels. E.g. the right-point arrow syntax is
  7541. // really: @>{optional label}>{optional label}>
  7542. // Collect parseNodes into labels.
  7543. for (let labelNum = 0; labelNum < 2; labelNum++) {
  7544. let inLabel = true;
  7545. for (let k = j + 1; k < rowNodes.length; k++) {
  7546. if (isLabelEnd(rowNodes[k], arrowChar)) {
  7547. inLabel = false;
  7548. j = k;
  7549. break;
  7550. }
  7551. if (isStartOfArrow(rowNodes[k])) {
  7552. throw new src_ParseError("Missing a " + arrowChar + " character to complete a CD arrow.", rowNodes[k]);
  7553. }
  7554. labels[labelNum].body.push(rowNodes[k]);
  7555. }
  7556. if (inLabel) {
  7557. // isLabelEnd never returned a true.
  7558. throw new src_ParseError("Missing a " + arrowChar + " character to complete a CD arrow.", rowNodes[j]);
  7559. }
  7560. }
  7561. } else {
  7562. throw new src_ParseError("Expected one of \"<>AV=|.\" after @", rowNodes[j]);
  7563. }
  7564. // Now join the arrow to its labels.
  7565. const arrow = cdArrow(arrowChar, labels, parser);
  7566. // Wrap the arrow in ParseNode<"styling">.
  7567. // This is done to match parseArray() behavior.
  7568. const wrappedArrow = {
  7569. type: "styling",
  7570. body: [arrow],
  7571. mode: "math",
  7572. style: "display" // CD is always displaystyle.
  7573. };
  7574. row.push(wrappedArrow);
  7575. // In CD's syntax, cells are implicit. That is, everything that
  7576. // is not an arrow gets collected into a cell. So create an empty
  7577. // cell now. It will collect upcoming parseNodes.
  7578. cell = newCell();
  7579. }
  7580. }
  7581. if (i % 2 === 0) {
  7582. // Even-numbered rows consist of: cell, arrow, cell, arrow, ... cell
  7583. // The last cell is not yet pushed into `row`, so:
  7584. row.push(cell);
  7585. } else {
  7586. // Odd-numbered rows consist of: vert arrow, empty cell, ... vert arrow
  7587. // Remove the empty cell that was placed at the beginning of `row`.
  7588. row.shift();
  7589. }
  7590. row = [];
  7591. body.push(row);
  7592. }
  7593. // End row group
  7594. parser.gullet.endGroup();
  7595. // End array group defining \\
  7596. parser.gullet.endGroup();
  7597. // define column separation.
  7598. const cols = new Array(body[0].length).fill({
  7599. type: "align",
  7600. align: "c",
  7601. pregap: 0.25,
  7602. // CD package sets \enskip between columns.
  7603. postgap: 0.25 // So pre and post each get half an \enskip, i.e. 0.25em.
  7604. });
  7605. return {
  7606. type: "array",
  7607. mode: "math",
  7608. body,
  7609. arraystretch: 1,
  7610. addJot: true,
  7611. rowGaps: [null],
  7612. cols,
  7613. colSeparationType: "CD",
  7614. hLinesBeforeRow: new Array(body.length + 1).fill([])
  7615. };
  7616. }
  7617. // The functions below are not available for general use.
  7618. // They are here only for internal use by the {CD} environment in placing labels
  7619. // next to vertical arrows.
  7620. // We don't need any such functions for horizontal arrows because we can reuse
  7621. // the functionality that already exists for extensible arrows.
  7622. defineFunction({
  7623. type: "cdlabel",
  7624. names: ["\\\\cdleft", "\\\\cdright"],
  7625. props: {
  7626. numArgs: 1
  7627. },
  7628. handler(_ref, args) {
  7629. let {
  7630. parser,
  7631. funcName
  7632. } = _ref;
  7633. return {
  7634. type: "cdlabel",
  7635. mode: parser.mode,
  7636. side: funcName.slice(4),
  7637. label: args[0]
  7638. };
  7639. },
  7640. htmlBuilder(group, options) {
  7641. const newOptions = options.havingStyle(options.style.sup());
  7642. const label = wrapFragment(buildGroup(group.label, newOptions, options), options);
  7643. label.classes.push("cd-label-" + group.side);
  7644. label.style.bottom = makeEm(0.8 - label.depth);
  7645. // Zero out label height & depth, so vertical align of arrow is set
  7646. // by the arrow height, not by the label.
  7647. label.height = 0;
  7648. label.depth = 0;
  7649. return label;
  7650. },
  7651. mathmlBuilder(group, options) {
  7652. let label = new MathNode("mrow", [buildMathML_buildGroup(group.label, options)]);
  7653. label = new MathNode("mpadded", [label]);
  7654. label.setAttribute("width", "0");
  7655. if (group.side === "left") {
  7656. label.setAttribute("lspace", "-1width");
  7657. }
  7658. // We have to guess at vertical alignment. We know the arrow is 1.8em tall,
  7659. // But we don't know the height or depth of the label.
  7660. label.setAttribute("voffset", "0.7em");
  7661. label = new MathNode("mstyle", [label]);
  7662. label.setAttribute("displaystyle", "false");
  7663. label.setAttribute("scriptlevel", "1");
  7664. return label;
  7665. }
  7666. });
  7667. defineFunction({
  7668. type: "cdlabelparent",
  7669. names: ["\\\\cdparent"],
  7670. props: {
  7671. numArgs: 1
  7672. },
  7673. handler(_ref2, args) {
  7674. let {
  7675. parser
  7676. } = _ref2;
  7677. return {
  7678. type: "cdlabelparent",
  7679. mode: parser.mode,
  7680. fragment: args[0]
  7681. };
  7682. },
  7683. htmlBuilder(group, options) {
  7684. // Wrap the vertical arrow and its labels.
  7685. // The parent gets position: relative. The child gets position: absolute.
  7686. // So CSS can locate the label correctly.
  7687. const parent = wrapFragment(buildGroup(group.fragment, options), options);
  7688. parent.classes.push("cd-vert-arrow");
  7689. return parent;
  7690. },
  7691. mathmlBuilder(group, options) {
  7692. return new MathNode("mrow", [buildMathML_buildGroup(group.fragment, options)]);
  7693. }
  7694. });
  7695. ;// ./src/functions/char.ts
  7696. // \@char is an internal function that takes a grouped decimal argument like
  7697. // {123} and converts into symbol with code 123. It is used by the *macro*
  7698. // \char defined in macros.js.
  7699. defineFunction({
  7700. type: "textord",
  7701. names: ["\\@char"],
  7702. props: {
  7703. numArgs: 1,
  7704. allowedInText: true
  7705. },
  7706. handler(_ref, args) {
  7707. let {
  7708. parser
  7709. } = _ref;
  7710. const arg = assertNodeType(args[0], "ordgroup");
  7711. const group = arg.body;
  7712. let number = "";
  7713. for (let i = 0; i < group.length; i++) {
  7714. const node = assertNodeType(group[i], "textord");
  7715. number += node.text;
  7716. }
  7717. let code = parseInt(number);
  7718. let text;
  7719. if (isNaN(code)) {
  7720. throw new src_ParseError("\\@char has non-numeric argument " + number);
  7721. // If we drop IE support, the following code could be replaced with
  7722. // text = String.fromCodePoint(code)
  7723. } else if (code < 0 || code >= 0x10ffff) {
  7724. throw new src_ParseError("\\@char with invalid code point " + number);
  7725. } else if (code <= 0xffff) {
  7726. text = String.fromCharCode(code);
  7727. } else {
  7728. // Astral code point; split into surrogate halves
  7729. code -= 0x10000;
  7730. text = String.fromCharCode((code >> 10) + 0xd800, (code & 0x3ff) + 0xdc00);
  7731. }
  7732. return {
  7733. type: "textord",
  7734. mode: parser.mode,
  7735. text: text
  7736. };
  7737. }
  7738. });
  7739. ;// ./src/functions/color.ts
  7740. const color_htmlBuilder = (group, options) => {
  7741. const elements = buildExpression(group.body, options.withColor(group.color), false);
  7742. // \color isn't supposed to affect the type of the elements it contains.
  7743. // To accomplish this, we wrap the results in a fragment, so the inner
  7744. // elements will be able to directly interact with their neighbors. For
  7745. // example, `\color{red}{2 +} 3` has the same spacing as `2 + 3`
  7746. return makeFragment(elements);
  7747. };
  7748. const color_mathmlBuilder = (group, options) => {
  7749. const inner = buildMathML_buildExpression(group.body, options.withColor(group.color));
  7750. const node = new MathNode("mstyle", inner);
  7751. node.setAttribute("mathcolor", group.color);
  7752. return node;
  7753. };
  7754. defineFunction({
  7755. type: "color",
  7756. names: ["\\textcolor"],
  7757. props: {
  7758. numArgs: 2,
  7759. allowedInText: true,
  7760. argTypes: ["color", "original"]
  7761. },
  7762. handler(_ref, args) {
  7763. let {
  7764. parser
  7765. } = _ref;
  7766. const color = assertNodeType(args[0], "color-token").color;
  7767. const body = args[1];
  7768. return {
  7769. type: "color",
  7770. mode: parser.mode,
  7771. color,
  7772. body: ordargument(body)
  7773. };
  7774. },
  7775. htmlBuilder: color_htmlBuilder,
  7776. mathmlBuilder: color_mathmlBuilder
  7777. });
  7778. defineFunction({
  7779. type: "color",
  7780. names: ["\\color"],
  7781. props: {
  7782. numArgs: 1,
  7783. allowedInText: true,
  7784. argTypes: ["color"]
  7785. },
  7786. handler(_ref2, args) {
  7787. let {
  7788. parser,
  7789. breakOnTokenText
  7790. } = _ref2;
  7791. const color = assertNodeType(args[0], "color-token").color;
  7792. // Set macro \current@color in current namespace to store the current
  7793. // color, mimicking the behavior of color.sty.
  7794. // This is currently used just to correctly color a \right
  7795. // that follows a \color command.
  7796. parser.gullet.macros.set("\\current@color", color);
  7797. // Parse out the implicit body that should be colored.
  7798. const body = parser.parseExpression(true, breakOnTokenText);
  7799. return {
  7800. type: "color",
  7801. mode: parser.mode,
  7802. color,
  7803. body
  7804. };
  7805. },
  7806. htmlBuilder: color_htmlBuilder,
  7807. mathmlBuilder: color_mathmlBuilder
  7808. });
  7809. ;// ./src/functions/cr.ts
  7810. // Row breaks within tabular environments, and line breaks at top level
  7811. // \DeclareRobustCommand\\{...\@xnewline}
  7812. defineFunction({
  7813. type: "cr",
  7814. names: ["\\\\"],
  7815. props: {
  7816. numArgs: 0,
  7817. numOptionalArgs: 0,
  7818. allowedInText: true
  7819. },
  7820. handler(_ref, args, optArgs) {
  7821. let {
  7822. parser
  7823. } = _ref;
  7824. const size = parser.gullet.future().text === "[" ? parser.parseSizeGroup(true) : null;
  7825. const newLine = !parser.settings.displayMode || !parser.settings.useStrictBehavior("newLineInDisplayMode", "In LaTeX, \\\\ or \\newline " + "does nothing in display mode");
  7826. return {
  7827. type: "cr",
  7828. mode: parser.mode,
  7829. newLine,
  7830. size: size && assertNodeType(size, "size").value
  7831. };
  7832. },
  7833. // The following builders are called only at the top level,
  7834. // not within tabular/array environments.
  7835. htmlBuilder(group, options) {
  7836. const span = makeSpan(["mspace"], [], options);
  7837. if (group.newLine) {
  7838. span.classes.push("newline");
  7839. if (group.size) {
  7840. span.style.marginTop = makeEm(calculateSize(group.size, options));
  7841. }
  7842. }
  7843. return span;
  7844. },
  7845. mathmlBuilder(group, options) {
  7846. const node = new MathNode("mspace");
  7847. if (group.newLine) {
  7848. node.setAttribute("linebreak", "newline");
  7849. if (group.size) {
  7850. node.setAttribute("height", makeEm(calculateSize(group.size, options)));
  7851. }
  7852. }
  7853. return node;
  7854. }
  7855. });
  7856. ;// ./src/functions/def.ts
  7857. const globalMap = {
  7858. "\\global": "\\global",
  7859. "\\long": "\\\\globallong",
  7860. "\\\\globallong": "\\\\globallong",
  7861. "\\def": "\\gdef",
  7862. "\\gdef": "\\gdef",
  7863. "\\edef": "\\xdef",
  7864. "\\xdef": "\\xdef",
  7865. "\\let": "\\\\globallet",
  7866. "\\futurelet": "\\\\globalfuture"
  7867. };
  7868. const checkControlSequence = tok => {
  7869. const name = tok.text;
  7870. if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
  7871. throw new src_ParseError("Expected a control sequence", tok);
  7872. }
  7873. return name;
  7874. };
  7875. const getRHS = parser => {
  7876. let tok = parser.gullet.popToken();
  7877. if (tok.text === "=") {
  7878. // consume optional equals
  7879. tok = parser.gullet.popToken();
  7880. if (tok.text === " ") {
  7881. // consume one optional space
  7882. tok = parser.gullet.popToken();
  7883. }
  7884. }
  7885. return tok;
  7886. };
  7887. const letCommand = (parser, name, tok, global) => {
  7888. let macro = parser.gullet.macros.get(tok.text);
  7889. if (macro == null) {
  7890. // don't expand it later even if a macro with the same name is defined
  7891. // e.g., \let\foo=\frac \def\frac{\relax} \frac12
  7892. tok.noexpand = true;
  7893. macro = {
  7894. tokens: [tok],
  7895. numArgs: 0,
  7896. // reproduce the same behavior in expansion
  7897. unexpandable: !parser.gullet.isExpandable(tok.text)
  7898. };
  7899. }
  7900. parser.gullet.macros.set(name, macro, global);
  7901. };
  7902. // <assignment> -> <non-macro assignment>|<macro assignment>
  7903. // <non-macro assignment> -> <simple assignment>|\global<non-macro assignment>
  7904. // <macro assignment> -> <definition>|<prefix><macro assignment>
  7905. // <prefix> -> \global|\long|\outer
  7906. defineFunction({
  7907. type: "internal",
  7908. names: ["\\global", "\\long", "\\\\globallong" // can’t be entered directly
  7909. ],
  7910. props: {
  7911. numArgs: 0,
  7912. allowedInText: true
  7913. },
  7914. handler(_ref) {
  7915. let {
  7916. parser,
  7917. funcName
  7918. } = _ref;
  7919. parser.consumeSpaces();
  7920. const token = parser.fetch();
  7921. if (globalMap[token.text]) {
  7922. // KaTeX doesn't have \par, so ignore \long
  7923. if (funcName === "\\global" || funcName === "\\\\globallong") {
  7924. token.text = globalMap[token.text];
  7925. }
  7926. return assertNodeType(parser.parseFunction(), "internal");
  7927. }
  7928. throw new src_ParseError("Invalid token after macro prefix", token);
  7929. }
  7930. });
  7931. // Basic support for macro definitions: \def, \gdef, \edef, \xdef
  7932. // <definition> -> <def><control sequence><definition text>
  7933. // <def> -> \def|\gdef|\edef|\xdef
  7934. // <definition text> -> <parameter text><left brace><balanced text><right brace>
  7935. defineFunction({
  7936. type: "internal",
  7937. names: ["\\def", "\\gdef", "\\edef", "\\xdef"],
  7938. props: {
  7939. numArgs: 0,
  7940. allowedInText: true,
  7941. primitive: true
  7942. },
  7943. handler(_ref2) {
  7944. let {
  7945. parser,
  7946. funcName
  7947. } = _ref2;
  7948. let tok = parser.gullet.popToken();
  7949. const name = tok.text;
  7950. if (/^(?:[\\{}$&#^_]|EOF)$/.test(name)) {
  7951. throw new src_ParseError("Expected a control sequence", tok);
  7952. }
  7953. let numArgs = 0;
  7954. let insert;
  7955. const delimiters = [[]];
  7956. // <parameter text> contains no braces
  7957. while (parser.gullet.future().text !== "{") {
  7958. tok = parser.gullet.popToken();
  7959. if (tok.text === "#") {
  7960. // If the very last character of the <parameter text> is #, so that
  7961. // this # is immediately followed by {, TeX will behave as if the {
  7962. // had been inserted at the right end of both the parameter text
  7963. // and the replacement text.
  7964. if (parser.gullet.future().text === "{") {
  7965. insert = parser.gullet.future();
  7966. delimiters[numArgs].push("{");
  7967. break;
  7968. }
  7969. // A parameter, the first appearance of # must be followed by 1,
  7970. // the next by 2, and so on; up to nine #’s are allowed
  7971. tok = parser.gullet.popToken();
  7972. if (!/^[1-9]$/.test(tok.text)) {
  7973. throw new src_ParseError("Invalid argument number \"" + tok.text + "\"");
  7974. }
  7975. if (parseInt(tok.text) !== numArgs + 1) {
  7976. throw new src_ParseError("Argument number \"" + tok.text + "\" out of order");
  7977. }
  7978. numArgs++;
  7979. delimiters.push([]);
  7980. } else if (tok.text === "EOF") {
  7981. throw new src_ParseError("Expected a macro definition");
  7982. } else {
  7983. delimiters[numArgs].push(tok.text);
  7984. }
  7985. }
  7986. // replacement text, enclosed in '{' and '}' and properly nested
  7987. let {
  7988. tokens
  7989. } = parser.gullet.consumeArg();
  7990. if (insert) {
  7991. tokens.unshift(insert);
  7992. }
  7993. if (funcName === "\\edef" || funcName === "\\xdef") {
  7994. tokens = parser.gullet.expandTokens(tokens);
  7995. tokens.reverse(); // to fit in with stack order
  7996. }
  7997. // Final arg is the expansion of the macro
  7998. parser.gullet.macros.set(name, {
  7999. tokens,
  8000. numArgs,
  8001. delimiters
  8002. }, funcName === globalMap[funcName]);
  8003. return {
  8004. type: "internal",
  8005. mode: parser.mode
  8006. };
  8007. }
  8008. });
  8009. // <simple assignment> -> <let assignment>
  8010. // <let assignment> -> \futurelet<control sequence><token><token>
  8011. // | \let<control sequence><equals><one optional space><token>
  8012. // <equals> -> <optional spaces>|<optional spaces>=
  8013. defineFunction({
  8014. type: "internal",
  8015. names: ["\\let", "\\\\globallet" // can’t be entered directly
  8016. ],
  8017. props: {
  8018. numArgs: 0,
  8019. allowedInText: true,
  8020. primitive: true
  8021. },
  8022. handler(_ref3) {
  8023. let {
  8024. parser,
  8025. funcName
  8026. } = _ref3;
  8027. const name = checkControlSequence(parser.gullet.popToken());
  8028. parser.gullet.consumeSpaces();
  8029. const tok = getRHS(parser);
  8030. letCommand(parser, name, tok, funcName === "\\\\globallet");
  8031. return {
  8032. type: "internal",
  8033. mode: parser.mode
  8034. };
  8035. }
  8036. });
  8037. // ref: https://www.tug.org/TUGboat/tb09-3/tb22bechtolsheim.pdf
  8038. defineFunction({
  8039. type: "internal",
  8040. names: ["\\futurelet", "\\\\globalfuture" // can’t be entered directly
  8041. ],
  8042. props: {
  8043. numArgs: 0,
  8044. allowedInText: true,
  8045. primitive: true
  8046. },
  8047. handler(_ref4) {
  8048. let {
  8049. parser,
  8050. funcName
  8051. } = _ref4;
  8052. const name = checkControlSequence(parser.gullet.popToken());
  8053. const middle = parser.gullet.popToken();
  8054. const tok = parser.gullet.popToken();
  8055. letCommand(parser, name, tok, funcName === "\\\\globalfuture");
  8056. parser.gullet.pushToken(tok);
  8057. parser.gullet.pushToken(middle);
  8058. return {
  8059. type: "internal",
  8060. mode: parser.mode
  8061. };
  8062. }
  8063. });
  8064. ;// ./src/delimiter.ts
  8065. /**
  8066. * This file deals with creating delimiters of various sizes. The TeXbook
  8067. * discusses these routines on page 441-442, in the "Another subroutine sets box
  8068. * x to a specified variable delimiter" paragraph.
  8069. *
  8070. * There are three main routines here. `makeSmallDelim` makes a delimiter in the
  8071. * normal font, but in either text, script, or scriptscript style.
  8072. * `makeLargeDelim` makes a delimiter in textstyle, but in one of the Size1,
  8073. * Size2, Size3, or Size4 fonts. `makeStackedDelim` makes a delimiter out of
  8074. * smaller pieces that are stacked on top of one another.
  8075. *
  8076. * The functions take a parameter `center`, which determines if the delimiter
  8077. * should be centered around the axis.
  8078. *
  8079. * Then, there are three exposed functions. `sizedDelim` makes a delimiter in
  8080. * one of the given sizes. This is used for things like `\bigl`.
  8081. * `customSizedDelim` makes a delimiter with a given total height+depth. It is
  8082. * called in places like `\sqrt`. `leftRightDelim` makes an appropriate
  8083. * delimiter which surrounds an expression of a given height an depth. It is
  8084. * used in `\left` and `\right`.
  8085. */
  8086. /**
  8087. * Get the metrics for a given symbol and font, after transformation (i.e.
  8088. * after following replacement from symbols.js)
  8089. */
  8090. const getMetrics = function (symbol, font, mode) {
  8091. const replace = src_symbols.math[symbol] && src_symbols.math[symbol].replace;
  8092. const metrics = getCharacterMetrics(replace || symbol, font, mode);
  8093. if (!metrics) {
  8094. throw new Error("Unsupported symbol " + symbol + " and font size " + font + ".");
  8095. }
  8096. return metrics;
  8097. };
  8098. /**
  8099. * Puts a delimiter span in a given style, and adds appropriate height, depth,
  8100. * and maxFontSizes.
  8101. */
  8102. const styleWrap = function (delim, toStyle, options, classes) {
  8103. const newOptions = options.havingBaseStyle(toStyle);
  8104. const span = makeSpan(classes.concat(newOptions.sizingClasses(options)), [delim], options);
  8105. const delimSizeMultiplier = newOptions.sizeMultiplier / options.sizeMultiplier;
  8106. span.height *= delimSizeMultiplier;
  8107. span.depth *= delimSizeMultiplier;
  8108. span.maxFontSize = newOptions.sizeMultiplier;
  8109. return span;
  8110. };
  8111. const centerSpan = function (span, options, style) {
  8112. const newOptions = options.havingBaseStyle(style);
  8113. const shift = (1 - options.sizeMultiplier / newOptions.sizeMultiplier) * options.fontMetrics().axisHeight;
  8114. span.classes.push("delimcenter");
  8115. span.style.top = makeEm(shift);
  8116. span.height -= shift;
  8117. span.depth += shift;
  8118. };
  8119. /**
  8120. * Makes a small delimiter. This is a delimiter that comes in the Main-Regular
  8121. * font, but is restyled to either be in textstyle, scriptstyle, or
  8122. * scriptscriptstyle.
  8123. */
  8124. const makeSmallDelim = function (delim, style, center, options, mode, classes) {
  8125. const text = makeSymbol(delim, "Main-Regular", mode, options);
  8126. const span = styleWrap(text, style, options, classes);
  8127. if (center) {
  8128. centerSpan(span, options, style);
  8129. }
  8130. return span;
  8131. };
  8132. /**
  8133. * Builds a symbol in the given font size (note size is an integer)
  8134. */
  8135. const mathrmSize = function (value, size, mode, options) {
  8136. return makeSymbol(value, "Size" + size + "-Regular", mode, options);
  8137. };
  8138. /**
  8139. * Makes a large delimiter. This is a delimiter that comes in the Size1, Size2,
  8140. * Size3, or Size4 fonts. It is always rendered in textstyle.
  8141. */
  8142. const makeLargeDelim = function (delim, size, center, options, mode, classes) {
  8143. const inner = mathrmSize(delim, size, mode, options);
  8144. const span = styleWrap(makeSpan(["delimsizing", "size" + size], [inner], options), src_Style.TEXT, options, classes);
  8145. if (center) {
  8146. centerSpan(span, options, src_Style.TEXT);
  8147. }
  8148. return span;
  8149. };
  8150. /**
  8151. * Make a span from a font glyph with the given offset and in the given font.
  8152. * This is used in makeStackedDelim to make the stacking pieces for the delimiter.
  8153. */
  8154. const makeGlyphSpan = function (symbol, font, mode) {
  8155. let sizeClass;
  8156. // Apply the correct CSS class to choose the right font.
  8157. if (font === "Size1-Regular") {
  8158. sizeClass = "delim-size1";
  8159. } else /* if (font === "Size4-Regular") */{
  8160. sizeClass = "delim-size4";
  8161. }
  8162. const corner = makeSpan(["delimsizinginner", sizeClass], [makeSpan([], [makeSymbol(symbol, font, mode)])]);
  8163. // Since this will be passed into `makeVList` in the end, wrap the element
  8164. // in the appropriate tag that VList uses.
  8165. return {
  8166. type: "elem",
  8167. elem: corner
  8168. };
  8169. };
  8170. const makeInner = function (ch, height, options) {
  8171. // Create a span with inline SVG for the inner part of a tall stacked delimiter.
  8172. const width = fontMetricsData['Size4-Regular'][ch.charCodeAt(0)] ? fontMetricsData['Size4-Regular'][ch.charCodeAt(0)][4] : fontMetricsData['Size1-Regular'][ch.charCodeAt(0)][4];
  8173. const path = new PathNode("inner", innerPath(ch, Math.round(1000 * height)));
  8174. const svgNode = new SvgNode([path], {
  8175. "width": makeEm(width),
  8176. "height": makeEm(height),
  8177. // Override CSS rule `.katex svg { width: 100% }`
  8178. "style": "width:" + makeEm(width),
  8179. "viewBox": "0 0 " + 1000 * width + " " + Math.round(1000 * height),
  8180. "preserveAspectRatio": "xMinYMin"
  8181. });
  8182. const span = makeSvgSpan([], [svgNode], options);
  8183. span.height = height;
  8184. span.style.height = makeEm(height);
  8185. span.style.width = makeEm(width);
  8186. return {
  8187. type: "elem",
  8188. elem: span
  8189. };
  8190. };
  8191. // Helpers for makeStackedDelim
  8192. const lapInEms = 0.008;
  8193. const lap = {
  8194. type: "kern",
  8195. size: -1 * lapInEms
  8196. };
  8197. const verts = new Set(["|", "\\lvert", "\\rvert", "\\vert"]);
  8198. const doubleVerts = new Set(["\\|", "\\lVert", "\\rVert", "\\Vert"]);
  8199. /**
  8200. * Make a stacked delimiter out of a given delimiter, with the total height at
  8201. * least `heightTotal`. This routine is mentioned on page 442 of the TeXbook.
  8202. */
  8203. const makeStackedDelim = function (delim, heightTotal, center, options, mode, classes) {
  8204. // There are four parts, the top, an optional middle, a repeated part, and a
  8205. // bottom.
  8206. let top;
  8207. let middle;
  8208. let repeat;
  8209. let bottom;
  8210. let svgLabel = "";
  8211. let viewBoxWidth = 0;
  8212. top = repeat = bottom = delim;
  8213. middle = null;
  8214. // Also keep track of what font the delimiters are in
  8215. let font = "Size1-Regular";
  8216. // We set the parts and font based on the symbol. Note that we use
  8217. // '\u23d0' instead of '|' and '\u2016' instead of '\\|' for the
  8218. // repeats of the arrows
  8219. if (delim === "\\uparrow") {
  8220. repeat = bottom = "\u23d0";
  8221. } else if (delim === "\\Uparrow") {
  8222. repeat = bottom = "\u2016";
  8223. } else if (delim === "\\downarrow") {
  8224. top = repeat = "\u23d0";
  8225. } else if (delim === "\\Downarrow") {
  8226. top = repeat = "\u2016";
  8227. } else if (delim === "\\updownarrow") {
  8228. top = "\\uparrow";
  8229. repeat = "\u23d0";
  8230. bottom = "\\downarrow";
  8231. } else if (delim === "\\Updownarrow") {
  8232. top = "\\Uparrow";
  8233. repeat = "\u2016";
  8234. bottom = "\\Downarrow";
  8235. } else if (verts.has(delim)) {
  8236. repeat = "\u2223";
  8237. svgLabel = "vert";
  8238. viewBoxWidth = 333;
  8239. } else if (doubleVerts.has(delim)) {
  8240. repeat = "\u2225";
  8241. svgLabel = "doublevert";
  8242. viewBoxWidth = 556;
  8243. } else if (delim === "[" || delim === "\\lbrack") {
  8244. top = "\u23a1";
  8245. repeat = "\u23a2";
  8246. bottom = "\u23a3";
  8247. font = "Size4-Regular";
  8248. svgLabel = "lbrack";
  8249. viewBoxWidth = 667;
  8250. } else if (delim === "]" || delim === "\\rbrack") {
  8251. top = "\u23a4";
  8252. repeat = "\u23a5";
  8253. bottom = "\u23a6";
  8254. font = "Size4-Regular";
  8255. svgLabel = "rbrack";
  8256. viewBoxWidth = 667;
  8257. } else if (delim === "\\lfloor" || delim === "\u230a") {
  8258. repeat = top = "\u23a2";
  8259. bottom = "\u23a3";
  8260. font = "Size4-Regular";
  8261. svgLabel = "lfloor";
  8262. viewBoxWidth = 667;
  8263. } else if (delim === "\\lceil" || delim === "\u2308") {
  8264. top = "\u23a1";
  8265. repeat = bottom = "\u23a2";
  8266. font = "Size4-Regular";
  8267. svgLabel = "lceil";
  8268. viewBoxWidth = 667;
  8269. } else if (delim === "\\rfloor" || delim === "\u230b") {
  8270. repeat = top = "\u23a5";
  8271. bottom = "\u23a6";
  8272. font = "Size4-Regular";
  8273. svgLabel = "rfloor";
  8274. viewBoxWidth = 667;
  8275. } else if (delim === "\\rceil" || delim === "\u2309") {
  8276. top = "\u23a4";
  8277. repeat = bottom = "\u23a5";
  8278. font = "Size4-Regular";
  8279. svgLabel = "rceil";
  8280. viewBoxWidth = 667;
  8281. } else if (delim === "(" || delim === "\\lparen") {
  8282. top = "\u239b";
  8283. repeat = "\u239c";
  8284. bottom = "\u239d";
  8285. font = "Size4-Regular";
  8286. svgLabel = "lparen";
  8287. viewBoxWidth = 875;
  8288. } else if (delim === ")" || delim === "\\rparen") {
  8289. top = "\u239e";
  8290. repeat = "\u239f";
  8291. bottom = "\u23a0";
  8292. font = "Size4-Regular";
  8293. svgLabel = "rparen";
  8294. viewBoxWidth = 875;
  8295. } else if (delim === "\\{" || delim === "\\lbrace") {
  8296. top = "\u23a7";
  8297. middle = "\u23a8";
  8298. bottom = "\u23a9";
  8299. repeat = "\u23aa";
  8300. font = "Size4-Regular";
  8301. } else if (delim === "\\}" || delim === "\\rbrace") {
  8302. top = "\u23ab";
  8303. middle = "\u23ac";
  8304. bottom = "\u23ad";
  8305. repeat = "\u23aa";
  8306. font = "Size4-Regular";
  8307. } else if (delim === "\\lgroup" || delim === "\u27ee") {
  8308. top = "\u23a7";
  8309. bottom = "\u23a9";
  8310. repeat = "\u23aa";
  8311. font = "Size4-Regular";
  8312. } else if (delim === "\\rgroup" || delim === "\u27ef") {
  8313. top = "\u23ab";
  8314. bottom = "\u23ad";
  8315. repeat = "\u23aa";
  8316. font = "Size4-Regular";
  8317. } else if (delim === "\\lmoustache" || delim === "\u23b0") {
  8318. top = "\u23a7";
  8319. bottom = "\u23ad";
  8320. repeat = "\u23aa";
  8321. font = "Size4-Regular";
  8322. } else if (delim === "\\rmoustache" || delim === "\u23b1") {
  8323. top = "\u23ab";
  8324. bottom = "\u23a9";
  8325. repeat = "\u23aa";
  8326. font = "Size4-Regular";
  8327. }
  8328. // Get the metrics of the four sections
  8329. const topMetrics = getMetrics(top, font, mode);
  8330. const topHeightTotal = topMetrics.height + topMetrics.depth;
  8331. const repeatMetrics = getMetrics(repeat, font, mode);
  8332. const repeatHeightTotal = repeatMetrics.height + repeatMetrics.depth;
  8333. const bottomMetrics = getMetrics(bottom, font, mode);
  8334. const bottomHeightTotal = bottomMetrics.height + bottomMetrics.depth;
  8335. let middleHeightTotal = 0;
  8336. let middleFactor = 1;
  8337. if (middle !== null) {
  8338. const middleMetrics = getMetrics(middle, font, mode);
  8339. middleHeightTotal = middleMetrics.height + middleMetrics.depth;
  8340. middleFactor = 2; // repeat symmetrically above and below middle
  8341. }
  8342. // Calculate the minimal height that the delimiter can have.
  8343. // It is at least the size of the top, bottom, and optional middle combined.
  8344. const minHeight = topHeightTotal + bottomHeightTotal + middleHeightTotal;
  8345. // Compute the number of copies of the repeat symbol we will need
  8346. const repeatCount = Math.max(0, Math.ceil((heightTotal - minHeight) / (middleFactor * repeatHeightTotal)));
  8347. // Compute the total height of the delimiter including all the symbols
  8348. const realHeightTotal = minHeight + repeatCount * middleFactor * repeatHeightTotal;
  8349. // The center of the delimiter is placed at the center of the axis. Note
  8350. // that in this context, "center" means that the delimiter should be
  8351. // centered around the axis in the current style, while normally it is
  8352. // centered around the axis in textstyle.
  8353. let axisHeight = options.fontMetrics().axisHeight;
  8354. if (center) {
  8355. axisHeight *= options.sizeMultiplier;
  8356. }
  8357. // Calculate the depth
  8358. const depth = realHeightTotal / 2 - axisHeight;
  8359. // Now, we start building the pieces that will go into the vlist
  8360. // Keep a list of the pieces of the stacked delimiter
  8361. const stack = [];
  8362. if (svgLabel.length > 0) {
  8363. // Instead of stacking glyphs, create a single SVG.
  8364. // This evades browser problems with imprecise positioning of spans.
  8365. const midHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
  8366. const viewBoxHeight = Math.round(realHeightTotal * 1000);
  8367. const pathStr = tallDelim(svgLabel, Math.round(midHeight * 1000));
  8368. const path = new PathNode(svgLabel, pathStr);
  8369. const width = makeEm(viewBoxWidth / 1000);
  8370. const height = makeEm(viewBoxHeight / 1000);
  8371. const svg = new SvgNode([path], {
  8372. "width": width,
  8373. "height": height,
  8374. "viewBox": "0 0 " + viewBoxWidth + " " + viewBoxHeight
  8375. });
  8376. const wrapper = makeSvgSpan([], [svg], options);
  8377. wrapper.height = viewBoxHeight / 1000;
  8378. wrapper.style.width = width;
  8379. wrapper.style.height = height;
  8380. stack.push({
  8381. type: "elem",
  8382. elem: wrapper
  8383. });
  8384. } else {
  8385. // Stack glyphs
  8386. // Start by adding the bottom symbol
  8387. stack.push(makeGlyphSpan(bottom, font, mode));
  8388. stack.push(lap); // overlap
  8389. if (middle === null) {
  8390. // The middle section will be an SVG. Make it an extra 0.016em tall.
  8391. // We'll overlap by 0.008em at top and bottom.
  8392. const innerHeight = realHeightTotal - topHeightTotal - bottomHeightTotal + 2 * lapInEms;
  8393. stack.push(makeInner(repeat, innerHeight, options));
  8394. } else {
  8395. // When there is a middle bit, we need the middle part and two repeated
  8396. // sections
  8397. const innerHeight = (realHeightTotal - topHeightTotal - bottomHeightTotal - middleHeightTotal) / 2 + 2 * lapInEms;
  8398. stack.push(makeInner(repeat, innerHeight, options));
  8399. // Now insert the middle of the brace.
  8400. stack.push(lap);
  8401. stack.push(makeGlyphSpan(middle, font, mode));
  8402. stack.push(lap);
  8403. stack.push(makeInner(repeat, innerHeight, options));
  8404. }
  8405. // Add the top symbol
  8406. stack.push(lap);
  8407. stack.push(makeGlyphSpan(top, font, mode));
  8408. }
  8409. // Finally, build the vlist
  8410. const newOptions = options.havingBaseStyle(src_Style.TEXT);
  8411. const inner = makeVList({
  8412. positionType: "bottom",
  8413. positionData: depth,
  8414. children: stack
  8415. }, newOptions);
  8416. return styleWrap(makeSpan(["delimsizing", "mult"], [inner], newOptions), src_Style.TEXT, options, classes);
  8417. };
  8418. // All surds have 0.08em padding above the vinculum inside the SVG.
  8419. // That keeps browser span height rounding error from pinching the line.
  8420. const vbPad = 80; // padding above the surd, measured inside the viewBox.
  8421. const emPad = 0.08; // padding, in ems, measured in the document.
  8422. const sqrtSvg = function (sqrtName, height, viewBoxHeight, extraVinculum, options) {
  8423. const path = sqrtPath(sqrtName, extraVinculum, viewBoxHeight);
  8424. const pathNode = new PathNode(sqrtName, path);
  8425. const svg = new SvgNode([pathNode], {
  8426. // Note: 1000:1 ratio of viewBox to document em width.
  8427. "width": "400em",
  8428. "height": makeEm(height),
  8429. "viewBox": "0 0 400000 " + viewBoxHeight,
  8430. "preserveAspectRatio": "xMinYMin slice"
  8431. });
  8432. return makeSvgSpan(["hide-tail"], [svg], options);
  8433. };
  8434. /**
  8435. * Make a sqrt image of the given height,
  8436. */
  8437. const makeSqrtImage = function (height, options) {
  8438. // Define a newOptions that removes the effect of size changes such as \Huge.
  8439. // We don't pick different a height surd for \Huge. For it, we scale up.
  8440. const newOptions = options.havingBaseSizing();
  8441. // Pick the desired surd glyph from a sequence of surds.
  8442. const delim = traverseSequence("\\surd", height * newOptions.sizeMultiplier, stackLargeDelimiterSequence, newOptions);
  8443. let sizeMultiplier = newOptions.sizeMultiplier; // default
  8444. // The standard sqrt SVGs each have a 0.04em thick vinculum.
  8445. // If Settings.minRuleThickness is larger than that, we add extraVinculum.
  8446. const extraVinculum = Math.max(0, options.minRuleThickness - options.fontMetrics().sqrtRuleThickness);
  8447. // Create a span containing an SVG image of a sqrt symbol.
  8448. let span;
  8449. let spanHeight = 0;
  8450. let texHeight = 0;
  8451. let viewBoxHeight = 0;
  8452. let advanceWidth;
  8453. // We create viewBoxes with 80 units of "padding" above each surd.
  8454. // Then browser rounding error on the parent span height will not
  8455. // encroach on the ink of the vinculum. But that padding is not
  8456. // included in the TeX-like `height` used for calculation of
  8457. // vertical alignment. So texHeight = span.height < span.style.height.
  8458. if (delim.type === "small") {
  8459. // Get an SVG that is derived from glyph U+221A in font KaTeX-Main.
  8460. // 1000 unit normal glyph height.
  8461. viewBoxHeight = 1000 + 1000 * extraVinculum + vbPad;
  8462. if (height < 1.0) {
  8463. sizeMultiplier = 1.0; // mimic a \textfont radical
  8464. } else if (height < 1.4) {
  8465. sizeMultiplier = 0.7; // mimic a \scriptfont radical
  8466. }
  8467. spanHeight = (1.0 + extraVinculum + emPad) / sizeMultiplier;
  8468. texHeight = (1.00 + extraVinculum) / sizeMultiplier;
  8469. span = sqrtSvg("sqrtMain", spanHeight, viewBoxHeight, extraVinculum, options);
  8470. span.style.minWidth = "0.853em";
  8471. advanceWidth = 0.833 / sizeMultiplier; // from the font.
  8472. } else if (delim.type === "large") {
  8473. // These SVGs come from fonts: KaTeX_Size1, _Size2, etc.
  8474. viewBoxHeight = (1000 + vbPad) * sizeToMaxHeight[delim.size];
  8475. texHeight = (sizeToMaxHeight[delim.size] + extraVinculum) / sizeMultiplier;
  8476. spanHeight = (sizeToMaxHeight[delim.size] + extraVinculum + emPad) / sizeMultiplier;
  8477. span = sqrtSvg("sqrtSize" + delim.size, spanHeight, viewBoxHeight, extraVinculum, options);
  8478. span.style.minWidth = "1.02em";
  8479. advanceWidth = 1.0 / sizeMultiplier; // 1.0 from the font.
  8480. } else {
  8481. // Tall sqrt. In TeX, this would be stacked using multiple glyphs.
  8482. // We'll use a single SVG to accomplish the same thing.
  8483. spanHeight = height + extraVinculum + emPad;
  8484. texHeight = height + extraVinculum;
  8485. viewBoxHeight = Math.floor(1000 * height + extraVinculum) + vbPad;
  8486. span = sqrtSvg("sqrtTall", spanHeight, viewBoxHeight, extraVinculum, options);
  8487. span.style.minWidth = "0.742em";
  8488. advanceWidth = 1.056;
  8489. }
  8490. span.height = texHeight;
  8491. span.style.height = makeEm(spanHeight);
  8492. return {
  8493. span,
  8494. advanceWidth,
  8495. // Calculate the actual line width.
  8496. // This actually should depend on the chosen font -- e.g. \boldmath
  8497. // should use the thicker surd symbols from e.g. KaTeX_Main-Bold, and
  8498. // have thicker rules.
  8499. ruleWidth: (options.fontMetrics().sqrtRuleThickness + extraVinculum) * sizeMultiplier
  8500. };
  8501. };
  8502. // There are three kinds of delimiters, delimiters that stack when they become
  8503. // too large
  8504. const stackLargeDelimiters = new Set(["(", "\\lparen", ")", "\\rparen", "[", "\\lbrack", "]", "\\rbrack", "\\{", "\\lbrace", "\\}", "\\rbrace", "\\lfloor", "\\rfloor", "\u230a", "\u230b", "\\lceil", "\\rceil", "\u2308", "\u2309", "\\surd"]);
  8505. // delimiters that always stack
  8506. const stackAlwaysDelimiters = new Set(["\\uparrow", "\\downarrow", "\\updownarrow", "\\Uparrow", "\\Downarrow", "\\Updownarrow", "|", "\\|", "\\vert", "\\Vert", "\\lvert", "\\rvert", "\\lVert", "\\rVert", "\\lgroup", "\\rgroup", "\u27ee", "\u27ef", "\\lmoustache", "\\rmoustache", "\u23b0", "\u23b1"]);
  8507. // and delimiters that never stack
  8508. const stackNeverDelimiters = new Set(["<", ">", "\\langle", "\\rangle", "/", "\\backslash", "\\lt", "\\gt"]);
  8509. // Metrics of the different sizes. Found by looking at TeX's output of
  8510. // $\bigl| // \Bigl| \biggl| \Biggl| \showlists$
  8511. // Used to create stacked delimiters of appropriate sizes in makeSizedDelim.
  8512. const sizeToMaxHeight = [0, 1.2, 1.8, 2.4, 3.0];
  8513. /**
  8514. * Used to create a delimiter of a specific size, where `size` is 1, 2, 3, or 4.
  8515. */
  8516. const makeSizedDelim = function (delim, size, options, mode, classes) {
  8517. // < and > turn into \langle and \rangle in delimiters
  8518. if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
  8519. delim = "\\langle";
  8520. } else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
  8521. delim = "\\rangle";
  8522. }
  8523. // Sized delimiters are never centered.
  8524. if (stackLargeDelimiters.has(delim) || stackNeverDelimiters.has(delim)) {
  8525. return makeLargeDelim(delim, size, false, options, mode, classes);
  8526. } else if (stackAlwaysDelimiters.has(delim)) {
  8527. return makeStackedDelim(delim, sizeToMaxHeight[size], false, options, mode, classes);
  8528. } else {
  8529. throw new src_ParseError("Illegal delimiter: '" + delim + "'");
  8530. }
  8531. };
  8532. /**
  8533. * There are three different sequences of delimiter sizes that the delimiters
  8534. * follow depending on the kind of delimiter. This is used when creating custom
  8535. * sized delimiters to decide whether to create a small, large, or stacked
  8536. * delimiter.
  8537. *
  8538. * In real TeX, these sequences aren't explicitly defined, but are instead
  8539. * defined inside the font metrics. Since there are only three sequences that
  8540. * are possible for the delimiters that TeX defines, it is easier to just encode
  8541. * them explicitly here.
  8542. */
  8543. // Delimiters that never stack try small delimiters and large delimiters only
  8544. const stackNeverDelimiterSequence = [{
  8545. type: "small",
  8546. style: src_Style.SCRIPTSCRIPT
  8547. }, {
  8548. type: "small",
  8549. style: src_Style.SCRIPT
  8550. }, {
  8551. type: "small",
  8552. style: src_Style.TEXT
  8553. }, {
  8554. type: "large",
  8555. size: 1
  8556. }, {
  8557. type: "large",
  8558. size: 2
  8559. }, {
  8560. type: "large",
  8561. size: 3
  8562. }, {
  8563. type: "large",
  8564. size: 4
  8565. }];
  8566. // Delimiters that always stack try the small delimiters first, then stack
  8567. const stackAlwaysDelimiterSequence = [{
  8568. type: "small",
  8569. style: src_Style.SCRIPTSCRIPT
  8570. }, {
  8571. type: "small",
  8572. style: src_Style.SCRIPT
  8573. }, {
  8574. type: "small",
  8575. style: src_Style.TEXT
  8576. }, {
  8577. type: "stack"
  8578. }];
  8579. // Delimiters that stack when large try the small and then large delimiters, and
  8580. // stack afterwards
  8581. const stackLargeDelimiterSequence = [{
  8582. type: "small",
  8583. style: src_Style.SCRIPTSCRIPT
  8584. }, {
  8585. type: "small",
  8586. style: src_Style.SCRIPT
  8587. }, {
  8588. type: "small",
  8589. style: src_Style.TEXT
  8590. }, {
  8591. type: "large",
  8592. size: 1
  8593. }, {
  8594. type: "large",
  8595. size: 2
  8596. }, {
  8597. type: "large",
  8598. size: 3
  8599. }, {
  8600. type: "large",
  8601. size: 4
  8602. }, {
  8603. type: "stack"
  8604. }];
  8605. /**
  8606. * Get the font used in a delimiter based on what kind of delimiter it is.
  8607. * TODO(#963) Use more specific font family return type once that is introduced.
  8608. */
  8609. const delimTypeToFont = function (type) {
  8610. if (type.type === "small") {
  8611. return "Main-Regular";
  8612. } else if (type.type === "large") {
  8613. return "Size" + type.size + "-Regular";
  8614. } else if (type.type === "stack") {
  8615. return "Size4-Regular";
  8616. } else {
  8617. const delimKind = type.type;
  8618. throw new Error("Add support for delim type '" + delimKind + "' here.");
  8619. }
  8620. };
  8621. /**
  8622. * Traverse a sequence of types of delimiters to decide what kind of delimiter
  8623. * should be used to create a delimiter of the given height+depth.
  8624. */
  8625. const traverseSequence = function (delim, height, sequence, options) {
  8626. // Here, we choose the index we should start at in the sequences. In smaller
  8627. // sizes (which correspond to larger numbers in style.size) we start earlier
  8628. // in the sequence. Thus, scriptscript starts at index 3-3=0, script starts
  8629. // at index 3-2=1, text starts at 3-1=2, and display starts at min(2,3-0)=2
  8630. const start = Math.min(2, 3 - options.style.size);
  8631. for (let i = start; i < sequence.length; i++) {
  8632. const delimType = sequence[i];
  8633. if (delimType.type === "stack") {
  8634. // This is always the last delimiter, so we just break the loop now.
  8635. break;
  8636. }
  8637. const metrics = getMetrics(delim, delimTypeToFont(delimType), "math");
  8638. let heightDepth = metrics.height + metrics.depth;
  8639. // Small delimiters are scaled down versions of the same font, so we
  8640. // account for the style change size.
  8641. if (delimType.type === "small") {
  8642. const newOptions = options.havingBaseStyle(delimType.style);
  8643. heightDepth *= newOptions.sizeMultiplier;
  8644. }
  8645. // Check if the delimiter at this size works for the given height.
  8646. if (heightDepth > height) {
  8647. return delimType;
  8648. }
  8649. }
  8650. // If we reached the end of the sequence, return the last sequence element.
  8651. return sequence[sequence.length - 1];
  8652. };
  8653. /**
  8654. * Make a delimiter of a given height+depth, with optional centering. Here, we
  8655. * traverse the sequences, and create a delimiter that the sequence tells us to.
  8656. */
  8657. const makeCustomSizedDelim = function (delim, height, center, options, mode, classes) {
  8658. if (delim === "<" || delim === "\\lt" || delim === "\u27e8") {
  8659. delim = "\\langle";
  8660. } else if (delim === ">" || delim === "\\gt" || delim === "\u27e9") {
  8661. delim = "\\rangle";
  8662. }
  8663. // Decide what sequence to use
  8664. let sequence;
  8665. if (stackNeverDelimiters.has(delim)) {
  8666. sequence = stackNeverDelimiterSequence;
  8667. } else if (stackLargeDelimiters.has(delim)) {
  8668. sequence = stackLargeDelimiterSequence;
  8669. } else {
  8670. sequence = stackAlwaysDelimiterSequence;
  8671. }
  8672. // Look through the sequence
  8673. const delimType = traverseSequence(delim, height, sequence, options);
  8674. // Get the delimiter from font glyphs.
  8675. // Depending on the sequence element we decided on, call the
  8676. // appropriate function.
  8677. if (delimType.type === "small") {
  8678. return makeSmallDelim(delim, delimType.style, center, options, mode, classes);
  8679. } else if (delimType.type === "large") {
  8680. return makeLargeDelim(delim, delimType.size, center, options, mode, classes);
  8681. } else /* if (delimType.type === "stack") */{
  8682. return makeStackedDelim(delim, height, center, options, mode, classes);
  8683. }
  8684. };
  8685. /**
  8686. * Make a delimiter for use with `\left` and `\right`, given a height and depth
  8687. * of an expression that the delimiters surround.
  8688. */
  8689. const makeLeftRightDelim = function (delim, height, depth, options, mode, classes) {
  8690. // We always center \left/\right delimiters, so the axis is always shifted
  8691. const axisHeight = options.fontMetrics().axisHeight * options.sizeMultiplier;
  8692. // Taken from TeX source, tex.web, function make_left_right
  8693. const delimiterFactor = 901;
  8694. const delimiterExtend = 5.0 / options.fontMetrics().ptPerEm;
  8695. const maxDistFromAxis = Math.max(height - axisHeight, depth + axisHeight);
  8696. const totalHeight = Math.max(
  8697. // In real TeX, calculations are done using integral values which are
  8698. // 65536 per pt, or 655360 per em. So, the division here truncates in
  8699. // TeX but doesn't here, producing different results. If we wanted to
  8700. // exactly match TeX's calculation, we could do
  8701. // Math.floor(655360 * maxDistFromAxis / 500) *
  8702. // delimiterFactor / 655360
  8703. // (To see the difference, compare
  8704. // x^{x^{\left(\rule{0.1em}{0.68em}\right)}}
  8705. // in TeX and KaTeX)
  8706. maxDistFromAxis / 500 * delimiterFactor, 2 * maxDistFromAxis - delimiterExtend);
  8707. // Finally, we defer to `makeCustomSizedDelim` with our calculated total
  8708. // height
  8709. return makeCustomSizedDelim(delim, totalHeight, true, options, mode, classes);
  8710. };
  8711. ;// ./src/functions/delimsizing.ts
  8712. // Extra data needed for the delimiter handler down below
  8713. const delimiterSizes = {
  8714. "\\bigl": {
  8715. mclass: "mopen",
  8716. size: 1
  8717. },
  8718. "\\Bigl": {
  8719. mclass: "mopen",
  8720. size: 2
  8721. },
  8722. "\\biggl": {
  8723. mclass: "mopen",
  8724. size: 3
  8725. },
  8726. "\\Biggl": {
  8727. mclass: "mopen",
  8728. size: 4
  8729. },
  8730. "\\bigr": {
  8731. mclass: "mclose",
  8732. size: 1
  8733. },
  8734. "\\Bigr": {
  8735. mclass: "mclose",
  8736. size: 2
  8737. },
  8738. "\\biggr": {
  8739. mclass: "mclose",
  8740. size: 3
  8741. },
  8742. "\\Biggr": {
  8743. mclass: "mclose",
  8744. size: 4
  8745. },
  8746. "\\bigm": {
  8747. mclass: "mrel",
  8748. size: 1
  8749. },
  8750. "\\Bigm": {
  8751. mclass: "mrel",
  8752. size: 2
  8753. },
  8754. "\\biggm": {
  8755. mclass: "mrel",
  8756. size: 3
  8757. },
  8758. "\\Biggm": {
  8759. mclass: "mrel",
  8760. size: 4
  8761. },
  8762. "\\big": {
  8763. mclass: "mord",
  8764. size: 1
  8765. },
  8766. "\\Big": {
  8767. mclass: "mord",
  8768. size: 2
  8769. },
  8770. "\\bigg": {
  8771. mclass: "mord",
  8772. size: 3
  8773. },
  8774. "\\Bigg": {
  8775. mclass: "mord",
  8776. size: 4
  8777. }
  8778. };
  8779. const delimiters = new Set(["(", "\\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", "."]);
  8780. // Delimiter functions
  8781. function checkDelimiter(delim, context) {
  8782. const symDelim = checkSymbolNodeType(delim);
  8783. if (symDelim && delimiters.has(symDelim.text)) {
  8784. return symDelim;
  8785. } else if (symDelim) {
  8786. throw new src_ParseError("Invalid delimiter '" + symDelim.text + "' after '" + context.funcName + "'", delim);
  8787. } else {
  8788. throw new src_ParseError("Invalid delimiter type '" + delim.type + "'", delim);
  8789. }
  8790. }
  8791. defineFunction({
  8792. type: "delimsizing",
  8793. names: ["\\bigl", "\\Bigl", "\\biggl", "\\Biggl", "\\bigr", "\\Bigr", "\\biggr", "\\Biggr", "\\bigm", "\\Bigm", "\\biggm", "\\Biggm", "\\big", "\\Big", "\\bigg", "\\Bigg"],
  8794. props: {
  8795. numArgs: 1,
  8796. argTypes: ["primitive"]
  8797. },
  8798. handler: (context, args) => {
  8799. const delim = checkDelimiter(args[0], context);
  8800. return {
  8801. type: "delimsizing",
  8802. mode: context.parser.mode,
  8803. size: delimiterSizes[context.funcName].size,
  8804. mclass: delimiterSizes[context.funcName].mclass,
  8805. delim: delim.text
  8806. };
  8807. },
  8808. htmlBuilder: (group, options) => {
  8809. if (group.delim === ".") {
  8810. // Empty delimiters still count as elements, even though they don't
  8811. // show anything.
  8812. return makeSpan([group.mclass]);
  8813. }
  8814. return makeSizedDelim(group.delim, group.size, options, group.mode, [group.mclass]);
  8815. },
  8816. mathmlBuilder: group => {
  8817. const children = [];
  8818. if (group.delim !== ".") {
  8819. children.push(makeText(group.delim, group.mode));
  8820. }
  8821. const node = new MathNode("mo", children);
  8822. if (group.mclass === "mopen" || group.mclass === "mclose") {
  8823. // Only some of the delimsizing functions act as fences, and they
  8824. // return "mopen" or "mclose" mclass.
  8825. node.setAttribute("fence", "true");
  8826. } else {
  8827. // Explicitly disable fencing if it's not a fence, to override the
  8828. // defaults.
  8829. node.setAttribute("fence", "false");
  8830. }
  8831. node.setAttribute("stretchy", "true");
  8832. const size = makeEm(sizeToMaxHeight[group.size]);
  8833. node.setAttribute("minsize", size);
  8834. node.setAttribute("maxsize", size);
  8835. return node;
  8836. }
  8837. });
  8838. function assertParsed(group) {
  8839. if (!group.body) {
  8840. throw new Error("Bug: The leftright ParseNode wasn't fully parsed.");
  8841. }
  8842. }
  8843. defineFunction({
  8844. type: "leftright-right",
  8845. names: ["\\right"],
  8846. props: {
  8847. numArgs: 1,
  8848. primitive: true
  8849. },
  8850. handler: (context, args) => {
  8851. // \left case below triggers parsing of \right in
  8852. // `const right = parser.parseFunction();`
  8853. // uses this return value.
  8854. const color = context.parser.gullet.macros.get("\\current@color");
  8855. if (color && typeof color !== "string") {
  8856. throw new src_ParseError("\\current@color set to non-string in \\right");
  8857. }
  8858. return {
  8859. type: "leftright-right",
  8860. mode: context.parser.mode,
  8861. delim: checkDelimiter(args[0], context).text,
  8862. color: color // undefined if not set via \color
  8863. };
  8864. }
  8865. });
  8866. defineFunction({
  8867. type: "leftright",
  8868. names: ["\\left"],
  8869. props: {
  8870. numArgs: 1,
  8871. primitive: true
  8872. },
  8873. handler: (context, args) => {
  8874. const delim = checkDelimiter(args[0], context);
  8875. const parser = context.parser;
  8876. // Parse out the implicit body
  8877. ++parser.leftrightDepth;
  8878. // parseExpression stops before '\\right'
  8879. const body = parser.parseExpression(false);
  8880. --parser.leftrightDepth;
  8881. // Check the next token
  8882. parser.expect("\\right", false);
  8883. const right = assertNodeType(parser.parseFunction(), "leftright-right");
  8884. return {
  8885. type: "leftright",
  8886. mode: parser.mode,
  8887. body,
  8888. left: delim.text,
  8889. right: right.delim,
  8890. rightColor: right.color
  8891. };
  8892. },
  8893. htmlBuilder: (group, options) => {
  8894. assertParsed(group);
  8895. // Build the inner expression
  8896. const inner = buildExpression(group.body, options, true, ["mopen", "mclose"]);
  8897. let innerHeight = 0;
  8898. let innerDepth = 0;
  8899. let hadMiddle = false;
  8900. // Calculate its height and depth
  8901. for (let i = 0; i < inner.length; i++) {
  8902. // Property `isMiddle` not defined on `span`. See comment in
  8903. // "middle"'s htmlBuilder.
  8904. // TODO(ts)
  8905. if (inner[i].isMiddle) {
  8906. hadMiddle = true;
  8907. } else {
  8908. innerHeight = Math.max(inner[i].height, innerHeight);
  8909. innerDepth = Math.max(inner[i].depth, innerDepth);
  8910. }
  8911. }
  8912. // The size of delimiters is the same, regardless of what style we are
  8913. // in. Thus, to correctly calculate the size of delimiter we need around
  8914. // a group, we scale down the inner size based on the size.
  8915. innerHeight *= options.sizeMultiplier;
  8916. innerDepth *= options.sizeMultiplier;
  8917. let leftDelim;
  8918. if (group.left === ".") {
  8919. // Empty delimiters in \left and \right make null delimiter spaces.
  8920. leftDelim = makeNullDelimiter(options, ["mopen"]);
  8921. } else {
  8922. // Otherwise, use leftRightDelim to generate the correct sized
  8923. // delimiter.
  8924. leftDelim = makeLeftRightDelim(group.left, innerHeight, innerDepth, options, group.mode, ["mopen"]);
  8925. }
  8926. // Add it to the beginning of the expression
  8927. inner.unshift(leftDelim);
  8928. // Handle middle delimiters
  8929. if (hadMiddle) {
  8930. for (let i = 1; i < inner.length; i++) {
  8931. const middleDelim = inner[i];
  8932. // Property `isMiddle` not defined on `span`. See comment in
  8933. // "middle"'s htmlBuilder.
  8934. // TODO(ts)
  8935. const isMiddle = middleDelim.isMiddle;
  8936. if (isMiddle) {
  8937. // Apply the options that were active when \middle was called
  8938. inner[i] = makeLeftRightDelim(isMiddle.delim, innerHeight, innerDepth, isMiddle.options, group.mode, []);
  8939. }
  8940. }
  8941. }
  8942. let rightDelim;
  8943. // Same for the right delimiter, but using color specified by \color
  8944. if (group.right === ".") {
  8945. rightDelim = makeNullDelimiter(options, ["mclose"]);
  8946. } else {
  8947. const colorOptions = group.rightColor ? options.withColor(group.rightColor) : options;
  8948. rightDelim = makeLeftRightDelim(group.right, innerHeight, innerDepth, colorOptions, group.mode, ["mclose"]);
  8949. }
  8950. // Add it to the end of the expression.
  8951. inner.push(rightDelim);
  8952. return makeSpan(["minner"], inner, options);
  8953. },
  8954. mathmlBuilder: (group, options) => {
  8955. assertParsed(group);
  8956. const inner = buildMathML_buildExpression(group.body, options);
  8957. if (group.left !== ".") {
  8958. const leftNode = new MathNode("mo", [makeText(group.left, group.mode)]);
  8959. leftNode.setAttribute("fence", "true");
  8960. inner.unshift(leftNode);
  8961. }
  8962. if (group.right !== ".") {
  8963. const rightNode = new MathNode("mo", [makeText(group.right, group.mode)]);
  8964. rightNode.setAttribute("fence", "true");
  8965. if (group.rightColor) {
  8966. rightNode.setAttribute("mathcolor", group.rightColor);
  8967. }
  8968. inner.push(rightNode);
  8969. }
  8970. return makeRow(inner);
  8971. }
  8972. });
  8973. defineFunction({
  8974. type: "middle",
  8975. names: ["\\middle"],
  8976. props: {
  8977. numArgs: 1,
  8978. primitive: true
  8979. },
  8980. handler: (context, args) => {
  8981. const delim = checkDelimiter(args[0], context);
  8982. if (!context.parser.leftrightDepth) {
  8983. throw new src_ParseError("\\middle without preceding \\left", delim);
  8984. }
  8985. return {
  8986. type: "middle",
  8987. mode: context.parser.mode,
  8988. delim: delim.text
  8989. };
  8990. },
  8991. htmlBuilder: (group, options) => {
  8992. let middleDelim;
  8993. if (group.delim === ".") {
  8994. middleDelim = makeNullDelimiter(options, []);
  8995. } else {
  8996. middleDelim = makeSizedDelim(group.delim, 1, options, group.mode, []);
  8997. const isMiddle = {
  8998. delim: group.delim,
  8999. options
  9000. };
  9001. // Property `isMiddle` not defined on `span`. It is only used in
  9002. // this file above.
  9003. // TODO: Fix this violation of the `span` type and possibly rename
  9004. // things since `isMiddle` sounds like a boolean, but is a struct.
  9005. // TODO(ts)
  9006. middleDelim.isMiddle = isMiddle;
  9007. }
  9008. return middleDelim;
  9009. },
  9010. mathmlBuilder: (group, options) => {
  9011. // A Firefox \middle will stretch a character vertically only if it
  9012. // is in the fence part of the operator dictionary at:
  9013. // https://www.w3.org/TR/MathML3/appendixc.html.
  9014. // So we need to avoid U+2223 and use plain "|" instead.
  9015. const textNode = group.delim === "\\vert" || group.delim === "|" ? makeText("|", "text") : makeText(group.delim, group.mode);
  9016. const middleNode = new MathNode("mo", [textNode]);
  9017. middleNode.setAttribute("fence", "true");
  9018. // MathML gives 5/18em spacing to each <mo> element.
  9019. // \middle should get delimiter spacing instead.
  9020. middleNode.setAttribute("lspace", "0.05em");
  9021. middleNode.setAttribute("rspace", "0.05em");
  9022. return middleNode;
  9023. }
  9024. });
  9025. ;// ./src/functions/enclose.ts
  9026. const enclose_htmlBuilder = (group, options) => {
  9027. // \cancel, \bcancel, \xcancel, \sout, \fbox, \colorbox, \fcolorbox, \phase
  9028. // Some groups can return document fragments. Handle those by wrapping
  9029. // them in a span.
  9030. const inner = wrapFragment(buildGroup(group.body, options), options);
  9031. const label = group.label.slice(1);
  9032. let scale = options.sizeMultiplier;
  9033. let img;
  9034. let imgShift = 0;
  9035. // In the LaTeX cancel package, line geometry is slightly different
  9036. // depending on whether the subject is wider than it is tall, or vice versa.
  9037. // We don't know the width of a group, so as a proxy, we test if
  9038. // the subject is a single character. This captures most of the
  9039. // subjects that should get the "tall" treatment.
  9040. const isSingleChar = isCharacterBox(group.body);
  9041. if (label === "sout") {
  9042. img = makeSpan(["stretchy", "sout"]);
  9043. img.height = options.fontMetrics().defaultRuleThickness / scale;
  9044. imgShift = -0.5 * options.fontMetrics().xHeight;
  9045. } else if (label === "phase") {
  9046. // Set a couple of dimensions from the steinmetz package.
  9047. const lineWeight = calculateSize({
  9048. number: 0.6,
  9049. unit: "pt"
  9050. }, options);
  9051. const clearance = calculateSize({
  9052. number: 0.35,
  9053. unit: "ex"
  9054. }, options);
  9055. // Prevent size changes like \Huge from affecting line thickness
  9056. const newOptions = options.havingBaseSizing();
  9057. scale = scale / newOptions.sizeMultiplier;
  9058. const angleHeight = inner.height + inner.depth + lineWeight + clearance;
  9059. // Reserve a left pad for the angle.
  9060. inner.style.paddingLeft = makeEm(angleHeight / 2 + lineWeight);
  9061. // Create an SVG
  9062. const viewBoxHeight = Math.floor(1000 * angleHeight * scale);
  9063. const path = phasePath(viewBoxHeight);
  9064. const svgNode = new SvgNode([new PathNode("phase", path)], {
  9065. "width": "400em",
  9066. "height": makeEm(viewBoxHeight / 1000),
  9067. "viewBox": "0 0 400000 " + viewBoxHeight,
  9068. "preserveAspectRatio": "xMinYMin slice"
  9069. });
  9070. // Wrap it in a span with overflow: hidden.
  9071. img = makeSvgSpan(["hide-tail"], [svgNode], options);
  9072. img.style.height = makeEm(angleHeight);
  9073. imgShift = inner.depth + lineWeight + clearance;
  9074. } else {
  9075. // Add horizontal padding
  9076. if (/cancel/.test(label)) {
  9077. if (!isSingleChar) {
  9078. inner.classes.push("cancel-pad");
  9079. }
  9080. } else if (label === "angl") {
  9081. inner.classes.push("anglpad");
  9082. } else {
  9083. inner.classes.push("boxpad");
  9084. }
  9085. // Add vertical padding
  9086. let topPad = 0;
  9087. let bottomPad = 0;
  9088. let ruleThickness = 0;
  9089. // ref: cancel package: \advance\totalheight2\p@ % "+2"
  9090. if (/box/.test(label)) {
  9091. ruleThickness = Math.max(options.fontMetrics().fboxrule,
  9092. // default
  9093. options.minRuleThickness // User override.
  9094. );
  9095. topPad = options.fontMetrics().fboxsep + (label === "colorbox" ? 0 : ruleThickness);
  9096. bottomPad = topPad;
  9097. } else if (label === "angl") {
  9098. ruleThickness = Math.max(options.fontMetrics().defaultRuleThickness, options.minRuleThickness);
  9099. topPad = 4 * ruleThickness; // gap = 3 × line, plus the line itself.
  9100. bottomPad = Math.max(0, 0.25 - inner.depth);
  9101. } else {
  9102. topPad = isSingleChar ? 0.2 : 0;
  9103. bottomPad = topPad;
  9104. }
  9105. img = stretchyEnclose(inner, label, topPad, bottomPad, options);
  9106. if (/fbox|boxed|fcolorbox/.test(label)) {
  9107. img.style.borderStyle = "solid";
  9108. img.style.borderWidth = makeEm(ruleThickness);
  9109. } else if (label === "angl" && ruleThickness !== 0.049) {
  9110. img.style.borderTopWidth = makeEm(ruleThickness);
  9111. img.style.borderRightWidth = makeEm(ruleThickness);
  9112. }
  9113. imgShift = inner.depth + bottomPad;
  9114. if (group.backgroundColor) {
  9115. img.style.backgroundColor = group.backgroundColor;
  9116. if (group.borderColor) {
  9117. img.style.borderColor = group.borderColor;
  9118. }
  9119. }
  9120. }
  9121. let vlist;
  9122. if (group.backgroundColor) {
  9123. vlist = makeVList({
  9124. positionType: "individualShift",
  9125. children: [
  9126. // Put the color background behind inner;
  9127. {
  9128. type: "elem",
  9129. elem: img,
  9130. shift: imgShift
  9131. }, {
  9132. type: "elem",
  9133. elem: inner,
  9134. shift: 0
  9135. }]
  9136. }, options);
  9137. } else {
  9138. const classes = /cancel|phase/.test(label) ? ["svg-align"] : [];
  9139. vlist = makeVList({
  9140. positionType: "individualShift",
  9141. children: [
  9142. // Write the \cancel stroke on top of inner.
  9143. {
  9144. type: "elem",
  9145. elem: inner,
  9146. shift: 0
  9147. }, {
  9148. type: "elem",
  9149. elem: img,
  9150. shift: imgShift,
  9151. wrapperClasses: classes
  9152. }]
  9153. }, options);
  9154. }
  9155. if (/cancel/.test(label)) {
  9156. // The cancel package documentation says that cancel lines add their height
  9157. // to the expression, but tests show that isn't how it actually works.
  9158. vlist.height = inner.height;
  9159. vlist.depth = inner.depth;
  9160. }
  9161. if (/cancel/.test(label) && !isSingleChar) {
  9162. // cancel does not create horiz space for its line extension.
  9163. return makeSpan(["mord", "cancel-lap"], [vlist], options);
  9164. } else {
  9165. return makeSpan(["mord"], [vlist], options);
  9166. }
  9167. };
  9168. const enclose_mathmlBuilder = (group, options) => {
  9169. let fboxsep = 0;
  9170. const node = new MathNode(group.label.includes("colorbox") ? "mpadded" : "menclose", [buildMathML_buildGroup(group.body, options)]);
  9171. switch (group.label) {
  9172. case "\\cancel":
  9173. node.setAttribute("notation", "updiagonalstrike");
  9174. break;
  9175. case "\\bcancel":
  9176. node.setAttribute("notation", "downdiagonalstrike");
  9177. break;
  9178. case "\\phase":
  9179. node.setAttribute("notation", "phasorangle");
  9180. break;
  9181. case "\\sout":
  9182. node.setAttribute("notation", "horizontalstrike");
  9183. break;
  9184. case "\\fbox":
  9185. node.setAttribute("notation", "box");
  9186. break;
  9187. case "\\angl":
  9188. node.setAttribute("notation", "actuarial");
  9189. break;
  9190. case "\\fcolorbox":
  9191. case "\\colorbox":
  9192. // <menclose> doesn't have a good notation option. So use <mpadded>
  9193. // instead. Set some attributes that come included with <menclose>.
  9194. fboxsep = options.fontMetrics().fboxsep * options.fontMetrics().ptPerEm;
  9195. node.setAttribute("width", "+" + 2 * fboxsep + "pt");
  9196. node.setAttribute("height", "+" + 2 * fboxsep + "pt");
  9197. node.setAttribute("lspace", fboxsep + "pt"); //
  9198. node.setAttribute("voffset", fboxsep + "pt");
  9199. if (group.label === "\\fcolorbox") {
  9200. const thk = Math.max(options.fontMetrics().fboxrule,
  9201. // default
  9202. options.minRuleThickness // user override
  9203. );
  9204. node.setAttribute("style", "border: " + makeEm(thk) + " solid " + group.borderColor);
  9205. }
  9206. break;
  9207. case "\\xcancel":
  9208. node.setAttribute("notation", "updiagonalstrike downdiagonalstrike");
  9209. break;
  9210. }
  9211. if (group.backgroundColor) {
  9212. node.setAttribute("mathbackground", group.backgroundColor);
  9213. }
  9214. return node;
  9215. };
  9216. defineFunction({
  9217. type: "enclose",
  9218. names: ["\\colorbox"],
  9219. props: {
  9220. numArgs: 2,
  9221. allowedInText: true,
  9222. argTypes: ["color", "text"]
  9223. },
  9224. handler(_ref, args, optArgs) {
  9225. let {
  9226. parser,
  9227. funcName
  9228. } = _ref;
  9229. const color = assertNodeType(args[0], "color-token").color;
  9230. const body = args[1];
  9231. return {
  9232. type: "enclose",
  9233. mode: parser.mode,
  9234. label: funcName,
  9235. backgroundColor: color,
  9236. body
  9237. };
  9238. },
  9239. htmlBuilder: enclose_htmlBuilder,
  9240. mathmlBuilder: enclose_mathmlBuilder
  9241. });
  9242. defineFunction({
  9243. type: "enclose",
  9244. names: ["\\fcolorbox"],
  9245. props: {
  9246. numArgs: 3,
  9247. allowedInText: true,
  9248. argTypes: ["color", "color", "text"]
  9249. },
  9250. handler(_ref2, args, optArgs) {
  9251. let {
  9252. parser,
  9253. funcName
  9254. } = _ref2;
  9255. const borderColor = assertNodeType(args[0], "color-token").color;
  9256. const backgroundColor = assertNodeType(args[1], "color-token").color;
  9257. const body = args[2];
  9258. return {
  9259. type: "enclose",
  9260. mode: parser.mode,
  9261. label: funcName,
  9262. backgroundColor,
  9263. borderColor,
  9264. body
  9265. };
  9266. },
  9267. htmlBuilder: enclose_htmlBuilder,
  9268. mathmlBuilder: enclose_mathmlBuilder
  9269. });
  9270. defineFunction({
  9271. type: "enclose",
  9272. names: ["\\fbox"],
  9273. props: {
  9274. numArgs: 1,
  9275. argTypes: ["hbox"],
  9276. allowedInText: true
  9277. },
  9278. handler(_ref3, args) {
  9279. let {
  9280. parser
  9281. } = _ref3;
  9282. return {
  9283. type: "enclose",
  9284. mode: parser.mode,
  9285. label: "\\fbox",
  9286. body: args[0]
  9287. };
  9288. }
  9289. });
  9290. defineFunction({
  9291. type: "enclose",
  9292. names: ["\\cancel", "\\bcancel", "\\xcancel", "\\phase"],
  9293. props: {
  9294. numArgs: 1
  9295. },
  9296. handler(_ref4, args) {
  9297. let {
  9298. parser,
  9299. funcName
  9300. } = _ref4;
  9301. const body = args[0];
  9302. return {
  9303. type: "enclose",
  9304. mode: parser.mode,
  9305. label: funcName,
  9306. body
  9307. };
  9308. },
  9309. htmlBuilder: enclose_htmlBuilder,
  9310. mathmlBuilder: enclose_mathmlBuilder
  9311. });
  9312. defineFunction({
  9313. type: "enclose",
  9314. names: ["\\sout"],
  9315. props: {
  9316. numArgs: 1,
  9317. allowedInText: true
  9318. },
  9319. handler(_ref5, args) {
  9320. let {
  9321. parser,
  9322. funcName
  9323. } = _ref5;
  9324. if (parser.mode === "math") {
  9325. parser.settings.reportNonstrict("mathVsSout", "LaTeX's \\sout works only in text mode");
  9326. }
  9327. const body = args[0];
  9328. return {
  9329. type: "enclose",
  9330. mode: parser.mode,
  9331. label: funcName,
  9332. body
  9333. };
  9334. },
  9335. htmlBuilder: enclose_htmlBuilder,
  9336. mathmlBuilder: enclose_mathmlBuilder
  9337. });
  9338. defineFunction({
  9339. type: "enclose",
  9340. names: ["\\angl"],
  9341. props: {
  9342. numArgs: 1,
  9343. argTypes: ["hbox"],
  9344. allowedInText: false
  9345. },
  9346. handler(_ref6, args) {
  9347. let {
  9348. parser
  9349. } = _ref6;
  9350. return {
  9351. type: "enclose",
  9352. mode: parser.mode,
  9353. label: "\\angl",
  9354. body: args[0]
  9355. };
  9356. }
  9357. });
  9358. ;// ./src/defineEnvironment.ts
  9359. /**
  9360. * The context contains the following properties:
  9361. * - mode: current parsing mode.
  9362. * - envName: the name of the environment, one of the listed names.
  9363. * - parser: the parser object.
  9364. */
  9365. /**
  9366. * - context: information and references provided by the parser
  9367. * - args: an array of arguments passed to \begin{name}
  9368. * - optArgs: an array of optional arguments passed to \begin{name}
  9369. */
  9370. /**
  9371. * - numArgs: (default 0) The number of arguments after the \begin{name} function.
  9372. * - argTypes: (optional) Just like for a function
  9373. * - allowedInText: (default false) Whether or not the environment is allowed
  9374. * inside text mode (not enforced yet).
  9375. * - numOptionalArgs: (default 0) Just like for a function
  9376. */
  9377. /**
  9378. * Final environment spec for use at parse time.
  9379. * This is almost identical to `EnvDefSpec`, except it
  9380. * 1. includes the function handler
  9381. * 2. requires all arguments except argType
  9382. * It is generated by `defineEnvironment()` below.
  9383. */
  9384. /**
  9385. * All registered environments.
  9386. * `environments.js` exports this same dictionary again and makes it public.
  9387. * `Parser.js` requires this dictionary via `environments.js`.
  9388. */
  9389. const _environments = {};
  9390. function defineEnvironment(_ref) {
  9391. let {
  9392. type,
  9393. names,
  9394. props,
  9395. handler,
  9396. htmlBuilder,
  9397. mathmlBuilder
  9398. } = _ref;
  9399. // Set default values of environments.
  9400. const data = {
  9401. type,
  9402. numArgs: props.numArgs || 0,
  9403. allowedInText: false,
  9404. numOptionalArgs: 0,
  9405. handler
  9406. };
  9407. for (let i = 0; i < names.length; ++i) {
  9408. // TODO: The value type of _environments should be a type union of all
  9409. // possible `EnvSpec<>` possibilities instead of `EnvSpec<*>`, which is
  9410. // an existential type.
  9411. _environments[names[i]] = data;
  9412. }
  9413. if (htmlBuilder) {
  9414. _htmlGroupBuilders[type] = htmlBuilder;
  9415. }
  9416. if (mathmlBuilder) {
  9417. _mathmlGroupBuilders[type] = mathmlBuilder;
  9418. }
  9419. }
  9420. ;// ./src/defineMacro.ts
  9421. /**
  9422. * Provides context to macros defined by functions. Implemented by
  9423. * MacroExpander.
  9424. */
  9425. /** Macro tokens (in reverse order). */
  9426. /**
  9427. * All registered global/built-in macros.
  9428. * `macros.js` exports this same dictionary again and makes it public.
  9429. * `Parser.js` requires this dictionary via `macros.js`.
  9430. */
  9431. const _macros = {};
  9432. // This function might one day accept an additional argument and do more things.
  9433. function defineMacro(name, body) {
  9434. _macros[name] = body;
  9435. }
  9436. ;// ./src/SourceLocation.ts
  9437. /**
  9438. * Lexing or parsing positional information for error reporting.
  9439. * This object is immutable.
  9440. */
  9441. class SourceLocation {
  9442. // The + prefix indicates that these fields aren't writeable
  9443. // Lexer holding the input string.
  9444. // Start offset, zero-based inclusive.
  9445. // End offset, zero-based exclusive.
  9446. constructor(lexer, start, end) {
  9447. this.lexer = lexer;
  9448. this.start = start;
  9449. this.end = end;
  9450. }
  9451. /**
  9452. * Merges two `SourceLocation`s from location providers, given they are
  9453. * provided in order of appearance.
  9454. * - Returns the first one's location if only the first is provided.
  9455. * - Returns a merged range of the first and the last if both are provided
  9456. * and their lexers match.
  9457. * - Otherwise, returns null.
  9458. */
  9459. static range(first, second) {
  9460. if (!second) {
  9461. return first && first.loc;
  9462. } else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) {
  9463. return null;
  9464. } else {
  9465. return new SourceLocation(first.loc.lexer, first.loc.start, second.loc.end);
  9466. }
  9467. }
  9468. }
  9469. ;// ./src/Token.ts
  9470. /**
  9471. * Interface required to break circular dependency between Token, Lexer, and
  9472. * ParseError.
  9473. */
  9474. /**
  9475. * The resulting token returned from `lex`.
  9476. *
  9477. * It consists of the token text plus some position information.
  9478. * The position information is essentially a range in an input string,
  9479. * but instead of referencing the bare input string, we refer to the lexer.
  9480. * That way it is possible to attach extra metadata to the input string,
  9481. * like for example a file name or similar.
  9482. *
  9483. * The position information is optional, so it is OK to construct synthetic
  9484. * tokens if appropriate. Not providing available position information may
  9485. * lead to degraded error reporting, though.
  9486. */
  9487. class Token {
  9488. // don't expand the token
  9489. // used in \noexpand
  9490. constructor(text,
  9491. // the text of this token
  9492. loc) {
  9493. this.text = text;
  9494. this.loc = loc;
  9495. }
  9496. /**
  9497. * Given a pair of tokens (this and endToken), compute a `Token` encompassing
  9498. * the whole input range enclosed by these two.
  9499. */
  9500. range(endToken,
  9501. // last token of the range, inclusive
  9502. text // the text of the newly constructed token
  9503. ) {
  9504. return new Token(text, SourceLocation.range(this, endToken));
  9505. }
  9506. }
  9507. ;// ./src/environments/array.ts
  9508. // Data stored in the ParseNode associated with the environment.
  9509. // Type to indicate column separation in MathML
  9510. // Helper functions
  9511. function getHLines(parser) {
  9512. // Return an array. The array length = number of hlines.
  9513. // Each element in the array tells if the line is dashed.
  9514. const hlineInfo = [];
  9515. parser.consumeSpaces();
  9516. let nxt = parser.fetch().text;
  9517. if (nxt === "\\relax") {
  9518. // \relax is an artifact of the \cr macro below
  9519. parser.consume();
  9520. parser.consumeSpaces();
  9521. nxt = parser.fetch().text;
  9522. }
  9523. while (nxt === "\\hline" || nxt === "\\hdashline") {
  9524. parser.consume();
  9525. hlineInfo.push(nxt === "\\hdashline");
  9526. parser.consumeSpaces();
  9527. nxt = parser.fetch().text;
  9528. }
  9529. return hlineInfo;
  9530. }
  9531. const validateAmsEnvironmentContext = context => {
  9532. const settings = context.parser.settings;
  9533. if (!settings.displayMode) {
  9534. throw new src_ParseError("{" + context.envName + "} can be used only in" + " display mode.");
  9535. }
  9536. };
  9537. const gatherEnvironments = new Set(["gather", "gather*"]);
  9538. // autoTag (an argument to parseArray) can be one of three values:
  9539. // * undefined: Regular (not-top-level) array; no tags on each row
  9540. // * true: Automatic equation numbering, overridable by \tag
  9541. // * false: Tags allowed on each row, but no automatic numbering
  9542. // This function *doesn't* work with the "split" environment name.
  9543. function getAutoTag(name) {
  9544. if (!name.includes("ed")) {
  9545. return !name.includes("*");
  9546. }
  9547. // return undefined;
  9548. }
  9549. /**
  9550. * Parse the body of the environment, with rows delimited by \\ and
  9551. * columns delimited by &, and create a nested list in row-major order
  9552. * with one group per cell. If given an optional argument style
  9553. * ("text", "display", etc.), then each cell is cast into that style.
  9554. */
  9555. function parseArray(parser, _ref, style) {
  9556. let {
  9557. hskipBeforeAndAfter,
  9558. addJot,
  9559. cols,
  9560. arraystretch,
  9561. colSeparationType,
  9562. autoTag,
  9563. singleRow,
  9564. emptySingleRow,
  9565. maxNumCols,
  9566. leqno
  9567. } = _ref;
  9568. parser.gullet.beginGroup();
  9569. if (!singleRow) {
  9570. // \cr is equivalent to \\ without the optional size argument (see below)
  9571. // TODO: provide helpful error when \cr is used outside array environment
  9572. parser.gullet.macros.set("\\cr", "\\\\\\relax");
  9573. }
  9574. // Get current arraystretch if it's not set by the environment
  9575. if (!arraystretch) {
  9576. const stretch = parser.gullet.expandMacroAsText("\\arraystretch");
  9577. if (stretch == null) {
  9578. // Default \arraystretch from lttab.dtx
  9579. arraystretch = 1;
  9580. } else {
  9581. arraystretch = parseFloat(stretch);
  9582. if (!arraystretch || arraystretch < 0) {
  9583. throw new src_ParseError("Invalid \\arraystretch: " + stretch);
  9584. }
  9585. }
  9586. }
  9587. // Start group for first cell
  9588. parser.gullet.beginGroup();
  9589. let row = [];
  9590. const body = [row];
  9591. const rowGaps = [];
  9592. const hLinesBeforeRow = [];
  9593. const tags = autoTag != null ? [] : undefined;
  9594. // amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
  9595. // whether this row should have an equation number. Simulate this with
  9596. // a \@eqnsw macro set to 1 or 0.
  9597. function beginRow() {
  9598. if (autoTag) {
  9599. parser.gullet.macros.set("\\@eqnsw", "1", true);
  9600. }
  9601. }
  9602. function endRow() {
  9603. if (tags) {
  9604. if (parser.gullet.macros.get("\\df@tag")) {
  9605. tags.push(parser.subparse([new Token("\\df@tag")]));
  9606. parser.gullet.macros.set("\\df@tag", undefined, true);
  9607. } else {
  9608. tags.push(Boolean(autoTag) && parser.gullet.macros.get("\\@eqnsw") === "1");
  9609. }
  9610. }
  9611. }
  9612. beginRow();
  9613. // Test for \hline at the top of the array.
  9614. hLinesBeforeRow.push(getHLines(parser));
  9615. while (true) {
  9616. // eslint-disable-line no-constant-condition
  9617. // Parse each cell in its own group (namespace)
  9618. const cellBody = parser.parseExpression(false, singleRow ? "\\end" : "\\\\");
  9619. parser.gullet.endGroup();
  9620. parser.gullet.beginGroup();
  9621. let cell = {
  9622. type: "ordgroup",
  9623. mode: parser.mode,
  9624. body: cellBody
  9625. };
  9626. if (style) {
  9627. cell = {
  9628. type: "styling",
  9629. mode: parser.mode,
  9630. style,
  9631. body: [cell]
  9632. };
  9633. }
  9634. row.push(cell);
  9635. const next = parser.fetch().text;
  9636. if (next === "&") {
  9637. if (maxNumCols && row.length === maxNumCols) {
  9638. if (singleRow || colSeparationType) {
  9639. // {equation} or {split}
  9640. throw new src_ParseError("Too many tab characters: &", parser.nextToken);
  9641. } else {
  9642. // {array} environment
  9643. parser.settings.reportNonstrict("textEnv", "Too few columns " + "specified in the {array} column argument.");
  9644. }
  9645. }
  9646. parser.consume();
  9647. } else if (next === "\\end") {
  9648. endRow();
  9649. // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
  9650. // the last line is empty. However, AMS environments keep the
  9651. // empty row if it's the only one.
  9652. // NOTE: Currently, `cell` is the last item added into `row`.
  9653. if (row.length === 1 && cell.type === "styling" && cell.body.length === 1 && cell.body[0].type === "ordgroup" && cell.body[0].body.length === 0 && (body.length > 1 || !emptySingleRow)) {
  9654. body.pop();
  9655. }
  9656. if (hLinesBeforeRow.length < body.length + 1) {
  9657. hLinesBeforeRow.push([]);
  9658. }
  9659. break;
  9660. } else if (next === "\\\\") {
  9661. parser.consume();
  9662. let size;
  9663. // \def\Let@{\let\\\math@cr}
  9664. // \def\math@cr{...\math@cr@}
  9665. // \def\math@cr@{\new@ifnextchar[\math@cr@@{\math@cr@@[\z@]}}
  9666. // \def\math@cr@@[#1]{...\math@cr@@@...}
  9667. // \def\math@cr@@@{\cr}
  9668. if (parser.gullet.future().text !== " ") {
  9669. size = parser.parseSizeGroup(true);
  9670. }
  9671. rowGaps.push(size ? size.value : null);
  9672. endRow();
  9673. // check for \hline(s) following the row separator
  9674. hLinesBeforeRow.push(getHLines(parser));
  9675. row = [];
  9676. body.push(row);
  9677. beginRow();
  9678. } else {
  9679. throw new src_ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
  9680. }
  9681. }
  9682. // End cell group
  9683. parser.gullet.endGroup();
  9684. // End array group defining \cr
  9685. parser.gullet.endGroup();
  9686. return {
  9687. type: "array",
  9688. mode: parser.mode,
  9689. addJot,
  9690. arraystretch,
  9691. body,
  9692. cols,
  9693. rowGaps,
  9694. hskipBeforeAndAfter,
  9695. hLinesBeforeRow,
  9696. colSeparationType,
  9697. tags,
  9698. leqno
  9699. };
  9700. }
  9701. // Decides on a style for cells in an array according to whether the given
  9702. // environment name starts with the letter 'd'.
  9703. function dCellStyle(envName) {
  9704. if (envName.slice(0, 1) === "d") {
  9705. return "display";
  9706. } else {
  9707. return "text";
  9708. }
  9709. }
  9710. const array_htmlBuilder = function (group, options) {
  9711. let r;
  9712. let c;
  9713. const nr = group.body.length;
  9714. const hLinesBeforeRow = group.hLinesBeforeRow;
  9715. let nc = 0;
  9716. const body = new Array(nr);
  9717. const hlines = [];
  9718. const ruleThickness = Math.max(
  9719. // From LaTeX \showthe\arrayrulewidth. Equals 0.04 em.
  9720. options.fontMetrics().arrayRuleWidth, options.minRuleThickness // User override.
  9721. );
  9722. // Horizontal spacing
  9723. const pt = 1 / options.fontMetrics().ptPerEm;
  9724. let arraycolsep = 5 * pt; // default value, i.e. \arraycolsep in article.cls
  9725. if (group.colSeparationType && group.colSeparationType === "small") {
  9726. // We're in a {smallmatrix}. Default column space is \thickspace,
  9727. // i.e. 5/18em = 0.2778em, per amsmath.dtx for {smallmatrix}.
  9728. // But that needs adjustment because LaTeX applies \scriptstyle to the
  9729. // entire array, including the colspace, but this function applies
  9730. // \scriptstyle only inside each element.
  9731. const localMultiplier = options.havingStyle(src_Style.SCRIPT).sizeMultiplier;
  9732. arraycolsep = 0.2778 * (localMultiplier / options.sizeMultiplier);
  9733. }
  9734. // Vertical spacing
  9735. const baselineskip = group.colSeparationType === "CD" ? calculateSize({
  9736. number: 3,
  9737. unit: "ex"
  9738. }, options) : 12 * pt; // see size10.clo
  9739. // Default \jot from ltmath.dtx
  9740. // TODO(edemaine): allow overriding \jot via \setlength (#687)
  9741. const jot = 3 * pt;
  9742. const arrayskip = group.arraystretch * baselineskip;
  9743. const arstrutHeight = 0.7 * arrayskip; // \strutbox in ltfsstrc.dtx and
  9744. const arstrutDepth = 0.3 * arrayskip; // \@arstrutbox in lttab.dtx
  9745. let totalHeight = 0;
  9746. // Set a position for \hline(s) at the top of the array, if any.
  9747. function setHLinePos(hlinesInGap) {
  9748. for (let i = 0; i < hlinesInGap.length; ++i) {
  9749. if (i > 0) {
  9750. totalHeight += 0.25;
  9751. }
  9752. hlines.push({
  9753. pos: totalHeight,
  9754. isDashed: hlinesInGap[i]
  9755. });
  9756. }
  9757. }
  9758. setHLinePos(hLinesBeforeRow[0]);
  9759. for (r = 0; r < group.body.length; ++r) {
  9760. const inrow = group.body[r];
  9761. let height = arstrutHeight; // \@array adds an \@arstrut
  9762. let depth = arstrutDepth; // to each tow (via the template)
  9763. if (nc < inrow.length) {
  9764. nc = inrow.length;
  9765. }
  9766. const outrow = new Array(inrow.length);
  9767. for (c = 0; c < inrow.length; ++c) {
  9768. const elt = buildGroup(inrow[c], options);
  9769. if (depth < elt.depth) {
  9770. depth = elt.depth;
  9771. }
  9772. if (height < elt.height) {
  9773. height = elt.height;
  9774. }
  9775. outrow[c] = elt;
  9776. }
  9777. const rowGap = group.rowGaps[r];
  9778. let gap = 0;
  9779. if (rowGap) {
  9780. gap = calculateSize(rowGap, options);
  9781. if (gap > 0) {
  9782. // \@argarraycr
  9783. gap += arstrutDepth;
  9784. if (depth < gap) {
  9785. depth = gap; // \@xargarraycr
  9786. }
  9787. gap = 0;
  9788. }
  9789. }
  9790. // In AMS multiline environments such as aligned and gathered, rows
  9791. // correspond to lines that have additional \jot added between lines
  9792. // via \openup.
  9793. // We simulate this by adding \jot depth to each row except the last.
  9794. if (group.addJot && r < group.body.length - 1) {
  9795. depth += jot;
  9796. }
  9797. outrow.height = height;
  9798. outrow.depth = depth;
  9799. totalHeight += height;
  9800. outrow.pos = totalHeight;
  9801. totalHeight += depth + gap; // \@yargarraycr
  9802. body[r] = outrow;
  9803. // Set a position for \hline(s), if any.
  9804. setHLinePos(hLinesBeforeRow[r + 1]);
  9805. }
  9806. const offset = totalHeight / 2 + options.fontMetrics().axisHeight;
  9807. const colDescriptions = group.cols || [];
  9808. const cols = [];
  9809. let colSep;
  9810. let colDescrNum;
  9811. const tagSpans = [];
  9812. if (group.tags && group.tags.some(tag => tag)) {
  9813. // An environment with manual tags and/or automatic equation numbers.
  9814. // Create node(s), the latter of which trigger CSS counter increment.
  9815. for (r = 0; r < nr; ++r) {
  9816. const rw = body[r];
  9817. const shift = rw.pos - offset;
  9818. const tag = group.tags[r];
  9819. let tagSpan;
  9820. if (tag === true) {
  9821. // automatic numbering
  9822. tagSpan = makeSpan(["eqn-num"], [], options);
  9823. } else if (tag === false) {
  9824. // \nonumber/\notag or starred environment
  9825. tagSpan = makeSpan([], [], options);
  9826. } else {
  9827. // manual \tag
  9828. tagSpan = makeSpan([], buildExpression(tag, options, true), options);
  9829. }
  9830. tagSpan.depth = rw.depth;
  9831. tagSpan.height = rw.height;
  9832. tagSpans.push({
  9833. type: "elem",
  9834. elem: tagSpan,
  9835. shift
  9836. });
  9837. }
  9838. }
  9839. for (c = 0, colDescrNum = 0;
  9840. // Continue while either there are more columns or more column
  9841. // descriptions, so trailing separators don't get lost.
  9842. c < nc || colDescrNum < colDescriptions.length; ++c, ++colDescrNum) {
  9843. var _colDescr3;
  9844. let colDescr = colDescriptions[colDescrNum];
  9845. let firstSeparator = true;
  9846. while (((_colDescr = colDescr) == null ? void 0 : _colDescr.type) === "separator") {
  9847. var _colDescr;
  9848. // If there is more than one separator in a row, add a space
  9849. // between them.
  9850. if (!firstSeparator) {
  9851. colSep = makeSpan(["arraycolsep"], []);
  9852. colSep.style.width = makeEm(options.fontMetrics().doubleRuleSep);
  9853. cols.push(colSep);
  9854. }
  9855. if (colDescr.separator === "|" || colDescr.separator === ":") {
  9856. const lineType = colDescr.separator === "|" ? "solid" : "dashed";
  9857. const separator = makeSpan(["vertical-separator"], [], options);
  9858. separator.style.height = makeEm(totalHeight);
  9859. separator.style.borderRightWidth = makeEm(ruleThickness);
  9860. separator.style.borderRightStyle = lineType;
  9861. separator.style.margin = "0 " + makeEm(-ruleThickness / 2);
  9862. const shift = totalHeight - offset;
  9863. if (shift) {
  9864. separator.style.verticalAlign = makeEm(-shift);
  9865. }
  9866. cols.push(separator);
  9867. } else {
  9868. throw new src_ParseError("Invalid separator type: " + colDescr.separator);
  9869. }
  9870. colDescrNum++;
  9871. colDescr = colDescriptions[colDescrNum];
  9872. firstSeparator = false;
  9873. }
  9874. if (c >= nc) {
  9875. continue;
  9876. }
  9877. let sepwidth;
  9878. if (c > 0 || group.hskipBeforeAndAfter) {
  9879. var _colDescr$pregap, _colDescr2;
  9880. sepwidth = (_colDescr$pregap = (_colDescr2 = colDescr) == null ? void 0 : _colDescr2.pregap) != null ? _colDescr$pregap : arraycolsep;
  9881. if (sepwidth !== 0) {
  9882. colSep = makeSpan(["arraycolsep"], []);
  9883. colSep.style.width = makeEm(sepwidth);
  9884. cols.push(colSep);
  9885. }
  9886. }
  9887. const colElems = [];
  9888. for (r = 0; r < nr; ++r) {
  9889. const row = body[r];
  9890. const elem = row[c];
  9891. if (!elem) {
  9892. continue;
  9893. }
  9894. const shift = row.pos - offset;
  9895. elem.depth = row.depth;
  9896. elem.height = row.height;
  9897. colElems.push({
  9898. type: "elem",
  9899. elem: elem,
  9900. shift: shift
  9901. });
  9902. }
  9903. const colVList = makeVList({
  9904. positionType: "individualShift",
  9905. children: colElems
  9906. }, options);
  9907. const colSpan = makeSpan(["col-align-" + (((_colDescr3 = colDescr) == null ? void 0 : _colDescr3.align) || "c")], [colVList]);
  9908. cols.push(colSpan);
  9909. if (c < nc - 1 || group.hskipBeforeAndAfter) {
  9910. var _colDescr$postgap, _colDescr4;
  9911. sepwidth = (_colDescr$postgap = (_colDescr4 = colDescr) == null ? void 0 : _colDescr4.postgap) != null ? _colDescr$postgap : arraycolsep;
  9912. if (sepwidth !== 0) {
  9913. colSep = makeSpan(["arraycolsep"], []);
  9914. colSep.style.width = makeEm(sepwidth);
  9915. cols.push(colSep);
  9916. }
  9917. }
  9918. }
  9919. let tableBody = makeSpan(["mtable"], cols);
  9920. // Add \hline(s), if any.
  9921. if (hlines.length > 0) {
  9922. const line = makeLineSpan("hline", options, ruleThickness);
  9923. const dashes = makeLineSpan("hdashline", options, ruleThickness);
  9924. const vListElems = [{
  9925. type: "elem",
  9926. elem: tableBody,
  9927. shift: 0
  9928. }];
  9929. while (hlines.length > 0) {
  9930. const hline = hlines.pop();
  9931. const lineShift = hline.pos - offset;
  9932. if (hline.isDashed) {
  9933. vListElems.push({
  9934. type: "elem",
  9935. elem: dashes,
  9936. shift: lineShift
  9937. });
  9938. } else {
  9939. vListElems.push({
  9940. type: "elem",
  9941. elem: line,
  9942. shift: lineShift
  9943. });
  9944. }
  9945. }
  9946. tableBody = makeVList({
  9947. positionType: "individualShift",
  9948. children: vListElems
  9949. }, options);
  9950. }
  9951. if (tagSpans.length === 0) {
  9952. return makeSpan(["mord"], [tableBody], options);
  9953. } else {
  9954. const eqnNumCol = makeVList({
  9955. positionType: "individualShift",
  9956. children: tagSpans
  9957. }, options);
  9958. const tagCol = makeSpan(["tag"], [eqnNumCol], options);
  9959. return makeFragment([tableBody, tagCol]);
  9960. }
  9961. };
  9962. const alignMap = {
  9963. c: "center ",
  9964. l: "left ",
  9965. r: "right "
  9966. };
  9967. const array_mathmlBuilder = function (group, options) {
  9968. const tbl = [];
  9969. const glue = new MathNode("mtd", [], ["mtr-glue"]);
  9970. const tag = new MathNode("mtd", [], ["mml-eqn-num"]);
  9971. for (let i = 0; i < group.body.length; i++) {
  9972. const rw = group.body[i];
  9973. const row = [];
  9974. for (let j = 0; j < rw.length; j++) {
  9975. row.push(new MathNode("mtd", [buildMathML_buildGroup(rw[j], options)]));
  9976. }
  9977. if (group.tags && group.tags[i]) {
  9978. row.unshift(glue);
  9979. row.push(glue);
  9980. if (group.leqno) {
  9981. row.unshift(tag);
  9982. } else {
  9983. row.push(tag);
  9984. }
  9985. }
  9986. tbl.push(new MathNode("mtr", row));
  9987. }
  9988. let table = new MathNode("mtable", tbl);
  9989. // Set column alignment, row spacing, column spacing, and
  9990. // array lines by setting attributes on the table element.
  9991. // Set the row spacing. In MathML, we specify a gap distance.
  9992. // We do not use rowGap[] because MathML automatically increases
  9993. // cell height with the height/depth of the element content.
  9994. // LaTeX \arraystretch multiplies the row baseline-to-baseline distance.
  9995. // We simulate this by adding (arraystretch - 1)em to the gap. This
  9996. // does a reasonable job of adjusting arrays containing 1 em tall content.
  9997. // The 0.16 and 0.09 values are found empirically. They produce an array
  9998. // similar to LaTeX and in which content does not interfere with \hlines.
  9999. const gap = group.arraystretch === 0.5 ? 0.1 // {smallmatrix}, {subarray}
  10000. : 0.16 + group.arraystretch - 1 + (group.addJot ? 0.09 : 0);
  10001. table.setAttribute("rowspacing", makeEm(gap));
  10002. // MathML table lines go only between cells.
  10003. // To place a line on an edge we'll use <menclose>, if necessary.
  10004. let menclose = "";
  10005. let align = "";
  10006. if (group.cols && group.cols.length > 0) {
  10007. // Find column alignment, column spacing, and vertical lines.
  10008. const cols = group.cols;
  10009. let columnLines = "";
  10010. let prevTypeWasAlign = false;
  10011. let iStart = 0;
  10012. let iEnd = cols.length;
  10013. if (cols[0].type === "separator") {
  10014. menclose += "top ";
  10015. iStart = 1;
  10016. }
  10017. if (cols[cols.length - 1].type === "separator") {
  10018. menclose += "bottom ";
  10019. iEnd -= 1;
  10020. }
  10021. for (let i = iStart; i < iEnd; i++) {
  10022. const col = cols[i];
  10023. if (col.type === "align") {
  10024. align += alignMap[col.align];
  10025. if (prevTypeWasAlign) {
  10026. columnLines += "none ";
  10027. }
  10028. prevTypeWasAlign = true;
  10029. } else if (col.type === "separator") {
  10030. // MathML accepts only single lines between cells.
  10031. // So we read only the first of consecutive separators.
  10032. if (prevTypeWasAlign) {
  10033. columnLines += col.separator === "|" ? "solid " : "dashed ";
  10034. prevTypeWasAlign = false;
  10035. }
  10036. }
  10037. }
  10038. table.setAttribute("columnalign", align.trim());
  10039. if (/[sd]/.test(columnLines)) {
  10040. table.setAttribute("columnlines", columnLines.trim());
  10041. }
  10042. }
  10043. // Set column spacing.
  10044. if (group.colSeparationType === "align") {
  10045. const cols = group.cols || [];
  10046. let spacing = "";
  10047. for (let i = 1; i < cols.length; i++) {
  10048. spacing += i % 2 ? "0em " : "1em ";
  10049. }
  10050. table.setAttribute("columnspacing", spacing.trim());
  10051. } else if (group.colSeparationType === "alignat" || group.colSeparationType === "gather") {
  10052. table.setAttribute("columnspacing", "0em");
  10053. } else if (group.colSeparationType === "small") {
  10054. table.setAttribute("columnspacing", "0.2778em");
  10055. } else if (group.colSeparationType === "CD") {
  10056. table.setAttribute("columnspacing", "0.5em");
  10057. } else {
  10058. table.setAttribute("columnspacing", "1em");
  10059. }
  10060. // Address \hline and \hdashline
  10061. let rowLines = "";
  10062. const hlines = group.hLinesBeforeRow;
  10063. menclose += hlines[0].length > 0 ? "left " : "";
  10064. menclose += hlines[hlines.length - 1].length > 0 ? "right " : "";
  10065. for (let i = 1; i < hlines.length - 1; i++) {
  10066. rowLines += hlines[i].length === 0 ? "none "
  10067. // MathML accepts only a single line between rows. Read one element.
  10068. : hlines[i][0] ? "dashed " : "solid ";
  10069. }
  10070. if (/[sd]/.test(rowLines)) {
  10071. table.setAttribute("rowlines", rowLines.trim());
  10072. }
  10073. if (menclose !== "") {
  10074. table = new MathNode("menclose", [table]);
  10075. table.setAttribute("notation", menclose.trim());
  10076. }
  10077. if (group.arraystretch && group.arraystretch < 1) {
  10078. // A small array. Wrap in scriptstyle so row gap is not too large.
  10079. table = new MathNode("mstyle", [table]);
  10080. table.setAttribute("scriptlevel", "1");
  10081. }
  10082. return table;
  10083. };
  10084. // Convenience function for align, align*, aligned, alignat, alignat*, alignedat.
  10085. const alignedHandler = function (context, args) {
  10086. if (!context.envName.includes("ed")) {
  10087. validateAmsEnvironmentContext(context);
  10088. }
  10089. const cols = [];
  10090. const separationType = context.envName.includes("at") ? "alignat" : "align";
  10091. const isSplit = context.envName === "split";
  10092. const res = parseArray(context.parser, {
  10093. cols,
  10094. addJot: true,
  10095. autoTag: isSplit ? undefined : getAutoTag(context.envName),
  10096. emptySingleRow: true,
  10097. colSeparationType: separationType,
  10098. maxNumCols: isSplit ? 2 : undefined,
  10099. leqno: context.parser.settings.leqno
  10100. }, "display");
  10101. // Determining number of columns.
  10102. // 1. If the first argument is given, we use it as a number of columns,
  10103. // and makes sure that each row doesn't exceed that number.
  10104. // 2. Otherwise, just count number of columns = maximum number
  10105. // of cells in each row ("aligned" mode -- isAligned will be true).
  10106. //
  10107. // At the same time, prepend empty group {} at beginning of every second
  10108. // cell in each row (starting with second cell) so that operators become
  10109. // binary. This behavior is implemented in amsmath's \start@aligned.
  10110. let numMaths = 0;
  10111. let numCols = 0;
  10112. const emptyGroup = {
  10113. type: "ordgroup",
  10114. mode: context.mode,
  10115. body: []
  10116. };
  10117. if (args[0] && args[0].type === "ordgroup") {
  10118. let arg0 = "";
  10119. for (let i = 0; i < args[0].body.length; i++) {
  10120. const textord = assertNodeType(args[0].body[i], "textord");
  10121. arg0 += textord.text;
  10122. }
  10123. numMaths = Number(arg0);
  10124. numCols = numMaths * 2;
  10125. }
  10126. const isAligned = !numCols;
  10127. res.body.forEach(function (row) {
  10128. for (let i = 1; i < row.length; i += 2) {
  10129. // Modify ordgroup node within styling node
  10130. const styling = assertNodeType(row[i], "styling");
  10131. const ordgroup = assertNodeType(styling.body[0], "ordgroup");
  10132. ordgroup.body.unshift(emptyGroup);
  10133. }
  10134. if (!isAligned) {
  10135. // Case 1
  10136. const curMaths = row.length / 2;
  10137. if (numMaths < curMaths) {
  10138. throw new src_ParseError("Too many math in a row: " + ("expected " + numMaths + ", but got " + curMaths), row[0]);
  10139. }
  10140. } else if (numCols < row.length) {
  10141. // Case 2
  10142. numCols = row.length;
  10143. }
  10144. });
  10145. // Adjusting alignment.
  10146. // In aligned mode, we add one \qquad between columns;
  10147. // otherwise we add nothing.
  10148. for (let i = 0; i < numCols; ++i) {
  10149. let align = "r";
  10150. let pregap = 0;
  10151. if (i % 2 === 1) {
  10152. align = "l";
  10153. } else if (i > 0 && isAligned) {
  10154. // "aligned" mode.
  10155. pregap = 1; // add one \quad
  10156. }
  10157. cols[i] = {
  10158. type: "align",
  10159. align: align,
  10160. pregap: pregap,
  10161. postgap: 0
  10162. };
  10163. }
  10164. res.colSeparationType = isAligned ? "align" : "alignat";
  10165. return res;
  10166. };
  10167. // Arrays are part of LaTeX, defined in lttab.dtx so its documentation
  10168. // is part of the source2e.pdf file of LaTeX2e source documentation.
  10169. // {darray} is an {array} environment where cells are set in \displaystyle,
  10170. // as defined in nccmath.sty.
  10171. defineEnvironment({
  10172. type: "array",
  10173. names: ["array", "darray"],
  10174. props: {
  10175. numArgs: 1
  10176. },
  10177. handler(context, args) {
  10178. // Since no types are specified above, the two possibilities are
  10179. // - The argument is wrapped in {} or [], in which case Parser's
  10180. // parseGroup() returns an "ordgroup" wrapping some symbol node.
  10181. // - The argument is a bare symbol node.
  10182. const symNode = checkSymbolNodeType(args[0]);
  10183. const colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
  10184. const cols = colalign.map(function (nde) {
  10185. const node = assertSymbolNodeType(nde);
  10186. const ca = node.text;
  10187. if ("lcr".includes(ca)) {
  10188. return {
  10189. type: "align",
  10190. align: ca
  10191. };
  10192. } else if (ca === "|") {
  10193. return {
  10194. type: "separator",
  10195. separator: "|"
  10196. };
  10197. } else if (ca === ":") {
  10198. return {
  10199. type: "separator",
  10200. separator: ":"
  10201. };
  10202. }
  10203. throw new src_ParseError("Unknown column alignment: " + ca, nde);
  10204. });
  10205. const res = {
  10206. cols,
  10207. hskipBeforeAndAfter: true,
  10208. // \@preamble in lttab.dtx
  10209. maxNumCols: cols.length
  10210. };
  10211. return parseArray(context.parser, res, dCellStyle(context.envName));
  10212. },
  10213. htmlBuilder: array_htmlBuilder,
  10214. mathmlBuilder: array_mathmlBuilder
  10215. });
  10216. // The matrix environments of amsmath builds on the array environment
  10217. // of LaTeX, which is discussed above.
  10218. // The mathtools package adds starred versions of the same environments.
  10219. // These have an optional argument to choose left|center|right justification.
  10220. defineEnvironment({
  10221. type: "array",
  10222. names: ["matrix", "pmatrix", "bmatrix", "Bmatrix", "vmatrix", "Vmatrix", "matrix*", "pmatrix*", "bmatrix*", "Bmatrix*", "vmatrix*", "Vmatrix*"],
  10223. props: {
  10224. numArgs: 0
  10225. },
  10226. handler(context) {
  10227. const delimiters = {
  10228. "matrix": null,
  10229. "pmatrix": ["(", ")"],
  10230. "bmatrix": ["[", "]"],
  10231. "Bmatrix": ["\\{", "\\}"],
  10232. "vmatrix": ["|", "|"],
  10233. "Vmatrix": ["\\Vert", "\\Vert"]
  10234. }[context.envName.replace("*", "")];
  10235. // \hskip -\arraycolsep in amsmath
  10236. let colAlign = "c";
  10237. const payload = {
  10238. hskipBeforeAndAfter: false,
  10239. cols: [{
  10240. type: "align",
  10241. align: colAlign
  10242. }]
  10243. };
  10244. if (context.envName.charAt(context.envName.length - 1) === "*") {
  10245. // It's one of the mathtools starred functions.
  10246. // Parse the optional alignment argument.
  10247. const parser = context.parser;
  10248. parser.consumeSpaces();
  10249. if (parser.fetch().text === "[") {
  10250. parser.consume();
  10251. parser.consumeSpaces();
  10252. colAlign = parser.fetch().text;
  10253. if (!"lcr".includes(colAlign)) {
  10254. throw new src_ParseError("Expected l or c or r", parser.nextToken);
  10255. }
  10256. parser.consume();
  10257. parser.consumeSpaces();
  10258. parser.expect("]");
  10259. parser.consume();
  10260. payload.cols = [{
  10261. type: "align",
  10262. align: colAlign
  10263. }];
  10264. }
  10265. }
  10266. const res = parseArray(context.parser, payload, dCellStyle(context.envName));
  10267. // Populate cols with the correct number of column alignment specs.
  10268. const numCols = Math.max(0, ...res.body.map(row => row.length));
  10269. res.cols = new Array(numCols).fill({
  10270. type: "align",
  10271. align: colAlign
  10272. });
  10273. return delimiters ? {
  10274. type: "leftright",
  10275. mode: context.mode,
  10276. body: [res],
  10277. left: delimiters[0],
  10278. right: delimiters[1],
  10279. rightColor: undefined // \right uninfluenced by \color in array
  10280. } : res;
  10281. },
  10282. htmlBuilder: array_htmlBuilder,
  10283. mathmlBuilder: array_mathmlBuilder
  10284. });
  10285. defineEnvironment({
  10286. type: "array",
  10287. names: ["smallmatrix"],
  10288. props: {
  10289. numArgs: 0
  10290. },
  10291. handler(context) {
  10292. const payload = {
  10293. arraystretch: 0.5
  10294. };
  10295. const res = parseArray(context.parser, payload, "script");
  10296. res.colSeparationType = "small";
  10297. return res;
  10298. },
  10299. htmlBuilder: array_htmlBuilder,
  10300. mathmlBuilder: array_mathmlBuilder
  10301. });
  10302. defineEnvironment({
  10303. type: "array",
  10304. names: ["subarray"],
  10305. props: {
  10306. numArgs: 1
  10307. },
  10308. handler(context, args) {
  10309. // Parsing of {subarray} is similar to {array}
  10310. const symNode = checkSymbolNodeType(args[0]);
  10311. const colalign = symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
  10312. const cols = colalign.map(function (nde) {
  10313. const node = assertSymbolNodeType(nde);
  10314. const ca = node.text;
  10315. // {subarray} only recognizes "l" & "c"
  10316. if ("lc".includes(ca)) {
  10317. return {
  10318. type: "align",
  10319. align: ca
  10320. };
  10321. }
  10322. throw new src_ParseError("Unknown column alignment: " + ca, nde);
  10323. });
  10324. if (cols.length > 1) {
  10325. throw new src_ParseError("{subarray} can contain only one column");
  10326. }
  10327. const payload = {
  10328. cols,
  10329. hskipBeforeAndAfter: false,
  10330. arraystretch: 0.5
  10331. };
  10332. const res = parseArray(context.parser, payload, "script");
  10333. if (res.body.length > 0 && res.body[0].length > 1) {
  10334. throw new src_ParseError("{subarray} can contain only one column");
  10335. }
  10336. return res;
  10337. },
  10338. htmlBuilder: array_htmlBuilder,
  10339. mathmlBuilder: array_mathmlBuilder
  10340. });
  10341. // A cases environment (in amsmath.sty) is almost equivalent to
  10342. // \def\arraystretch{1.2}%
  10343. // \left\{\begin{array}{@{}l@{\quad}l@{}} … \end{array}\right.
  10344. // {dcases} is a {cases} environment where cells are set in \displaystyle,
  10345. // as defined in mathtools.sty.
  10346. // {rcases} is another mathtools environment. It's brace is on the right side.
  10347. defineEnvironment({
  10348. type: "array",
  10349. names: ["cases", "dcases", "rcases", "drcases"],
  10350. props: {
  10351. numArgs: 0
  10352. },
  10353. handler(context) {
  10354. const payload = {
  10355. arraystretch: 1.2,
  10356. cols: [{
  10357. type: "align",
  10358. align: "l",
  10359. pregap: 0,
  10360. // TODO(kevinb) get the current style.
  10361. // For now we use the metrics for TEXT style which is what we were
  10362. // doing before. Before attempting to get the current style we
  10363. // should look at TeX's behavior especially for \over and matrices.
  10364. postgap: 1.0 /* 1em quad */
  10365. }, {
  10366. type: "align",
  10367. align: "l",
  10368. pregap: 0,
  10369. postgap: 0
  10370. }]
  10371. };
  10372. const res = parseArray(context.parser, payload, dCellStyle(context.envName));
  10373. return {
  10374. type: "leftright",
  10375. mode: context.mode,
  10376. body: [res],
  10377. left: context.envName.includes("r") ? "." : "\\{",
  10378. right: context.envName.includes("r") ? "\\}" : ".",
  10379. rightColor: undefined
  10380. };
  10381. },
  10382. htmlBuilder: array_htmlBuilder,
  10383. mathmlBuilder: array_mathmlBuilder
  10384. });
  10385. // In the align environment, one uses ampersands, &, to specify number of
  10386. // columns in each row, and to locate spacing between each column.
  10387. // align gets automatic numbering. align* and aligned do not.
  10388. // The alignedat environment can be used in math mode.
  10389. // Note that we assume \nomallineskiplimit to be zero,
  10390. // so that \strut@ is the same as \strut.
  10391. defineEnvironment({
  10392. type: "array",
  10393. names: ["align", "align*", "aligned", "split"],
  10394. props: {
  10395. numArgs: 0
  10396. },
  10397. handler: alignedHandler,
  10398. htmlBuilder: array_htmlBuilder,
  10399. mathmlBuilder: array_mathmlBuilder
  10400. });
  10401. // A gathered environment is like an array environment with one centered
  10402. // column, but where rows are considered lines so get \jot line spacing
  10403. // and contents are set in \displaystyle.
  10404. defineEnvironment({
  10405. type: "array",
  10406. names: ["gathered", "gather", "gather*"],
  10407. props: {
  10408. numArgs: 0
  10409. },
  10410. handler(context) {
  10411. if (gatherEnvironments.has(context.envName)) {
  10412. validateAmsEnvironmentContext(context);
  10413. }
  10414. const res = {
  10415. cols: [{
  10416. type: "align",
  10417. align: "c"
  10418. }],
  10419. addJot: true,
  10420. colSeparationType: "gather",
  10421. autoTag: getAutoTag(context.envName),
  10422. emptySingleRow: true,
  10423. leqno: context.parser.settings.leqno
  10424. };
  10425. return parseArray(context.parser, res, "display");
  10426. },
  10427. htmlBuilder: array_htmlBuilder,
  10428. mathmlBuilder: array_mathmlBuilder
  10429. });
  10430. // alignat environment is like an align environment, but one must explicitly
  10431. // specify maximum number of columns in each row, and can adjust spacing between
  10432. // each columns.
  10433. defineEnvironment({
  10434. type: "array",
  10435. names: ["alignat", "alignat*", "alignedat"],
  10436. props: {
  10437. numArgs: 1
  10438. },
  10439. handler: alignedHandler,
  10440. htmlBuilder: array_htmlBuilder,
  10441. mathmlBuilder: array_mathmlBuilder
  10442. });
  10443. defineEnvironment({
  10444. type: "array",
  10445. names: ["equation", "equation*"],
  10446. props: {
  10447. numArgs: 0
  10448. },
  10449. handler(context) {
  10450. validateAmsEnvironmentContext(context);
  10451. const res = {
  10452. autoTag: getAutoTag(context.envName),
  10453. emptySingleRow: true,
  10454. singleRow: true,
  10455. maxNumCols: 1,
  10456. leqno: context.parser.settings.leqno
  10457. };
  10458. return parseArray(context.parser, res, "display");
  10459. },
  10460. htmlBuilder: array_htmlBuilder,
  10461. mathmlBuilder: array_mathmlBuilder
  10462. });
  10463. defineEnvironment({
  10464. type: "array",
  10465. names: ["CD"],
  10466. props: {
  10467. numArgs: 0
  10468. },
  10469. handler(context) {
  10470. validateAmsEnvironmentContext(context);
  10471. return parseCD(context.parser);
  10472. },
  10473. htmlBuilder: array_htmlBuilder,
  10474. mathmlBuilder: array_mathmlBuilder
  10475. });
  10476. defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
  10477. defineMacro("\\notag", "\\nonumber");
  10478. // Catch \hline outside array environment
  10479. defineFunction({
  10480. type: "text",
  10481. // Doesn't matter what this is.
  10482. names: ["\\hline", "\\hdashline"],
  10483. props: {
  10484. numArgs: 0,
  10485. allowedInText: true,
  10486. allowedInMath: true
  10487. },
  10488. handler(context, args) {
  10489. throw new src_ParseError(context.funcName + " valid only within array environment");
  10490. }
  10491. });
  10492. ;// ./src/environments.ts
  10493. const environments = _environments;
  10494. /* harmony default export */ var src_environments = (environments);
  10495. // All environment definitions should be imported below
  10496. ;// ./src/functions/environment.ts
  10497. // Environment delimiters. HTML/MathML rendering is defined in the corresponding
  10498. // defineEnvironment definitions.
  10499. defineFunction({
  10500. type: "environment",
  10501. names: ["\\begin", "\\end"],
  10502. props: {
  10503. numArgs: 1,
  10504. argTypes: ["text"]
  10505. },
  10506. handler(_ref, args) {
  10507. let {
  10508. parser,
  10509. funcName
  10510. } = _ref;
  10511. const nameGroup = args[0];
  10512. if (nameGroup.type !== "ordgroup") {
  10513. throw new src_ParseError("Invalid environment name", nameGroup);
  10514. }
  10515. let envName = "";
  10516. for (let i = 0; i < nameGroup.body.length; ++i) {
  10517. envName += assertNodeType(nameGroup.body[i], "textord").text;
  10518. }
  10519. if (funcName === "\\begin") {
  10520. // begin...end is similar to left...right
  10521. if (!src_environments.hasOwnProperty(envName)) {
  10522. throw new src_ParseError("No such environment: " + envName, nameGroup);
  10523. }
  10524. // Build the environment object. Arguments and other information will
  10525. // be made available to the begin and end methods using properties.
  10526. const env = src_environments[envName];
  10527. const {
  10528. args,
  10529. optArgs
  10530. } = parser.parseArguments("\\begin{" + envName + "}", env);
  10531. const context = {
  10532. mode: parser.mode,
  10533. envName,
  10534. parser
  10535. };
  10536. const result = env.handler(context, args, optArgs);
  10537. parser.expect("\\end", false);
  10538. const endNameToken = parser.nextToken;
  10539. const end = assertNodeType(parser.parseFunction(), "environment");
  10540. if (end.name !== envName) {
  10541. throw new src_ParseError("Mismatch: \\begin{" + envName + "} matched by \\end{" + end.name + "}", endNameToken);
  10542. }
  10543. // TODO(ts), "environment" handler returns an environment ParseNode
  10544. return result;
  10545. }
  10546. return {
  10547. type: "environment",
  10548. mode: parser.mode,
  10549. name: envName,
  10550. nameGroup
  10551. };
  10552. }
  10553. });
  10554. ;// ./src/functions/font.ts
  10555. // TODO(kevinb): implement \\sl and \\sc
  10556. const font_htmlBuilder = (group, options) => {
  10557. const font = group.font;
  10558. const newOptions = options.withFont(font);
  10559. return buildGroup(group.body, newOptions);
  10560. };
  10561. const font_mathmlBuilder = (group, options) => {
  10562. const font = group.font;
  10563. const newOptions = options.withFont(font);
  10564. return buildMathML_buildGroup(group.body, newOptions);
  10565. };
  10566. const fontAliases = {
  10567. "\\Bbb": "\\mathbb",
  10568. "\\bold": "\\mathbf",
  10569. "\\frak": "\\mathfrak",
  10570. "\\bm": "\\boldsymbol"
  10571. };
  10572. defineFunction({
  10573. type: "font",
  10574. names: [
  10575. // styles, except \boldsymbol defined below
  10576. "\\mathrm", "\\mathit", "\\mathbf", "\\mathnormal", "\\mathsfit",
  10577. // families
  10578. "\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf", "\\mathtt",
  10579. // aliases, except \bm defined below
  10580. "\\Bbb", "\\bold", "\\frak"],
  10581. props: {
  10582. numArgs: 1,
  10583. allowedInArgument: true
  10584. },
  10585. handler: (_ref, args) => {
  10586. let {
  10587. parser,
  10588. funcName
  10589. } = _ref;
  10590. const body = normalizeArgument(args[0]);
  10591. let func = funcName;
  10592. if (func in fontAliases) {
  10593. func = fontAliases[func];
  10594. }
  10595. return {
  10596. type: "font",
  10597. mode: parser.mode,
  10598. font: func.slice(1),
  10599. body
  10600. };
  10601. },
  10602. htmlBuilder: font_htmlBuilder,
  10603. mathmlBuilder: font_mathmlBuilder
  10604. });
  10605. defineFunction({
  10606. type: "mclass",
  10607. names: ["\\boldsymbol", "\\bm"],
  10608. props: {
  10609. numArgs: 1
  10610. },
  10611. handler: (_ref2, args) => {
  10612. let {
  10613. parser
  10614. } = _ref2;
  10615. const body = args[0];
  10616. // amsbsy.sty's \boldsymbol uses \binrel spacing to inherit the
  10617. // argument's bin|rel|ord status
  10618. return {
  10619. type: "mclass",
  10620. mode: parser.mode,
  10621. mclass: binrelClass(body),
  10622. body: [{
  10623. type: "font",
  10624. mode: parser.mode,
  10625. font: "boldsymbol",
  10626. body
  10627. }],
  10628. isCharacterBox: isCharacterBox(body)
  10629. };
  10630. }
  10631. });
  10632. // Old font changing functions
  10633. defineFunction({
  10634. type: "font",
  10635. names: ["\\rm", "\\sf", "\\tt", "\\bf", "\\it", "\\cal"],
  10636. props: {
  10637. numArgs: 0,
  10638. allowedInText: true
  10639. },
  10640. handler: (_ref3, args) => {
  10641. let {
  10642. parser,
  10643. funcName,
  10644. breakOnTokenText
  10645. } = _ref3;
  10646. const {
  10647. mode
  10648. } = parser;
  10649. const body = parser.parseExpression(true, breakOnTokenText);
  10650. const style = "math" + funcName.slice(1);
  10651. return {
  10652. type: "font",
  10653. mode: mode,
  10654. font: style,
  10655. body: {
  10656. type: "ordgroup",
  10657. mode: parser.mode,
  10658. body
  10659. }
  10660. };
  10661. },
  10662. htmlBuilder: font_htmlBuilder,
  10663. mathmlBuilder: font_mathmlBuilder
  10664. });
  10665. ;// ./src/functions/genfrac.ts
  10666. const genfrac_htmlBuilder = (group, options) => {
  10667. // Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
  10668. const style = options.style;
  10669. const nstyle = style.fracNum();
  10670. const dstyle = style.fracDen();
  10671. let newOptions;
  10672. newOptions = options.havingStyle(nstyle);
  10673. const numerm = buildGroup(group.numer, newOptions, options);
  10674. if (group.continued) {
  10675. // \cfrac inserts a \strut into the numerator.
  10676. // Get \strut dimensions from TeXbook page 353.
  10677. const hStrut = 8.5 / options.fontMetrics().ptPerEm;
  10678. const dStrut = 3.5 / options.fontMetrics().ptPerEm;
  10679. numerm.height = numerm.height < hStrut ? hStrut : numerm.height;
  10680. numerm.depth = numerm.depth < dStrut ? dStrut : numerm.depth;
  10681. }
  10682. newOptions = options.havingStyle(dstyle);
  10683. const denomm = buildGroup(group.denom, newOptions, options);
  10684. let rule;
  10685. let ruleWidth;
  10686. let ruleSpacing;
  10687. if (group.hasBarLine) {
  10688. if (group.barSize) {
  10689. ruleWidth = calculateSize(group.barSize, options);
  10690. rule = makeLineSpan("frac-line", options, ruleWidth);
  10691. } else {
  10692. rule = makeLineSpan("frac-line", options);
  10693. }
  10694. ruleWidth = rule.height;
  10695. ruleSpacing = rule.height;
  10696. } else {
  10697. rule = null;
  10698. ruleWidth = 0;
  10699. ruleSpacing = options.fontMetrics().defaultRuleThickness;
  10700. }
  10701. // Rule 15b
  10702. let numShift;
  10703. let clearance;
  10704. let denomShift;
  10705. if (style.size === src_Style.DISPLAY.size) {
  10706. numShift = options.fontMetrics().num1;
  10707. if (ruleWidth > 0) {
  10708. clearance = 3 * ruleSpacing;
  10709. } else {
  10710. clearance = 7 * ruleSpacing;
  10711. }
  10712. denomShift = options.fontMetrics().denom1;
  10713. } else {
  10714. if (ruleWidth > 0) {
  10715. numShift = options.fontMetrics().num2;
  10716. clearance = ruleSpacing;
  10717. } else {
  10718. numShift = options.fontMetrics().num3;
  10719. clearance = 3 * ruleSpacing;
  10720. }
  10721. denomShift = options.fontMetrics().denom2;
  10722. }
  10723. let frac;
  10724. if (!rule) {
  10725. // Rule 15c
  10726. const candidateClearance = numShift - numerm.depth - (denomm.height - denomShift);
  10727. if (candidateClearance < clearance) {
  10728. numShift += 0.5 * (clearance - candidateClearance);
  10729. denomShift += 0.5 * (clearance - candidateClearance);
  10730. }
  10731. frac = makeVList({
  10732. positionType: "individualShift",
  10733. children: [{
  10734. type: "elem",
  10735. elem: denomm,
  10736. shift: denomShift
  10737. }, {
  10738. type: "elem",
  10739. elem: numerm,
  10740. shift: -numShift
  10741. }]
  10742. }, options);
  10743. } else {
  10744. // Rule 15d
  10745. const axisHeight = options.fontMetrics().axisHeight;
  10746. if (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth) < clearance) {
  10747. numShift += clearance - (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth));
  10748. }
  10749. if (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift) < clearance) {
  10750. denomShift += clearance - (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift));
  10751. }
  10752. const midShift = -(axisHeight - 0.5 * ruleWidth);
  10753. frac = makeVList({
  10754. positionType: "individualShift",
  10755. children: [{
  10756. type: "elem",
  10757. elem: denomm,
  10758. shift: denomShift
  10759. }, {
  10760. type: "elem",
  10761. elem: rule,
  10762. shift: midShift
  10763. }, {
  10764. type: "elem",
  10765. elem: numerm,
  10766. shift: -numShift
  10767. }]
  10768. }, options);
  10769. }
  10770. // Since we manually change the style sometimes (with \dfrac or \tfrac),
  10771. // account for the possible size change here.
  10772. newOptions = options.havingStyle(style);
  10773. frac.height *= newOptions.sizeMultiplier / options.sizeMultiplier;
  10774. frac.depth *= newOptions.sizeMultiplier / options.sizeMultiplier;
  10775. // Rule 15e
  10776. let delimSize;
  10777. if (style.size === src_Style.DISPLAY.size) {
  10778. delimSize = options.fontMetrics().delim1;
  10779. } else if (style.size === src_Style.SCRIPTSCRIPT.size) {
  10780. delimSize = options.havingStyle(src_Style.SCRIPT).fontMetrics().delim2;
  10781. } else {
  10782. delimSize = options.fontMetrics().delim2;
  10783. }
  10784. let leftDelim;
  10785. let rightDelim;
  10786. if (group.leftDelim == null) {
  10787. leftDelim = makeNullDelimiter(options, ["mopen"]);
  10788. } else {
  10789. leftDelim = makeCustomSizedDelim(group.leftDelim, delimSize, true, options.havingStyle(style), group.mode, ["mopen"]);
  10790. }
  10791. if (group.continued) {
  10792. rightDelim = makeSpan([]); // zero width for \cfrac
  10793. } else if (group.rightDelim == null) {
  10794. rightDelim = makeNullDelimiter(options, ["mclose"]);
  10795. } else {
  10796. rightDelim = makeCustomSizedDelim(group.rightDelim, delimSize, true, options.havingStyle(style), group.mode, ["mclose"]);
  10797. }
  10798. return makeSpan(["mord"].concat(newOptions.sizingClasses(options)), [leftDelim, makeSpan(["mfrac"], [frac]), rightDelim], options);
  10799. };
  10800. const genfrac_mathmlBuilder = (group, options) => {
  10801. const node = new MathNode("mfrac", [buildMathML_buildGroup(group.numer, options), buildMathML_buildGroup(group.denom, options)]);
  10802. if (!group.hasBarLine) {
  10803. node.setAttribute("linethickness", "0px");
  10804. } else if (group.barSize) {
  10805. const ruleWidth = calculateSize(group.barSize, options);
  10806. node.setAttribute("linethickness", makeEm(ruleWidth));
  10807. }
  10808. if (group.leftDelim != null || group.rightDelim != null) {
  10809. const withDelims = [];
  10810. if (group.leftDelim != null) {
  10811. const leftOp = new MathNode("mo", [new TextNode(group.leftDelim.replace("\\", ""))]);
  10812. leftOp.setAttribute("fence", "true");
  10813. withDelims.push(leftOp);
  10814. }
  10815. withDelims.push(node);
  10816. if (group.rightDelim != null) {
  10817. const rightOp = new MathNode("mo", [new TextNode(group.rightDelim.replace("\\", ""))]);
  10818. rightOp.setAttribute("fence", "true");
  10819. withDelims.push(rightOp);
  10820. }
  10821. return makeRow(withDelims);
  10822. }
  10823. return node;
  10824. };
  10825. const wrapWithStyle = (frac, style) => {
  10826. if (!style) {
  10827. return frac;
  10828. }
  10829. const wrapper = {
  10830. type: "styling",
  10831. mode: frac.mode,
  10832. style,
  10833. body: [frac]
  10834. };
  10835. // @ts-ignore defineFunction handler needs to return ParseNode<"genfrac">
  10836. return wrapper;
  10837. };
  10838. defineFunction({
  10839. type: "genfrac",
  10840. names: ["\\cfrac", "\\dfrac", "\\frac", "\\tfrac", "\\dbinom", "\\binom", "\\tbinom", "\\\\atopfrac",
  10841. // can’t be entered directly
  10842. "\\\\bracefrac", "\\\\brackfrac" // ditto
  10843. ],
  10844. props: {
  10845. numArgs: 2,
  10846. allowedInArgument: true
  10847. },
  10848. handler: (_ref, args) => {
  10849. let {
  10850. parser,
  10851. funcName
  10852. } = _ref;
  10853. const numer = args[0];
  10854. const denom = args[1];
  10855. let hasBarLine;
  10856. let leftDelim = null;
  10857. let rightDelim = null;
  10858. switch (funcName) {
  10859. case "\\cfrac":
  10860. case "\\dfrac":
  10861. case "\\frac":
  10862. case "\\tfrac":
  10863. hasBarLine = true;
  10864. break;
  10865. case "\\\\atopfrac":
  10866. hasBarLine = false;
  10867. break;
  10868. case "\\dbinom":
  10869. case "\\binom":
  10870. case "\\tbinom":
  10871. hasBarLine = false;
  10872. leftDelim = "(";
  10873. rightDelim = ")";
  10874. break;
  10875. case "\\\\bracefrac":
  10876. hasBarLine = false;
  10877. leftDelim = "\\{";
  10878. rightDelim = "\\}";
  10879. break;
  10880. case "\\\\brackfrac":
  10881. hasBarLine = false;
  10882. leftDelim = "[";
  10883. rightDelim = "]";
  10884. break;
  10885. default:
  10886. throw new Error("Unrecognized genfrac command");
  10887. }
  10888. const continued = funcName === "\\cfrac";
  10889. let style = null;
  10890. if (continued || funcName.startsWith("\\d")) {
  10891. style = "display";
  10892. } else if (funcName.startsWith("\\t")) {
  10893. style = "text";
  10894. }
  10895. return wrapWithStyle({
  10896. type: "genfrac",
  10897. mode: parser.mode,
  10898. numer,
  10899. denom,
  10900. continued,
  10901. hasBarLine,
  10902. leftDelim,
  10903. rightDelim,
  10904. barSize: null
  10905. }, style);
  10906. },
  10907. htmlBuilder: genfrac_htmlBuilder,
  10908. mathmlBuilder: genfrac_mathmlBuilder
  10909. });
  10910. // Infix generalized fractions -- these are not rendered directly, but replaced
  10911. // immediately by one of the variants above.
  10912. defineFunction({
  10913. type: "infix",
  10914. names: ["\\over", "\\choose", "\\atop", "\\brace", "\\brack"],
  10915. props: {
  10916. numArgs: 0,
  10917. infix: true
  10918. },
  10919. handler(_ref2) {
  10920. let {
  10921. parser,
  10922. funcName,
  10923. token
  10924. } = _ref2;
  10925. let replaceWith;
  10926. switch (funcName) {
  10927. case "\\over":
  10928. replaceWith = "\\frac";
  10929. break;
  10930. case "\\choose":
  10931. replaceWith = "\\binom";
  10932. break;
  10933. case "\\atop":
  10934. replaceWith = "\\\\atopfrac";
  10935. break;
  10936. case "\\brace":
  10937. replaceWith = "\\\\bracefrac";
  10938. break;
  10939. case "\\brack":
  10940. replaceWith = "\\\\brackfrac";
  10941. break;
  10942. default:
  10943. throw new Error("Unrecognized infix genfrac command");
  10944. }
  10945. return {
  10946. type: "infix",
  10947. mode: parser.mode,
  10948. replaceWith,
  10949. token
  10950. };
  10951. }
  10952. });
  10953. const stylArray = ["display", "text", "script", "scriptscript"];
  10954. const delimFromValue = function (delimString) {
  10955. let delim = null;
  10956. if (delimString.length > 0) {
  10957. delim = delimString;
  10958. delim = delim === "." ? null : delim;
  10959. }
  10960. return delim;
  10961. };
  10962. defineFunction({
  10963. type: "genfrac",
  10964. names: ["\\genfrac"],
  10965. props: {
  10966. numArgs: 6,
  10967. allowedInArgument: true,
  10968. argTypes: ["math", "math", "size", "text", "math", "math"]
  10969. },
  10970. handler(_ref3, args) {
  10971. let {
  10972. parser
  10973. } = _ref3;
  10974. const numer = args[4];
  10975. const denom = args[5];
  10976. // Look into the parse nodes to get the desired delimiters.
  10977. const leftNode = normalizeArgument(args[0]);
  10978. const leftDelim = leftNode.type === "atom" && leftNode.family === "open" ? delimFromValue(leftNode.text) : null;
  10979. const rightNode = normalizeArgument(args[1]);
  10980. const rightDelim = rightNode.type === "atom" && rightNode.family === "close" ? delimFromValue(rightNode.text) : null;
  10981. const barNode = assertNodeType(args[2], "size");
  10982. let hasBarLine;
  10983. let barSize = null;
  10984. if (barNode.isBlank) {
  10985. // \genfrac acts differently than \above.
  10986. // \genfrac treats an empty size group as a signal to use a
  10987. // standard bar size. \above would see size = 0 and omit the bar.
  10988. hasBarLine = true;
  10989. } else {
  10990. barSize = barNode.value;
  10991. hasBarLine = barSize.number > 0;
  10992. }
  10993. // Find out if we want displaystyle, textstyle, etc.
  10994. let size = null;
  10995. let styl = args[3];
  10996. if (styl.type === "ordgroup") {
  10997. if (styl.body.length > 0) {
  10998. const textOrd = assertNodeType(styl.body[0], "textord");
  10999. size = stylArray[Number(textOrd.text)];
  11000. }
  11001. } else {
  11002. styl = assertNodeType(styl, "textord");
  11003. size = stylArray[Number(styl.text)];
  11004. }
  11005. return wrapWithStyle({
  11006. type: "genfrac",
  11007. mode: parser.mode,
  11008. numer,
  11009. denom,
  11010. continued: false,
  11011. hasBarLine,
  11012. barSize,
  11013. leftDelim,
  11014. rightDelim
  11015. }, size);
  11016. }
  11017. });
  11018. // \above is an infix fraction that also defines a fraction bar size.
  11019. defineFunction({
  11020. type: "infix",
  11021. names: ["\\above"],
  11022. props: {
  11023. numArgs: 1,
  11024. argTypes: ["size"],
  11025. infix: true
  11026. },
  11027. handler(_ref4, args) {
  11028. let {
  11029. parser,
  11030. funcName,
  11031. token
  11032. } = _ref4;
  11033. return {
  11034. type: "infix",
  11035. mode: parser.mode,
  11036. replaceWith: "\\\\abovefrac",
  11037. size: assertNodeType(args[0], "size").value,
  11038. token
  11039. };
  11040. }
  11041. });
  11042. defineFunction({
  11043. type: "genfrac",
  11044. names: ["\\\\abovefrac"],
  11045. props: {
  11046. numArgs: 3,
  11047. argTypes: ["math", "size", "math"]
  11048. },
  11049. handler: (_ref5, args) => {
  11050. let {
  11051. parser,
  11052. funcName
  11053. } = _ref5;
  11054. const numer = args[0];
  11055. const barSize = assertNodeType(args[1], "infix").size;
  11056. if (!barSize) {
  11057. throw new Error("\\\\abovefrac expected size, but got " + String(barSize));
  11058. }
  11059. const denom = args[2];
  11060. const hasBarLine = barSize.number > 0;
  11061. return {
  11062. type: "genfrac",
  11063. mode: parser.mode,
  11064. numer,
  11065. denom,
  11066. continued: false,
  11067. hasBarLine,
  11068. barSize,
  11069. leftDelim: null,
  11070. rightDelim: null
  11071. };
  11072. }
  11073. });
  11074. ;// ./src/functions/horizBrace.ts
  11075. // NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
  11076. // also "supsub" since an over/underbrace can affect super/subscripting.
  11077. const horizBrace_htmlBuilder = (grp, options) => {
  11078. const style = options.style;
  11079. // Pull out the `ParseNode<"horizBrace">` if `grp` is a "supsub" node.
  11080. let supSubGroup;
  11081. let group;
  11082. if (grp.type === "supsub") {
  11083. // Ref: LaTeX source2e: }}}}\limits}
  11084. // i.e. LaTeX treats the brace similar to an op and passes it
  11085. // with \limits, so we need to assign supsub style.
  11086. supSubGroup = grp.sup ? buildGroup(grp.sup, options.havingStyle(style.sup()), options) : buildGroup(grp.sub, options.havingStyle(style.sub()), options);
  11087. group = assertNodeType(grp.base, "horizBrace");
  11088. } else {
  11089. group = assertNodeType(grp, "horizBrace");
  11090. }
  11091. // Build the base group
  11092. const body = buildGroup(group.base, options.havingBaseStyle(src_Style.DISPLAY));
  11093. // Create the stretchy element
  11094. const braceBody = stretchySvg(group, options);
  11095. // Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
  11096. // This first vlist contains the content and the brace: equation
  11097. let vlist;
  11098. if (group.isOver) {
  11099. vlist = makeVList({
  11100. positionType: "firstBaseline",
  11101. children: [{
  11102. type: "elem",
  11103. elem: body
  11104. }, {
  11105. type: "kern",
  11106. size: 0.1
  11107. }, {
  11108. type: "elem",
  11109. elem: braceBody
  11110. }]
  11111. }, options);
  11112. // TODO(ts): Replace this with passing "svg-align" into makeVList.
  11113. vlist.children[0].children[0].children[1].classes.push("svg-align");
  11114. } else {
  11115. vlist = makeVList({
  11116. positionType: "bottom",
  11117. positionData: body.depth + 0.1 + braceBody.height,
  11118. children: [{
  11119. type: "elem",
  11120. elem: braceBody
  11121. }, {
  11122. type: "kern",
  11123. size: 0.1
  11124. }, {
  11125. type: "elem",
  11126. elem: body
  11127. }]
  11128. }, options);
  11129. // TODO(ts): Replace this with passing "svg-align" into makeVList.
  11130. vlist.children[0].children[0].children[0].classes.push("svg-align");
  11131. }
  11132. if (supSubGroup) {
  11133. // To write the supsub, wrap the first vlist in another vlist:
  11134. // They can't all go in the same vlist, because the note might be
  11135. // wider than the equation. We want the equation to control the
  11136. // brace width.
  11137. // note long note long note
  11138. // ┏━━━━━━━━┓ or ┏━━━┓ not ┏━━━━━━━━━┓
  11139. // equation eqn eqn
  11140. const vSpan = makeSpan(["minner", group.isOver ? "mover" : "munder"], [vlist], options);
  11141. if (group.isOver) {
  11142. vlist = makeVList({
  11143. positionType: "firstBaseline",
  11144. children: [{
  11145. type: "elem",
  11146. elem: vSpan
  11147. }, {
  11148. type: "kern",
  11149. size: 0.2
  11150. }, {
  11151. type: "elem",
  11152. elem: supSubGroup
  11153. }]
  11154. }, options);
  11155. } else {
  11156. vlist = makeVList({
  11157. positionType: "bottom",
  11158. positionData: vSpan.depth + 0.2 + supSubGroup.height + supSubGroup.depth,
  11159. children: [{
  11160. type: "elem",
  11161. elem: supSubGroup
  11162. }, {
  11163. type: "kern",
  11164. size: 0.2
  11165. }, {
  11166. type: "elem",
  11167. elem: vSpan
  11168. }]
  11169. }, options);
  11170. }
  11171. }
  11172. return makeSpan(["minner", group.isOver ? "mover" : "munder"], [vlist], options);
  11173. };
  11174. const horizBrace_mathmlBuilder = (group, options) => {
  11175. const accentNode = stretchyMathML(group.label);
  11176. return new MathNode(group.isOver ? "mover" : "munder", [buildMathML_buildGroup(group.base, options), accentNode]);
  11177. };
  11178. // Horizontal stretchy braces
  11179. defineFunction({
  11180. type: "horizBrace",
  11181. names: ["\\overbrace", "\\underbrace", "\\overbracket", "\\underbracket"],
  11182. props: {
  11183. numArgs: 1
  11184. },
  11185. handler(_ref, args) {
  11186. let {
  11187. parser,
  11188. funcName
  11189. } = _ref;
  11190. return {
  11191. type: "horizBrace",
  11192. mode: parser.mode,
  11193. label: funcName,
  11194. isOver: funcName.includes("\\over"),
  11195. base: args[0]
  11196. };
  11197. },
  11198. htmlBuilder: horizBrace_htmlBuilder,
  11199. mathmlBuilder: horizBrace_mathmlBuilder
  11200. });
  11201. ;// ./src/functions/href.ts
  11202. defineFunction({
  11203. type: "href",
  11204. names: ["\\href"],
  11205. props: {
  11206. numArgs: 2,
  11207. argTypes: ["url", "original"],
  11208. allowedInText: true
  11209. },
  11210. handler: (_ref, args) => {
  11211. let {
  11212. parser
  11213. } = _ref;
  11214. const body = args[1];
  11215. const href = assertNodeType(args[0], "url").url;
  11216. if (!parser.settings.isTrusted({
  11217. command: "\\href",
  11218. url: href
  11219. })) {
  11220. return parser.formatUnsupportedCmd("\\href");
  11221. }
  11222. return {
  11223. type: "href",
  11224. mode: parser.mode,
  11225. href,
  11226. body: ordargument(body)
  11227. };
  11228. },
  11229. htmlBuilder: (group, options) => {
  11230. const elements = buildExpression(group.body, options, false);
  11231. return makeAnchor(group.href, [], elements, options);
  11232. },
  11233. mathmlBuilder: (group, options) => {
  11234. let math = buildExpressionRow(group.body, options);
  11235. if (!(math instanceof MathNode)) {
  11236. math = new MathNode("mrow", [math]);
  11237. }
  11238. math.setAttribute("href", group.href);
  11239. return math;
  11240. }
  11241. });
  11242. defineFunction({
  11243. type: "href",
  11244. names: ["\\url"],
  11245. props: {
  11246. numArgs: 1,
  11247. argTypes: ["url"],
  11248. allowedInText: true
  11249. },
  11250. handler: (_ref2, args) => {
  11251. let {
  11252. parser
  11253. } = _ref2;
  11254. const href = assertNodeType(args[0], "url").url;
  11255. if (!parser.settings.isTrusted({
  11256. command: "\\url",
  11257. url: href
  11258. })) {
  11259. return parser.formatUnsupportedCmd("\\url");
  11260. }
  11261. const chars = [];
  11262. for (let i = 0; i < href.length; i++) {
  11263. let c = href[i];
  11264. if (c === "~") {
  11265. c = "\\textasciitilde";
  11266. }
  11267. chars.push({
  11268. type: "textord",
  11269. mode: "text",
  11270. text: c
  11271. });
  11272. }
  11273. const body = {
  11274. type: "text",
  11275. mode: parser.mode,
  11276. font: "\\texttt",
  11277. body: chars
  11278. };
  11279. return {
  11280. type: "href",
  11281. mode: parser.mode,
  11282. href,
  11283. body: ordargument(body)
  11284. };
  11285. }
  11286. });
  11287. ;// ./src/functions/hbox.ts
  11288. // \hbox is provided for compatibility with LaTeX \vcenter.
  11289. // In LaTeX, \vcenter can act only on a box, as in
  11290. // \vcenter{\hbox{$\frac{a+b}{\dfrac{c}{d}}$}}
  11291. // This function by itself doesn't do anything but prevent a soft line break.
  11292. defineFunction({
  11293. type: "hbox",
  11294. names: ["\\hbox"],
  11295. props: {
  11296. numArgs: 1,
  11297. argTypes: ["text"],
  11298. allowedInText: true,
  11299. primitive: true
  11300. },
  11301. handler(_ref, args) {
  11302. let {
  11303. parser
  11304. } = _ref;
  11305. return {
  11306. type: "hbox",
  11307. mode: parser.mode,
  11308. body: ordargument(args[0])
  11309. };
  11310. },
  11311. htmlBuilder(group, options) {
  11312. const elements = buildExpression(group.body, options, false);
  11313. return makeFragment(elements);
  11314. },
  11315. mathmlBuilder(group, options) {
  11316. return new MathNode("mrow", buildMathML_buildExpression(group.body, options));
  11317. }
  11318. });
  11319. ;// ./src/functions/html.ts
  11320. defineFunction({
  11321. type: "html",
  11322. names: ["\\htmlClass", "\\htmlId", "\\htmlStyle", "\\htmlData"],
  11323. props: {
  11324. numArgs: 2,
  11325. argTypes: ["raw", "original"],
  11326. allowedInText: true
  11327. },
  11328. handler: (_ref, args) => {
  11329. let {
  11330. parser,
  11331. funcName,
  11332. token
  11333. } = _ref;
  11334. const value = assertNodeType(args[0], "raw").string;
  11335. const body = args[1];
  11336. if (parser.settings.strict) {
  11337. parser.settings.reportNonstrict("htmlExtension", "HTML extension is disabled on strict mode");
  11338. }
  11339. let trustContext;
  11340. const attributes = {};
  11341. switch (funcName) {
  11342. case "\\htmlClass":
  11343. attributes.class = value;
  11344. trustContext = {
  11345. command: "\\htmlClass",
  11346. class: value
  11347. };
  11348. break;
  11349. case "\\htmlId":
  11350. attributes.id = value;
  11351. trustContext = {
  11352. command: "\\htmlId",
  11353. id: value
  11354. };
  11355. break;
  11356. case "\\htmlStyle":
  11357. attributes.style = value;
  11358. trustContext = {
  11359. command: "\\htmlStyle",
  11360. style: value
  11361. };
  11362. break;
  11363. case "\\htmlData":
  11364. {
  11365. const data = value.split(",");
  11366. for (let i = 0; i < data.length; i++) {
  11367. const item = data[i];
  11368. const firstEquals = item.indexOf("=");
  11369. if (firstEquals < 0) {
  11370. throw new src_ParseError("\\htmlData key/value '" + item + "'" + " missing equals sign");
  11371. }
  11372. const key = item.slice(0, firstEquals);
  11373. const value = item.slice(firstEquals + 1);
  11374. attributes["data-" + key.trim()] = value;
  11375. }
  11376. trustContext = {
  11377. command: "\\htmlData",
  11378. attributes
  11379. };
  11380. break;
  11381. }
  11382. default:
  11383. throw new Error("Unrecognized html command");
  11384. }
  11385. if (!parser.settings.isTrusted(trustContext)) {
  11386. return parser.formatUnsupportedCmd(funcName);
  11387. }
  11388. return {
  11389. type: "html",
  11390. mode: parser.mode,
  11391. attributes,
  11392. body: ordargument(body)
  11393. };
  11394. },
  11395. htmlBuilder: (group, options) => {
  11396. const elements = buildExpression(group.body, options, false);
  11397. const classes = ["enclosing"];
  11398. if (group.attributes.class) {
  11399. classes.push(...group.attributes.class.trim().split(/\s+/));
  11400. }
  11401. const span = makeSpan(classes, elements, options);
  11402. for (const attr in group.attributes) {
  11403. if (attr !== "class" && group.attributes.hasOwnProperty(attr)) {
  11404. span.setAttribute(attr, group.attributes[attr]);
  11405. }
  11406. }
  11407. return span;
  11408. },
  11409. mathmlBuilder: (group, options) => {
  11410. return buildExpressionRow(group.body, options);
  11411. }
  11412. });
  11413. ;// ./src/functions/htmlmathml.ts
  11414. defineFunction({
  11415. type: "htmlmathml",
  11416. names: ["\\html@mathml"],
  11417. props: {
  11418. numArgs: 2,
  11419. allowedInArgument: true,
  11420. allowedInText: true
  11421. },
  11422. handler: (_ref, args) => {
  11423. let {
  11424. parser
  11425. } = _ref;
  11426. return {
  11427. type: "htmlmathml",
  11428. mode: parser.mode,
  11429. html: ordargument(args[0]),
  11430. mathml: ordargument(args[1])
  11431. };
  11432. },
  11433. htmlBuilder: (group, options) => {
  11434. const elements = buildExpression(group.html, options, false);
  11435. return makeFragment(elements);
  11436. },
  11437. mathmlBuilder: (group, options) => {
  11438. return buildExpressionRow(group.mathml, options);
  11439. }
  11440. });
  11441. ;// ./src/functions/includegraphics.ts
  11442. const sizeData = function (str) {
  11443. if (/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(str)) {
  11444. // str is a number with no unit specified.
  11445. // default unit is bp, per graphix package.
  11446. return {
  11447. number: +str,
  11448. unit: "bp"
  11449. };
  11450. } else {
  11451. const match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(str);
  11452. if (!match) {
  11453. throw new src_ParseError("Invalid size: '" + str + "' in \\includegraphics");
  11454. }
  11455. const data = {
  11456. number: +(match[1] + match[2]),
  11457. // sign + magnitude, cast to number
  11458. unit: match[3]
  11459. };
  11460. if (!validUnit(data)) {
  11461. throw new src_ParseError("Invalid unit: '" + data.unit + "' in \\includegraphics.");
  11462. }
  11463. return data;
  11464. }
  11465. };
  11466. defineFunction({
  11467. type: "includegraphics",
  11468. names: ["\\includegraphics"],
  11469. props: {
  11470. numArgs: 1,
  11471. numOptionalArgs: 1,
  11472. argTypes: ["raw", "url"],
  11473. allowedInText: false
  11474. },
  11475. handler: (_ref, args, optArgs) => {
  11476. let {
  11477. parser
  11478. } = _ref;
  11479. let width = {
  11480. number: 0,
  11481. unit: "em"
  11482. };
  11483. let height = {
  11484. number: 0.9,
  11485. unit: "em"
  11486. }; // sorta character sized.
  11487. let totalheight = {
  11488. number: 0,
  11489. unit: "em"
  11490. };
  11491. let alt = "";
  11492. if (optArgs[0]) {
  11493. const attributeStr = assertNodeType(optArgs[0], "raw").string;
  11494. // Parser.js does not parse key/value pairs. We get a string.
  11495. const attributes = attributeStr.split(",");
  11496. for (let i = 0; i < attributes.length; i++) {
  11497. const keyVal = attributes[i].split("=");
  11498. if (keyVal.length === 2) {
  11499. const str = keyVal[1].trim();
  11500. switch (keyVal[0].trim()) {
  11501. case "alt":
  11502. alt = str;
  11503. break;
  11504. case "width":
  11505. width = sizeData(str);
  11506. break;
  11507. case "height":
  11508. height = sizeData(str);
  11509. break;
  11510. case "totalheight":
  11511. totalheight = sizeData(str);
  11512. break;
  11513. default:
  11514. throw new src_ParseError("Invalid key: '" + keyVal[0] + "' in \\includegraphics.");
  11515. }
  11516. }
  11517. }
  11518. }
  11519. const src = assertNodeType(args[0], "url").url;
  11520. if (alt === "") {
  11521. // No alt given. Use the file name. Strip away the path.
  11522. alt = src;
  11523. alt = alt.replace(/^.*[\\/]/, '');
  11524. alt = alt.substring(0, alt.lastIndexOf('.'));
  11525. }
  11526. if (!parser.settings.isTrusted({
  11527. command: "\\includegraphics",
  11528. url: src
  11529. })) {
  11530. return parser.formatUnsupportedCmd("\\includegraphics");
  11531. }
  11532. return {
  11533. type: "includegraphics",
  11534. mode: parser.mode,
  11535. alt: alt,
  11536. width: width,
  11537. height: height,
  11538. totalheight: totalheight,
  11539. src: src
  11540. };
  11541. },
  11542. htmlBuilder: (group, options) => {
  11543. const height = calculateSize(group.height, options);
  11544. let depth = 0;
  11545. if (group.totalheight.number > 0) {
  11546. depth = calculateSize(group.totalheight, options) - height;
  11547. }
  11548. let width = 0;
  11549. if (group.width.number > 0) {
  11550. width = calculateSize(group.width, options);
  11551. }
  11552. const style = {
  11553. height: makeEm(height + depth)
  11554. };
  11555. if (width > 0) {
  11556. style.width = makeEm(width);
  11557. }
  11558. if (depth > 0) {
  11559. style.verticalAlign = makeEm(-depth);
  11560. }
  11561. const node = new Img(group.src, group.alt, style);
  11562. node.height = height;
  11563. node.depth = depth;
  11564. return node;
  11565. },
  11566. mathmlBuilder: (group, options) => {
  11567. const node = new MathNode("mglyph", []);
  11568. node.setAttribute("alt", group.alt);
  11569. const height = calculateSize(group.height, options);
  11570. let depth = 0;
  11571. if (group.totalheight.number > 0) {
  11572. depth = calculateSize(group.totalheight, options) - height;
  11573. node.setAttribute("valign", makeEm(-depth));
  11574. }
  11575. node.setAttribute("height", makeEm(height + depth));
  11576. if (group.width.number > 0) {
  11577. const width = calculateSize(group.width, options);
  11578. node.setAttribute("width", makeEm(width));
  11579. }
  11580. node.setAttribute("src", group.src);
  11581. return node;
  11582. }
  11583. });
  11584. ;// ./src/functions/kern.ts
  11585. // Horizontal spacing commands
  11586. // TODO: \hskip and \mskip should support plus and minus in lengths
  11587. defineFunction({
  11588. type: "kern",
  11589. names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
  11590. props: {
  11591. numArgs: 1,
  11592. argTypes: ["size"],
  11593. primitive: true,
  11594. allowedInText: true
  11595. },
  11596. handler(_ref, args) {
  11597. let {
  11598. parser,
  11599. funcName
  11600. } = _ref;
  11601. const size = assertNodeType(args[0], "size");
  11602. if (parser.settings.strict) {
  11603. const mathFunction = funcName[1] === 'm'; // \mkern, \mskip
  11604. const muUnit = size.value.unit === 'mu';
  11605. if (mathFunction) {
  11606. if (!muUnit) {
  11607. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " supports only mu units, " + ("not " + size.value.unit + " units"));
  11608. }
  11609. if (parser.mode !== "math") {
  11610. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " works only in math mode");
  11611. }
  11612. } else {
  11613. // !mathFunction
  11614. if (muUnit) {
  11615. parser.settings.reportNonstrict("mathVsTextUnits", "LaTeX's " + funcName + " doesn't support mu units");
  11616. }
  11617. }
  11618. }
  11619. return {
  11620. type: "kern",
  11621. mode: parser.mode,
  11622. dimension: size.value
  11623. };
  11624. },
  11625. htmlBuilder(group, options) {
  11626. return makeGlue(group.dimension, options);
  11627. },
  11628. mathmlBuilder(group, options) {
  11629. const dimension = calculateSize(group.dimension, options);
  11630. return new SpaceNode(dimension);
  11631. }
  11632. });
  11633. ;// ./src/functions/lap.ts
  11634. // Horizontal overlap functions
  11635. defineFunction({
  11636. type: "lap",
  11637. names: ["\\mathllap", "\\mathrlap", "\\mathclap"],
  11638. props: {
  11639. numArgs: 1,
  11640. allowedInText: true
  11641. },
  11642. handler: (_ref, args) => {
  11643. let {
  11644. parser,
  11645. funcName
  11646. } = _ref;
  11647. const body = args[0];
  11648. return {
  11649. type: "lap",
  11650. mode: parser.mode,
  11651. alignment: funcName.slice(5),
  11652. body
  11653. };
  11654. },
  11655. htmlBuilder: (group, options) => {
  11656. // mathllap, mathrlap, mathclap
  11657. let inner;
  11658. if (group.alignment === "clap") {
  11659. // ref: https://www.math.lsu.edu/~aperlis/publications/mathclap/
  11660. inner = makeSpan([], [buildGroup(group.body, options)]);
  11661. // wrap, since CSS will center a .clap > .inner > span
  11662. inner = makeSpan(["inner"], [inner], options);
  11663. } else {
  11664. inner = makeSpan(["inner"], [buildGroup(group.body, options)]);
  11665. }
  11666. const fix = makeSpan(["fix"], []);
  11667. let node = makeSpan([group.alignment], [inner, fix], options);
  11668. // At this point, we have correctly set horizontal alignment of the
  11669. // two items involved in the lap.
  11670. // Next, use a strut to set the height of the HTML bounding box.
  11671. // Otherwise, a tall argument may be misplaced.
  11672. // This code resolved issue #1153
  11673. const strut = makeSpan(["strut"]);
  11674. strut.style.height = makeEm(node.height + node.depth);
  11675. if (node.depth) {
  11676. strut.style.verticalAlign = makeEm(-node.depth);
  11677. }
  11678. node.children.unshift(strut);
  11679. // Next, prevent vertical misplacement when next to something tall.
  11680. // This code resolves issue #1234
  11681. node = makeSpan(["thinbox"], [node], options);
  11682. return makeSpan(["mord", "vbox"], [node], options);
  11683. },
  11684. mathmlBuilder: (group, options) => {
  11685. // mathllap, mathrlap, mathclap
  11686. const node = new MathNode("mpadded", [buildMathML_buildGroup(group.body, options)]);
  11687. if (group.alignment !== "rlap") {
  11688. const offset = group.alignment === "llap" ? "-1" : "-0.5";
  11689. node.setAttribute("lspace", offset + "width");
  11690. }
  11691. node.setAttribute("width", "0px");
  11692. return node;
  11693. }
  11694. });
  11695. ;// ./src/functions/math.ts
  11696. // Switching from text mode back to math mode
  11697. defineFunction({
  11698. type: "styling",
  11699. names: ["\\(", "$"],
  11700. props: {
  11701. numArgs: 0,
  11702. allowedInText: true,
  11703. allowedInMath: false
  11704. },
  11705. handler(_ref, args) {
  11706. let {
  11707. funcName,
  11708. parser
  11709. } = _ref;
  11710. const outerMode = parser.mode;
  11711. parser.switchMode("math");
  11712. const close = funcName === "\\(" ? "\\)" : "$";
  11713. const body = parser.parseExpression(false, close);
  11714. parser.expect(close);
  11715. parser.switchMode(outerMode);
  11716. return {
  11717. type: "styling",
  11718. mode: parser.mode,
  11719. style: "text",
  11720. body
  11721. };
  11722. }
  11723. });
  11724. // Check for extra closing math delimiters
  11725. defineFunction({
  11726. type: "text",
  11727. // Doesn't matter what this is.
  11728. names: ["\\)", "\\]"],
  11729. props: {
  11730. numArgs: 0,
  11731. allowedInText: true,
  11732. allowedInMath: false
  11733. },
  11734. handler(context, args) {
  11735. throw new src_ParseError("Mismatched " + context.funcName);
  11736. }
  11737. });
  11738. ;// ./src/functions/mathchoice.ts
  11739. const chooseMathStyle = (group, options) => {
  11740. switch (options.style.size) {
  11741. case src_Style.DISPLAY.size:
  11742. return group.display;
  11743. case src_Style.TEXT.size:
  11744. return group.text;
  11745. case src_Style.SCRIPT.size:
  11746. return group.script;
  11747. case src_Style.SCRIPTSCRIPT.size:
  11748. return group.scriptscript;
  11749. default:
  11750. return group.text;
  11751. }
  11752. };
  11753. defineFunction({
  11754. type: "mathchoice",
  11755. names: ["\\mathchoice"],
  11756. props: {
  11757. numArgs: 4,
  11758. primitive: true
  11759. },
  11760. handler: (_ref, args) => {
  11761. let {
  11762. parser
  11763. } = _ref;
  11764. return {
  11765. type: "mathchoice",
  11766. mode: parser.mode,
  11767. display: ordargument(args[0]),
  11768. text: ordargument(args[1]),
  11769. script: ordargument(args[2]),
  11770. scriptscript: ordargument(args[3])
  11771. };
  11772. },
  11773. htmlBuilder: (group, options) => {
  11774. const body = chooseMathStyle(group, options);
  11775. const elements = buildExpression(body, options, false);
  11776. return makeFragment(elements);
  11777. },
  11778. mathmlBuilder: (group, options) => {
  11779. const body = chooseMathStyle(group, options);
  11780. return buildExpressionRow(body, options);
  11781. }
  11782. });
  11783. ;// ./src/functions/utils/assembleSupSub.ts
  11784. // For an operator with limits, assemble the base, sup, and sub into a span.
  11785. const assembleSupSub = (base, supGroup, subGroup, options, style, slant, baseShift) => {
  11786. base = makeSpan([], [base]);
  11787. const subIsSingleCharacter = subGroup && isCharacterBox(subGroup);
  11788. let sub;
  11789. let sup;
  11790. // We manually have to handle the superscripts and subscripts. This,
  11791. // aside from the kern calculations, is copied from supsub.
  11792. if (supGroup) {
  11793. const elem = buildGroup(supGroup, options.havingStyle(style.sup()), options);
  11794. sup = {
  11795. elem,
  11796. kern: Math.max(options.fontMetrics().bigOpSpacing1, options.fontMetrics().bigOpSpacing3 - elem.depth)
  11797. };
  11798. }
  11799. if (subGroup) {
  11800. const elem = buildGroup(subGroup, options.havingStyle(style.sub()), options);
  11801. sub = {
  11802. elem,
  11803. kern: Math.max(options.fontMetrics().bigOpSpacing2, options.fontMetrics().bigOpSpacing4 - elem.height)
  11804. };
  11805. }
  11806. // Build the final group as a vlist of the possible subscript, base,
  11807. // and possible superscript.
  11808. let finalGroup;
  11809. if (sup && sub) {
  11810. const bottom = options.fontMetrics().bigOpSpacing5 + sub.elem.height + sub.elem.depth + sub.kern + base.depth + baseShift;
  11811. finalGroup = makeVList({
  11812. positionType: "bottom",
  11813. positionData: bottom,
  11814. children: [{
  11815. type: "kern",
  11816. size: options.fontMetrics().bigOpSpacing5
  11817. }, {
  11818. type: "elem",
  11819. elem: sub.elem,
  11820. marginLeft: makeEm(-slant)
  11821. }, {
  11822. type: "kern",
  11823. size: sub.kern
  11824. }, {
  11825. type: "elem",
  11826. elem: base
  11827. }, {
  11828. type: "kern",
  11829. size: sup.kern
  11830. }, {
  11831. type: "elem",
  11832. elem: sup.elem,
  11833. marginLeft: makeEm(slant)
  11834. }, {
  11835. type: "kern",
  11836. size: options.fontMetrics().bigOpSpacing5
  11837. }]
  11838. }, options);
  11839. } else if (sub) {
  11840. const top = base.height - baseShift;
  11841. // Shift the limits by the slant of the symbol. Note
  11842. // that we are supposed to shift the limits by 1/2 of the slant,
  11843. // but since we are centering the limits adding a full slant of
  11844. // margin will shift by 1/2 that.
  11845. finalGroup = makeVList({
  11846. positionType: "top",
  11847. positionData: top,
  11848. children: [{
  11849. type: "kern",
  11850. size: options.fontMetrics().bigOpSpacing5
  11851. }, {
  11852. type: "elem",
  11853. elem: sub.elem,
  11854. marginLeft: makeEm(-slant)
  11855. }, {
  11856. type: "kern",
  11857. size: sub.kern
  11858. }, {
  11859. type: "elem",
  11860. elem: base
  11861. }]
  11862. }, options);
  11863. } else if (sup) {
  11864. const bottom = base.depth + baseShift;
  11865. finalGroup = makeVList({
  11866. positionType: "bottom",
  11867. positionData: bottom,
  11868. children: [{
  11869. type: "elem",
  11870. elem: base
  11871. }, {
  11872. type: "kern",
  11873. size: sup.kern
  11874. }, {
  11875. type: "elem",
  11876. elem: sup.elem,
  11877. marginLeft: makeEm(slant)
  11878. }, {
  11879. type: "kern",
  11880. size: options.fontMetrics().bigOpSpacing5
  11881. }]
  11882. }, options);
  11883. } else {
  11884. // This case probably shouldn't occur (this would mean the
  11885. // supsub was sending us a group with no superscript or
  11886. // subscript) but be safe.
  11887. return base;
  11888. }
  11889. const parts = [finalGroup];
  11890. if (sub && slant !== 0 && !subIsSingleCharacter) {
  11891. // A negative margin-left was applied to the lower limit.
  11892. // Avoid an overlap by placing a spacer on the left on the group.
  11893. const spacer = makeSpan(["mspace"], [], options);
  11894. spacer.style.marginRight = makeEm(slant);
  11895. parts.unshift(spacer);
  11896. }
  11897. return makeSpan(["mop", "op-limits"], parts, options);
  11898. };
  11899. ;// ./src/functions/op.ts
  11900. // Limits, symbols
  11901. // Most operators have a large successor symbol, but these don't.
  11902. const noSuccessor = new Set(["\\smallint"]);
  11903. // NOTE: Unlike most `htmlBuilder`s, this one handles not only "op", but also
  11904. // "supsub" since some of them (like \int) can affect super/subscripting.
  11905. const op_htmlBuilder = (grp, options) => {
  11906. // Operators are handled in the TeXbook pg. 443-444, rule 13(a).
  11907. let supGroup;
  11908. let subGroup;
  11909. let hasLimits = false;
  11910. let group;
  11911. if (grp.type === "supsub") {
  11912. // If we have limits, supsub will pass us its group to handle. Pull
  11913. // out the superscript and subscript and set the group to the op in
  11914. // its base.
  11915. supGroup = grp.sup;
  11916. subGroup = grp.sub;
  11917. group = assertNodeType(grp.base, "op");
  11918. hasLimits = true;
  11919. } else {
  11920. group = assertNodeType(grp, "op");
  11921. }
  11922. const style = options.style;
  11923. let large = false;
  11924. if (style.size === src_Style.DISPLAY.size && group.symbol && !noSuccessor.has(group.name)) {
  11925. // Most symbol operators get larger in displaystyle (rule 13)
  11926. large = true;
  11927. }
  11928. let base;
  11929. if (group.symbol) {
  11930. // If this is a symbol, create the symbol.
  11931. const fontName = large ? "Size2-Regular" : "Size1-Regular";
  11932. let stash = "";
  11933. if (group.name === "\\oiint" || group.name === "\\oiiint") {
  11934. // No font glyphs yet, so use a glyph w/o the oval.
  11935. // TODO: When font glyphs are available, delete this code.
  11936. stash = group.name.slice(1);
  11937. group.name = stash === "oiint" ? "\\iint" : "\\iiint";
  11938. }
  11939. base = makeSymbol(group.name, fontName, "math", options, ["mop", "op-symbol", large ? "large-op" : "small-op"]);
  11940. if (stash.length > 0) {
  11941. // We're in \oiint or \oiiint. Overlay the oval.
  11942. // TODO: When font glyphs are available, delete this code.
  11943. const italic = base.italic;
  11944. const oval = staticSvg(stash + "Size" + (large ? "2" : "1"), options);
  11945. base = makeVList({
  11946. positionType: "individualShift",
  11947. children: [{
  11948. type: "elem",
  11949. elem: base,
  11950. shift: 0
  11951. }, {
  11952. type: "elem",
  11953. elem: oval,
  11954. shift: large ? 0.08 : 0
  11955. }]
  11956. }, options);
  11957. group.name = "\\" + stash;
  11958. base.classes.unshift("mop");
  11959. // TODO(ts)
  11960. base.italic = italic;
  11961. }
  11962. } else if (group.body) {
  11963. // If this is a list, compose that list.
  11964. const inner = buildExpression(group.body, options, true);
  11965. if (inner.length === 1 && inner[0] instanceof SymbolNode) {
  11966. base = inner[0];
  11967. base.classes[0] = "mop"; // replace old mclass
  11968. } else {
  11969. base = makeSpan(["mop"], inner, options);
  11970. }
  11971. } else {
  11972. // Otherwise, this is a text operator. Build the text from the
  11973. // operator's name.
  11974. const output = [];
  11975. for (let i = 1; i < group.name.length; i++) {
  11976. output.push(mathsym(group.name[i], group.mode, options));
  11977. }
  11978. base = makeSpan(["mop"], output, options);
  11979. }
  11980. // If content of op is a single symbol, shift it vertically.
  11981. let baseShift = 0;
  11982. let slant = 0;
  11983. if ((base instanceof SymbolNode || group.name === "\\oiint" || group.name === "\\oiiint") && !group.suppressBaseShift) {
  11984. // We suppress the shift of the base of \overset and \underset. Otherwise,
  11985. // shift the symbol so its center lies on the axis (rule 13). It
  11986. // appears that our fonts have the centers of the symbols already
  11987. // almost on the axis, so these numbers are very small. Note we
  11988. // don't actually apply this here, but instead it is used either in
  11989. // the vlist creation or separately when there are no limits.
  11990. baseShift = (base.height - base.depth) / 2 - options.fontMetrics().axisHeight;
  11991. // The slant of the symbol is just its italic correction.
  11992. // TODO(ts)
  11993. slant = base.italic || 0;
  11994. }
  11995. if (hasLimits) {
  11996. return assembleSupSub(base, supGroup, subGroup, options, style, slant, baseShift);
  11997. } else {
  11998. if (baseShift) {
  11999. base.style.position = "relative";
  12000. base.style.top = makeEm(baseShift);
  12001. }
  12002. return base;
  12003. }
  12004. };
  12005. const op_mathmlBuilder = (group, options) => {
  12006. let node;
  12007. if (group.symbol) {
  12008. // This is a symbol. Just add the symbol.
  12009. node = new MathNode("mo", [makeText(group.name, group.mode)]);
  12010. if (noSuccessor.has(group.name)) {
  12011. node.setAttribute("largeop", "false");
  12012. }
  12013. } else if (group.body) {
  12014. // This is an operator with children. Add them.
  12015. node = new MathNode("mo", buildMathML_buildExpression(group.body, options));
  12016. } else {
  12017. // This is a text operator. Add all the characters from the
  12018. // operator's name.
  12019. node = new MathNode("mi", [new TextNode(group.name.slice(1))]);
  12020. // Append an <mo>&ApplyFunction;</mo>.
  12021. // ref: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4
  12022. const operator = new MathNode("mo", [makeText("\u2061", "text")]);
  12023. if (group.parentIsSupSub) {
  12024. node = new MathNode("mrow", [node, operator]);
  12025. } else {
  12026. node = newDocumentFragment([node, operator]);
  12027. }
  12028. }
  12029. return node;
  12030. };
  12031. const singleCharBigOps = {
  12032. "\u220F": "\\prod",
  12033. "\u2210": "\\coprod",
  12034. "\u2211": "\\sum",
  12035. "\u22c0": "\\bigwedge",
  12036. "\u22c1": "\\bigvee",
  12037. "\u22c2": "\\bigcap",
  12038. "\u22c3": "\\bigcup",
  12039. "\u2a00": "\\bigodot",
  12040. "\u2a01": "\\bigoplus",
  12041. "\u2a02": "\\bigotimes",
  12042. "\u2a04": "\\biguplus",
  12043. "\u2a06": "\\bigsqcup"
  12044. };
  12045. defineFunction({
  12046. type: "op",
  12047. 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"],
  12048. props: {
  12049. numArgs: 0
  12050. },
  12051. handler: (_ref, args) => {
  12052. let {
  12053. parser,
  12054. funcName
  12055. } = _ref;
  12056. let fName = funcName;
  12057. if (fName.length === 1) {
  12058. fName = singleCharBigOps[fName];
  12059. }
  12060. return {
  12061. type: "op",
  12062. mode: parser.mode,
  12063. limits: true,
  12064. parentIsSupSub: false,
  12065. symbol: true,
  12066. name: fName
  12067. };
  12068. },
  12069. htmlBuilder: op_htmlBuilder,
  12070. mathmlBuilder: op_mathmlBuilder
  12071. });
  12072. // Note: calling defineFunction with a type that's already been defined only
  12073. // works because the same htmlBuilder and mathmlBuilder are being used.
  12074. defineFunction({
  12075. type: "op",
  12076. names: ["\\mathop"],
  12077. props: {
  12078. numArgs: 1,
  12079. primitive: true
  12080. },
  12081. handler: (_ref2, args) => {
  12082. let {
  12083. parser
  12084. } = _ref2;
  12085. const body = args[0];
  12086. return {
  12087. type: "op",
  12088. mode: parser.mode,
  12089. limits: false,
  12090. parentIsSupSub: false,
  12091. symbol: false,
  12092. body: ordargument(body)
  12093. };
  12094. },
  12095. htmlBuilder: op_htmlBuilder,
  12096. mathmlBuilder: op_mathmlBuilder
  12097. });
  12098. // There are 2 flags for operators; whether they produce limits in
  12099. // displaystyle, and whether they are symbols and should grow in
  12100. // displaystyle. These four groups cover the four possible choices.
  12101. const singleCharIntegrals = {
  12102. "\u222b": "\\int",
  12103. "\u222c": "\\iint",
  12104. "\u222d": "\\iiint",
  12105. "\u222e": "\\oint",
  12106. "\u222f": "\\oiint",
  12107. "\u2230": "\\oiiint"
  12108. };
  12109. // No limits, not symbols
  12110. defineFunction({
  12111. type: "op",
  12112. 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"],
  12113. props: {
  12114. numArgs: 0
  12115. },
  12116. handler(_ref3) {
  12117. let {
  12118. parser,
  12119. funcName
  12120. } = _ref3;
  12121. return {
  12122. type: "op",
  12123. mode: parser.mode,
  12124. limits: false,
  12125. parentIsSupSub: false,
  12126. symbol: false,
  12127. name: funcName
  12128. };
  12129. },
  12130. htmlBuilder: op_htmlBuilder,
  12131. mathmlBuilder: op_mathmlBuilder
  12132. });
  12133. // Limits, not symbols
  12134. defineFunction({
  12135. type: "op",
  12136. names: ["\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup"],
  12137. props: {
  12138. numArgs: 0
  12139. },
  12140. handler(_ref4) {
  12141. let {
  12142. parser,
  12143. funcName
  12144. } = _ref4;
  12145. return {
  12146. type: "op",
  12147. mode: parser.mode,
  12148. limits: true,
  12149. parentIsSupSub: false,
  12150. symbol: false,
  12151. name: funcName
  12152. };
  12153. },
  12154. htmlBuilder: op_htmlBuilder,
  12155. mathmlBuilder: op_mathmlBuilder
  12156. });
  12157. // No limits, symbols
  12158. defineFunction({
  12159. type: "op",
  12160. names: ["\\int", "\\iint", "\\iiint", "\\oint", "\\oiint", "\\oiiint", "\u222b", "\u222c", "\u222d", "\u222e", "\u222f", "\u2230"],
  12161. props: {
  12162. numArgs: 0,
  12163. allowedInArgument: true
  12164. },
  12165. handler(_ref5) {
  12166. let {
  12167. parser,
  12168. funcName
  12169. } = _ref5;
  12170. let fName = funcName;
  12171. if (fName.length === 1) {
  12172. fName = singleCharIntegrals[fName];
  12173. }
  12174. return {
  12175. type: "op",
  12176. mode: parser.mode,
  12177. limits: false,
  12178. parentIsSupSub: false,
  12179. symbol: true,
  12180. name: fName
  12181. };
  12182. },
  12183. htmlBuilder: op_htmlBuilder,
  12184. mathmlBuilder: op_mathmlBuilder
  12185. });
  12186. ;// ./src/functions/operatorname.ts
  12187. // NOTE: Unlike most `htmlBuilder`s, this one handles not only
  12188. // "operatorname", but also "supsub" since \operatorname* can
  12189. // affect super/subscripting.
  12190. const operatorname_htmlBuilder = (grp, options) => {
  12191. // Operators are handled in the TeXbook pg. 443-444, rule 13(a).
  12192. let supGroup;
  12193. let subGroup;
  12194. let hasLimits = false;
  12195. let group;
  12196. if (grp.type === "supsub") {
  12197. // If we have limits, supsub will pass us its group to handle. Pull
  12198. // out the superscript and subscript and set the group to the op in
  12199. // its base.
  12200. supGroup = grp.sup;
  12201. subGroup = grp.sub;
  12202. group = assertNodeType(grp.base, "operatorname");
  12203. hasLimits = true;
  12204. } else {
  12205. group = assertNodeType(grp, "operatorname");
  12206. }
  12207. let base;
  12208. if (group.body.length > 0) {
  12209. const body = group.body.map(child => {
  12210. const childText = "text" in child ? child.text : undefined;
  12211. if (typeof childText === "string") {
  12212. return {
  12213. type: "textord",
  12214. mode: child.mode,
  12215. text: childText
  12216. };
  12217. } else {
  12218. return child;
  12219. }
  12220. });
  12221. // Consolidate function names into symbol characters.
  12222. const expression = buildExpression(body, options.withFont("mathrm"), true);
  12223. for (let i = 0; i < expression.length; i++) {
  12224. const child = expression[i];
  12225. if (child instanceof SymbolNode) {
  12226. // Per amsopn package,
  12227. // change minus to hyphen and \ast to asterisk
  12228. child.text = child.text.replace(/\u2212/, "-").replace(/\u2217/, "*");
  12229. }
  12230. }
  12231. base = makeSpan(["mop"], expression, options);
  12232. } else {
  12233. base = makeSpan(["mop"], [], options);
  12234. }
  12235. if (hasLimits) {
  12236. return assembleSupSub(base, supGroup, subGroup, options, options.style, 0, 0);
  12237. } else {
  12238. return base;
  12239. }
  12240. };
  12241. const operatorname_mathmlBuilder = (group, options) => {
  12242. // The steps taken here are similar to the html version.
  12243. let expression = buildMathML_buildExpression(group.body, options.withFont("mathrm"));
  12244. // Is expression a string or has it something like a fraction?
  12245. let isAllString = true; // default
  12246. for (let i = 0; i < expression.length; i++) {
  12247. const node = expression[i];
  12248. if (node instanceof SpaceNode) {
  12249. // Do nothing
  12250. } else if (node instanceof MathNode) {
  12251. switch (node.type) {
  12252. case "mi":
  12253. case "mn":
  12254. case "mspace":
  12255. case "mtext":
  12256. break;
  12257. // Do nothing yet.
  12258. case "mo":
  12259. {
  12260. const child = node.children[0];
  12261. if (node.children.length === 1 && child instanceof TextNode) {
  12262. child.text = child.text.replace(/\u2212/, "-").replace(/\u2217/, "*");
  12263. } else {
  12264. isAllString = false;
  12265. }
  12266. break;
  12267. }
  12268. default:
  12269. isAllString = false;
  12270. }
  12271. } else {
  12272. isAllString = false;
  12273. }
  12274. }
  12275. if (isAllString) {
  12276. // Write a single TextNode instead of multiple nested tags.
  12277. const word = expression.map(node => node.toText()).join("");
  12278. expression = [new TextNode(word)];
  12279. }
  12280. const identifier = new MathNode("mi", expression);
  12281. identifier.setAttribute("mathvariant", "normal");
  12282. // \u2061 is the same as &ApplyFunction;
  12283. // ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp
  12284. const operator = new MathNode("mo", [makeText("\u2061", "text")]);
  12285. if (group.parentIsSupSub) {
  12286. return new MathNode("mrow", [identifier, operator]);
  12287. } else {
  12288. return newDocumentFragment([identifier, operator]);
  12289. }
  12290. };
  12291. // \operatorname
  12292. // amsopn.dtx: \mathop{#1\kern\z@\operator@font#3}\newmcodes@
  12293. defineFunction({
  12294. type: "operatorname",
  12295. names: ["\\operatorname@", "\\operatornamewithlimits"],
  12296. props: {
  12297. numArgs: 1
  12298. },
  12299. handler: (_ref, args) => {
  12300. let {
  12301. parser,
  12302. funcName
  12303. } = _ref;
  12304. const body = args[0];
  12305. return {
  12306. type: "operatorname",
  12307. mode: parser.mode,
  12308. body: ordargument(body),
  12309. alwaysHandleSupSub: funcName === "\\operatornamewithlimits",
  12310. limits: false,
  12311. parentIsSupSub: false
  12312. };
  12313. },
  12314. htmlBuilder: operatorname_htmlBuilder,
  12315. mathmlBuilder: operatorname_mathmlBuilder
  12316. });
  12317. defineMacro("\\operatorname", "\\@ifstar\\operatornamewithlimits\\operatorname@");
  12318. ;// ./src/functions/ordgroup.ts
  12319. defineFunctionBuilders({
  12320. type: "ordgroup",
  12321. htmlBuilder(group, options) {
  12322. if (group.semisimple) {
  12323. return makeFragment(buildExpression(group.body, options, false));
  12324. }
  12325. return makeSpan(["mord"], buildExpression(group.body, options, true), options);
  12326. },
  12327. mathmlBuilder(group, options) {
  12328. return buildExpressionRow(group.body, options, true);
  12329. }
  12330. });
  12331. ;// ./src/functions/overline.ts
  12332. defineFunction({
  12333. type: "overline",
  12334. names: ["\\overline"],
  12335. props: {
  12336. numArgs: 1
  12337. },
  12338. handler(_ref, args) {
  12339. let {
  12340. parser
  12341. } = _ref;
  12342. const body = args[0];
  12343. return {
  12344. type: "overline",
  12345. mode: parser.mode,
  12346. body
  12347. };
  12348. },
  12349. htmlBuilder(group, options) {
  12350. // Overlines are handled in the TeXbook pg 443, Rule 9.
  12351. // Build the inner group in the cramped style.
  12352. const innerGroup = buildGroup(group.body, options.havingCrampedStyle());
  12353. // Create the line above the body
  12354. const line = makeLineSpan("overline-line", options);
  12355. // Generate the vlist, with the appropriate kerns
  12356. const defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
  12357. const vlist = makeVList({
  12358. positionType: "firstBaseline",
  12359. children: [{
  12360. type: "elem",
  12361. elem: innerGroup
  12362. }, {
  12363. type: "kern",
  12364. size: 3 * defaultRuleThickness
  12365. }, {
  12366. type: "elem",
  12367. elem: line
  12368. }, {
  12369. type: "kern",
  12370. size: defaultRuleThickness
  12371. }]
  12372. }, options);
  12373. return makeSpan(["mord", "overline"], [vlist], options);
  12374. },
  12375. mathmlBuilder(group, options) {
  12376. const operator = new MathNode("mo", [new TextNode("\u203e")]);
  12377. operator.setAttribute("stretchy", "true");
  12378. const node = new MathNode("mover", [buildMathML_buildGroup(group.body, options), operator]);
  12379. node.setAttribute("accent", "true");
  12380. return node;
  12381. }
  12382. });
  12383. ;// ./src/functions/phantom.ts
  12384. defineFunction({
  12385. type: "phantom",
  12386. names: ["\\phantom"],
  12387. props: {
  12388. numArgs: 1,
  12389. allowedInText: true
  12390. },
  12391. handler: (_ref, args) => {
  12392. let {
  12393. parser
  12394. } = _ref;
  12395. const body = args[0];
  12396. return {
  12397. type: "phantom",
  12398. mode: parser.mode,
  12399. body: ordargument(body)
  12400. };
  12401. },
  12402. htmlBuilder: (group, options) => {
  12403. const elements = buildExpression(group.body, options.withPhantom(), false);
  12404. // \phantom isn't supposed to affect the elements it contains.
  12405. // See "color" for more details.
  12406. return makeFragment(elements);
  12407. },
  12408. mathmlBuilder: (group, options) => {
  12409. const inner = buildMathML_buildExpression(group.body, options);
  12410. return new MathNode("mphantom", inner);
  12411. }
  12412. });
  12413. defineMacro("\\hphantom", "\\smash{\\phantom{#1}}");
  12414. defineFunction({
  12415. type: "vphantom",
  12416. names: ["\\vphantom"],
  12417. props: {
  12418. numArgs: 1,
  12419. allowedInText: true
  12420. },
  12421. handler: (_ref2, args) => {
  12422. let {
  12423. parser
  12424. } = _ref2;
  12425. const body = args[0];
  12426. return {
  12427. type: "vphantom",
  12428. mode: parser.mode,
  12429. body
  12430. };
  12431. },
  12432. htmlBuilder: (group, options) => {
  12433. const inner = makeSpan(["inner"], [buildGroup(group.body, options.withPhantom())]);
  12434. const fix = makeSpan(["fix"], []);
  12435. return makeSpan(["mord", "rlap"], [inner, fix], options);
  12436. },
  12437. mathmlBuilder: (group, options) => {
  12438. const inner = buildMathML_buildExpression(ordargument(group.body), options);
  12439. const phantom = new MathNode("mphantom", inner);
  12440. const node = new MathNode("mpadded", [phantom]);
  12441. node.setAttribute("width", "0px");
  12442. return node;
  12443. }
  12444. });
  12445. ;// ./src/functions/raisebox.ts
  12446. // Box manipulation
  12447. defineFunction({
  12448. type: "raisebox",
  12449. names: ["\\raisebox"],
  12450. props: {
  12451. numArgs: 2,
  12452. argTypes: ["size", "hbox"],
  12453. allowedInText: true
  12454. },
  12455. handler(_ref, args) {
  12456. let {
  12457. parser
  12458. } = _ref;
  12459. const amount = assertNodeType(args[0], "size").value;
  12460. const body = args[1];
  12461. return {
  12462. type: "raisebox",
  12463. mode: parser.mode,
  12464. dy: amount,
  12465. body
  12466. };
  12467. },
  12468. htmlBuilder(group, options) {
  12469. const body = buildGroup(group.body, options);
  12470. const dy = calculateSize(group.dy, options);
  12471. return makeVList({
  12472. positionType: "shift",
  12473. positionData: -dy,
  12474. children: [{
  12475. type: "elem",
  12476. elem: body
  12477. }]
  12478. }, options);
  12479. },
  12480. mathmlBuilder(group, options) {
  12481. const node = new MathNode("mpadded", [buildMathML_buildGroup(group.body, options)]);
  12482. const dy = group.dy.number + group.dy.unit;
  12483. node.setAttribute("voffset", dy);
  12484. return node;
  12485. }
  12486. });
  12487. ;// ./src/functions/relax.ts
  12488. defineFunction({
  12489. type: "internal",
  12490. names: ["\\relax"],
  12491. props: {
  12492. numArgs: 0,
  12493. allowedInText: true,
  12494. allowedInArgument: true
  12495. },
  12496. handler(_ref) {
  12497. let {
  12498. parser
  12499. } = _ref;
  12500. return {
  12501. type: "internal",
  12502. mode: parser.mode
  12503. };
  12504. }
  12505. });
  12506. ;// ./src/functions/rule.ts
  12507. defineFunction({
  12508. type: "rule",
  12509. names: ["\\rule"],
  12510. props: {
  12511. numArgs: 2,
  12512. numOptionalArgs: 1,
  12513. allowedInText: true,
  12514. allowedInMath: true,
  12515. argTypes: ["size", "size", "size"]
  12516. },
  12517. handler(_ref, args, optArgs) {
  12518. let {
  12519. parser
  12520. } = _ref;
  12521. const shift = optArgs[0];
  12522. const width = assertNodeType(args[0], "size");
  12523. const height = assertNodeType(args[1], "size");
  12524. return {
  12525. type: "rule",
  12526. mode: parser.mode,
  12527. shift: shift && assertNodeType(shift, "size").value,
  12528. width: width.value,
  12529. height: height.value
  12530. };
  12531. },
  12532. htmlBuilder(group, options) {
  12533. // Make an empty span for the rule
  12534. const rule = makeSpan(["mord", "rule"], [], options);
  12535. // Calculate the shift, width, and height of the rule, and account for units
  12536. const width = calculateSize(group.width, options);
  12537. const height = calculateSize(group.height, options);
  12538. const shift = group.shift ? calculateSize(group.shift, options) : 0;
  12539. // Style the rule to the right size
  12540. rule.style.borderRightWidth = makeEm(width);
  12541. rule.style.borderTopWidth = makeEm(height);
  12542. rule.style.bottom = makeEm(shift);
  12543. // Record the height and width
  12544. rule.width = width;
  12545. rule.height = height + shift;
  12546. rule.depth = -shift;
  12547. // Font size is the number large enough that the browser will
  12548. // reserve at least `absHeight` space above the baseline.
  12549. // The 1.125 factor was empirically determined
  12550. rule.maxFontSize = height * 1.125 * options.sizeMultiplier;
  12551. return rule;
  12552. },
  12553. mathmlBuilder(group, options) {
  12554. const width = calculateSize(group.width, options);
  12555. const height = calculateSize(group.height, options);
  12556. const shift = group.shift ? calculateSize(group.shift, options) : 0;
  12557. const color = options.color && options.getColor() || "black";
  12558. const rule = new MathNode("mspace");
  12559. rule.setAttribute("mathbackground", color);
  12560. rule.setAttribute("width", makeEm(width));
  12561. rule.setAttribute("height", makeEm(height));
  12562. const wrapper = new MathNode("mpadded", [rule]);
  12563. if (shift >= 0) {
  12564. wrapper.setAttribute("height", makeEm(shift));
  12565. } else {
  12566. wrapper.setAttribute("height", makeEm(shift));
  12567. wrapper.setAttribute("depth", makeEm(-shift));
  12568. }
  12569. wrapper.setAttribute("voffset", makeEm(shift));
  12570. return wrapper;
  12571. }
  12572. });
  12573. ;// ./src/functions/sizing.ts
  12574. function sizingGroup(value, options, baseOptions) {
  12575. const inner = buildExpression(value, options, false);
  12576. const multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier;
  12577. // Add size-resetting classes to the inner list and set maxFontSize
  12578. // manually. Handle nested size changes.
  12579. for (let i = 0; i < inner.length; i++) {
  12580. const pos = inner[i].classes.indexOf("sizing");
  12581. if (pos < 0) {
  12582. Array.prototype.push.apply(inner[i].classes, options.sizingClasses(baseOptions));
  12583. } else if (inner[i].classes[pos + 1] === "reset-size" + options.size) {
  12584. // This is a nested size change: e.g., inner[i] is the "b" in
  12585. // `\Huge a \small b`. Override the old size (the `reset-` class)
  12586. // but not the new size.
  12587. inner[i].classes[pos + 1] = "reset-size" + baseOptions.size;
  12588. }
  12589. inner[i].height *= multiplier;
  12590. inner[i].depth *= multiplier;
  12591. }
  12592. return makeFragment(inner);
  12593. }
  12594. const sizeFuncs = ["\\tiny", "\\sixptsize", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"];
  12595. const sizing_htmlBuilder = (group, options) => {
  12596. // Handle sizing operators like \Huge. Real TeX doesn't actually allow
  12597. // these functions inside of math expressions, so we do some special
  12598. // handling.
  12599. const newOptions = options.havingSize(group.size);
  12600. return sizingGroup(group.body, newOptions, options);
  12601. };
  12602. defineFunction({
  12603. type: "sizing",
  12604. names: sizeFuncs,
  12605. props: {
  12606. numArgs: 0,
  12607. allowedInText: true
  12608. },
  12609. handler: (_ref, args) => {
  12610. let {
  12611. breakOnTokenText,
  12612. funcName,
  12613. parser
  12614. } = _ref;
  12615. const body = parser.parseExpression(false, breakOnTokenText);
  12616. return {
  12617. type: "sizing",
  12618. mode: parser.mode,
  12619. // Figure out what size to use based on the list of functions above
  12620. size: sizeFuncs.indexOf(funcName) + 1,
  12621. body
  12622. };
  12623. },
  12624. htmlBuilder: sizing_htmlBuilder,
  12625. mathmlBuilder: (group, options) => {
  12626. const newOptions = options.havingSize(group.size);
  12627. const inner = buildMathML_buildExpression(group.body, newOptions);
  12628. const node = new MathNode("mstyle", inner);
  12629. // TODO(emily): This doesn't produce the correct size for nested size
  12630. // changes, because we don't keep state of what style we're currently
  12631. // in, so we can't reset the size to normal before changing it. Now
  12632. // that we're passing an options parameter we should be able to fix
  12633. // this.
  12634. node.setAttribute("mathsize", makeEm(newOptions.sizeMultiplier));
  12635. return node;
  12636. }
  12637. });
  12638. ;// ./src/functions/smash.ts
  12639. // smash, with optional [tb], as in AMS
  12640. defineFunction({
  12641. type: "smash",
  12642. names: ["\\smash"],
  12643. props: {
  12644. numArgs: 1,
  12645. numOptionalArgs: 1,
  12646. allowedInText: true
  12647. },
  12648. handler: (_ref, args, optArgs) => {
  12649. let {
  12650. parser
  12651. } = _ref;
  12652. let smashHeight = false;
  12653. let smashDepth = false;
  12654. const tbArg = optArgs[0] && assertNodeType(optArgs[0], "ordgroup");
  12655. if (tbArg) {
  12656. // Optional [tb] argument is engaged.
  12657. // ref: amsmath: \renewcommand{\smash}[1][tb]{%
  12658. // def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}%
  12659. let letter = "";
  12660. for (let i = 0; i < tbArg.body.length; ++i) {
  12661. const node = tbArg.body[i];
  12662. letter = assertSymbolNodeType(node).text;
  12663. if (letter === "t") {
  12664. smashHeight = true;
  12665. } else if (letter === "b") {
  12666. smashDepth = true;
  12667. } else {
  12668. smashHeight = false;
  12669. smashDepth = false;
  12670. break;
  12671. }
  12672. }
  12673. } else {
  12674. smashHeight = true;
  12675. smashDepth = true;
  12676. }
  12677. const body = args[0];
  12678. return {
  12679. type: "smash",
  12680. mode: parser.mode,
  12681. body,
  12682. smashHeight,
  12683. smashDepth
  12684. };
  12685. },
  12686. htmlBuilder: (group, options) => {
  12687. const node = makeSpan([], [buildGroup(group.body, options)]);
  12688. if (!group.smashHeight && !group.smashDepth) {
  12689. return node;
  12690. }
  12691. if (group.smashHeight) {
  12692. node.height = 0;
  12693. }
  12694. if (group.smashDepth) {
  12695. node.depth = 0;
  12696. }
  12697. if (group.smashHeight && group.smashDepth) {
  12698. // Symmetric \smash can stay in inline layout.
  12699. return makeSpan(["mord", "smash"], [node], options);
  12700. }
  12701. // In order to influence makeVList for asymmetric smashing, we have to
  12702. // reset the children.
  12703. if (node.children) {
  12704. for (let i = 0; i < node.children.length; i++) {
  12705. if (group.smashHeight) {
  12706. node.children[i].height = 0;
  12707. }
  12708. if (group.smashDepth) {
  12709. node.children[i].depth = 0;
  12710. }
  12711. }
  12712. }
  12713. // At this point, we've reset the TeX-like height and depth values.
  12714. // But the span still has an HTML line height.
  12715. // makeVList applies "display: table-cell", which prevents the browser
  12716. // from acting on that line height. So we'll call makeVList now.
  12717. const smashedNode = makeVList({
  12718. positionType: "firstBaseline",
  12719. children: [{
  12720. type: "elem",
  12721. elem: node
  12722. }]
  12723. }, options);
  12724. // For spacing, TeX treats \smash as a math group (same spacing as ord).
  12725. return makeSpan(["mord"], [smashedNode], options);
  12726. },
  12727. mathmlBuilder: (group, options) => {
  12728. const node = new MathNode("mpadded", [buildMathML_buildGroup(group.body, options)]);
  12729. if (group.smashHeight) {
  12730. node.setAttribute("height", "0px");
  12731. }
  12732. if (group.smashDepth) {
  12733. node.setAttribute("depth", "0px");
  12734. }
  12735. return node;
  12736. }
  12737. });
  12738. ;// ./src/functions/sqrt.ts
  12739. defineFunction({
  12740. type: "sqrt",
  12741. names: ["\\sqrt"],
  12742. props: {
  12743. numArgs: 1,
  12744. numOptionalArgs: 1
  12745. },
  12746. handler(_ref, args, optArgs) {
  12747. let {
  12748. parser
  12749. } = _ref;
  12750. const index = optArgs[0];
  12751. const body = args[0];
  12752. return {
  12753. type: "sqrt",
  12754. mode: parser.mode,
  12755. body,
  12756. index
  12757. };
  12758. },
  12759. htmlBuilder(group, options) {
  12760. // Square roots are handled in the TeXbook pg. 443, Rule 11.
  12761. // First, we do the same steps as in overline to build the inner group
  12762. // and line
  12763. let inner = buildGroup(group.body, options.havingCrampedStyle());
  12764. if (inner.height === 0) {
  12765. // Render a small surd.
  12766. inner.height = options.fontMetrics().xHeight;
  12767. }
  12768. // Some groups can return document fragments. Handle those by wrapping
  12769. // them in a span.
  12770. inner = wrapFragment(inner, options);
  12771. // Calculate the minimum size for the \surd delimiter
  12772. const metrics = options.fontMetrics();
  12773. const theta = metrics.defaultRuleThickness;
  12774. let phi = theta;
  12775. if (options.style.id < src_Style.TEXT.id) {
  12776. phi = options.fontMetrics().xHeight;
  12777. }
  12778. // Calculate the clearance between the body and line
  12779. let lineClearance = theta + phi / 4;
  12780. const minDelimiterHeight = inner.height + inner.depth + lineClearance + theta;
  12781. // Create a sqrt SVG of the required minimum size
  12782. const {
  12783. span: img,
  12784. ruleWidth,
  12785. advanceWidth
  12786. } = makeSqrtImage(minDelimiterHeight, options);
  12787. const delimDepth = img.height - ruleWidth;
  12788. // Adjust the clearance based on the delimiter size
  12789. if (delimDepth > inner.height + inner.depth + lineClearance) {
  12790. lineClearance = (lineClearance + delimDepth - inner.height - inner.depth) / 2;
  12791. }
  12792. // Shift the sqrt image
  12793. const imgShift = img.height - inner.height - lineClearance - ruleWidth;
  12794. inner.style.paddingLeft = makeEm(advanceWidth);
  12795. // Overlay the image and the argument.
  12796. const body = makeVList({
  12797. positionType: "firstBaseline",
  12798. children: [{
  12799. type: "elem",
  12800. elem: inner,
  12801. wrapperClasses: ["svg-align"]
  12802. }, {
  12803. type: "kern",
  12804. size: -(inner.height + imgShift)
  12805. }, {
  12806. type: "elem",
  12807. elem: img
  12808. }, {
  12809. type: "kern",
  12810. size: ruleWidth
  12811. }]
  12812. }, options);
  12813. if (!group.index) {
  12814. return makeSpan(["mord", "sqrt"], [body], options);
  12815. } else {
  12816. // Handle the optional root index
  12817. // The index is always in scriptscript style
  12818. const newOptions = options.havingStyle(src_Style.SCRIPTSCRIPT);
  12819. const rootm = buildGroup(group.index, newOptions, options);
  12820. // The amount the index is shifted by. This is taken from the TeX
  12821. // source, in the definition of `\r@@t`.
  12822. const toShift = 0.6 * (body.height - body.depth);
  12823. // Build a VList with the superscript shifted up correctly
  12824. const rootVList = makeVList({
  12825. positionType: "shift",
  12826. positionData: -toShift,
  12827. children: [{
  12828. type: "elem",
  12829. elem: rootm
  12830. }]
  12831. }, options);
  12832. // Add a class surrounding it so we can add on the appropriate
  12833. // kerning
  12834. const rootVListWrap = makeSpan(["root"], [rootVList]);
  12835. return makeSpan(["mord", "sqrt"], [rootVListWrap, body], options);
  12836. }
  12837. },
  12838. mathmlBuilder(group, options) {
  12839. const {
  12840. body,
  12841. index
  12842. } = group;
  12843. return index ? new MathNode("mroot", [buildMathML_buildGroup(body, options), buildMathML_buildGroup(index, options)]) : new MathNode("msqrt", [buildMathML_buildGroup(body, options)]);
  12844. }
  12845. });
  12846. ;// ./src/functions/styling.ts
  12847. const styling_styleMap = {
  12848. "display": src_Style.DISPLAY,
  12849. "text": src_Style.TEXT,
  12850. "script": src_Style.SCRIPT,
  12851. "scriptscript": src_Style.SCRIPTSCRIPT
  12852. };
  12853. defineFunction({
  12854. type: "styling",
  12855. names: ["\\displaystyle", "\\textstyle", "\\scriptstyle", "\\scriptscriptstyle"],
  12856. props: {
  12857. numArgs: 0,
  12858. allowedInText: true,
  12859. primitive: true
  12860. },
  12861. handler(_ref, args) {
  12862. let {
  12863. breakOnTokenText,
  12864. funcName,
  12865. parser
  12866. } = _ref;
  12867. // parse out the implicit body
  12868. const body = parser.parseExpression(true, breakOnTokenText);
  12869. // TODO: Refactor to avoid duplicating styleMap in multiple places (e.g.
  12870. // here and in buildHTML and de-dupe the enumeration of all the styles).
  12871. // TODO(ts): The names above exactly match the styles.
  12872. const style = funcName.slice(1, funcName.length - 5);
  12873. return {
  12874. type: "styling",
  12875. mode: parser.mode,
  12876. // Figure out what style to use by pulling out the style from
  12877. // the function name
  12878. style,
  12879. body
  12880. };
  12881. },
  12882. htmlBuilder(group, options) {
  12883. // Style changes are handled in the TeXbook on pg. 442, Rule 3.
  12884. const newStyle = styling_styleMap[group.style];
  12885. const newOptions = options.havingStyle(newStyle).withFont('');
  12886. return sizingGroup(group.body, newOptions, options);
  12887. },
  12888. mathmlBuilder(group, options) {
  12889. // Figure out what style we're changing to.
  12890. const newStyle = styling_styleMap[group.style];
  12891. const newOptions = options.havingStyle(newStyle);
  12892. const inner = buildMathML_buildExpression(group.body, newOptions);
  12893. const node = new MathNode("mstyle", inner);
  12894. const styleAttributes = {
  12895. "display": ["0", "true"],
  12896. "text": ["0", "false"],
  12897. "script": ["1", "false"],
  12898. "scriptscript": ["2", "false"]
  12899. };
  12900. const attr = styleAttributes[group.style];
  12901. node.setAttribute("scriptlevel", attr[0]);
  12902. node.setAttribute("displaystyle", attr[1]);
  12903. return node;
  12904. }
  12905. });
  12906. ;// ./src/functions/supsub.ts
  12907. /**
  12908. * Sometimes, groups perform special rules when they have superscripts or
  12909. * subscripts attached to them. This function lets the `supsub` group know that
  12910. * Sometimes, groups perform special rules when they have superscripts or
  12911. * its inner element should handle the superscripts and subscripts instead of
  12912. * handling them itself.
  12913. */
  12914. const htmlBuilderDelegate = function (group, options) {
  12915. const base = group.base;
  12916. if (!base) {
  12917. return null;
  12918. } else if (base.type === "op") {
  12919. // Operators handle supsubs differently when they have limits
  12920. // (e.g. `\displaystyle\sum_2^3`)
  12921. const delegate = base.limits && (options.style.size === src_Style.DISPLAY.size || base.alwaysHandleSupSub);
  12922. return delegate ? op_htmlBuilder : null;
  12923. } else if (base.type === "operatorname") {
  12924. const delegate = base.alwaysHandleSupSub && (options.style.size === src_Style.DISPLAY.size || base.limits);
  12925. return delegate ? operatorname_htmlBuilder : null;
  12926. } else if (base.type === "accent") {
  12927. return isCharacterBox(base.base) ? htmlBuilder : null;
  12928. } else if (base.type === "horizBrace") {
  12929. const isSup = !group.sub;
  12930. return isSup === base.isOver ? horizBrace_htmlBuilder : null;
  12931. } else {
  12932. return null;
  12933. }
  12934. };
  12935. // Super scripts and subscripts, whose precise placement can depend on other
  12936. // functions that precede them.
  12937. defineFunctionBuilders({
  12938. type: "supsub",
  12939. htmlBuilder(group, options) {
  12940. // Superscript and subscripts are handled in the TeXbook on page
  12941. // 445-446, rules 18(a-f).
  12942. // Here is where we defer to the inner group if it should handle
  12943. // superscripts and subscripts itself.
  12944. const builderDelegate = htmlBuilderDelegate(group, options);
  12945. if (builderDelegate) {
  12946. return builderDelegate(group, options);
  12947. }
  12948. const {
  12949. base: valueBase,
  12950. sup: valueSup,
  12951. sub: valueSub
  12952. } = group;
  12953. const base = buildGroup(valueBase, options);
  12954. let supm;
  12955. let subm;
  12956. const metrics = options.fontMetrics();
  12957. // Rule 18a
  12958. let supShift = 0;
  12959. let subShift = 0;
  12960. const isCharBox = valueBase && isCharacterBox(valueBase);
  12961. if (valueSup) {
  12962. const newOptions = options.havingStyle(options.style.sup());
  12963. supm = buildGroup(valueSup, newOptions, options);
  12964. if (!isCharBox) {
  12965. supShift = base.height - newOptions.fontMetrics().supDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
  12966. }
  12967. }
  12968. if (valueSub) {
  12969. const newOptions = options.havingStyle(options.style.sub());
  12970. subm = buildGroup(valueSub, newOptions, options);
  12971. if (!isCharBox) {
  12972. subShift = base.depth + newOptions.fontMetrics().subDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
  12973. }
  12974. }
  12975. // Rule 18c
  12976. let minSupShift;
  12977. if (options.style === src_Style.DISPLAY) {
  12978. minSupShift = metrics.sup1;
  12979. } else if (options.style.cramped) {
  12980. minSupShift = metrics.sup3;
  12981. } else {
  12982. minSupShift = metrics.sup2;
  12983. }
  12984. // scriptspace is a font-size-independent size, so scale it
  12985. // appropriately for use as the marginRight.
  12986. const multiplier = options.sizeMultiplier;
  12987. const marginRight = makeEm(0.5 / metrics.ptPerEm / multiplier);
  12988. let marginLeft = null;
  12989. if (subm) {
  12990. // Subscripts shouldn't be shifted by the base's italic correction.
  12991. // Account for that by shifting the subscript back the appropriate
  12992. // amount. Note we only do this when the base is a single symbol.
  12993. const isOiint = group.base && group.base.type === "op" && group.base.name && (group.base.name === "\\oiint" || group.base.name === "\\oiiint");
  12994. if (base instanceof SymbolNode || isOiint) {
  12995. // @ts-ignore
  12996. marginLeft = makeEm(-base.italic);
  12997. }
  12998. }
  12999. let supsub;
  13000. if (supm && subm) {
  13001. supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
  13002. subShift = Math.max(subShift, metrics.sub2);
  13003. const ruleWidth = metrics.defaultRuleThickness;
  13004. // Rule 18e
  13005. const maxWidth = 4 * ruleWidth;
  13006. if (supShift - supm.depth - (subm.height - subShift) < maxWidth) {
  13007. subShift = maxWidth - (supShift - supm.depth) + subm.height;
  13008. const psi = 0.8 * metrics.xHeight - (supShift - supm.depth);
  13009. if (psi > 0) {
  13010. supShift += psi;
  13011. subShift -= psi;
  13012. }
  13013. }
  13014. const vlistElem = [{
  13015. type: "elem",
  13016. elem: subm,
  13017. shift: subShift,
  13018. marginRight,
  13019. marginLeft
  13020. }, {
  13021. type: "elem",
  13022. elem: supm,
  13023. shift: -supShift,
  13024. marginRight
  13025. }];
  13026. supsub = makeVList({
  13027. positionType: "individualShift",
  13028. children: vlistElem
  13029. }, options);
  13030. } else if (subm) {
  13031. // Rule 18b
  13032. subShift = Math.max(subShift, metrics.sub1, subm.height - 0.8 * metrics.xHeight);
  13033. const vlistElem = [{
  13034. type: "elem",
  13035. elem: subm,
  13036. marginLeft,
  13037. marginRight
  13038. }];
  13039. supsub = makeVList({
  13040. positionType: "shift",
  13041. positionData: subShift,
  13042. children: vlistElem
  13043. }, options);
  13044. } else if (supm) {
  13045. // Rule 18c, d
  13046. supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
  13047. supsub = makeVList({
  13048. positionType: "shift",
  13049. positionData: -supShift,
  13050. children: [{
  13051. type: "elem",
  13052. elem: supm,
  13053. marginRight
  13054. }]
  13055. }, options);
  13056. } else {
  13057. throw new Error("supsub must have either sup or sub.");
  13058. }
  13059. // Wrap the supsub vlist in a span.msupsub to reset text-align.
  13060. const mclass = getTypeOfDomTree(base, "right") || "mord";
  13061. return makeSpan([mclass], [base, makeSpan(["msupsub"], [supsub])], options);
  13062. },
  13063. mathmlBuilder(group, options) {
  13064. // Is the inner group a relevant horizontal brace?
  13065. let isBrace = false;
  13066. let isOver;
  13067. let isSup;
  13068. if (group.base && group.base.type === "horizBrace") {
  13069. isSup = !!group.sup;
  13070. if (isSup === group.base.isOver) {
  13071. isBrace = true;
  13072. isOver = group.base.isOver;
  13073. }
  13074. }
  13075. if (group.base && (group.base.type === "op" || group.base.type === "operatorname")) {
  13076. group.base.parentIsSupSub = true;
  13077. }
  13078. const children = [buildMathML_buildGroup(group.base, options)];
  13079. if (group.sub) {
  13080. children.push(buildMathML_buildGroup(group.sub, options));
  13081. }
  13082. if (group.sup) {
  13083. children.push(buildMathML_buildGroup(group.sup, options));
  13084. }
  13085. let nodeType;
  13086. if (isBrace) {
  13087. nodeType = isOver ? "mover" : "munder";
  13088. } else if (!group.sub) {
  13089. const base = group.base;
  13090. if (base && base.type === "op" && base.limits && (options.style === src_Style.DISPLAY || base.alwaysHandleSupSub)) {
  13091. nodeType = "mover";
  13092. } else if (base && base.type === "operatorname" && base.alwaysHandleSupSub && (base.limits || options.style === src_Style.DISPLAY)) {
  13093. nodeType = "mover";
  13094. } else {
  13095. nodeType = "msup";
  13096. }
  13097. } else if (!group.sup) {
  13098. const base = group.base;
  13099. if (base && base.type === "op" && base.limits && (options.style === src_Style.DISPLAY || base.alwaysHandleSupSub)) {
  13100. nodeType = "munder";
  13101. } else if (base && base.type === "operatorname" && base.alwaysHandleSupSub && (base.limits || options.style === src_Style.DISPLAY)) {
  13102. nodeType = "munder";
  13103. } else {
  13104. nodeType = "msub";
  13105. }
  13106. } else {
  13107. const base = group.base;
  13108. if (base && base.type === "op" && base.limits && options.style === src_Style.DISPLAY) {
  13109. nodeType = "munderover";
  13110. } else if (base && base.type === "operatorname" && base.alwaysHandleSupSub && (options.style === src_Style.DISPLAY || base.limits)) {
  13111. nodeType = "munderover";
  13112. } else {
  13113. nodeType = "msubsup";
  13114. }
  13115. }
  13116. return new MathNode(nodeType, children);
  13117. }
  13118. });
  13119. ;// ./src/functions/symbolsOp.ts
  13120. // Operator ParseNodes created in Parser.js from symbol Groups in src/symbols.js.
  13121. defineFunctionBuilders({
  13122. type: "atom",
  13123. htmlBuilder(group, options) {
  13124. return mathsym(group.text, group.mode, options, ["m" + group.family]);
  13125. },
  13126. mathmlBuilder(group, options) {
  13127. const node = new MathNode("mo", [makeText(group.text, group.mode)]);
  13128. if (group.family === "bin") {
  13129. const variant = getVariant(group, options);
  13130. if (variant === "bold-italic") {
  13131. node.setAttribute("mathvariant", variant);
  13132. }
  13133. } else if (group.family === "punct") {
  13134. node.setAttribute("separator", "true");
  13135. } else if (group.family === "open" || group.family === "close") {
  13136. // Delims built here should not stretch vertically.
  13137. // See delimsizing.js for stretchy delims.
  13138. node.setAttribute("stretchy", "false");
  13139. }
  13140. return node;
  13141. }
  13142. });
  13143. ;// ./src/functions/symbolsOrd.ts
  13144. // "mathord" and "textord" ParseNodes created in Parser.js from symbol Groups in
  13145. // src/symbols.js.
  13146. const defaultVariant = {
  13147. "mi": "italic",
  13148. "mn": "normal",
  13149. "mtext": "normal"
  13150. };
  13151. defineFunctionBuilders({
  13152. type: "mathord",
  13153. htmlBuilder(group, options) {
  13154. return makeOrd(group, options, "mathord");
  13155. },
  13156. mathmlBuilder(group, options) {
  13157. const node = new MathNode("mi", [makeText(group.text, group.mode, options)]);
  13158. const variant = getVariant(group, options) || "italic";
  13159. if (variant !== defaultVariant[node.type]) {
  13160. node.setAttribute("mathvariant", variant);
  13161. }
  13162. return node;
  13163. }
  13164. });
  13165. defineFunctionBuilders({
  13166. type: "textord",
  13167. htmlBuilder(group, options) {
  13168. return makeOrd(group, options, "textord");
  13169. },
  13170. mathmlBuilder(group, options) {
  13171. const text = makeText(group.text, group.mode, options);
  13172. const variant = getVariant(group, options) || "normal";
  13173. let node;
  13174. if (group.mode === 'text') {
  13175. node = new MathNode("mtext", [text]);
  13176. } else if (/[0-9]/.test(group.text)) {
  13177. node = new MathNode("mn", [text]);
  13178. } else if (group.text === "\\prime") {
  13179. node = new MathNode("mo", [text]);
  13180. } else {
  13181. node = new MathNode("mi", [text]);
  13182. }
  13183. if (variant !== defaultVariant[node.type]) {
  13184. node.setAttribute("mathvariant", variant);
  13185. }
  13186. return node;
  13187. }
  13188. });
  13189. ;// ./src/functions/symbolsSpacing.ts
  13190. // A map of CSS-based spacing functions to their CSS class.
  13191. const cssSpace = {
  13192. "\\nobreak": "nobreak",
  13193. "\\allowbreak": "allowbreak"
  13194. };
  13195. // A lookup table to determine whether a spacing function/symbol should be
  13196. // treated like a regular space character. If a symbol or command is a key
  13197. // in this table, then it should be a regular space character. Furthermore,
  13198. // the associated value may have a `className` specifying an extra CSS class
  13199. // to add to the created `span`.
  13200. const regularSpace = {
  13201. " ": {},
  13202. "\\ ": {},
  13203. "~": {
  13204. className: "nobreak"
  13205. },
  13206. "\\space": {},
  13207. "\\nobreakspace": {
  13208. className: "nobreak"
  13209. }
  13210. };
  13211. // ParseNode<"spacing"> created in Parser.js from the "spacing" symbol Groups in
  13212. // src/symbols.js.
  13213. defineFunctionBuilders({
  13214. type: "spacing",
  13215. htmlBuilder(group, options) {
  13216. if (regularSpace.hasOwnProperty(group.text)) {
  13217. const className = regularSpace[group.text].className || "";
  13218. // Spaces are generated by adding an actual space. Each of these
  13219. // things has an entry in the symbols table, so these will be turned
  13220. // into appropriate outputs.
  13221. if (group.mode === "text") {
  13222. const ord = makeOrd(group, options, "textord");
  13223. ord.classes.push(className);
  13224. return ord;
  13225. } else {
  13226. return makeSpan(["mspace", className], [mathsym(group.text, group.mode, options)], options);
  13227. }
  13228. } else if (cssSpace.hasOwnProperty(group.text)) {
  13229. // Spaces based on just a CSS class.
  13230. return makeSpan(["mspace", cssSpace[group.text]], [], options);
  13231. } else {
  13232. throw new src_ParseError("Unknown type of space \"" + group.text + "\"");
  13233. }
  13234. },
  13235. mathmlBuilder(group, options) {
  13236. let node;
  13237. if (regularSpace.hasOwnProperty(group.text)) {
  13238. node = new MathNode("mtext", [new TextNode("\u00a0")]);
  13239. } else if (cssSpace.hasOwnProperty(group.text)) {
  13240. // CSS-based MathML spaces (\nobreak, \allowbreak) are ignored
  13241. return new MathNode("mspace");
  13242. } else {
  13243. throw new src_ParseError("Unknown type of space \"" + group.text + "\"");
  13244. }
  13245. return node;
  13246. }
  13247. });
  13248. ;// ./src/functions/tag.ts
  13249. const pad = () => {
  13250. const padNode = new MathNode("mtd", []);
  13251. padNode.setAttribute("width", "50%");
  13252. return padNode;
  13253. };
  13254. defineFunctionBuilders({
  13255. type: "tag",
  13256. mathmlBuilder(group, options) {
  13257. const table = new MathNode("mtable", [new MathNode("mtr", [pad(), new MathNode("mtd", [buildExpressionRow(group.body, options)]), pad(), new MathNode("mtd", [buildExpressionRow(group.tag, options)])])]);
  13258. table.setAttribute("width", "100%");
  13259. return table;
  13260. // TODO: Left-aligned tags.
  13261. // Currently, the group and options passed here do not contain
  13262. // enough info to set tag alignment. `leqno` is in Settings but it is
  13263. // not passed to Options. On the HTML side, leqno is
  13264. // set by a CSS class applied in buildTree.js. That would have worked
  13265. // in MathML if browsers supported <mlabeledtr>. Since they don't, we
  13266. // need to rewrite the way this function is called.
  13267. }
  13268. });
  13269. ;// ./src/functions/text.ts
  13270. // Non-mathy text, possibly in a font
  13271. const textFontFamilies = {
  13272. "\\text": undefined,
  13273. "\\textrm": "textrm",
  13274. "\\textsf": "textsf",
  13275. "\\texttt": "texttt",
  13276. "\\textnormal": "textrm"
  13277. };
  13278. const textFontWeights = {
  13279. "\\textbf": "textbf",
  13280. "\\textmd": "textmd"
  13281. };
  13282. const textFontShapes = {
  13283. "\\textit": "textit",
  13284. "\\textup": "textup"
  13285. };
  13286. const optionsWithFont = (group, options) => {
  13287. const font = group.font;
  13288. // Checks if the argument is a font family or a font style.
  13289. if (!font) {
  13290. return options;
  13291. } else if (textFontFamilies[font]) {
  13292. return options.withTextFontFamily(textFontFamilies[font]);
  13293. } else if (textFontWeights[font]) {
  13294. return options.withTextFontWeight(textFontWeights[font]);
  13295. } else if (font === "\\emph") {
  13296. return options.fontShape === "textit" ? options.withTextFontShape("textup") : options.withTextFontShape("textit");
  13297. }
  13298. return options.withTextFontShape(textFontShapes[font]);
  13299. };
  13300. defineFunction({
  13301. type: "text",
  13302. names: [
  13303. // Font families
  13304. "\\text", "\\textrm", "\\textsf", "\\texttt", "\\textnormal",
  13305. // Font weights
  13306. "\\textbf", "\\textmd",
  13307. // Font Shapes
  13308. "\\textit", "\\textup", "\\emph"],
  13309. props: {
  13310. numArgs: 1,
  13311. argTypes: ["text"],
  13312. allowedInArgument: true,
  13313. allowedInText: true
  13314. },
  13315. handler(_ref, args) {
  13316. let {
  13317. parser,
  13318. funcName
  13319. } = _ref;
  13320. const body = args[0];
  13321. return {
  13322. type: "text",
  13323. mode: parser.mode,
  13324. body: ordargument(body),
  13325. font: funcName
  13326. };
  13327. },
  13328. htmlBuilder(group, options) {
  13329. const newOptions = optionsWithFont(group, options);
  13330. const inner = buildExpression(group.body, newOptions, true);
  13331. return makeSpan(["mord", "text"], inner, newOptions);
  13332. },
  13333. mathmlBuilder(group, options) {
  13334. const newOptions = optionsWithFont(group, options);
  13335. return buildExpressionRow(group.body, newOptions);
  13336. }
  13337. });
  13338. ;// ./src/functions/underline.ts
  13339. defineFunction({
  13340. type: "underline",
  13341. names: ["\\underline"],
  13342. props: {
  13343. numArgs: 1,
  13344. allowedInText: true
  13345. },
  13346. handler(_ref, args) {
  13347. let {
  13348. parser
  13349. } = _ref;
  13350. return {
  13351. type: "underline",
  13352. mode: parser.mode,
  13353. body: args[0]
  13354. };
  13355. },
  13356. htmlBuilder(group, options) {
  13357. // Underlines are handled in the TeXbook pg 443, Rule 10.
  13358. // Build the inner group.
  13359. const innerGroup = buildGroup(group.body, options);
  13360. // Create the line to go below the body
  13361. const line = makeLineSpan("underline-line", options);
  13362. // Generate the vlist, with the appropriate kerns
  13363. const defaultRuleThickness = options.fontMetrics().defaultRuleThickness;
  13364. const vlist = makeVList({
  13365. positionType: "top",
  13366. positionData: innerGroup.height,
  13367. children: [{
  13368. type: "kern",
  13369. size: defaultRuleThickness
  13370. }, {
  13371. type: "elem",
  13372. elem: line
  13373. }, {
  13374. type: "kern",
  13375. size: 3 * defaultRuleThickness
  13376. }, {
  13377. type: "elem",
  13378. elem: innerGroup
  13379. }]
  13380. }, options);
  13381. return makeSpan(["mord", "underline"], [vlist], options);
  13382. },
  13383. mathmlBuilder(group, options) {
  13384. const operator = new MathNode("mo", [new TextNode("\u203e")]);
  13385. operator.setAttribute("stretchy", "true");
  13386. const node = new MathNode("munder", [buildMathML_buildGroup(group.body, options), operator]);
  13387. node.setAttribute("accentunder", "true");
  13388. return node;
  13389. }
  13390. });
  13391. ;// ./src/functions/vcenter.ts
  13392. // \vcenter: Vertically center the argument group on the math axis.
  13393. defineFunction({
  13394. type: "vcenter",
  13395. names: ["\\vcenter"],
  13396. props: {
  13397. numArgs: 1,
  13398. argTypes: ["original"],
  13399. // In LaTeX, \vcenter can act only on a box.
  13400. allowedInText: false
  13401. },
  13402. handler(_ref, args) {
  13403. let {
  13404. parser
  13405. } = _ref;
  13406. return {
  13407. type: "vcenter",
  13408. mode: parser.mode,
  13409. body: args[0]
  13410. };
  13411. },
  13412. htmlBuilder(group, options) {
  13413. const body = buildGroup(group.body, options);
  13414. const axisHeight = options.fontMetrics().axisHeight;
  13415. const dy = 0.5 * (body.height - axisHeight - (body.depth + axisHeight));
  13416. return makeVList({
  13417. positionType: "shift",
  13418. positionData: dy,
  13419. children: [{
  13420. type: "elem",
  13421. elem: body
  13422. }]
  13423. }, options);
  13424. },
  13425. mathmlBuilder(group, options) {
  13426. // There is no way to do this in MathML.
  13427. // Write a class as a breadcrumb in case some post-processor wants
  13428. // to perform a vcenter adjustment.
  13429. return new MathNode("mpadded", [buildMathML_buildGroup(group.body, options)], ["vcenter"]);
  13430. }
  13431. });
  13432. ;// ./src/functions/verb.ts
  13433. defineFunction({
  13434. type: "verb",
  13435. names: ["\\verb"],
  13436. props: {
  13437. numArgs: 0,
  13438. allowedInText: true
  13439. },
  13440. handler(context, args, optArgs) {
  13441. // \verb and \verb* are dealt with directly in Parser.js.
  13442. // If we end up here, it's because of a failure to match the two delimiters
  13443. // in the regex in Lexer.js. LaTeX raises the following error when \verb is
  13444. // terminated by end of line (or file).
  13445. throw new src_ParseError("\\verb ended by end of line instead of matching delimiter");
  13446. },
  13447. htmlBuilder(group, options) {
  13448. const text = makeVerb(group);
  13449. const body = [];
  13450. // \verb enters text mode and therefore is sized like \textstyle
  13451. const newOptions = options.havingStyle(options.style.text());
  13452. for (let i = 0; i < text.length; i++) {
  13453. let c = text[i];
  13454. if (c === '~') {
  13455. c = '\\textasciitilde';
  13456. }
  13457. body.push(makeSymbol(c, "Typewriter-Regular", group.mode, newOptions, ["mord", "texttt"]));
  13458. }
  13459. return makeSpan(["mord", "text"].concat(newOptions.sizingClasses(options)), tryCombineChars(body), newOptions);
  13460. },
  13461. mathmlBuilder(group, options) {
  13462. const text = new TextNode(makeVerb(group));
  13463. const node = new MathNode("mtext", [text]);
  13464. node.setAttribute("mathvariant", "monospace");
  13465. return node;
  13466. }
  13467. });
  13468. /**
  13469. * Converts verb group into body string.
  13470. *
  13471. * \verb* replaces each space with an open box \u2423
  13472. * \verb replaces each space with a no-break space \xA0
  13473. */
  13474. const makeVerb = group => group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');
  13475. ;// ./src/functions.ts
  13476. /** Include this to ensure that all functions are defined. */
  13477. const functions = _functions;
  13478. /* harmony default export */ var src_functions = (functions);
  13479. // TODO(kevinb): have functions return an object and call defineFunction with
  13480. // that object in this file instead of relying on side-effects.
  13481. ;// ./src/Lexer.ts
  13482. /**
  13483. * The Lexer class handles tokenizing the input in various ways. Since our
  13484. * parser expects us to be able to backtrack, the lexer allows lexing from any
  13485. * given starting point.
  13486. *
  13487. * Its main exposed function is the `lex` function, which takes a position to
  13488. * lex from and a type of token to lex. It defers to the appropriate `_innerLex`
  13489. * function.
  13490. *
  13491. * The various `_innerLex` functions perform the actual lexing of different
  13492. * kinds.
  13493. */
  13494. /* The following tokenRegex
  13495. * - matches typical whitespace (but not NBSP etc.) using its first group
  13496. * - does not match any control character \x00-\x1f except whitespace
  13497. * - does not match a bare backslash
  13498. * - matches any ASCII character except those just mentioned
  13499. * - does not match the BMP private use area \uE000-\uF8FF
  13500. * - does not match bare surrogate code units
  13501. * - matches any BMP character except for those just described
  13502. * - matches any valid Unicode surrogate pair
  13503. * - matches a backslash followed by one or more whitespace characters
  13504. * - matches a backslash followed by one or more letters then whitespace
  13505. * - matches a backslash followed by any BMP character
  13506. * Capturing groups:
  13507. * [1] regular whitespace
  13508. * [2] backslash followed by whitespace
  13509. * [3] anything else, which may include:
  13510. * [4] left character of \verb*
  13511. * [5] left character of \verb
  13512. * [6] backslash followed by word, excluding any trailing whitespace
  13513. * Just because the Lexer matches something doesn't mean it's valid input:
  13514. * If there is no matching function or symbol definition, the Parser will
  13515. * still reject the input.
  13516. */
  13517. const spaceRegexString = "[ \r\n\t]";
  13518. const controlWordRegexString = "\\\\[a-zA-Z@]+";
  13519. const controlSymbolRegexString = "\\\\[^\uD800-\uDFFF]";
  13520. const controlWordWhitespaceRegexString = "(" + controlWordRegexString + ")" + spaceRegexString + "*";
  13521. const controlSpaceRegexString = "\\\\(\n|[ \r\t]+\n?)[ \r\t]*";
  13522. const combiningDiacriticalMarkString = "[\u0300-\u036f]";
  13523. const combiningDiacriticalMarksEndRegex = new RegExp(combiningDiacriticalMarkString + "+$");
  13524. const tokenRegexString = "(" + spaceRegexString + "+)|" + (// whitespace
  13525. controlSpaceRegexString + "|") +
  13526. // \whitespace
  13527. "([!-\\[\\]-\u2027\u202A-\uD7FF\uF900-\uFFFF]" + (// single codepoint
  13528. combiningDiacriticalMarkString + "*") +
  13529. // ...plus accents
  13530. "|[\uD800-\uDBFF][\uDC00-\uDFFF]" + (// surrogate pair
  13531. combiningDiacriticalMarkString + "*") +
  13532. // ...plus accents
  13533. "|\\\\verb\\*([^]).*?\\4" +
  13534. // \verb*
  13535. "|\\\\verb([^*a-zA-Z]).*?\\5" + (// \verb unstarred
  13536. "|" + controlWordWhitespaceRegexString) + (// \macroName + spaces
  13537. "|" + controlSymbolRegexString + ")"); // \\, \', etc.
  13538. /** Main Lexer class */
  13539. class Lexer {
  13540. // Category codes. The lexer only supports comment characters (14) for now.
  13541. // MacroExpander additionally distinguishes active (13).
  13542. constructor(input, settings) {
  13543. // Separate accents from characters
  13544. this.input = input;
  13545. this.settings = settings;
  13546. this.tokenRegex = new RegExp(tokenRegexString, 'g');
  13547. this.catcodes = {
  13548. "%": 14,
  13549. // comment character
  13550. "~": 13 // active character
  13551. };
  13552. }
  13553. setCatcode(char, code) {
  13554. this.catcodes[char] = code;
  13555. }
  13556. /**
  13557. * This function lexes a single token.
  13558. */
  13559. lex() {
  13560. const input = this.input;
  13561. const pos = this.tokenRegex.lastIndex;
  13562. if (pos === input.length) {
  13563. return new Token("EOF", new SourceLocation(this, pos, pos));
  13564. }
  13565. const match = this.tokenRegex.exec(input);
  13566. if (match === null || match.index !== pos) {
  13567. throw new src_ParseError("Unexpected character: '" + input[pos] + "'", new Token(input[pos], new SourceLocation(this, pos, pos + 1)));
  13568. }
  13569. const text = match[6] || match[3] || (match[2] ? "\\ " : " ");
  13570. if (this.catcodes[text] === 14) {
  13571. // comment character
  13572. const nlIndex = input.indexOf('\n', this.tokenRegex.lastIndex);
  13573. if (nlIndex === -1) {
  13574. this.tokenRegex.lastIndex = input.length; // EOF
  13575. this.settings.reportNonstrict("commentAtEnd", "% comment has no terminating newline; LaTeX would " + "fail because of commenting the end of math mode (e.g. $)");
  13576. } else {
  13577. this.tokenRegex.lastIndex = nlIndex + 1;
  13578. }
  13579. return this.lex();
  13580. }
  13581. return new Token(text, new SourceLocation(this, pos, this.tokenRegex.lastIndex));
  13582. }
  13583. }
  13584. ;// ./src/Namespace.ts
  13585. /**
  13586. * A `Namespace` refers to a space of nameable things like macros or lengths,
  13587. * which can be `set` either globally or local to a nested group, using an
  13588. * undo stack similar to how TeX implements this functionality.
  13589. * Performance-wise, `get` and local `set` take constant time, while global
  13590. * `set` takes time proportional to the depth of group nesting.
  13591. */
  13592. class Namespace {
  13593. /**
  13594. * Both arguments are optional. The first argument is an object of
  13595. * built-in mappings which never change. The second argument is an object
  13596. * of initial (global-level) mappings, which will constantly change
  13597. * according to any global/top-level `set`s done.
  13598. */
  13599. constructor(builtins, globalMacros) {
  13600. if (builtins === void 0) {
  13601. builtins = {};
  13602. }
  13603. if (globalMacros === void 0) {
  13604. globalMacros = {};
  13605. }
  13606. this.current = globalMacros;
  13607. this.builtins = builtins;
  13608. this.undefStack = [];
  13609. }
  13610. /**
  13611. * Start a new nested group, affecting future local `set`s.
  13612. */
  13613. beginGroup() {
  13614. this.undefStack.push({});
  13615. }
  13616. /**
  13617. * End current nested group, restoring values before the group began.
  13618. */
  13619. endGroup() {
  13620. if (this.undefStack.length === 0) {
  13621. throw new src_ParseError("Unbalanced namespace destruction: attempt " + "to pop global namespace; please report this as a bug");
  13622. }
  13623. const undefs = this.undefStack.pop();
  13624. for (const undef in undefs) {
  13625. if (undefs.hasOwnProperty(undef)) {
  13626. if (undefs[undef] == null) {
  13627. delete this.current[undef];
  13628. } else {
  13629. this.current[undef] = undefs[undef];
  13630. }
  13631. }
  13632. }
  13633. }
  13634. /**
  13635. * Ends all currently nested groups (if any), restoring values before the
  13636. * groups began. Useful in case of an error in the middle of parsing.
  13637. */
  13638. endGroups() {
  13639. while (this.undefStack.length > 0) {
  13640. this.endGroup();
  13641. }
  13642. }
  13643. /**
  13644. * Detect whether `name` has a definition. Equivalent to
  13645. * `get(name) != null`.
  13646. */
  13647. has(name) {
  13648. return this.current.hasOwnProperty(name) || this.builtins.hasOwnProperty(name);
  13649. }
  13650. /**
  13651. * Get the current value of a name, or `undefined` if there is no value.
  13652. *
  13653. * Note: Do not use `if (namespace.get(...))` to detect whether a macro
  13654. * is defined, as the definition may be the empty string which evaluates
  13655. * to `false` in JavaScript. Use `if (namespace.get(...) != null)` or
  13656. * `if (namespace.has(...))`.
  13657. */
  13658. get(name) {
  13659. if (this.current.hasOwnProperty(name)) {
  13660. return this.current[name];
  13661. } else {
  13662. return this.builtins[name];
  13663. }
  13664. }
  13665. /**
  13666. * Set the current value of a name, and optionally set it globally too.
  13667. * Local set() sets the current value and (when appropriate) adds an undo
  13668. * operation to the undo stack. Global set() may change the undo
  13669. * operation at every level, so takes time linear in their number.
  13670. * A value of undefined means to delete existing definitions.
  13671. */
  13672. set(name, value, global) {
  13673. if (global === void 0) {
  13674. global = false;
  13675. }
  13676. if (global) {
  13677. // Global set is equivalent to setting in all groups. Simulate this
  13678. // by destroying any undos currently scheduled for this name,
  13679. // and adding an undo with the *new* value (in case it later gets
  13680. // locally reset within this environment).
  13681. for (let i = 0; i < this.undefStack.length; i++) {
  13682. delete this.undefStack[i][name];
  13683. }
  13684. if (this.undefStack.length > 0) {
  13685. this.undefStack[this.undefStack.length - 1][name] = value;
  13686. }
  13687. } else {
  13688. // Undo this set at end of this group (possibly to `undefined`),
  13689. // unless an undo is already in place, in which case that older
  13690. // value is the correct one.
  13691. const top = this.undefStack[this.undefStack.length - 1];
  13692. if (top && !top.hasOwnProperty(name)) {
  13693. top[name] = this.current[name];
  13694. }
  13695. }
  13696. if (value == null) {
  13697. delete this.current[name];
  13698. } else {
  13699. this.current[name] = value;
  13700. }
  13701. }
  13702. }
  13703. ;// ./src/macros.ts
  13704. /**
  13705. * Predefined macros for KaTeX.
  13706. * This can be used to define some commands in terms of others.
  13707. */
  13708. // Export global macros object from defineMacro
  13709. const macros = _macros;
  13710. /* harmony default export */ var src_macros = (macros);
  13711. //////////////////////////////////////////////////////////////////////
  13712. // macro tools
  13713. defineMacro("\\noexpand", function (context) {
  13714. // The expansion is the token itself; but that token is interpreted
  13715. // as if its meaning were ‘\relax’ if it is a control sequence that
  13716. // would ordinarily be expanded by TeX’s expansion rules.
  13717. const t = context.popToken();
  13718. if (context.isExpandable(t.text)) {
  13719. t.noexpand = true;
  13720. t.treatAsRelax = true;
  13721. }
  13722. return {
  13723. tokens: [t],
  13724. numArgs: 0
  13725. };
  13726. });
  13727. defineMacro("\\expandafter", function (context) {
  13728. // TeX first reads the token that comes immediately after \expandafter,
  13729. // without expanding it; let’s call this token t. Then TeX reads the
  13730. // token that comes after t (and possibly more tokens, if that token
  13731. // has an argument), replacing it by its expansion. Finally TeX puts
  13732. // t back in front of that expansion.
  13733. const t = context.popToken();
  13734. context.expandOnce(true); // expand only an expandable token
  13735. return {
  13736. tokens: [t],
  13737. numArgs: 0
  13738. };
  13739. });
  13740. // LaTeX's \@firstoftwo{#1}{#2} expands to #1, skipping #2
  13741. // TeX source: \long\def\@firstoftwo#1#2{#1}
  13742. defineMacro("\\@firstoftwo", function (context) {
  13743. const args = context.consumeArgs(2);
  13744. return {
  13745. tokens: args[0],
  13746. numArgs: 0
  13747. };
  13748. });
  13749. // LaTeX's \@secondoftwo{#1}{#2} expands to #2, skipping #1
  13750. // TeX source: \long\def\@secondoftwo#1#2{#2}
  13751. defineMacro("\\@secondoftwo", function (context) {
  13752. const args = context.consumeArgs(2);
  13753. return {
  13754. tokens: args[1],
  13755. numArgs: 0
  13756. };
  13757. });
  13758. // LaTeX's \@ifnextchar{#1}{#2}{#3} looks ahead to the next (unexpanded)
  13759. // symbol that isn't a space, consuming any spaces but not consuming the
  13760. // first nonspace character. If that nonspace character matches #1, then
  13761. // the macro expands to #2; otherwise, it expands to #3.
  13762. defineMacro("\\@ifnextchar", function (context) {
  13763. const args = context.consumeArgs(3); // symbol, if, else
  13764. context.consumeSpaces();
  13765. const nextToken = context.future();
  13766. if (args[0].length === 1 && args[0][0].text === nextToken.text) {
  13767. return {
  13768. tokens: args[1],
  13769. numArgs: 0
  13770. };
  13771. } else {
  13772. return {
  13773. tokens: args[2],
  13774. numArgs: 0
  13775. };
  13776. }
  13777. });
  13778. // LaTeX's \@ifstar{#1}{#2} looks ahead to the next (unexpanded) symbol.
  13779. // If it is `*`, then it consumes the symbol, and the macro expands to #1;
  13780. // otherwise, the macro expands to #2 (without consuming the symbol).
  13781. // TeX source: \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
  13782. defineMacro("\\@ifstar", "\\@ifnextchar *{\\@firstoftwo{#1}}");
  13783. // LaTeX's \TextOrMath{#1}{#2} expands to #1 in text mode, #2 in math mode
  13784. defineMacro("\\TextOrMath", function (context) {
  13785. const args = context.consumeArgs(2);
  13786. if (context.mode === 'text') {
  13787. return {
  13788. tokens: args[0],
  13789. numArgs: 0
  13790. };
  13791. } else {
  13792. return {
  13793. tokens: args[1],
  13794. numArgs: 0
  13795. };
  13796. }
  13797. });
  13798. // Lookup table for parsing numbers in base 8 through 16
  13799. const digitToNumber = {
  13800. "0": 0,
  13801. "1": 1,
  13802. "2": 2,
  13803. "3": 3,
  13804. "4": 4,
  13805. "5": 5,
  13806. "6": 6,
  13807. "7": 7,
  13808. "8": 8,
  13809. "9": 9,
  13810. "a": 10,
  13811. "A": 10,
  13812. "b": 11,
  13813. "B": 11,
  13814. "c": 12,
  13815. "C": 12,
  13816. "d": 13,
  13817. "D": 13,
  13818. "e": 14,
  13819. "E": 14,
  13820. "f": 15,
  13821. "F": 15
  13822. };
  13823. // TeX \char makes a literal character (catcode 12) using the following forms:
  13824. // (see The TeXBook, p. 43)
  13825. // \char123 -- decimal
  13826. // \char'123 -- octal
  13827. // \char"123 -- hex
  13828. // \char`x -- character that can be written (i.e. isn't active)
  13829. // \char`\x -- character that cannot be written (e.g. %)
  13830. // These all refer to characters from the font, so we turn them into special
  13831. // calls to a function \@char dealt with in the Parser.
  13832. defineMacro("\\char", function (context) {
  13833. let token = context.popToken();
  13834. let base;
  13835. let number = 0;
  13836. if (token.text === "'") {
  13837. base = 8;
  13838. token = context.popToken();
  13839. } else if (token.text === '"') {
  13840. base = 16;
  13841. token = context.popToken();
  13842. } else if (token.text === "`") {
  13843. token = context.popToken();
  13844. if (token.text[0] === "\\") {
  13845. number = token.text.charCodeAt(1);
  13846. } else if (token.text === "EOF") {
  13847. throw new src_ParseError("\\char` missing argument");
  13848. } else {
  13849. number = token.text.charCodeAt(0);
  13850. }
  13851. } else {
  13852. base = 10;
  13853. }
  13854. if (base) {
  13855. // Parse a number in the given base, starting with first `token`.
  13856. number = digitToNumber[token.text];
  13857. if (number == null || number >= base) {
  13858. throw new src_ParseError("Invalid base-" + base + " digit " + token.text);
  13859. }
  13860. let digit;
  13861. while ((digit = digitToNumber[context.future().text]) != null && digit < base) {
  13862. number *= base;
  13863. number += digit;
  13864. context.popToken();
  13865. }
  13866. }
  13867. return "\\@char{" + number + "}";
  13868. });
  13869. // \newcommand{\macro}[args]{definition}
  13870. // \renewcommand{\macro}[args]{definition}
  13871. // TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
  13872. const newcommand = (context, existsOK, nonexistsOK, skipIfExists) => {
  13873. let arg = context.consumeArg().tokens;
  13874. if (arg.length !== 1) {
  13875. throw new src_ParseError("\\newcommand's first argument must be a macro name");
  13876. }
  13877. const name = arg[0].text;
  13878. const exists = context.isDefined(name);
  13879. if (exists && !existsOK) {
  13880. throw new src_ParseError("\\newcommand{" + name + "} attempting to redefine " + (name + "; use \\renewcommand"));
  13881. }
  13882. if (!exists && !nonexistsOK) {
  13883. throw new src_ParseError("\\renewcommand{" + name + "} when command " + name + " " + "does not yet exist; use \\newcommand");
  13884. }
  13885. let numArgs = 0;
  13886. arg = context.consumeArg().tokens;
  13887. if (arg.length === 1 && arg[0].text === "[") {
  13888. let argText = '';
  13889. let token = context.expandNextToken();
  13890. while (token.text !== "]" && token.text !== "EOF") {
  13891. // TODO: Should properly expand arg, e.g., ignore {}s
  13892. argText += token.text;
  13893. token = context.expandNextToken();
  13894. }
  13895. if (!argText.match(/^\s*[0-9]+\s*$/)) {
  13896. throw new src_ParseError("Invalid number of arguments: " + argText);
  13897. }
  13898. numArgs = parseInt(argText);
  13899. arg = context.consumeArg().tokens;
  13900. }
  13901. if (!(exists && skipIfExists)) {
  13902. // Final arg is the expansion of the macro
  13903. context.macros.set(name, {
  13904. tokens: arg,
  13905. numArgs
  13906. });
  13907. }
  13908. return '';
  13909. };
  13910. defineMacro("\\newcommand", context => newcommand(context, false, true, false));
  13911. defineMacro("\\renewcommand", context => newcommand(context, true, false, false));
  13912. defineMacro("\\providecommand", context => newcommand(context, true, true, true));
  13913. // terminal (console) tools
  13914. defineMacro("\\message", context => {
  13915. const arg = context.consumeArgs(1)[0];
  13916. // eslint-disable-next-line no-console
  13917. console.log(arg.reverse().map(token => token.text).join(""));
  13918. return '';
  13919. });
  13920. defineMacro("\\errmessage", context => {
  13921. const arg = context.consumeArgs(1)[0];
  13922. // eslint-disable-next-line no-console
  13923. console.error(arg.reverse().map(token => token.text).join(""));
  13924. return '';
  13925. });
  13926. defineMacro("\\show", context => {
  13927. const tok = context.popToken();
  13928. const name = tok.text;
  13929. // eslint-disable-next-line no-console
  13930. console.log(tok, context.macros.get(name), src_functions[name], src_symbols.math[name], src_symbols.text[name]);
  13931. return '';
  13932. });
  13933. //////////////////////////////////////////////////////////////////////
  13934. // Grouping
  13935. // \let\bgroup={ \let\egroup=}
  13936. defineMacro("\\bgroup", "{");
  13937. defineMacro("\\egroup", "}");
  13938. // Symbols from latex.ltx:
  13939. // \def~{\nobreakspace{}}
  13940. // \def\lq{`}
  13941. // \def\rq{'}
  13942. // \def \aa {\r a}
  13943. // \def \AA {\r A}
  13944. defineMacro("~", "\\nobreakspace");
  13945. defineMacro("\\lq", "`");
  13946. defineMacro("\\rq", "'");
  13947. defineMacro("\\aa", "\\r a");
  13948. defineMacro("\\AA", "\\r A");
  13949. // Copyright (C) and registered (R) symbols. Use raw symbol in MathML.
  13950. // \DeclareTextCommandDefault{\textcopyright}{\textcircled{c}}
  13951. // \DeclareTextCommandDefault{\textregistered}{\textcircled{%
  13952. // \check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont R}}
  13953. // \DeclareRobustCommand{\copyright}{%
  13954. // \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
  13955. defineMacro("\\textcopyright", "\\html@mathml{\\textcircled{c}}{\\char`©}");
  13956. defineMacro("\\copyright", "\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");
  13957. defineMacro("\\textregistered", "\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}");
  13958. // Characters omitted from Unicode range 1D400–1D7FF
  13959. defineMacro("\u212C", "\\mathscr{B}"); // script
  13960. defineMacro("\u2130", "\\mathscr{E}");
  13961. defineMacro("\u2131", "\\mathscr{F}");
  13962. defineMacro("\u210B", "\\mathscr{H}");
  13963. defineMacro("\u2110", "\\mathscr{I}");
  13964. defineMacro("\u2112", "\\mathscr{L}");
  13965. defineMacro("\u2133", "\\mathscr{M}");
  13966. defineMacro("\u211B", "\\mathscr{R}");
  13967. defineMacro("\u212D", "\\mathfrak{C}"); // Fraktur
  13968. defineMacro("\u210C", "\\mathfrak{H}");
  13969. defineMacro("\u2128", "\\mathfrak{Z}");
  13970. // Define \Bbbk with a macro that works in both HTML and MathML.
  13971. defineMacro("\\Bbbk", "\\Bbb{k}");
  13972. // \llap and \rlap render their contents in text mode
  13973. defineMacro("\\llap", "\\mathllap{\\textrm{#1}}");
  13974. defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}");
  13975. defineMacro("\\clap", "\\mathclap{\\textrm{#1}}");
  13976. // \mathstrut from the TeXbook, p 360
  13977. defineMacro("\\mathstrut", "\\vphantom{(}");
  13978. // \underbar from TeXbook p 353
  13979. defineMacro("\\underbar", "\\underline{\\text{#1}}");
  13980. // \not is defined by base/fontmath.ltx via
  13981. // \DeclareMathSymbol{\not}{\mathrel}{symbols}{"36}
  13982. // It's thus treated like a \mathrel, but defined by a symbol that has zero
  13983. // width but extends to the right. We use \rlap to get that spacing.
  13984. // For MathML we write U+0338 here. buildMathML.js will then do the overlay.
  13985. defineMacro("\\not", "\\html@mathml{\\mathrel{\\mathrlap\\@not}\\nobreak}" + "{\\char\"338}");
  13986. // Negated symbols from base/fontmath.ltx:
  13987. // \def\neq{\not=} \let\ne=\neq
  13988. // \DeclareRobustCommand
  13989. // \notin{\mathrel{\m@th\mathpalette\c@ncel\in}}
  13990. // \def\c@ncel#1#2{\m@th\ooalign{$\hfil#1\mkern1mu/\hfil$\crcr$#1#2$}}
  13991. defineMacro("\\neq", "\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}");
  13992. defineMacro("\\ne", "\\neq");
  13993. defineMacro("\u2260", "\\neq");
  13994. defineMacro("\\notin", "\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}" + "{\\mathrel{\\char`∉}}");
  13995. defineMacro("\u2209", "\\notin");
  13996. // Unicode stacked relations
  13997. defineMacro("\u2258", "\\html@mathml{" + "\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}" + "}{\\mathrel{\\char`\u2258}}");
  13998. defineMacro("\u2259", "\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`\u2258}}");
  13999. defineMacro("\u225A", "\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`\u225A}}");
  14000. defineMacro("\u225B", "\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}" + "{\\mathrel{\\char`\u225B}}");
  14001. defineMacro("\u225D", "\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}" + "{\\mathrel{\\char`\u225D}}");
  14002. defineMacro("\u225E", "\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}" + "{\\mathrel{\\char`\u225E}}");
  14003. defineMacro("\u225F", "\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`\u225F}}");
  14004. // Misc Unicode
  14005. defineMacro("\u27C2", "\\perp");
  14006. defineMacro("\u203C", "\\mathclose{!\\mkern-0.8mu!}");
  14007. defineMacro("\u220C", "\\notni");
  14008. defineMacro("\u231C", "\\ulcorner");
  14009. defineMacro("\u231D", "\\urcorner");
  14010. defineMacro("\u231E", "\\llcorner");
  14011. defineMacro("\u231F", "\\lrcorner");
  14012. defineMacro("\u00A9", "\\copyright");
  14013. defineMacro("\u00AE", "\\textregistered");
  14014. // The KaTeX fonts have corners at codepoints that don't match Unicode.
  14015. // For MathML purposes, use the Unicode code point.
  14016. defineMacro("\\ulcorner", "\\html@mathml{\\@ulcorner}{\\mathop{\\char\"231c}}");
  14017. defineMacro("\\urcorner", "\\html@mathml{\\@urcorner}{\\mathop{\\char\"231d}}");
  14018. defineMacro("\\llcorner", "\\html@mathml{\\@llcorner}{\\mathop{\\char\"231e}}");
  14019. defineMacro("\\lrcorner", "\\html@mathml{\\@lrcorner}{\\mathop{\\char\"231f}}");
  14020. //////////////////////////////////////////////////////////////////////
  14021. // LaTeX_2ε
  14022. // \vdots{\vbox{\baselineskip4\p@ \lineskiplimit\z@
  14023. // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
  14024. // We'll call \varvdots, which gets a glyph from symbols.js.
  14025. // The zero-width rule gets us an equivalent to the vertical 6pt kern.
  14026. defineMacro("\\vdots", "{\\varvdots\\rule{0pt}{15pt}}");
  14027. defineMacro("\u22ee", "\\vdots");
  14028. //////////////////////////////////////////////////////////////////////
  14029. // amsmath.sty
  14030. // http://mirrors.concertpass.com/tex-archive/macros/latex/required/amsmath/amsmath.pdf
  14031. // Italic Greek capital letters. AMS defines these with \DeclareMathSymbol,
  14032. // but they are equivalent to \mathit{\Letter}.
  14033. defineMacro("\\varGamma", "\\mathit{\\Gamma}");
  14034. defineMacro("\\varDelta", "\\mathit{\\Delta}");
  14035. defineMacro("\\varTheta", "\\mathit{\\Theta}");
  14036. defineMacro("\\varLambda", "\\mathit{\\Lambda}");
  14037. defineMacro("\\varXi", "\\mathit{\\Xi}");
  14038. defineMacro("\\varPi", "\\mathit{\\Pi}");
  14039. defineMacro("\\varSigma", "\\mathit{\\Sigma}");
  14040. defineMacro("\\varUpsilon", "\\mathit{\\Upsilon}");
  14041. defineMacro("\\varPhi", "\\mathit{\\Phi}");
  14042. defineMacro("\\varPsi", "\\mathit{\\Psi}");
  14043. defineMacro("\\varOmega", "\\mathit{\\Omega}");
  14044. //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
  14045. defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}");
  14046. // \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
  14047. // \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
  14048. defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}" + "\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax");
  14049. // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
  14050. defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}");
  14051. // \def\iff{\DOTSB\;\Longleftrightarrow\;}
  14052. // \def\implies{\DOTSB\;\Longrightarrow\;}
  14053. // \def\impliedby{\DOTSB\;\Longleftarrow\;}
  14054. defineMacro("\\iff", "\\DOTSB\\;\\Longleftrightarrow\\;");
  14055. defineMacro("\\implies", "\\DOTSB\\;\\Longrightarrow\\;");
  14056. defineMacro("\\impliedby", "\\DOTSB\\;\\Longleftarrow\\;");
  14057. // \def\dddot#1{{\mathop{#1}\limits^{\vbox to-1.4\ex@{\kern-\tw@\ex@
  14058. // \hbox{\normalfont ...}\vss}}}}
  14059. // We use \overset which avoids the vertical shift of \mathop.
  14060. defineMacro("\\dddot", "{\\overset{\\raisebox{-0.1ex}{\\normalsize ...}}{#1}}");
  14061. defineMacro("\\ddddot", "{\\overset{\\raisebox{-0.1ex}{\\normalsize ....}}{#1}}");
  14062. // AMSMath's automatic \dots, based on \mdots@@ macro.
  14063. const dotsByToken = {
  14064. ',': '\\dotsc',
  14065. '\\not': '\\dotsb',
  14066. // \keybin@ checks for the following:
  14067. '+': '\\dotsb',
  14068. '=': '\\dotsb',
  14069. '<': '\\dotsb',
  14070. '>': '\\dotsb',
  14071. '-': '\\dotsb',
  14072. '*': '\\dotsb',
  14073. ':': '\\dotsb',
  14074. // Symbols whose definition starts with \DOTSB:
  14075. '\\DOTSB': '\\dotsb',
  14076. '\\coprod': '\\dotsb',
  14077. '\\bigvee': '\\dotsb',
  14078. '\\bigwedge': '\\dotsb',
  14079. '\\biguplus': '\\dotsb',
  14080. '\\bigcap': '\\dotsb',
  14081. '\\bigcup': '\\dotsb',
  14082. '\\prod': '\\dotsb',
  14083. '\\sum': '\\dotsb',
  14084. '\\bigotimes': '\\dotsb',
  14085. '\\bigoplus': '\\dotsb',
  14086. '\\bigodot': '\\dotsb',
  14087. '\\bigsqcup': '\\dotsb',
  14088. '\\And': '\\dotsb',
  14089. '\\longrightarrow': '\\dotsb',
  14090. '\\Longrightarrow': '\\dotsb',
  14091. '\\longleftarrow': '\\dotsb',
  14092. '\\Longleftarrow': '\\dotsb',
  14093. '\\longleftrightarrow': '\\dotsb',
  14094. '\\Longleftrightarrow': '\\dotsb',
  14095. '\\mapsto': '\\dotsb',
  14096. '\\longmapsto': '\\dotsb',
  14097. '\\hookrightarrow': '\\dotsb',
  14098. '\\doteq': '\\dotsb',
  14099. // Symbols whose definition starts with \mathbin:
  14100. '\\mathbin': '\\dotsb',
  14101. // Symbols whose definition starts with \mathrel:
  14102. '\\mathrel': '\\dotsb',
  14103. '\\relbar': '\\dotsb',
  14104. '\\Relbar': '\\dotsb',
  14105. '\\xrightarrow': '\\dotsb',
  14106. '\\xleftarrow': '\\dotsb',
  14107. // Symbols whose definition starts with \DOTSI:
  14108. '\\DOTSI': '\\dotsi',
  14109. '\\int': '\\dotsi',
  14110. '\\oint': '\\dotsi',
  14111. '\\iint': '\\dotsi',
  14112. '\\iiint': '\\dotsi',
  14113. '\\iiiint': '\\dotsi',
  14114. '\\idotsint': '\\dotsi',
  14115. // Symbols whose definition starts with \DOTSX:
  14116. '\\DOTSX': '\\dotsx'
  14117. };
  14118. const dotsbGroups = new Set(['bin', 'rel']);
  14119. defineMacro("\\dots", function (context) {
  14120. // TODO: If used in text mode, should expand to \textellipsis.
  14121. // However, in KaTeX, \textellipsis and \ldots behave the same
  14122. // (in text mode), and it's unlikely we'd see any of the math commands
  14123. // that affect the behavior of \dots when in text mode. So fine for now
  14124. // (until we support \ifmmode ... \else ... \fi).
  14125. let thedots = '\\dotso';
  14126. const next = context.expandAfterFuture().text;
  14127. if (next in dotsByToken) {
  14128. thedots = dotsByToken[next];
  14129. } else if (next.slice(0, 4) === '\\not') {
  14130. thedots = '\\dotsb';
  14131. } else if (next in src_symbols.math) {
  14132. if (dotsbGroups.has(src_symbols.math[next].group)) {
  14133. thedots = '\\dotsb';
  14134. }
  14135. }
  14136. return thedots;
  14137. });
  14138. const spaceAfterDots = {
  14139. // \rightdelim@ checks for the following:
  14140. ')': true,
  14141. ']': true,
  14142. '\\rbrack': true,
  14143. '\\}': true,
  14144. '\\rbrace': true,
  14145. '\\rangle': true,
  14146. '\\rceil': true,
  14147. '\\rfloor': true,
  14148. '\\rgroup': true,
  14149. '\\rmoustache': true,
  14150. '\\right': true,
  14151. '\\bigr': true,
  14152. '\\biggr': true,
  14153. '\\Bigr': true,
  14154. '\\Biggr': true,
  14155. // \extra@ also tests for the following:
  14156. '$': true,
  14157. // \extrap@ checks for the following:
  14158. ';': true,
  14159. '.': true,
  14160. ',': true
  14161. };
  14162. defineMacro("\\dotso", function (context) {
  14163. const next = context.future().text;
  14164. if (next in spaceAfterDots) {
  14165. return "\\ldots\\,";
  14166. } else {
  14167. return "\\ldots";
  14168. }
  14169. });
  14170. defineMacro("\\dotsc", function (context) {
  14171. const next = context.future().text;
  14172. // \dotsc uses \extra@ but not \extrap@, instead specially checking for
  14173. // ';' and '.', but doesn't check for ','.
  14174. if (next in spaceAfterDots && next !== ',') {
  14175. return "\\ldots\\,";
  14176. } else {
  14177. return "\\ldots";
  14178. }
  14179. });
  14180. defineMacro("\\cdots", function (context) {
  14181. const next = context.future().text;
  14182. if (next in spaceAfterDots) {
  14183. return "\\@cdots\\,";
  14184. } else {
  14185. return "\\@cdots";
  14186. }
  14187. });
  14188. defineMacro("\\dotsb", "\\cdots");
  14189. defineMacro("\\dotsm", "\\cdots");
  14190. defineMacro("\\dotsi", "\\!\\cdots");
  14191. // amsmath doesn't actually define \dotsx, but \dots followed by a macro
  14192. // starting with \DOTSX implies \dotso, and then \extra@ detects this case
  14193. // and forces the added `\,`.
  14194. defineMacro("\\dotsx", "\\ldots\\,");
  14195. // \let\DOTSI\relax
  14196. // \let\DOTSB\relax
  14197. // \let\DOTSX\relax
  14198. defineMacro("\\DOTSI", "\\relax");
  14199. defineMacro("\\DOTSB", "\\relax");
  14200. defineMacro("\\DOTSX", "\\relax");
  14201. // Spacing, based on amsmath.sty's override of LaTeX defaults
  14202. // \DeclareRobustCommand{\tmspace}[3]{%
  14203. // \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
  14204. defineMacro("\\tmspace", "\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax");
  14205. // \renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
  14206. // TODO: math mode should use \thinmuskip
  14207. defineMacro("\\,", "\\tmspace+{3mu}{.1667em}");
  14208. // \let\thinspace\,
  14209. defineMacro("\\thinspace", "\\,");
  14210. // \def\>{\mskip\medmuskip}
  14211. // \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
  14212. // TODO: \> and math mode of \: should use \medmuskip = 4mu plus 2mu minus 4mu
  14213. defineMacro("\\>", "\\mskip{4mu}");
  14214. defineMacro("\\:", "\\tmspace+{4mu}{.2222em}");
  14215. // \let\medspace\:
  14216. defineMacro("\\medspace", "\\:");
  14217. // \renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
  14218. // TODO: math mode should use \thickmuskip = 5mu plus 5mu
  14219. defineMacro("\\;", "\\tmspace+{5mu}{.2777em}");
  14220. // \let\thickspace\;
  14221. defineMacro("\\thickspace", "\\;");
  14222. // \renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
  14223. // TODO: math mode should use \thinmuskip
  14224. defineMacro("\\!", "\\tmspace-{3mu}{.1667em}");
  14225. // \let\negthinspace\!
  14226. defineMacro("\\negthinspace", "\\!");
  14227. // \newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
  14228. // TODO: math mode should use \medmuskip
  14229. defineMacro("\\negmedspace", "\\tmspace-{4mu}{.2222em}");
  14230. // \newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
  14231. // TODO: math mode should use \thickmuskip
  14232. defineMacro("\\negthickspace", "\\tmspace-{5mu}{.277em}");
  14233. // \def\enspace{\kern.5em }
  14234. defineMacro("\\enspace", "\\kern.5em ");
  14235. // \def\enskip{\hskip.5em\relax}
  14236. defineMacro("\\enskip", "\\hskip.5em\\relax");
  14237. // \def\quad{\hskip1em\relax}
  14238. defineMacro("\\quad", "\\hskip1em\\relax");
  14239. // \def\qquad{\hskip2em\relax}
  14240. defineMacro("\\qquad", "\\hskip2em\\relax");
  14241. // \tag@in@display form of \tag
  14242. defineMacro("\\tag", "\\@ifstar\\tag@literal\\tag@paren");
  14243. defineMacro("\\tag@paren", "\\tag@literal{({#1})}");
  14244. defineMacro("\\tag@literal", context => {
  14245. if (context.macros.get("\\df@tag")) {
  14246. throw new src_ParseError("Multiple \\tag");
  14247. }
  14248. return "\\gdef\\df@tag{\\text{#1}}";
  14249. });
  14250. // \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
  14251. // {\operator@font mod}\penalty900
  14252. // \mkern5mu\nonscript\mskip-\medmuskip}
  14253. // \newcommand{\pod}[1]{\allowbreak
  14254. // \if@display\mkern18mu\else\mkern8mu\fi(#1)}
  14255. // \renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}
  14256. // \newcommand{\mod}[1]{\allowbreak\if@display\mkern18mu
  14257. // \else\mkern12mu\fi{\operator@font mod}\,\,#1}
  14258. // TODO: math mode should use \medmuskip = 4mu plus 2mu minus 4mu
  14259. defineMacro("\\bmod", "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}" + "\\mathbin{\\rm mod}" + "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}");
  14260. defineMacro("\\pod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");
  14261. defineMacro("\\pmod", "\\pod{{\\rm mod}\\mkern6mu#1}");
  14262. defineMacro("\\mod", "\\allowbreak" + "\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}" + "{\\rm mod}\\,\\,#1");
  14263. //////////////////////////////////////////////////////////////////////
  14264. // LaTeX source2e
  14265. // \expandafter\let\expandafter\@normalcr
  14266. // \csname\expandafter\@gobble\string\\ \endcsname
  14267. // \DeclareRobustCommand\newline{\@normalcr\relax}
  14268. defineMacro("\\newline", "\\\\\\relax");
  14269. // \def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}
  14270. // TODO: Doesn't normally work in math mode because \@ fails. KaTeX doesn't
  14271. // support \@ yet, so that's omitted, and we add \text so that the result
  14272. // doesn't look funny in math mode.
  14273. defineMacro("\\TeX", "\\textrm{\\html@mathml{" + "T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX" + "}{TeX}}");
  14274. // \DeclareRobustCommand{\LaTeX}{L\kern-.36em%
  14275. // {\sbox\z@ T%
  14276. // \vbox to\ht\z@{\hbox{\check@mathfonts
  14277. // \fontsize\sf@size\z@
  14278. // \math@fontsfalse\selectfont
  14279. // A}%
  14280. // \vss}%
  14281. // }%
  14282. // \kern-.15em%
  14283. // \TeX}
  14284. // This code aligns the top of the A with the T (from the perspective of TeX's
  14285. // boxes, though visually the A appears to extend above slightly).
  14286. // We compute the corresponding \raisebox when A is rendered in \normalsize
  14287. // \scriptstyle, which has a scale factor of 0.7 (see Options.js).
  14288. const latexRaiseA = makeEm(fontMetricsData['Main-Regular']["T".charCodeAt(0)][1] - 0.7 * fontMetricsData['Main-Regular']["A".charCodeAt(0)][1]);
  14289. defineMacro("\\LaTeX", "\\textrm{\\html@mathml{" + ("L\\kern-.36em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{LaTeX}}");
  14290. // New KaTeX logo based on tweaking LaTeX logo
  14291. defineMacro("\\KaTeX", "\\textrm{\\html@mathml{" + ("K\\kern-.17em\\raisebox{" + latexRaiseA + "}{\\scriptstyle A}") + "\\kern-.15em\\TeX}{KaTeX}}");
  14292. // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
  14293. // \def\@hspace#1{\hskip #1\relax}
  14294. // \def\@hspacer#1{\vrule \@width\z@\nobreak
  14295. // \hskip #1\hskip \z@skip}
  14296. defineMacro("\\hspace", "\\@ifstar\\@hspacer\\@hspace");
  14297. defineMacro("\\@hspace", "\\hskip #1\\relax");
  14298. defineMacro("\\@hspacer", "\\rule{0pt}{0pt}\\hskip #1\\relax");
  14299. //////////////////////////////////////////////////////////////////////
  14300. // mathtools.sty
  14301. //\providecommand\ordinarycolon{:}
  14302. defineMacro("\\ordinarycolon", ":");
  14303. //\def\vcentcolon{\mathrel{\mathop\ordinarycolon}}
  14304. //TODO(edemaine): Not yet centered. Fix via \raisebox or #726
  14305. defineMacro("\\vcentcolon", "\\mathrel{\\mathop\\ordinarycolon}");
  14306. // \providecommand*\dblcolon{\vcentcolon\mathrel{\mkern-.9mu}\vcentcolon}
  14307. defineMacro("\\dblcolon", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}" + "{\\mathop{\\char\"2237}}");
  14308. // \providecommand*\coloneqq{\vcentcolon\mathrel{\mkern-1.2mu}=}
  14309. defineMacro("\\coloneqq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2254}}"); // ≔
  14310. // \providecommand*\Coloneqq{\dblcolon\mathrel{\mkern-1.2mu}=}
  14311. defineMacro("\\Coloneqq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}" + "{\\mathop{\\char\"2237\\char\"3d}}");
  14312. // \providecommand*\coloneq{\vcentcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
  14313. defineMacro("\\coloneq", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"3a\\char\"2212}}");
  14314. // \providecommand*\Coloneq{\dblcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
  14315. defineMacro("\\Coloneq", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" + "{\\mathop{\\char\"2237\\char\"2212}}");
  14316. // \providecommand*\eqqcolon{=\mathrel{\mkern-1.2mu}\vcentcolon}
  14317. defineMacro("\\eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2255}}"); // ≕
  14318. // \providecommand*\Eqqcolon{=\mathrel{\mkern-1.2mu}\dblcolon}
  14319. defineMacro("\\Eqqcolon", "\\html@mathml{" + "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"3d\\char\"2237}}");
  14320. // \providecommand*\eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\vcentcolon}
  14321. defineMacro("\\eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" + "{\\mathop{\\char\"2239}}");
  14322. // \providecommand*\Eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\dblcolon}
  14323. defineMacro("\\Eqcolon", "\\html@mathml{" + "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}" + "{\\mathop{\\char\"2212\\char\"2237}}");
  14324. // \providecommand*\colonapprox{\vcentcolon\mathrel{\mkern-1.2mu}\approx}
  14325. defineMacro("\\colonapprox", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"3a\\char\"2248}}");
  14326. // \providecommand*\Colonapprox{\dblcolon\mathrel{\mkern-1.2mu}\approx}
  14327. defineMacro("\\Colonapprox", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}" + "{\\mathop{\\char\"2237\\char\"2248}}");
  14328. // \providecommand*\colonsim{\vcentcolon\mathrel{\mkern-1.2mu}\sim}
  14329. defineMacro("\\colonsim", "\\html@mathml{" + "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"3a\\char\"223c}}");
  14330. // \providecommand*\Colonsim{\dblcolon\mathrel{\mkern-1.2mu}\sim}
  14331. defineMacro("\\Colonsim", "\\html@mathml{" + "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}" + "{\\mathop{\\char\"2237\\char\"223c}}");
  14332. // Some Unicode characters are implemented with macros to mathtools functions.
  14333. defineMacro("\u2237", "\\dblcolon"); // ::
  14334. defineMacro("\u2239", "\\eqcolon"); // -:
  14335. defineMacro("\u2254", "\\coloneqq"); // :=
  14336. defineMacro("\u2255", "\\eqqcolon"); // =:
  14337. defineMacro("\u2A74", "\\Coloneqq"); // ::=
  14338. //////////////////////////////////////////////////////////////////////
  14339. // colonequals.sty
  14340. // Alternate names for mathtools's macros:
  14341. defineMacro("\\ratio", "\\vcentcolon");
  14342. defineMacro("\\coloncolon", "\\dblcolon");
  14343. defineMacro("\\colonequals", "\\coloneqq");
  14344. defineMacro("\\coloncolonequals", "\\Coloneqq");
  14345. defineMacro("\\equalscolon", "\\eqqcolon");
  14346. defineMacro("\\equalscoloncolon", "\\Eqqcolon");
  14347. defineMacro("\\colonminus", "\\coloneq");
  14348. defineMacro("\\coloncolonminus", "\\Coloneq");
  14349. defineMacro("\\minuscolon", "\\eqcolon");
  14350. defineMacro("\\minuscoloncolon", "\\Eqcolon");
  14351. // \colonapprox name is same in mathtools and colonequals.
  14352. defineMacro("\\coloncolonapprox", "\\Colonapprox");
  14353. // \colonsim name is same in mathtools and colonequals.
  14354. defineMacro("\\coloncolonsim", "\\Colonsim");
  14355. // Additional macros, implemented by analogy with mathtools definitions:
  14356. defineMacro("\\simcolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
  14357. defineMacro("\\simcoloncolon", "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}");
  14358. defineMacro("\\approxcolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
  14359. defineMacro("\\approxcoloncolon", "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}");
  14360. // Present in newtxmath, pxfonts and txfonts
  14361. defineMacro("\\notni", "\\html@mathml{\\not\\ni}{\\mathrel{\\char`\u220C}}");
  14362. defineMacro("\\limsup", "\\DOTSB\\operatorname*{lim\\,sup}");
  14363. defineMacro("\\liminf", "\\DOTSB\\operatorname*{lim\\,inf}");
  14364. //////////////////////////////////////////////////////////////////////
  14365. // From amsopn.sty
  14366. defineMacro("\\injlim", "\\DOTSB\\operatorname*{inj\\,lim}");
  14367. defineMacro("\\projlim", "\\DOTSB\\operatorname*{proj\\,lim}");
  14368. defineMacro("\\varlimsup", "\\DOTSB\\operatorname*{\\overline{lim}}");
  14369. defineMacro("\\varliminf", "\\DOTSB\\operatorname*{\\underline{lim}}");
  14370. defineMacro("\\varinjlim", "\\DOTSB\\operatorname*{\\underrightarrow{lim}}");
  14371. defineMacro("\\varprojlim", "\\DOTSB\\operatorname*{\\underleftarrow{lim}}");
  14372. //////////////////////////////////////////////////////////////////////
  14373. // MathML alternates for KaTeX glyphs in the Unicode private area
  14374. defineMacro("\\gvertneqq", "\\html@mathml{\\@gvertneqq}{\u2269}");
  14375. defineMacro("\\lvertneqq", "\\html@mathml{\\@lvertneqq}{\u2268}");
  14376. defineMacro("\\ngeqq", "\\html@mathml{\\@ngeqq}{\u2271}");
  14377. defineMacro("\\ngeqslant", "\\html@mathml{\\@ngeqslant}{\u2271}");
  14378. defineMacro("\\nleqq", "\\html@mathml{\\@nleqq}{\u2270}");
  14379. defineMacro("\\nleqslant", "\\html@mathml{\\@nleqslant}{\u2270}");
  14380. defineMacro("\\nshortmid", "\\html@mathml{\\@nshortmid}{∤}");
  14381. defineMacro("\\nshortparallel", "\\html@mathml{\\@nshortparallel}{∦}");
  14382. defineMacro("\\nsubseteqq", "\\html@mathml{\\@nsubseteqq}{\u2288}");
  14383. defineMacro("\\nsupseteqq", "\\html@mathml{\\@nsupseteqq}{\u2289}");
  14384. defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
  14385. defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
  14386. defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
  14387. defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
  14388. defineMacro("\\imath", "\\html@mathml{\\@imath}{\u0131}");
  14389. defineMacro("\\jmath", "\\html@mathml{\\@jmath}{\u0237}");
  14390. //////////////////////////////////////////////////////////////////////
  14391. // stmaryrd and semantic
  14392. // The stmaryrd and semantic packages render the next four items by calling a
  14393. // glyph. Those glyphs do not exist in the KaTeX fonts. Hence the macros.
  14394. defineMacro("\\llbracket", "\\html@mathml{" + "\\mathopen{[\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u27e6}}");
  14395. defineMacro("\\rrbracket", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu]}}" + "{\\mathclose{\\char`\u27e7}}");
  14396. defineMacro("\u27e6", "\\llbracket"); // blackboard bold [
  14397. defineMacro("\u27e7", "\\rrbracket"); // blackboard bold ]
  14398. defineMacro("\\lBrace", "\\html@mathml{" + "\\mathopen{\\{\\mkern-3.2mu[}}" + "{\\mathopen{\\char`\u2983}}");
  14399. defineMacro("\\rBrace", "\\html@mathml{" + "\\mathclose{]\\mkern-3.2mu\\}}}" + "{\\mathclose{\\char`\u2984}}");
  14400. defineMacro("\u2983", "\\lBrace"); // blackboard bold {
  14401. defineMacro("\u2984", "\\rBrace"); // blackboard bold }
  14402. // TODO: Create variable sized versions of the last two items. I believe that
  14403. // will require new font glyphs.
  14404. // The stmaryrd function `\minuso` provides a "Plimsoll" symbol that
  14405. // superimposes the characters \circ and \mathminus. Used in chemistry.
  14406. defineMacro("\\minuso", "\\mathbin{\\html@mathml{" + "{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}" + "{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}" + "{\\char`⦵}}");
  14407. defineMacro("⦵", "\\minuso");
  14408. //////////////////////////////////////////////////////////////////////
  14409. // texvc.sty
  14410. // The texvc package contains macros available in mediawiki pages.
  14411. // We omit the functions deprecated at
  14412. // https://en.wikipedia.org/wiki/Help:Displaying_a_formula#Deprecated_syntax
  14413. // We also omit texvc's \O, which conflicts with \text{\O}
  14414. defineMacro("\\darr", "\\downarrow");
  14415. defineMacro("\\dArr", "\\Downarrow");
  14416. defineMacro("\\Darr", "\\Downarrow");
  14417. defineMacro("\\lang", "\\langle");
  14418. defineMacro("\\rang", "\\rangle");
  14419. defineMacro("\\uarr", "\\uparrow");
  14420. defineMacro("\\uArr", "\\Uparrow");
  14421. defineMacro("\\Uarr", "\\Uparrow");
  14422. defineMacro("\\N", "\\mathbb{N}");
  14423. defineMacro("\\R", "\\mathbb{R}");
  14424. defineMacro("\\Z", "\\mathbb{Z}");
  14425. defineMacro("\\alef", "\\aleph");
  14426. defineMacro("\\alefsym", "\\aleph");
  14427. defineMacro("\\Alpha", "\\mathrm{A}");
  14428. defineMacro("\\Beta", "\\mathrm{B}");
  14429. defineMacro("\\bull", "\\bullet");
  14430. defineMacro("\\Chi", "\\mathrm{X}");
  14431. defineMacro("\\clubs", "\\clubsuit");
  14432. defineMacro("\\cnums", "\\mathbb{C}");
  14433. defineMacro("\\Complex", "\\mathbb{C}");
  14434. defineMacro("\\Dagger", "\\ddagger");
  14435. defineMacro("\\diamonds", "\\diamondsuit");
  14436. defineMacro("\\empty", "\\emptyset");
  14437. defineMacro("\\Epsilon", "\\mathrm{E}");
  14438. defineMacro("\\Eta", "\\mathrm{H}");
  14439. defineMacro("\\exist", "\\exists");
  14440. defineMacro("\\harr", "\\leftrightarrow");
  14441. defineMacro("\\hArr", "\\Leftrightarrow");
  14442. defineMacro("\\Harr", "\\Leftrightarrow");
  14443. defineMacro("\\hearts", "\\heartsuit");
  14444. defineMacro("\\image", "\\Im");
  14445. defineMacro("\\infin", "\\infty");
  14446. defineMacro("\\Iota", "\\mathrm{I}");
  14447. defineMacro("\\isin", "\\in");
  14448. defineMacro("\\Kappa", "\\mathrm{K}");
  14449. defineMacro("\\larr", "\\leftarrow");
  14450. defineMacro("\\lArr", "\\Leftarrow");
  14451. defineMacro("\\Larr", "\\Leftarrow");
  14452. defineMacro("\\lrarr", "\\leftrightarrow");
  14453. defineMacro("\\lrArr", "\\Leftrightarrow");
  14454. defineMacro("\\Lrarr", "\\Leftrightarrow");
  14455. defineMacro("\\Mu", "\\mathrm{M}");
  14456. defineMacro("\\natnums", "\\mathbb{N}");
  14457. defineMacro("\\Nu", "\\mathrm{N}");
  14458. defineMacro("\\Omicron", "\\mathrm{O}");
  14459. defineMacro("\\plusmn", "\\pm");
  14460. defineMacro("\\rarr", "\\rightarrow");
  14461. defineMacro("\\rArr", "\\Rightarrow");
  14462. defineMacro("\\Rarr", "\\Rightarrow");
  14463. defineMacro("\\real", "\\Re");
  14464. defineMacro("\\reals", "\\mathbb{R}");
  14465. defineMacro("\\Reals", "\\mathbb{R}");
  14466. defineMacro("\\Rho", "\\mathrm{P}");
  14467. defineMacro("\\sdot", "\\cdot");
  14468. defineMacro("\\sect", "\\S");
  14469. defineMacro("\\spades", "\\spadesuit");
  14470. defineMacro("\\sub", "\\subset");
  14471. defineMacro("\\sube", "\\subseteq");
  14472. defineMacro("\\supe", "\\supseteq");
  14473. defineMacro("\\Tau", "\\mathrm{T}");
  14474. defineMacro("\\thetasym", "\\vartheta");
  14475. // TODO: defineMacro("\\varcoppa", "\\\mbox{\\coppa}");
  14476. defineMacro("\\weierp", "\\wp");
  14477. defineMacro("\\Zeta", "\\mathrm{Z}");
  14478. //////////////////////////////////////////////////////////////////////
  14479. // statmath.sty
  14480. // https://ctan.math.illinois.edu/macros/latex/contrib/statmath/statmath.pdf
  14481. defineMacro("\\argmin", "\\DOTSB\\operatorname*{arg\\,min}");
  14482. defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
  14483. defineMacro("\\plim", "\\DOTSB\\mathop{\\operatorname{plim}}\\limits");
  14484. //////////////////////////////////////////////////////////////////////
  14485. // braket.sty
  14486. // http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
  14487. defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
  14488. defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
  14489. defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
  14490. defineMacro("\\Bra", "\\left\\langle#1\\right|");
  14491. defineMacro("\\Ket", "\\left|#1\\right\\rangle");
  14492. const braketHelper = one => context => {
  14493. const left = context.consumeArg().tokens;
  14494. const middle = context.consumeArg().tokens;
  14495. const middleDouble = context.consumeArg().tokens;
  14496. const right = context.consumeArg().tokens;
  14497. const oldMiddle = context.macros.get("|");
  14498. const oldMiddleDouble = context.macros.get("\\|");
  14499. context.macros.beginGroup();
  14500. const midMacro = double => context => {
  14501. if (one) {
  14502. // Only modify the first instance of | or \|
  14503. context.macros.set("|", oldMiddle);
  14504. if (middleDouble.length) {
  14505. context.macros.set("\\|", oldMiddleDouble);
  14506. }
  14507. }
  14508. let doubled = double;
  14509. if (!double && middleDouble.length) {
  14510. // Mimic \@ifnextchar
  14511. const nextToken = context.future();
  14512. if (nextToken.text === "|") {
  14513. context.popToken();
  14514. doubled = true;
  14515. }
  14516. }
  14517. return {
  14518. tokens: doubled ? middleDouble : middle,
  14519. numArgs: 0
  14520. };
  14521. };
  14522. context.macros.set("|", midMacro(false));
  14523. if (middleDouble.length) {
  14524. context.macros.set("\\|", midMacro(true));
  14525. }
  14526. const arg = context.consumeArg().tokens;
  14527. const expanded = context.expandTokens([...right, ...arg, ...left // reversed
  14528. ]);
  14529. context.macros.endGroup();
  14530. return {
  14531. tokens: expanded.reverse(),
  14532. numArgs: 0
  14533. };
  14534. };
  14535. defineMacro("\\bra@ket", braketHelper(false));
  14536. defineMacro("\\bra@set", braketHelper(true));
  14537. defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" + "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
  14538. defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" + "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
  14539. defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}");
  14540. // has no support for special || or \|
  14541. //////////////////////////////////////////////////////////////////////
  14542. // actuarialangle.dtx
  14543. defineMacro("\\angln", "{\\angl n}");
  14544. // Custom Khan Academy colors, should be moved to an optional package
  14545. defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
  14546. defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
  14547. defineMacro("\\pink", "\\textcolor{##ff00af}{#1}");
  14548. defineMacro("\\red", "\\textcolor{##df0030}{#1}");
  14549. defineMacro("\\green", "\\textcolor{##28ae7b}{#1}");
  14550. defineMacro("\\gray", "\\textcolor{gray}{#1}");
  14551. defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}");
  14552. defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}");
  14553. defineMacro("\\blueB", "\\textcolor{##80f6ff}{#1}");
  14554. defineMacro("\\blueC", "\\textcolor{##63d9ea}{#1}");
  14555. defineMacro("\\blueD", "\\textcolor{##11accd}{#1}");
  14556. defineMacro("\\blueE", "\\textcolor{##0c7f99}{#1}");
  14557. defineMacro("\\tealA", "\\textcolor{##94fff5}{#1}");
  14558. defineMacro("\\tealB", "\\textcolor{##26edd5}{#1}");
  14559. defineMacro("\\tealC", "\\textcolor{##01d1c1}{#1}");
  14560. defineMacro("\\tealD", "\\textcolor{##01a995}{#1}");
  14561. defineMacro("\\tealE", "\\textcolor{##208170}{#1}");
  14562. defineMacro("\\greenA", "\\textcolor{##b6ffb0}{#1}");
  14563. defineMacro("\\greenB", "\\textcolor{##8af281}{#1}");
  14564. defineMacro("\\greenC", "\\textcolor{##74cf70}{#1}");
  14565. defineMacro("\\greenD", "\\textcolor{##1fab54}{#1}");
  14566. defineMacro("\\greenE", "\\textcolor{##0d923f}{#1}");
  14567. defineMacro("\\goldA", "\\textcolor{##ffd0a9}{#1}");
  14568. defineMacro("\\goldB", "\\textcolor{##ffbb71}{#1}");
  14569. defineMacro("\\goldC", "\\textcolor{##ff9c39}{#1}");
  14570. defineMacro("\\goldD", "\\textcolor{##e07d10}{#1}");
  14571. defineMacro("\\goldE", "\\textcolor{##a75a05}{#1}");
  14572. defineMacro("\\redA", "\\textcolor{##fca9a9}{#1}");
  14573. defineMacro("\\redB", "\\textcolor{##ff8482}{#1}");
  14574. defineMacro("\\redC", "\\textcolor{##f9685d}{#1}");
  14575. defineMacro("\\redD", "\\textcolor{##e84d39}{#1}");
  14576. defineMacro("\\redE", "\\textcolor{##bc2612}{#1}");
  14577. defineMacro("\\maroonA", "\\textcolor{##ffbde0}{#1}");
  14578. defineMacro("\\maroonB", "\\textcolor{##ff92c6}{#1}");
  14579. defineMacro("\\maroonC", "\\textcolor{##ed5fa6}{#1}");
  14580. defineMacro("\\maroonD", "\\textcolor{##ca337c}{#1}");
  14581. defineMacro("\\maroonE", "\\textcolor{##9e034e}{#1}");
  14582. defineMacro("\\purpleA", "\\textcolor{##ddd7ff}{#1}");
  14583. defineMacro("\\purpleB", "\\textcolor{##c6b9fc}{#1}");
  14584. defineMacro("\\purpleC", "\\textcolor{##aa87ff}{#1}");
  14585. defineMacro("\\purpleD", "\\textcolor{##7854ab}{#1}");
  14586. defineMacro("\\purpleE", "\\textcolor{##543b78}{#1}");
  14587. defineMacro("\\mintA", "\\textcolor{##f5f9e8}{#1}");
  14588. defineMacro("\\mintB", "\\textcolor{##edf2df}{#1}");
  14589. defineMacro("\\mintC", "\\textcolor{##e0e5cc}{#1}");
  14590. defineMacro("\\grayA", "\\textcolor{##f6f7f7}{#1}");
  14591. defineMacro("\\grayB", "\\textcolor{##f0f1f2}{#1}");
  14592. defineMacro("\\grayC", "\\textcolor{##e3e5e6}{#1}");
  14593. defineMacro("\\grayD", "\\textcolor{##d6d8da}{#1}");
  14594. defineMacro("\\grayE", "\\textcolor{##babec2}{#1}");
  14595. defineMacro("\\grayF", "\\textcolor{##888d93}{#1}");
  14596. defineMacro("\\grayG", "\\textcolor{##626569}{#1}");
  14597. defineMacro("\\grayH", "\\textcolor{##3b3e40}{#1}");
  14598. defineMacro("\\grayI", "\\textcolor{##21242c}{#1}");
  14599. defineMacro("\\kaBlue", "\\textcolor{##314453}{#1}");
  14600. defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
  14601. ;// ./src/MacroExpander.ts
  14602. /**
  14603. * This file contains the “gullet” where macros are expanded
  14604. * until only non-macro tokens remain.
  14605. */
  14606. // List of commands that act like macros but aren't defined as a macro,
  14607. // function, or symbol. Used in `isDefined`.
  14608. const implicitCommands = {
  14609. "^": true,
  14610. // Parser.js
  14611. "_": true,
  14612. // Parser.js
  14613. "\\limits": true,
  14614. // Parser.js
  14615. "\\nolimits": true // Parser.js
  14616. };
  14617. class MacroExpander {
  14618. constructor(input, settings, mode) {
  14619. this.settings = settings;
  14620. this.expansionCount = 0;
  14621. this.feed(input);
  14622. // Make new global namespace
  14623. this.macros = new Namespace(src_macros, settings.macros);
  14624. this.mode = mode;
  14625. this.stack = []; // contains tokens in REVERSE order
  14626. }
  14627. /**
  14628. * Feed a new input string to the same MacroExpander
  14629. * (with existing macros etc.).
  14630. */
  14631. feed(input) {
  14632. this.lexer = new Lexer(input, this.settings);
  14633. }
  14634. /**
  14635. * Switches between "text" and "math" modes.
  14636. */
  14637. switchMode(newMode) {
  14638. this.mode = newMode;
  14639. }
  14640. /**
  14641. * Start a new group nesting within all namespaces.
  14642. */
  14643. beginGroup() {
  14644. this.macros.beginGroup();
  14645. }
  14646. /**
  14647. * End current group nesting within all namespaces.
  14648. */
  14649. endGroup() {
  14650. this.macros.endGroup();
  14651. }
  14652. /**
  14653. * Ends all currently nested groups (if any), restoring values before the
  14654. * groups began. Useful in case of an error in the middle of parsing.
  14655. */
  14656. endGroups() {
  14657. this.macros.endGroups();
  14658. }
  14659. /**
  14660. * Returns the topmost token on the stack, without expanding it.
  14661. * Similar in behavior to TeX's `\futurelet`.
  14662. */
  14663. future() {
  14664. if (this.stack.length === 0) {
  14665. this.pushToken(this.lexer.lex());
  14666. }
  14667. return this.stack[this.stack.length - 1];
  14668. }
  14669. /**
  14670. * Remove and return the next unexpanded token.
  14671. */
  14672. popToken() {
  14673. this.future(); // ensure non-empty stack
  14674. return this.stack.pop();
  14675. }
  14676. /**
  14677. * Add a given token to the token stack. In particular, this get be used
  14678. * to put back a token returned from one of the other methods.
  14679. */
  14680. pushToken(token) {
  14681. this.stack.push(token);
  14682. }
  14683. /**
  14684. * Append an array of tokens to the token stack.
  14685. */
  14686. pushTokens(tokens) {
  14687. this.stack.push(...tokens);
  14688. }
  14689. /**
  14690. * Find an macro argument without expanding tokens and append the array of
  14691. * tokens to the token stack. Uses Token as a container for the result.
  14692. */
  14693. scanArgument(isOptional) {
  14694. let start;
  14695. let end;
  14696. let tokens;
  14697. if (isOptional) {
  14698. this.consumeSpaces(); // \@ifnextchar gobbles any space following it
  14699. if (this.future().text !== "[") {
  14700. return null;
  14701. }
  14702. start = this.popToken(); // don't include [ in tokens
  14703. ({
  14704. tokens,
  14705. end
  14706. } = this.consumeArg(["]"]));
  14707. } else {
  14708. ({
  14709. tokens,
  14710. start,
  14711. end
  14712. } = this.consumeArg());
  14713. }
  14714. // indicate the end of an argument
  14715. this.pushToken(new Token("EOF", end.loc));
  14716. this.pushTokens(tokens);
  14717. return new Token("", SourceLocation.range(start, end));
  14718. }
  14719. /**
  14720. * Consume all following space tokens, without expansion.
  14721. */
  14722. consumeSpaces() {
  14723. for (;;) {
  14724. const token = this.future();
  14725. if (token.text === " ") {
  14726. this.stack.pop();
  14727. } else {
  14728. break;
  14729. }
  14730. }
  14731. }
  14732. /**
  14733. * Consume an argument from the token stream, and return the resulting array
  14734. * of tokens and start/end token.
  14735. */
  14736. consumeArg(delims) {
  14737. // The argument for a delimited parameter is the shortest (possibly
  14738. // empty) sequence of tokens with properly nested {...} groups that is
  14739. // followed ... by this particular list of non-parameter tokens.
  14740. // The argument for an undelimited parameter is the next nonblank
  14741. // token, unless that token is ‘{’, when the argument will be the
  14742. // entire {...} group that follows.
  14743. const tokens = [];
  14744. const isDelimited = delims && delims.length > 0;
  14745. if (!isDelimited) {
  14746. // Ignore spaces between arguments. As the TeXbook says:
  14747. // "After you have said ‘\def\row#1#2{...}’, you are allowed to
  14748. // put spaces between the arguments (e.g., ‘\row x n’), because
  14749. // TeX doesn’t use single spaces as undelimited arguments."
  14750. this.consumeSpaces();
  14751. }
  14752. const start = this.future();
  14753. let tok;
  14754. let depth = 0;
  14755. let match = 0;
  14756. do {
  14757. tok = this.popToken();
  14758. tokens.push(tok);
  14759. if (tok.text === "{") {
  14760. ++depth;
  14761. } else if (tok.text === "}") {
  14762. --depth;
  14763. if (depth === -1) {
  14764. throw new src_ParseError("Extra }", tok);
  14765. }
  14766. } else if (tok.text === "EOF") {
  14767. throw new src_ParseError("Unexpected end of input in a macro argument" + ", expected '" + (delims && isDelimited ? delims[match] : "}") + "'", tok);
  14768. }
  14769. if (delims && isDelimited) {
  14770. if ((depth === 0 || depth === 1 && delims[match] === "{") && tok.text === delims[match]) {
  14771. ++match;
  14772. if (match === delims.length) {
  14773. // don't include delims in tokens
  14774. tokens.splice(-match, match);
  14775. break;
  14776. }
  14777. } else {
  14778. match = 0;
  14779. }
  14780. }
  14781. } while (depth !== 0 || isDelimited);
  14782. // If the argument found ... has the form ‘{<nested tokens>}’,
  14783. // ... the outermost braces enclosing the argument are removed
  14784. if (start.text === "{" && tokens[tokens.length - 1].text === "}") {
  14785. tokens.pop();
  14786. tokens.shift();
  14787. }
  14788. tokens.reverse(); // to fit in with stack order
  14789. return {
  14790. tokens,
  14791. start,
  14792. end: tok
  14793. };
  14794. }
  14795. /**
  14796. * Consume the specified number of (delimited) arguments from the token
  14797. * stream and return the resulting array of arguments.
  14798. */
  14799. consumeArgs(numArgs, delimiters) {
  14800. if (delimiters) {
  14801. if (delimiters.length !== numArgs + 1) {
  14802. throw new src_ParseError("The length of delimiters doesn't match the number of args!");
  14803. }
  14804. const delims = delimiters[0];
  14805. for (let i = 0; i < delims.length; i++) {
  14806. const tok = this.popToken();
  14807. if (delims[i] !== tok.text) {
  14808. throw new src_ParseError("Use of the macro doesn't match its definition", tok);
  14809. }
  14810. }
  14811. }
  14812. const args = [];
  14813. for (let i = 0; i < numArgs; i++) {
  14814. args.push(this.consumeArg(delimiters && delimiters[i + 1]).tokens);
  14815. }
  14816. return args;
  14817. }
  14818. /**
  14819. * Increment `expansionCount` by the specified amount.
  14820. * Throw an error if it exceeds `maxExpand`.
  14821. */
  14822. countExpansion(amount) {
  14823. this.expansionCount += amount;
  14824. if (this.expansionCount > this.settings.maxExpand) {
  14825. throw new src_ParseError("Too many expansions: infinite loop or " + "need to increase maxExpand setting");
  14826. }
  14827. }
  14828. /**
  14829. * Expand the next token only once if possible.
  14830. *
  14831. * If the token is expanded, the resulting tokens will be pushed onto
  14832. * the stack in reverse order, and the number of such tokens will be
  14833. * returned. This number might be zero or positive.
  14834. *
  14835. * If not, the return value is `false`, and the next token remains at the
  14836. * top of the stack.
  14837. *
  14838. * In either case, the next token will be on the top of the stack,
  14839. * or the stack will be empty (in case of empty expansion
  14840. * and no other tokens).
  14841. *
  14842. * Used to implement `expandAfterFuture` and `expandNextToken`.
  14843. *
  14844. * If expandableOnly, only expandable tokens are expanded and
  14845. * an undefined control sequence results in an error.
  14846. */
  14847. expandOnce(expandableOnly) {
  14848. const topToken = this.popToken();
  14849. const name = topToken.text;
  14850. const expansion = !topToken.noexpand ? this._getExpansion(name) : null;
  14851. if (expansion == null || expandableOnly && expansion.unexpandable) {
  14852. if (expandableOnly && expansion == null && name[0] === "\\" && !this.isDefined(name)) {
  14853. throw new src_ParseError("Undefined control sequence: " + name);
  14854. }
  14855. this.pushToken(topToken);
  14856. return false;
  14857. }
  14858. this.countExpansion(1);
  14859. let tokens = expansion.tokens;
  14860. const args = this.consumeArgs(expansion.numArgs, expansion.delimiters);
  14861. if (expansion.numArgs) {
  14862. // paste arguments in place of the placeholders
  14863. tokens = tokens.slice(); // make a shallow copy
  14864. for (let i = tokens.length - 1; i >= 0; --i) {
  14865. let tok = tokens[i];
  14866. if (tok.text === "#") {
  14867. if (i === 0) {
  14868. throw new src_ParseError("Incomplete placeholder at end of macro body", tok);
  14869. }
  14870. tok = tokens[--i]; // next token on stack
  14871. if (tok.text === "#") {
  14872. // ## → #
  14873. tokens.splice(i + 1, 1); // drop first #
  14874. } else if (/^[1-9]$/.test(tok.text)) {
  14875. // replace the placeholder with the indicated argument
  14876. tokens.splice(i, 2, ...args[+tok.text - 1]);
  14877. } else {
  14878. throw new src_ParseError("Not a valid argument number", tok);
  14879. }
  14880. }
  14881. }
  14882. }
  14883. // Concatenate expansion onto top of stack.
  14884. this.pushTokens(tokens);
  14885. return tokens.length;
  14886. }
  14887. /**
  14888. * Expand the next token only once (if possible), and return the resulting
  14889. * top token on the stack (without removing anything from the stack).
  14890. * Similar in behavior to TeX's `\expandafter\futurelet`.
  14891. * Equivalent to expandOnce() followed by future().
  14892. */
  14893. expandAfterFuture() {
  14894. this.expandOnce();
  14895. return this.future();
  14896. }
  14897. /**
  14898. * Recursively expand first token, then return first non-expandable token.
  14899. */
  14900. expandNextToken() {
  14901. for (;;) {
  14902. if (this.expandOnce() === false) {
  14903. // fully expanded
  14904. const token = this.stack.pop();
  14905. // the token after \noexpand is interpreted as if its meaning
  14906. // were ‘\relax’
  14907. if (token.treatAsRelax) {
  14908. token.text = "\\relax";
  14909. }
  14910. return token;
  14911. }
  14912. }
  14913. }
  14914. /**
  14915. * Fully expand the given macro name and return the resulting list of
  14916. * tokens, or return `undefined` if no such macro is defined.
  14917. */
  14918. expandMacro(name) {
  14919. return this.macros.has(name) ? this.expandTokens([new Token(name)]) : undefined;
  14920. }
  14921. /**
  14922. * Fully expand the given token stream and return the resulting list of
  14923. * tokens. Note that the input tokens are in reverse order, but the
  14924. * output tokens are in forward order.
  14925. */
  14926. expandTokens(tokens) {
  14927. const output = [];
  14928. const oldStackLength = this.stack.length;
  14929. this.pushTokens(tokens);
  14930. while (this.stack.length > oldStackLength) {
  14931. // Expand only expandable tokens
  14932. if (this.expandOnce(true) === false) {
  14933. // fully expanded
  14934. const token = this.stack.pop();
  14935. if (token.treatAsRelax) {
  14936. // the expansion of \noexpand is the token itself
  14937. token.noexpand = false;
  14938. token.treatAsRelax = false;
  14939. }
  14940. output.push(token);
  14941. }
  14942. }
  14943. // Count all of these tokens as additional expansions, to prevent
  14944. // exponential blowup from linearly many \edef's.
  14945. this.countExpansion(output.length);
  14946. return output;
  14947. }
  14948. /**
  14949. * Fully expand the given macro name and return the result as a string,
  14950. * or return `undefined` if no such macro is defined.
  14951. */
  14952. expandMacroAsText(name) {
  14953. const tokens = this.expandMacro(name);
  14954. if (tokens) {
  14955. return tokens.map(token => token.text).join("");
  14956. } else {
  14957. return tokens;
  14958. }
  14959. }
  14960. /**
  14961. * Returns the expanded macro as a reversed array of tokens and a macro
  14962. * argument count. Or returns `null` if no such macro.
  14963. */
  14964. _getExpansion(name) {
  14965. const definition = this.macros.get(name);
  14966. if (definition == null) {
  14967. // mainly checking for undefined here
  14968. return definition;
  14969. }
  14970. // If a single character has an associated catcode other than 13
  14971. // (active character), then don't expand it.
  14972. if (name.length === 1) {
  14973. const catcode = this.lexer.catcodes[name];
  14974. if (catcode != null && catcode !== 13) {
  14975. return;
  14976. }
  14977. }
  14978. const expansion = typeof definition === "function" ? definition(this) : definition;
  14979. if (typeof expansion === "string") {
  14980. let numArgs = 0;
  14981. if (expansion.includes("#")) {
  14982. const stripped = expansion.replace(/##/g, "");
  14983. while (stripped.includes("#" + (numArgs + 1))) {
  14984. ++numArgs;
  14985. }
  14986. }
  14987. const bodyLexer = new Lexer(expansion, this.settings);
  14988. const tokens = [];
  14989. let tok = bodyLexer.lex();
  14990. while (tok.text !== "EOF") {
  14991. tokens.push(tok);
  14992. tok = bodyLexer.lex();
  14993. }
  14994. tokens.reverse(); // to fit in with stack using push and pop
  14995. const expanded = {
  14996. tokens,
  14997. numArgs
  14998. };
  14999. return expanded;
  15000. }
  15001. return expansion;
  15002. }
  15003. /**
  15004. * Determine whether a command is currently "defined" (has some
  15005. * functionality), meaning that it's a macro (in the current group),
  15006. * a function, a symbol, or one of the special commands listed in
  15007. * `implicitCommands`.
  15008. */
  15009. isDefined(name) {
  15010. return this.macros.has(name) || src_functions.hasOwnProperty(name) || src_symbols.math.hasOwnProperty(name) || src_symbols.text.hasOwnProperty(name) || implicitCommands.hasOwnProperty(name);
  15011. }
  15012. /**
  15013. * Determine whether a command is expandable.
  15014. */
  15015. isExpandable(name) {
  15016. const macro = this.macros.get(name);
  15017. return macro != null ? typeof macro === "string" || typeof macro === "function" || !macro.unexpandable : src_functions.hasOwnProperty(name) && !src_functions[name].primitive;
  15018. }
  15019. }
  15020. ;// ./src/unicodeSupOrSub.ts
  15021. // Helpers for Parser.js handling of Unicode (sub|super)script characters.
  15022. const unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
  15023. const uSubsAndSups = Object.freeze({
  15024. '₊': '+',
  15025. '₋': '-',
  15026. '₌': '=',
  15027. '₍': '(',
  15028. '₎': ')',
  15029. '₀': '0',
  15030. '₁': '1',
  15031. '₂': '2',
  15032. '₃': '3',
  15033. '₄': '4',
  15034. '₅': '5',
  15035. '₆': '6',
  15036. '₇': '7',
  15037. '₈': '8',
  15038. '₉': '9',
  15039. '\u2090': 'a',
  15040. '\u2091': 'e',
  15041. '\u2095': 'h',
  15042. '\u1D62': 'i',
  15043. '\u2C7C': 'j',
  15044. '\u2096': 'k',
  15045. '\u2097': 'l',
  15046. '\u2098': 'm',
  15047. '\u2099': 'n',
  15048. '\u2092': 'o',
  15049. '\u209A': 'p',
  15050. '\u1D63': 'r',
  15051. '\u209B': 's',
  15052. '\u209C': 't',
  15053. '\u1D64': 'u',
  15054. '\u1D65': 'v',
  15055. '\u2093': 'x',
  15056. '\u1D66': 'β',
  15057. '\u1D67': 'γ',
  15058. '\u1D68': 'ρ',
  15059. '\u1D69': '\u03d5',
  15060. '\u1D6A': 'χ',
  15061. '⁺': '+',
  15062. '⁻': '-',
  15063. '⁼': '=',
  15064. '⁽': '(',
  15065. '⁾': ')',
  15066. '⁰': '0',
  15067. '¹': '1',
  15068. '²': '2',
  15069. '³': '3',
  15070. '⁴': '4',
  15071. '⁵': '5',
  15072. '⁶': '6',
  15073. '⁷': '7',
  15074. '⁸': '8',
  15075. '⁹': '9',
  15076. '\u1D2C': 'A',
  15077. '\u1D2E': 'B',
  15078. '\u1D30': 'D',
  15079. '\u1D31': 'E',
  15080. '\u1D33': 'G',
  15081. '\u1D34': 'H',
  15082. '\u1D35': 'I',
  15083. '\u1D36': 'J',
  15084. '\u1D37': 'K',
  15085. '\u1D38': 'L',
  15086. '\u1D39': 'M',
  15087. '\u1D3A': 'N',
  15088. '\u1D3C': 'O',
  15089. '\u1D3E': 'P',
  15090. '\u1D3F': 'R',
  15091. '\u1D40': 'T',
  15092. '\u1D41': 'U',
  15093. '\u2C7D': 'V',
  15094. '\u1D42': 'W',
  15095. '\u1D43': 'a',
  15096. '\u1D47': 'b',
  15097. '\u1D9C': 'c',
  15098. '\u1D48': 'd',
  15099. '\u1D49': 'e',
  15100. '\u1DA0': 'f',
  15101. '\u1D4D': 'g',
  15102. '\u02B0': 'h',
  15103. '\u2071': 'i',
  15104. '\u02B2': 'j',
  15105. '\u1D4F': 'k',
  15106. '\u02E1': 'l',
  15107. '\u1D50': 'm',
  15108. '\u207F': 'n',
  15109. '\u1D52': 'o',
  15110. '\u1D56': 'p',
  15111. '\u02B3': 'r',
  15112. '\u02E2': 's',
  15113. '\u1D57': 't',
  15114. '\u1D58': 'u',
  15115. '\u1D5B': 'v',
  15116. '\u02B7': 'w',
  15117. '\u02E3': 'x',
  15118. '\u02B8': 'y',
  15119. '\u1DBB': 'z',
  15120. '\u1D5D': 'β',
  15121. '\u1D5E': 'γ',
  15122. '\u1D5F': 'δ',
  15123. '\u1D60': '\u03d5',
  15124. '\u1D61': 'χ',
  15125. '\u1DBF': 'θ'
  15126. });
  15127. ;// ./src/Parser.ts
  15128. /* eslint no-constant-condition:0 */
  15129. // Pre-evaluate both modules as unicodeSymbols require String.normalize()
  15130. const unicodeAccents = {
  15131. "́": {
  15132. "text": "\\'",
  15133. "math": "\\acute"
  15134. },
  15135. "̀": {
  15136. "text": "\\`",
  15137. "math": "\\grave"
  15138. },
  15139. "̈": {
  15140. "text": "\\\"",
  15141. "math": "\\ddot"
  15142. },
  15143. "̃": {
  15144. "text": "\\~",
  15145. "math": "\\tilde"
  15146. },
  15147. "̄": {
  15148. "text": "\\=",
  15149. "math": "\\bar"
  15150. },
  15151. "̆": {
  15152. "text": "\\u",
  15153. "math": "\\breve"
  15154. },
  15155. "̌": {
  15156. "text": "\\v",
  15157. "math": "\\check"
  15158. },
  15159. "̂": {
  15160. "text": "\\^",
  15161. "math": "\\hat"
  15162. },
  15163. "̇": {
  15164. "text": "\\.",
  15165. "math": "\\dot"
  15166. },
  15167. "̊": {
  15168. "text": "\\r",
  15169. "math": "\\mathring"
  15170. },
  15171. "̋": {
  15172. "text": "\\H"
  15173. },
  15174. "̧": {
  15175. "text": "\\c"
  15176. }
  15177. };
  15178. const unicodeSymbols = {
  15179. "á": "á",
  15180. "à": "à",
  15181. "ä": "ä",
  15182. "ǟ": "ǟ",
  15183. "ã": "ã",
  15184. "ā": "ā",
  15185. "ă": "ă",
  15186. "ắ": "ắ",
  15187. "ằ": "ằ",
  15188. "ẵ": "ẵ",
  15189. "ǎ": "ǎ",
  15190. "â": "â",
  15191. "ấ": "ấ",
  15192. "ầ": "ầ",
  15193. "ẫ": "ẫ",
  15194. "ȧ": "ȧ",
  15195. "ǡ": "ǡ",
  15196. "å": "å",
  15197. "ǻ": "ǻ",
  15198. "ḃ": "ḃ",
  15199. "ć": "ć",
  15200. "ḉ": "ḉ",
  15201. "č": "č",
  15202. "ĉ": "ĉ",
  15203. "ċ": "ċ",
  15204. "ç": "ç",
  15205. "ď": "ď",
  15206. "ḋ": "ḋ",
  15207. "ḑ": "ḑ",
  15208. "é": "é",
  15209. "è": "è",
  15210. "ë": "ë",
  15211. "ẽ": "ẽ",
  15212. "ē": "ē",
  15213. "ḗ": "ḗ",
  15214. "ḕ": "ḕ",
  15215. "ĕ": "ĕ",
  15216. "ḝ": "ḝ",
  15217. "ě": "ě",
  15218. "ê": "ê",
  15219. "ế": "ế",
  15220. "ề": "ề",
  15221. "ễ": "ễ",
  15222. "ė": "ė",
  15223. "ȩ": "ȩ",
  15224. "ḟ": "ḟ",
  15225. "ǵ": "ǵ",
  15226. "ḡ": "ḡ",
  15227. "ğ": "ğ",
  15228. "ǧ": "ǧ",
  15229. "ĝ": "ĝ",
  15230. "ġ": "ġ",
  15231. "ģ": "ģ",
  15232. "ḧ": "ḧ",
  15233. "ȟ": "ȟ",
  15234. "ĥ": "ĥ",
  15235. "ḣ": "ḣ",
  15236. "ḩ": "ḩ",
  15237. "í": "í",
  15238. "ì": "ì",
  15239. "ï": "ï",
  15240. "ḯ": "ḯ",
  15241. "ĩ": "ĩ",
  15242. "ī": "ī",
  15243. "ĭ": "ĭ",
  15244. "ǐ": "ǐ",
  15245. "î": "î",
  15246. "ǰ": "ǰ",
  15247. "ĵ": "ĵ",
  15248. "ḱ": "ḱ",
  15249. "ǩ": "ǩ",
  15250. "ķ": "ķ",
  15251. "ĺ": "ĺ",
  15252. "ľ": "ľ",
  15253. "ļ": "ļ",
  15254. "ḿ": "ḿ",
  15255. "ṁ": "ṁ",
  15256. "ń": "ń",
  15257. "ǹ": "ǹ",
  15258. "ñ": "ñ",
  15259. "ň": "ň",
  15260. "ṅ": "ṅ",
  15261. "ņ": "ņ",
  15262. "ó": "ó",
  15263. "ò": "ò",
  15264. "ö": "ö",
  15265. "ȫ": "ȫ",
  15266. "õ": "õ",
  15267. "ṍ": "ṍ",
  15268. "ṏ": "ṏ",
  15269. "ȭ": "ȭ",
  15270. "ō": "ō",
  15271. "ṓ": "ṓ",
  15272. "ṑ": "ṑ",
  15273. "ŏ": "ŏ",
  15274. "ǒ": "ǒ",
  15275. "ô": "ô",
  15276. "ố": "ố",
  15277. "ồ": "ồ",
  15278. "ỗ": "ỗ",
  15279. "ȯ": "ȯ",
  15280. "ȱ": "ȱ",
  15281. "ő": "ő",
  15282. "ṕ": "ṕ",
  15283. "ṗ": "ṗ",
  15284. "ŕ": "ŕ",
  15285. "ř": "ř",
  15286. "ṙ": "ṙ",
  15287. "ŗ": "ŗ",
  15288. "ś": "ś",
  15289. "ṥ": "ṥ",
  15290. "š": "š",
  15291. "ṧ": "ṧ",
  15292. "ŝ": "ŝ",
  15293. "ṡ": "ṡ",
  15294. "ş": "ş",
  15295. "ẗ": "ẗ",
  15296. "ť": "ť",
  15297. "ṫ": "ṫ",
  15298. "ţ": "ţ",
  15299. "ú": "ú",
  15300. "ù": "ù",
  15301. "ü": "ü",
  15302. "ǘ": "ǘ",
  15303. "ǜ": "ǜ",
  15304. "ǖ": "ǖ",
  15305. "ǚ": "ǚ",
  15306. "ũ": "ũ",
  15307. "ṹ": "ṹ",
  15308. "ū": "ū",
  15309. "ṻ": "ṻ",
  15310. "ŭ": "ŭ",
  15311. "ǔ": "ǔ",
  15312. "û": "û",
  15313. "ů": "ů",
  15314. "ű": "ű",
  15315. "ṽ": "ṽ",
  15316. "ẃ": "ẃ",
  15317. "ẁ": "ẁ",
  15318. "ẅ": "ẅ",
  15319. "ŵ": "ŵ",
  15320. "ẇ": "ẇ",
  15321. "ẘ": "ẘ",
  15322. "ẍ": "ẍ",
  15323. "ẋ": "ẋ",
  15324. "ý": "ý",
  15325. "ỳ": "ỳ",
  15326. "ÿ": "ÿ",
  15327. "ỹ": "ỹ",
  15328. "ȳ": "ȳ",
  15329. "ŷ": "ŷ",
  15330. "ẏ": "ẏ",
  15331. "ẙ": "ẙ",
  15332. "ź": "ź",
  15333. "ž": "ž",
  15334. "ẑ": "ẑ",
  15335. "ż": "ż",
  15336. "Á": "Á",
  15337. "À": "À",
  15338. "Ä": "Ä",
  15339. "Ǟ": "Ǟ",
  15340. "Ã": "Ã",
  15341. "Ā": "Ā",
  15342. "Ă": "Ă",
  15343. "Ắ": "Ắ",
  15344. "Ằ": "Ằ",
  15345. "Ẵ": "Ẵ",
  15346. "Ǎ": "Ǎ",
  15347. "Â": "Â",
  15348. "Ấ": "Ấ",
  15349. "Ầ": "Ầ",
  15350. "Ẫ": "Ẫ",
  15351. "Ȧ": "Ȧ",
  15352. "Ǡ": "Ǡ",
  15353. "Å": "Å",
  15354. "Ǻ": "Ǻ",
  15355. "Ḃ": "Ḃ",
  15356. "Ć": "Ć",
  15357. "Ḉ": "Ḉ",
  15358. "Č": "Č",
  15359. "Ĉ": "Ĉ",
  15360. "Ċ": "Ċ",
  15361. "Ç": "Ç",
  15362. "Ď": "Ď",
  15363. "Ḋ": "Ḋ",
  15364. "Ḑ": "Ḑ",
  15365. "É": "É",
  15366. "È": "È",
  15367. "Ë": "Ë",
  15368. "Ẽ": "Ẽ",
  15369. "Ē": "Ē",
  15370. "Ḗ": "Ḗ",
  15371. "Ḕ": "Ḕ",
  15372. "Ĕ": "Ĕ",
  15373. "Ḝ": "Ḝ",
  15374. "Ě": "Ě",
  15375. "Ê": "Ê",
  15376. "Ế": "Ế",
  15377. "Ề": "Ề",
  15378. "Ễ": "Ễ",
  15379. "Ė": "Ė",
  15380. "Ȩ": "Ȩ",
  15381. "Ḟ": "Ḟ",
  15382. "Ǵ": "Ǵ",
  15383. "Ḡ": "Ḡ",
  15384. "Ğ": "Ğ",
  15385. "Ǧ": "Ǧ",
  15386. "Ĝ": "Ĝ",
  15387. "Ġ": "Ġ",
  15388. "Ģ": "Ģ",
  15389. "Ḧ": "Ḧ",
  15390. "Ȟ": "Ȟ",
  15391. "Ĥ": "Ĥ",
  15392. "Ḣ": "Ḣ",
  15393. "Ḩ": "Ḩ",
  15394. "Í": "Í",
  15395. "Ì": "Ì",
  15396. "Ï": "Ï",
  15397. "Ḯ": "Ḯ",
  15398. "Ĩ": "Ĩ",
  15399. "Ī": "Ī",
  15400. "Ĭ": "Ĭ",
  15401. "Ǐ": "Ǐ",
  15402. "Î": "Î",
  15403. "İ": "İ",
  15404. "Ĵ": "Ĵ",
  15405. "Ḱ": "Ḱ",
  15406. "Ǩ": "Ǩ",
  15407. "Ķ": "Ķ",
  15408. "Ĺ": "Ĺ",
  15409. "Ľ": "Ľ",
  15410. "Ļ": "Ļ",
  15411. "Ḿ": "Ḿ",
  15412. "Ṁ": "Ṁ",
  15413. "Ń": "Ń",
  15414. "Ǹ": "Ǹ",
  15415. "Ñ": "Ñ",
  15416. "Ň": "Ň",
  15417. "Ṅ": "Ṅ",
  15418. "Ņ": "Ņ",
  15419. "Ó": "Ó",
  15420. "Ò": "Ò",
  15421. "Ö": "Ö",
  15422. "Ȫ": "Ȫ",
  15423. "Õ": "Õ",
  15424. "Ṍ": "Ṍ",
  15425. "Ṏ": "Ṏ",
  15426. "Ȭ": "Ȭ",
  15427. "Ō": "Ō",
  15428. "Ṓ": "Ṓ",
  15429. "Ṑ": "Ṑ",
  15430. "Ŏ": "Ŏ",
  15431. "Ǒ": "Ǒ",
  15432. "Ô": "Ô",
  15433. "Ố": "Ố",
  15434. "Ồ": "Ồ",
  15435. "Ỗ": "Ỗ",
  15436. "Ȯ": "Ȯ",
  15437. "Ȱ": "Ȱ",
  15438. "Ő": "Ő",
  15439. "Ṕ": "Ṕ",
  15440. "Ṗ": "Ṗ",
  15441. "Ŕ": "Ŕ",
  15442. "Ř": "Ř",
  15443. "Ṙ": "Ṙ",
  15444. "Ŗ": "Ŗ",
  15445. "Ś": "Ś",
  15446. "Ṥ": "Ṥ",
  15447. "Š": "Š",
  15448. "Ṧ": "Ṧ",
  15449. "Ŝ": "Ŝ",
  15450. "Ṡ": "Ṡ",
  15451. "Ş": "Ş",
  15452. "Ť": "Ť",
  15453. "Ṫ": "Ṫ",
  15454. "Ţ": "Ţ",
  15455. "Ú": "Ú",
  15456. "Ù": "Ù",
  15457. "Ü": "Ü",
  15458. "Ǘ": "Ǘ",
  15459. "Ǜ": "Ǜ",
  15460. "Ǖ": "Ǖ",
  15461. "Ǚ": "Ǚ",
  15462. "Ũ": "Ũ",
  15463. "Ṹ": "Ṹ",
  15464. "Ū": "Ū",
  15465. "Ṻ": "Ṻ",
  15466. "Ŭ": "Ŭ",
  15467. "Ǔ": "Ǔ",
  15468. "Û": "Û",
  15469. "Ů": "Ů",
  15470. "Ű": "Ű",
  15471. "Ṽ": "Ṽ",
  15472. "Ẃ": "Ẃ",
  15473. "Ẁ": "Ẁ",
  15474. "Ẅ": "Ẅ",
  15475. "Ŵ": "Ŵ",
  15476. "Ẇ": "Ẇ",
  15477. "Ẍ": "Ẍ",
  15478. "Ẋ": "Ẋ",
  15479. "Ý": "Ý",
  15480. "Ỳ": "Ỳ",
  15481. "Ÿ": "Ÿ",
  15482. "Ỹ": "Ỹ",
  15483. "Ȳ": "Ȳ",
  15484. "Ŷ": "Ŷ",
  15485. "Ẏ": "Ẏ",
  15486. "Ź": "Ź",
  15487. "Ž": "Ž",
  15488. "Ẑ": "Ẑ",
  15489. "Ż": "Ż",
  15490. "ά": "ά",
  15491. "ὰ": "ὰ",
  15492. "ᾱ": "ᾱ",
  15493. "ᾰ": "ᾰ",
  15494. "έ": "έ",
  15495. "ὲ": "ὲ",
  15496. "ή": "ή",
  15497. "ὴ": "ὴ",
  15498. "ί": "ί",
  15499. "ὶ": "ὶ",
  15500. "ϊ": "ϊ",
  15501. "ΐ": "ΐ",
  15502. "ῒ": "ῒ",
  15503. "ῑ": "ῑ",
  15504. "ῐ": "ῐ",
  15505. "ό": "ό",
  15506. "ὸ": "ὸ",
  15507. "ύ": "ύ",
  15508. "ὺ": "ὺ",
  15509. "ϋ": "ϋ",
  15510. "ΰ": "ΰ",
  15511. "ῢ": "ῢ",
  15512. "ῡ": "ῡ",
  15513. "ῠ": "ῠ",
  15514. "ώ": "ώ",
  15515. "ὼ": "ὼ",
  15516. "Ύ": "Ύ",
  15517. "Ὺ": "Ὺ",
  15518. "Ϋ": "Ϋ",
  15519. "Ῡ": "Ῡ",
  15520. "Ῠ": "Ῠ",
  15521. "Ώ": "Ώ",
  15522. "Ὼ": "Ὼ"
  15523. };
  15524. /**
  15525. * This file contains the parser used to parse out a TeX expression from the
  15526. * input. Since TeX isn't context-free, standard parsers don't work particularly
  15527. * well.
  15528. *
  15529. * The strategy of this parser is as such:
  15530. *
  15531. * The main functions (the `.parse...` ones) take a position in the current
  15532. * parse string to parse tokens from. The lexer (found in Lexer.js, stored at
  15533. * this.gullet.lexer) also supports pulling out tokens at arbitrary places. When
  15534. * individual tokens are needed at a position, the lexer is called to pull out a
  15535. * token, which is then used.
  15536. *
  15537. * The parser has a property called "mode" indicating the mode that
  15538. * the parser is currently in. Currently it has to be one of "math" or
  15539. * "text", which denotes whether the current environment is a math-y
  15540. * one or a text-y one (e.g. inside \text). Currently, this serves to
  15541. * limit the functions which can be used in text mode.
  15542. *
  15543. * The main functions then return an object which contains the useful data that
  15544. * was parsed at its given point, and a new position at the end of the parsed
  15545. * data. The main functions can call each other and continue the parsing by
  15546. * using the returned position as a new starting point.
  15547. *
  15548. * There are also extra `.handle...` functions, which pull out some reused
  15549. * functionality into self-contained functions.
  15550. *
  15551. * The functions return ParseNodes.
  15552. */
  15553. class Parser {
  15554. constructor(input, settings) {
  15555. // Start in math mode
  15556. this.mode = "math";
  15557. // Create a new macro expander (gullet) and (indirectly via that) also a
  15558. // new lexer (mouth) for this parser (stomach, in the language of TeX)
  15559. this.gullet = new MacroExpander(input, settings, this.mode);
  15560. // Store the settings for use in parsing
  15561. this.settings = settings;
  15562. // Count leftright depth (for \middle errors)
  15563. this.leftrightDepth = 0;
  15564. this.nextToken = null;
  15565. }
  15566. /**
  15567. * Checks a result to make sure it has the right type, and throws an
  15568. * appropriate error otherwise.
  15569. */
  15570. expect(text, consume) {
  15571. if (consume === void 0) {
  15572. consume = true;
  15573. }
  15574. if (this.fetch().text !== text) {
  15575. throw new src_ParseError("Expected '" + text + "', got '" + this.fetch().text + "'", this.fetch());
  15576. }
  15577. if (consume) {
  15578. this.consume();
  15579. }
  15580. }
  15581. /**
  15582. * Discards the current lookahead token, considering it consumed.
  15583. */
  15584. consume() {
  15585. this.nextToken = null;
  15586. }
  15587. /**
  15588. * Return the current lookahead token, or if there isn't one (at the
  15589. * beginning, or if the previous lookahead token was consume()d),
  15590. * fetch the next token as the new lookahead token and return it.
  15591. */
  15592. fetch() {
  15593. if (this.nextToken == null) {
  15594. this.nextToken = this.gullet.expandNextToken();
  15595. }
  15596. return this.nextToken;
  15597. }
  15598. /**
  15599. * Switches between "text" and "math" modes.
  15600. */
  15601. switchMode(newMode) {
  15602. this.mode = newMode;
  15603. this.gullet.switchMode(newMode);
  15604. }
  15605. /**
  15606. * Main parsing function, which parses an entire input.
  15607. */
  15608. parse() {
  15609. if (!this.settings.globalGroup) {
  15610. // Create a group namespace for the math expression.
  15611. // (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
  15612. this.gullet.beginGroup();
  15613. }
  15614. // Use old \color behavior (same as LaTeX's \textcolor) if requested.
  15615. // We do this within the group for the math expression, so it doesn't
  15616. // pollute settings.macros.
  15617. if (this.settings.colorIsTextColor) {
  15618. this.gullet.macros.set("\\color", "\\textcolor");
  15619. }
  15620. try {
  15621. // Try to parse the input
  15622. const parse = this.parseExpression(false);
  15623. // If we succeeded, make sure there's an EOF at the end
  15624. this.expect("EOF");
  15625. // End the group namespace for the expression
  15626. if (!this.settings.globalGroup) {
  15627. this.gullet.endGroup();
  15628. }
  15629. return parse;
  15630. // Close any leftover groups in case of a parse error.
  15631. } finally {
  15632. this.gullet.endGroups();
  15633. }
  15634. }
  15635. /**
  15636. * Fully parse a separate sequence of tokens as a separate job.
  15637. * Tokens should be specified in reverse order, as in a MacroDefinition.
  15638. */
  15639. subparse(tokens) {
  15640. // Save the next token from the current job.
  15641. const oldToken = this.nextToken;
  15642. this.consume();
  15643. // Run the new job, terminating it with an excess '}'
  15644. this.gullet.pushToken(new Token("}"));
  15645. this.gullet.pushTokens(tokens);
  15646. const parse = this.parseExpression(false);
  15647. this.expect("}");
  15648. // Restore the next token from the current job.
  15649. this.nextToken = oldToken;
  15650. return parse;
  15651. }
  15652. /**
  15653. * Parses an "expression", which is a list of atoms.
  15654. *
  15655. * `breakOnInfix`: Should the parsing stop when we hit infix nodes? This
  15656. * happens when functions have higher precedence than infix
  15657. * nodes in implicit parses.
  15658. *
  15659. * `breakOnTokenText`: The text of the token that the expression should end
  15660. * with, or `null` if something else should end the
  15661. * expression.
  15662. */
  15663. parseExpression(breakOnInfix, breakOnTokenText) {
  15664. const body = [];
  15665. // Keep adding atoms to the body until we can't parse any more atoms (either
  15666. // we reached the end, a }, or a \right)
  15667. while (true) {
  15668. // Ignore spaces in math mode
  15669. if (this.mode === "math") {
  15670. this.consumeSpaces();
  15671. }
  15672. const lex = this.fetch();
  15673. if (Parser.endOfExpression.has(lex.text)) {
  15674. break;
  15675. }
  15676. if (breakOnTokenText && lex.text === breakOnTokenText) {
  15677. break;
  15678. }
  15679. if (breakOnInfix && src_functions[lex.text] && src_functions[lex.text].infix) {
  15680. break;
  15681. }
  15682. const atom = this.parseAtom(breakOnTokenText);
  15683. if (!atom) {
  15684. break;
  15685. } else if (atom.type === "internal") {
  15686. // Internal nodes do not appear in parse tree
  15687. continue;
  15688. }
  15689. body.push(atom);
  15690. }
  15691. if (this.mode === "text") {
  15692. this.formLigatures(body);
  15693. }
  15694. return this.handleInfixNodes(body);
  15695. }
  15696. /**
  15697. * Rewrites infix operators such as \over with corresponding commands such
  15698. * as \frac.
  15699. *
  15700. * There can only be one infix operator per group. If there's more than one
  15701. * then the expression is ambiguous. This can be resolved by adding {}.
  15702. */
  15703. handleInfixNodes(body) {
  15704. let overIndex = -1;
  15705. let funcName;
  15706. for (let i = 0; i < body.length; i++) {
  15707. const node = body[i];
  15708. if (node.type === "infix") {
  15709. if (overIndex !== -1) {
  15710. throw new src_ParseError("only one infix operator per group", node.token);
  15711. }
  15712. overIndex = i;
  15713. funcName = node.replaceWith;
  15714. }
  15715. }
  15716. if (overIndex !== -1 && funcName) {
  15717. let numerNode;
  15718. let denomNode;
  15719. const numerBody = body.slice(0, overIndex);
  15720. const denomBody = body.slice(overIndex + 1);
  15721. if (numerBody.length === 1 && numerBody[0].type === "ordgroup") {
  15722. numerNode = numerBody[0];
  15723. } else {
  15724. numerNode = {
  15725. type: "ordgroup",
  15726. mode: this.mode,
  15727. body: numerBody
  15728. };
  15729. }
  15730. if (denomBody.length === 1 && denomBody[0].type === "ordgroup") {
  15731. denomNode = denomBody[0];
  15732. } else {
  15733. denomNode = {
  15734. type: "ordgroup",
  15735. mode: this.mode,
  15736. body: denomBody
  15737. };
  15738. }
  15739. let node;
  15740. if (funcName === "\\\\abovefrac") {
  15741. node = this.callFunction(funcName, [numerNode, body[overIndex], denomNode], []);
  15742. } else {
  15743. node = this.callFunction(funcName, [numerNode, denomNode], []);
  15744. }
  15745. return [node];
  15746. } else {
  15747. return body;
  15748. }
  15749. }
  15750. /**
  15751. * Handle a subscript or superscript with nice errors.
  15752. */
  15753. handleSupSubscript(name // For error reporting.
  15754. ) {
  15755. const symbolToken = this.fetch();
  15756. const symbol = symbolToken.text;
  15757. this.consume();
  15758. this.consumeSpaces(); // ignore spaces before sup/subscript argument
  15759. // Skip over allowed internal nodes such as \relax
  15760. let group;
  15761. do {
  15762. var _group;
  15763. group = this.parseGroup(name);
  15764. } while (((_group = group) == null ? void 0 : _group.type) === "internal");
  15765. if (!group) {
  15766. throw new src_ParseError("Expected group after '" + symbol + "'", symbolToken);
  15767. }
  15768. return group;
  15769. }
  15770. /**
  15771. * Converts the textual input of an unsupported command into a text node
  15772. * contained within a color node whose color is determined by errorColor
  15773. */
  15774. formatUnsupportedCmd(text) {
  15775. const textordArray = [];
  15776. for (let i = 0; i < text.length; i++) {
  15777. textordArray.push({
  15778. type: "textord",
  15779. mode: "text",
  15780. text: text[i]
  15781. });
  15782. }
  15783. const textNode = {
  15784. type: "text",
  15785. mode: this.mode,
  15786. body: textordArray
  15787. };
  15788. const colorNode = {
  15789. type: "color",
  15790. mode: this.mode,
  15791. color: this.settings.errorColor,
  15792. body: [textNode]
  15793. };
  15794. return colorNode;
  15795. }
  15796. /**
  15797. * Parses a group with optional super/subscripts.
  15798. */
  15799. parseAtom(breakOnTokenText) {
  15800. // The body of an atom is an implicit group, so that things like
  15801. // \left(x\right)^2 work correctly.
  15802. const base = this.parseGroup("atom", breakOnTokenText);
  15803. // Internal nodes (e.g. \relax) cannot support super/subscripts.
  15804. // Instead we will pick up super/subscripts with blank base next round.
  15805. if ((base == null ? void 0 : base.type) === "internal") {
  15806. return base;
  15807. }
  15808. // In text mode, we don't have superscripts or subscripts
  15809. if (this.mode === "text") {
  15810. return base;
  15811. }
  15812. // Note that base may be empty (i.e. null) at this point.
  15813. let superscript;
  15814. let subscript;
  15815. while (true) {
  15816. // Guaranteed in math mode, so eat any spaces first.
  15817. this.consumeSpaces();
  15818. // Lex the first token
  15819. const lex = this.fetch();
  15820. if (lex.text === "\\limits" || lex.text === "\\nolimits") {
  15821. // We got a limit control
  15822. if (base && base.type === "op") {
  15823. const limits = lex.text === "\\limits";
  15824. base.limits = limits;
  15825. base.alwaysHandleSupSub = true;
  15826. } else if (base && base.type === "operatorname") {
  15827. if (base.alwaysHandleSupSub) {
  15828. base.limits = lex.text === "\\limits";
  15829. }
  15830. } else {
  15831. throw new src_ParseError("Limit controls must follow a math operator", lex);
  15832. }
  15833. this.consume();
  15834. } else if (lex.text === "^") {
  15835. // We got a superscript start
  15836. if (superscript) {
  15837. throw new src_ParseError("Double superscript", lex);
  15838. }
  15839. superscript = this.handleSupSubscript("superscript");
  15840. } else if (lex.text === "_") {
  15841. // We got a subscript start
  15842. if (subscript) {
  15843. throw new src_ParseError("Double subscript", lex);
  15844. }
  15845. subscript = this.handleSupSubscript("subscript");
  15846. } else if (lex.text === "'") {
  15847. // We got a prime
  15848. if (superscript) {
  15849. throw new src_ParseError("Double superscript", lex);
  15850. }
  15851. const prime = {
  15852. type: "textord",
  15853. mode: this.mode,
  15854. text: "\\prime"
  15855. };
  15856. // Many primes can be grouped together, so we handle this here
  15857. const primes = [prime];
  15858. this.consume();
  15859. // Keep lexing tokens until we get something that's not a prime
  15860. while (this.fetch().text === "'") {
  15861. // For each one, add another prime to the list
  15862. primes.push(prime);
  15863. this.consume();
  15864. }
  15865. // If there's a superscript following the primes, combine that
  15866. // superscript in with the primes.
  15867. if (this.fetch().text === "^") {
  15868. primes.push(this.handleSupSubscript("superscript"));
  15869. }
  15870. // Put everything into an ordgroup as the superscript
  15871. superscript = {
  15872. type: "ordgroup",
  15873. mode: this.mode,
  15874. body: primes
  15875. };
  15876. } else if (uSubsAndSups[lex.text]) {
  15877. // A Unicode subscript or superscript character.
  15878. // We treat these similarly to the unicode-math package.
  15879. // So we render a string of Unicode (sub|super)scripts the
  15880. // same as a (sub|super)script of regular characters.
  15881. const isSub = unicodeSubRegEx.test(lex.text);
  15882. const subsupTokens = [];
  15883. subsupTokens.push(new Token(uSubsAndSups[lex.text]));
  15884. this.consume();
  15885. // Continue fetching tokens to fill out the string.
  15886. while (true) {
  15887. const token = this.fetch().text;
  15888. if (!uSubsAndSups[token]) {
  15889. break;
  15890. }
  15891. if (unicodeSubRegEx.test(token) !== isSub) {
  15892. break;
  15893. }
  15894. subsupTokens.unshift(new Token(uSubsAndSups[token]));
  15895. this.consume();
  15896. }
  15897. // Now create a (sub|super)script.
  15898. const body = this.subparse(subsupTokens);
  15899. if (isSub) {
  15900. subscript = {
  15901. type: "ordgroup",
  15902. mode: "math",
  15903. body
  15904. };
  15905. } else {
  15906. superscript = {
  15907. type: "ordgroup",
  15908. mode: "math",
  15909. body
  15910. };
  15911. }
  15912. } else {
  15913. // If it wasn't ^, _, or ', stop parsing super/subscripts
  15914. break;
  15915. }
  15916. }
  15917. // Base must be set if superscript or subscript are set per logic above,
  15918. // but need to check here for type check to pass.
  15919. if (superscript || subscript) {
  15920. // If we got either a superscript or subscript, create a supsub
  15921. return {
  15922. type: "supsub",
  15923. mode: this.mode,
  15924. base: base,
  15925. sup: superscript,
  15926. sub: subscript
  15927. };
  15928. } else {
  15929. // Otherwise return the original body
  15930. return base;
  15931. }
  15932. }
  15933. /**
  15934. * Parses an entire function, including its base and all of its arguments.
  15935. */
  15936. parseFunction(breakOnTokenText, name // For determining its context
  15937. ) {
  15938. const token = this.fetch();
  15939. const func = token.text;
  15940. const funcData = src_functions[func];
  15941. if (!funcData) {
  15942. return null;
  15943. }
  15944. this.consume(); // consume command token
  15945. if (name && name !== "atom" && !funcData.allowedInArgument) {
  15946. throw new src_ParseError("Got function '" + func + "' with no arguments" + (name ? " as " + name : ""), token);
  15947. } else if (this.mode === "text" && !funcData.allowedInText) {
  15948. throw new src_ParseError("Can't use function '" + func + "' in text mode", token);
  15949. } else if (this.mode === "math" && funcData.allowedInMath === false) {
  15950. throw new src_ParseError("Can't use function '" + func + "' in math mode", token);
  15951. }
  15952. const {
  15953. args,
  15954. optArgs
  15955. } = this.parseArguments(func, funcData);
  15956. return this.callFunction(func, args, optArgs, token, breakOnTokenText);
  15957. }
  15958. /**
  15959. * Call a function handler with a suitable context and arguments.
  15960. */
  15961. callFunction(name, args, optArgs, token, breakOnTokenText) {
  15962. const context = {
  15963. funcName: name,
  15964. parser: this,
  15965. token,
  15966. breakOnTokenText
  15967. };
  15968. const func = src_functions[name];
  15969. if (func && func.handler) {
  15970. return func.handler(context, args, optArgs);
  15971. } else {
  15972. throw new src_ParseError("No function handler for " + name);
  15973. }
  15974. }
  15975. /**
  15976. * Parses the arguments of a function or environment
  15977. */
  15978. parseArguments(func,
  15979. // Should look like "\name" or "\begin{name}".
  15980. funcData) {
  15981. const totalArgs = funcData.numArgs + funcData.numOptionalArgs;
  15982. if (totalArgs === 0) {
  15983. return {
  15984. args: [],
  15985. optArgs: []
  15986. };
  15987. }
  15988. const args = [];
  15989. const optArgs = [];
  15990. for (let i = 0; i < totalArgs; i++) {
  15991. let argType = funcData.argTypes && funcData.argTypes[i];
  15992. const isOptional = i < funcData.numOptionalArgs;
  15993. if ("primitive" in funcData && funcData.primitive && argType == null ||
  15994. // \sqrt expands into primitive if optional argument doesn't exist
  15995. funcData.type === "sqrt" && i === 1 && optArgs[0] == null) {
  15996. argType = "primitive";
  15997. }
  15998. const arg = this.parseGroupOfType("argument to '" + func + "'", argType, isOptional);
  15999. if (isOptional) {
  16000. optArgs.push(arg);
  16001. } else if (arg != null) {
  16002. args.push(arg);
  16003. } else {
  16004. // should be unreachable
  16005. throw new src_ParseError("Null argument, please report this as a bug");
  16006. }
  16007. }
  16008. return {
  16009. args,
  16010. optArgs
  16011. };
  16012. }
  16013. /**
  16014. * Parses a group when the mode is changing.
  16015. */
  16016. parseGroupOfType(name, type, optional) {
  16017. switch (type) {
  16018. case "color":
  16019. return this.parseColorGroup(optional);
  16020. case "size":
  16021. return this.parseSizeGroup(optional);
  16022. case "url":
  16023. return this.parseUrlGroup(optional);
  16024. case "math":
  16025. case "text":
  16026. return this.parseArgumentGroup(optional, type);
  16027. case "hbox":
  16028. {
  16029. // hbox argument type wraps the argument in the equivalent of
  16030. // \hbox, which is like \text but switching to \textstyle size.
  16031. const group = this.parseArgumentGroup(optional, "text");
  16032. return group != null ? {
  16033. type: "styling",
  16034. mode: group.mode,
  16035. body: [group],
  16036. style: "text" // simulate \textstyle
  16037. } : null;
  16038. }
  16039. case "raw":
  16040. {
  16041. const token = this.parseStringGroup("raw", optional);
  16042. return token != null ? {
  16043. type: "raw",
  16044. mode: "text",
  16045. string: token.text
  16046. } : null;
  16047. }
  16048. case "primitive":
  16049. {
  16050. if (optional) {
  16051. throw new src_ParseError("A primitive argument cannot be optional");
  16052. }
  16053. const group = this.parseGroup(name);
  16054. if (group == null) {
  16055. throw new src_ParseError("Expected group as " + name, this.fetch());
  16056. }
  16057. return group;
  16058. }
  16059. case "original":
  16060. case null:
  16061. case undefined:
  16062. return this.parseArgumentGroup(optional);
  16063. default:
  16064. throw new src_ParseError("Unknown group type as " + name, this.fetch());
  16065. }
  16066. }
  16067. /**
  16068. * Discard any space tokens, fetching the next non-space token.
  16069. */
  16070. consumeSpaces() {
  16071. while (this.fetch().text === " ") {
  16072. this.consume();
  16073. }
  16074. }
  16075. /**
  16076. * Parses a group, essentially returning the string formed by the
  16077. * brace-enclosed tokens plus some position information.
  16078. */
  16079. parseStringGroup(modeName,
  16080. // Used to describe the mode in error messages.
  16081. optional) {
  16082. const argToken = this.gullet.scanArgument(optional);
  16083. if (argToken == null) {
  16084. return null;
  16085. }
  16086. let str = "";
  16087. let nextToken;
  16088. while ((nextToken = this.fetch()).text !== "EOF") {
  16089. str += nextToken.text;
  16090. this.consume();
  16091. }
  16092. this.consume(); // consume the end of the argument
  16093. argToken.text = str;
  16094. return argToken;
  16095. }
  16096. /**
  16097. * Parses a regex-delimited group: the largest sequence of tokens
  16098. * whose concatenated strings match `regex`. Returns the string
  16099. * formed by the tokens plus some position information.
  16100. */
  16101. parseRegexGroup(regex, modeName // Used to describe the mode in error messages.
  16102. ) {
  16103. const firstToken = this.fetch();
  16104. let lastToken = firstToken;
  16105. let str = "";
  16106. let nextToken;
  16107. while ((nextToken = this.fetch()).text !== "EOF" && regex.test(str + nextToken.text)) {
  16108. lastToken = nextToken;
  16109. str += lastToken.text;
  16110. this.consume();
  16111. }
  16112. if (str === "") {
  16113. throw new src_ParseError("Invalid " + modeName + ": '" + firstToken.text + "'", firstToken);
  16114. }
  16115. return firstToken.range(lastToken, str);
  16116. }
  16117. /**
  16118. * Parses a color description.
  16119. */
  16120. parseColorGroup(optional) {
  16121. const res = this.parseStringGroup("color", optional);
  16122. if (res == null) {
  16123. return null;
  16124. }
  16125. const match = /^(#[a-f0-9]{3,4}|#[a-f0-9]{6}|#[a-f0-9]{8}|[a-f0-9]{6}|[a-z]+)$/i.exec(res.text);
  16126. if (!match) {
  16127. throw new src_ParseError("Invalid color: '" + res.text + "'", res);
  16128. }
  16129. let color = match[0];
  16130. if (/^[0-9a-f]{6}$/i.test(color)) {
  16131. // We allow a 6-digit HTML color spec without a leading "#".
  16132. // This follows the xcolor package's HTML color model.
  16133. // Predefined color names are all missed by this RegEx pattern.
  16134. color = "#" + color;
  16135. }
  16136. return {
  16137. type: "color-token",
  16138. mode: this.mode,
  16139. color
  16140. };
  16141. }
  16142. /**
  16143. * Parses a size specification, consisting of magnitude and unit.
  16144. */
  16145. parseSizeGroup(optional) {
  16146. let res;
  16147. let isBlank = false;
  16148. // don't expand before parseStringGroup
  16149. this.gullet.consumeSpaces();
  16150. if (!optional && this.gullet.future().text !== "{") {
  16151. res = this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size");
  16152. } else {
  16153. res = this.parseStringGroup("size", optional);
  16154. }
  16155. if (!res) {
  16156. return null;
  16157. }
  16158. if (!optional && res.text.length === 0) {
  16159. // Because we've tested for what is !optional, this block won't
  16160. // affect \kern, \hspace, etc. It will capture the mandatory arguments
  16161. // to \genfrac and \above.
  16162. res.text = "0pt"; // Enable \above{}
  16163. isBlank = true; // This is here specifically for \genfrac
  16164. }
  16165. const match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(res.text);
  16166. if (!match) {
  16167. throw new src_ParseError("Invalid size: '" + res.text + "'", res);
  16168. }
  16169. const data = {
  16170. number: +(match[1] + match[2]),
  16171. // sign + magnitude, cast to number
  16172. unit: match[3]
  16173. };
  16174. if (!validUnit(data)) {
  16175. throw new src_ParseError("Invalid unit: '" + data.unit + "'", res);
  16176. }
  16177. return {
  16178. type: "size",
  16179. mode: this.mode,
  16180. value: data,
  16181. isBlank
  16182. };
  16183. }
  16184. /**
  16185. * Parses an URL, checking escaped letters and allowed protocols,
  16186. * and setting the catcode of % as an active character (as in \hyperref).
  16187. */
  16188. parseUrlGroup(optional) {
  16189. this.gullet.lexer.setCatcode("%", 13); // active character
  16190. this.gullet.lexer.setCatcode("~", 12); // other character
  16191. const res = this.parseStringGroup("url", optional);
  16192. this.gullet.lexer.setCatcode("%", 14); // comment character
  16193. this.gullet.lexer.setCatcode("~", 13); // active character
  16194. if (res == null) {
  16195. return null;
  16196. }
  16197. // hyperref package allows backslashes alone in href, but doesn't
  16198. // generate valid links in such cases; we interpret this as
  16199. // "undefined" behaviour, and keep them as-is. Some browser will
  16200. // replace backslashes with forward slashes.
  16201. const url = res.text.replace(/\\([#$%&~_^{}])/g, '$1');
  16202. return {
  16203. type: "url",
  16204. mode: this.mode,
  16205. url
  16206. };
  16207. }
  16208. /**
  16209. * Parses an argument with the mode specified.
  16210. */
  16211. parseArgumentGroup(optional, mode) {
  16212. const argToken = this.gullet.scanArgument(optional);
  16213. if (argToken == null) {
  16214. return null;
  16215. }
  16216. const outerMode = this.mode;
  16217. if (mode) {
  16218. // Switch to specified mode
  16219. this.switchMode(mode);
  16220. }
  16221. this.gullet.beginGroup();
  16222. const expression = this.parseExpression(false, "EOF");
  16223. // TODO: find an alternative way to denote the end
  16224. this.expect("EOF"); // expect the end of the argument
  16225. this.gullet.endGroup();
  16226. const result = {
  16227. type: "ordgroup",
  16228. mode: this.mode,
  16229. loc: argToken.loc,
  16230. body: expression
  16231. };
  16232. if (mode) {
  16233. // Switch mode back
  16234. this.switchMode(outerMode);
  16235. }
  16236. return result;
  16237. }
  16238. /**
  16239. * Parses an ordinary group, which is either a single nucleus (like "x")
  16240. * or an expression in braces (like "{x+y}") or an implicit group, a group
  16241. * that starts at the current position, and ends right before a higher explicit
  16242. * group ends, or at EOF.
  16243. */
  16244. parseGroup(name,
  16245. // For error reporting.
  16246. breakOnTokenText) {
  16247. const firstToken = this.fetch();
  16248. const text = firstToken.text;
  16249. let result;
  16250. // Try to parse an open brace or \begingroup
  16251. if (text === "{" || text === "\\begingroup") {
  16252. this.consume();
  16253. const groupEnd = text === "{" ? "}" : "\\endgroup";
  16254. this.gullet.beginGroup();
  16255. // If we get a brace, parse an expression
  16256. const expression = this.parseExpression(false, groupEnd);
  16257. const lastToken = this.fetch();
  16258. this.expect(groupEnd); // Check that we got a matching closing brace
  16259. this.gullet.endGroup();
  16260. result = {
  16261. type: "ordgroup",
  16262. mode: this.mode,
  16263. loc: SourceLocation.range(firstToken, lastToken),
  16264. body: expression,
  16265. // A group formed by \begingroup...\endgroup is a semi-simple group
  16266. // which doesn't affect spacing in math mode, i.e., is transparent.
  16267. // https://tex.stackexchange.com/questions/1930/when-should-one-
  16268. // use-begingroup-instead-of-bgroup
  16269. semisimple: text === "\\begingroup" || undefined
  16270. };
  16271. } else {
  16272. // If there exists a function with this name, parse the function.
  16273. // Otherwise, just return a nucleus
  16274. result = this.parseFunction(breakOnTokenText, name) || this.parseSymbol();
  16275. if (result == null && text[0] === "\\" && !implicitCommands.hasOwnProperty(text)) {
  16276. if (this.settings.throwOnError) {
  16277. throw new src_ParseError("Undefined control sequence: " + text, firstToken);
  16278. }
  16279. result = this.formatUnsupportedCmd(text);
  16280. this.consume();
  16281. }
  16282. }
  16283. return result;
  16284. }
  16285. /**
  16286. * Form ligature-like combinations of characters for text mode.
  16287. * This includes inputs like "--", "---", "``" and "''".
  16288. * The result will simply replace multiple textord nodes with a single
  16289. * character in each value by a single textord node having multiple
  16290. * characters in its value. The representation is still ASCII source.
  16291. * The group will be modified in place.
  16292. */
  16293. formLigatures(group) {
  16294. let n = group.length - 1;
  16295. for (let i = 0; i < n; ++i) {
  16296. const a = group[i];
  16297. if (a.type !== "textord") {
  16298. continue;
  16299. }
  16300. const v = a.text;
  16301. const next = group[i + 1];
  16302. if (!next || next.type !== "textord") {
  16303. continue;
  16304. }
  16305. if (v === "-" && next.text === "-") {
  16306. const afterNext = group[i + 2];
  16307. if (i + 1 < n && afterNext && afterNext.type === "textord" && afterNext.text === "-") {
  16308. group.splice(i, 3, {
  16309. type: "textord",
  16310. mode: "text",
  16311. loc: SourceLocation.range(a, afterNext),
  16312. text: "---"
  16313. });
  16314. n -= 2;
  16315. } else {
  16316. group.splice(i, 2, {
  16317. type: "textord",
  16318. mode: "text",
  16319. loc: SourceLocation.range(a, next),
  16320. text: "--"
  16321. });
  16322. n -= 1;
  16323. }
  16324. }
  16325. if ((v === "'" || v === "`") && next.text === v) {
  16326. group.splice(i, 2, {
  16327. type: "textord",
  16328. mode: "text",
  16329. loc: SourceLocation.range(a, next),
  16330. text: v + v
  16331. });
  16332. n -= 1;
  16333. }
  16334. }
  16335. }
  16336. /**
  16337. * Parse a single symbol out of the string. Here, we handle single character
  16338. * symbols and special functions like \verb.
  16339. */
  16340. parseSymbol() {
  16341. const nucleus = this.fetch();
  16342. let text = nucleus.text;
  16343. if (/^\\verb[^a-zA-Z]/.test(text)) {
  16344. this.consume();
  16345. let arg = text.slice(5);
  16346. const star = arg.charAt(0) === "*";
  16347. if (star) {
  16348. arg = arg.slice(1);
  16349. }
  16350. // Lexer's tokenRegex is constructed to always have matching
  16351. // first/last characters.
  16352. if (arg.length < 2 || arg.charAt(0) !== arg.slice(-1)) {
  16353. throw new src_ParseError("\\verb assertion failed --\n please report what input caused this bug");
  16354. }
  16355. arg = arg.slice(1, -1); // remove first and last char
  16356. return {
  16357. type: "verb",
  16358. mode: "text",
  16359. body: arg,
  16360. star
  16361. };
  16362. }
  16363. // At this point, we should have a symbol, possibly with accents.
  16364. // First expand any accented base symbol according to unicodeSymbols.
  16365. if (unicodeSymbols.hasOwnProperty(text[0]) && !src_symbols[this.mode][text[0]]) {
  16366. // This behavior is not strict (XeTeX-compatible) in math mode.
  16367. if (this.settings.strict && this.mode === "math") {
  16368. this.settings.reportNonstrict("unicodeTextInMathMode", "Accented Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
  16369. }
  16370. text = unicodeSymbols[text[0]] + text.slice(1);
  16371. }
  16372. // Strip off any combining characters
  16373. const match = combiningDiacriticalMarksEndRegex.exec(text);
  16374. if (match) {
  16375. text = text.substring(0, match.index);
  16376. if (text === 'i') {
  16377. text = '\u0131'; // dotless i, in math and text mode
  16378. } else if (text === 'j') {
  16379. text = '\u0237'; // dotless j, in math and text mode
  16380. }
  16381. }
  16382. // Recognize base symbol
  16383. let symbol;
  16384. if (src_symbols[this.mode][text]) {
  16385. if (this.settings.strict && this.mode === 'math' && extraLatin.includes(text)) {
  16386. this.settings.reportNonstrict("unicodeTextInMathMode", "Latin-1/Unicode text character \"" + text[0] + "\" used in " + "math mode", nucleus);
  16387. }
  16388. const group = src_symbols[this.mode][text].group;
  16389. const loc = SourceLocation.range(nucleus);
  16390. let s;
  16391. if (ATOMS.hasOwnProperty(group)) {
  16392. // TODO(ts)
  16393. const family = group;
  16394. s = {
  16395. type: "atom",
  16396. mode: this.mode,
  16397. family,
  16398. loc,
  16399. text
  16400. };
  16401. } else {
  16402. // TODO(ts)
  16403. s = {
  16404. type: group,
  16405. mode: this.mode,
  16406. loc,
  16407. text
  16408. };
  16409. }
  16410. // TODO(ts)
  16411. symbol = s;
  16412. } else if (text.charCodeAt(0) >= 0x80) {
  16413. // no symbol for e.g. ^
  16414. if (this.settings.strict) {
  16415. if (!supportedCodepoint(text.charCodeAt(0))) {
  16416. this.settings.reportNonstrict("unknownSymbol", "Unrecognized Unicode character \"" + text[0] + "\"" + (" (" + text.charCodeAt(0) + ")"), nucleus);
  16417. } else if (this.mode === "math") {
  16418. this.settings.reportNonstrict("unicodeTextInMathMode", "Unicode text character \"" + text[0] + "\" used in math mode", nucleus);
  16419. }
  16420. }
  16421. // All nonmathematical Unicode characters are rendered as if they
  16422. // are in text mode (wrapped in \text) because that's what it
  16423. // takes to render them in LaTeX. Setting `mode: this.mode` is
  16424. // another natural choice (the user requested math mode), but
  16425. // this makes it more difficult for getCharacterMetrics() to
  16426. // distinguish Unicode characters without metrics and those for
  16427. // which we want to simulate the letter M.
  16428. symbol = {
  16429. type: "textord",
  16430. mode: "text",
  16431. loc: SourceLocation.range(nucleus),
  16432. text
  16433. };
  16434. } else {
  16435. return null; // EOF, ^, _, {, }, etc.
  16436. }
  16437. this.consume();
  16438. // Transform combining characters into accents
  16439. if (match) {
  16440. for (let i = 0; i < match[0].length; i++) {
  16441. const accent = match[0][i];
  16442. if (!unicodeAccents[accent]) {
  16443. throw new src_ParseError("Unknown accent ' " + accent + "'", nucleus);
  16444. }
  16445. const command = unicodeAccents[accent][this.mode] || unicodeAccents[accent].text;
  16446. if (!command) {
  16447. throw new src_ParseError("Accent " + accent + " unsupported in " + this.mode + " mode", nucleus);
  16448. }
  16449. symbol = {
  16450. type: "accent",
  16451. mode: this.mode,
  16452. loc: SourceLocation.range(nucleus),
  16453. label: command,
  16454. isStretchy: false,
  16455. isShifty: true,
  16456. // TODO(ts)
  16457. base: symbol
  16458. };
  16459. }
  16460. }
  16461. // TODO(ts)
  16462. return symbol;
  16463. }
  16464. }
  16465. Parser.endOfExpression = new Set(["}", "\\endgroup", "\\end", "\\right", "&"]);
  16466. ;// ./src/parseTree.ts
  16467. /**
  16468. * Provides a single function for parsing an expression using a Parser
  16469. * TODO(emily): Remove this
  16470. */
  16471. /**
  16472. * Parses an expression using a Parser, then returns the parsed result.
  16473. */
  16474. const parseTree = function (toParse, settings) {
  16475. if (!(typeof toParse === 'string' || toParse instanceof String)) {
  16476. throw new TypeError('KaTeX can only parse string typed expression');
  16477. }
  16478. const parser = new Parser(toParse, settings);
  16479. // Blank out any \df@tag to avoid spurious "Duplicate \tag" errors
  16480. delete parser.gullet.macros.current["\\df@tag"];
  16481. let tree = parser.parse();
  16482. // Prevent a color definition from persisting between calls to katex.render().
  16483. delete parser.gullet.macros.current["\\current@color"];
  16484. delete parser.gullet.macros.current["\\color"];
  16485. // If the input used \tag, it will set the \df@tag macro to the tag.
  16486. // In this case, we separately parse the tag and wrap the tree.
  16487. if (parser.gullet.macros.get("\\df@tag")) {
  16488. if (!settings.displayMode) {
  16489. throw new src_ParseError("\\tag works only in display equations");
  16490. }
  16491. tree = [{
  16492. type: "tag",
  16493. mode: "text",
  16494. body: tree,
  16495. tag: parser.subparse([new Token("\\df@tag")])
  16496. }];
  16497. }
  16498. return tree;
  16499. };
  16500. /* harmony default export */ var src_parseTree = (parseTree);
  16501. ;// ./katex.ts
  16502. /* eslint no-console:0 */
  16503. /**
  16504. * This is the main entry point for KaTeX. Here, we expose functions for
  16505. * rendering expressions either to DOM nodes or to markup strings.
  16506. *
  16507. * We also expose the ParseError class to check if errors thrown from KaTeX are
  16508. * errors in the expression, or errors in javascript handling.
  16509. */
  16510. /**
  16511. * Parse and build an expression, and place that expression in the DOM node
  16512. * given.
  16513. */
  16514. let render = function (expression, baseNode, options) {
  16515. baseNode.textContent = "";
  16516. const node = renderToDomTree(expression, options).toNode();
  16517. baseNode.appendChild(node);
  16518. };
  16519. // KaTeX's styles don't work properly in quirks mode. Print out an error, and
  16520. // disable rendering.
  16521. if (typeof document !== "undefined") {
  16522. if (document.compatMode !== "CSS1Compat") {
  16523. typeof console !== "undefined" && console.warn("Warning: KaTeX doesn't work in quirks mode. Make sure your " + "website has a suitable doctype.");
  16524. render = function () {
  16525. throw new src_ParseError("KaTeX doesn't work in quirks mode.");
  16526. };
  16527. }
  16528. }
  16529. /**
  16530. * Parse and build an expression, and return the markup for that.
  16531. */
  16532. const renderToString = function (expression, options) {
  16533. const markup = renderToDomTree(expression, options).toMarkup();
  16534. return markup;
  16535. };
  16536. /**
  16537. * Parse an expression and return the parse tree.
  16538. */
  16539. const generateParseTree = function (expression, options) {
  16540. const settings = new Settings(options);
  16541. return src_parseTree(expression, settings);
  16542. };
  16543. /**
  16544. * If the given error is a KaTeX ParseError and options.throwOnError is false,
  16545. * renders the invalid LaTeX as a span with hover title giving the KaTeX
  16546. * error message. Otherwise, simply throws the error.
  16547. */
  16548. const renderError = function (error, expression, options) {
  16549. if (options.throwOnError || !(error instanceof src_ParseError)) {
  16550. throw error;
  16551. }
  16552. const node = makeSpan(["katex-error"], [new SymbolNode(expression)]);
  16553. node.setAttribute("title", error.toString());
  16554. node.setAttribute("style", "color:" + options.errorColor);
  16555. return node;
  16556. };
  16557. /**
  16558. * Generates and returns the katex build tree. This is used for advanced
  16559. * use cases (like rendering to custom output).
  16560. */
  16561. const renderToDomTree = function (expression, options) {
  16562. const settings = new Settings(options);
  16563. try {
  16564. const tree = src_parseTree(expression, settings);
  16565. return buildTree(tree, expression, settings);
  16566. } catch (error) {
  16567. return renderError(error, expression, settings);
  16568. }
  16569. };
  16570. /**
  16571. * Generates and returns the katex build tree, with just HTML (no MathML).
  16572. * This is used for advanced use cases (like rendering to custom output).
  16573. */
  16574. const renderToHTMLTree = function (expression, options) {
  16575. const settings = new Settings(options);
  16576. try {
  16577. const tree = src_parseTree(expression, settings);
  16578. return buildHTMLTree(tree, expression, settings);
  16579. } catch (error) {
  16580. return renderError(error, expression, settings);
  16581. }
  16582. };
  16583. const version = "0.16.44";
  16584. const __domTree = {
  16585. Span: Span,
  16586. Anchor: Anchor,
  16587. SymbolNode: SymbolNode,
  16588. SvgNode: SvgNode,
  16589. PathNode: PathNode,
  16590. LineNode: LineNode
  16591. };
  16592. // ESM exports
  16593. // CJS exports and ESM default export
  16594. /* harmony default export */ var katex = ({
  16595. /**
  16596. * Current KaTeX version
  16597. */
  16598. version,
  16599. /**
  16600. * Renders the given LaTeX into an HTML+MathML combination, and adds
  16601. * it as a child to the specified DOM node.
  16602. */
  16603. render,
  16604. /**
  16605. * Renders the given LaTeX into an HTML+MathML combination string,
  16606. * for sending to the client.
  16607. */
  16608. renderToString,
  16609. /**
  16610. * KaTeX error, usually during parsing.
  16611. */
  16612. ParseError: src_ParseError,
  16613. /**
  16614. * The schema of Settings
  16615. */
  16616. SETTINGS_SCHEMA: SETTINGS_SCHEMA,
  16617. /**
  16618. * Parses the given LaTeX into KaTeX's internal parse tree structure,
  16619. * without rendering to HTML or MathML.
  16620. *
  16621. * NOTE: This method is not currently recommended for public use.
  16622. * The internal tree representation is unstable and is very likely
  16623. * to change. Use at your own risk.
  16624. */
  16625. __parse: generateParseTree,
  16626. /**
  16627. * Renders the given LaTeX into an HTML+MathML internal DOM tree
  16628. * representation, without flattening that representation to a string.
  16629. *
  16630. * NOTE: This method is not currently recommended for public use.
  16631. * The internal tree representation is unstable and is very likely
  16632. * to change. Use at your own risk.
  16633. */
  16634. __renderToDomTree: renderToDomTree,
  16635. /**
  16636. * Renders the given LaTeX into an HTML internal DOM tree representation,
  16637. * without MathML and without flattening that representation to a string.
  16638. *
  16639. * NOTE: This method is not currently recommended for public use.
  16640. * The internal tree representation is unstable and is very likely
  16641. * to change. Use at your own risk.
  16642. */
  16643. __renderToHTMLTree: renderToHTMLTree,
  16644. /**
  16645. * extends internal font metrics object with a new object
  16646. * each key in the new object represents a font name
  16647. */
  16648. __setFontMetrics: setFontMetrics,
  16649. /**
  16650. * adds a new symbol to builtin symbols table
  16651. */
  16652. __defineSymbol: defineSymbol,
  16653. /**
  16654. * adds a new function to builtin function list,
  16655. * which directly produce parse tree elements
  16656. * and have their own html/mathml builders
  16657. */
  16658. __defineFunction: defineFunction,
  16659. /**
  16660. * adds a new macro to builtin macro list
  16661. */
  16662. __defineMacro: defineMacro,
  16663. /**
  16664. * Expose the dom tree node types, which can be useful for type checking nodes.
  16665. *
  16666. * NOTE: These methods are not currently recommended for public use.
  16667. * The internal tree representation is unstable and is very likely
  16668. * to change. Use at your own risk.
  16669. */
  16670. __domTree
  16671. });
  16672. ;// ./katex.webpack.js
  16673. /**
  16674. * This is the webpack entry point for KaTeX. As ECMAScript, flow[1] and jest[2]
  16675. * doesn't support CSS modules natively, a separate entry point is used and
  16676. * it is not flowtyped.
  16677. *
  16678. * [1] https://gist.github.com/lambdahands/d19e0da96285b749f0ef
  16679. * [2] https://facebook.github.io/jest/docs/en/webpack.html
  16680. */
  16681. /* harmony default export */ var katex_webpack = (katex);
  16682. __webpack_exports__ = __webpack_exports__["default"];
  16683. /******/ return __webpack_exports__;
  16684. /******/ })()
  16685. ;
  16686. });