tex2typst 0.3.26 → 0.3.27

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.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +21 -4
  3. package/dist/index.js +409 -340
  4. package/dist/parser.js +23 -0
  5. package/dist/tex2typst.min.js +12 -12
  6. package/package.json +6 -7
  7. package/src/convert.ts +56 -6
  8. package/src/exposed-types.ts +23 -0
  9. package/src/index.ts +9 -5
  10. package/src/jslex.ts +1 -1
  11. package/src/tex-tokenizer.ts +1 -0
  12. package/src/tex-types.ts +1 -17
  13. package/src/tex2typst.ts +2 -4
  14. package/src/typst-parser.ts +9 -10
  15. package/src/typst-types.ts +484 -230
  16. package/src/typst-writer.ts +28 -274
  17. package/tests/cheat-sheet.test.ts +42 -0
  18. package/tests/cheat-sheet.toml +304 -0
  19. package/tests/example.ts +15 -0
  20. package/tests/general-symbols.test.ts +22 -0
  21. package/tests/general-symbols.toml +755 -0
  22. package/tests/integration-tex2typst.yaml +89 -0
  23. package/tests/struct-bidirection.yaml +179 -0
  24. package/tests/struct-tex2typst.yaml +443 -0
  25. package/tests/struct-typst2tex.yaml +412 -0
  26. package/tests/symbol.yml +123 -0
  27. package/tests/test-common.ts +26 -0
  28. package/tests/tex-parser.test.ts +57 -0
  29. package/tests/tex-to-typst.test.ts +143 -0
  30. package/tests/typst-parser.test.ts +134 -0
  31. package/tests/typst-to-tex.test.ts +76 -0
  32. package/tsconfig.json +11 -16
  33. package/dist/convert.d.ts +0 -9
  34. package/dist/generic.d.ts +0 -9
  35. package/dist/jslex.d.ts +0 -107
  36. package/dist/map.d.ts +0 -5
  37. package/dist/tex-parser.d.ts +0 -23
  38. package/dist/tex-tokenizer.d.ts +0 -4
  39. package/dist/tex-types.d.ts +0 -107
  40. package/dist/tex-writer.d.ts +0 -8
  41. package/dist/typst-parser.d.ts +0 -23
  42. package/dist/typst-shorthands.d.ts +0 -3
  43. package/dist/typst-tokenizer.d.ts +0 -2
  44. package/dist/typst-types.d.ts +0 -98
  45. package/dist/typst-writer.d.ts +0 -30
  46. package/dist/util.d.ts +0 -3
