tex2typst 0.3.26 → 0.3.27-beta.1
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/dist/index.d.ts +24 -6
- package/dist/index.js +80 -35
- package/dist/tex2typst.min.js +9 -9
- package/package.json +6 -7
- package/src/convert.ts +3 -4
- package/src/exposed-types.ts +24 -0
- package/src/index.ts +2 -2
- package/src/tex-types.ts +1 -17
- package/tsconfig.json +7 -12
- package/dist/convert.d.ts +0 -9
- package/dist/generic.d.ts +0 -9
- package/dist/jslex.d.ts +0 -107
- package/dist/map.d.ts +0 -5
- package/dist/tex-parser.d.ts +0 -23
- package/dist/tex-tokenizer.d.ts +0 -4
- package/dist/tex-types.d.ts +0 -107
- package/dist/tex-writer.d.ts +0 -8
- package/dist/typst-parser.d.ts +0 -23
- package/dist/typst-shorthands.d.ts +0 -3
- package/dist/typst-tokenizer.d.ts +0 -2
- package/dist/typst-types.d.ts +0 -98
- package/dist/typst-writer.d.ts +0 -30
- package/dist/util.d.ts +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* ATTENTION:
|
|
4
|
+
* Don't use any options except those explicitly documented in
|
|
5
|
+
* https://github.com/qwinsi/tex2typst/blob/main/docs/api-reference.md
|
|
6
|
+
* Any undocumented options may be not working at present or break in the future!
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface Tex2TypstOptions {
|
|
10
|
+
nonStrict?: boolean; /** default is true */
|
|
11
|
+
preferShorthands?: boolean; /** default is true */
|
|
12
|
+
keepSpaces?: boolean; /** default is false */
|
|
13
|
+
fracToSlash?: boolean; /** default is true */
|
|
14
|
+
inftyToOo?: boolean; /** default is false */
|
|
15
|
+
optimize?: boolean; /** default is true */
|
|
16
|
+
nonAsciiWrapper?: string; /** default is "" */
|
|
17
|
+
customTexMacros?: { [key: string]: string; };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare function tex2typst(tex: string, options?: Tex2TypstOptions): string;
|
|
21
|
+
export declare function typst2tex(typst: string): string;
|
|
22
|
+
|
|
23
|
+
export declare const symbolMap: Map<string, string>;
|
|
24
|
+
export declare const shorthandMap: Map<string, string>;
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,8 @@ function assert(condition, message = "Assertion failed.") {
|
|
|
10
10
|
|
|
11
11
|
// src/tex-types.ts
|
|
12
12
|
var TexToken = class _TexToken {
|
|
13
|
+
type;
|
|
14
|
+
value;
|
|
13
15
|
constructor(type, value) {
|
|
14
16
|
this.type = type;
|
|
15
17
|
this.value = value;
|
|
@@ -28,11 +30,11 @@ var TexToken = class _TexToken {
|
|
|
28
30
|
toNode() {
|
|
29
31
|
return new TexTerminal(this);
|
|
30
32
|
}
|
|
31
|
-
static
|
|
32
|
-
this.EMPTY = new _TexToken(0 /* EMPTY */, "");
|
|
33
|
-
}
|
|
33
|
+
static EMPTY = new _TexToken(0 /* EMPTY */, "");
|
|
34
34
|
};
|
|
35
35
|
var TexNode = class {
|
|
36
|
+
type;
|
|
37
|
+
head;
|
|
36
38
|
constructor(type, head) {
|
|
37
39
|
this.type = type;
|
|
38
40
|
this.head = head ? head : TexToken.EMPTY;
|
|
@@ -90,6 +92,7 @@ var TexText = class extends TexNode {
|
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
94
|
var TexGroup = class extends TexNode {
|
|
95
|
+
items;
|
|
93
96
|
constructor(items) {
|
|
94
97
|
super("ordgroup", TexToken.EMPTY);
|
|
95
98
|
this.items = items;
|
|
@@ -99,6 +102,9 @@ var TexGroup = class extends TexNode {
|
|
|
99
102
|
}
|
|
100
103
|
};
|
|
101
104
|
var TexSupSub = class extends TexNode {
|
|
105
|
+
base;
|
|
106
|
+
sup;
|
|
107
|
+
sub;
|
|
102
108
|
constructor(data) {
|
|
103
109
|
super("supsub", TexToken.EMPTY);
|
|
104
110
|
this.base = data.base;
|
|
@@ -142,6 +148,9 @@ var TexSupSub = class extends TexNode {
|
|
|
142
148
|
}
|
|
143
149
|
};
|
|
144
150
|
var TexFuncCall = class extends TexNode {
|
|
151
|
+
args;
|
|
152
|
+
// For type="sqrt", it's additional argument wrapped square bracket. e.g. 3 in \sqrt[3]{x}
|
|
153
|
+
data;
|
|
145
154
|
constructor(head, args, data = null) {
|
|
146
155
|
super("funcCall", head);
|
|
147
156
|
this.args = args;
|
|
@@ -164,6 +173,9 @@ var TexFuncCall = class extends TexNode {
|
|
|
164
173
|
}
|
|
165
174
|
};
|
|
166
175
|
var TexLeftRight = class extends TexNode {
|
|
176
|
+
body;
|
|
177
|
+
left;
|
|
178
|
+
right;
|
|
167
179
|
constructor(data) {
|
|
168
180
|
super("leftright", TexToken.EMPTY);
|
|
169
181
|
this.body = data.body;
|
|
@@ -181,6 +193,9 @@ var TexLeftRight = class extends TexNode {
|
|
|
181
193
|
}
|
|
182
194
|
};
|
|
183
195
|
var TexBeginEnd = class extends TexNode {
|
|
196
|
+
matrix;
|
|
197
|
+
// for environment="array" or "subarray", there's additional data like {c|c} right after \begin{env}
|
|
198
|
+
data;
|
|
184
199
|
constructor(head, matrix, data = null) {
|
|
185
200
|
assert(head.type === 3 /* LITERAL */);
|
|
186
201
|
super("beginend", head);
|
|
@@ -279,20 +294,23 @@ function matchcompare(m1, m2) {
|
|
|
279
294
|
}
|
|
280
295
|
}
|
|
281
296
|
var Scanner = class {
|
|
297
|
+
_input;
|
|
298
|
+
_lexer;
|
|
299
|
+
// position within input stream
|
|
300
|
+
_pos = 0;
|
|
301
|
+
// current line number
|
|
302
|
+
_line = 0;
|
|
303
|
+
// current column number
|
|
304
|
+
_col = 0;
|
|
305
|
+
_offset = 0;
|
|
306
|
+
_less = null;
|
|
307
|
+
_go = false;
|
|
308
|
+
_newstate = null;
|
|
309
|
+
_state;
|
|
310
|
+
_text = null;
|
|
311
|
+
_leng = null;
|
|
312
|
+
_reMatchArray = null;
|
|
282
313
|
constructor(input, lexer) {
|
|
283
|
-
// position within input stream
|
|
284
|
-
this._pos = 0;
|
|
285
|
-
// current line number
|
|
286
|
-
this._line = 0;
|
|
287
|
-
// current column number
|
|
288
|
-
this._col = 0;
|
|
289
|
-
this._offset = 0;
|
|
290
|
-
this._less = null;
|
|
291
|
-
this._go = false;
|
|
292
|
-
this._newstate = null;
|
|
293
|
-
this._text = null;
|
|
294
|
-
this._leng = null;
|
|
295
|
-
this._reMatchArray = null;
|
|
296
314
|
this._input = input;
|
|
297
315
|
this._lexer = lexer;
|
|
298
316
|
this._state = lexer.states[0];
|
|
@@ -443,6 +461,8 @@ var Scanner = class {
|
|
|
443
461
|
}
|
|
444
462
|
};
|
|
445
463
|
var JSLex = class {
|
|
464
|
+
states;
|
|
465
|
+
specification;
|
|
446
466
|
constructor(spec3) {
|
|
447
467
|
this.states = Object.keys(spec3);
|
|
448
468
|
this.specification = {};
|
|
@@ -736,6 +756,8 @@ var LatexParserError = class extends Error {
|
|
|
736
756
|
var SUB_SYMBOL = new TexToken(7 /* CONTROL */, "_");
|
|
737
757
|
var SUP_SYMBOL = new TexToken(7 /* CONTROL */, "^");
|
|
738
758
|
var LatexParser = class {
|
|
759
|
+
space_sensitive;
|
|
760
|
+
newline_sensitive;
|
|
739
761
|
constructor(space_sensitive = false, newline_sensitive = true) {
|
|
740
762
|
this.space_sensitive = space_sensitive;
|
|
741
763
|
this.newline_sensitive = newline_sensitive;
|
|
@@ -1098,6 +1120,8 @@ function parseTex(tex, customTexMacros) {
|
|
|
1098
1120
|
|
|
1099
1121
|
// src/typst-types.ts
|
|
1100
1122
|
var TypstToken = class _TypstToken {
|
|
1123
|
+
type;
|
|
1124
|
+
value;
|
|
1101
1125
|
constructor(type, content) {
|
|
1102
1126
|
this.type = type;
|
|
1103
1127
|
this.value = content;
|
|
@@ -1121,14 +1145,14 @@ var TypstToken = class _TypstToken {
|
|
|
1121
1145
|
return this.value;
|
|
1122
1146
|
}
|
|
1123
1147
|
}
|
|
1124
|
-
static
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1127
|
-
static {
|
|
1128
|
-
this.EMPTY = new _TypstToken(2 /* ELEMENT */, "");
|
|
1129
|
-
}
|
|
1148
|
+
static NONE = new _TypstToken(0 /* NONE */, "#none");
|
|
1149
|
+
static EMPTY = new _TypstToken(2 /* ELEMENT */, "");
|
|
1130
1150
|
};
|
|
1131
1151
|
var TypstNode = class {
|
|
1152
|
+
type;
|
|
1153
|
+
head;
|
|
1154
|
+
// Some Typst functions accept additional options. e.g. mat() has option "delim", op() has option "limits"
|
|
1155
|
+
options;
|
|
1132
1156
|
constructor(type, head) {
|
|
1133
1157
|
this.type = type;
|
|
1134
1158
|
this.head = head ? head : TypstToken.NONE;
|
|
@@ -1156,6 +1180,7 @@ var TypstTerminal = class extends TypstNode {
|
|
|
1156
1180
|
}
|
|
1157
1181
|
};
|
|
1158
1182
|
var TypstGroup = class extends TypstNode {
|
|
1183
|
+
items;
|
|
1159
1184
|
constructor(items) {
|
|
1160
1185
|
super("group", TypstToken.NONE);
|
|
1161
1186
|
this.items = items;
|
|
@@ -1165,6 +1190,9 @@ var TypstGroup = class extends TypstNode {
|
|
|
1165
1190
|
}
|
|
1166
1191
|
};
|
|
1167
1192
|
var TypstSupsub = class extends TypstNode {
|
|
1193
|
+
base;
|
|
1194
|
+
sup;
|
|
1195
|
+
sub;
|
|
1168
1196
|
constructor(data) {
|
|
1169
1197
|
super("supsub", TypstToken.NONE);
|
|
1170
1198
|
this.base = data.base;
|
|
@@ -1176,6 +1204,7 @@ var TypstSupsub = class extends TypstNode {
|
|
|
1176
1204
|
}
|
|
1177
1205
|
};
|
|
1178
1206
|
var TypstFuncCall = class extends TypstNode {
|
|
1207
|
+
args;
|
|
1179
1208
|
constructor(head, args) {
|
|
1180
1209
|
super("funcCall", head);
|
|
1181
1210
|
this.args = args;
|
|
@@ -1188,6 +1217,7 @@ var TypstFuncCall = class extends TypstNode {
|
|
|
1188
1217
|
}
|
|
1189
1218
|
};
|
|
1190
1219
|
var TypstFraction = class extends TypstNode {
|
|
1220
|
+
args;
|
|
1191
1221
|
constructor(args) {
|
|
1192
1222
|
super("fraction", TypstToken.NONE);
|
|
1193
1223
|
this.args = args;
|
|
@@ -1197,6 +1227,9 @@ var TypstFraction = class extends TypstNode {
|
|
|
1197
1227
|
}
|
|
1198
1228
|
};
|
|
1199
1229
|
var TypstLeftright = class extends TypstNode {
|
|
1230
|
+
body;
|
|
1231
|
+
left;
|
|
1232
|
+
right;
|
|
1200
1233
|
// head is either null or 'lr'
|
|
1201
1234
|
constructor(head, data) {
|
|
1202
1235
|
super("leftright", head);
|
|
@@ -1209,6 +1242,7 @@ var TypstLeftright = class extends TypstNode {
|
|
|
1209
1242
|
}
|
|
1210
1243
|
};
|
|
1211
1244
|
var TypstMatrixLike = class extends TypstNode {
|
|
1245
|
+
matrix;
|
|
1212
1246
|
// head is 'mat', 'cases' or null
|
|
1213
1247
|
constructor(head, data) {
|
|
1214
1248
|
super("matrixLike", head);
|
|
@@ -1217,14 +1251,18 @@ var TypstMatrixLike = class extends TypstNode {
|
|
|
1217
1251
|
isOverHigh() {
|
|
1218
1252
|
return true;
|
|
1219
1253
|
}
|
|
1220
|
-
static
|
|
1221
|
-
|
|
1222
|
-
}
|
|
1223
|
-
static {
|
|
1224
|
-
this.CASES = new TypstToken(1 /* SYMBOL */, "cases");
|
|
1225
|
-
}
|
|
1254
|
+
static MAT = new TypstToken(1 /* SYMBOL */, "mat");
|
|
1255
|
+
static CASES = new TypstToken(1 /* SYMBOL */, "cases");
|
|
1226
1256
|
};
|
|
1227
1257
|
var TypstMarkupFunc = class extends TypstNode {
|
|
1258
|
+
/*
|
|
1259
|
+
In idealized situations, for `#heading([some text and math $x + y$ example])`,
|
|
1260
|
+
fragments would be [TypstMarkup{"some text and math "}, TypstNode{"x + y"}, TypstMarkup{" example"}]
|
|
1261
|
+
At present, we haven't implemented anything about TypstMarkup.
|
|
1262
|
+
So only pattens like `#heading(level: 2)[$x+y$]`, `#text(fill: red)[$x + y$]` are supported.
|
|
1263
|
+
Therefore, fragments is always a list containing exactly 1 TypstNode in well-working situations.
|
|
1264
|
+
*/
|
|
1265
|
+
fragments;
|
|
1228
1266
|
constructor(head, fragments) {
|
|
1229
1267
|
super("markupFunc", head);
|
|
1230
1268
|
this.fragments = fragments;
|
|
@@ -1292,6 +1330,7 @@ var TYPST_COMMA = new TypstToken(2 /* ELEMENT */, ",");
|
|
|
1292
1330
|
var TYPST_NEWLINE = new TypstToken(1 /* SYMBOL */, "\n");
|
|
1293
1331
|
var SOFT_SPACE = new TypstToken(7 /* CONTROL */, " ");
|
|
1294
1332
|
var TypstWriterError = class extends Error {
|
|
1333
|
+
node;
|
|
1295
1334
|
constructor(message, node) {
|
|
1296
1335
|
super(message);
|
|
1297
1336
|
this.name = "TypstWriterError";
|
|
@@ -1299,10 +1338,15 @@ var TypstWriterError = class extends Error {
|
|
|
1299
1338
|
}
|
|
1300
1339
|
};
|
|
1301
1340
|
var TypstWriter = class {
|
|
1341
|
+
nonStrict;
|
|
1342
|
+
preferShorthands;
|
|
1343
|
+
keepSpaces;
|
|
1344
|
+
inftyToOo;
|
|
1345
|
+
optimize;
|
|
1346
|
+
buffer = "";
|
|
1347
|
+
queue = [];
|
|
1348
|
+
insideFunctionDepth = 0;
|
|
1302
1349
|
constructor(options) {
|
|
1303
|
-
this.buffer = "";
|
|
1304
|
-
this.queue = [];
|
|
1305
|
-
this.insideFunctionDepth = 0;
|
|
1306
1350
|
this.nonStrict = options.nonStrict;
|
|
1307
1351
|
this.preferShorthands = options.preferShorthands;
|
|
1308
1352
|
this.keepSpaces = options.keepSpaces;
|
|
@@ -2687,6 +2731,7 @@ for (const [key, value] of texAliasMap) {
|
|
|
2687
2731
|
|
|
2688
2732
|
// src/convert.ts
|
|
2689
2733
|
var ConverterError = class extends Error {
|
|
2734
|
+
node;
|
|
2690
2735
|
constructor(message, node = null) {
|
|
2691
2736
|
super(message);
|
|
2692
2737
|
this.name = "ConverterError";
|
|
@@ -3606,6 +3651,8 @@ var SEMICOLON = new TypstToken(2 /* ELEMENT */, ";");
|
|
|
3606
3651
|
var SINGLE_SPACE = new TypstToken(6 /* SPACE */, " ");
|
|
3607
3652
|
var CONTROL_AND = new TypstToken(7 /* CONTROL */, "&");
|
|
3608
3653
|
var TypstParser = class {
|
|
3654
|
+
space_sensitive;
|
|
3655
|
+
newline_sensitive;
|
|
3609
3656
|
constructor(space_sensitive = true, newline_sensitive = true) {
|
|
3610
3657
|
this.space_sensitive = space_sensitive;
|
|
3611
3658
|
this.newline_sensitive = newline_sensitive;
|
|
@@ -3846,10 +3893,8 @@ function parseTypst(typst) {
|
|
|
3846
3893
|
|
|
3847
3894
|
// src/tex-writer.ts
|
|
3848
3895
|
var TexWriter = class {
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
this.queue = [];
|
|
3852
|
-
}
|
|
3896
|
+
buffer = "";
|
|
3897
|
+
queue = [];
|
|
3853
3898
|
append(node) {
|
|
3854
3899
|
this.queue = this.queue.concat(node.serialize());
|
|
3855
3900
|
}
|