tex2typst 0.3.23 → 0.3.24

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.
@@ -1,4 +1,4 @@
1
- import { TexNode, TexToken } from "./types";
1
+ import { TexNode, TexToken } from "./tex-types";
2
2
  export declare class LatexParserError extends Error {
3
3
  constructor(message: string);
4
4
  }
@@ -1,4 +1,4 @@
1
- import { TexToken } from "./types";
1
+ import { TexToken } from "./tex-types";
2
2
  export declare const TEX_UNARY_COMMANDS: string[];
3
3
  export declare const TEX_BINARY_COMMANDS: string[];
4
4
  export declare function tokenize_tex(input: string): TexToken[];
@@ -0,0 +1,103 @@
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
+ 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
+ left: TexToken | null;
33
+ right: TexToken | null;
34
+ }
35
+ /**
36
+ * funcCall: LaTeX macro with 1 or more parameters. e.g. \sqrt{3} \log{x} \exp{x} \frac{1}{2}
37
+ * text: text enclosed by braces. e.g. \text{hello world}
38
+ */
39
+ type TexNodeType = 'terminal' | 'text' | 'ordgroup' | 'supsub' | 'funcCall' | 'leftright' | 'beginend';
40
+ export declare abstract class TexNode {
41
+ type: TexNodeType;
42
+ head: TexToken;
43
+ args?: TexNode[];
44
+ constructor(type: TexNodeType, head: TexToken | null, args?: TexNode[]);
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
+ constructor(args: TexNode[]);
59
+ serialize(): TexToken[];
60
+ }
61
+ export declare class TexSupSub extends TexNode {
62
+ base: TexNode;
63
+ sup: TexNode | null;
64
+ sub: TexNode | null;
65
+ constructor(data: TexSupsubData);
66
+ serialize(): TexToken[];
67
+ }
68
+ export declare class TexFuncCall extends TexNode {
69
+ data: TexNode | null;
70
+ constructor(head: TexToken, args: TexNode[], data?: TexNode | null);
71
+ serialize(): TexToken[];
72
+ }
73
+ export declare class TexLeftRight extends TexNode {
74
+ left: TexToken | null;
75
+ right: TexToken | null;
76
+ constructor(args: TexNode[], data: TexLeftRightData);
77
+ serialize(): TexToken[];
78
+ }
79
+ export declare class TexBeginEnd extends TexNode {
80
+ matrix: TexNode[][];
81
+ constructor(head: TexToken, args: TexNode[], data: TexNode[][]);
82
+ serialize(): TexToken[];
83
+ }
84
+ export declare function writeTexTokenBuffer(buffer: string, token: TexToken): string;
85
+ /**
86
+ * ATTENTION:
87
+ * Don't use any options except those explicitly documented in
88
+ * https://github.com/qwinsi/tex2typst/blob/main/docs/api-reference.md
89
+ * Any undocumented options may be not working at present or break in the future!
90
+ */
91
+ export interface Tex2TypstOptions {
92
+ nonStrict?: boolean; /** default is true */
93
+ preferShorthands?: boolean; /** default is true */
94
+ keepSpaces?: boolean; /** default is false */
95
+ fracToSlash?: boolean; /** default is true */
96
+ inftyToOo?: boolean; /** default is false */
97
+ optimize?: boolean; /** default is true */
98
+ nonAsciiWrapper?: string; /** default is "" */
99
+ customTexMacros?: {
100
+ [key: string]: string;
101
+ };
102
+ }
103
+ export {};
@@ -1,8 +1,7 @@
1
- import { TexNode, TexToken } from "./types";
1
+ import { TexNode, TexToken } from "./tex-types";
2
2
  export declare class TexWriter {
3
3
  protected buffer: string;
4
4
  queue: TexToken[];
5
- private writeBuffer;
6
5
  append(node: TexNode): void;
7
6
  protected flushQueue(): void;
8
7
  finalize(): string;