@@ -0,0 +1,143 @@
1
+ import { describe, it, test, expect } from 'vitest';
2
+ import { tokenize_tex } from '../src/tex-tokenizer';
3
+ import { parseTex } from '../src/tex-parser';
4
+ import { tex2typst } from '../src/index';
5
+ import { TypstWriterError } from '../src/typst-writer';
6
+ import { TexNode, TexToken } from '../src/tex-types';
7
+ import type { Tex2TypstOptions } from '../src/exposed-types';
8
+ import { loadTestCases, TestCase } from './test-common';
9
+ import { ConverterError } from '../src/convert';
10
+
11
+ describe('options', () => {
12
+ it('nonStrict = false', function () {
13
+ const input = '\\nonExistentCommand';
14
+ // must throw error
15
+ expect(() => tex2typst(input, { nonStrict: false })).toThrowError(ConverterError);
16
+ });
17
+
18
+
19
+ it('fracToSlash = true', function () {
20
+ const input = '\\frac{a}{b}';
21
+ const expected = 'a/b';
22
+ const res = tex2typst(input, { fracToSlash: true });
23
+ expect(res).toEqual(expected);
24
+ });
25
+
26
+ it('fracToSlash = false', function () {
27
+ const input = '\\frac{a}{b}';
28
+ const expected = 'frac(a, b)';
29
+ const res = tex2typst(input, { fracToSlash: false });
30
+ expect(res).toEqual(expected);
31
+ });
32
+
33
+
34
+ it('nonAsciiWrapper = ""', function () {
35
+ const input = 'a + b = \\text{こにちは、世界}';
36
+ const expected = 'a + b = "こにちは、世界"';
37
+ const res = tex2typst(input);
38
+ expect(res).toEqual(expected);
39
+ });
40
+
41
+ it('nonAsciiWrapper = "ut"', function () {
42
+ const input = 'a + b = \\text{こにちは、世界}';
43
+ const expected = 'a + b = ut("こにちは、世界")';
44
+ const res = tex2typst(input, { nonAsciiWrapper: 'ut' });
45
+ expect(res).toEqual(expected);
46
+ });
47
+
48
+ it('preferShorthands = true', function () {
49
+ const map = new Map<string, string>([
50
+ ['a \\rightarrow b', 'a -> b'],
51
+ ['a \\to b', 'a -> b'],
52
+ ['a \\implies b', 'a ==> b'],
53
+ ['a \\iff b', 'a <==> b'],
54
+ ['a \\ll b', 'a << b'],
55
+ ['a \\gg b', 'a >> b'],
56
+
57
+ ]);
58
+ for(const [input, expected] of map.entries()) {
59
+ const res = tex2typst(input, { preferShorthands: true });
60
+ expect(res).toEqual(expected);
61
+ }
62
+ });
63
+
64
+ it('preferShorthands = false', function () {
65
+ const map = new Map<string, string>([
66
+ ['a \\rightarrow b', 'a arrow.r b'],
67
+ ['a \\to b', 'a arrow.r b'],
68
+ ['a \\implies b', 'a arrow.r.double.long b'],
69
+ ['a \\iff b', 'a arrow.l.r.double.long b'],
70
+ ['a \\ll b', 'a lt.double b'],
71
+ ['a \\gg b', 'a gt.double b'],
72
+
73
+ ]);
74
+ for(const [input, expected] of map.entries()) {
75
+ const res = tex2typst(input, { preferShorthands: false });
76
+ expect(res).toEqual(expected);
77
+ }
78
+ });
79
+
80
+ it ('customTexMacros', function () {
81
+ const input = '\\myop y=\\sgn(x)';
82
+ const expected = 'op("myop") y = op("sgn")(x)';
83
+ const res = tex2typst(input, { customTexMacros: {
84
+ '\\myop': '\\operatorname{myop}',
85
+ '\\sgn': '\\operatorname{sgn}',
86
+ } });
87
+ expect(res).toEqual(expected);
88
+ });
89
+
90
+ it ('customTexMacros 2', function () {
91
+ const input = '123 \\foo 456';
92
+ const expected = '123 root(3, x) 456';
93
+ const res = tex2typst(input, { customTexMacros: {
94
+ '\\foo': '\\sqrt[3]{x}',
95
+ } });
96
+ expect(res).toEqual(expected);
97
+ });
98
+ });
99
+
100
+
101
+ const caseFiles = ["struct-tex2typst.yaml", "symbol.yml", "struct-bidirection.yaml", "integration-tex2typst.yaml"];
102
+
103
+ caseFiles.forEach((ymlFilename) => {
104
+ const suite = loadTestCases(ymlFilename);
105
+ describe(ymlFilename, () => {
106
+ suite.cases.forEach((c: TestCase) => {
107
+ test(c.title, function() {
108
+ const {tex, typst} = c;
109
+ let tokens: null | TexToken[] = null;
110
+ let tex_node: null | TexNode = null;
111
+ let result: null | string = null;
112
+ try {
113
+ const settings: Tex2TypstOptions = {
114
+ nonStrict: c.nonStrict? c.nonStrict: false,
115
+ preferShorthands: c.preferShorthands !== undefined? c.preferShorthands: true,
116
+ inftyToOo: c.inftyToOo !== undefined? c.inftyToOo: false,
117
+ customTexMacros: c.customTexMacros? c.customTexMacros: {},
118
+ };
119
+ tokens = tokenize_tex(tex);
120
+ tex_node = parseTex(tex, settings.customTexMacros!);
121
+ result = tex2typst(tex, settings);
122
+ if (result !== typst) {
123
+ console.log(`====== 😭 Wrong ======`);
124
+ console.log(tex);
125
+ console.log(tokens);
126
+ console.dir(tex_node, {depth: null});
127
+ }
128
+ expect(result).toBe(typst);
129
+ } catch (e) {
130
+ console.log(`====== 😭 Error ======`);
131
+ if (e instanceof TypstWriterError) {
132
+ console.log(e.node);
133
+ }
134
+ if (tex_node !== null) {
135
+ console.dir(tex_node, {depth: null});
136
+ }
137
+ console.log(tex);
138
+ throw e;
139
+ }
140
+ })
141
+ });
142
+ });
143
+ });
@@ -0,0 +1,134 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { tokenize_typst } from '../src/typst-tokenizer';
3
+ import { TypstParser } from '../src/typst-parser';
4
+ import { TypstFraction, TypstFuncCall, TypstGroup, TypstLeftright, TypstSupsub, TypstTerminal, TypstToken, TypstTokenType } from '../src/typst-types';
5
+
6
+
7
+ describe('typst-tokenizer', () => {
8
+ it('a + b', function () {
9
+ const res = tokenize_typst('a + b');
10
+ expect(res).toEqual([
11
+ new TypstToken(TypstTokenType.ELEMENT, 'a'),
12
+ new TypstToken(TypstTokenType.SPACE, ' '),
13
+ new TypstToken(TypstTokenType.ELEMENT, '+'),
14
+ new TypstToken(TypstTokenType.SPACE, ' '),
15
+ new TypstToken(TypstTokenType.ELEMENT, 'b'),
16
+ ]);
17
+ });
18
+
19
+ it('a (x)', function () {
20
+ const res = tokenize_typst('a (x)');
21
+ expect(res).toEqual([
22
+ new TypstToken(TypstTokenType.ELEMENT, 'a'),
23
+ new TypstToken(TypstTokenType.SPACE, ' '),
24
+ new TypstToken(TypstTokenType.ELEMENT, '('),
25
+ new TypstToken(TypstTokenType.ELEMENT, 'x'),
26
+ new TypstToken(TypstTokenType.ELEMENT, ')'),
27
+ ]);
28
+ });
29
+
30
+ it('f(x)', function () {
31
+ const res = tokenize_typst('f(x)');
32
+ expect(res).toEqual([
33
+ new TypstToken(TypstTokenType.ELEMENT, 'f'),
34
+ new TypstToken(TypstTokenType.ELEMENT, '('),
35
+ new TypstToken(TypstTokenType.ELEMENT, 'x'),
36
+ new TypstToken(TypstTokenType.ELEMENT, ')'),
37
+ ]);
38
+ });
39
+
40
+ it('comment', function() {
41
+ const res = tokenize_typst('a // comment');
42
+ expect(res).toEqual([
43
+ new TypstToken(TypstTokenType.ELEMENT, 'a'),
44
+ new TypstToken(TypstTokenType.SPACE, ' '),
45
+ new TypstToken(TypstTokenType.COMMENT, ' comment'),
46
+ ]);
47
+ })
48
+ });
49
+
50
+ describe('typst-parser', () => {
51
+ const parser = new TypstParser();
52
+ it('a + b', function () {
53
+ const tokens = tokenize_typst('a + b');
54
+ const res = parser.parse(tokens);
55
+ expect(res).toEqual(new TypstGroup([
56
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'a')),
57
+ new TypstTerminal(new TypstToken(TypstTokenType.SPACE, ' ')),
58
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, '+')),
59
+ new TypstTerminal(new TypstToken(TypstTokenType.SPACE, ' ')),
60
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'b')),
61
+ ]));
62
+ });
63
+
64
+ it('a (x)', function () {
65
+ const tokens = tokenize_typst('a (x)');
66
+ const res = parser.parse(tokens);
67
+ expect(res).toEqual(new TypstGroup([
68
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'a')),
69
+ new TypstTerminal(new TypstToken(TypstTokenType.SPACE, ' ')),
70
+ new TypstLeftright(null, {
71
+ body: new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'x')),
72
+ left: new TypstToken(TypstTokenType.ELEMENT, '('),
73
+ right: new TypstToken(TypstTokenType.ELEMENT, ')')
74
+ })
75
+ ]));
76
+ });
77
+
78
+ it('f(x)', function () {
79
+ const tokens = tokenize_typst('f(x)');
80
+ const res = parser.parse(tokens);
81
+ expect(res).toEqual(new TypstFuncCall(new TypstToken(TypstTokenType.ELEMENT, 'f'), [
82
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'x')),
83
+ ]));
84
+ });
85
+
86
+ it('root(x, 3)', function () {
87
+ const tokens = tokenize_typst('root(x, 3)');
88
+ const res = parser.parse(tokens);
89
+ expect(res).toEqual(new TypstFuncCall(new TypstToken(TypstTokenType.SYMBOL, 'root'), [
90
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'x')),
91
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, '3')),
92
+ ]));
93
+ });
94
+
95
+ it('lim_(x arrow.r 0)', function () {
96
+ const tokens = tokenize_typst('lim_(x arrow.r 0)');
97
+ const res = parser.parse(tokens);
98
+ expect(res).toEqual(new TypstSupsub({
99
+ base: new TypstTerminal(new TypstToken(TypstTokenType.SYMBOL, 'lim')),
100
+ sub: new TypstGroup([
101
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'x')),
102
+ new TypstTerminal(new TypstToken(TypstTokenType.SPACE, ' ')),
103
+ new TypstTerminal(new TypstToken(TypstTokenType.SYMBOL, 'arrow.r')),
104
+ new TypstTerminal(new TypstToken(TypstTokenType.SPACE, ' ')),
105
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, '0')),
106
+ ]),
107
+ sup: null,
108
+ }));
109
+ });
110
+
111
+ it('a -> b', function () {
112
+ const tokens = tokenize_typst('a -> b');
113
+ const res = parser.parse(tokens);
114
+ expect(res).toEqual(new TypstGroup([
115
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'a')),
116
+ new TypstTerminal(new TypstToken(TypstTokenType.SPACE, ' ')),
117
+ new TypstTerminal(new TypstToken(TypstTokenType.SYMBOL, 'arrow.r')),
118
+ new TypstTerminal(new TypstToken(TypstTokenType.SPACE, ' ')),
119
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, 'b')),
120
+ ]));
121
+ });
122
+
123
+ it('1/(2/3)', function () {
124
+ const tokens = tokenize_typst('1/(2/3)');
125
+ const res = parser.parse(tokens);
126
+ expect(res).toEqual(new TypstFraction([
127
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, '1')),
128
+ new TypstFraction([
129
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, '2')),
130
+ new TypstTerminal(new TypstToken(TypstTokenType.ELEMENT, '3')),
131
+ ]),
132
+ ]));
133
+ });
134
+ });
@@ -0,0 +1,76 @@
1
+
2
+ import { describe, it, test, expect } from 'vitest';
3
+ import { parseTypst } from '../src/typst-parser';
4
+ import { TexWriter } from '../src/tex-writer';
5
+ import { convert_typst_node_to_tex } from '../src/convert';
6
+ import { loadTestCases, TestCase } from './test-common';
7
+
8
+
9
+
10
+ describe('examples', () => {
11
+ it('a + b', function () {
12
+ const typst_node = parseTypst('a + b');
13
+ const tex_node = convert_typst_node_to_tex(typst_node);
14
+ const writer = new TexWriter();
15
+ writer.append(tex_node);
16
+ const res = writer.finalize();
17
+ expect(res).toEqual('a + b');
18
+ });
19
+
20
+ it('sqrt(x)', function () {
21
+ const typst_node = parseTypst('sqrt(x)');
22
+ const tex_node = convert_typst_node_to_tex(typst_node);
23
+ const writer = new TexWriter();
24
+ writer.append(tex_node);
25
+ const res = writer.finalize();
26
+ expect(res).toEqual('\\sqrt{x}');
27
+ });
28
+
29
+ it('integral_a^b f(x) dif x', function () {
30
+ const typst_node = parseTypst('integral_a^b f(x) dif x');
31
+ const tex_node = convert_typst_node_to_tex(typst_node);
32
+ const writer = new TexWriter();
33
+ writer.append(tex_node);
34
+ const res = writer.finalize();
35
+ expect(res).toEqual('\\int_a^b f(x) \\mathrm{d} x');
36
+ });
37
+
38
+ it('lr({a + 1/3))', function () {
39
+ const typst_node = parseTypst('lr({a + 1/3))');
40
+ const tex_node = convert_typst_node_to_tex(typst_node);
41
+ const writer = new TexWriter();
42
+ writer.append(tex_node);
43
+ const res = writer.finalize();
44
+ expect(res).toEqual('\\left\\{a + \\frac{1}{3} \\right)');
45
+ });
46
+ });
47
+
48
+
49
+
50
+ describe('struct-typst2tex.yaml', function () {
51
+ const suite = loadTestCases('struct-typst2tex.yaml');
52
+ suite.cases.forEach((c: TestCase) => {
53
+ test(c.title, function () {
54
+ const typst_node = parseTypst(c.typst);
55
+ const tex_node = convert_typst_node_to_tex(typst_node);
56
+ const writer = new TexWriter();
57
+ writer.append(tex_node);
58
+ const res = writer.finalize();
59
+ expect(res).toEqual(c.tex);
60
+ });
61
+ });
62
+ });
63
+
64
+ describe('struct-bidirection.yaml', function () {
65
+ const suite = loadTestCases('struct-bidirection.yaml');
66
+ suite.cases.forEach((c: TestCase) => {
67
+ test(c.title, function () {
68
+ const typst_node = parseTypst(c.typst);
69
+ const tex_node = convert_typst_node_to_tex(typst_node);
70
+ const writer = new TexWriter();
71
+ writer.append(tex_node);
72
+ const res = writer.finalize();
73
+ expect(res).toEqual(c.tex);
74
+ });
75
+ });
76
+ });
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
3
+ /* This is not the full list because some meaningless options are not listed. */
4
4
 
