tex2typst
Version:
JavaScript library for converting TeX code to Typst
1,705 lines (1,700 loc) • 115 kB
JavaScript
// src/map.ts
var symbolMap = /* @__PURE__ */ new Map([
["displaystyle", "display"],
[",", "thin"],
[":", "med"],
[";", "thick"],
["cos", "cos"],
["sin", "sin"],
["tan", "tan"],
["cot", "cot"],
["sec", "sec"],
["csc", "csc"],
["mod", "mod"],
["omicron", "omicron"],
["Xi", "Xi"],
["Upsilon", "Upsilon"],
["lim", "lim"],
["nonumber", ""],
["vec", "arrow"],
["neq", "eq.not"],
["dot", "dot"],
["ddot", "dot.double"],
["doteq", "dot(eq)"],
["dots", "dots.h"],
["vdots", "dots.v"],
["ddots", "dots.down"],
["widehat", "hat"],
// Ideally, the result of \widehat should be longer than \hat. But it is not implemented now.
["widetilde", "tilde"],
// Ideally, the result of \widetilde should be longer than \tilde. But it is not implemented now.
["quad", "quad"],
["qquad", "wide"],
["overbrace", "overbrace"],
// same
["underbrace", "underbrace"],
// same
["overline", "overline"],
// same
["underline", "underline"],
// same
["bar", "macron"],
["dbinom", "binom"],
["tbinom", "binom"],
["dfrac", "frac"],
["tfrac", "frac"],
["operatorname", "op"],
["boldsymbol", "bold"],
["mathbb", "bb"],
["mathbf", "bold"],
["mathcal", "cal"],
["mathit", "italic"],
["mathfrak", "frak"],
["mathrm", "upright"],
["mathsf", "sans"],
["mathtt", "mono"],
["rm", "upright"],
// TODO: \pmb need special logic to handle but it is not implemented now. See the commented test case.
["pmb", "bold"],
["leadsto", "arrow.r.squiggly"],
["P", "pilcrow"],
["S", "section"],
["aleph", "alef"],
["infin", "infinity"],
["Delta", "Delta"],
["Gamma", "Gamma"],
["Lambda", "Lambda"],
["Omega", "Omega"],
["Phi", "Phi"],
["Pi", "Pi"],
["Psi", "Psi"],
["Sigma", "Sigma"],
["Theta", "Theta"],
["alpha", "alpha"],
// ['amalg', 'product.co'],
["beta", "beta"],
["bigcirc", "circle.big"],
// ['bowtie', 'join'],
["bullet", "bullet"],
["cdot", "dot.op"],
// 'dot.op' or 'dot.c'
["cdots", "dots.c"],
["checkmark", "checkmark"],
["chi", "chi"],
["circ", "circle.small"],
// 'circle.small' or 'compose'
["colon", "colon"],
["cong", "tilde.equiv"],
["coprod", "product.co"],
["copyright", "copyright"],
["cup", "union"],
["curlyvee", "or.curly"],
["curlywedge", "and.curly"],
["dagger", "dagger"],
["dashv", "tack.l"],
["ddagger", "dagger.double"],
["delta", "delta"],
["ddots", "dots.down"],
["diamond", "diamond"],
["div", "div"],
["divideontimes", "times.div"],
["dotplus", "plus.dot"],
["ell", "ell"],
["emptyset", "nothing"],
["epsilon", "epsilon.alt"],
["equiv", "equiv"],
["eta", "eta"],
["exists", "exists"],
["forall", "forall"],
// ['frown', 'paren.t'],
["gamma", "gamma"],
["ge", "gt.eq"],
["geq", "gt.eq"],
["geqslant", "gt.eq.slant"],
["gg", "gt.double"],
["hbar", "planck.reduce"],
["imath", "dotless.i"],
["iiiint", "integral.quad"],
["iiint", "integral.triple"],
["iint", "integral.double"],
["in", "in"],
["infty", "infinity"],
["int", "integral"],
["intercal", "top"],
// 'top' or 'tack.b'
["iota", "iota"],
["jmath", "dotless.j"],
["kappa", "kappa"],
["lambda", "lambda"],
["land", "and"],
["langle", "angle.l"],
["lbrace", "brace.l"],
["lbrack", "bracket.l"],
["ldots", "dots.h"],
["le", "lt.eq"],
["leftthreetimes", "times.three.l"],
["leftrightarrow", "arrow.l.r"],
["leq", "lt.eq"],
["leqslant", "lt.eq.slant"],
["lhd", "triangle.l"],
["ll", "lt.double"],
// ['longmapsto', 'arrow.bar.long'],
// ['longrightarrow', 'arrow.long'],
["lor", "or"],
["ltimes", "times.l"],
// ['mapsto', 'arrow.bar'],
["measuredangle", "angle.arc"],
["mid", "divides"],
["models", "models"],
["mp", "minus.plus"],
["mu", "mu"],
// ['nRightarrow', 'arrow.double.not'],
["nabla", "nabla"],
["ncong", "tilde.equiv.not"],
["ne", "eq.not"],
["neg", "not"],
["neq", "eq.not"],
["nexists", "exists.not"],
["ni", "in.rev"],
["nleftarrow", "arrow.l.not"],
["nleq", "lt.eq.not"],
["nparallel", "parallel.not"],
["ngeq", "gt.eq.not"],
["nmid", "divides.not"],
["notin", "in.not"],
// ['nrightarrow', 'arrow.not'],
["nsim", "tilde.not"],
["nsubseteq", "subset.eq.not"],
["nu", "nu"],
["ntriangleleft", "lt.tri.not"],
["ntriangleright", "gt.tri.not"],
["odot", "dot.circle"],
["oint", "integral.cont"],
["oiint", "integral.surf"],
["oiiint", "integral.vol"],
["omega", "omega"],
["ominus", "minus.circle"],
// ['oplus', 'xor'], // or 'plus.circle'
["otimes", "times.circle"],
["parallel", "parallel"],
["partial", "diff"],
["perp", "perp"],
["phi", "phi.alt"],
["pi", "pi"],
["pm", "plus.minus"],
["pounds", "pound"],
["prec", "prec"],
["preceq", "prec.eq"],
["prime", "prime"],
["prod", "product"],
["propto", "prop"],
["psi", "psi"],
["rangle", "angle.r"],
["rbrace", "brace.r"],
["rbrack", "bracket.r"],
["rhd", "triangle"],
["rho", "rho"],
["rightarrow", "arrow.r"],
["rightthreetimes", "times.three.r"],
["rtimes", "times.r"],
["setminus", "without"],
["sigma", "sigma"],
["sim", "tilde.op"],
["simeq", "tilde.eq"],
["slash", "slash"],
["smallsetminus", "without"],
// ['smile', 'paren.b'],
["spadesuit", "suit.spade"],
["sqsubseteq", "subset.eq.sq"],
["sqsupseteq", "supset.eq.sq"],
// ['star', 'star'],
["subset", "subset"],
["subseteq", "subset.eq"],
["subsetneq", "subset.neq"],
["succ", "succ"],
["succeq", "succ.eq"],
["sum", "sum"],
["supset", "supset"],
["supseteq", "supset.eq"],
["supsetneq", "supset.neq"],
["tau", "tau"],
["theta", "theta"],
["times", "times"],
["to", "arrow.r"],
["top", "top"],
["triangle", "triangle.t"],
// ['triangledown', 'triangle.b.small'],
// ['triangleleft', 'triangle.l.small'],
// ['triangleright', 'triangle.r.small'],
["twoheadrightarrow", "arrow.r.twohead"],
["upharpoonright", "harpoon.tr"],
["uplus", "union.plus"],
["upsilon", "upsilon"],
["varepsilon", "epsilon"],
["varnothing", "diameter"],
// empty set
["varphi", "phi"],
["varpi", "pi.alt"],
["varrho", "rho.alt"],
["varsigma", "sigma.alt"],
["vartheta", "theta.alt"],
["vdash", "tack.r"],
["vdots", "dots.v"],
["vee", "or"],
["wedge", "and"],
["wr", "wreath"],
["xi", "xi"],
["yen", "yen"],
["zeta", "zeta"],
// extended
["mathscr", "scr"],
["LaTeX", "#LaTeX"],
["TeX", "#TeX"]
]);
var map_from_official_docs = /* @__PURE__ */ new Map([
["acwopencirclearrow", "arrow.ccw"],
["adots", "dots.up"],
["angdnr", "angle.acute"],
["angle", "angle"],
["angles", "angle.s"],
["approx", "approx"],
["approxeq", "approx.eq"],
["approxident", "tilde.triple"],
["assert", "tack.r.short"],
["ast", "ast.op"],
["asymp", "asymp"],
["awint", "integral.ccw"],
["backcong", "tilde.rev.equiv"],
["backdprime", "prime.double.rev"],
["backprime", "prime.rev"],
["backsim", "tilde.rev"],
["backsimeq", "tilde.eq.rev"],
["backslash", "backslash"],
["backtrprime", "prime.triple.rev"],
["bardownharpoonleft", "harpoon.bl.bar"],
["bardownharpoonright", "harpoon.br.bar"],
["barleftarrow", "arrow.l.stop"],
["barleftarrowrightarrowbar", "arrows.lr.stop"],
["barleftharpoondown", "harpoon.lb.stop"],
["barleftharpoonup", "harpoon.lt.stop"],
["barrightharpoondown", "harpoon.rb.bar"],
["barrightharpoonup", "harpoon.rt.bar"],
["baruparrow", "arrow.t.stop"],
["barupharpoonleft", "harpoon.tl.stop"],
["barupharpoonright", "harpoon.tr.stop"],
["barV", "tack.b.double"],
["BbbA", "AA"],
["BbbB", "BB"],
["BbbC", "CC"],
["BbbD", "DD"],
["BbbE", "EE"],
["BbbF", "FF"],
["BbbG", "GG"],
["BbbH", "HH"],
["BbbI", "II"],
["BbbJ", "JJ"],
["BbbK", "KK"],
["BbbL", "LL"],
["BbbM", "MM"],
["BbbN", "NN"],
["BbbO", "OO"],
["BbbP", "PP"],
["BbbQ", "QQ"],
["BbbR", "RR"],
["BbbS", "SS"],
["BbbT", "TT"],
["BbbU", "UU"],
["BbbV", "VV"],
["BbbW", "WW"],
["BbbX", "XX"],
["BbbY", "YY"],
["BbbZ", "ZZ"],
["because", "because"],
["bigblacktriangledown", "triangle.filled.b"],
["bigblacktriangleup", "triangle.filled.t"],
["bigbot", "tack.t.big"],
["bigcap", "inter.big"],
["bigcup", "union.big"],
["bigcupdot", "union.dot.big"],
["biginterleave", "interleave.big"],
["bigodot", "dot.circle.big"],
["bigoplus", "plus.circle.big"],
// or 'xor.big'
["bigotimes", "times.circle.big"],
["bigsqcap", "inter.sq.big"],
["bigsqcup", "union.sq.big"],
["bigstar", "star.filled"],
["bigtimes", "times.big"],
["bigtop", "tack.b.big"],
["bigtriangledown", "triangle.stroked.b"],
// or 'triangle.b'
["bigtriangleup", "triangle.stroked.t"],
// or 'triangle.t'
["biguplus", "union.plus.big"],
["bigvee", "or.big"],
["bigwedge", "and.big"],
["bigwhitestar", "star.stroked"],
["blackhourglass", "hourglass.filled"],
["blacktriangle", "triangle.filled.small.t"],
["blacktriangledown", "triangle.filled.small.b"],
["blacktriangleleft", "triangle.filled.l"],
["blacktriangleright", "triangle.filled.r"],
["blkhorzoval", "ellipse.filled.h"],
["blkvertoval", "ellipse.filled.v"],
["bot", "bot"],
["boxast", "ast.square"],
["boxdot", "dot.square"],
["boxminus", "minus.square"],
["boxplus", "plus.square"],
["boxtimes", "times.square"],
["cap", "inter"],
["Cap", "inter.double"],
["capdot", "inter.dot"],
["capwedge", "inter.and"],
["caretinsert", "caret"],
["cdot", "dot.op"],
["cdotp", "dot.c"],
["checkmark", "checkmark"],
["circledast", "ast.circle"],
["circledcirc", "circle.nested"],
["circleddash", "dash.circle"],
["circledequal", "eq.circle"],
["circledparallel", "parallel.circle"],
["circledvert", "bar.v.circle"],
["clubsuit", "suit.club.filled"],
["Colon", "colon.double"],
["coloneq", "colon.eq"],
["Coloneq", "colon.double.eq"],
["complement", "complement"],
["cong", "tilde.equiv"],
["coprod", "product.co"],
["cup", "union"],
["Cup", "union.double"],
["cupdot", "union.dot"],
["cupleftarrow", "union.arrow"],
["cupvee", "union.or"],
["curlyeqprec", "eq.prec"],
["curlyeqsucc", "eq.succ"],
["curlyvee", "or.curly"],
["curlywedge", "and.curly"],
["curvearrowleft", "arrow.ccw.half"],
["curvearrowright", "arrow.cw.half"],
["cwopencirclearrow", "arrow.cw"],
["dagger", "dagger"],
["dashcolon", "dash.colon"],
["dashv", "tack.l"],
["Dashv", "tack.l.double"],
["dashVdash", "tack.l.r"],
["ddagger", "dagger.double"],
["ddddot", "dot.quad"],
["dddot", "dot.triple"],
["ddots", "dots.down"],
["DDownarrow", "arrow.b.quad"],
["Ddownarrow", "arrow.b.triple"],
["diameter", "diameter"],
["diamondcdot", "diamond.stroked.dot"],
["diamondsuit", "suit.diamond.stroked"],
["dicei", "die.one"],
["diceii", "die.two"],
["diceiii", "die.three"],
["diceiv", "die.four"],
["dicev", "die.five"],
["dicevi", "die.six"],
["div", "div"],
["divideontimes", "times.div"],
["Doteq", "eq.dots"],
["dotminus", "minus.dot"],
["dotplus", "plus.dot"],
["dotsim", "tilde.dot"],
["dottedcircle", "circle.dotted"],
["dottedsquare", "square.stroked.dotted"],
["doubleplus", "plus.double"],
["downarrow", "arrow.b"],
["Downarrow", "arrow.b.double"],
["downarrowbar", "arrow.b.stop"],
["downdasharrow", "arrow.b.dashed"],
["downdownarrows", "arrows.bb"],
["downharpoonleft", "harpoon.bl"],
["downharpoonleftbar", "harpoon.bl.stop"],
["downharpoonright", "harpoon.br"],
["downharpoonrightbar", "harpoon.br.stop"],
["downharpoonsleftright", "harpoons.blbr"],
["downrightcurvedarrow", "arrow.b.curve"],
["downuparrows", "arrows.bt"],
["downupharpoonsleftright", "harpoons.bltr"],
["downwhitearrow", "arrow.b.stroked"],
["downzigzagarrow", "arrow.zigzag"],
["dprime", "prime.double"],
["dualmap", "multimap.double"],
["eighthnote", "note.eighth.alt"],
["ell", "ell"],
["emptysetoarr", "emptyset.arrow.r"],
["emptysetoarrl", "emptyset.arrow.l"],
["emptysetobar", "emptyset.bar"],
["emptysetocirc", "emptyset.circle"],
["eparsl", "parallel.slanted.eq"],
["eqcolon", "eq.colon"],
["eqdef", "eq.def"],
// \usepackage{mathtools} defines \eqdef
["eqgtr", "eq.gt"],
["eqless", "eq.lt"],
["eqsim", "minus.tilde"],
["equal", "eq"],
["equalparallel", "parallel.eq"],
["equiv", "eq.triple"],
["Equiv", "eq.quad"],
["equivVert", "parallel.equiv"],
["eqvparsl", "parallel.slanted.equiv"],
["errbarblackcircle", "errorbar.circle.filled"],
["errbarblackdiamond", "errorbar.diamond.filled"],
["errbarblacksquare", "errorbar.square.filled"],
["errbarcircle", "errorbar.circle.stroked"],
["errbardiamond", "errorbar.diamond.stroked"],
["errbarsquare", "errorbar.square.stroked"],
["euro", "euro"],
["Exclam", "excl.double"],
["exists", "exists"],
["fallingdotseq", "eq.dots.down"],
["fint", "integral.slash"],
["flat", "flat"],
["forall", "forall"],
["fourvdots", "fence.dotted"],
["fullouterjoin", "join.l.r"],
["geq", "gt.eq"],
["geqq", "gt.equiv"],
["geqslant", "gt.eq.slant"],
["gg", "gt.double"],
["ggg", "gt.triple"],
["gggnest", "gt.triple.nested"],
["gnapprox", "gt.napprox"],
["gneq", "gt.neq"],
["gneqq", "gt.nequiv"],
["gnsim", "gt.ntilde"],
["greater", "gt"],
["gtlpar", "angle.spheric.rev"],
["gtrapprox", "gt.approx"],
["gtrdot", "gt.dot"],
["gtreqless", "gt.eq.lt"],
["gtrless", "gt.lt"],
["gtrsim", "gt.tilde"],
["heartsuit", "suit.heart.stroked"],
["hknearrow", "arrow.tr.hook"],
["hknwarrow", "arrow.tl.hook"],
["hksearrow", "arrow.br.hook"],
["hkswarrow", "arrow.bl.hook"],
["hookleftarrow", "arrow.l.hook"],
["hookrightarrow", "arrow.r.hook"],
["horizbar", "bar.h"],
["hourglass", "hourglass.stroked"],
["hrectangle", "rect.stroked.h"],
["hrectangleblack", "rect.filled.h"],
["hslash", "planck.reduce"],
["hzigzag", "dash.wave.double"],
["iiiint", "integral.quad"],
["iiint", "integral.triple"],
["iinfin", "infinity.incomplete"],
["iint", "integral.double"],
["Im", "Im"],
["imageof", "image"],
["in", "in"],
["increment", "laplace"],
["infty", "infinity"],
["int", "integral"],
["intbar", "integral.dash"],
["intBar", "integral.dash.double"],
["intcap", "integral.inter"],
["intclockwise", "integral.cw"],
["intcup", "integral.union"],
["interleave", "interleave"],
["intlarhk", "integral.arrow.hook"],
["intx", "integral.times"],
["Join", "join"],
["langle", "angle.l"],
["lAngle", "angle.l.double"],
["langledot", "angle.l.dot"],
["lat", "lat"],
["late", "lat.eq"],
["lbrace", "brace.l"],
["lBrace", "brace.l.double"],
["lbrack", "bracket.l"],
["lBrack", "bracket.l.double"],
["lbrbrak", "shell.l"],
["Lbrbrak", "shell.l.double"],
["lceil", "ceil.l"],
["lcurvyangle", "angle.l.curly"],
["leftarrow", "arrow.l"],
["Leftarrow", "arrow.l.double"],
["leftarrowtail", "arrow.l.tail"],
["leftdasharrow", "arrow.l.dashed"],
["leftdotarrow", "arrow.l.dotted"],
["leftdowncurvedarrow", "arrow.l.curve"],
["leftharpoondown", "harpoon.lb"],
["leftharpoondownbar", "harpoon.lb.bar"],
["leftharpoonsupdown", "harpoons.ltlb"],
["leftharpoonup", "harpoon.lt"],
["leftharpoonupbar", "harpoon.lt.bar"],
["leftleftarrows", "arrows.ll"],
["leftouterjoin", "join.l"],
["leftrightarrow", "arrow.l.r"],
["Leftrightarrow", "arrow.l.r.double"],
["leftrightarrows", "arrows.lr"],
["leftrightharpoondowndown", "harpoon.lb.rb"],
["leftrightharpoondownup", "harpoon.lb.rt"],
["leftrightharpoons", "harpoons.ltrb"],
["leftrightharpoonsdown", "harpoons.lbrb"],
["leftrightharpoonsup", "harpoons.ltrt"],
["leftrightharpoonupdown", "harpoon.lt.rb"],
["leftrightharpoonupup", "harpoon.lt.rt"],
["leftrightsquigarrow", "arrow.l.r.wave"],
["leftsquigarrow", "arrow.l.squiggly"],
["leftthreearrows", "arrows.lll"],
["leftthreetimes", "times.three.l"],
["leftwavearrow", "arrow.l.wave"],
["leftwhitearrow", "arrow.l.stroked"],
["leq", "lt.eq"],
["leqq", "lt.equiv"],
["leqslant", "lt.eq.slant"],
["less", "lt"],
["lessapprox", "lt.approx"],
["lessdot", "lt.dot"],
["lesseqgtr", "lt.eq.gt"],
["lessgtr", "lt.gt"],
["lesssim", "lt.tilde"],
["lfloor", "floor.l"],
["lgblkcircle", "circle.filled.big"],
["lgblksquare", "square.filled.big"],
["lgwhtcircle", "circle.stroked.big"],
["lgwhtsquare", "square.stroked.big"],
["ll", "lt.double"],
["llblacktriangle", "triangle.filled.bl"],
["LLeftarrow", "arrow.l.quad"],
["Lleftarrow", "arrow.l.triple"],
["lll", "lt.triple"],
["lllnest", "lt.triple.nested"],
["lltriangle", "triangle.stroked.bl"],
["lnapprox", "lt.napprox"],
["lneq", "lt.neq"],
["lneqq", "lt.nequiv"],
["lnsim", "lt.ntilde"],
["longdashv", "tack.l.long"],
["Longleftarrow", "arrow.l.double.long"],
["longleftarrow", "arrow.l.long"],
["Longleftrightarrow", "arrow.l.r.double.long"],
["longleftrightarrow", "arrow.l.r.long"],
["longleftsquigarrow", "arrow.l.long.squiggly"],
["Longmapsfrom", "arrow.l.double.long.bar"],
["longmapsfrom", "arrow.l.long.bar"],
["longmapsto", "arrow.r.long.bar"],
["Longmapsto", "arrow.r.double.long.bar"],
["Longrightarrow", "arrow.r.double.long"],
["longrightarrow", "arrow.r.long"],
["longrightsquigarrow", "arrow.r.long.squiggly"],
["looparrowleft", "arrow.l.loop"],
["looparrowright", "arrow.r.loop"],
["lparen", "paren.l"],
["lParen", "paren.l.double"],
["lrblacktriangle", "triangle.filled.br"],
["lrtriangle", "triangle.stroked.br"],
["ltimes", "times.l"],
["lvzigzag", "fence.l"],
["Lvzigzag", "fence.l.double"],
["maltese", "maltese"],
["mapsdown", "arrow.b.bar"],
["mapsfrom", "arrow.l.bar"],
["Mapsfrom", "arrow.l.double.bar"],
["mapsto", "arrow.r.bar"],
["Mapsto", "arrow.r.double.bar"],
["mapsup", "arrow.t.bar"],
["mathampersand", "amp"],
["mathatsign", "at"],
["mathcolon", "colon"],
["mathcomma", "comma"],
["mathdollar", "dollar"],
["mathexclam", "excl"],
// ['mathhyphen', 'hyph'], // \mathhyphen is not defined in standard amsmath package
["mathoctothorpe", "hash"],
["mathparagraph", "pilcrow"],
["mathpercent", "percent"],
["mathperiod", "dot.basic"],
["mathplus", "plus"],
["mathquestion", "quest"],
["mathratio", "ratio"],
["mathsection", "section"],
["mathsemicolon", "semi"],
["mathslash", "slash"],
["mathsterling", "pound"],
["mathyen", "yen"],
["mdblkdiamond", "diamond.filled.medium"],
["mdblklozenge", "lozenge.filled.medium"],
["mdblksquare", "square.filled.medium"],
["mdlgblkcircle", "circle.filled"],
["mdlgblkdiamond", "diamond.filled"],
["mdlgblklozenge", "lozenge.filled"],
["mdlgblksquare", "square.filled"],
["mdlgwhtcircle", "circle.stroked"],
["mdlgwhtdiamond", "diamond.stroked"],
["mdlgwhtlozenge", "lozenge.stroked"],
["mdlgwhtsquare", "square.stroked"],
["mdsmblkcircle", "circle.filled.tiny"],
["mdsmblksquare", "square.filled.small"],
["mdsmwhtcircle", "circle.stroked.small"],
["mdsmwhtsquare", "square.stroked.small"],
["mdwhtdiamond", "diamond.stroked.medium"],
["mdwhtlozenge", "lozenge.stroked.medium"],
["mdwhtsquare", "square.stroked.medium"],
["measeq", "eq.m"],
["measuredangle", "angle.arc"],
["measuredangleleft", "angle.arc.rev"],
["measuredrightangle", "angle.right.arc"],
["mho", "Omega.inv"],
["mid", "divides"],
["minus", "minus"],
["models", "models"],
["mp", "minus.plus"],
["multimap", "multimap"],
/* ['mupAlpha', 'Alpha'],
['mupalpha', 'alpha'],
['mupBeta', 'Beta'],
['mupbeta', 'beta'],
['mupChi', 'Chi'],
['mupchi', 'chi'],
['mupDelta', 'Delta'],
['mupdelta', 'delta'],
['mupEpsilon', 'Epsilon'],
['mupepsilon', 'epsilon.alt'],
['mupEta', 'Eta'],
['mupeta', 'eta'],
['mupGamma', 'Gamma'],
['mupgamma', 'gamma'],
['mupIota', 'Iota'],
['mupiota', 'iota'],
['mupKappa', 'Kappa'],
['mupkappa', 'kappa'],
['mupLambda', 'Lambda'],
['muplambda', 'lambda'],
['mupMu', 'Mu'],
['mupmu', 'mu'],
['mupNu', 'Nu'],
['mupnu', 'nu'],
['mupOmega', 'Omega'],
['mupomega', 'omega'],
['mupOmicron', 'Omicron'],
['mupomicron', 'omicron'],
['mupPhi', 'Phi'],
['mupphi', 'phi.alt'],
['mupPi', 'Pi'],
['muppi', 'pi'],
['mupPsi', 'Psi'],
['muppsi', 'psi'],
['mupRho', 'Rho'],
['muprho', 'rho'],
['mupSigma', 'Sigma'],
['mupsigma', 'sigma'],
['mupTau', 'Tau'],
['muptau', 'tau'],
['mupTheta', 'Theta'],
['muptheta', 'theta'],
['mupUpsilon', 'Upsilon'],
['mupupsilon', 'upsilon'],
['mupvarepsilon', 'epsilon'],
['mupvarkappa', 'kappa.alt'],
['mupvarphi', 'phi'],
['mupvarpi', 'pi.alt'],
['mupvarrho', 'rho.alt'],
['mupvarsigma', 'sigma.alt'],
['mupvartheta', 'theta.alt'],
['mupXi', 'Xi'],
['mupxi', 'xi'],
['mupZeta', 'Zeta'],
['mupzeta', 'zeta'], */
["nabla", "gradient"],
["napprox", "approx.not"],
["nasymp", "asymp.not"],
["natural", "natural"],
["ncong", "tilde.equiv.not"],
["ne", "eq.not"],
["nearrow", "arrow.tr"],
["Nearrow", "arrow.tr.double"],
["neg", "not"],
["nequiv", "equiv.not"],
// or eq.triple.not
["neswarrow", "arrow.tr.bl"],
["nexists", "exists.not"],
["ngeq", "gt.eq.not"],
["ngtr", "gt.not"],
["ngtrless", "gt.lt.not"],
["ngtrsim", "gt.tilde.not"],
["nhpar", "parallel.struck"],
["nhVvert", "interleave.struck"],
["ni", "in.rev"],
["nLeftarrow", "arrow.l.double.not"],
["nleftarrow", "arrow.l.not"],
["nLeftrightarrow", "arrow.l.r.double.not"],
["nleftrightarrow", "arrow.l.r.not"],
["nleq", "lt.eq.not"],
["nless", "lt.not"],
["nlessgtr", "lt.gt.not"],
["nlesssim", "lt.tilde.not"],
["nmid", "divides.not"],
["nni", "in.rev.not"],
["notin", "in.not"],
["nparallel", "parallel.not"],
["nprec", "prec.not"],
["npreccurlyeq", "prec.curly.eq.not"],
["nRightarrow", "arrow.r.double.not"],
["nrightarrow", "arrow.r.not"],
["nsim", "tilde.not"],
["nsimeq", "tilde.eq.not"],
["nsqsubseteq", "subset.eq.sq.not"],
["nsqsupseteq", "supset.eq.sq.not"],
["nsubset", "subset.not"],
["nsubseteq", "subset.eq.not"],
["nsucc", "succ.not"],
["nsucccurlyeq", "succ.curly.eq.not"],
["nsupset", "supset.not"],
["nsupseteq", "supset.eq.not"],
["ntrianglelefteq", "lt.tri.eq.not"],
["ntrianglerighteq", "gt.tri.eq.not"],
["nvartriangleleft", "lt.tri.not"],
["nvartriangleright", "gt.tri.not"],
["nVdash", "forces.not"],
["nvdash", "tack.r.not"],
["nvDash", "tack.r.double.not"],
["nvinfty", "infinity.bar"],
["nwarrow", "arrow.tl"],
["Nwarrow", "arrow.tl.double"],
["nwsearrow", "arrow.tl.br"],
["obrbrak", "shell.t"],
["obslash", "backslash.circle"],
["odiv", "div.circle"],
["odot", "dot.circle"],
["ogreaterthan", "gt.circle"],
["oiiint", "integral.vol"],
["oiint", "integral.surf"],
["oint", "integral.cont"],
["ointctrclockwise", "integral.cont.ccw"],
["olessthan", "lt.circle"],
["ominus", "minus.circle"],
["operp", "perp.circle"],
["oplus", "plus.circle"],
["origof", "original"],
["otimes", "times.circle"],
// ['overbrace', 'brace.t'],
["overbracket", "bracket.t"],
["overparen", "paren.t"],
["parallel", "parallel"],
["parallelogram", "parallelogram.stroked"],
["parallelogramblack", "parallelogram.filled"],
["parsim", "parallel.tilde"],
["partial", "diff"],
["pentagon", "penta.stroked"],
["pentagonblack", "penta.filled"],
["perp", "perp"],
["Planckconst", "planck"],
["pm", "plus.minus"],
["prec", "prec"],
["Prec", "prec.double"],
["precapprox", "prec.approx"],
["preccurlyeq", "prec.curly.eq"],
["preceq", "prec.eq"],
["preceqq", "prec.equiv"],
["precnapprox", "prec.napprox"],
["precneq", "prec.neq"],
["precneqq", "prec.nequiv"],
["precnsim", "prec.ntilde"],
["precsim", "prec.tilde"],
["prime", "prime"],
["prod", "product"],
["propto", "prop"],
["QED", "qed"],
["qprime", "prime.quad"],
["quarternote", "note.quarter.alt"],
["questeq", "eq.quest"],
["Question", "quest.double"],
["rangle", "angle.r"],
["rAngle", "angle.r.double"],
["rangledot", "angle.r.dot"],
["rbrace", "brace.r"],
["rBrace", "brace.r.double"],
["rbrack", "bracket.r"],
["rBrack", "bracket.r.double"],
["rbrbrak", "shell.r"],
["Rbrbrak", "shell.r.double"],
["rceil", "ceil.r"],
["rcurvyangle", "angle.r.curly"],
["Re", "Re"],
["revangle", "angle.rev"],
["revemptyset", "emptyset.rev"],
["revnmid", "divides.not.rev"],
["rfloor", "floor.r"],
["rightangle", "angle.right"],
["rightanglemdot", "angle.right.dot"],
["rightanglesqr", "angle.right.sq"],
["rightarrow", "arrow.r"],
["Rightarrow", "arrow.r.double"],
["rightarrowbar", "arrow.r.stop"],
["rightarrowonoplus", "plus.circle.arrow"],
["rightarrowtail", "arrow.r.tail"],
["rightdasharrow", "arrow.r.dashed"],
["rightdotarrow", "arrow.r.dotted"],
["rightdowncurvedarrow", "arrow.r.curve"],
["rightharpoondown", "harpoon.rb"],
["rightharpoondownbar", "harpoon.rb.stop"],
["rightharpoonsupdown", "harpoons.rtrb"],
["rightharpoonup", "harpoon.rt"],
["rightharpoonupbar", "harpoon.rt.stop"],
["rightleftarrows", "arrows.rl"],
["rightleftharpoons", "harpoons.rtlb"],
["rightleftharpoonsdown", "harpoons.rblb"],
["rightleftharpoonsup", "harpoons.rtlt"],
["rightouterjoin", "join.r"],
["rightrightarrows", "arrows.rr"],
["rightsquigarrow", "arrow.r.squiggly"],
["rightthreearrows", "arrows.rrr"],
["rightthreetimes", "times.three.r"],
["rightwavearrow", "arrow.r.wave"],
["rightwhitearrow", "arrow.r.stroked"],
["risingdotseq", "eq.dots.up"],
["rparen", "paren.r"],
["rParen", "paren.r.double"],
["RRightarrow", "arrow.r.quad"],
["Rrightarrow", "arrow.r.triple"],
["rsolbar", "backslash.not"],
["rtimes", "times.r"],
["rvzigzag", "fence.r"],
["Rvzigzag", "fence.r.double"],
["searrow", "arrow.br"],
["Searrow", "arrow.br.double"],
["setminus", "without"],
["sharp", "sharp"],
["shortdowntack", "tack.b.short"],
["shortlefttack", "tack.l.short"],
["shortuptack", "tack.t.short"],
["sim", "tilde.op"],
["sime", "tilde.eq"],
["similarleftarrow", "arrow.l.tilde"],
["similarrightarrow", "arrow.r.tilde"],
["simneqq", "tilde.nequiv"],
["smallblacktriangleleft", "triangle.filled.small.l"],
["smallblacktriangleright", "triangle.filled.small.r"],
["smallin", "in.small"],
["smallni", "in.rev.small"],
["smalltriangleleft", "triangle.stroked.small.l"],
["smalltriangleright", "triangle.stroked.small.r"],
["smashtimes", "smash"],
["smblkcircle", "bullet"],
["smblkdiamond", "diamond.filled.small"],
["smblklozenge", "lozenge.filled.small"],
["smblksquare", "square.filled.tiny"],
["smeparsl", "parallel.slanted.eq.tilde"],
["smt", "smt"],
["smte", "smt.eq"],
["smwhtdiamond", "diamond.stroked.small"],
["smwhtlozenge", "lozenge.stroked.small"],
["smwhtsquare", "square.stroked.tiny"],
["spadesuit", "suit.spade.filled"],
["sphericalangle", "angle.spheric"],
["sphericalangleup", "angle.spheric.top"],
["sqcap", "inter.sq"],
["Sqcap", "inter.sq.double"],
["sqcup", "union.sq"],
["Sqcup", "union.sq.double"],
["sqint", "integral.square"],
["sqsubset", "subset.sq"],
["sqsubseteq", "subset.eq.sq"],
["sqsubsetneq", "subset.sq.neq"],
["sqsupset", "supset.sq"],
["sqsupseteq", "supset.eq.sq"],
["sqsupsetneq", "supset.sq.neq"],
["squoval", "square.stroked.rounded"],
["sslash", "slash.double"],
["star", "star.op"],
["stareq", "eq.star"],
["subset", "subset"],
["Subset", "subset.double"],
["subsetdot", "subset.dot"],
["subseteq", "subset.eq"],
["subsetneq", "subset.neq"],
["succ", "succ"],
["Succ", "succ.double"],
["succapprox", "succ.approx"],
["succcurlyeq", "succ.curly.eq"],
["succeq", "succ.eq"],
["succeqq", "succ.equiv"],
["succnapprox", "succ.napprox"],
["succneq", "succ.neq"],
["succneqq", "succ.nequiv"],
["succnsim", "succ.ntilde"],
["succsim", "succ.tilde"],
["sum", "sum"],
["sumint", "sum.integral"],
["supset", "supset"],
["Supset", "supset.double"],
["supsetdot", "supset.dot"],
["supseteq", "supset.eq"],
["supsetneq", "supset.neq"],
["swarrow", "arrow.bl"],
["Swarrow", "arrow.bl.double"],
["therefore", "therefore"],
["threedangle", "angle.spatial"],
["threedotcolon", "colon.tri.op"],
["tieinfty", "infinity.tie"],
["times", "times"],
["tminus", "miny"],
["top", "tack.b"],
["tplus", "tiny"],
["trianglecdot", "triangle.stroked.dot"],
["triangledown", "triangle.stroked.small.b"],
["triangleleft", "triangle.stroked.l"],
["trianglelefteq", "lt.tri.eq"],
["triangleminus", "minus.triangle"],
["triangleplus", "plus.triangle"],
["triangleq", "eq.delta"],
["triangleright", "triangle.stroked.r"],
["trianglerighteq", "gt.tri.eq"],
["triangletimes", "times.triangle"],
["tripleplus", "plus.triple"],
["trprime", "prime.triple"],
["trslash", "slash.triple"],
["twoheaddownarrow", "arrow.b.twohead"],
["twoheadleftarrow", "arrow.l.twohead"],
["twoheadmapsfrom", "arrow.l.twohead.bar"],
["twoheadmapsto", "arrow.r.twohead.bar"],
["twoheadrightarrow", "arrow.r.twohead"],
["twoheaduparrow", "arrow.t.twohead"],
["twonotes", "note.eighth.beamed"],
["ubrbrak", "shell.b"],
["ulblacktriangle", "triangle.filled.tl"],
["ultriangle", "triangle.stroked.tl"],
["uminus", "union.minus"],
["underbrace", "brace.b"],
["underbracket", "bracket.b"],
["underparen", "paren.b"],
["unicodecdots", "dots.h.c"],
["unicodeellipsis", "dots.h"],
["upand", "amp.inv"],
["uparrow", "arrow.t"],
["Uparrow", "arrow.t.double"],
["updasharrow", "arrow.t.dashed"],
["updownarrow", "arrow.t.b"],
["Updownarrow", "arrow.t.b.double"],
["updownarrows", "arrows.tb"],
["updownharpoonleftleft", "harpoon.tl.bl"],
["updownharpoonleftright", "harpoon.tl.br"],
["updownharpoonrightleft", "harpoon.tr.bl"],
["updownharpoonrightright", "harpoon.tr.br"],
["updownharpoonsleftright", "harpoons.tlbr"],
["upharpoonleft", "harpoon.tl"],
["upharpoonleftbar", "harpoon.tl.bar"],
["upharpoonright", "harpoon.tr"],
["upharpoonrightbar", "harpoon.tr.bar"],
["upharpoonsleftright", "harpoons.tltr"],
["uplus", "union.plus"],
["uprightcurvearrow", "arrow.t.curve"],
["upuparrows", "arrows.tt"],
["upwhitearrow", "arrow.t.stroked"],
["urblacktriangle", "triangle.filled.tr"],
["urtriangle", "triangle.stroked.tr"],
["UUparrow", "arrow.t.quad"],
["Uuparrow", "arrow.t.triple"],
["varclubsuit", "suit.club.stroked"],
["vardiamondsuit", "suit.diamond.filled"],
["varheartsuit", "suit.heart.filled"],
["varhexagon", "hexa.stroked"],
["varhexagonblack", "hexa.filled"],
["varnothing", "emptyset"],
["varointclockwise", "integral.cont.cw"],
["varspadesuit", "suit.spade.stroked"],
["vartriangle", "triangle.stroked.small.t"],
["vartriangleleft", "lt.tri"],
["vartriangleright", "gt.tri"],
["Vbar", "tack.t.double"],
["Vdash", "forces"],
["vdash", "tack.r"],
["vDash", "tack.r.double"],
["vdots", "dots.v"],
["vee", "or"],
["Vee", "or.double"],
["veedot", "or.dot"],
["veeeq", "eq.equi"],
["vert", "bar.v"],
["Vert", "bar.v.double"],
["vlongdash", "tack.r.long"],
["vrectangle", "rect.stroked.v"],
["vrectangleblack", "rect.filled.v"],
["Vvert", "bar.v.triple"],
["vysmblkcircle", "circle.filled.small"],
["vysmwhtcircle", "circle.stroked.tiny"],
// or compose
["wedge", "and"],
["Wedge", "and.double"],
["wedgedot", "and.dot"],
["wedgeq", "eq.est"],
["whiteinwhitetriangle", "triangle.stroked.nested"],
["whthorzoval", "ellipse.stroked.h"],
["whtvertoval", "ellipse.stroked.v"],
["wideangledown", "angle.oblique"],
["wr", "wreath"],
["xsol", "slash.big"]
]);
var texAliasMap = /* @__PURE__ */ new Map([
["gets", "leftarrow"],
["iff", "Longleftrightarrow"],
["implies", "Longrightarrow"]
]);
for (const [key, value] of map_from_official_docs) {
if (!symbolMap.has(key)) {
symbolMap.set(key, value);
}
}
var reverseSymbolMap = /* @__PURE__ */ new Map();
for (const [key, value] of Array.from(symbolMap.entries()).reverse()) {
reverseSymbolMap.set(value, key);
}
reverseSymbolMap.set("dif", "mathrm{d}");
reverseSymbolMap.set("oo", "infty");
var typst_to_tex_map = /* @__PURE__ */ new Map([
["top", "top"],
["frac", "frac"],
["tilde", "tilde"],
["hat", "hat"],
["upright", "mathrm"],
["bold", "boldsymbol"],
["infinity", "infty"],
["hyph.minus", "\\text{-}"]
]);
for (const [key, value] of typst_to_tex_map) {
reverseSymbolMap.set(key, value);
}
for (const [key, value] of texAliasMap) {
if (!symbolMap.has(key)) {
symbolMap.set(key, symbolMap.get(value));
}
}
// src/generic.ts
function array_find(array, item, start = 0) {
for (let i = start; i < array.length; i++) {
if (array[i].eq(item)) {
return i;
}
}
return -1;
}
function array_includes(array, item) {
for (const i of array) {
if (i.eq(item)) {
return true;
}
}
return false;
}
function array_split(array, sep) {
const res = [];
let current_slice = [];
for (const i of array) {
if (i.eq(sep)) {
res.push(current_slice);
current_slice = [];
} else {
current_slice.push(i);
}
}
res.push(current_slice);
return res;
}
function array_join(array, sep) {
const res = [];
for (let i = 0; i < array.length; i++) {
res.push(array[i]);
if (i != array.length - 1) {
res.push(sep);
}
}
return res;
}
// src/types.ts
var TexToken = class {
constructor(type, value) {
this.type = type;
this.value = value;
}
eq(token) {
return this.type === token.type && this.value === token.value;
}
toString() {
switch (this.type) {
case 2 /* TEXT */:
return `\\text{${this.value}}`;
case 3 /* COMMENT */:
return `%${this.value}`;
default:
return this.value;
}
}
};
function apply_escape_if_needed(c) {
if (["{", "}", "%"].includes(c)) {
return "\\" + c;
}
return c;
}
var TexNode = class {
constructor(type, content, args, data) {
this.type = type;
this.content = content;
this.args = args;
this.data = data;
}
// Note that this is only shallow equality.
eq(other) {
return this.type === other.type && this.content === other.content;
}
toString() {
switch (this.type) {
case "text":
return `\\text{${this.content}}`;
default:
throw new Error(`toString() is not implemented for type ${this.type}`);
}
}
serialize() {
switch (this.type) {
case "empty":
return [];
case "element": {
let c = this.content;
c = apply_escape_if_needed(c);
return [new TexToken(0 /* ELEMENT */, c)];
}
case "symbol":
return [new TexToken(1 /* COMMAND */, this.content)];
case "text":
return [new TexToken(2 /* TEXT */, this.content)];
case "comment":
return [new TexToken(3 /* COMMENT */, this.content)];
case "whitespace": {
const tokens = [];
for (const c of this.content) {
const token_type = c === " " ? 4 /* SPACE */ : 5 /* NEWLINE */;
tokens.push(new TexToken(token_type, c));
}
return tokens;
}
case "ordgroup": {
return this.args.map((n) => n.serialize()).flat();
}
case "unaryFunc": {
let tokens = [];
tokens.push(new TexToken(1 /* COMMAND */, this.content));
if (this.content === "\\sqrt" && this.data) {
tokens.push(new TexToken(0 /* ELEMENT */, "["));
tokens = tokens.concat(this.data.serialize());
tokens.push(new TexToken(0 /* ELEMENT */, "]"));
}
if (this.content === "\\operatorname" && this.args.length === 1 && this.args[0].type === "text") {
const text = this.args[0].content;
tokens.push(new TexToken(0 /* ELEMENT */, "{"));
tokens.push(new TexToken(1 /* COMMAND */, text));
tokens.push(new TexToken(0 /* ELEMENT */, "}"));
return tokens;
}
tokens.push(new TexToken(0 /* ELEMENT */, "{"));
tokens = tokens.concat(this.args[0].serialize());
tokens.push(new TexToken(0 /* ELEMENT */, "}"));
return tokens;
}
case "binaryFunc": {
let tokens = [];
tokens.push(new TexToken(1 /* COMMAND */, this.content));
tokens.push(new TexToken(0 /* ELEMENT */, "{"));
tokens = tokens.concat(this.args[0].serialize());
tokens.push(new TexToken(0 /* ELEMENT */, "}"));
tokens.push(new TexToken(0 /* ELEMENT */, "{"));
tokens = tokens.concat(this.args[1].serialize());
tokens.push(new TexToken(0 /* ELEMENT */, "}"));
return tokens;
}
case "supsub": {
let should_wrap_in_braces2 = function(node) {
if (node.type === "ordgroup" || node.type === "supsub" || node.type === "empty") {
return true;
} else if (node.type === "element" && /\d+(\.\d+)?/.test(node.content) && node.content.length > 1) {
return true;
} else {
return false;
}
};
var should_wrap_in_braces = should_wrap_in_braces2;
let tokens = [];
const { base, sup, sub } = this.data;
tokens = tokens.concat(base.serialize());
if (sub) {
tokens.push(new TexToken(6 /* CONTROL */, "_"));
if (should_wrap_in_braces2(sub)) {
tokens.push(new TexToken(0 /* ELEMENT */, "{"));
tokens = tokens.concat(sub.serialize());
tokens.push(new TexToken(0 /* ELEMENT */, "}"));
} else {
tokens = tokens.concat(sub.serialize());
}
}
if (sup) {
tokens.push(new TexToken(6 /* CONTROL */, "^"));
if (should_wrap_in_braces2(sup)) {
tokens.push(new TexToken(0 /* ELEMENT */, "{"));
tokens = tokens.concat(sup.serialize());
tokens.push(new TexToken(0 /* ELEMENT */, "}"));
} else {
tokens = tokens.concat(sup.serialize());
}
}
return tokens;
}
case "control": {
return [new TexToken(6 /* CONTROL */, this.content)];
}
case "beginend": {
let tokens = [];
const matrix = this.data;
tokens.push(new TexToken(1 /* COMMAND */, `\\begin{${this.content}}`));
tokens.push(new TexToken(5 /* NEWLINE */, "\n"));
for (let i = 0; i < matrix.length; i++) {
const row = matrix[i];
for (let j = 0; j < row.length; j++) {
const cell = row[j];
tokens = tokens.concat(cell.serialize());
if (j !== row.length - 1) {
tokens.push(new TexToken(6 /* CONTROL */, "&"));
}
}
if (i !== matrix.length - 1) {
tokens.push(new TexToken(6 /* CONTROL */, "\\\\"));
}
}
tokens.push(new TexToken(5 /* NEWLINE */, "\n"));
tokens.push(new TexToken(1 /* COMMAND */, `\\end{${this.content}}`));
return tokens;
}
default:
throw new Error("[TexNode.serialize] Unimplemented type: " + this.type);
}
}
};
var TypstToken = class {
constructor(type, content) {
this.type = type;
this.value = content;
}
eq(other) {
return this.type === other.type && this.value === other.value;
}
isOneOf(tokens) {
return array_includes(tokens, this);
}
toNode() {
switch (this.type) {
case 0 /* NONE */:
return new TypstNode("none", "#none");
case 3 /* TEXT */:
return new TypstNode("text", this.value);
case 4 /* COMMENT */:
return new TypstNode("comment", this.value);
case 5 /* SPACE */:
case 7 /* NEWLINE */:
return new TypstNode("whitespace", this.value);
case 2 /* ELEMENT */:
return new TypstNode("atom", this.value);
case 1 /* SYMBOL */:
return new TypstNode("symbol", this.value);
case 6 /* CONTROL */: {
const controlChar = this.value;
switch (controlChar) {
case "":
case "_":
case "^":
throw new Error(`Should not convert ${controlChar} to a node`);
case "&":
return new TypstNode("control", "&");
case "\\":
return new TypstNode("control", "\\");
default:
throw new Error(`Unexpected control character ${controlChar}`);
}
}
default:
throw new Error(`Unexpected token type ${this.type}`);
}
}
toString() {
switch (this.type) {
case 3 /* TEXT */:
return `"${this.value}"`;
case 4 /* COMMENT */:
return `//${this.value}`;
default:
return this.value;
}
}
};
var TypstNode = class {
constructor(type, content, args, data) {
this.type = type;
this.content = content;
this.args = args;
this.data = data;
}
setOptions(options) {
this.options = options;
}
// Note that this is only shallow equality.
eq(other) {
return this.type === other.type && this.content === other.content;
}
// whether the node is over high so that if it's wrapped in braces, \left and \right should be used in its TeX form
// e.g. 1/2 is over high, "2" is not.
isOverHigh() {
switch (this.type) {
case "fraction":
return true;
case "funcCall": {
if (this.content === "frac") {
return true;
}
return this.args.some((n) => n.isOverHigh());
}
case "group":
return this.args.some((n) => n.isOverHigh());
case "supsub":
return this.data.base.isOverHigh();
case "align":
case "cases":
case "matrix":
return true;
default:
return false;
}
}
};
var TYPST_NONE = new TypstNode("none", "#none");
var TYPST_TRUE = true;
// src/util.ts
function isalpha(char) {
return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(char);
}
function assert(condition, message = "") {
if (!condition) {
throw new Error(message);
}
}
// src/jslex.ts
var EOF = {};
function matchcompare(m1, m2) {
if (m2.len !== m1.len) {
return m2.len - m1.len;
} else {
return m1.index - m2.index;
}
}
var Scanner = class {
constructor(input, lexer) {
// position within input stream
this._pos = 0;
// current line number
this._line = 0;
// current column number
this._col = 0;
this._offset = 0;
this._less = null;
this._go = false;
this._newstate = null;
this._text = null;
this._leng = null;
this._input = input;
this._lexer = lexer;
this._state = lexer.states[0];
}
/**
* Analogous to yytext and yyleng in lex - will be set during scan.
*/
text() {
return this._text;
}
leng() {
return this._leng;
}
/**
* Position of in stream, line number and column number of match.
*/
pos() {
return this._pos;
}
line() {
return this._line;
}
column() {
return this._col;
}
/**
* Analogous to input() in lex.
* @return {string} The next character in the stream.
*/
input() {
return this._input.charAt(this._pos + this._leng + this._offset++);
}
/**
* Similar to unput() in lex, but does not allow modifying the stream.
* @return {int} The offset position after the operation.
*/
unput() {
return this._offset = this._offset > 0 ? this._offset-- : 0;
}
/**
* Analogous to yyless(n) in lex - retains the first n characters from this pattern, and returns
* the rest to the input stream, such that they will be used in the next pattern-matching operation.
* @param {int} n Number of characters to retain.
* @return {int} Length of the stream after the operation has completed.
*/
less(n) {
this._less = n;
this._offset = 0;
this._text = this._text.substring(0, n);
return this._leng = this._text.length;
}
/**
* Like less(), but instead of retaining the first n characters, it chops off the last n.
* @param {int} n Number of characters to chop.
* @return {int} Length of the stream after the operation has completed.
*/
pushback(n) {
return this.less(this._leng - n);
}
/**
* Similar to REJECT in lex, except it doesn't break the current execution context.
* TIP: reject() should be the last instruction in a spec callback.
*/
reject() {
this._go = true;
}
/**
* Analogous to BEGIN in lex - sets the named state (start condition).
* @param {string|int} state Name of state to switch to, or ordinal number (0 is first, etc).
* @return {string} The new state on successful switch, throws exception on failure.
*/
begin(state) {
if (this._lexer.specification[state]) {
return this._newstate = state;
}
const s = this._lexer.states[parseInt(state)];
if (s) {
return this._newstate = s;
}
throw "Unknown state '" + state + "' requested";
}
/**
* Simple accessor for reading in the current state.
* @return {string} The current state.
*/
state() {
return this._state;
}
/**
* Scan method to be returned to caller - grabs the next token and fires appropriate calback.
* @return {T} The next token extracted from the stream.
*/
scan() {
if (this._pos >= this._input.length) {
return EOF;
}
const str = this._input.substring(this._pos);
const rules = this._lexer.specification[this._state];
const matches = [];
for (let i = 0; i < rules.length; i++) {
const rule = rules[i];
const mt = str.match(rule.re);
if (mt !== null && mt[0].length > 0) {
matches.push({
index: i,
text: mt[0],
len: mt[0].length,
rule
});
}
}
if (matches.length === 0) {
throw new Error("No match found for input '" + str + "'");
}
matches.sort(matchcompare);
this._go = true;
let result;
let m;
for (let j = 0, n = matches.length; j < n && this._go; j++) {
this._offset = 0;
this._less = null;
this._go = false;
this._newstate = null;
m = matches[j];
this._text = m.text;
this._leng = m.len;
result = m.rule.action(this);
if (this._newstate && this._newstate != this._state) {
this._state = this._newstate;
break;
}
}
const text = this._less === null ? m.text : m.text.substring(0, this._less);
const len = text.length;
this._pos += len + this._offset;
const nlm = text.match(/\n/g);
if (nlm !== null) {
this._line += nlm.length;
this._col = len - text.lastIndexOf("\n") - 1;
} else {
this._col += len;
}
return result;
}
};
var JSLex = class {
constructor(spec3) {
this.states = Object.keys(spec3);
this.specification = {};
for (const s of this.states) {
const rule_map = spec3[s];
if (s in this.specification) {
throw "Duplicate state declaration encountered for state '" + s + "'";
}
this.specification[s] = [];
for (const [k, v] of rule_map.entries()) {
let re;
try {
re = new RegExp("^" + k);
} catch (err) {
throw "Invalid regexp '" + k + "' in state '" + s + "' (" + err.message + ")";
}
this.specification[s].push({
re,
action: v
});
}
}
}
/**
* Scanner function - makes a new scanner object which is used to get tokens one at a time.
* @param {string} input Input text to tokenize.
* @return {function} Scanner function.
*/
scanner(input) {
return new Scanner(input, this);
}
/**
* Similar to lex's yylex() function, consumes all input, calling calback for each token.
* @param {string} input Text to lex.
* @param {function} callback Function to execute for each token.
*/
lex(input, callback) {
const scanner = this.scanner(input);
while (true) {
const token = scanner.scan();
if (token === EOF) {
return;
}
if (token !== void 0) {
callback(token);
}
}
}
/**
* Consumes all input, collecting tokens along the way.
* @param {string} input Text to lex.
* @return {array} List of tokens, may contain an Error at the end.
*/
collect(input) {
const tokens = [];
const callback = function(item) {
if (Array.isArray(item)) {
tokens.push(...item);
} else {
tokens.push(item);
}
};
this.lex(input, callback);
return tokens;
}
};
// src/tex-parser.ts
var UNARY_COMMANDS = [
"sqrt",
"text",
"bar",
"bold",
"boldsymbol",
"ddot",
"dot",
"hat",
"mathbb",
"mathbf",
"mathcal",
"mathfrak",
"mathit",
"mathrm",
"mathscr",
"mathsf",
"mathtt",
"operatorname",
"overbrace",
"overline",
"pmb",
"rm",
"tilde",
"underbrace",
"underline",
"vec",
"widehat",
"widetilde",
"overleftarrow",
"overrightarrow",
"hspace"
];
var BINARY_COMMANDS = [
"frac",
"tfrac",
"binom",
"dbinom",
"dfrac",
"tbinom",
"overset"
];
var IGNORED_COMMANDS = [
"bigl",
"bigr",
"biggl",
"biggr",
"Bigl",
"Bigr",
"Biggl",
"Biggr"
];
var EMPTY_NODE = new TexNode("empty", "");
function get_command_param_num(command) {
if (UNARY_COMMANDS.includes(command)) {
return 1;
} else if (BINARY_COMMANDS.includes(command)) {
return 2;
} else {
return 0;
}
}
var LEFT_CURLY_BRACKET = new TexToken(6 /* CONTROL */, "{");
var RIGHT_CURLY_BRACKET = new TexToken(6 /* CONTROL */, "}");
var LEFT_SQUARE_BRACKET = new TexToken(0 /* ELEMENT */, "[");
var RIGHT_SQUARE_BRACKET = new TexToken(0 /* ELEMENT */, "]");
function eat_whitespaces(tokens, start) {
let pos = start;
while (pos < tokens.length && [4 /* SPACE */, 5 /* NEWLINE */].includes(tokens[pos].type)) {
pos++;
}
return tokens.slice(start, pos);
}
function eat_parenthesis(tokens, start) {
const firstToken = tokens[start];
if (firstToken.type === 0 /* ELEMENT */ && ["(", ")", "[", "]", "|", "\\{", "\\}", ".