Skip to content

Commit

Permalink
support more symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
qwinsi committed Aug 13, 2024
1 parent 4fef0e5 commit 116e5b0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 58 deletions.
64 changes: 26 additions & 38 deletions src/map.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const symbolMap = new Map<string, string>([
['gets', 'arrow.l'],
['infty', 'infinity'], // infinity
['nonumber', ''],
['vec', 'arrow'],
['mathbf', 'bold'],
Expand Down Expand Up @@ -46,40 +45,6 @@ export const symbolMap = new Map<string, string>([
['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
Expand All @@ -103,7 +68,6 @@ export const symbolMap = new Map<string, string>([
['longleftrightarrow', 'arrow.l.r.long'],
['rightrightarrows', 'arrows.rr'],

['binom', 'binom'],

/* left and right floor,ceil */
// tex: \lfloor \rfloor \lceil \rceil
Expand Down Expand Up @@ -193,12 +157,14 @@ export const symbolMap = new Map<string, string>([
['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'],
Expand All @@ -214,6 +180,7 @@ export const symbolMap = new Map<string, string>([
['ll', 'lt.double'],
['longmapsto', 'arrow.long.bar'],
['longrightarrow', 'arrow.long'],
['lor', 'or'],
['ltimes', 'times.l'],
['mapsto', 'arrow.bar'],
['measuredangle', 'angle.arc'],
Expand All @@ -227,14 +194,25 @@ export const symbolMap = new Map<string, string>([
['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'],
Expand Down Expand Up @@ -264,9 +242,14 @@ export const symbolMap = new Map<string, string>([
['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'],
Expand All @@ -277,19 +260,24 @@ export const symbolMap = new Map<string, string>([
['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'],
Expand Down
1 change: 1 addition & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
28 changes: 12 additions & 16 deletions test/cheat-sheet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
34 changes: 30 additions & 4 deletions test/cheat-sheet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"

0 comments on commit 116e5b0

Please sign in to comment.