5
5
  /* Projects */
6
6
  // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
@@ -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": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14
+ "target": "es2022", /* 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. */
@@ -20,14 +20,12 @@
20
20
  // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
21
  // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
22
  // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
23
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
24
 
27
25
  /* Modules */
28
- "module": "esnext", /* Specify what module code is generated. */
26
+ // "module": "es6", /* Specify what module code is generated. */
29
27
  // "rootDir": "./", /* Specify the root folder within your source files. */
30
- // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
28
+ "moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
31
29
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
30
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
31
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@@ -35,7 +33,7 @@
35
33
  // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
34
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
35
  // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
- "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
36
+ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
37
  // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
38
  // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
39
  // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
@@ -49,12 +47,11 @@
49
47
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
48
 
51
49
  /* Emit */
52
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
50
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
53
51
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54
- "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
52
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55
53
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
54
  // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
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. */
58
55
  // "outDir": "./", /* Specify an output folder for all emitted files. */
59
56
  // "removeComments": true, /* Disable emitting comments. */
60
57
  // "noEmit": true, /* Disable emitting files from a compilation. */
@@ -63,13 +60,11 @@
63
60
  // "sourceRoot": "./", /* Specify the root path for debuggers to find the reference source code. */
64
61
  // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
65
62
  // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
66
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
67
- // "newLine": "crlf", /* Set the newline character for emitting files. */
68
63
  // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
