diff --git a/src/map.ts b/src/map.ts index e0bb73d..43826be 100644 --- a/src/map.ts +++ b/src/map.ts @@ -1,6 +1,5 @@ export const symbolMap = new Map([ ['gets', 'arrow.l'], - ['infty', 'infinity'], // infinity ['nonumber', ''], ['vec', 'arrow'], ['mathbf', 'bold'], @@ -46,40 +45,6 @@ export const symbolMap = new Map([ ['otimes', 'times.circle'], ['boxtimes', 'times.square'], - /* symbols in mathematical logic */ - ['neg', 'not'], - ['land', 'and'], - ['lor', 'or'], - - ['varnothing', 'diameter'], // empty set - - /* symbols about comparing numbers */ - // tex: \neq \leq \geq \ll \gg \prec \succ \preceq \succeq - // typst: eq.not lt.eq gt.eq lt.double gt.double prec succ prec.eq succ.eq - ['neq', 'eq.not'], - ['leq', 'lt.eq'], - ['geq', 'gt.eq'], - ['ll', 'lt.double'], - ['gg', 'gt.double'], - ['prec', 'prec'], - ['succ', 'succ'], - ['preceq', 'prec.eq'], - ['succeq', 'succ.eq'], - - /* symbols about differential */ - ['Delta', 'Delta'], - ['nabla', 'nabla'], - ['partial', 'diff'], - - /* symbols about integral */ - // tex: \int \oint \iint \oiint \iiint \oiiint - // typst: integral integral.cont integral.double integral.surf integral.triple integral.vol - ['int', 'integral'], - ['oint', 'integral.cont'], - ['iint', 'integral.double'], - ['oiint', 'integral.surf'], - ['iiint', 'integral.triple'], - ['oiiint', 'integral.vol'], /* wave */ // tex: \sim \approx \cong \simeq \asymp \equiv \propto @@ -103,7 +68,6 @@ export const symbolMap = new Map([ ['longleftrightarrow', 'arrow.l.r.long'], ['rightrightarrows', 'arrows.rr'], - ['binom', 'binom'], /* left and right floor,ceil */ // tex: \lfloor \rfloor \lceil \rceil @@ -193,12 +157,14 @@ export const symbolMap = new Map([ ['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'], @@ -214,6 +180,7 @@ export const symbolMap = new Map([ ['ll', 'lt.double'], ['longmapsto', 'arrow.long.bar'], ['longrightarrow', 'arrow.long'], + ['lor', 'or'], ['ltimes', 'times.l'], ['mapsto', 'arrow.bar'], ['measuredangle', 'angle.arc'], @@ -227,14 +194,25 @@ export const symbolMap = new Map([ ['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'], - ['nleftarrow', 'arrow.l.not'], ['nrightarrow', 'arrow.not'], ['nsim', 'tilde.not'], + ['nsubseteq', 'subset.eq.not'], ['nu', 'nu'], + ['ntriangleleft', 'lt.tri.not'], + ['ntriangleright', 'gt.tri.not'], + ['nwarrow', 'arrow.tl'], ['odot', 'dot.circle'], ['oint', 'integral.cont'], + ['oiint', 'integral.surf'], + ['oiiint', 'integral.vol'], ['omega', 'omega'], // ['omicron', 'omicron'], ['ominus', 'minus.circle'], @@ -264,9 +242,14 @@ export const symbolMap = new Map([ ['sigma', 'sigma'], ['sim', 'tilde'], ['simeq', 'tilde.eq'], + ['slash', 'slash'], + ['smallsetminus', 'without'], // ['smile', 'paren.b'], + ['spadesuit', 'suit.spade'], ['sqcap', 'sect.sq'], ['sqcup', 'union.sq'], + ['sqsubseteq', 'subset.eq.sq'], + ['sqsupseteq', 'supset.eq.sq'], ['star', 'star'], ['subset', 'subset'], ['subseteq', 'subset.eq'], @@ -277,19 +260,24 @@ export const symbolMap = new Map([ ['supset', 'supset'], ['supseteq', 'supset.eq'], ['supsetneq', 'supset.neq'], + ['swarrow', 'arrow.bl'], ['tau', 'tau'], ['theta', 'theta'], ['times', 'times'], ['to', 'arrow.r'], + ['top', 'top'], ['triangle', 'triangle.t'], + ['triangledown', 'triangle.b.small'], ['triangleleft', 'triangle.l.small'], - ['triangleright', 'triangle.small'], + ['triangleright', 'triangle.r.small'], + ['twoheadrightarrow', 'arrow.r.twohead'], ['uparrow', 'arrow.t'], ['updownarrow', 'arrow.t.b'], ['upharpoonright', 'harpoon.tr'], ['uplus', 'union.plus'], ['upsilon', 'upsilon'], ['varepsilon', 'epsilon'], + ['varnothing', 'diameter'], // empty set ['varphi', 'phi'], ['varpi', 'pi.alt'], ['varrho', 'rho.alt'], diff --git a/src/parser.ts b/src/parser.ts index ef3fd3e..cdde996 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -253,6 +253,7 @@ export function parseTex(tex: string, customTexMacros: {[key: string]: string}): '\\jmath': '\\operatorname{SyMb01-jmath}', '\\vdots': '\\operatorname{SyMb01-vdots}', '\\notin': '\\operatorname{SyMb01-notin}', + '\\slash': '\\operatorname{SyMb01-slash}', ...customTexMacros }; const options = { diff --git a/test/cheat-sheet.test.ts b/test/cheat-sheet.test.ts index 2574b00..fa5638f 100644 --- a/test/cheat-sheet.test.ts +++ b/test/cheat-sheet.test.ts @@ -16,32 +16,28 @@ describe('cheat sheet', () => { expect(data.math_symbols).toBeDefined(); - describe('math_commands', () => { + test('math_commands', () => { expect(data.math_commands).toBeDefined(); for (const [key, value] of Object.entries(data.math_commands)) { - test(key, function () { - const input = `\\${key}{x}{y}`; - const expected1 = `${value} x y`; - const expected2 = `${value}(x) y`; - const expected3 = `${value}(x, y)`; - const result = tex2typst(input); - expect([expected1, expected2, expected3]).toContain(result); - }); + const input = `\\${key}{x}{y}`; + const expected1 = `${value} x y`; + const expected2 = `${value}(x) y`; + const expected3 = `${value}(x, y)`; + const result = tex2typst(input); + expect([expected1, expected2, expected3]).toContain(result); } }); - describe('math_symbols', () => { + test('math_symbols', () => { expect(data.math_symbols).toBeDefined(); for (const [key, value] of Object.entries(data.math_symbols)) { - test(key, function() { - const input = `\\${key}`; - const expected = value; - const result = tex2typst(input); - expect(result).toBe(expected); - }); + const input = `\\${key}`; + const expected = value; + const result = tex2typst(input); + expect(result).toBe(expected); } }); }); diff --git a/test/cheat-sheet.toml b/test/cheat-sheet.toml index 763bf11..66a43d2 100644 --- a/test/cheat-sheet.toml +++ b/test/cheat-sheet.toml @@ -136,12 +136,14 @@ iiiint = "intgral.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" @@ -166,22 +168,33 @@ mp = "minus.plus" mu = "mu" nRightarrow = "arrow.double.not" nabla = "nabla" +# natural = # Typst does not have a symbol for this ncong = "tilde.nequiv" ne = "eq.not" neg = "not" neq = "eq.not" +nexists = "exists.not" +ngeq = "gt.eq.not" +ni = "in.rev" +nleftarrow = "arrow.l.not" +nleq = "lt.eq.not" +nparallel = "parallel.not" nmid = "divides.not" notin = "in.not" -nleftarrow = "arrow.l.not" nrightarrow = "arrow.not" nsim = "tilde.not" +nsubseteq = "subset.eq.not" nu = "nu" +ntriangleleft = "lt.tri.not" +ntriangleright = "gt.tri.not" +nwarrow = "arrow.tl" odot = "dot.circle" oint = "integral.cont" omega = "omega" # omicron = "omicron" ominus = "minus.circle" oplus = "xor" # or "plus.circle" +# oslash = # Unfortunately Typst does not have a symbol for this otimes = "times.circle" parallel = "parallel" partial = "diff" @@ -198,18 +211,25 @@ psi = "psi" rangle = "angle.r" rbrace = "brace.r" rbrack = "bracket.r" +# rceil = "ceil.r" # Unfortunately Typst does not have a symbol for this +# rfloor = "floor.r" # Unfortunately Typst does not have a symbol for this rhd = "triangle" rho = "rho" rightarrow = "arrow.r" rightthreetimes = "times.three.r" rtimes = "times.r" -setminus = "without" +setminus = "without" # Not exactly. Ideally this should be something like "withoug.big" sigma = "sigma" sim = "tilde" simeq = "tilde.eq" -# smile = "paren.b" +slash = "slash" # or "\\/" # This symbol is not supported by Typst but supported by LaTeX +smallsetminus = "without" +# smile = "paren.b" # Typst does not have a symbol for this. "paren.b" just look like it but has different size. +spadesuit = "suit.spade" sqcap = "sect.sq" sqcup = "union.sq" +sqsubseteq = "subset.eq.sq" +sqsupseteq = "supset.eq.sq" star = "star" subset = "subset" subseteq = "subset.eq" @@ -220,13 +240,18 @@ sum = "sum" supset = "supset" supseteq = "supset.eq" supsetneq = "supset.neq" +# surd = # not supported by Typst +swarrow = "arrow.bl" tau = "tau" theta = "theta" times = "times" to = "arrow.r" +top = "top" triangle = "triangle.t" +triangledown = "triangle.b.small" triangleleft = "triangle.l.small" -triangleright = "triangle.small" +triangleright = "triangle.r.small" +twoheadrightarrow = "arrow.r.twohead" uparrow = "arrow.t" updownarrow = "arrow.t.b" upharpoonright = "harpoon.tr" @@ -242,6 +267,7 @@ vdash = "tack.r" vdots = "dots.v" vee = "or" wedge = "and" +# wp = # not supported by Typst wr = "wreath" xi = "xi" zeta = "zeta"