tex2typst 0.1.20 → 0.2.0
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 +3 -1
- package/dist/index.js +574 -229
- package/dist/parser.d.ts +18 -5
- package/dist/tex2typst.min.js +1 -1
- package/dist/types.d.ts +10 -5
- package/package.json +1 -1
- package/src/map.ts +4 -0
- package/src/parser.ts +689 -272
- package/src/types.ts +11 -5
- package/src/writer.ts +4 -9
- package/tsconfig.json +1 -1
package/src/types.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface LatexParseNode {
|
|
2
2
|
type: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
content?: string;
|
|
4
|
+
arg1?: LatexParseNode;
|
|
5
|
+
arg2?: LatexParseNode;
|
|
6
|
+
args?: LatexParseNode[];
|
|
7
|
+
base?: LatexParseNode;
|
|
8
|
+
sub?: LatexParseNode;
|
|
9
|
+
sup?: LatexParseNode;
|
|
10
|
+
exponent?: LatexParseNode;
|
|
11
|
+
body?: LatexParseNode | LatexParseNode[] | LatexParseNode[][];
|
|
7
12
|
}
|
|
8
13
|
|
|
14
|
+
|
|
9
15
|
export interface TexSupsubData {
|
|
10
16
|
base: TexNode;
|
|
11
17
|
sup?: TexNode;
|
package/src/writer.ts
CHANGED
|
@@ -103,7 +103,7 @@ export class TypstWriter {
|
|
|
103
103
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (
|
|
106
|
+
if (base.type === 'empty') {
|
|
107
107
|
this.queue.push({ type: 'text', content: '' });
|
|
108
108
|
} else {
|
|
109
109
|
this.appendWithBracketsIfNeeded(base);
|
|
@@ -210,14 +210,6 @@ export class TypstWriter {
|
|
|
210
210
|
if (this.preferTypstIntrinsic && TYPST_INTRINSIC_SYMBOLS.includes(text)) {
|
|
211
211
|
// e.g. we prefer just sech over op("sech")
|
|
212
212
|
this.queue.push({ type: 'symbol', content: text});
|
|
213
|
-
} else if (text.startsWith('SyMb01-')) {
|
|
214
|
-
// special hacks made in parseTex()
|
|
215
|
-
const special_symbol = text.substring(7);
|
|
216
|
-
if (special_symbol === 'newline') {
|
|
217
|
-
this.queue.push({ type: 'newline', content: '\n'});
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
this.queue.push({ type: 'symbol', content: '\\' + special_symbol});
|
|
221
213
|
} else {
|
|
222
214
|
this.queue.push({ type: 'symbol', content: 'op' });
|
|
223
215
|
this.queue.push({ type: 'atom', content: '('});
|
|
@@ -233,6 +225,9 @@ export class TypstWriter {
|
|
|
233
225
|
this.append(arg0);
|
|
234
226
|
this.queue.push({ type: 'atom', content: ')'});
|
|
235
227
|
this.insideFunctionDepth --;
|
|
228
|
+
} else if (node.type === 'newline') {
|
|
229
|
+
this.queue.push({ type: 'newline', content: '\n'});
|
|
230
|
+
return;
|
|
236
231
|
} else if (node.type === 'align') {
|
|
237
232
|
const matrix = node.irregularData as TexNode[][];
|
|
238
233
|
matrix.forEach((row, i) => {
|
package/tsconfig.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
12
|
|
|
13
13
|
/* Language and Environment */
|
|
14
|
-
"target": "
|
|
14
|
+
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
15
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
16
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
17
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|