69
64
  // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
70
65
  // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
71
66
  // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
72
- "declarationDir": "./dist", /* Specify the output directory for generated declaration files. */
67
+ // "declarationDir": "./dist", /* Specify the output directory for generated declaration files. */
73
68
 
74
69
  /* Interop Constraints */
75
70
  // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
@@ -82,7 +77,7 @@
82
77
 
83
78
  /* Type Checking */
84
79
  "strict": true, /* Enable all strict type-checking options. */
85
- "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
80
+ // "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
86
81
  // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
87
82
  // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
88
83
  // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
@@ -106,10 +101,10 @@
106
101
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
107
102
  },
108
103
  "include": [
109
- "src/**/*.ts"
104
+ "src/**/*.ts",
105
+ "tests/**/*.ts",
110
106
  ],
111
107
  "exclude": [
112
108
  "src/tex2typst.ts",
113
- "tests/**/*"
114
109
  ]
115
110
  }
package/dist/convert.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { TexNode, Tex2TypstOptions, TexToken } from "./tex-types";
2
- import { TypstNode } from "./typst-types";
3
- import { TypstToken } from "./typst-types";
4
- export declare class ConverterError extends Error {
5
- node: TexNode | TypstNode | TexToken | TypstToken | null;
6
- constructor(message: string, node?: TexNode | TypstNode | TexToken | TypstToken | null);
7
- }
8
- export declare function convert_tex_node_to_typst(abstractNode: TexNode, options?: Tex2TypstOptions): TypstNode;
9
- export declare function convert_typst_node_to_tex(abstractNode: TypstNode): TexNode;
package/dist/generic.d.ts DELETED
@@ -1,9 +0,0 @@
1
- interface IEquatable {
2
- eq(other: IEquatable): boolean;
3
- }
4
- export declare function array_equal<T extends IEquatable>(a: T[], b: T[]): boolean;
5
- export declare function array_find<T extends IEquatable>(array: T[], item: T, start?: number): number;
6
- export declare function array_includes<T extends IEquatable>(array: T[], item: T): boolean;
7
- export declare function array_split<T extends IEquatable>(array: T[], sep: T): T[][];
8
- export declare function array_intersperse<T>(array: T[], sep: T): T[];
9
- export {};
package/dist/jslex.d.ts DELETED
@@ -1,107 +0,0 @@
1
- /**
2
- * Adapted from jslex - A lexer in JavaScript. https://github.com/jimbojw/jslex
3
- * Licensed under MIT license
4
- */
5
- interface ILexSpec<T> {
6
- start: Map<string, (arg0: Scanner<T>) => T | T[]>;
7
- }
8
- interface IRule<T> {
9
- re: RegExp;
10
- action: (a: Scanner<T>) => T | T[];
11
- }
12
- export declare class Scanner<T> {
13
- private _input;
14
- private _lexer;
15
- private _pos;
16
- private _line;
17
- private _col;
18
- private _offset;
19
- private _less;
20
- private _go;
21
- private _newstate;
22
- private _state;
23
- private _text;
24
- private _leng;
25
- private _reMatchArray;
26
- constructor(input: string, lexer: JSLex<T>);
27
- /**
28
- * Analogous to yytext and yyleng in lex - will be set during scan.
29
- */
30
- text(): string | null;
31
- leng(): number | null;
32
- reMatchArray(): RegExpMatchArray | null;
33
- /**
34
- * Position of in stream, line number and column number of match.
35
- */
36
- pos(): number;
37
- line(): number;
38
- column(): number;
39
- /**
40
- * Analogous to input() in lex.
41
- * @return {string} The next character in the stream.
42
- */
43
- input(): string;
44
- /**
45
- * Similar to unput() in lex, but does not allow modifying the stream.
46
- * @return {int} The offset position after the operation.
47
- */
48
- unput(): number;
49
- /**
50
- * Analogous to yyless(n) in lex - retains the first n characters from this pattern, and returns
51
- * the rest to the input stream, such that they will be used in the next pattern-matching operation.
52
- * @param {int} n Number of characters to retain.
53
- * @return {int} Length of the stream after the operation has completed.
54
- */
55
- less(n: number): number;
56
- /**
57
- * Like less(), but instead of retaining the first n characters, it chops off the last n.
58
- * @param {int} n Number of characters to chop.
59
- * @return {int} Length of the stream after the operation has completed.
60
- */
61
- pushback(n: number): number;
62
- /**
63
- * Similar to REJECT in lex, except it doesn't break the current execution context.
64
- * TIP: reject() should be the last instruction in a spec callback.
65
- */
66
- reject(): void;
67
- /**
68
- * Analogous to BEGIN in lex - sets the named state (start condition).
69
- * @param {string|int} state Name of state to switch to, or ordinal number (0 is first, etc).
70
- * @return {string} The new state on successful switch, throws exception on failure.
71
- */
72
- begin(state: string | number): string;
73
- /**
74
- * Simple accessor for reading in the current state.
75
- * @return {string} The current state.
76
- */
77
- state(): string;
78
- /**
79
- * Scan method to be returned to caller - grabs the next token and fires appropriate calback.
80
- * @return {T} The next token extracted from the stream.
81
- */
82
- scan(): T | T[];
83
- }
84
- export declare class JSLex<T> {
85
- states: string[];
86
- specification: Record<string, IRule<T>[]>;
87
- constructor(spec: ILexSpec<T>);
88
- /**
89
- * Scanner function - makes a new scanner object which is used to get tokens one at a time.
90
- * @param {string} input Input text to tokenize.
91
- * @return {function} Scanner function.
92
- */
93
- scanner(input: string): Scanner<T>;
94
- /**
95
- * Similar to lex's yylex() function, consumes all input, calling calback for each token.
96
- * @param {string} input Text to lex.
97
- * @param {function} callback Function to execute for each token.
98
- */
99
- lex(input: string, callback: (arg0: T | T[]) => void): void;
100
- /**
101
- * Consumes all input, collecting tokens along the way.
102
- * @param {string} input Text to lex.
103
- * @return {array} List of tokens, may contain an Error at the end.
104
- */
105
- collect(input: string): T[];
106
- }
107
- export {};
package/dist/map.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare const symbolMap: Map<string, string>;
2
- declare const texAliasMap: Map<string, string>;
3
- declare const typstAliasMap: Map<string, string>;
4
- declare const reverseSymbolMap: Map<string, string>;
5
- export { reverseSymbolMap, symbolMap, texAliasMap, typstAliasMap };
@@ -1,23 +0,0 @@
1
- import { TexNode, TexToken } from "./tex-types";
2
- export declare class LatexParserError extends Error {
3
- constructor(message: string);
4
- }
5
- type ParseResult = [TexNode, number];
6
- export declare class LatexParser {
7
- space_sensitive: boolean;
8
- newline_sensitive: boolean;
9
- constructor(space_sensitive?: boolean, newline_sensitive?: boolean);
10
- parse(tokens: TexToken[]): TexNode;
11
- parseGroup(tokens: TexToken[], start: number, end: number): ParseResult;
12
- parseNextExpr(tokens: TexToken[], start: number): ParseResult;
13
- parseNextExprWithoutSupSub(tokens: TexToken[], start: number): ParseResult;
14
- parseCommandExpr(tokens: TexToken[], start: number): ParseResult;
15
- parseNextArg(tokens: TexToken[], start: number): ParseResult;
16
- parseLeftRightExpr(tokens: TexToken[], start: number): ParseResult;
17
- parseBeginEndExpr(tokens: TexToken[], start: number): ParseResult;
18
- parseAligned(tokens: TexToken[]): TexNode[][];
19
- }
20
- export declare function parseTex(tex: string, customTexMacros: {
21
- [key: string]: string;
22
- }): TexNode;
23
- export {};
@@ -1,4 +0,0 @@
1
- import { TexToken } from "./tex-types";
2
- export declare const TEX_UNARY_COMMANDS: string[];
3
- export declare const TEX_BINARY_COMMANDS: string[];
4
- export declare function tokenize_tex(input: string): TexToken[];