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
@@ -1,107 +0,0 @@
1
- /**
2
- * ELEMENT: 0-9, a-z, A-Z, punctuations such as +-/*,:; etc.
3
- * COMMAND: LaTeX macro with no parameter. e.g. \sin \cos \int \sum
4
- * EMPTY: special type when something is empty. e.g. the base of _{a} or ^{a}
5
- */
6
- export declare enum TexTokenType {
7
- EMPTY = 0,
8
- ELEMENT = 1,
9
- COMMAND = 2,
10
- LITERAL = 3,
11
- COMMENT = 4,
12
- SPACE = 5,
13
- NEWLINE = 6,
14
- CONTROL = 7,
15
- UNKNOWN = 8
16
- }
17
- export declare class TexToken {
18
- readonly type: TexTokenType;
19
- value: string;
20
- constructor(type: TexTokenType, value: string);
21
- eq(token: TexToken): boolean;
22
- toString(): string;
23
- toNode(): TexNode;
24
- static readonly EMPTY: TexToken;
25
- }
26
- export interface TexSupsubData {
27
- base: TexNode;
28
- sup: TexNode | null;
29
- sub: TexNode | null;
30
- }
31
- export interface TexLeftRightData {
32
- body: TexNode;
33
- left: TexToken | null;
34
- right: TexToken | null;
35
- }
36
- /**
37
- * funcCall: LaTeX macro with 1 or more parameters. e.g. \sqrt{3} \log{x} \exp{x} \frac{1}{2}
38
- * text: text enclosed by braces. e.g. \text{hello world}
39
- */
40
- type TexNodeType = 'terminal' | 'text' | 'ordgroup' | 'supsub' | 'funcCall' | 'leftright' | 'beginend';
41
- export declare abstract class TexNode {
42
- readonly type: TexNodeType;
43
- head: TexToken;
44
- constructor(type: TexNodeType, head: TexToken | null);
45
- eq(other: TexNode): boolean;
46
- abstract serialize(): TexToken[];
47
- toString(): string;
48
- }
49
- export declare class TexTerminal extends TexNode {
50
- constructor(head: TexToken);
51
- serialize(): TexToken[];
52
- }
53
- export declare class TexText extends TexNode {
54
- constructor(head: TexToken);
55
- serialize(): TexToken[];
56
- }
57
- export declare class TexGroup extends TexNode {
58
- items: TexNode[];
59
- constructor(items: TexNode[]);
60
- serialize(): TexToken[];
61
- }
62
- export declare class TexSupSub extends TexNode {
63
- base: TexNode;
64
- sup: TexNode | null;
65
- sub: TexNode | null;
66
- constructor(data: TexSupsubData);
67
- serialize(): TexToken[];
68
- }
69
- export declare class TexFuncCall extends TexNode {
70
- args: TexNode[];
71
- data: TexNode | null;
72
- constructor(head: TexToken, args: TexNode[], data?: TexNode | null);
73
- serialize(): TexToken[];
74
- }
75
- export declare class TexLeftRight extends TexNode {
76
- body: TexNode;
77
- left: TexToken | null;
78
- right: TexToken | null;
79
- constructor(data: TexLeftRightData);
80
- serialize(): TexToken[];
81
- }
82
- export declare class TexBeginEnd extends TexNode {
83
- matrix: TexNode[][];
84
- data: TexNode | null;
85
- constructor(head: TexToken, matrix: TexNode[][], data?: TexNode | null);
86
- serialize(): TexToken[];
87
- }
88
- export declare function writeTexTokenBuffer(buffer: string, token: TexToken): string;
89
- /**
90
- * ATTENTION:
91
- * Don't use any options except those explicitly documented in
92
- * https://github.com/qwinsi/tex2typst/blob/main/docs/api-reference.md
93
- * Any undocumented options may be not working at present or break in the future!
94
- */
95
- export interface Tex2TypstOptions {
96
- nonStrict?: boolean; /** default is true */
97
- preferShorthands?: boolean; /** default is true */
98
- keepSpaces?: boolean; /** default is false */
99
- fracToSlash?: boolean; /** default is true */
100
- inftyToOo?: boolean; /** default is false */
101
- optimize?: boolean; /** default is true */
102
- nonAsciiWrapper?: string; /** default is "" */
103
- customTexMacros?: {
104
- [key: string]: string;
105
- };
106
- }
107
- export {};
@@ -1,8 +0,0 @@
1
- import { TexNode, TexToken } from "./tex-types";
2
- export declare class TexWriter {
3
- protected buffer: string;
4
- queue: TexToken[];
5
- append(node: TexNode): void;
6
- protected flushQueue(): void;
7
- finalize(): string;
8
- }
@@ -1,23 +0,0 @@
1
- import { TypstNode } from "./typst-types";
2
- import { TypstNamedParams } from "./typst-types";
3
- import { TypstToken } from "./typst-types";
4
- export declare class TypstParserError extends Error {
5
- constructor(message: string);
6
- }
7
- type TypstParseResult = [TypstNode, number];
8
- export declare class TypstParser {
9
- space_sensitive: boolean;
10
- newline_sensitive: boolean;
11
- constructor(space_sensitive?: boolean, newline_sensitive?: boolean);
12
- parse(tokens: TypstToken[]): TypstNode;
13
- parseGroup(tokens: TypstToken[], start: number, end: number, parentheses?: boolean): TypstParseResult;
14
- parseNextExpr(tokens: TypstToken[], start: number): TypstParseResult;
15
- parseSupOrSub(tokens: TypstToken[], start: number): TypstParseResult;
16
- parseNextExprWithoutSupSub(tokens: TypstToken[], start: number): TypstParseResult;
17
- parseArguments(tokens: TypstToken[], start: number): [TypstNode[], number];
18
- parseLrArguments(tokens: TypstToken[], start: number): [TypstNode, number];
19
- parseMatrix(tokens: TypstToken[], start: number, rowSepToken: TypstToken, cellSepToken: TypstToken): [TypstNode[][], TypstNamedParams, number];
20
- parseArgumentsWithSeparator(tokens: TypstToken[], start: number, end: number, sepToken: TypstToken): TypstNode[];
21
- }
22
- export declare function parseTypst(typst: string): TypstNode;
23
- export {};
@@ -1,3 +0,0 @@
1
- declare const shorthandMap: Map<string, string>;
2
- declare const reverseShorthandMap: Map<string, string>;
3
- export { shorthandMap, reverseShorthandMap };
@@ -1,2 +0,0 @@
1
- import { TypstToken } from "./typst-types";
2
- export declare function tokenize_typst(input: string): TypstToken[];
@@ -1,98 +0,0 @@
1
- export declare enum TypstTokenType {
2
- NONE = 0,
3
- SYMBOL = 1,
4
- ELEMENT = 2,
5
- LITERAL = 3,
6
- TEXT = 4,
7
- COMMENT = 5,
8
- SPACE = 6,
9
- CONTROL = 7,
10
- NEWLINE = 8
11
- }
12
- export declare class TypstToken {
13
- readonly type: TypstTokenType;
14
- value: string;
15
- constructor(type: TypstTokenType, content: string);
16
- eq(other: TypstToken): boolean;
17
- isOneOf(tokens: TypstToken[]): boolean;
18
- toNode(): TypstNode;
19
- toString(): string;
20
- static readonly NONE: TypstToken;
21
- static readonly EMPTY: TypstToken;
22
- }
23
- export interface TypstSupsubData {
24
- base: TypstNode;
25
- sup: TypstNode | null;
26
- sub: TypstNode | null;
27
- }
28
- export interface TypstLeftRightData {
29
- body: TypstNode;
30
- left: TypstToken | null;
31
- right: TypstToken | null;
32
- }
33
- /**
34
- * fraction: `1/2`, `(x + y)/2`, `(1+x)/(1-x)`
35
- * group: `a + 1/3`
36
- * leftright: `(a + 1/3)`, `[a + 1/3)`, `lr(]sum_(x=1)^n])`
37
- * markupFunc: `#heading(level: 2)[something]`, `#text(fill: red)[some text and math $x + y$]`
38
- */
39
- export type TypstNodeType = 'terminal' | 'group' | 'supsub' | 'funcCall' | 'fraction' | 'leftright' | 'matrixLike' | 'markupFunc';
40
- export type TypstNamedParams = {
41
- [key: string]: TypstNode;
42
- };
43
- export declare abstract class TypstNode {
44
- readonly type: TypstNodeType;
45
- head: TypstToken;
46
- options?: TypstNamedParams;
47
- constructor(type: TypstNodeType, head: TypstToken | null);
48
- abstract isOverHigh(): boolean;
49
- setOptions(options: TypstNamedParams): void;
50
- eq(other: TypstNode): boolean;
51
- toString(): string;
52
- }
53
- export declare class TypstTerminal extends TypstNode {
54
- constructor(head: TypstToken);
55
- isOverHigh(): boolean;
56
- toString(): string;
57
- }
58
- export declare class TypstGroup extends TypstNode {
59
- items: TypstNode[];
60
- constructor(items: TypstNode[]);
61
- isOverHigh(): boolean;
62
- }
63
- export declare class TypstSupsub extends TypstNode {
64
- base: TypstNode;
65
- sup: TypstNode | null;
66
- sub: TypstNode | null;
67
- constructor(data: TypstSupsubData);
68
- isOverHigh(): boolean;
69
- }
70
- export declare class TypstFuncCall extends TypstNode {
71
- args: TypstNode[];
72
- constructor(head: TypstToken, args: TypstNode[]);
73
- isOverHigh(): boolean;
74
- }
75
- export declare class TypstFraction extends TypstNode {
76
- args: TypstNode[];
77
- constructor(args: TypstNode[]);
78
- isOverHigh(): boolean;
79
- }
80
- export declare class TypstLeftright extends TypstNode {
81
- body: TypstNode;
82
- left: TypstToken | null;
83
- right: TypstToken | null;
84
- constructor(head: TypstToken | null, data: TypstLeftRightData);
85
- isOverHigh(): boolean;
86
- }
87
- export declare class TypstMatrixLike extends TypstNode {
88
- matrix: TypstNode[][];
89
- constructor(head: TypstToken | null, data: TypstNode[][]);
90
- isOverHigh(): boolean;
91
- static readonly MAT: TypstToken;
92
- static readonly CASES: TypstToken;
93
- }
94
- export declare class TypstMarkupFunc extends TypstNode {
95
- fragments: TypstNode[];
96
- constructor(head: TypstToken, fragments: TypstNode[]);
97
- isOverHigh(): boolean;
98
- }
@@ -1,30 +0,0 @@
1
- import { TexNode } from "./tex-types";
2
- import { TypstNode } from "./typst-types";
3
- import { TypstToken } from "./typst-types";
4
- export declare class TypstWriterError extends Error {
5
- node: TexNode | TypstNode | TypstToken;
6
- constructor(message: string, node: TexNode | TypstNode | TypstToken);
7
- }
8
- export interface TypstWriterOptions {
9
- nonStrict: boolean;
10
- preferShorthands: boolean;
11
- keepSpaces: boolean;
12
- inftyToOo: boolean;
13
- optimize: boolean;
14
- }
15
- export declare class TypstWriter {
16
- private nonStrict;
17
- private preferShorthands;
18
- private keepSpaces;
19
- private inftyToOo;
20
- private optimize;
21
- protected buffer: string;
22
- protected queue: TypstToken[];
23
- private insideFunctionDepth;
24
- constructor(options: TypstWriterOptions);
25
- private writeBuffer;
26
- serialize(abstractNode: TypstNode): void;
27
- private appendWithBracketsIfNeeded;
28
- protected flushQueue(): void;
29
- finalize(): string;
30
- }
package/dist/util.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function isalpha(char: string): boolean;
2
- export declare function isdigit(char: string): boolean;
3
- export declare function assert(condition: boolean, message?: string): void;