tex2typst 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +844 -22
- package/dist/parser.d.ts +1 -1
- package/dist/tex2typst.min.js +1 -0
- package/package.json +6 -2
- package/src/index.ts +3 -0
- package/src/map.ts +5 -8
- package/src/parser.ts +1 -1
- package/src/tex2typst.ts +9 -0
- package/src/writer.ts +13 -0
- package/tool/dist/dist/ka.js +13654 -0
- package/tool/dist/ka.js +13634 -0
- package/tsconfig.json +4 -3
- package/.github/workflows/github-ci.yml +0 -35
- package/dist/map.js +0 -291
- package/dist/parser.js +0 -265
- package/dist/types.js +0 -2
- package/dist/writer.js +0 -356
package/tsconfig.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
26
|
|
|
27
27
|
/* Modules */
|
|
28
|
-
"module": "
|
|
28
|
+
"module": "esnext", /* Specify what module code is generated. */
|
|
29
29
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
30
|
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
31
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
36
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
37
|
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
-
|
|
38
|
+
"allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
39
|
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
40
|
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
41
|
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
/* Emit */
|
|
52
52
|
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
53
|
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
|
-
|
|
54
|
+
"emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
55
|
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
56
56
|
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
57
57
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"src/**/*.ts"
|
|
110
110
|
],
|
|
111
111
|
"exclude": [
|
|
112
|
+
"src/tex2typst.ts",
|
|
112
113
|
"tests/**/*"
|
|
113
114
|
]
|
|
114
115
|
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
name: tex2typst Tests
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
- dev
|
|
7
|
-
pull_request:
|
|
8
|
-
branches:
|
|
9
|
-
- main
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
unit-tests:
|
|
13
|
-
name: Unit tests
|
|
14
|
-
runs-on: ${{ matrix.os }}
|
|
15
|
-
|
|
16
|
-
strategy:
|
|
17
|
-
matrix:
|
|
18
|
-
os: [ubuntu-latest]
|
|
19
|
-
node: [18]
|
|
20
|
-
|
|
21
|
-
steps:
|
|
22
|
-
- name: Checkout
|
|
23
|
-
uses: actions/checkout@v3
|
|
24
|
-
|
|
25
|
-
- name: Setup node env
|
|
26
|
-
uses: actions/setup-node@v4
|
|
27
|
-
with:
|
|
28
|
-
node-version: ${{ matrix.node }}
|
|
29
|
-
cache: 'yarn'
|
|
30
|
-
|
|
31
|
-
- name: Install dependencies
|
|
32
|
-
run: yarn install
|
|
33
|
-
|
|
34
|
-
- name: Run Vitest Test
|
|
35
|
-
run: npx vitest run
|
package/dist/map.js
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.symbolMap = void 0;
|
|
4
|
-
exports.symbolMap = new Map([
|
|
5
|
-
['gets', 'arrow.l'],
|
|
6
|
-
['nonumber', ''],
|
|
7
|
-
['vec', 'arrow'],
|
|
8
|
-
['mathbf', 'bold'],
|
|
9
|
-
['boldsymbol', 'bold'],
|
|
10
|
-
['mathfrak', 'frak'],
|
|
11
|
-
['neq', 'eq.not'],
|
|
12
|
-
['dot', 'dot'],
|
|
13
|
-
['ddot', 'dot.double'],
|
|
14
|
-
['doteq', 'dot(eq)'],
|
|
15
|
-
['dots', 'dots.h'],
|
|
16
|
-
['ldots', 'dots.h'],
|
|
17
|
-
['vdots', 'dots.v'],
|
|
18
|
-
['ddots', 'dots.down'],
|
|
19
|
-
['widehat', 'hat'], // Ideally, the result of \widehat should be longer than \hat. But it is not implemented now.
|
|
20
|
-
['widetilde', 'tilde'], // Ideally, the result of \widetilde should be longer than \tilde. But it is not implemented now.
|
|
21
|
-
['quad', 'quad'],
|
|
22
|
-
['qquad', 'wide'],
|
|
23
|
-
['overbrace', 'overbrace'], // same
|
|
24
|
-
['underbrace', 'underbrace'], // same
|
|
25
|
-
['overline', 'overline'], // same
|
|
26
|
-
['underline', 'underline'], // same
|
|
27
|
-
['bar', 'macron'],
|
|
28
|
-
['mathbb', 'bb'],
|
|
29
|
-
['mathcal', 'cal'],
|
|
30
|
-
// TODO: This result it not proper. A solution is define scr in Typst code:
|
|
31
|
-
// #let scr(a) = text(font: "STIX Two Math", stylistic-set: 01)[#math.cal(a)]
|
|
32
|
-
// https://qiita.com/Yarakashi_Kikohshi/items/b7beaa0fba62a527df2b
|
|
33
|
-
// https://github.com/typst/typst/issues/1431
|
|
34
|
-
['mathscr', 'cal'],
|
|
35
|
-
['mathrm', 'upright'],
|
|
36
|
-
['rm', 'upright'],
|
|
37
|
-
// TODO: \pmb need special logic to handle but it is not implemented now. See the commented test case.
|
|
38
|
-
['pmb', 'bold'],
|
|
39
|
-
/* variants of plus,minus,times,divide */
|
|
40
|
-
['pm', 'plus.minus'],
|
|
41
|
-
['mp', 'minus.plus'],
|
|
42
|
-
['oplus', 'xor'], // \oplus and also be plus.circle
|
|
43
|
-
['boxplus', 'plus.square'],
|
|
44
|
-
['otimes', 'times.circle'],
|
|
45
|
-
['boxtimes', 'times.square'],
|
|
46
|
-
/* wave */
|
|
47
|
-
// tex: \sim \approx \cong \simeq \asymp \equiv \propto
|
|
48
|
-
// typst: tilde approx tilde.equiv tilde.eq ≍ equiv prop
|
|
49
|
-
['sim', 'tilde'],
|
|
50
|
-
['approx', 'approx'],
|
|
51
|
-
['cong', 'tilde.equiv'],
|
|
52
|
-
['simeq', 'tilde.eq'],
|
|
53
|
-
['asymp', '≍'], // just use the unicode character :-)
|
|
54
|
-
['equiv', 'equiv'],
|
|
55
|
-
['propto', 'prop'],
|
|
56
|
-
/* arrows used in proofs */
|
|
57
|
-
// tex: \implies \iff \leftrightarrow \longleftrightarrow \rightrightarrows
|
|
58
|
-
// typst: arrow.r.double.long arrow.l.r.double.long arrow.l.r arrow.l.r.long arrows.rr
|
|
59
|
-
['implies', 'arrow.r.double.long'],
|
|
60
|
-
['Longrightarrow', 'arrow.r.double.long'], // Note: This macro is not supported by KaTeX
|
|
61
|
-
['iff', 'arrow.l.r.double.long'],
|
|
62
|
-
['Longleftrightarrow', 'arrow.l.r.double.long'], // Note: This macro is not supported by KaTeX
|
|
63
|
-
['leftrightarrow', 'arrow.l.r'],
|
|
64
|
-
['longleftrightarrow', 'arrow.l.r.long'],
|
|
65
|
-
['rightrightarrows', 'arrows.rr'],
|
|
66
|
-
/* left and right floor,ceil */
|
|
67
|
-
// tex: \lfloor \rfloor \lceil \rceil
|
|
68
|
-
// typst: ⌊ ⌋ ⌈ ⌉
|
|
69
|
-
// TODO: Ideally, \lfloor x \rfloor should be translated to floor(x) but it is not implemented now.
|
|
70
|
-
// The KaTeX parser parses it as \lfloor x \rfloor. So it would take some effort to implement it.
|
|
71
|
-
['lfloor', '⌊'],
|
|
72
|
-
['rfloor', '⌋'],
|
|
73
|
-
['lceil', '⌈'],
|
|
74
|
-
['rceil', '⌉'],
|
|
75
|
-
['Cap', 'sect.double'],
|
|
76
|
-
['Cup', 'union.double'],
|
|
77
|
-
['Delta', 'Delta'],
|
|
78
|
-
['Gamma', 'Gamma'],
|
|
79
|
-
['Join', 'join'],
|
|
80
|
-
['Lambda', 'Lambda'],
|
|
81
|
-
['Longrightarrow', 'arrow.r.double.long'],
|
|
82
|
-
['Omega', 'Omega'],
|
|
83
|
-
['Phi', 'Phi'],
|
|
84
|
-
['Pi', 'Pi'],
|
|
85
|
-
['Psi', 'Psi'],
|
|
86
|
-
['Rightarrow', 'arrow.double'],
|
|
87
|
-
['Sigma', 'Sigma'],
|
|
88
|
-
['Theta', 'Theta'],
|
|
89
|
-
['aleph', 'alef'],
|
|
90
|
-
['alpha', 'alpha'],
|
|
91
|
-
// ['amalg', 'product.co'],
|
|
92
|
-
['angle', 'angle'],
|
|
93
|
-
['approx', 'approx'],
|
|
94
|
-
['approxeq', 'approx.eq'],
|
|
95
|
-
['ast', 'ast'],
|
|
96
|
-
['beta', 'beta'],
|
|
97
|
-
['bigcap', 'sect.big'],
|
|
98
|
-
['bigcirc', 'circle.big'],
|
|
99
|
-
['bigcup', 'union.big'],
|
|
100
|
-
['bigodot', 'dot.circle.big'],
|
|
101
|
-
['bigoplus', 'xor.big'], // or "plus.circle.big"
|
|
102
|
-
['bigotimes', 'times.circle.big'],
|
|
103
|
-
['bigsqcup', 'union.sq.big'],
|
|
104
|
-
['bigtriangledown', 'triangle.b'],
|
|
105
|
-
['bigtriangleup', 'triangle.t'],
|
|
106
|
-
['biguplus', 'union.plus.big'],
|
|
107
|
-
['bigvee', 'or.big'],
|
|
108
|
-
['bigwedge', 'and.big'],
|
|
109
|
-
// ['bowtie', 'join'],
|
|
110
|
-
['bullet', 'bullet'],
|
|
111
|
-
['cap', 'sect'],
|
|
112
|
-
['cdot', 'dot.op'], // 'dot.op' or 'dot.c'
|
|
113
|
-
['cdots', 'dots.c'],
|
|
114
|
-
['checkmark', 'checkmark'],
|
|
115
|
-
['chi', 'chi'],
|
|
116
|
-
['circ', 'circle.small'], // 'circle.small' or 'compose'
|
|
117
|
-
['colon', 'colon'],
|
|
118
|
-
['cong', 'tilde.equiv'],
|
|
119
|
-
['coprod', 'product.co'],
|
|
120
|
-
['cup', 'union'],
|
|
121
|
-
['curlyvee', 'or.curly'],
|
|
122
|
-
['curlywedge', 'and.curly'],
|
|
123
|
-
['dagger', 'dagger'],
|
|
124
|
-
['dashv', 'tack.l'],
|
|
125
|
-
['ddagger', 'dagger.double'],
|
|
126
|
-
['delta', 'delta'],
|
|
127
|
-
['ddots', 'dots.down'],
|
|
128
|
-
['diamond', 'diamond'],
|
|
129
|
-
['div', 'div'],
|
|
130
|
-
['divideontimes', 'times.div'],
|
|
131
|
-
['dotplus', 'plus.dot'],
|
|
132
|
-
['downarrow', 'arrow.b'],
|
|
133
|
-
['ell', 'ell'],
|
|
134
|
-
['emptyset', 'nothing'],
|
|
135
|
-
['epsilon', 'epsilon.alt'],
|
|
136
|
-
['equiv', 'equiv'],
|
|
137
|
-
['eta', 'eta'],
|
|
138
|
-
['exists', 'exists'],
|
|
139
|
-
['forall', 'forall'],
|
|
140
|
-
// ['frown', 'paren.t'],
|
|
141
|
-
['gamma', 'gamma'],
|
|
142
|
-
['ge', 'gt.eq'],
|
|
143
|
-
['geq', 'gt.eq'],
|
|
144
|
-
['geqslant', 'gt.eq.slant'],
|
|
145
|
-
['gg', 'gt.double'],
|
|
146
|
-
['hbar', 'planck.reduce'],
|
|
147
|
-
['imath', 'dotless.i'],
|
|
148
|
-
['iiiint', 'intgral.quad'],
|
|
149
|
-
['iiint', 'integral.triple'],
|
|
150
|
-
['iint', 'integral.double'],
|
|
151
|
-
['in', 'in'],
|
|
152
|
-
['infty', 'infinity'],
|
|
153
|
-
['int', 'integral'],
|
|
154
|
-
['intercal', 'top'], // 'top' or 'tack.b'
|
|
155
|
-
['iota', 'iota'],
|
|
156
|
-
['jmath', 'dotless.j'],
|
|
157
|
-
['kappa', 'kappa'],
|
|
158
|
-
['lambda', 'lambda'],
|
|
159
|
-
['land', 'and'],
|
|
160
|
-
['langle', 'angle.l'],
|
|
161
|
-
['lbrace', 'brace.l'],
|
|
162
|
-
['lbrack', 'bracket.l'],
|
|
163
|
-
['ldots', 'dots.l'],
|
|
164
|
-
['le', 'lt.eq'],
|
|
165
|
-
['leadsto', 'arrow.squiggly'],
|
|
166
|
-
['leftarrow', 'arrow.l'],
|
|
167
|
-
['leftthreetimes', 'times.three.l'],
|
|
168
|
-
['leftrightarrow', 'arrow.l.r'],
|
|
169
|
-
['leq', 'lt.eq'],
|
|
170
|
-
['leqslant', 'lt.eq.slant'],
|
|
171
|
-
['lhd', 'triangle.l'],
|
|
172
|
-
['ll', 'lt.double'],
|
|
173
|
-
['longmapsto', 'arrow.long.bar'],
|
|
174
|
-
['longrightarrow', 'arrow.long'],
|
|
175
|
-
['lor', 'or'],
|
|
176
|
-
['ltimes', 'times.l'],
|
|
177
|
-
['mapsto', 'arrow.bar'],
|
|
178
|
-
['measuredangle', 'angle.arc'],
|
|
179
|
-
['mid', 'divides'],
|
|
180
|
-
['models', 'models'],
|
|
181
|
-
['mp', 'minus.plus'],
|
|
182
|
-
['mu', 'mu'],
|
|
183
|
-
['nRightarrow', 'arrow.double.not'],
|
|
184
|
-
['nabla', 'nabla'],
|
|
185
|
-
['ncong', 'tilde.nequiv'],
|
|
186
|
-
['ne', 'eq.not'],
|
|
187
|
-
['neg', 'not'],
|
|
188
|
-
['neq', 'eq.not'],
|
|
189
|
-
['nexists', 'exists.not'],
|
|
190
|
-
['ni', "in.rev"],
|
|
191
|
-
['nleftarrow', "arrow.l.not"],
|
|
192
|
-
['nleq', "lt.eq.not"],
|
|
193
|
-
['nparallel', "parallel.not"],
|
|
194
|
-
['ngeq', 'gt.eq.not'],
|
|
195
|
-
['nmid', 'divides.not'],
|
|
196
|
-
['notin', 'in.not'],
|
|
197
|
-
['nrightarrow', 'arrow.not'],
|
|
198
|
-
['nsim', 'tilde.not'],
|
|
199
|
-
['nsubseteq', 'subset.eq.not'],
|
|
200
|
-
['nu', 'nu'],
|
|
201
|
-
['ntriangleleft', 'lt.tri.not'],
|
|
202
|
-
['ntriangleright', 'gt.tri.not'],
|
|
203
|
-
['nwarrow', 'arrow.tl'],
|
|
204
|
-
['odot', 'dot.circle'],
|
|
205
|
-
['oint', 'integral.cont'],
|
|
206
|
-
['oiint', 'integral.surf'],
|
|
207
|
-
['oiiint', 'integral.vol'],
|
|
208
|
-
['omega', 'omega'],
|
|
209
|
-
// ['omicron', 'omicron'],
|
|
210
|
-
['ominus', 'minus.circle'],
|
|
211
|
-
['oplus', 'xor'], // or 'plus.circle'
|
|
212
|
-
['otimes', 'times.circle'],
|
|
213
|
-
['parallel', 'parallel'],
|
|
214
|
-
['partial', 'diff'],
|
|
215
|
-
['perp', 'perp'],
|
|
216
|
-
['phi', 'phi.alt'],
|
|
217
|
-
['pi', 'pi'],
|
|
218
|
-
['pm', 'plus.minus'],
|
|
219
|
-
['pounds', 'pound'],
|
|
220
|
-
['prec', 'prec'],
|
|
221
|
-
['preceq', 'prec.eq'],
|
|
222
|
-
['prime', 'prime'],
|
|
223
|
-
['prod', 'product'],
|
|
224
|
-
['propto', 'prop'],
|
|
225
|
-
['psi', 'psi'],
|
|
226
|
-
['rangle', 'angle.r'],
|
|
227
|
-
['rbrace', 'brace.r'],
|
|
228
|
-
['rbrack', 'bracket.r'],
|
|
229
|
-
['rhd', 'triangle'],
|
|
230
|
-
['rho', 'rho'],
|
|
231
|
-
['rightarrow', 'arrow.r'],
|
|
232
|
-
['rightthreetimes', 'times.three.r'],
|
|
233
|
-
['rtimes', 'times.r'],
|
|
234
|
-
['setminus', 'without'],
|
|
235
|
-
['sigma', 'sigma'],
|
|
236
|
-
['sim', 'tilde'],
|
|
237
|
-
['simeq', 'tilde.eq'],
|
|
238
|
-
['slash', 'slash'],
|
|
239
|
-
['smallsetminus', 'without'],
|
|
240
|
-
// ['smile', 'paren.b'],
|
|
241
|
-
['spadesuit', 'suit.spade'],
|
|
242
|
-
['sqcap', 'sect.sq'],
|
|
243
|
-
['sqcup', 'union.sq'],
|
|
244
|
-
['sqsubseteq', 'subset.eq.sq'],
|
|
245
|
-
['sqsupseteq', 'supset.eq.sq'],
|
|
246
|
-
['star', 'star'],
|
|
247
|
-
['subset', 'subset'],
|
|
248
|
-
['subseteq', 'subset.eq'],
|
|
249
|
-
['subsetneq', 'subset.neq'],
|
|
250
|
-
['succ', 'succ'],
|
|
251
|
-
['succeq', 'succ.eq'],
|
|
252
|
-
['sum', 'sum'],
|
|
253
|
-
['supset', 'supset'],
|
|
254
|
-
['supseteq', 'supset.eq'],
|
|
255
|
-
['supsetneq', 'supset.neq'],
|
|
256
|
-
['swarrow', 'arrow.bl'],
|
|
257
|
-
['tau', 'tau'],
|
|
258
|
-
['theta', 'theta'],
|
|
259
|
-
['times', 'times'],
|
|
260
|
-
['to', 'arrow.r'],
|
|
261
|
-
['top', 'top'],
|
|
262
|
-
['triangle', 'triangle.t'],
|
|
263
|
-
['triangledown', 'triangle.b.small'],
|
|
264
|
-
['triangleleft', 'triangle.l.small'],
|
|
265
|
-
['triangleright', 'triangle.r.small'],
|
|
266
|
-
['twoheadrightarrow', 'arrow.r.twohead'],
|
|
267
|
-
['uparrow', 'arrow.t'],
|
|
268
|
-
['updownarrow', 'arrow.t.b'],
|
|
269
|
-
['upharpoonright', 'harpoon.tr'],
|
|
270
|
-
['uplus', 'union.plus'],
|
|
271
|
-
['upsilon', 'upsilon'],
|
|
272
|
-
['varepsilon', 'epsilon'],
|
|
273
|
-
['varnothing', 'diameter'], // empty set
|
|
274
|
-
['varphi', 'phi'],
|
|
275
|
-
['varpi', 'pi.alt'],
|
|
276
|
-
['varrho', 'rho.alt'],
|
|
277
|
-
['varsigma', 'sigma.alt'],
|
|
278
|
-
['vartheta', 'theta.alt'],
|
|
279
|
-
['vdash', 'tack.r'],
|
|
280
|
-
['vdots', 'dots.v'],
|
|
281
|
-
['vee', 'or'],
|
|
282
|
-
['wedge', 'and'],
|
|
283
|
-
['wr', 'wreath'],
|
|
284
|
-
['xi', 'xi'],
|
|
285
|
-
['yen', 'yen'],
|
|
286
|
-
['zeta', 'zeta'],
|
|
287
|
-
// extended
|
|
288
|
-
['mathscr', 'scr'],
|
|
289
|
-
['LaTeX', '#LaTeX'],
|
|
290
|
-
['TeX', '#TeX'],
|
|
291
|
-
]);
|
package/dist/parser.js
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.KatexNodeToTexNodeError = void 0;
|
|
7
|
-
exports.katexNodeToTexNode = katexNodeToTexNode;
|
|
8
|
-
exports.parseTex = parseTex;
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const katex_1 = __importDefault(require("katex"));
|
|
11
|
-
const generateParseTree = katex_1.default.__parse;
|
|
12
|
-
class KatexNodeToTexNodeError extends Error {
|
|
13
|
-
constructor(message, node) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = "KatexNodeToTexNodeError";
|
|
16
|
-
this.node = node;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.KatexNodeToTexNodeError = KatexNodeToTexNodeError;
|
|
20
|
-
function katexNodeToTexNode(node) {
|
|
21
|
-
try {
|
|
22
|
-
if (node.loc) {
|
|
23
|
-
delete node.loc;
|
|
24
|
-
}
|
|
25
|
-
let res = {};
|
|
26
|
-
switch (node.type) {
|
|
27
|
-
case 'atom':
|
|
28
|
-
// basic symbol like +, -, =, '(', ')', '\{', '\}'
|
|
29
|
-
// other punctuation-like macro such as \cdot, \to, \pm
|
|
30
|
-
res.type = 'atom';
|
|
31
|
-
res.content = node.text;
|
|
32
|
-
if (node.text === '\\{' || node.text === '\\}') {
|
|
33
|
-
res.content = node.text.substring(1); // '{' or '}'
|
|
34
|
-
}
|
|
35
|
-
else if (node.text.startsWith('\\')) {
|
|
36
|
-
res.type = 'symbol';
|
|
37
|
-
}
|
|
38
|
-
break;
|
|
39
|
-
case 'mathord':
|
|
40
|
-
// basic variable like a, b, c
|
|
41
|
-
// macro variable like \alpha, \beta, \gamma
|
|
42
|
-
case 'textord':
|
|
43
|
-
// - constant number like 1, 2, 3
|
|
44
|
-
// - operator symbol like \nabla, \partial
|
|
45
|
-
case 'op':
|
|
46
|
-
// \lim, \sum
|
|
47
|
-
case 'cr':
|
|
48
|
-
// new line symbol '\\'
|
|
49
|
-
res.type = 'symbol';
|
|
50
|
-
res.content = node.text;
|
|
51
|
-
if (node.type === 'op') {
|
|
52
|
-
res.content = node['name'];
|
|
53
|
-
}
|
|
54
|
-
else if (node.type === 'cr') {
|
|
55
|
-
res.content = '\\\\';
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
case 'genfrac':
|
|
59
|
-
res.type = 'binaryFunc';
|
|
60
|
-
if (node['leftDelim'] === '(' && node['rightDelim'] === ')') {
|
|
61
|
-
// This occurs for \binom \tbinom
|
|
62
|
-
res.content = '\\binom';
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
res.content = '\\frac';
|
|
66
|
-
}
|
|
67
|
-
res.args = [
|
|
68
|
-
katexNodeToTexNode(node['numer']),
|
|
69
|
-
katexNodeToTexNode(node['denom'])
|
|
70
|
-
];
|
|
71
|
-
break;
|
|
72
|
-
case 'supsub':
|
|
73
|
-
res.type = 'supsub';
|
|
74
|
-
res.irregularData = {};
|
|
75
|
-
if (node['base']) {
|
|
76
|
-
res.irregularData.base = katexNodeToTexNode(node['base']);
|
|
77
|
-
}
|
|
78
|
-
if (node['sup']) {
|
|
79
|
-
res.irregularData.sup = katexNodeToTexNode(node['sup']);
|
|
80
|
-
}
|
|
81
|
-
if (node['sub']) {
|
|
82
|
-
res.irregularData.sub = katexNodeToTexNode(node['sub']);
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
case 'mclass':
|
|
86
|
-
case 'ordgroup':
|
|
87
|
-
res.type = 'ordgroup';
|
|
88
|
-
res.args = node.body.map((n) => katexNodeToTexNode(n));
|
|
89
|
-
if (res.args.length === 1) {
|
|
90
|
-
res = res.args[0];
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
case 'leftright': {
|
|
94
|
-
const body = katexNodeToTexNode({
|
|
95
|
-
type: 'ordgroup',
|
|
96
|
-
mode: 'math',
|
|
97
|
-
body: node.body
|
|
98
|
-
});
|
|
99
|
-
res.type = 'leftright';
|
|
100
|
-
let left = node['left'];
|
|
101
|
-
if (left === "\\{") {
|
|
102
|
-
left = "{";
|
|
103
|
-
}
|
|
104
|
-
let right = node['right'];
|
|
105
|
-
if (right === "\\}") {
|
|
106
|
-
right = "}";
|
|
107
|
-
}
|
|
108
|
-
const is_atom = (str) => (['(', ')', '[', ']', '{', '}'].includes(str));
|
|
109
|
-
res.args = [
|
|
110
|
-
{ type: is_atom(left) ? 'atom' : 'symbol', content: left },
|
|
111
|
-
body,
|
|
112
|
-
{ type: is_atom(right) ? 'atom' : 'symbol', content: right }
|
|
113
|
-
];
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
case 'underline':
|
|
117
|
-
case 'overline':
|
|
118
|
-
res.type = 'unaryFunc';
|
|
119
|
-
res.content = '\\' + node.type;
|
|
120
|
-
res.args = [
|
|
121
|
-
katexNodeToTexNode(node['body'])
|
|
122
|
-
];
|
|
123
|
-
break;
|
|
124
|
-
case 'accent': {
|
|
125
|
-
res.type = 'unaryFunc';
|
|
126
|
-
res.content = node['label'];
|
|
127
|
-
res.args = [
|
|
128
|
-
katexNodeToTexNode(node['base'])
|
|
129
|
-
];
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
case 'sqrt':
|
|
133
|
-
if (node['index']) {
|
|
134
|
-
// There is a [] after \sqrt
|
|
135
|
-
// \sqrt[some thing]{}
|
|
136
|
-
res.irregularData = katexNodeToTexNode(node['index']);
|
|
137
|
-
}
|
|
138
|
-
// Fall through
|
|
139
|
-
case 'font':
|
|
140
|
-
case 'operatorname':
|
|
141
|
-
res.type = 'unaryFunc';
|
|
142
|
-
res.content = ('\\' + node.type);
|
|
143
|
-
if (node.type === 'font') {
|
|
144
|
-
res.content = '\\' + node['font']; // e.g. \mathbf, \mathrm
|
|
145
|
-
}
|
|
146
|
-
if (Array.isArray(node.body)) {
|
|
147
|
-
const obj = {
|
|
148
|
-
type: 'ordgroup',
|
|
149
|
-
mode: 'math',
|
|
150
|
-
body: node.body
|
|
151
|
-
};
|
|
152
|
-
res.args = [
|
|
153
|
-
katexNodeToTexNode(obj)
|
|
154
|
-
];
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
res.args = [
|
|
158
|
-
katexNodeToTexNode(node.body)
|
|
159
|
-
];
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
case 'horizBrace':
|
|
163
|
-
res.type = 'unaryFunc';
|
|
164
|
-
res.content = node['label']; // '\\overbrace' or '\\unerbrace'
|
|
165
|
-
res.args = [
|
|
166
|
-
katexNodeToTexNode(node['base']),
|
|
167
|
-
];
|
|
168
|
-
break;
|
|
169
|
-
case 'array':
|
|
170
|
-
if (node['colSeparationType'] === 'align') {
|
|
171
|
-
// align environment
|
|
172
|
-
res.type = 'align';
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
res.type = 'matrix';
|
|
176
|
-
}
|
|
177
|
-
res.irregularData = node.body.map((row) => {
|
|
178
|
-
return row.map((cell) => {
|
|
179
|
-
if (cell.type !== 'styling' || cell.body.length !== 1) {
|
|
180
|
-
throw new KatexNodeToTexNodeError("Expecting cell.type==='\\styling' and cell.body.length===1", cell);
|
|
181
|
-
}
|
|
182
|
-
return katexNodeToTexNode(cell.body[0]);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
break;
|
|
186
|
-
case 'text': {
|
|
187
|
-
res.type = 'text';
|
|
188
|
-
let str = "";
|
|
189
|
-
node.body.forEach((n) => {
|
|
190
|
-
if (n.mode !== 'text') {
|
|
191
|
-
throw new KatexNodeToTexNodeError("Expecting node.mode==='text'", node);
|
|
192
|
-
}
|
|
193
|
-
str += n.text;
|
|
194
|
-
});
|
|
195
|
-
res.content = str;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
case 'spacing':
|
|
199
|
-
// res.type = 'spacing';
|
|
200
|
-
// res.content = node.text! as string;
|
|
201
|
-
// break;
|
|
202
|
-
case 'kern':
|
|
203
|
-
// This can occur for \implies, \iff.
|
|
204
|
-
// e.g. \implies is parsed as [{type:'kern'}, {type:'atom', text:'\\Longrightarrow'}, {type:'kern'}]
|
|
205
|
-
// TODO: Ideally, we should output a single symbol \implies.
|
|
206
|
-
// But for now, we simply let the output be \Longrightarrow
|
|
207
|
-
res.type = 'empty';
|
|
208
|
-
res.content = ' ';
|
|
209
|
-
break;
|
|
210
|
-
case 'htmlmathml': {
|
|
211
|
-
// This can occur for \neq.
|
|
212
|
-
const element = node['mathml'][0]['body'][0];
|
|
213
|
-
if (element && element.type === 'textord' && element.text === '≠') {
|
|
214
|
-
res.type = 'symbol';
|
|
215
|
-
res.content = '\\neq';
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
// Fall through to throw error
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
case 'color':
|
|
223
|
-
// KaTeX encounters an unrecognized macro.
|
|
224
|
-
if (Array.isArray(node.body) && node.body.length === 1) {
|
|
225
|
-
const sub_body = node.body[0];
|
|
226
|
-
if (sub_body.type === 'text') {
|
|
227
|
-
res.type = 'unknownMacro';
|
|
228
|
-
const joined = sub_body.body.map((n) => n.text).join('');
|
|
229
|
-
if (/^\\[a-zA-Z]+$/.test(joined)) {
|
|
230
|
-
res.content = joined.substring(1);
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
throw new KatexNodeToTexNodeError(`Unknown error type in parsed result:`, node);
|
|
236
|
-
default:
|
|
237
|
-
throw new KatexNodeToTexNodeError(`Unknown node type: ${node.type}`, node);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
return res;
|
|
241
|
-
}
|
|
242
|
-
catch (e) {
|
|
243
|
-
throw e;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
function parseTex(tex, customTexMacros) {
|
|
247
|
-
// displayMode=true. Otherwise, "KaTeX parse error: {align*} can be used only in display mode."
|
|
248
|
-
const macros = Object.assign({
|
|
249
|
-
// KaTeX parse these commands so complicatedly that we need some hacks to keep things simple.
|
|
250
|
-
'\\mod': '\\operatorname{SyMb01-mod}', '\\liminf': '\\operatorname{SyMb01-liminf}', '\\limsup': '\\operatorname{SyMb01-limsup}', '\\qquad': '\\operatorname{SyMb01-qquad}', '\\quad': '\\operatorname{SyMb01-quad}', '\\cdots': '\\operatorname{SyMb01-cdots}', '\\colon': '\\operatorname{SyMb01-colon}', '\\imath': '\\operatorname{SyMb01-imath}', '\\\iiiint': '\\operatorname{SyMb01-iiiint}', '\\jmath': '\\operatorname{SyMb01-jmath}', '\\vdots': '\\operatorname{SyMb01-vdots}', '\\notin': '\\operatorname{SyMb01-notin}', '\\slash': '\\operatorname{SyMb01-slash}', '\\LaTeX': '\\operatorname{SyMb01-LaTeX}', '\\TeX': '\\operatorname{SyMb01-TeX}' }, customTexMacros);
|
|
251
|
-
const options = {
|
|
252
|
-
macros: macros,
|
|
253
|
-
displayMode: true,
|
|
254
|
-
strict: "ignore",
|
|
255
|
-
throwOnError: false
|
|
256
|
-
};
|
|
257
|
-
let treeArray = generateParseTree(tex, options);
|
|
258
|
-
let t = {
|
|
259
|
-
type: 'ordgroup',
|
|
260
|
-
mode: 'math',
|
|
261
|
-
body: treeArray,
|
|
262
|
-
loc: {}
|
|
263
|
-
};
|
|
264
|
-
return katexNodeToTexNode(t);
|
|
265
|
-
}
|
package/dist/types.js
DELETED